From 3fc7c195c30e62e7cdacdf0b2369ceab009d4eac Mon Sep 17 00:00:00 2001 From: Opostol Date: Fri, 10 Aug 2018 13:54:09 +0300 Subject: [PATCH 1/5] DockWidgetMovable feature implemented In my implementation DockWidgetMovable feature also not allows tab to float. --- src/DockWidgetTitleBar.cpp | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/DockWidgetTitleBar.cpp b/src/DockWidgetTitleBar.cpp index 2663206..b9f5be9 100644 --- a/src/DockWidgetTitleBar.cpp +++ b/src/DockWidgetTitleBar.cpp @@ -240,16 +240,19 @@ void CDockWidgetTitleBar::mouseReleaseEvent(QMouseEvent* ev) // End of tab moving, change order now if (d->isDraggingState(DraggingTab) && d->DockArea) { - // Find tab under mouse - QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos()); - int fromIndex = d->DockArea->tabIndex(d->DockWidget); - int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this); - if (-1 == toIndex) - { - toIndex = d->DockArea->count() - 1; + if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + // Find tab under mouse + QPoint pos = d->DockArea->mapFromGlobal(ev->globalPos()); + int fromIndex = d->DockArea->tabIndex(d->DockWidget); + int toIndex = d->DockArea->indexOfContentByTitlePos(pos, this); + if (-1 == toIndex) + { + toIndex = d->DockArea->count() - 1; + } + qDebug() << "Move tab from " << fromIndex << " to " << toIndex; + d->DockArea->reorderDockWidget(fromIndex, toIndex); } - qDebug() << "Move tab from " << fromIndex << " to " << toIndex; - d->DockArea->reorderDockWidget(fromIndex, toIndex); + } if (!d->DragStartMousePosition.isNull()) @@ -275,7 +278,9 @@ void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev) if (d->isDraggingState(DraggingFloatingWidget)) { - d->FloatingWidget->moveFloating(); + if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + d->FloatingWidget->moveFloating(); + } QFrame::mouseMoveEvent(ev); return; } @@ -283,19 +288,25 @@ void CDockWidgetTitleBar::mouseMoveEvent(QMouseEvent* ev) // move tab if (d->isDraggingState(DraggingTab)) { - d->moveTab(ev); + if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + d->moveTab(ev); + } } bool MouseInsideTitleArea = d->titleAreaGeometryContains(ev->globalPos()); if (!MouseInsideTitleArea) { - d->startFloating(); + if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + d->startFloating(); + } return; } else if (d->DockArea->count() > 1 && (ev->pos() - d->DragStartMousePosition).manhattanLength() >= QApplication::startDragDistance()) // Wait a few pixels before start moving { - d->DragState = DraggingTab; + if (d->DockWidget->features() & CDockWidget::DockWidgetMovable) { + d->DragState = DraggingTab; + } return; } From 4188d69356445e067e4a5d7b1bdf1735f5a8f384 Mon Sep 17 00:00:00 2001 From: Opostol Date: Fri, 10 Aug 2018 14:46:57 +0300 Subject: [PATCH 2/5] Dock area currentChanging signal introduced(part1) currentChanging signal helps to save previous layout state before tab will be changed --- src/DockAreaWidget.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index f9ff5df..0079f8b 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -187,6 +187,13 @@ signals: */ void tabBarClicked(int index); + /** + * This signal is emitted when the tab bar's current tab is about to be changed. The new + * current has the given index, or -1 if there isn't a new one. + * @param index + */ + void currentChanging(int index); + /** * This signal is emitted when the tab bar's current tab changes. The new * current has the given index, or -1 if there isn't a new one From 8eceed9aa31cdd0501c0567eecd81dd842544c13 Mon Sep 17 00:00:00 2001 From: Opostol Date: Fri, 10 Aug 2018 14:48:20 +0300 Subject: [PATCH 3/5] Dock area currentChanging signal introduced(part2) --- src/DockAreaWidget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 868934e..dbbf144 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -533,7 +533,9 @@ void CDockAreaWidget::setCurrentIndex(int index) { qWarning() << Q_FUNC_INFO << "Invalid index" << index; return; - } + } + + emit currentChanging(index); // Set active TAB and update all other tabs to be inactive for (int i = 0; i < d->TabsLayout->count(); ++i) From 7b4a19b943ea712cd667a6d5a2bc8ce967bb20a3 Mon Sep 17 00:00:00 2001 From: Opostol Date: Fri, 10 Aug 2018 15:11:57 +0300 Subject: [PATCH 4/5] DockManager stateChanged signal introduced(part1) Can be helpful to reconnect to area signals --- src/DockManager.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DockManager.h b/src/DockManager.h index 0aad01b..d6e19c7 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -187,6 +187,11 @@ signals: * This signal is emitted if the list of perspectives changed */ void perspectiveListChanged(); + + /** + * This signal is emitted if the state changed in restoreState + */ + void stateChanged(); }; // class DockManager } // namespace ads //----------------------------------------------------------------------------- From b470dd5f99a296c9968b671d42daf594e1e1d20c Mon Sep 17 00:00:00 2001 From: Opostol Date: Fri, 10 Aug 2018 15:12:38 +0300 Subject: [PATCH 5/5] DockManager stateChanged signal introduced(part2) --- src/DockManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DockManager.cpp b/src/DockManager.cpp index c32c556..df34055 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -369,6 +369,8 @@ bool CDockManager::restoreState(const QByteArray &state, int version) } } + emit stateChanged(); + return true; }