From 4627ead8f20541aabdb56c9d4e28a555c5f9c7e7 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 10 Jul 2015 15:24:24 +0200 Subject: [PATCH] Add custom properties to ToolWindowManager toolwindows, update titles * Two properties added - DisallowUserDocking which completely prevents a toolwindow from being dragged or docked other than programmatically. * HideCloseButton also hides the close button that normally appears on the tabs created * Also tabs now watch for title change signals and update the titles in tabs. --- .../toolwindowmanager/ToolWindowManager.cpp | 28 +++++++++++++++++++ .../toolwindowmanager/ToolWindowManager.h | 23 +++++++++++++++ .../ToolWindowManagerArea.cpp | 15 ++++++++++ .../toolwindowmanager/ToolWindowManagerArea.h | 5 ++++ 4 files changed, 71 insertions(+) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp index f59c51625..baf2251f5 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp @@ -80,6 +80,17 @@ ToolWindowManager::~ToolWindowManager() { } } +void ToolWindowManager::setToolWindowProperties(QWidget* toolWindow, ToolWindowManager::ToolWindowProperty properties) { + m_toolWindowProperties[toolWindow] = properties; + ToolWindowManagerArea *area = areaOf(toolWindow); + if(area) + area->updateToolWindow(toolWindow); +} + +ToolWindowManager::ToolWindowProperty ToolWindowManager::toolWindowProperties(QWidget* toolWindow) { + return m_toolWindowProperties[toolWindow]; +} + void ToolWindowManager::addToolWindow(QWidget *toolWindow, const AreaReference &area) { addToolWindows(QList() << toolWindow, area); } @@ -97,6 +108,8 @@ void ToolWindowManager::addToolWindows(QList toolWindows, const ToolW toolWindow->hide(); toolWindow->setParent(0); m_toolWindows << toolWindow; + m_toolWindowProperties[toolWindow] = ToolWindowProperty(0); + QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, &ToolWindowManager::windowTitleChanged); } moveToolWindows(toolWindows, area); } @@ -211,6 +224,7 @@ void ToolWindowManager::removeToolWindow(QWidget *toolWindow) { } moveToolWindow(toolWindow, NoArea); m_toolWindows.removeOne(toolWindow); + m_toolWindowProperties.remove(toolWindow); } void ToolWindowManager::setSuggestionSwitchInterval(int msec) { @@ -373,6 +387,9 @@ void ToolWindowManager::startDrag(const QList &toolWindows) { qWarning("ToolWindowManager::execDrag: drag is already in progress"); return; } + foreach(QWidget* toolWindow, toolWindows) { + if(toolWindowProperties(toolWindow) & DisallowUserDocking) { return; } + } if (toolWindows.isEmpty()) { return; } m_draggedToolWindows = toolWindows; m_dragIndicator->setPixmap(generateDragPixmap(toolWindows)); @@ -675,6 +692,17 @@ void ToolWindowManager::tabCloseRequested(int index) { hideToolWindow(toolWindow); } +void ToolWindowManager::windowTitleChanged(const QString &title) { + QWidget* toolWindow = qobject_cast(sender()); + if(!toolWindow) { + return; + } + ToolWindowManagerArea *area = areaOf(toolWindow); + if(area) { + area->updateToolWindow(toolWindow); + } +} + QSplitter *ToolWindowManager::createSplitter() { QSplitter* splitter = new QSplitter(); splitter->setChildrenCollapsible(false); diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h index d3f9cb66d..4312e20a8 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h @@ -103,6 +103,14 @@ public: */ virtual ~ToolWindowManager(); + //! Toolwindow properties + enum ToolWindowProperty { + //! Disables all drag/docking ability by the user + DisallowUserDocking = 0x1, + //! Hides the close button on the tab for this tool window + HideCloseButton = 0x2, + }; + //! Type of AreaReference. enum AreaReferenceType { //! The area tool windows has been added to most recently. @@ -157,6 +165,16 @@ public: */ void addToolWindow(QWidget* toolWindow, const AreaReference& area); + /*! + * Sets the set of \a properties on \a toolWindow that is already added to the manager. + */ + void setToolWindowProperties(QWidget* toolWindow, ToolWindowProperty properties); + + /*! + * Returns the set of \a properties on \a toolWindow. + */ + ToolWindowProperty toolWindowProperties(QWidget* toolWindow); + /*! * \brief Adds \a toolWindows to the manager and moves it to the position specified by * \a area. @@ -250,6 +268,7 @@ signals: private: QList m_toolWindows; // all added tool windows + QHash m_toolWindowProperties; // all tool window properties QList m_areas; // all areas for this manager QList m_wrappers; // all wrappers for this manager int m_borderSensitivity; @@ -309,7 +328,11 @@ protected: private slots: void showNextDropSuggestion(); void tabCloseRequested(int index); + void windowTitleChanged(const QString &title); }; +inline ToolWindowManager::ToolWindowProperty operator|(ToolWindowManager::ToolWindowProperty a, ToolWindowManager::ToolWindowProperty b) +{ return ToolWindowManager::ToolWindowProperty(int(a) | int(b)); } + #endif // TOOLWINDOWMANAGER_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp index 3531459ff..d3a44dff1 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp @@ -53,6 +53,9 @@ void ToolWindowManagerArea::addToolWindows(const QList &toolWindows) int index = 0; foreach(QWidget* toolWindow, toolWindows) { index = addTab(toolWindow, toolWindow->windowIcon(), toolWindow->windowTitle()); + if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) { + tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0); + } } setCurrentIndex(index); m_manager->m_lastUsedArea = this; @@ -66,6 +69,18 @@ QList ToolWindowManagerArea::toolWindows() { return result; } +void ToolWindowManagerArea::updateToolWindow(QWidget* toolWindow) { + int index = indexOf(toolWindow); + if(index >= 0) { + if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) { + tabBar()->tabButton(index, QTabBar::RightSide)->resize(0, 0); + } else { + tabBar()->tabButton(index, QTabBar::RightSide)->resize(16, 16); + } + tabBar()->setTabText(index, toolWindow->windowTitle()); + } +} + void ToolWindowManagerArea::mousePressEvent(QMouseEvent *) { if (qApp->mouseButtons() == Qt::LeftButton) { m_dragCanStart = true; diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h index 8714069c2..faad11b2f 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h @@ -57,6 +57,11 @@ public: */ QList toolWindows(); + /*! + * Updates the \a toolWindow to its current properties and title. + */ + void updateToolWindow(QWidget* toolWindow); + protected: //! Reimplemented from QTabWidget::mousePressEvent. virtual void mousePressEvent(QMouseEvent *);