SVN commit 1168869 by kuemmel: Plots could be moved to a other tab by drag&drop. Drag the plot with the upper left round button to a other tabbar. CBUG: 248885 M +49 -0 tabwidget.cpp M +38 -1 viewitem.cpp M +15 -0 viewitem.h --- branches/work/kst/portto4/kst/src/libkstapp/tabwidget.cpp #1168868:1168869 @@ -12,7 +12,10 @@ #include "tabwidget.h" #include "mainwindow.h" #include "view.h" +#include "viewitem.h" +#include "curveplacement.h" + #include #include #include @@ -21,8 +24,53 @@ namespace Kst { +class TabBar : public QTabBar +{ +public: + TabBar(TabWidget* tabw); + + void dragEnterEvent(QDragEnterEvent* event); + void dragMoveEvent(QDragMoveEvent* event); + void dropEvent(QDropEvent* event); + + TabWidget* tabWidget; +}; + +TabBar::TabBar(TabWidget* tabw) : QTabBar(), tabWidget(tabw) +{ + setAcceptDrops(true); +} + +void TabBar::dragEnterEvent(QDragEnterEvent* event) +{ + if (MimeDataViewItem::downcast(event->mimeData())) { + event->acceptProposedAction(); + } +} + +void TabBar::dragMoveEvent(QDragMoveEvent* event) +{ + if (MimeDataViewItem::downcast(event->mimeData())) { + setCurrentIndex(tabAt(event->pos())); + event->acceptProposedAction(); + } +} + +void TabBar::dropEvent(QDropEvent* event) +{ + const MimeDataViewItem* m = MimeDataViewItem::downcast(event->mimeData()); + if (m && m->item) { + View* view = tabWidget->currentView(); + view->appendToLayout(CurvePlacement::Auto, m->item); + event->acceptProposedAction(); + } +} + + + TabWidget::TabWidget(QWidget *parent) : QTabWidget(parent) { + setTabBar(new TabBar(this)); tabBar()->setContextMenuPolicy(Qt::CustomContextMenu); connect(tabBar(), SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(contextMenu(const QPoint&))); _cnt = 0; @@ -56,6 +104,7 @@ addTab(view, label); setCurrentWidget(view); + tabBar()->setAcceptDrops(true); } --- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #1168868:1168869 @@ -31,6 +31,8 @@ #include #include #include +#include +#include static const double ONE_PI = 3.14159265358979323846264338327950288419717; static double TWO_PI = 2.0 * ONE_PI; @@ -108,6 +110,8 @@ _customLayoutAction = new QAction(tr("Custom"), this); connect(_customLayoutAction, SIGNAL(triggered()), this, SLOT(createCustomLayout())); + + setAcceptDrops(true); } @@ -915,6 +919,23 @@ void ViewItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { + if (event->buttons() & Qt::LeftButton && + (event->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance()) { + + QDrag *drag = new QDrag(event->widget()); + MimeDataViewItem* mimeData = new MimeDataViewItem; + mimeData->item = this; + drag->setMimeData(mimeData); + + + Qt::DropActions dact = Qt::MoveAction; + Qt::DropAction dropAction = drag->exec(dact); + if (dropAction == Qt::MoveAction) { + _autoLayoutAction->trigger(); + } + } + + if (parentView()->viewMode() == View::Data) { event->ignore(); return; @@ -1587,12 +1608,18 @@ void ViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + QPointF p = event->pos(); + if (checkBox().contains(p)) { + if (event->buttons() & Qt::LeftButton) { + dragStartPosition = p; + } + } + if (parentView()->viewMode() == View::Data) { event->ignore(); return; } - QPointF p = event->pos(); if (isAllowed(TopLeftGrip) && topLeftGrip().contains(p)) { setActiveGrip(TopLeftGrip); } else if (isAllowed(TopRightGrip) && topRightGrip().contains(p)) { @@ -2166,6 +2193,16 @@ _item->setTransform(_newTransform); } + + + +MimeDataViewItem::MimeDataViewItem() : QMimeData() { } +const MimeDataViewItem* MimeDataViewItem::downcast(const QMimeData* m) { + return qobject_cast(m); +} + +} + // vim: ts=2 sw=2 et --- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #1168868:1168869 @@ -17,6 +17,7 @@ #include #include #include +#include #include "namedobject.h" #include "kst_export.h" @@ -259,6 +260,7 @@ virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + QAction *_editAction; QAction *_deleteAction; QAction *_raiseAction; @@ -310,6 +312,8 @@ QSizeF _layoutMargins, _layoutSpacing; + QPointF dragStartPosition; + friend class View; friend class Scene; }; @@ -522,6 +526,17 @@ return tItems; } +class MimeDataViewItem : public QMimeData +{ + Q_OBJECT +public: + MimeDataViewItem(); + + ViewItem* item; + + static const MimeDataViewItem* downcast(const QMimeData*); +}; + } #endif