From 764d13e11d0637af74ad868c404d34f6aa1c4715 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 25 Mar 2015 19:02:29 +0000 Subject: [PATCH] Include ToolWindowManager for Qt docking implementation * From https://github.com/Riateche/toolwindowmanager * It seems superior to the built-in Qt docking as-is, and since it's a few open source files it should be easy to improve with features we might want to match DockingUI functionality. * Programmatic sizing for the default layout seems inflexible, but since that's a one-time thing it's not the end of the world. * There's no auto-hide functionality. * The highlighting of where to drop could be improved, as well as the detection of where to drop (currently it seems to cycle through several possibilities each second rather than having a consistent drop location). * Floating windows could be styled a bit better. * Need to check whether we can have nested docking sections (so the texture viewer e.g. can have its own docks, that won't float or go out of the texture viewer. --- qrenderdoc/3rdparty/toolwindowmanager/LICENSE | 21 + .../3rdparty/toolwindowmanager/README.md | 18 + .../toolwindowmanager/ToolWindowManager.cpp | 713 ++++++++++++++++++ .../toolwindowmanager/ToolWindowManager.h | 303 ++++++++ .../ToolWindowManagerArea.cpp | 180 +++++ .../toolwindowmanager/ToolWindowManagerArea.h | 91 +++ .../ToolWindowManagerWrapper.cpp | 97 +++ .../ToolWindowManagerWrapper.h | 64 ++ 8 files changed, 1487 insertions(+) create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/LICENSE create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/README.md create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp create mode 100644 qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h diff --git a/qrenderdoc/3rdparty/toolwindowmanager/LICENSE b/qrenderdoc/3rdparty/toolwindowmanager/LICENSE new file mode 100644 index 000000000..bd8b7d916 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Pavel Strakhov + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/qrenderdoc/3rdparty/toolwindowmanager/README.md b/qrenderdoc/3rdparty/toolwindowmanager/README.md new file mode 100644 index 000000000..82e4b08d8 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/README.md @@ -0,0 +1,18 @@ +ToolWindowManager +================= + +ToolWindowManager is a Qt based tool window manager. + +This project implements docking tool behavior that is similar to tool windows mechanism in Visual Studio or Eclipse. User can arrange tool windows in tabs, dock it to any border, split with vertical and horizontal splitters, tabify them together and detach to floating windows. + +[API documentation](http://riateche.github.io/toolwindowmanager/doc/class_tool_window_manager.html) + +Demo (animated GIF): + +![demo](doc/0.gif) + +More screenshots: + +![screenshot](doc/1.png) + +![screenshot](doc/2.png) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp new file mode 100644 index 000000000..e5680b843 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp @@ -0,0 +1,713 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#include "ToolWindowManager.h" +#include "ToolWindowManagerArea.h" +#include "ToolWindowManagerWrapper.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +T findClosestParent(QWidget* widget) { + while(widget) { + if (qobject_cast(widget)) { + return static_cast(widget); + } + widget = widget->parentWidget(); + } + return 0; +} + +ToolWindowManager::ToolWindowManager(QWidget *parent) : + QWidget(parent) +{ + m_borderSensitivity = 12; + QSplitter* testSplitter = new QSplitter(); + m_rubberBandLineWidth = testSplitter->handleWidth(); + delete testSplitter; + m_dragIndicator = new QLabel(0, Qt::ToolTip ); + m_dragIndicator->setAttribute(Qt::WA_ShowWithoutActivating); + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(0, 0, 0, 0); + ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this); + wrapper->setWindowFlags(wrapper->windowFlags() & ~Qt::Tool); + mainLayout->addWidget(wrapper); + connect(&m_dropSuggestionSwitchTimer, SIGNAL(timeout()), + this, SLOT(showNextDropSuggestion())); + m_dropSuggestionSwitchTimer.setInterval(1000); + m_dropCurrentSuggestionIndex = 0; + + m_rectRubberBand = new QRubberBand(QRubberBand::Rectangle, this); + m_lineRubberBand = new QRubberBand(QRubberBand::Line, this); +} + +ToolWindowManager::~ToolWindowManager() { + while(!m_areas.isEmpty()) { + delete m_areas.first(); + } + while(!m_wrappers.isEmpty()) { + delete m_wrappers.first(); + } +} + +void ToolWindowManager::addToolWindow(QWidget *toolWindow, const AreaReference &area) { + addToolWindows(QList() << toolWindow, area); +} + +void ToolWindowManager::addToolWindows(QList toolWindows, const ToolWindowManager::AreaReference &area) { + foreach(QWidget* toolWindow, toolWindows) { + if (!toolWindow) { + qWarning("cannot add null widget"); + continue; + } + if (m_toolWindows.contains(toolWindow)) { + qWarning("this tool window has already been added"); + continue; + } + toolWindow->hide(); + toolWindow->setParent(0); + m_toolWindows << toolWindow; + } + moveToolWindows(toolWindows, area); +} + +ToolWindowManagerArea *ToolWindowManager::areaOf(QWidget *toolWindow) { + return findClosestParent(toolWindow); +} + +void ToolWindowManager::moveToolWindow(QWidget *toolWindow, AreaReference area) { + moveToolWindows(QList() << toolWindow, area); +} + +void ToolWindowManager::moveToolWindows(QList toolWindows, + ToolWindowManager::AreaReference area) { + foreach(QWidget* toolWindow, toolWindows) { + if (!m_toolWindows.contains(toolWindow)) { + qWarning("unknown tool window"); + return; + } + if (toolWindow->parentWidget() != 0) { + releaseToolWindow(toolWindow); + } + } + if (area.type() == LastUsedArea && !m_lastUsedArea) { + ToolWindowManagerArea* foundArea = findChild(); + if (foundArea) { + area = AreaReference(AddTo, foundArea); + } else { + area = EmptySpace; + } + } + + if (area.type() == NoArea) { + //do nothing + } else if (area.type() == NewFloatingArea) { + ToolWindowManagerArea* area = createArea(); + area->addToolWindows(toolWindows); + ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this); + wrapper->layout()->addWidget(area); + wrapper->move(QCursor::pos()); + wrapper->show(); + } else if (area.type() == AddTo) { + area.area()->addToolWindows(toolWindows); + } else if (area.type() == LeftOf || area.type() == RightOf || + area.type() == TopOf || area.type() == BottomOf) { + QSplitter* parentSplitter = qobject_cast(area.widget()->parentWidget()); + ToolWindowManagerWrapper* wrapper = qobject_cast(area.widget()->parentWidget()); + if (!parentSplitter && !wrapper) { + qWarning("unknown parent type"); + return; + } + bool useParentSplitter = false; + int indexInParentSplitter = 0; + if (parentSplitter) { + indexInParentSplitter = parentSplitter->indexOf(area.widget()); + if (parentSplitter->orientation() == Qt::Vertical) { + useParentSplitter = area.type() == TopOf || area.type() == BottomOf; + } else { + useParentSplitter = area.type() == LeftOf || area.type() == RightOf; + } + } + if (useParentSplitter) { + if (area.type() == BottomOf || area.type() == RightOf) { + indexInParentSplitter++; + } + ToolWindowManagerArea* newArea = createArea(); + newArea->addToolWindows(toolWindows); + parentSplitter->insertWidget(indexInParentSplitter, newArea); + } else { + area.widget()->hide(); + area.widget()->setParent(0); + QSplitter* splitter = createSplitter(); + if (area.type() == TopOf || area.type() == BottomOf) { + splitter->setOrientation(Qt::Vertical); + } else { + splitter->setOrientation(Qt::Horizontal); + } + splitter->addWidget(area.widget()); + area.widget()->show(); + ToolWindowManagerArea* newArea = createArea(); + if (area.type() == TopOf || area.type() == LeftOf) { + splitter->insertWidget(0, newArea); + } else { + splitter->addWidget(newArea); + } + if (parentSplitter) { + parentSplitter->insertWidget(indexInParentSplitter, splitter); + } else { + wrapper->layout()->addWidget(splitter); + } + newArea->addToolWindows(toolWindows); + } + } else if (area.type() == EmptySpace) { + ToolWindowManagerArea* newArea = createArea(); + findChild()->layout()->addWidget(newArea); + newArea->addToolWindows(toolWindows); + } else if (area.type() == LastUsedArea) { + m_lastUsedArea->addToolWindows(toolWindows); + } else { + qWarning("invalid type"); + } + simplifyLayout(); + foreach(QWidget* toolWindow, toolWindows) { + emit toolWindowVisibilityChanged(toolWindow, toolWindow->parent() != 0); + } +} + +void ToolWindowManager::removeToolWindow(QWidget *toolWindow) { + if (!m_toolWindows.contains(toolWindow)) { + qWarning("unknown tool window"); + return; + } + moveToolWindow(toolWindow, NoArea); + m_toolWindows.removeOne(toolWindow); +} + +void ToolWindowManager::setSuggestionSwitchInterval(int msec) { + m_dropSuggestionSwitchTimer.setInterval(msec); +} + +int ToolWindowManager::suggestionSwitchInterval() { + return m_dropSuggestionSwitchTimer.interval(); +} + +void ToolWindowManager::setBorderSensitivity(int pixels) { + m_borderSensitivity = pixels; +} + +void ToolWindowManager::setRubberBandLineWidth(int pixels) { + m_rubberBandLineWidth = pixels; +} + +QVariant ToolWindowManager::saveState() { + QVariantMap result; + result["toolWindowManagerStateFormat"] = 1; + ToolWindowManagerWrapper* mainWrapper = findChild(); + if (!mainWrapper) { + qWarning("can't find main wrapper"); + return QVariant(); + } + result["mainWrapper"] = mainWrapper->saveState(); + QVariantList floatingWindowsData; + foreach(ToolWindowManagerWrapper* wrapper, m_wrappers) { + if (!wrapper->isWindow()) { continue; } + floatingWindowsData << wrapper->saveState(); + } + result["floatingWindows"] = floatingWindowsData; + return result; +} + +void ToolWindowManager::restoreState(const QVariant &data) { + if (!data.isValid()) { return; } + QVariantMap dataMap = data.toMap(); + if (dataMap["toolWindowManagerStateFormat"].toInt() != 1) { + qWarning("state format is not recognized"); + return; + } + moveToolWindows(m_toolWindows, NoArea); + ToolWindowManagerWrapper* mainWrapper = findChild(); + if (!mainWrapper) { + qWarning("can't find main wrapper"); + return; + } + mainWrapper->restoreState(dataMap["mainWrapper"].toMap()); + foreach(QVariant windowData, dataMap["floatingWindows"].toList()) { + ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this); + wrapper->restoreState(windowData.toMap()); + wrapper->show(); + } + simplifyLayout(); + foreach(QWidget* toolWindow, m_toolWindows) { + emit toolWindowVisibilityChanged(toolWindow, toolWindow->parentWidget() != 0); + } +} + +ToolWindowManagerArea *ToolWindowManager::createArea() { + ToolWindowManagerArea* area = new ToolWindowManagerArea(this, 0); + connect(area, SIGNAL(tabCloseRequested(int)), + this, SLOT(tabCloseRequested(int))); + return area; +} + + +void ToolWindowManager::handleNoSuggestions() { + m_rectRubberBand->hide(); + m_lineRubberBand->hide(); + m_lineRubberBand->setParent(this); + m_rectRubberBand->setParent(this); + m_suggestions.clear(); + m_dropCurrentSuggestionIndex = 0; + if (m_dropSuggestionSwitchTimer.isActive()) { + m_dropSuggestionSwitchTimer.stop(); + } +} + +void ToolWindowManager::releaseToolWindow(QWidget *toolWindow) { + ToolWindowManagerArea* previousTabWidget = findClosestParent(toolWindow); + if (!previousTabWidget) { + qWarning("cannot find tab widget for tool window"); + return; + } + previousTabWidget->removeTab(previousTabWidget->indexOf(toolWindow)); + toolWindow->hide(); + toolWindow->setParent(0); + +} + +void ToolWindowManager::simplifyLayout() { + foreach(ToolWindowManagerArea* area, m_areas) { + if (area->parentWidget() == 0) { + if (area->count() == 0) { + if (area == m_lastUsedArea) { m_lastUsedArea = 0; } + //QTimer::singleShot(1000, area, SLOT(deleteLater())); + area->deleteLater(); + } + continue; + } + QSplitter* splitter = qobject_cast(area->parentWidget()); + QSplitter* validSplitter = 0; // least top level splitter that should remain + QSplitter* invalidSplitter = 0; //most top level splitter that should be deleted + while(splitter) { + if (splitter->count() > 1) { + validSplitter = splitter; + break; + } else { + invalidSplitter = splitter; + splitter = qobject_cast(splitter->parentWidget()); + } + } + if (!validSplitter) { + ToolWindowManagerWrapper* wrapper = findClosestParent(area); + if (!wrapper) { + qWarning("can't find wrapper"); + return; + } + if (area->count() == 0 && wrapper->isWindow()) { + wrapper->hide(); + // can't deleteLater immediately (strange MacOS bug) + //QTimer::singleShot(1000, wrapper, SLOT(deleteLater())); + wrapper->deleteLater(); + } else if (area->parent() != wrapper) { + wrapper->layout()->addWidget(area); + } + } else { + if (area->count() > 0) { + if (validSplitter && area->parent() != validSplitter) { + int index = validSplitter->indexOf(invalidSplitter); + validSplitter->insertWidget(index, area); + } + } + } + if (invalidSplitter) { + invalidSplitter->hide(); + invalidSplitter->setParent(0); + //QTimer::singleShot(1000, invalidSplitter, SLOT(deleteLater())); + invalidSplitter->deleteLater(); + } + if (area->count() == 0) { + area->hide(); + area->setParent(0); + if (area == m_lastUsedArea) { m_lastUsedArea = 0; } + //QTimer::singleShot(1000, area, SLOT(deleteLater())); + area->deleteLater(); + } + } +} + +void ToolWindowManager::startDrag(const QList &toolWindows) { + if (dragInProgress()) { + qWarning("ToolWindowManager::execDrag: drag is already in progress"); + return; + } + if (toolWindows.isEmpty()) { return; } + m_draggedToolWindows = toolWindows; + m_dragIndicator->setPixmap(generateDragPixmap(toolWindows)); + updateDragPosition(); + m_dragIndicator->show(); +} + +QVariantMap ToolWindowManager::saveSplitterState(QSplitter *splitter) { + QVariantMap result; + result["state"] = splitter->saveState(); + result["type"] = "splitter"; + QVariantList items; + for(int i = 0; i < splitter->count(); i++) { + QWidget* item = splitter->widget(i); + QVariantMap itemValue; + ToolWindowManagerArea* area = qobject_cast(item); + if (area) { + itemValue = area->saveState(); + } else { + QSplitter* childSplitter = qobject_cast(item); + if (childSplitter) { + itemValue = saveSplitterState(childSplitter); + } else { + qWarning("unknown splitter item"); + } + } + items << itemValue; + } + result["items"] = items; + return result; +} + +QSplitter *ToolWindowManager::restoreSplitterState(const QVariantMap &data) { + if (data["items"].toList().count() < 2) { + qWarning("invalid splitter encountered"); + } + QSplitter* splitter = createSplitter(); + + foreach(QVariant itemData, data["items"].toList()) { + QVariantMap itemValue = itemData.toMap(); + QString itemType = itemValue["type"].toString(); + if (itemType == "splitter") { + splitter->addWidget(restoreSplitterState(itemValue)); + } else if (itemType == "area") { + ToolWindowManagerArea* area = createArea(); + area->restoreState(itemValue); + splitter->addWidget(area); + } else { + qWarning("unknown item type"); + } + } + splitter->restoreState(data["state"].toByteArray()); + return splitter; +} + +QPixmap ToolWindowManager::generateDragPixmap(const QList &toolWindows) { + QTabBar widget; + widget.setDocumentMode(true); + foreach(QWidget* toolWindow, toolWindows) { + widget.addTab(toolWindow->windowIcon(), toolWindow->windowTitle()); + } +#if QT_VERSION >= 0x050000 // Qt5 + return widget.grab(); +#else //Qt4 + return QPixmap::grabWidget(&widget); +#endif +} + +void ToolWindowManager::showNextDropSuggestion() { + if (m_suggestions.isEmpty()) { + qWarning("showNextDropSuggestion called but no suggestions"); + return; + } + m_dropCurrentSuggestionIndex++; + if (m_dropCurrentSuggestionIndex >= m_suggestions.count()) { + m_dropCurrentSuggestionIndex = 0; + } + const AreaReference& suggestion = m_suggestions[m_dropCurrentSuggestionIndex]; + if (suggestion.type() == AddTo || suggestion.type() == EmptySpace) { + QWidget* widget; + if (suggestion.type() == EmptySpace) { + widget = findChild(); + } else { + widget = suggestion.widget(); + } + QWidget* placeHolderParent; + if (widget->topLevelWidget() == topLevelWidget()) { + placeHolderParent = this; + } else { + placeHolderParent = widget->topLevelWidget(); + } + QRect placeHolderGeometry = widget->rect(); + placeHolderGeometry.moveTopLeft(widget->mapTo(placeHolderParent, + placeHolderGeometry.topLeft())); + m_rectRubberBand->setGeometry(placeHolderGeometry); + m_rectRubberBand->setParent(placeHolderParent); + m_rectRubberBand->show(); + m_lineRubberBand->hide(); + } else if (suggestion.type() == LeftOf || suggestion.type() == RightOf || + suggestion.type() == TopOf || suggestion.type() == BottomOf) { + QWidget* placeHolderParent; + if (suggestion.widget()->topLevelWidget() == topLevelWidget()) { + placeHolderParent = this; + } else { + placeHolderParent = suggestion.widget()->topLevelWidget(); + } + QRect placeHolderGeometry = sidePlaceHolderRect(suggestion.widget(), suggestion.type()); + placeHolderGeometry.moveTopLeft(suggestion.widget()->mapTo(placeHolderParent, + placeHolderGeometry.topLeft())); + + m_lineRubberBand->setGeometry(placeHolderGeometry); + m_lineRubberBand->setParent(placeHolderParent); + m_lineRubberBand->show(); + m_rectRubberBand->hide(); + } else { + qWarning("unsupported suggestion type"); + } +} + +void ToolWindowManager::findSuggestions(ToolWindowManagerWrapper* wrapper) { + m_suggestions.clear(); + m_dropCurrentSuggestionIndex = -1; + QPoint globalPos = QCursor::pos(); + QList candidates; + foreach(QSplitter* splitter, wrapper->findChildren()) { + candidates << splitter; + } + foreach(ToolWindowManagerArea* area, m_areas) { + if (area->topLevelWidget() == wrapper->topLevelWidget()) { + candidates << area; + } + } + foreach(QWidget* widget, candidates) { + QSplitter* splitter = qobject_cast(widget); + ToolWindowManagerArea* area = qobject_cast(widget); + if (!splitter && !area) { + qWarning("unexpected widget type"); + continue; + } + QSplitter* parentSplitter = qobject_cast(widget->parentWidget()); + bool lastInSplitter = parentSplitter && + parentSplitter->indexOf(widget) == parentSplitter->count() - 1; + + QList allowedSides; + if (!splitter || splitter->orientation() == Qt::Vertical) { + allowedSides << LeftOf; + } + if (!splitter || splitter->orientation() == Qt::Horizontal) { + allowedSides << TopOf; + } + if (!parentSplitter || parentSplitter->orientation() == Qt::Vertical || lastInSplitter) { + if (!splitter || splitter->orientation() == Qt::Vertical) { + allowedSides << RightOf; + } + } + if (!parentSplitter || parentSplitter->orientation() == Qt::Horizontal || lastInSplitter) { + if (!splitter || splitter->orientation() == Qt::Horizontal) { + allowedSides << BottomOf; + } + } + foreach(AreaReferenceType side, allowedSides) { + if (sideSensitiveArea(widget, side).contains(widget->mapFromGlobal(globalPos))) { + m_suggestions << AreaReference(side, widget); + } + } + if (area && area->rect().contains(area->mapFromGlobal(globalPos))) { + m_suggestions << AreaReference(AddTo, area); + } + } + if (candidates.isEmpty()) { + m_suggestions << EmptySpace; + } + + if (m_suggestions.isEmpty()) { + handleNoSuggestions(); + } else { + showNextDropSuggestion(); + } +} + +QRect ToolWindowManager::sideSensitiveArea(QWidget *widget, ToolWindowManager::AreaReferenceType side) { + QRect widgetRect = widget->rect(); + if (side == TopOf) { + return QRect(QPoint(widgetRect.left(), widgetRect.top() - m_borderSensitivity), + QSize(widgetRect.width(), m_borderSensitivity * 2)); + } else if (side == LeftOf) { + return QRect(QPoint(widgetRect.left() - m_borderSensitivity, widgetRect.top()), + QSize(m_borderSensitivity * 2, widgetRect.height())); + + } else if (side == BottomOf) { + return QRect(QPoint(widgetRect.left(), widgetRect.top() + widgetRect.height() - m_borderSensitivity), + QSize(widgetRect.width(), m_borderSensitivity * 2)); + } else if (side == RightOf) { + return QRect(QPoint(widgetRect.left() + widgetRect.width() - m_borderSensitivity, widgetRect.top()), + QSize(m_borderSensitivity * 2, widgetRect.height())); + } else { + qWarning("invalid side"); + return QRect(); + } +} + +QRect ToolWindowManager::sidePlaceHolderRect(QWidget *widget, ToolWindowManager::AreaReferenceType side) { + QRect widgetRect = widget->rect(); + QSplitter* parentSplitter = qobject_cast(widget->parentWidget()); + if (parentSplitter && parentSplitter->indexOf(widget) > 0) { + int delta = parentSplitter->handleWidth() / 2 + m_rubberBandLineWidth / 2; + if (side == TopOf && parentSplitter->orientation() == Qt::Vertical) { + return QRect(QPoint(widgetRect.left(), widgetRect.top() - delta), + QSize(widgetRect.width(), m_rubberBandLineWidth)); + } else if (side == LeftOf && parentSplitter->orientation() == Qt::Horizontal) { + return QRect(QPoint(widgetRect.left() - delta, widgetRect.top()), + QSize(m_rubberBandLineWidth, widgetRect.height())); + } + } + if (side == TopOf) { + return QRect(QPoint(widgetRect.left(), widgetRect.top()), + QSize(widgetRect.width(), m_rubberBandLineWidth)); + } else if (side == LeftOf) { + return QRect(QPoint(widgetRect.left(), widgetRect.top()), + QSize(m_rubberBandLineWidth, widgetRect.height())); + } else if (side == BottomOf) { + return QRect(QPoint(widgetRect.left(), widgetRect.top() + widgetRect.height() - m_rubberBandLineWidth), + QSize(widgetRect.width(), m_rubberBandLineWidth)); + } else if (side == RightOf) { + return QRect(QPoint(widgetRect.left() + widgetRect.width() - m_rubberBandLineWidth, widgetRect.top()), + QSize(m_rubberBandLineWidth, widgetRect.height())); + } else { + qWarning("invalid side"); + return QRect(); + } +} + +void ToolWindowManager::updateDragPosition() { + if (!dragInProgress()) { return; } + if (!(qApp->mouseButtons() & Qt::LeftButton)) { + finishDrag(); + return; + } + + QPoint pos = QCursor::pos(); + m_dragIndicator->move(pos + QPoint(1, 1)); + bool foundWrapper = false; + + QWidget* window = qApp->topLevelAt(pos); + foreach(ToolWindowManagerWrapper* wrapper, m_wrappers) { + if (wrapper->window() == window) { + if (wrapper->rect().contains(wrapper->mapFromGlobal(pos))) { + findSuggestions(wrapper); + if (!m_suggestions.isEmpty()) { + //starting or restarting timer + if (m_dropSuggestionSwitchTimer.isActive()) { + m_dropSuggestionSwitchTimer.stop(); + } + m_dropSuggestionSwitchTimer.start(); + foundWrapper = true; + } + } + break; + } + } + if (!foundWrapper) { + handleNoSuggestions(); + } +} + +void ToolWindowManager::finishDrag() { + if (!dragInProgress()) { + qWarning("unexpected finishDrag"); + return; + } + if (m_suggestions.isEmpty()) { + moveToolWindows(m_draggedToolWindows, NewFloatingArea); + + } else { + if (m_dropCurrentSuggestionIndex >= m_suggestions.count()) { + qWarning("invalid m_dropCurrentSuggestionIndex"); + return; + } + ToolWindowManager::AreaReference suggestion = m_suggestions[m_dropCurrentSuggestionIndex]; + handleNoSuggestions(); + moveToolWindows(m_draggedToolWindows, suggestion); + } + + + m_dragIndicator->hide(); + m_draggedToolWindows.clear(); +} + +void ToolWindowManager::tabCloseRequested(int index) { + ToolWindowManagerArea* tabWidget = qobject_cast(sender()); + if (!tabWidget) { + qWarning("sender is not a ToolWindowManagerArea"); + return; + } + QWidget* toolWindow = tabWidget->widget(index); + if (!m_toolWindows.contains(toolWindow)) { + qWarning("unknown tab in tab widget"); + return; + } + hideToolWindow(toolWindow); +} + +QSplitter *ToolWindowManager::createSplitter() { + QSplitter* splitter = new QSplitter(); + splitter->setChildrenCollapsible(false); + return splitter; +} + +ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, ToolWindowManagerArea *area) { + m_type = type; + setWidget(area); +} + +void ToolWindowManager::AreaReference::setWidget(QWidget *widget) { + if (m_type == LastUsedArea || m_type == NewFloatingArea || m_type == NoArea || m_type == EmptySpace) { + if (widget != 0) { + qWarning("area parameter ignored for this type"); + } + m_widget = 0; + } else if (m_type == AddTo) { + m_widget = qobject_cast(widget); + if (!m_widget) { + qWarning("only ToolWindowManagerArea can be used with this type"); + } + } else { + if (!qobject_cast(widget) && + !qobject_cast(widget)) { + qWarning("only ToolWindowManagerArea or splitter can be used with this type"); + m_widget = 0; + } else { + m_widget = widget; + } + } +} + +ToolWindowManagerArea *ToolWindowManager::AreaReference::area() const { + return qobject_cast(m_widget); +} + +ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, QWidget *widget) { + m_type = type; + setWidget(widget); +} diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h new file mode 100644 index 000000000..5c9968371 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h @@ -0,0 +1,303 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#ifndef TOOLWINDOWMANAGER_H +#define TOOLWINDOWMANAGER_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class ToolWindowManagerArea; +class ToolWindowManagerWrapper; + + +/*! + * \brief The ToolWindowManager class provides docking tool behavior. + * + * The behavior is similar to tool windows mechanism in Visual Studio or Eclipse. + * User can arrange tool windows + * in tabs, dock it to any border, split with vertical and horizontal splitters, + * tabify them together and detach to floating windows. + * + * See https://github.com/Riateche/toolwindowmanager for detailed description. + */ +class ToolWindowManager : public QWidget { + Q_OBJECT + /*! + * \brief The delay between showing the next suggestion of drop location in milliseconds. + * + * When user starts a tool window drag and moves mouse pointer to a position, there can be + * an ambiguity in new position of the tool window. If user holds the left mouse button and + * stops mouse movements, all possible suggestions will be indicated periodically, one at a time. + * + * Default value is 1000 (i.e. 1 second). + * + * Access functions: suggestionSwitchInterval, setSuggestionSwitchInterval. + * + */ + Q_PROPERTY(int suggestionSwitchInterval READ suggestionSwitchInterval WRITE setSuggestionSwitchInterval) + /*! + * \brief Maximal distance in pixels between mouse position and area border that allows + * to display a suggestion. + * + * Default value is 12. + * + * Access functions: borderSensitivity, setBorderSensitivity. + */ + Q_PROPERTY(int borderSensitivity READ borderSensitivity WRITE setBorderSensitivity) + /*! + * \brief Visible width of rubber band line that is used to display drop suggestions. + * + * Default value is the same as QSplitter::handleWidth default value on current platform. + * + * Access functions: rubberBandLineWidth, setRubberBandLineWidth. + * + */ + Q_PROPERTY(int rubberBandLineWidth READ rubberBandLineWidth WRITE setRubberBandLineWidth) + +public: + /*! + * \brief Creates a manager with given \a parent. + */ + explicit ToolWindowManager(QWidget *parent = 0); + /*! + * \brief Destroys the widget. Additionally all tool windows and all floating windows + * created by this widget are destroyed. + */ + virtual ~ToolWindowManager(); + + //! Type of AreaReference. + enum AreaReferenceType { + //! The area tool windows has been added to most recently. + LastUsedArea, + //! New area in a detached window. + NewFloatingArea, + //! Area inside the manager widget (only available when there is no tool windows in it). + EmptySpace, + //! Tool window is hidden. + NoArea, + //! Existing area specified in AreaReference argument. + AddTo, + //! New area to the left of the area specified in AreaReference argument. + LeftOf, + //! New area to the right of the area specified in AreaReference argument. + RightOf, + //! New area to the top of the area specified in AreaReference argument. + TopOf, + //! New area to the bottom of the area specified in AreaReference argument. + BottomOf + }; + + /*! + * \brief The AreaReference class represents a place where tool windows should be moved. + */ + class AreaReference { + public: + /*! + * Creates an area reference of the given \a type. If \a type requires specifying + * area, it should be given in \a area argument. Otherwise \a area should have default value (0). + */ + AreaReference(AreaReferenceType type = NoArea, ToolWindowManagerArea* area = 0); + //! Returns type of the reference. + AreaReferenceType type() const { return m_type; } + //! Returns area of the reference, or 0 if it was not specified. + ToolWindowManagerArea* area() const; + + private: + AreaReferenceType m_type; + QWidget* m_widget; + QWidget* widget() const { return m_widget; } + AreaReference(AreaReferenceType type, QWidget* widget); + void setWidget(QWidget* widget); + + friend class ToolWindowManager; + + }; + + /*! + * Adds \a toolWindow to the manager and moves it to the position specified by + * \a area. This function is a shortcut for ToolWindowManager::addToolWindows. + */ + void addToolWindow(QWidget* toolWindow, const AreaReference& area); + + /*! + * \brief Adds \a toolWindows to the manager and moves it to the position specified by + * \a area. + * The manager takes ownership of the tool windows and will delete them upon destruction. + * + * toolWindow->windowIcon() and toolWindow->windowTitle() will be used as the icon and title + * of the tab that represents the tool window. + * + * If you intend to use ToolWindowManager::saveState + * and ToolWindowManager::restoreState functions, you must set objectName() of each added + * tool window to a non-empty unique string. + */ + void addToolWindows(QList toolWindows, const AreaReference& area); + + /*! + * Returns area that contains \a toolWindow, or 0 if \a toolWindow is hidden. + */ + ToolWindowManagerArea* areaOf(QWidget* toolWindow); + + /*! + * \brief Moves \a toolWindow to the position specified by \a area. + * + * \a toolWindow must be added to the manager prior to calling this function. + */ + void moveToolWindow(QWidget* toolWindow, AreaReference area); + + /*! + * \brief Moves \a toolWindows to the position specified by \a area. + * + * \a toolWindows must be added to the manager prior to calling this function. + */ + void moveToolWindows(QList toolWindows, AreaReference area); + + /*! + * \brief Removes \a toolWindow from the manager. \a toolWindow becomes a hidden + * top level widget. The ownership of \a toolWindow is returned to the caller. + */ + void removeToolWindow(QWidget* toolWindow); + + /*! + * \brief Returns all tool window added to the manager. + */ + const QList& toolWindows() { return m_toolWindows; } + + /*! + * Hides \a toolWindow. + * + * \a toolWindow must be added to the manager prior to calling this function. + */ + void hideToolWindow(QWidget* toolWindow) { moveToolWindow(toolWindow, NoArea); } + + /*! + * \brief saveState + */ + QVariant saveState(); + + /*! + * \brief restoreState + */ + void restoreState(const QVariant& data); + + + /*! \cond PRIVATE */ + void setSuggestionSwitchInterval(int msec); + int suggestionSwitchInterval(); + int borderSensitivity() { return m_borderSensitivity; } + void setBorderSensitivity(int pixels); + void setRubberBandLineWidth(int pixels); + int rubberBandLineWidth() { return m_rubberBandLineWidth; } + /*! \endcond */ + + /*! + * Returns the widget that is used to display rectangular drop suggestions. + */ + QRubberBand* rectRubberBand() { return m_rectRubberBand; } + + /*! + * Returns the widget that is used to display line drop suggestions. + */ + QRubberBand* lineRubberBand() { return m_lineRubberBand; } + + +signals: + /*! + * \brief This signal is emitted when \a toolWindow may be hidden or shown. + * \a visible indicates new visibility state of the tool window. + */ + void toolWindowVisibilityChanged(QWidget* toolWindow, bool visible); + +private: + QList m_toolWindows; // all added tool windows + QList m_areas; // all areas for this manager + QList m_wrappers; // all wrappers for this manager + int m_borderSensitivity; + int m_rubberBandLineWidth; + // list of tool windows that are currently dragged, or empty list if there is no current drag + QList m_draggedToolWindows; + QLabel* m_dragIndicator; // label used to display dragged content + + QRubberBand* m_rectRubberBand; // placeholder objects used for displaying drop suggestions + QRubberBand* m_lineRubberBand; + QList m_suggestions; //full list of suggestions for current cursor position + int m_dropCurrentSuggestionIndex; // index of currently displayed drop suggestion + // (e.g. always 0 if there is only one possible drop location) + QTimer m_dropSuggestionSwitchTimer; // used for switching drop suggestions + + // last widget used for adding tool windows, or 0 if there isn't one + // (warning: may contain pointer to deleted object) + ToolWindowManagerArea* m_lastUsedArea; + void handleNoSuggestions(); + //remove tool window from its area (if any) and set parent to 0 + void releaseToolWindow(QWidget* toolWindow); + void simplifyLayout(); //remove constructions that became useless + void startDrag(const QList& toolWindows); + + QVariantMap saveSplitterState(QSplitter* splitter); + QSplitter* restoreSplitterState(const QVariantMap& data); + void findSuggestions(ToolWindowManagerWrapper *wrapper); + QRect sideSensitiveArea(QWidget* widget, AreaReferenceType side); + QRect sidePlaceHolderRect(QWidget* widget, AreaReferenceType side); + + void updateDragPosition(); + void finishDrag(); + bool dragInProgress() { return !m_draggedToolWindows.isEmpty(); } + + friend class ToolWindowManagerArea; + friend class ToolWindowManagerWrapper; + +protected: + /*! + * \brief Creates new splitter and sets its default properties. You may reimplement + * this function to change properties of all splitters used by this class. + */ + virtual QSplitter* createSplitter(); + /*! + * \brief Creates new area and sets its default properties. You may reimplement + * this function to change properties of all tab widgets used by this class. + */ + virtual ToolWindowManagerArea *createArea(); + /*! + * \brief Generates a pixmap that is used to represent the data in a drag and drop operation + * near the mouse cursor. + * You may reimplement this function to use different pixmaps. + */ + virtual QPixmap generateDragPixmap(const QList &toolWindows); + +private slots: + void showNextDropSuggestion(); + void tabCloseRequested(int index); + +}; + +#endif // TOOLWINDOWMANAGER_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp new file mode 100644 index 000000000..3531459ff --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp @@ -0,0 +1,180 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#include "ToolWindowManagerArea.h" +#include "ToolWindowManager.h" +#include +#include +#include + +ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget *parent) : + QTabWidget(parent) +, m_manager(manager) +{ + m_dragCanStart = false; + m_tabDragCanStart = false; + setMovable(true); + setTabsClosable(true); + setDocumentMode(true); + tabBar()->installEventFilter(this); + m_manager->m_areas << this; +} + +ToolWindowManagerArea::~ToolWindowManagerArea() { + m_manager->m_areas.removeOne(this); +} + +void ToolWindowManagerArea::addToolWindow(QWidget *toolWindow) { + addToolWindows(QList() << toolWindow); +} + +void ToolWindowManagerArea::addToolWindows(const QList &toolWindows) { + int index = 0; + foreach(QWidget* toolWindow, toolWindows) { + index = addTab(toolWindow, toolWindow->windowIcon(), toolWindow->windowTitle()); + } + setCurrentIndex(index); + m_manager->m_lastUsedArea = this; +} + +QList ToolWindowManagerArea::toolWindows() { + QList result; + for(int i = 0; i < count(); i++) { + result << widget(i); + } + return result; +} + +void ToolWindowManagerArea::mousePressEvent(QMouseEvent *) { + if (qApp->mouseButtons() == Qt::LeftButton) { + m_dragCanStart = true; + } +} + +void ToolWindowManagerArea::mouseReleaseEvent(QMouseEvent *) { + m_dragCanStart = false; + m_manager->updateDragPosition(); +} + +void ToolWindowManagerArea::mouseMoveEvent(QMouseEvent *) { + check_mouse_move(); +} + +bool ToolWindowManagerArea::eventFilter(QObject *object, QEvent *event) { + if (object == tabBar()) { + if (event->type() == QEvent::MouseButtonPress && + qApp->mouseButtons() == Qt::LeftButton) { + // can start tab drag only if mouse is at some tab, not at empty tabbar space + if (tabBar()->tabAt(static_cast(event)->pos()) >= 0 ) { + m_tabDragCanStart = true; + } else { + m_dragCanStart = true; + } + + } else if (event->type() == QEvent::MouseButtonRelease) { + m_tabDragCanStart = false; + m_dragCanStart = false; + m_manager->updateDragPosition(); + } else if (event->type() == QEvent::MouseMove) { + m_manager->updateDragPosition(); + if (m_tabDragCanStart) { + if (tabBar()->rect().contains(static_cast(event)->pos())) { + return false; + } + if (qApp->mouseButtons() != Qt::LeftButton) { + return false; + } + QWidget* toolWindow = currentWidget(); + if (!toolWindow || !m_manager->m_toolWindows.contains(toolWindow)) { + return false; + } + m_tabDragCanStart = false; + //stop internal tab drag in QTabBar + QMouseEvent* releaseEvent = new QMouseEvent(QEvent::MouseButtonRelease, + static_cast(event)->pos(), + Qt::LeftButton, Qt::LeftButton, 0); + qApp->sendEvent(tabBar(), releaseEvent); + m_manager->startDrag(QList() << toolWindow); + } else if (m_dragCanStart) { + check_mouse_move(); + } + } + } + return QTabWidget::eventFilter(object, event); +} + +QVariantMap ToolWindowManagerArea::saveState() { + QVariantMap result; + result["type"] = "area"; + result["currentIndex"] = currentIndex(); + QStringList objectNames; + for(int i = 0; i < count(); i++) { + QString name = widget(i)->objectName(); + if (name.isEmpty()) { + qWarning("cannot save state of tool window without object name"); + } else { + objectNames << name; + } + } + result["objectNames"] = objectNames; + return result; +} + +void ToolWindowManagerArea::restoreState(const QVariantMap &data) { + foreach(QVariant objectNameValue, data["objectNames"].toList()) { + QString objectName = objectNameValue.toString(); + if (objectName.isEmpty()) { continue; } + bool found = false; + foreach(QWidget* toolWindow, m_manager->m_toolWindows) { + if (toolWindow->objectName() == objectName) { + addToolWindow(toolWindow); + found = true; + break; + } + } + if (!found) { + qWarning("tool window with name '%s' not found", objectName.toLocal8Bit().constData()); + } + } + setCurrentIndex(data["currentIndex"].toInt()); +} + +void ToolWindowManagerArea::check_mouse_move() { + m_manager->updateDragPosition(); + if (qApp->mouseButtons() == Qt::LeftButton && + !rect().contains(mapFromGlobal(QCursor::pos())) && + m_dragCanStart) { + m_dragCanStart = false; + QList toolWindows; + for(int i = 0; i < count(); i++) { + QWidget* toolWindow = widget(i); + if (!m_manager->m_toolWindows.contains(toolWindow)) { + qWarning("tab widget contains unmanaged widget"); + } else { + toolWindows << toolWindow; + } + } + m_manager->startDrag(toolWindows); + } +} diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h new file mode 100644 index 000000000..8714069c2 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h @@ -0,0 +1,91 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#ifndef TOOLWINDOWMANAGERAREA_H +#define TOOLWINDOWMANAGERAREA_H + +#include +#include + +class ToolWindowManager; + +/*! + * \brief The ToolWindowManagerArea class is a tab widget used to store tool windows. + * It implements dragging of its tab or the whole tab widget. + */ +class ToolWindowManagerArea : public QTabWidget { + Q_OBJECT +public: + //! Creates new area. + explicit ToolWindowManagerArea(ToolWindowManager* manager, QWidget *parent = 0); + //! Destroys the area. + virtual ~ToolWindowManagerArea(); + + /*! + * Add \a toolWindow to this area. + */ + void addToolWindow(QWidget* toolWindow); + + /*! + * Add \a toolWindows to this area. + */ + void addToolWindows(const QList& toolWindows); + + /*! + * Returns a list of all tool windows in this area. + */ + QList toolWindows(); + +protected: + //! Reimplemented from QTabWidget::mousePressEvent. + virtual void mousePressEvent(QMouseEvent *); + //! Reimplemented from QTabWidget::mouseReleaseEvent. + virtual void mouseReleaseEvent(QMouseEvent *); + //! Reimplemented from QTabWidget::mouseMoveEvent. + virtual void mouseMoveEvent(QMouseEvent *); + //! Reimplemented from QTabWidget::eventFilter. + virtual bool eventFilter(QObject *object, QEvent *event); + +private: + ToolWindowManager* m_manager; + bool m_dragCanStart; // indicates that user has started mouse movement on QTabWidget + // that can be considered as dragging it if the cursor will leave + // its area + + bool m_tabDragCanStart; // indicates that user has started mouse movement on QTabWidget + // that can be considered as dragging current tab + // if the cursor will leave the tab bar area + + QVariantMap saveState(); // dump contents to variable + void restoreState(const QVariantMap& data); //restore contents from given variable + + //check if mouse left tab widget area so that dragging should start + void check_mouse_move(); + + friend class ToolWindowManager; + friend class ToolWindowManagerWrapper; + +}; + +#endif // TOOLWINDOWMANAGERAREA_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp new file mode 100644 index 000000000..730979d46 --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp @@ -0,0 +1,97 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#include "ToolWindowManagerWrapper.h" +#include "ToolWindowManager.h" +#include "ToolWindowManagerArea.h" +#include +#include +#include +#include +#include + +ToolWindowManagerWrapper::ToolWindowManagerWrapper(ToolWindowManager *manager) : + QWidget(manager) +, m_manager(manager) +{ + setWindowFlags(windowFlags() | Qt::Tool); + setWindowTitle(" "); + + QVBoxLayout* mainLayout = new QVBoxLayout(this); + mainLayout->setContentsMargins(0, 0, 0, 0); + m_manager->m_wrappers << this; +} + +ToolWindowManagerWrapper::~ToolWindowManagerWrapper() { + m_manager->m_wrappers.removeOne(this); +} + +void ToolWindowManagerWrapper::closeEvent(QCloseEvent *) { + QList toolWindows; + foreach(ToolWindowManagerArea* tabWidget, findChildren()) { + toolWindows << tabWidget->toolWindows(); + } + m_manager->moveToolWindows(toolWindows, ToolWindowManager::NoArea); +} + +QVariantMap ToolWindowManagerWrapper::saveState() { + if (layout()->count() > 1) { + qWarning("too many children for wrapper"); + return QVariantMap(); + } + if (isWindow() && layout()->count() == 0) { + qWarning("empty top level wrapper"); + return QVariantMap(); + } + QVariantMap result; + result["geometry"] = saveGeometry(); + QSplitter* splitter = findChild(); + if (splitter) { + result["splitter"] = m_manager->saveSplitterState(splitter); + } else { + ToolWindowManagerArea* area = findChild(); + if (area) { + result["area"] = area->saveState(); + } else if (layout()->count() > 0) { + qWarning("unknown child"); + return QVariantMap(); + } + } + return result; +} + +void ToolWindowManagerWrapper::restoreState(const QVariantMap &data) { + restoreGeometry(data["geometry"].toByteArray()); + if (layout()->count() > 0) { + qWarning("wrapper is not empty"); + return; + } + if (data.contains("splitter")) { + layout()->addWidget(m_manager->restoreSplitterState(data["splitter"].toMap())); + } else if (data.contains("area")) { + ToolWindowManagerArea* area = m_manager->createArea(); + area->restoreState(data["area"].toMap()); + layout()->addWidget(area); + } +} diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h new file mode 100644 index 000000000..4227d98ee --- /dev/null +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h @@ -0,0 +1,64 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2014 Pavel Strakhov + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ +#ifndef TOOLWINDOWMANAGERWRAPPER_H +#define TOOLWINDOWMANAGERWRAPPER_H + +#include +#include + +class ToolWindowManager; + +/*! + * \brief The ToolWindowManagerWrapper class is used by ToolWindowManager to wrap its content. + * One wrapper is a direct child of the manager and contains tool windows that are inside its window. + * All other wrappers are top level floating windows that contain detached tool windows. + * + */ +class ToolWindowManagerWrapper : public QWidget { + Q_OBJECT +public: + //! Creates new wrapper. + explicit ToolWindowManagerWrapper(ToolWindowManager* manager); + //! Removes the wrapper. + virtual ~ToolWindowManagerWrapper(); + +protected: + //! Reimplemented to register hiding of contained tool windows when user closes the floating window. + virtual void closeEvent(QCloseEvent *); + +private: + ToolWindowManager* m_manager; + + //dump content's layout to variable + QVariantMap saveState(); + + //construct layout based on given dump + void restoreState(const QVariantMap& data); + + friend class ToolWindowManager; + +}; + +#endif // TOOLWINDOWMANAGERWRAPPER_H