diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2015-03-04 15:07:53 +0100 |
---|---|---|
committer | Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com> | 2015-04-11 09:26:56 +0000 |
commit | 02a13a86fab1f928d5dd40069d121ded549366f1 (patch) | |
tree | d9082cc7869ec5094bad4d240178af91395cccf3 /src | |
parent | 60e8519544b9194d4a44db61fb5b0b10572282cc (diff) | |
download | qtbase-02a13a86fab1f928d5dd40069d121ded549366f1.tar.gz |
Allow for rearranging tabified QDockWidgets
Allow to drag and drop tabs
[ChangeLog][QtWidgets][Important Behavior Changes] The tabs
for the tabified docks can be moved by the user.
Task-number: QTBUG-1049
Task-number: QTBUG-2295
Task-number: QTBUG-4532
Task-number: QTBUG-18883
Task-number: QTBUG-35148
Change-Id: I7ef9d4987db081654bd5d648e14370b3d381a720
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: Jørgen Lind <jorgen.lind@theqtcompany.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/widgets/qdockarealayout.cpp | 16 | ||||
-rw-r--r-- | src/widgets/widgets/qdockarealayout_p.h | 3 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 12 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout_p.h | 1 |
4 files changed, 32 insertions, 0 deletions
diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index e71b9616fc..af0f2515fe 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -2244,6 +2244,22 @@ QRect QDockAreaLayoutInfo::tabContentRect() const return result; } + +int QDockAreaLayoutInfo::tabIndexToListIndex(int tabIndex) const +{ + Q_ASSERT(tabbed && tabBar); + quintptr data = qvariant_cast<quintptr>(tabBar->tabData(tabIndex)); + for (int i = 0; i < item_list.count(); ++i) { + if (tabId(item_list.at(i)) == data) + return i; + } + return -1; +} + +void QDockAreaLayoutInfo::moveTab(int from, int to) +{ + item_list.move(tabIndexToListIndex(from), tabIndexToListIndex(to)); +} #endif // QT_NO_TABBAR /****************************************************************************** diff --git a/src/widgets/widgets/qdockarealayout_p.h b/src/widgets/widgets/qdockarealayout_p.h index 7c67466c7b..64fae7ebf6 100644 --- a/src/widgets/widgets/qdockarealayout_p.h +++ b/src/widgets/widgets/qdockarealayout_p.h @@ -208,6 +208,9 @@ public: QSize tabBarSizeHint() const; QSet<QTabBar*> usedTabBars() const; + + int tabIndexToListIndex(int) const; + void moveTab(int from, int to); #endif // QT_NO_TABBAR }; diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 046666f571..3620aa04fc 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -1280,7 +1280,9 @@ QTabBar *QMainWindowLayout::getTabBar() result->setDrawBase(true); result->setElideMode(Qt::ElideRight); result->setDocumentMode(_documentMode); + result->setMovable(true); connect(result, SIGNAL(currentChanged(int)), this, SLOT(tabChanged())); + connect(result, &QTabBar::tabMoved, this, &QMainWindowLayout::tabMoved); } usedTabBars.insert(result); @@ -1316,6 +1318,16 @@ void QMainWindowLayout::tabChanged() if (QWidget *w = centralWidget()) w->raise(); } + +void QMainWindowLayout::tabMoved(int from, int to) +{ + QTabBar *tb = qobject_cast<QTabBar*>(sender()); + Q_ASSERT(tb); + QDockAreaLayoutInfo *info = layoutState.dockAreaLayout.info(tb); + Q_ASSERT(info); + + info->moveTab(from, to); +} #endif // QT_NO_TABBAR bool QMainWindowLayout::startSeparatorMove(const QPoint &pos) diff --git a/src/widgets/widgets/qmainwindowlayout_p.h b/src/widgets/widgets/qmainwindowlayout_p.h index 9f84ee95db..8ccb4d303f 100644 --- a/src/widgets/widgets/qmainwindowlayout_p.h +++ b/src/widgets/widgets/qmainwindowlayout_p.h @@ -286,6 +286,7 @@ private Q_SLOTS: #ifndef QT_NO_DOCKWIDGET #ifndef QT_NO_TABBAR void tabChanged(); + void tabMoved(int from, int to); #endif #endif private: |