From e548cb5cf7a62d028d0c0d6325c0c7eba2ae0486 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 10 Jul 2015 15:25:15 +0200 Subject: [PATCH] Allow disabling a specific tab from being dragged * Also cancels any re-arrangements that involve that tab (mostly useful for a fixed tab at the start of the tab list). --- .../toolwindowmanager/ToolWindowManager.h | 2 ++ .../ToolWindowManagerArea.cpp | 31 ++++++++++++++++++- .../toolwindowmanager/ToolWindowManagerArea.h | 5 +++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h index 4312e20a8..5bb274a7b 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h @@ -109,6 +109,8 @@ public: DisallowUserDocking = 0x1, //! Hides the close button on the tab for this tool window HideCloseButton = 0x2, + //! Disable the user being able to drag this tab in the tab bar, to rearrange + DisableDraggableTab = 0x4, }; //! Type of AreaReference. diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp index d3a44dff1..58a601b21 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp @@ -34,11 +34,14 @@ ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget { m_dragCanStart = false; m_tabDragCanStart = false; + m_inTabMoved = false; setMovable(true); setTabsClosable(true); setDocumentMode(true); tabBar()->installEventFilter(this); m_manager->m_areas << this; + + QObject::connect(tabBar(), &QTabBar::tabMoved, this, &ToolWindowManagerArea::tabMoved); } ToolWindowManagerArea::~ToolWindowManagerArea() { @@ -100,9 +103,18 @@ bool ToolWindowManagerArea::eventFilter(QObject *object, QEvent *event) { if (object == tabBar()) { if (event->type() == QEvent::MouseButtonPress && qApp->mouseButtons() == Qt::LeftButton) { + + int tabIndex = tabBar()->tabAt(static_cast(event)->pos()); + // can start tab drag only if mouse is at some tab, not at empty tabbar space - if (tabBar()->tabAt(static_cast(event)->pos()) >= 0 ) { + if (tabIndex >= 0) { m_tabDragCanStart = true; + + if (m_manager->toolWindowProperties(widget(tabIndex)) & ToolWindowManager::DisableDraggableTab) { + setMovable(false); + } else { + setMovable(true); + } } else { m_dragCanStart = true; } @@ -193,3 +205,20 @@ void ToolWindowManagerArea::check_mouse_move() { m_manager->startDrag(toolWindows); } } + +void ToolWindowManagerArea::tabMoved(int from, int to) { + if(m_inTabMoved) return; + + QWidget *a = widget(from); + QWidget *b = widget(to); + + if(!a || !b) return; + + if(m_manager->toolWindowProperties(a) & ToolWindowManager::DisableDraggableTab || + m_manager->toolWindowProperties(b) & ToolWindowManager::DisableDraggableTab) + { + m_inTabMoved = true; + tabBar()->moveTab(to, from); + m_inTabMoved = false; + } +} diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h index faad11b2f..354ebe2dd 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h @@ -82,6 +82,9 @@ private: // that can be considered as dragging current tab // if the cursor will leave the tab bar area + bool m_inTabMoved; // if we're in the tabMoved() function (so if we call tabMove to cancel + // the movement, we shouldn't re-check the tabMoved behaviour) + QVariantMap saveState(); // dump contents to variable void restoreState(const QVariantMap& data); //restore contents from given variable @@ -91,6 +94,8 @@ private: friend class ToolWindowManager; friend class ToolWindowManagerWrapper; +private slots: + void tabMoved(int from, int to); }; #endif // TOOLWINDOWMANAGERAREA_H