From 8f598e0b0fe4b43297b2e04d14ec48117cd21078 Mon Sep 17 00:00:00 2001 From: baldurk Date: Thu, 21 Dec 2017 11:44:55 +0000 Subject: [PATCH] Update toolwindowmanager to 2b84ee038d3883836e13a952ae14ab2e6ff842a6 --- .../toolwindowmanager/ToolWindowManager.cpp | 1025 +++++++++++------ .../toolwindowmanager/ToolWindowManager.h | 132 ++- .../ToolWindowManagerArea.cpp | 273 +++-- .../toolwindowmanager/ToolWindowManagerArea.h | 57 +- .../ToolWindowManagerSplitter.cpp | 33 +- .../ToolWindowManagerSplitter.h | 5 +- .../ToolWindowManagerTabBar.cpp | 178 +-- .../ToolWindowManagerTabBar.h | 33 +- .../ToolWindowManagerWrapper.cpp | 368 +++--- .../ToolWindowManagerWrapper.h | 42 +- 10 files changed, 1313 insertions(+), 833 deletions(-) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp index fc00f2536..14c745970 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.cpp @@ -23,27 +23,30 @@ * */ #include "ToolWindowManager.h" -#include "ToolWindowManagerArea.h" -#include "ToolWindowManagerSplitter.h" -#include "ToolWindowManagerWrapper.h" -#include -#include -#include #include +#include +#include #include +#include #include #include #include #include -#include #include #include #include +#include +#include "ToolWindowManagerArea.h" +#include "ToolWindowManagerSplitter.h" +#include "ToolWindowManagerWrapper.h" -template -T findClosestParent(QWidget* widget) { - while(widget) { - if (qobject_cast(widget)) { +template +T findClosestParent(QWidget *widget) +{ + while(widget) + { + if(qobject_cast(widget)) + { return static_cast(widget); } widget = widget->parentWidget(); @@ -51,12 +54,11 @@ T findClosestParent(QWidget* widget) { return 0; } -ToolWindowManager::ToolWindowManager(QWidget *parent) : - QWidget(parent) +ToolWindowManager::ToolWindowManager(QWidget *parent) : QWidget(parent) { - QVBoxLayout* mainLayout = new QVBoxLayout(this); + QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); - ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this, false); + ToolWindowManagerWrapper *wrapper = new ToolWindowManagerWrapper(this, false); wrapper->setWindowFlags(wrapper->windowFlags() & ~Qt::Tool); mainLayout->addWidget(wrapper); m_allowFloatingWindow = true; @@ -72,7 +74,8 @@ ToolWindowManager::ToolWindowManager(QWidget *parent) : m_previewOverlay = new QWidget(NULL); m_previewOverlay->setAutoFillBackground(true); m_previewOverlay->setPalette(pal); - m_previewOverlay->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); + m_previewOverlay->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | + Qt::X11BypassWindowManagerHint); m_previewOverlay->setWindowOpacity(0.3); m_previewOverlay->setAttribute(Qt::WA_ShowWithoutActivating); m_previewOverlay->setAttribute(Qt::WA_AlwaysStackOnTop); @@ -81,14 +84,14 @@ ToolWindowManager::ToolWindowManager(QWidget *parent) : m_previewTabOverlay = new QWidget(NULL); m_previewTabOverlay->setAutoFillBackground(true); m_previewTabOverlay->setPalette(pal); - m_previewTabOverlay->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); + m_previewTabOverlay->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); m_previewTabOverlay->setWindowOpacity(0.3); m_previewTabOverlay->setAttribute(Qt::WA_ShowWithoutActivating); m_previewTabOverlay->setAttribute(Qt::WA_AlwaysStackOnTop); m_previewTabOverlay->hide(); - - for (int i=0; i < NumReferenceTypes; i++) + for(int i = 0; i < NumReferenceTypes; i++) m_dropHotspots[i] = NULL; m_dropHotspotDimension = 32; @@ -96,13 +99,12 @@ ToolWindowManager::ToolWindowManager(QWidget *parent) : drawHotspotPixmaps(); - for (AreaReferenceType type : { AddTo, - TopOf, LeftOf, - RightOf, BottomOf, - TopWindowSide, LeftWindowSide, - RightWindowSide, BottomWindowSide }) { + for(AreaReferenceType type : {AddTo, TopOf, LeftOf, RightOf, BottomOf, TopWindowSide, + LeftWindowSide, RightWindowSide, BottomWindowSide}) + { m_dropHotspots[type] = new QLabel(NULL); - m_dropHotspots[type]->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); + m_dropHotspots[type]->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint | + Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); m_dropHotspots[type]->setAttribute(Qt::WA_ShowWithoutActivating); m_dropHotspots[type]->setAttribute(Qt::WA_AlwaysStackOnTop); m_dropHotspots[type]->setPixmap(m_pixmaps[type]); @@ -110,125 +112,163 @@ ToolWindowManager::ToolWindowManager(QWidget *parent) : } } -ToolWindowManager::~ToolWindowManager() { +ToolWindowManager::~ToolWindowManager() +{ delete m_previewOverlay; delete m_previewTabOverlay; for(QWidget *hotspot : m_dropHotspots) delete hotspot; - while(!m_areas.isEmpty()) { + while(!m_areas.isEmpty()) + { delete m_areas.first(); } - while(!m_wrappers.isEmpty()) { + while(!m_wrappers.isEmpty()) + { delete m_wrappers.first(); } } -void ToolWindowManager::setToolWindowProperties(QWidget* toolWindow, ToolWindowManager::ToolWindowProperty properties) { +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) { +ToolWindowManager::ToolWindowProperty ToolWindowManager::toolWindowProperties(QWidget *toolWindow) +{ return m_toolWindowProperties[toolWindow]; } -void ToolWindowManager::addToolWindow(QWidget *toolWindow, const AreaReference &area) { - addToolWindows(QList() << toolWindow, area); +void ToolWindowManager::addToolWindow(QWidget *toolWindow, const AreaReference &area, + ToolWindowManager::ToolWindowProperty properties) +{ + addToolWindows(QList() << toolWindow, area, properties); } -void ToolWindowManager::addToolWindows(QList toolWindows, const ToolWindowManager::AreaReference &area) { - foreach(QWidget* toolWindow, toolWindows) { - if (!toolWindow) { +void ToolWindowManager::addToolWindows(QList toolWindows, + const ToolWindowManager::AreaReference &area, + ToolWindowManager::ToolWindowProperty properties) +{ + foreach(QWidget *toolWindow, toolWindows) + { + if(!toolWindow) + { qWarning("cannot add null widget"); continue; } - if (m_toolWindows.contains(toolWindow)) { + if(m_toolWindows.contains(toolWindow)) + { qWarning("this tool window has already been added"); continue; } toolWindow->hide(); toolWindow->setParent(0); m_toolWindows << toolWindow; - m_toolWindowProperties[toolWindow] = ToolWindowProperty(0); - QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, &ToolWindowManager::windowTitleChanged); + m_toolWindowProperties[toolWindow] = properties; + QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, + &ToolWindowManager::windowTitleChanged); } moveToolWindows(toolWindows, area); } -ToolWindowManagerArea *ToolWindowManager::areaOf(QWidget *toolWindow) { - return findClosestParent(toolWindow); +ToolWindowManagerArea *ToolWindowManager::areaOf(QWidget *toolWindow) +{ + return findClosestParent(toolWindow); } -ToolWindowManagerWrapper *ToolWindowManager::wrapperOf(QWidget *toolWindow) { - return findClosestParent(toolWindow); +ToolWindowManagerWrapper *ToolWindowManager::wrapperOf(QWidget *toolWindow) +{ + return findClosestParent(toolWindow); } -void ToolWindowManager::moveToolWindow(QWidget *toolWindow, AreaReference area) { - moveToolWindows(QList() << toolWindow, area); +void ToolWindowManager::moveToolWindow(QWidget *toolWindow, AreaReference area) +{ + moveToolWindows(QList() << toolWindow, area); } void ToolWindowManager::moveToolWindows(QList toolWindows, - ToolWindowManager::AreaReference area) { - QList wrappersToUpdate; - foreach(QWidget* toolWindow, toolWindows) { - if (!m_toolWindows.contains(toolWindow)) { + ToolWindowManager::AreaReference area) +{ + QList wrappersToUpdate; + foreach(QWidget *toolWindow, toolWindows) + { + if(!m_toolWindows.contains(toolWindow)) + { qWarning("unknown tool window"); return; } ToolWindowManagerWrapper *oldWrapper = wrapperOf(toolWindow); - if (toolWindow->parentWidget() != 0) { + if(toolWindow->parentWidget() != 0) + { releaseToolWindow(toolWindow); } - if (oldWrapper && !wrappersToUpdate.contains(oldWrapper)) + if(oldWrapper && !wrappersToUpdate.contains(oldWrapper)) wrappersToUpdate.push_back(oldWrapper); } - if (area.type() == LastUsedArea && !m_lastUsedArea) { - ToolWindowManagerArea* foundArea = findChild(); - if (foundArea) { + if(area.type() == LastUsedArea && !m_lastUsedArea) + { + ToolWindowManagerArea *foundArea = findChild(); + if(foundArea) + { area = AreaReference(AddTo, foundArea); - } else { + } + else + { area = EmptySpace; } } - if (area.type() == NoArea) { - //do nothing - } else if (area.type() == NewFloatingArea) { - ToolWindowManagerArea* floatArea = createArea(); + if(area.type() == NoArea) + { + // do nothing + } + else if(area.type() == NewFloatingArea) + { + ToolWindowManagerArea *floatArea = createArea(); floatArea->addToolWindows(toolWindows); - ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this, true); + ToolWindowManagerWrapper *wrapper = new ToolWindowManagerWrapper(this, true); wrapper->layout()->addWidget(floatArea); wrapper->move(QCursor::pos()); wrapper->updateTitle(); wrapper->show(); - } else if (area.type() == AddTo) { + } + else if(area.type() == AddTo) + { int idx = -1; - if (area.dragResult) { + if(area.dragResult) + { idx = area.area()->tabBar()->tabAt(area.area()->tabBar()->mapFromGlobal(QCursor::pos())); } area.area()->addToolWindows(toolWindows, idx); - } else if (area.type() == LeftWindowSide || area.type() == RightWindowSide || - area.type() == TopWindowSide || area.type() == BottomWindowSide) { - ToolWindowManagerWrapper* wrapper = findClosestParent(area.area()); - if (!wrapper) { + } + else if(area.type() == LeftWindowSide || area.type() == RightWindowSide || + area.type() == TopWindowSide || area.type() == BottomWindowSide) + { + ToolWindowManagerWrapper *wrapper = findClosestParent(area.area()); + if(!wrapper) + { qWarning("couldn't find wrapper"); return; } - if (wrapper->layout()->count() > 1) + if(wrapper->layout()->count() > 1) { qWarning("wrapper has multiple direct children"); return; } - QLayoutItem* item = wrapper->layout()->takeAt(0); + QLayoutItem *item = wrapper->layout()->takeAt(0); - QSplitter* splitter = createSplitter(); - if (area.type() == TopWindowSide || area.type() == BottomWindowSide) { + QSplitter *splitter = createSplitter(); + if(area.type() == TopWindowSide || area.type() == BottomWindowSide) + { splitter->setOrientation(Qt::Vertical); - } else { + } + else + { splitter->setOrientation(Qt::Horizontal); } @@ -237,46 +277,76 @@ void ToolWindowManager::moveToolWindows(QList toolWindows, delete item; - ToolWindowManagerArea* newArea = createArea(); + ToolWindowManagerArea *newArea = createArea(); newArea->addToolWindows(toolWindows); - if (area.type() == TopWindowSide || area.type() == LeftWindowSide) { + if(area.type() == TopWindowSide || area.type() == LeftWindowSide) + { splitter->insertWidget(0, newArea); - } else { + } + else + { splitter->addWidget(newArea); } wrapper->layout()->addWidget(splitter); - } 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) { + + QRect areaGeometry = area.widget()->geometry(); + + // Convert area percentage desired to relative sizes. + const int totalStretch = (area.type() == TopWindowSide || area.type() == BottomWindowSide) + ? areaGeometry.height() + : areaGeometry.width(); + int pct = int(totalStretch * area.percentage()); + + int a = pct; + int b = totalStretch - pct; + + if(area.type() == BottomWindowSide || area.type() == RightWindowSide) + std::swap(a, b); + + splitter->setSizes({a, b}); + } + 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; QList parentSplitterSizes; - if (parentSplitter) { + if(parentSplitter) + { indexInParentSplitter = parentSplitter->indexOf(area.widget()); parentSplitterSizes = parentSplitter->sizes(); - if (parentSplitter->orientation() == Qt::Vertical) { + if(parentSplitter->orientation() == Qt::Vertical) + { useParentSplitter = area.type() == TopOf || area.type() == BottomOf; - } else { + } + else + { useParentSplitter = area.type() == LeftOf || area.type() == RightOf; } } - if (useParentSplitter) { + if(useParentSplitter) + { int insertIndex = indexInParentSplitter; - if (area.type() == BottomOf || area.type() == RightOf) { + if(area.type() == BottomOf || area.type() == RightOf) + { insertIndex++; } - ToolWindowManagerArea* newArea = createArea(); + ToolWindowManagerArea *newArea = createArea(); newArea->addToolWindows(toolWindows); parentSplitter->insertWidget(insertIndex, newArea); - if(parentSplitterSizes.count() > indexInParentSplitter && parentSplitterSizes[0] != 0) { + if(parentSplitterSizes.count() > indexInParentSplitter && parentSplitterSizes[0] != 0) + { int availSize = parentSplitterSizes[indexInParentSplitter]; parentSplitterSizes[indexInParentSplitter] = int(availSize * (1.0f - area.percentage())); @@ -284,17 +354,22 @@ void ToolWindowManager::moveToolWindows(QList toolWindows, parentSplitter->setSizes(parentSplitterSizes); } - } else { + } + else + { area.widget()->hide(); area.widget()->setParent(0); - QSplitter* splitter = createSplitter(); - if (area.type() == TopOf || area.type() == BottomOf) { + QSplitter *splitter = createSplitter(); + if(area.type() == TopOf || area.type() == BottomOf) + { splitter->setOrientation(Qt::Vertical); - } else { + } + else + { splitter->setOrientation(Qt::Horizontal); } - ToolWindowManagerArea* newArea = createArea(); + ToolWindowManagerArea *newArea = createArea(); // inherit the size policy from the widget we are wrapping splitter->setSizePolicy(area.widget()->sizePolicy()); @@ -306,20 +381,26 @@ void ToolWindowManager::moveToolWindows(QList toolWindows, splitter->addWidget(area.widget()); area.widget()->show(); - if (area.type() == TopOf || area.type() == LeftOf) { + if(area.type() == TopOf || area.type() == LeftOf) + { splitter->insertWidget(0, newArea); - } else { + } + else + { splitter->addWidget(newArea); } - if (parentSplitter) { + if(parentSplitter) + { parentSplitter->insertWidget(indexInParentSplitter, splitter); - if (parentSplitterSizes.count() > 0 && parentSplitterSizes[0] != 0) { + if(parentSplitterSizes.count() > 0 && parentSplitterSizes[0] != 0) + { parentSplitter->setSizes(parentSplitterSizes); } - - } else { + } + else + { wrapper->layout()->addWidget(splitter); } @@ -329,55 +410,66 @@ void ToolWindowManager::moveToolWindows(QList toolWindows, newArea->setGeometry(newGeometry); // Convert area percentage desired to relative sizes. - const int totalStretch = - (area.type() == TopOf || area.type() == BottomOf) - ? areaGeometry.height() : areaGeometry.width(); - int pct = int(totalStretch*area.percentage()); + const int totalStretch = (area.type() == TopOf || area.type() == BottomOf) + ? areaGeometry.height() + : areaGeometry.width(); + int pct = int(totalStretch * area.percentage()); int a = pct; - int b = totalStretch-pct; + int b = totalStretch - pct; - if (area.type() == BottomOf || area.type() == RightOf) + if(area.type() == BottomOf || area.type() == RightOf) std::swap(a, b); splitter->setSizes({a, b}); } - } else if (area.type() == EmptySpace) { - ToolWindowManagerArea* newArea = createArea(); - findChild()->layout()->addWidget(newArea); + } + else if(area.type() == EmptySpace) + { + ToolWindowManagerArea *newArea = createArea(); + findChild()->layout()->addWidget(newArea); newArea->addToolWindows(toolWindows); - } else if (area.type() == LastUsedArea) { + } + else if(area.type() == LastUsedArea) + { m_lastUsedArea->addToolWindows(toolWindows); - } else { + } + else + { qWarning("invalid type"); } simplifyLayout(); - foreach(QWidget* toolWindow, toolWindows) { + foreach(QWidget *toolWindow, toolWindows) + { emit toolWindowVisibilityChanged(toolWindow, toolWindow->parent() != 0); - ToolWindowManagerWrapper* wrapper = wrapperOf(toolWindow); - if (wrapper && !wrappersToUpdate.contains(wrapper)) + ToolWindowManagerWrapper *wrapper = wrapperOf(toolWindow); + if(wrapper && !wrappersToUpdate.contains(wrapper)) wrappersToUpdate.push_back(wrapper); } - foreach(ToolWindowManagerWrapper* wrapper, wrappersToUpdate) { + foreach(ToolWindowManagerWrapper *wrapper, wrappersToUpdate) + { wrapper->updateTitle(); } } -void ToolWindowManager::removeToolWindow(QWidget *toolWindow) { - if (!m_toolWindows.contains(toolWindow)) { +void ToolWindowManager::removeToolWindow(QWidget *toolWindow) +{ + if(!m_toolWindows.contains(toolWindow)) + { qWarning("unknown tool window"); return; } // search up to find the first parent manager - ToolWindowManager *manager = findClosestParent(toolWindow); + ToolWindowManager *manager = findClosestParent(toolWindow); - if (!manager) { + if(!manager) + { qWarning("unknown tool window"); return; } - if (!manager->allowClose(toolWindow)) + if(!manager->allowClose(toolWindow)) return; moveToolWindow(toolWindow, NoArea); @@ -386,25 +478,40 @@ void ToolWindowManager::removeToolWindow(QWidget *toolWindow) { delete toolWindow; } -ToolWindowManager* ToolWindowManager::managerOf(QWidget* toolWindow) { - if (!toolWindow) { +bool ToolWindowManager::isFloating(QWidget *toolWindow) +{ + ToolWindowManagerWrapper *wrapper = wrapperOf(toolWindow); + if(wrapper) + { + return wrapper->floating(); + } + return false; +} + +ToolWindowManager *ToolWindowManager::managerOf(QWidget *toolWindow) +{ + if(!toolWindow) + { qWarning("NULL tool window"); return NULL; } - return findClosestParent(toolWindow); + return findClosestParent(toolWindow); } -void ToolWindowManager::closeToolWindow(QWidget *toolWindow) { - if (!toolWindow) { +void ToolWindowManager::closeToolWindow(QWidget *toolWindow) +{ + if(!toolWindow) + { qWarning("NULL tool window"); return; } // search up to find the first parent manager - ToolWindowManager *manager = findClosestParent(toolWindow); + ToolWindowManager *manager = findClosestParent(toolWindow); - if(manager) { + if(manager) + { manager->removeToolWindow(toolWindow); return; } @@ -412,19 +519,21 @@ void ToolWindowManager::closeToolWindow(QWidget *toolWindow) { qWarning("window not child of any tool window"); } -void ToolWindowManager::raiseToolWindow(QWidget *toolWindow) { - if (!toolWindow) { +void ToolWindowManager::raiseToolWindow(QWidget *toolWindow) +{ + if(!toolWindow) + { qWarning("NULL tool window"); return; } // if the parent is a ToolWindowManagerArea, switch tabs QWidget *parent = toolWindow->parentWidget(); - ToolWindowManagerArea *area = qobject_cast(parent); + ToolWindowManagerArea *area = qobject_cast(parent); if(area == NULL) parent = parent->parentWidget(); - area = qobject_cast(parent); + area = qobject_cast(parent); if(area) area->setCurrentWidget(toolWindow); @@ -432,14 +541,17 @@ void ToolWindowManager::raiseToolWindow(QWidget *toolWindow) { qWarning("parent is not a tool window area"); } -QWidget* ToolWindowManager::createToolWindow(const QString& objectName) +QWidget *ToolWindowManager::createToolWindow(const QString &objectName) { - if (m_createCallback) { + if(m_createCallback) + { QWidget *toolWindow = m_createCallback(objectName); - if(toolWindow) { + if(toolWindow) + { m_toolWindows << toolWindow; m_toolWindowProperties[toolWindow] = ToolWindowProperty(0); - QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, &ToolWindowManager::windowTitleChanged); + QObject::connect(toolWindow, &QWidget::windowTitleChanged, this, + &ToolWindowManager::windowTitleChanged); return toolWindow; } } @@ -447,58 +559,75 @@ QWidget* ToolWindowManager::createToolWindow(const QString& objectName) return NULL; } -void ToolWindowManager::setDropHotspotMargin(int pixels) { +void ToolWindowManager::setDropHotspotMargin(int pixels) +{ m_dropHotspotMargin = pixels; drawHotspotPixmaps(); } -void ToolWindowManager::setDropHotspotDimension(int pixels) { +void ToolWindowManager::setDropHotspotDimension(int pixels) +{ m_dropHotspotDimension = pixels; - for (QLabel *hotspot : m_dropHotspots) { + for(QLabel *hotspot : m_dropHotspots) + { if(hotspot) hotspot->setFixedSize(m_dropHotspotDimension, m_dropHotspotDimension); } } -void ToolWindowManager::setAllowFloatingWindow(bool allow) { +void ToolWindowManager::setAllowFloatingWindow(bool allow) +{ m_allowFloatingWindow = allow; } -QVariantMap ToolWindowManager::saveState() { +QVariantMap ToolWindowManager::saveState() +{ QVariantMap result; result[QStringLiteral("toolWindowManagerStateFormat")] = 1; - ToolWindowManagerWrapper* mainWrapper = findChild(); - if (!mainWrapper) { + ToolWindowManagerWrapper *mainWrapper = findChild(); + if(!mainWrapper) + { qWarning("can't find main wrapper"); return QVariantMap(); } result[QStringLiteral("mainWrapper")] = mainWrapper->saveState(); QVariantList floatingWindowsData; - foreach(ToolWindowManagerWrapper* wrapper, m_wrappers) { - if (!wrapper->isWindow()) { continue; } + foreach(ToolWindowManagerWrapper *wrapper, m_wrappers) + { + if(!wrapper->isWindow()) + { + continue; + } floatingWindowsData << wrapper->saveState(); } result[QStringLiteral("floatingWindows")] = floatingWindowsData; return result; } -void ToolWindowManager::restoreState(const QVariantMap &dataMap) { - if (dataMap.isEmpty()) { return; } - if (dataMap[QStringLiteral("toolWindowManagerStateFormat")].toInt() != 1) { +void ToolWindowManager::restoreState(const QVariantMap &dataMap) +{ + if(dataMap.isEmpty()) + { + return; + } + if(dataMap[QStringLiteral("toolWindowManagerStateFormat")].toInt() != 1) + { qWarning("state format is not recognized"); return; } moveToolWindows(m_toolWindows, NoArea); - ToolWindowManagerWrapper* mainWrapper = findChild(); - if (!mainWrapper) { + ToolWindowManagerWrapper *mainWrapper = findChild(); + if(!mainWrapper) + { qWarning("can't find main wrapper"); return; } mainWrapper->restoreState(dataMap[QStringLiteral("mainWrapper")].toMap()); QVariantList floatWins = dataMap[QStringLiteral("floatingWindows")].toList(); - foreach(QVariant windowData, floatWins) { - ToolWindowManagerWrapper* wrapper = new ToolWindowManagerWrapper(this, true); + foreach(QVariant windowData, floatWins) + { + ToolWindowManagerWrapper *wrapper = new ToolWindowManagerWrapper(this, true); wrapper->restoreState(windowData.toMap()); wrapper->updateTitle(); wrapper->show(); @@ -509,122 +638,166 @@ void ToolWindowManager::restoreState(const QVariantMap &dataMap) { } } simplifyLayout(); - foreach(QWidget* toolWindow, m_toolWindows) { + 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))); +ToolWindowManagerArea *ToolWindowManager::createArea() +{ + ToolWindowManagerArea *area = new ToolWindowManagerArea(this, 0); + connect(area, SIGNAL(tabCloseRequested(int)), this, SLOT(tabCloseRequested(int))); return area; } -void ToolWindowManager::releaseToolWindow(QWidget *toolWindow) { - ToolWindowManagerArea* previousTabWidget = findClosestParent(toolWindow); - if (!previousTabWidget) { +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())); +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) { + 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 { + } + else + { invalidSplitter = splitter; - splitter = qobject_cast(splitter->parentWidget()); + splitter = qobject_cast(splitter->parentWidget()); } } - if (!validSplitter) { - ToolWindowManagerWrapper* wrapper = findClosestParent(area); - if (!wrapper) { + if(!validSplitter) + { + ToolWindowManagerWrapper *wrapper = findClosestParent(area); + if(!wrapper) + { qWarning("can't find wrapper"); return; } - if (area->count() == 0 && wrapper->isWindow()) { + if(area->count() == 0 && wrapper->isWindow()) + { wrapper->hide(); // can't deleteLater immediately (strange MacOS bug) - //QTimer::singleShot(1000, wrapper, SLOT(deleteLater())); + // QTimer::singleShot(1000, wrapper, SLOT(deleteLater())); wrapper->deleteLater(); - } else if (area->parent() != wrapper) { + } + else if(area->parent() != wrapper) + { wrapper->layout()->addWidget(area); } - } else { - if (area->count() > 0) { - if (validSplitter && area->parent() != validSplitter) { + } + else + { + if(area->count() > 0) + { + if(validSplitter && area->parent() != validSplitter) + { int index = validSplitter->indexOf(invalidSplitter); validSplitter->insertWidget(index, area); } } } - if (invalidSplitter) { + if(invalidSplitter) + { invalidSplitter->hide(); invalidSplitter->setParent(0); - //QTimer::singleShot(1000, invalidSplitter, SLOT(deleteLater())); + // QTimer::singleShot(1000, invalidSplitter, SLOT(deleteLater())); invalidSplitter->deleteLater(); } - if (area->count() == 0) { + if(area->count() == 0) + { area->hide(); area->setParent(0); - if (area == m_lastUsedArea) { m_lastUsedArea = 0; } - //QTimer::singleShot(1000, area, SLOT(deleteLater())); + if(area == m_lastUsedArea) + { + m_lastUsedArea = 0; + } + // QTimer::singleShot(1000, area, SLOT(deleteLater())); area->deleteLater(); } } } void ToolWindowManager::startDrag(const QList &toolWindows, - ToolWindowManagerWrapper *wrapper) { - if (dragInProgress()) { + ToolWindowManagerWrapper *wrapper) +{ + if(dragInProgress()) + { qWarning("ToolWindowManager::execDrag: drag is already in progress"); return; } - foreach(QWidget* toolWindow, toolWindows) { - if(toolWindowProperties(toolWindow) & DisallowUserDocking) { return; } + foreach(QWidget *toolWindow, toolWindows) + { + if(toolWindowProperties(toolWindow) & DisallowUserDocking) + { + return; + } + } + if(toolWindows.isEmpty()) + { + return; } - if (toolWindows.isEmpty()) { return; } m_draggedWrapper = wrapper; m_draggedToolWindows = toolWindows; qApp->installEventFilter(this); } -QVariantMap ToolWindowManager::saveSplitterState(QSplitter *splitter) { +QVariantMap ToolWindowManager::saveSplitterState(QSplitter *splitter) +{ QVariantMap result; result[QStringLiteral("state")] = splitter->saveState().toBase64(); result[QStringLiteral("type")] = QStringLiteral("splitter"); QVariantList items; - for(int i = 0; i < splitter->count(); i++) { - QWidget* item = splitter->widget(i); + for(int i = 0; i < splitter->count(); i++) + { + QWidget *item = splitter->widget(i); QVariantMap itemValue; - ToolWindowManagerArea* area = qobject_cast(item); - if (area) { + ToolWindowManagerArea *area = qobject_cast(item); + if(area) + { itemValue = area->saveState(); - } else { - QSplitter* childSplitter = qobject_cast(item); - if (childSplitter) { + } + else + { + QSplitter *childSplitter = qobject_cast(item); + if(childSplitter) + { itemValue = saveSplitterState(childSplitter); - } else { + } + else + { qWarning("unknown splitter item"); } } @@ -634,23 +807,31 @@ QVariantMap ToolWindowManager::saveSplitterState(QSplitter *splitter) { return result; } -QSplitter *ToolWindowManager::restoreSplitterState(const QVariantMap &savedData) { - if (savedData[QStringLiteral("items")].toList().count() < 2) { +QSplitter *ToolWindowManager::restoreSplitterState(const QVariantMap &savedData) +{ + if(savedData[QStringLiteral("items")].toList().count() < 2) + { qWarning("invalid splitter encountered"); } - QSplitter* splitter = createSplitter(); + QSplitter *splitter = createSplitter(); QVariantList itemList = savedData[QStringLiteral("items")].toList(); - foreach(QVariant itemData, itemList) { + foreach(QVariant itemData, itemList) + { QVariantMap itemValue = itemData.toMap(); QString itemType = itemValue[QStringLiteral("type")].toString(); - if (itemType == QStringLiteral("splitter")) { + if(itemType == QStringLiteral("splitter")) + { splitter->addWidget(restoreSplitterState(itemValue)); - } else if (itemType == QStringLiteral("area")) { - ToolWindowManagerArea* area = createArea(); + } + else if(itemType == QStringLiteral("area")) + { + ToolWindowManagerArea *area = createArea(); area->restoreState(itemValue); splitter->addWidget(area); - } else { + } + else + { qWarning("unknown item type"); } } @@ -658,35 +839,47 @@ QSplitter *ToolWindowManager::restoreSplitterState(const QVariantMap &savedData) return splitter; } -void ToolWindowManager::updateDragPosition() { - if (!dragInProgress()) { return; } - if (!(qApp->mouseButtons() & Qt::LeftButton)) { +void ToolWindowManager::updateDragPosition() +{ + if(!dragInProgress()) + { + return; + } + if(!(qApp->mouseButtons() & Qt::LeftButton)) + { finishDrag(); return; } QPoint pos = QCursor::pos(); m_hoverArea = NULL; - ToolWindowManagerWrapper* hoverWrapper = NULL; + ToolWindowManagerWrapper *hoverWrapper = NULL; - foreach(ToolWindowManagerArea* area, m_areas) { + foreach(ToolWindowManagerArea *area, m_areas) + { // don't allow dragging a whole wrapper into a subset of itself - if (m_draggedWrapper && area->window() == m_draggedWrapper->window()) { + if(m_draggedWrapper && area->window() == m_draggedWrapper->window()) + { continue; } - if (area->rect().contains(area->mapFromGlobal(pos))) { + if(area->rect().contains(area->mapFromGlobal(pos))) + { m_hoverArea = area; break; } } - if (m_hoverArea == NULL) { - foreach(ToolWindowManagerWrapper* wrapper, m_wrappers) { + if(m_hoverArea == NULL) + { + foreach(ToolWindowManagerWrapper *wrapper, m_wrappers) + { // don't allow dragging a whole wrapper into a subset of itself - if (wrapper == m_draggedWrapper) { + if(wrapper == m_draggedWrapper) + { continue; } - if (wrapper->rect().contains(wrapper->mapFromGlobal(pos))) { + if(wrapper->rect().contains(wrapper->mapFromGlobal(pos))) + { hoverWrapper = wrapper; break; } @@ -695,36 +888,40 @@ void ToolWindowManager::updateDragPosition() { // if we found a wrapper and it's not empty, then we fill into a gap between two areas in a // splitter. Search down the hierarchy until we find a splitter whose handle intersects the // cursor and pick an area to map to. - if (hoverWrapper) { - QSplitter* splitter = qobject_cast(hoverWrapper->layout()->itemAt(0)->widget()); + if(hoverWrapper) + { + QSplitter *splitter = qobject_cast(hoverWrapper->layout()->itemAt(0)->widget()); - while (splitter) { - QSplitter* previous = splitter; + while(splitter) + { + QSplitter *previous = splitter; - for (int h=1; h < splitter->count(); h++) { - QSplitterHandle* handle = splitter->handle(h); + for(int h = 1; h < splitter->count(); h++) + { + QSplitterHandle *handle = splitter->handle(h); - if (handle->rect().contains(handle->mapFromGlobal(pos))) { - QWidget* a = splitter->widget(h); - QWidget* b = splitter->widget(h+1); + if(handle->rect().contains(handle->mapFromGlobal(pos))) + { + QWidget *a = splitter->widget(h); + QWidget *b = splitter->widget(h + 1); // try the first widget, if it's an area stop m_hoverArea = qobject_cast(a); - if (m_hoverArea) + if(m_hoverArea) break; // then the second widget m_hoverArea = qobject_cast(b); - if (m_hoverArea) + if(m_hoverArea) break; // neither widget is an area - let's search for a splitter to recurse to splitter = qobject_cast(a); - if (splitter) + if(splitter) break; splitter = qobject_cast(b); - if (splitter) + if(splitter) break; // neither side is an area or a splitter - should be impossible, but stop recursing @@ -738,14 +935,16 @@ void ToolWindowManager::updateDragPosition() { // if we still have a splitter, and didn't find an area, find which widget contains the // cursor and recurse to that splitter - if (previous == splitter && !m_hoverArea) + if(previous == splitter && !m_hoverArea) { - for (int w=0; w < splitter->count(); w++) { - QWidget* widget = splitter->widget(w); + for(int w = 0; w < splitter->count(); w++) + { + QWidget *widget = splitter->widget(w); - if (widget->rect().contains(widget->mapFromGlobal(pos))) { + if(widget->rect().contains(widget->mapFromGlobal(pos))) + { splitter = qobject_cast(widget); - if (splitter) + if(splitter) break; // if this isn't a splitter, and it's not an area (since that would have been found @@ -759,11 +958,11 @@ void ToolWindowManager::updateDragPosition() { } // we found an area to use! stop now - if (m_hoverArea) + if(m_hoverArea) break; // if we still haven't found anything, bail out - if (previous == splitter) + if(previous == splitter) { qWarning("Couldn't find cursor inside any child of wrapper"); splitter = NULL; @@ -774,24 +973,26 @@ void ToolWindowManager::updateDragPosition() { } } - if (m_hoverArea || hoverWrapper) { - ToolWindowManagerWrapper* wrapper = hoverWrapper; - if (m_hoverArea) - wrapper = findClosestParent(m_hoverArea); + if(m_hoverArea || hoverWrapper) + { + ToolWindowManagerWrapper *wrapper = hoverWrapper; + if(m_hoverArea) + wrapper = findClosestParent(m_hoverArea); QRect wrapperGeometry; wrapperGeometry.setSize(wrapper->rect().size()); - wrapperGeometry.moveTo(wrapper->mapToGlobal(QPoint(0,0))); + wrapperGeometry.moveTo(wrapper->mapToGlobal(QPoint(0, 0))); const int margin = m_dropHotspotMargin; const int size = m_dropHotspotDimension; const int hsize = size / 2; - if (m_hoverArea) { + if(m_hoverArea) + { QRect areaClientRect; // calculate the rect of the area - areaClientRect.setTopLeft(m_hoverArea->mapToGlobal(QPoint(0,0))); + areaClientRect.setTopLeft(m_hoverArea->mapToGlobal(QPoint(0, 0))); areaClientRect.setSize(m_hoverArea->rect().size()); // subtract the rect for the tab bar. @@ -802,16 +1003,16 @@ void ToolWindowManager::updateDragPosition() { m_dropHotspots[AddTo]->move(c + QPoint(-hsize, -hsize)); m_dropHotspots[AddTo]->show(); - m_dropHotspots[TopOf]->move(c + QPoint(-hsize, -hsize-margin-size)); + m_dropHotspots[TopOf]->move(c + QPoint(-hsize, -hsize - margin - size)); m_dropHotspots[TopOf]->show(); - m_dropHotspots[LeftOf]->move(c + QPoint(-hsize-margin-size, -hsize)); + m_dropHotspots[LeftOf]->move(c + QPoint(-hsize - margin - size, -hsize)); m_dropHotspots[LeftOf]->show(); - m_dropHotspots[RightOf]->move(c + QPoint( hsize+margin, -hsize)); + m_dropHotspots[RightOf]->move(c + QPoint(hsize + margin, -hsize)); m_dropHotspots[RightOf]->show(); - m_dropHotspots[BottomOf]->move(c + QPoint(-hsize, hsize+margin)); + m_dropHotspots[BottomOf]->move(c + QPoint(-hsize, hsize + margin)); m_dropHotspots[BottomOf]->show(); c = wrapperGeometry.center(); @@ -822,12 +1023,16 @@ void ToolWindowManager::updateDragPosition() { m_dropHotspots[LeftWindowSide]->move(QPoint(wrapperGeometry.x() + margin * 2, c.y() - hsize)); m_dropHotspots[LeftWindowSide]->show(); - m_dropHotspots[RightWindowSide]->move(QPoint(wrapperGeometry.right() - size - margin * 2, c.y() - hsize)); + m_dropHotspots[RightWindowSide]->move( + QPoint(wrapperGeometry.right() - size - margin * 2, c.y() - hsize)); m_dropHotspots[RightWindowSide]->show(); - m_dropHotspots[BottomWindowSide]->move(QPoint(c.x() - hsize, wrapperGeometry.bottom() - size - margin * 2)); + m_dropHotspots[BottomWindowSide]->move( + QPoint(c.x() - hsize, wrapperGeometry.bottom() - size - margin * 2)); m_dropHotspots[BottomWindowSide]->show(); - } else { + } + else + { m_dropHotspots[AddTo]->move(wrapperGeometry.center() + QPoint(-hsize, -hsize)); m_dropHotspots[AddTo]->show(); @@ -845,17 +1050,18 @@ void ToolWindowManager::updateDragPosition() { for(QWidget *hotspot : m_dropHotspots) if(hotspot) hotspot->show(); - } else { + } + else + { for(QWidget *hotspot : m_dropHotspots) if(hotspot) hotspot->hide(); } AreaReferenceType hotspot = currentHotspot(); - if ((m_hoverArea || hoverWrapper) && - (hotspot == AddTo || - hotspot == LeftOf || hotspot == RightOf || - hotspot == TopOf || hotspot == BottomOf)) { + if((m_hoverArea || hoverWrapper) && (hotspot == AddTo || hotspot == LeftOf || hotspot == RightOf || + hotspot == TopOf || hotspot == BottomOf)) + { QWidget *parent = m_hoverArea; if(parent == NULL) parent = hoverWrapper; @@ -863,26 +1069,28 @@ void ToolWindowManager::updateDragPosition() { QRect g = parent->geometry(); g.moveTopLeft(parent->parentWidget()->mapToGlobal(g.topLeft())); - if (hotspot == LeftOf) - g.adjust(0, 0, -g.width()/2, 0); - else if (hotspot == RightOf) - g.adjust(g.width()/2, 0, 0, 0); - else if (hotspot == TopOf) - g.adjust(0, 0, 0, -g.height()/2); - else if (hotspot == BottomOf) - g.adjust(0, g.height()/2, 0, 0); + if(hotspot == LeftOf) + g.adjust(0, 0, -g.width() / 2, 0); + else if(hotspot == RightOf) + g.adjust(g.width() / 2, 0, 0, 0); + else if(hotspot == TopOf) + g.adjust(0, 0, 0, -g.height() / 2); + else if(hotspot == BottomOf) + g.adjust(0, g.height() / 2, 0, 0); QRect tabGeom; - if (hotspot == AddTo && m_hoverArea && m_hoverArea->count() > 1) { - QTabBar* tb = m_hoverArea->tabBar(); + if(hotspot == AddTo && m_hoverArea && m_hoverArea->count() > 1) + { + QTabBar *tb = m_hoverArea->tabBar(); g.adjust(0, tb->rect().height(), 0, 0); int idx = tb->tabAt(tb->mapFromGlobal(pos)); - if (idx == -1) { - tabGeom = tb->tabRect(m_hoverArea->count()-1); - tabGeom.moveTo(tb->mapToGlobal(QPoint(0,0)) + tabGeom.topLeft()); + if(idx == -1) + { + tabGeom = tb->tabRect(m_hoverArea->count() - 1); + tabGeom.moveTo(tb->mapToGlobal(QPoint(0, 0)) + tabGeom.topLeft()); // move the tab one to the right, to indicate the tab is being added after the last one. tabGeom.moveLeft(tabGeom.left() + tabGeom.width()); @@ -890,52 +1098,61 @@ void ToolWindowManager::updateDragPosition() { // clamp from the right, to ensure we don't display any tab off the end of the range if(tabGeom.right() > g.right()) tabGeom.moveLeft(g.right() - tabGeom.width()); - } else { + } + else + { tabGeom = tb->tabRect(idx); - tabGeom.moveTo(tb->mapToGlobal(QPoint(0,0)) + tabGeom.topLeft()); + tabGeom.moveTo(tb->mapToGlobal(QPoint(0, 0)) + tabGeom.topLeft()); } } m_previewOverlay->setGeometry(g); m_previewTabOverlay->setGeometry(tabGeom); - } else if((m_hoverArea || hoverWrapper) && - (hotspot == LeftWindowSide || hotspot == RightWindowSide || - hotspot == TopWindowSide || hotspot == BottomWindowSide)) { - ToolWindowManagerWrapper* wrapper = hoverWrapper; - if (m_hoverArea) - wrapper = findClosestParent(m_hoverArea); + } + else if((m_hoverArea || hoverWrapper) && (hotspot == LeftWindowSide || hotspot == RightWindowSide || + hotspot == TopWindowSide || hotspot == BottomWindowSide)) + { + ToolWindowManagerWrapper *wrapper = hoverWrapper; + if(m_hoverArea) + wrapper = findClosestParent(m_hoverArea); QRect g; g.moveTopLeft(wrapper->mapToGlobal(QPoint())); g.setSize(wrapper->rect().size()); if(hotspot == LeftWindowSide) - g.adjust(0, 0, -(g.width()*5)/6, 0); + g.adjust(0, 0, -(g.width() * 5) / 6, 0); else if(hotspot == RightWindowSide) - g.adjust((g.width()*5)/6, 0, 0, 0); + g.adjust((g.width() * 5) / 6, 0, 0, 0); else if(hotspot == TopWindowSide) - g.adjust(0, 0, 0, -(g.height()*3)/4); + g.adjust(0, 0, 0, -(g.height() * 3) / 4); else if(hotspot == BottomWindowSide) - g.adjust(0, (g.height()*3)/4, 0, 0); + g.adjust(0, (g.height() * 3) / 4, 0, 0); m_previewOverlay->setGeometry(g); m_previewTabOverlay->setGeometry(QRect()); - } else { + } + else + { bool allowFloat = m_allowFloatingWindow; - for (QWidget *w : m_draggedToolWindows) + for(QWidget *w : m_draggedToolWindows) allowFloat &= !(toolWindowProperties(w) & DisallowFloatWindow); // no hotspot highlighted, draw geometry for a float window if previewing a tear-off, or draw // nothing if we're dragging a float window as it moves itself. // we also don't render any preview tear-off when floating windows are disallowed - if (m_draggedWrapper || !allowFloat) { + if(m_draggedWrapper || !allowFloat) + { m_previewOverlay->setGeometry(QRect()); - } else { + } + else + { QRect r; - for (QWidget *w : m_draggedToolWindows) { - if (w->isVisible()) + for(QWidget *w : m_draggedToolWindows) + { + if(w->isVisible()) r = r.united(w->rect()); } m_previewOverlay->setGeometry(pos.x(), pos.y(), r.width(), r.height()); @@ -950,8 +1167,9 @@ void ToolWindowManager::updateDragPosition() { h->raise(); } -void ToolWindowManager::abortDrag() { - if (!dragInProgress()) +void ToolWindowManager::abortDrag() +{ + if(!dragInProgress()) return; m_previewOverlay->hide(); @@ -964,8 +1182,10 @@ void ToolWindowManager::abortDrag() { qApp->removeEventFilter(this); } -void ToolWindowManager::finishDrag() { - if (!dragInProgress()) { +void ToolWindowManager::finishDrag() +{ + if(!dragInProgress()) + { qWarning("unexpected finishDrag"); return; } @@ -973,7 +1193,7 @@ void ToolWindowManager::finishDrag() { // move these locally to prevent re-entrancy QList draggedToolWindows = m_draggedToolWindows; - ToolWindowManagerWrapper* draggedWrapper = m_draggedWrapper; + ToolWindowManagerWrapper *draggedWrapper = m_draggedWrapper; m_draggedToolWindows.clear(); m_draggedWrapper = NULL; @@ -986,19 +1206,23 @@ void ToolWindowManager::finishDrag() { if(h) h->hide(); - if (hotspot == NewFloatingArea) { - // check if we're dragging a whole float window, if so we don't do anything as it's already moved - if (!draggedWrapper) { + if(hotspot == NewFloatingArea) + { + // check if we're dragging a whole float window, if so we don't do anything as it's already + // moved + if(!draggedWrapper) + { bool allowFloat = m_allowFloatingWindow; - for (QWidget *w : draggedToolWindows) + for(QWidget *w : draggedToolWindows) allowFloat &= !(toolWindowProperties(w) & DisallowFloatWindow); - if (allowFloat) + if(allowFloat) { QRect r; - for (QWidget *w : draggedToolWindows) { - if (w->isVisible()) + for(QWidget *w : draggedToolWindows) + { + if(w->isVisible()) r = r.united(w->rect()); } @@ -1009,20 +1233,28 @@ void ToolWindowManager::finishDrag() { area->parentWidget()->resize(r.size()); } } - } else { - if (m_hoverArea) { + } + else + { + if(m_hoverArea) + { AreaReference ref(hotspot, m_hoverArea); ref.dragResult = true; moveToolWindows(draggedToolWindows, ref); - } else { + } + else + { moveToolWindows(draggedToolWindows, AreaReference(EmptySpace)); } } } -void ToolWindowManager::drawHotspotPixmaps() { - for (AreaReferenceType ref : { AddTo, LeftOf, TopOf, RightOf, BottomOf }) { - m_pixmaps[ref] = QPixmap(m_dropHotspotDimension*devicePixelRatio(), m_dropHotspotDimension*devicePixelRatio()); +void ToolWindowManager::drawHotspotPixmaps() +{ + for(AreaReferenceType ref : {AddTo, LeftOf, TopOf, RightOf, BottomOf}) + { + m_pixmaps[ref] = QPixmap(m_dropHotspotDimension * devicePixelRatio(), + m_dropHotspotDimension * devicePixelRatio()); m_pixmaps[ref].setDevicePixelRatio(devicePixelRatioF()); QPainter p(&m_pixmaps[ref]); @@ -1044,13 +1276,13 @@ void ToolWindowManager::drawHotspotPixmaps() { QRectF fullRect = rect; - if (ref == LeftOf) + if(ref == LeftOf) rect = rect.marginsAdded(QMarginsF(0, 0, -12, 0)); - else if (ref == TopOf) + else if(ref == TopOf) rect = rect.marginsAdded(QMarginsF(0, 0, 0, -12)); - else if (ref == RightOf) + else if(ref == RightOf) rect = rect.marginsAdded(QMarginsF(-12, 0, 0, 0)); - else if (ref == BottomOf) + else if(ref == BottomOf) rect = rect.marginsAdded(QMarginsF(0, -12, 0, 0)); p.setPen(QPen(QBrush(Qt::black), 1.0)); @@ -1062,37 +1294,41 @@ void ToolWindowManager::drawHotspotPixmaps() { p.fillRect(rect, Qt::SolidPattern); // for the sides, add an arrow. - if (ref != AddTo) { + if(ref != AddTo) + { QPainterPath path; - if (ref == LeftOf) { - QPointF tip = fullRect.center() + QPointF( 4, 0); + if(ref == LeftOf) + { + QPointF tip = fullRect.center() + QPointF(4, 0); - path.addPolygon(QPolygonF({tip, - tip + QPoint( 3, 3), - tip + QPoint( 3, -3), - })); - } else if (ref == TopOf) { - QPointF tip = fullRect.center() + QPointF( 0, 4); + path.addPolygon(QPolygonF({ + tip, tip + QPoint(3, 3), tip + QPoint(3, -3), + })); + } + else if(ref == TopOf) + { + QPointF tip = fullRect.center() + QPointF(0, 4); - path.addPolygon(QPolygonF({tip, - tip + QPointF(-3, 3), - tip + QPointF( 3, 3), - })); - } else if (ref == RightOf) { - QPointF tip = fullRect.center() + QPointF(-4, 0); + path.addPolygon(QPolygonF({ + tip, tip + QPointF(-3, 3), tip + QPointF(3, 3), + })); + } + else if(ref == RightOf) + { + QPointF tip = fullRect.center() + QPointF(-4, 0); - path.addPolygon(QPolygonF({tip, - tip + QPointF(-3, 3), - tip + QPointF(-3, -3), - })); - } else if (ref == BottomOf) { - QPointF tip = fullRect.center() + QPointF( 0, -4); + path.addPolygon(QPolygonF({ + tip, tip + QPointF(-3, 3), tip + QPointF(-3, -3), + })); + } + else if(ref == BottomOf) + { + QPointF tip = fullRect.center() + QPointF(0, -4); - path.addPolygon(QPolygonF({tip, - tip + QPointF(-3, -3), - tip + QPointF( 3, -3), - })); + path.addPolygon(QPolygonF({ + tip, tip + QPointF(-3, -3), tip + QPointF(3, -3), + })); } p.fillPath(path, QBrush(Qt::black)); @@ -1106,50 +1342,65 @@ void ToolWindowManager::drawHotspotPixmaps() { m_pixmaps[BottomWindowSide] = m_pixmaps[BottomOf]; } -ToolWindowManager::AreaReferenceType ToolWindowManager::currentHotspot() { +ToolWindowManager::AreaReferenceType ToolWindowManager::currentHotspot() +{ QPoint pos = QCursor::pos(); - for (int i=0; i < NumReferenceTypes; i++) { - if (m_dropHotspots[i] && m_dropHotspots[i]->isVisible() && - m_dropHotspots[i]->geometry().contains(pos)) { + for(int i = 0; i < NumReferenceTypes; i++) + { + if(m_dropHotspots[i] && m_dropHotspots[i]->isVisible() && + m_dropHotspots[i]->geometry().contains(pos)) + { return (ToolWindowManager::AreaReferenceType)i; } } - if (m_hoverArea) { - QTabBar* tb = m_hoverArea->tabBar(); - if (tb->rect().contains(tb->mapFromGlobal(QCursor::pos()))) + if(m_hoverArea) + { + QTabBar *tb = m_hoverArea->tabBar(); + if(tb->rect().contains(tb->mapFromGlobal(QCursor::pos()))) return AddTo; } return NewFloatingArea; } -bool ToolWindowManager::eventFilter(QObject *object, QEvent *event) { - if (event->type() == QEvent::MouseButtonRelease) { +bool ToolWindowManager::eventFilter(QObject *object, QEvent *event) +{ + if(event->type() == QEvent::MouseButtonRelease) + { // right clicking aborts any drag in progress - if (static_cast(event)->button() == Qt::RightButton) + if(static_cast(event)->button() == Qt::RightButton) abortDrag(); - } else if (event->type() == QEvent::KeyPress) { + } + else if(event->type() == QEvent::KeyPress) + { // pressing escape any drag in progress QKeyEvent *ke = (QKeyEvent *)event; - if(ke->key() == Qt::Key_Escape) { + if(ke->key() == Qt::Key_Escape) + { abortDrag(); } } return QWidget::eventFilter(object, event); } -bool ToolWindowManager::allowClose(QWidget *toolWindow) { - if (!m_toolWindows.contains(toolWindow)) { +bool ToolWindowManager::allowClose(QWidget *toolWindow) +{ + if(!m_toolWindows.contains(toolWindow)) + { qWarning("unknown tool window"); return true; } - int methodIndex = toolWindow->metaObject()->indexOfMethod(QMetaObject::normalizedSignature("checkAllowClose()")); + int methodIndex = toolWindow->metaObject()->indexOfMethod( + QMetaObject::normalizedSignature("checkAllowClose()")); - if(methodIndex >= 0) { + if(methodIndex >= 0) + { bool ret = true; - toolWindow->metaObject()->method(methodIndex).invoke(toolWindow, Qt::DirectConnection, Q_RETURN_ARG(bool, ret)); + toolWindow->metaObject() + ->method(methodIndex) + .invoke(toolWindow, Qt::DirectConnection, Q_RETURN_ARG(bool, ret)); return ret; } @@ -1157,19 +1408,22 @@ bool ToolWindowManager::allowClose(QWidget *toolWindow) { return true; } -void ToolWindowManager::tabCloseRequested(int index) { - ToolWindowManagerArea* tabWidget = qobject_cast(sender()); - if (!tabWidget) { +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)) { + QWidget *toolWindow = tabWidget->widget(index); + if(!m_toolWindows.contains(toolWindow)) + { qWarning("unknown tab in tab widget"); return; } - if (!allowClose(toolWindow)) + if(!allowClose(toolWindow)) return; if(toolWindowProperties(toolWindow) & ToolWindowManager::HideOnClose) @@ -1178,57 +1432,76 @@ void ToolWindowManager::tabCloseRequested(int index) { removeToolWindow(toolWindow); } -void ToolWindowManager::windowTitleChanged(const QString &) { - QWidget* toolWindow = qobject_cast(sender()); - if(!toolWindow) { +void ToolWindowManager::windowTitleChanged(const QString &) +{ + QWidget *toolWindow = qobject_cast(sender()); + if(!toolWindow) + { return; } ToolWindowManagerArea *area = areaOf(toolWindow); - if(area) { + if(area) + { area->updateToolWindow(toolWindow); } } -QSplitter *ToolWindowManager::createSplitter() { - QSplitter* splitter = new ToolWindowManagerSplitter(); +QSplitter *ToolWindowManager::createSplitter() +{ + QSplitter *splitter = new ToolWindowManagerSplitter(); splitter->setChildrenCollapsible(false); return splitter; } -ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, ToolWindowManagerArea *area, float percentage) { +ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, + ToolWindowManagerArea *area, float percentage) +{ m_type = type; m_percentage = percentage; dragResult = false; setWidget(area); } -void ToolWindowManager::AreaReference::setWidget(QWidget *widget) { - if (m_type == LastUsedArea || m_type == NewFloatingArea || m_type == NoArea || m_type == EmptySpace) { - if (widget != 0) { +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) { + } + 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)) { + } + else + { + if(!qobject_cast(widget) && !qobject_cast(widget)) + { qWarning("only ToolWindowManagerArea or splitter can be used with this type"); m_widget = 0; - } else { + } + else + { m_widget = widget; } } } -ToolWindowManagerArea *ToolWindowManager::AreaReference::area() const { - return qobject_cast(m_widget); +ToolWindowManagerArea *ToolWindowManager::AreaReference::area() const +{ + return qobject_cast(m_widget); } -ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, QWidget *widget) { +ToolWindowManager::AreaReference::AreaReference(ToolWindowManager::AreaReferenceType type, + QWidget *widget) +{ m_type = type; dragResult = false; setWidget(widget); diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h index 76522f7c5..ef58428d6 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManager.h @@ -25,10 +25,10 @@ #ifndef TOOLWINDOWMANAGER_H #define TOOLWINDOWMANAGER_H -#include #include -#include #include +#include +#include #include @@ -48,7 +48,8 @@ class QSplitter; * * See https://github.com/Riateche/toolwindowmanager for detailed description. */ -class ToolWindowManager : public QWidget { +class ToolWindowManager : public QWidget +{ Q_OBJECT /*! * \brief Whether or not to allow floating windows to be created. @@ -92,7 +93,8 @@ public: virtual ~ToolWindowManager(); //! Toolwindow properties - enum ToolWindowProperty { + enum ToolWindowProperty + { //! Disables all drag/docking ability by the user DisallowUserDocking = 0x1, //! Hides the close button on the tab for this tool window @@ -108,7 +110,8 @@ public: }; //! Type of AreaReference. - enum AreaReferenceType { + enum AreaReferenceType + { //! The area tool windows has been added to most recently. LastUsedArea, //! New area in a detached window. @@ -142,47 +145,50 @@ public: /*! * \brief The AreaReference class represents a place where tool windows should be moved. */ - class AreaReference { + 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). + * area, it should be given in \a area argument. Otherwise \a area should have default value + * (0). */ - AreaReference(AreaReferenceType type = NoArea, ToolWindowManagerArea* area = 0, float percentage = 0.5f); + AreaReference(AreaReferenceType type = NoArea, ToolWindowManagerArea *area = 0, + float percentage = 0.5f); //! 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; + ToolWindowManagerArea *area() const; private: AreaReferenceType m_type; - QWidget* m_widget; + QWidget *m_widget; float m_percentage; bool dragResult; - QWidget* widget() const { return m_widget; } + QWidget *widget() const { return m_widget; } float percentage() const { return m_percentage; } - AreaReference(AreaReferenceType type, QWidget* widget); - void setWidget(QWidget* 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); + void addToolWindow(QWidget *toolWindow, const AreaReference &area, + ToolWindowProperty properties = ToolWindowProperty(0)); /*! * Sets the set of \a properties on \a toolWindow that is already added to the manager. */ - void setToolWindowProperties(QWidget* toolWindow, ToolWindowProperty properties); + void setToolWindowProperties(QWidget *toolWindow, ToolWindowProperty properties); /*! * Returns the set of \a properties on \a toolWindow. */ - ToolWindowProperty toolWindowProperties(QWidget* toolWindow); + ToolWindowProperty toolWindowProperties(QWidget *toolWindow); /*! * \brief Adds \a toolWindows to the manager and moves it to the position specified by @@ -196,46 +202,50 @@ public: * 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); + void addToolWindows(QList toolWindows, const AreaReference &area, + ToolWindowProperty properties = ToolWindowProperty(0)); /*! * Returns area that contains \a toolWindow, or 0 if \a toolWindow is hidden. */ - ToolWindowManagerArea* areaOf(QWidget* toolWindow); + 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); + 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); + 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); + void removeToolWindow(QWidget *toolWindow); + + /*! + * Returns if \a toolWindow is floating instead of being docked. + */ + bool isFloating(QWidget *toolWindow); /*! * \brief Returns all tool window added to the manager. */ - const QList& toolWindows() { return m_toolWindows; } - + 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); } - - static ToolWindowManager* managerOf(QWidget* toolWindow); + void hideToolWindow(QWidget *toolWindow) { moveToolWindow(toolWindow, NoArea); } + static ToolWindowManager *managerOf(QWidget *toolWindow); static void closeToolWindow(QWidget *toolWindow); static void raiseToolWindow(QWidget *toolWindow); @@ -247,56 +257,53 @@ public: /*! * \brief restoreState */ - void restoreState(const QVariantMap& data); + void restoreState(const QVariantMap &data); - typedef std::function CreateCallback; + typedef std::function CreateCallback; void setToolWindowCreateCallback(const CreateCallback &cb) { m_createCallback = cb; } - QWidget *createToolWindow(const QString& objectName); + QWidget *createToolWindow(const QString &objectName); void setHotspotPixmap(AreaReferenceType ref, const QPixmap &pix) { m_pixmaps[ref] = pix; } - void setDropHotspotMargin(int pixels); bool dropHotspotMargin() { return m_dropHotspotMargin; } - void setDropHotspotDimension(int pixels); bool dropHotspotDimension() { return m_dropHotspotDimension; } - /*! \cond PRIVATE */ void setAllowFloatingWindow(bool pixels); bool allowFloatingWindow() { return m_allowFloatingWindow; } /*! \endcond */ - 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); + void toolWindowVisibilityChanged(QWidget *toolWindow, bool visible); 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 + 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 // list of tool windows that are currently dragged, or empty list if there is no current drag - QList m_draggedToolWindows; - ToolWindowManagerWrapper* m_draggedWrapper; // the wrapper if a whole float window is being dragged - ToolWindowManagerArea* m_hoverArea; // the area currently being hovered over in a drag + QList m_draggedToolWindows; + ToolWindowManagerWrapper + *m_draggedWrapper; // the wrapper if a whole float window is being dragged + ToolWindowManagerArea *m_hoverArea; // the area currently being hovered over in a drag // a semi-transparent preview of where the dragged toolwindow(s) will be docked - QWidget* m_previewOverlay; - QWidget* m_previewTabOverlay; - QLabel* m_dropHotspots[NumReferenceTypes]; + QWidget *m_previewOverlay; + QWidget *m_previewTabOverlay; + QLabel *m_dropHotspots[NumReferenceTypes]; QPixmap m_pixmaps[NumReferenceTypes]; - bool m_allowFloatingWindow; // Allow floating windows from this docking area - int m_dropHotspotMargin; // The pixels between drop hotspot icons - int m_dropHotspotDimension; // The pixel dimension of the hotspot icons + bool m_allowFloatingWindow; // Allow floating windows from this docking area + int m_dropHotspotMargin; // The pixels between drop hotspot icons + int m_dropHotspotDimension; // The pixel dimension of the hotspot icons CreateCallback m_createCallback; - ToolWindowManagerWrapper* wrapperOf(QWidget* toolWindow); + ToolWindowManagerWrapper *wrapperOf(QWidget *toolWindow); void drawHotspotPixmaps(); @@ -304,14 +311,14 @@ private: // last widget used for adding tool windows, or 0 if there isn't one // (warning: may contain pointer to deleted object) - ToolWindowManagerArea* m_lastUsedArea; - //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, ToolWindowManagerWrapper *wrapper); + ToolWindowManagerArea *m_lastUsedArea; + // 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, ToolWindowManagerWrapper *wrapper); - QVariantMap saveSplitterState(QSplitter* splitter); - QSplitter* restoreSplitterState(const QVariantMap& data); + QVariantMap saveSplitterState(QSplitter *splitter); + QSplitter *restoreSplitterState(const QVariantMap &data); AreaReferenceType currentHotspot(); @@ -319,7 +326,6 @@ private: void abortDrag(); void finishDrag(); bool dragInProgress() { return !m_draggedToolWindows.isEmpty(); } - friend class ToolWindowManagerArea; friend class ToolWindowManagerWrapper; @@ -331,7 +337,7 @@ 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(); + 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. @@ -341,10 +347,12 @@ protected: private slots: 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)); } +inline ToolWindowManager::ToolWindowProperty operator|(ToolWindowManager::ToolWindowProperty a, + ToolWindowManager::ToolWindowProperty b) +{ + return ToolWindowManager::ToolWindowProperty(int(a) | int(b)); +} -#endif // TOOLWINDOWMANAGER_H +#endif // TOOLWINDOWMANAGER_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp index e6213901e..006af2485 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.cpp @@ -23,14 +23,15 @@ * */ #include "ToolWindowManagerArea.h" -#include "ToolWindowManagerTabBar.h" -#include "ToolWindowManagerWrapper.h" -#include "ToolWindowManager.h" #include #include #include +#include "ToolWindowManager.h" +#include "ToolWindowManagerTabBar.h" +#include "ToolWindowManagerWrapper.h" -static void showCloseButton(QTabBar *bar, int index, bool show) { +static void showCloseButton(QTabBar *bar, int index, bool show) +{ QWidget *button = bar->tabButton(index, QTabBar::RightSide); if(button == NULL) button = bar->tabButton(index, QTabBar::LeftSide); @@ -39,9 +40,8 @@ static void showCloseButton(QTabBar *bar, int index, bool show) { button->resize(show ? QSize(16, 16) : QSize(0, 0)); } -ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget *parent) : - QTabWidget(parent) -, m_manager(manager) +ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget *parent) + : QTabWidget(parent), m_manager(manager) { m_tabBar = new ToolWindowManagerTabBar(this); setTabBar(m_tabBar); @@ -63,110 +63,145 @@ ToolWindowManagerArea::ToolWindowManagerArea(ToolWindowManager *manager, QWidget QObject::connect(this, &QTabWidget::currentChanged, this, &ToolWindowManagerArea::tabSelected); } -ToolWindowManagerArea::~ToolWindowManagerArea() { +ToolWindowManagerArea::~ToolWindowManagerArea() +{ m_manager->m_areas.removeOne(this); } -void ToolWindowManagerArea::addToolWindow(QWidget *toolWindow, int insertIndex) { - addToolWindows(QList() << toolWindow, insertIndex); +void ToolWindowManagerArea::addToolWindow(QWidget *toolWindow, int insertIndex) +{ + addToolWindows(QList() << toolWindow, insertIndex); } -void ToolWindowManagerArea::addToolWindows(const QList &toolWindows, int insertIndex) { +void ToolWindowManagerArea::addToolWindows(const QList &toolWindows, int insertIndex) +{ int index = 0; - foreach(QWidget* toolWindow, toolWindows) { + foreach(QWidget *toolWindow, toolWindows) + { index = insertTab(insertIndex, toolWindow, toolWindow->windowIcon(), toolWindow->windowTitle()); - insertIndex = index+1; + insertIndex = index + 1; } setCurrentIndex(index); - for (int i=0; i < count(); i++) { + for(int i = 0; i < count(); i++) + { updateToolWindow(widget(i)); } m_manager->m_lastUsedArea = this; } -QList ToolWindowManagerArea::toolWindows() { +QList ToolWindowManagerArea::toolWindows() +{ QList result; - for(int i = 0; i < count(); i++) { + for(int i = 0; i < count(); i++) + { result << widget(i); } return result; } -void ToolWindowManagerArea::updateToolWindow(QWidget* toolWindow) { +void ToolWindowManagerArea::updateToolWindow(QWidget *toolWindow) +{ int index = indexOf(toolWindow); - if(index >= 0) { - if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) { + if(index >= 0) + { + ToolWindowManagerTabBar *tb = static_cast(tabBar()); + if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideCloseButton) + { + tb->setTabsClosable(false); showCloseButton(tabBar(), index, false); - } else { + } + else + { + tb->setTabsClosable(true); showCloseButton(tabBar(), index, true); } tabBar()->setTabText(index, toolWindow->windowTitle()); } } -void ToolWindowManagerArea::mouseMoveEvent(QMouseEvent *) { +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) { - - QPoint pos = static_cast(event)->pos(); +bool ToolWindowManagerArea::eventFilter(QObject *object, QEvent *event) +{ + if(object == tabBar()) + { + if(event->type() == QEvent::MouseButtonPress && qApp->mouseButtons() == Qt::LeftButton) + { + QPoint pos = static_cast(event)->pos(); int tabIndex = tabBar()->tabAt(pos); // can start tab drag only if mouse is at some tab, not at empty tabbar space - if (tabIndex >= 0) { + if(tabIndex >= 0) + { m_tabDragCanStart = true; - if (m_manager->toolWindowProperties(widget(tabIndex)) & ToolWindowManager::DisableDraggableTab) { + if(m_manager->toolWindowProperties(widget(tabIndex)) & ToolWindowManager::DisableDraggableTab) + { setMovable(false); - } else { + } + else + { setMovable(true); } - } else if (m_tabBar == NULL || !m_tabBar->inButton(pos)) { + } + else if(m_tabBar == NULL || !m_tabBar->inButton(pos)) + { m_dragCanStart = true; m_dragCanStartPos = QCursor::pos(); } - } else if (event->type() == QEvent::MouseButtonPress && - qApp->mouseButtons() == Qt::MiddleButton) { + } + else if(event->type() == QEvent::MouseButtonPress && qApp->mouseButtons() == Qt::MiddleButton) + { + int tabIndex = tabBar()->tabAt(static_cast(event)->pos()); - int tabIndex = tabBar()->tabAt(static_cast(event)->pos()); - - if(tabIndex >= 0) { + if(tabIndex >= 0) + { QWidget *w = widget(tabIndex); - if(!(m_manager->toolWindowProperties(w) & ToolWindowManager::HideCloseButton)) { + if(!(m_manager->toolWindowProperties(w) & ToolWindowManager::HideCloseButton)) + { emit tabCloseRequested(tabIndex); } } - } else if (event->type() == QEvent::MouseButtonRelease) { + } + else if(event->type() == QEvent::MouseButtonRelease) + { m_tabDragCanStart = false; m_dragCanStart = false; m_manager->updateDragPosition(); - } else if (event->type() == QEvent::MouseMove) { + } + else if(event->type() == QEvent::MouseMove) + { m_manager->updateDragPosition(); - if (m_tabDragCanStart) { - if (tabBar()->rect().contains(static_cast(event)->pos())) { + if(m_tabDragCanStart) + { + if(tabBar()->rect().contains(static_cast(event)->pos())) + { return false; } - if (qApp->mouseButtons() != Qt::LeftButton) { + if(qApp->mouseButtons() != Qt::LeftButton) + { return false; } - QWidget* toolWindow = currentWidget(); - if (!toolWindow || !m_manager->m_toolWindows.contains(toolWindow)) { + 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); + // 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, NULL); - } else if (m_dragCanStart) { + m_manager->startDrag(QList() << toolWindow, NULL); + } + else if(m_dragCanStart) + { check_mouse_move(); } } @@ -174,78 +209,90 @@ bool ToolWindowManagerArea::eventFilter(QObject *object, QEvent *event) { return QTabWidget::eventFilter(object, event); } -void ToolWindowManagerArea::tabInserted(int index) { +void ToolWindowManagerArea::tabInserted(int index) +{ // update the select order. Increment any existing index after the insertion point to keep the // indices in the list up to date. - for (int &idx : m_tabSelectOrder) { - if (idx >= index) + for(int &idx : m_tabSelectOrder) + { + if(idx >= index) idx++; } // if the tab inserted is the current index (most likely) then add it at the end, otherwise // add it next-to-end (to keep the most recent tab the same). - if (currentIndex() == index || m_tabSelectOrder.isEmpty()) + if(currentIndex() == index || m_tabSelectOrder.isEmpty()) m_tabSelectOrder.append(index); else - m_tabSelectOrder.insert(m_tabSelectOrder.count()-1, index); + m_tabSelectOrder.insert(m_tabSelectOrder.count() - 1, index); QTabWidget::tabInserted(index); } -void ToolWindowManagerArea::tabRemoved(int index) { +void ToolWindowManagerArea::tabRemoved(int index) +{ // update the select order. Remove the index that just got deleted, and decrement any index // greater than it to remap to their new indices m_tabSelectOrder.removeOne(index); - for (int &idx : m_tabSelectOrder) { - if (idx > index) + for(int &idx : m_tabSelectOrder) + { + if(idx > index) idx--; } QTabWidget::tabRemoved(index); } -void ToolWindowManagerArea::tabSelected(int index) { +void ToolWindowManagerArea::tabSelected(int index) +{ // move this tab to the end of the select order, as long as we have it - if it's a new index then // ignore and leave it to be handled in tabInserted() - if (m_tabSelectOrder.contains(index)) { + if(m_tabSelectOrder.contains(index)) + { m_tabSelectOrder.removeOne(index); m_tabSelectOrder.append(index); } - ToolWindowManagerWrapper* wrapper = m_manager->wrapperOf(this); - if (wrapper) + ToolWindowManagerWrapper *wrapper = m_manager->wrapperOf(this); + if(wrapper) wrapper->updateTitle(); } -void ToolWindowManagerArea::tabClosing(int index) { +void ToolWindowManagerArea::tabClosing(int index) +{ // before closing this index, switch the current index to the next tab in succession. // should never get here but let's check this - if (m_tabSelectOrder.isEmpty()) + if(m_tabSelectOrder.isEmpty()) return; // when closing the last tab there's nothing to do - if (m_tabSelectOrder.count() == 1) + if(m_tabSelectOrder.count() == 1) return; // if the last in the select order is being closed, switch to the next most selected tab - if (m_tabSelectOrder.last() == index) - setCurrentIndex(m_tabSelectOrder.at(m_tabSelectOrder.count()-2)); + if(m_tabSelectOrder.last() == index) + setCurrentIndex(m_tabSelectOrder.at(m_tabSelectOrder.count() - 2)); } -QVariantMap ToolWindowManagerArea::saveState() { +QVariantMap ToolWindowManagerArea::saveState() +{ QVariantMap result; result[QStringLiteral("type")] = QStringLiteral("area"); result[QStringLiteral("currentIndex")] = currentIndex(); QVariantList objects; objects.reserve(count()); - for(int i = 0; i < count(); i++) { + for(int i = 0; i < count(); i++) + { QWidget *w = widget(i); QString name = w->objectName(); - if (name.isEmpty()) { + if(name.isEmpty()) + { qWarning("cannot save state of tool window without object name"); - } else { + } + else + { QVariantMap objectData; objectData[QStringLiteral("name")] = name; objectData[QStringLiteral("data")] = w->property("persistData"); @@ -256,44 +303,65 @@ QVariantMap ToolWindowManagerArea::saveState() { return result; } -void ToolWindowManagerArea::restoreState(const QVariantMap &savedData) { - for(QVariant object : savedData[QStringLiteral("objects")].toList()) { +void ToolWindowManagerArea::restoreState(const QVariantMap &savedData) +{ + for(QVariant object : savedData[QStringLiteral("objects")].toList()) + { QVariantMap objectData = object.toMap(); - if (objectData.isEmpty()) { continue; } + if(objectData.isEmpty()) + { + continue; + } QString objectName = objectData[QStringLiteral("name")].toString(); - if (objectName.isEmpty()) { continue; } + if(objectName.isEmpty()) + { + continue; + } QWidget *t = NULL; - for(QWidget* toolWindow : m_manager->m_toolWindows) { - if (toolWindow->objectName() == objectName) { + for(QWidget *toolWindow : m_manager->m_toolWindows) + { + if(toolWindow->objectName() == objectName) + { t = toolWindow; break; } } - if (t == NULL) t = m_manager->createToolWindow(objectName); - if (t) { - t->setProperty("persistData", objectData[QStringLiteral("data")]); - addToolWindow(t); - } else { - qWarning("tool window with name '%s' not found or created", objectName.toLocal8Bit().constData()); + if(t == NULL) + t = m_manager->createToolWindow(objectName); + if(t) + { + t->setProperty("persistData", objectData[QStringLiteral("data")]); + addToolWindow(t); + } + else + { + qWarning("tool window with name '%s' not found or created", + objectName.toLocal8Bit().constData()); } } setCurrentIndex(savedData[QStringLiteral("currentIndex")].toInt()); } -void ToolWindowManagerArea::check_mouse_move() { - if (qApp->mouseButtons() != Qt::LeftButton && m_dragCanStart) { +void ToolWindowManagerArea::check_mouse_move() +{ + if(qApp->mouseButtons() != Qt::LeftButton && m_dragCanStart) + { m_dragCanStart = false; } m_manager->updateDragPosition(); - if (m_dragCanStart && - (QCursor::pos() - m_dragCanStartPos).manhattanLength() > 10) { + if(m_dragCanStart && (QCursor::pos() - m_dragCanStartPos).manhattanLength() > 10) + { m_dragCanStart = false; - QList toolWindows; - for(int i = 0; i < count(); i++) { - QWidget* toolWindow = widget(i); - if (!m_manager->m_toolWindows.contains(toolWindow)) { + 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 { + } + else + { toolWindows << toolWindow; } } @@ -301,32 +369,37 @@ void ToolWindowManagerArea::check_mouse_move() { } } -bool ToolWindowManagerArea::useMinimalTabBar() { +bool ToolWindowManagerArea::useMinimalTabBar() +{ QWidget *w = widget(0); - if (w == NULL) + if(w == NULL) return false; return (m_manager->toolWindowProperties(w) & ToolWindowManager::AlwaysDisplayFullTabs) == 0; } -void ToolWindowManagerArea::tabMoved(int from, int to) { - if(m_inTabMoved) return; +void ToolWindowManagerArea::tabMoved(int from, int to) +{ + if(m_inTabMoved) + return; // update the select order. // This amounts to just a swap - any indices other than the pair in question are unaffected since // one tab is removed (above/below) and added (below/above) so the indices themselves remain the // same. - for (int &idx : m_tabSelectOrder) { - if (idx == from) + for(int &idx : m_tabSelectOrder) + { + if(idx == from) idx = to; - else if (idx == to) + else if(idx == to) idx = from; } QWidget *a = widget(from); QWidget *b = widget(to); - if(!a || !b) return; + if(!a || !b) + return; if(m_manager->toolWindowProperties(a) & ToolWindowManager::DisableDraggableTab || m_manager->toolWindowProperties(b) & ToolWindowManager::DisableDraggableTab) diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h index c9b3fe822..9b26958c6 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerArea.h @@ -35,40 +35,38 @@ class ToolWindowManagerTabBar; * \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 { +class ToolWindowManagerArea : public QTabWidget +{ Q_OBJECT public: //! Creates new area. - explicit ToolWindowManagerArea(ToolWindowManager* manager, QWidget *parent = 0); + explicit ToolWindowManagerArea(ToolWindowManager *manager, QWidget *parent = 0); //! Destroys the area. virtual ~ToolWindowManagerArea(); /*! * Add \a toolWindow to this area. */ - void addToolWindow(QWidget* toolWindow, int insertIndex = -1); + void addToolWindow(QWidget *toolWindow, int insertIndex = -1); /*! * Add \a toolWindows to this area. */ - void addToolWindows(const QList& toolWindows, int insertIndex = -1); + void addToolWindows(const QList &toolWindows, int insertIndex = -1); void enableUserDrop() { m_userCanDrop = true; } void disableUserDrop() { m_userCanDrop = false; } - bool allowUserDrop() { return m_userCanDrop; } - /*! * Returns a list of all tool windows in this area. */ - QList toolWindows(); - - ToolWindowManager* manager() { return m_manager; } + QList toolWindows(); + ToolWindowManager *manager() { return m_manager; } /*! * Updates the \a toolWindow to its current properties and title. */ - void updateToolWindow(QWidget* toolWindow); + void updateToolWindow(QWidget *toolWindow); protected: //! Reimplemented from QTabWidget::mouseMoveEvent. @@ -82,30 +80,31 @@ protected: virtual void tabRemoved(int index); private: - ToolWindowManager* m_manager; - ToolWindowManagerTabBar* m_tabBar; - 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 - QPoint m_dragCanStartPos; // the position the cursor was at + ToolWindowManager *m_manager; + ToolWindowManagerTabBar *m_tabBar; + 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 + QPoint m_dragCanStartPos; // the position the cursor was at - 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 + 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 - bool m_userCanDrop; // indictes the user is allowed to drop things on this area + bool m_userCanDrop; // indictes the user is allowed to drop things on this 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) + 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) - QVector m_tabSelectOrder; // This is the 'history' order of the tabs as they were selected, - // with most recently selected index last. Any time a tab is closed - // we select the last one on the list. + QVector + m_tabSelectOrder; // This is the 'history' order of the tabs as they were selected, + // with most recently selected index last. Any time a tab is closed + // we select the last one on the list. - QVariantMap saveState(); // dump contents to variable - void restoreState(const QVariantMap& data); //restore contents from given variable + 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 + // check if mouse left tab widget area so that dragging should start void check_mouse_move(); bool useMinimalTabBar(); @@ -120,4 +119,4 @@ private slots: void tabClosing(int index); }; -#endif // TOOLWINDOWMANAGERAREA_H +#endif // TOOLWINDOWMANAGERAREA_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.cpp index 7b5e0ab77..98400a23c 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.cpp @@ -26,45 +26,52 @@ #include #include -ToolWindowManagerSplitter::ToolWindowManagerSplitter(QWidget *parent) : - QSplitter(parent) +ToolWindowManagerSplitter::ToolWindowManagerSplitter(QWidget *parent) : QSplitter(parent) { } -ToolWindowManagerSplitter::~ToolWindowManagerSplitter() { +ToolWindowManagerSplitter::~ToolWindowManagerSplitter() +{ } -void ToolWindowManagerSplitter::childEvent(QChildEvent *event) { +void ToolWindowManagerSplitter::childEvent(QChildEvent *event) +{ QList s = sizes(); - QWidget *w = qobject_cast(event->child()); + QWidget *w = qobject_cast(event->child()); int idx = -1; - if (w) + if(w) idx = indexOf(w); QSplitter::childEvent(event); - if (event->type() == QEvent::ChildRemoved && idx >= 0 && idx < s.count()) { + if(event->type() == QEvent::ChildRemoved && idx >= 0 && idx < s.count()) + { int removedSize = s[idx]; s.removeAt(idx); // if we removed an item at one extreme or another, the new end should get all the space // (unless the list is now empty) - if (idx == 0) { + if(idx == 0) + { if(!s.isEmpty()) s[0] += removedSize; - } else if (idx == s.count()) { + } + else if(idx == s.count()) + { if(!s.isEmpty()) - s[s.count()-1] += removedSize; - } else { + s[s.count() - 1] += removedSize; + } + else + { // we removed an item in the middle, share the space between its previous neighbours, now in // [idx-1] and [idx], and we know they're valid since if there were only two elements before // the removal one or the other case above would have matched. So there are at least two // elements now and idx > 0 - s[idx-1] += removedSize/2; - s[idx] += removedSize/2; + s[idx - 1] += removedSize / 2; + s[idx] += removedSize / 2; } setSizes(s); diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.h index 95b9c2fcd..d8d967859 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerSplitter.h @@ -31,7 +31,8 @@ * \brief The ToolWindowManagerSplitter class is a splitter that tweaks how sizes are allocated in * children when a child is removed. */ -class ToolWindowManagerSplitter : public QSplitter { +class ToolWindowManagerSplitter : public QSplitter +{ Q_OBJECT public: //! Creates new tab bar. @@ -44,4 +45,4 @@ protected: void childEvent(QChildEvent *) Q_DECL_OVERRIDE; }; -#endif // TOOLWINDOWMANAGERSPLITTER_H +#endif // TOOLWINDOWMANAGERSPLITTER_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.cpp index 09ac2ca17..2b71ca401 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.cpp @@ -23,16 +23,15 @@ * */ #include "ToolWindowManager.h" -#include "ToolWindowManagerTabBar.h" -#include "ToolWindowManagerArea.h" -#include "ToolWindowManagerWrapper.h" #include #include -#include #include +#include +#include "ToolWindowManagerArea.h" +#include "ToolWindowManagerTabBar.h" +#include "ToolWindowManagerWrapper.h" -ToolWindowManagerTabBar::ToolWindowManagerTabBar(QWidget *parent) : - QTabBar(parent) +ToolWindowManagerTabBar::ToolWindowManagerTabBar(QWidget *parent) : QTabBar(parent) { m_tabsClosable = false; @@ -66,23 +65,27 @@ ToolWindowManagerTabBar::ToolWindowManagerTabBar(QWidget *parent) : m_close.hover = m_close.clicked = false; } -ToolWindowManagerTabBar::~ToolWindowManagerTabBar() { +ToolWindowManagerTabBar::~ToolWindowManagerTabBar() +{ } bool ToolWindowManagerTabBar::useMinimalBar() const { - if (count() > 1) + if(count() > 1) return false; - if (m_area) { + if(m_area) + { return m_area->useMinimalTabBar(); } return true; } -QSize ToolWindowManagerTabBar::sizeHint() const { - if(useMinimalBar()) { - if (floatingWindowChild()) +QSize ToolWindowManagerTabBar::sizeHint() const +{ + if(useMinimalBar()) + { + if(floatingWindowChild()) return QSize(0, 0); QFontMetrics fm = fontMetrics(); @@ -90,7 +93,7 @@ QSize ToolWindowManagerTabBar::sizeHint() const { int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); int mw = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, this); - int h = qMax(fm.height(), iconSize) + 2*mw; + int h = qMax(fm.height(), iconSize) + 2 * mw; return QSize(m_area->width(), h); } @@ -98,9 +101,11 @@ QSize ToolWindowManagerTabBar::sizeHint() const { return QTabBar::sizeHint(); } -QSize ToolWindowManagerTabBar::minimumSizeHint() const { - if (useMinimalBar()) { - if (floatingWindowChild()) +QSize ToolWindowManagerTabBar::minimumSizeHint() const +{ + if(useMinimalBar()) + { + if(floatingWindowChild()) return QSize(0, 0); QFontMetrics fm = fontMetrics(); @@ -108,7 +113,7 @@ QSize ToolWindowManagerTabBar::minimumSizeHint() const { int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); int mw = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, this); - int h = qMax(fm.height(), iconSize) + 2*mw; + int h = qMax(fm.height(), iconSize) + 2 * mw; return QSize(h, h); } @@ -116,13 +121,16 @@ QSize ToolWindowManagerTabBar::minimumSizeHint() const { return QTabBar::minimumSizeHint(); } -bool ToolWindowManagerTabBar::inButton(QPoint pos) { +bool ToolWindowManagerTabBar::inButton(QPoint pos) +{ return m_pin.rect.contains(pos) || m_close.rect.contains(pos); } -void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { - if (useMinimalBar()) { - if (floatingWindowChild()) +void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) +{ + if(useMinimalBar()) + { + if(floatingWindowChild()) return; QStylePainter p(this); @@ -138,8 +146,8 @@ void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { option.floatable = true; Shape s = shape(); - option.verticalTitleBar = s == RoundedEast || s == TriangularEast || - s == RoundedWest || s == TriangularWest; + option.verticalTitleBar = + s == RoundedEast || s == TriangularEast || s == RoundedWest || s == TriangularWest; p.drawControl(QStyle::CE_DockWidgetTitle, option); @@ -153,17 +161,17 @@ void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { buttonOpt.activeSubControls = 0; buttonOpt.features = QStyleOptionToolButton::None; buttonOpt.arrowType = Qt::NoArrow; - buttonOpt.state = QStyle::State_Active|QStyle::State_Enabled|QStyle::State_AutoRaise; + buttonOpt.state = QStyle::State_Active | QStyle::State_Enabled | QStyle::State_AutoRaise; buttonOpt.rect = m_pin.rect; buttonOpt.icon = m_pin.icon; ToolWindowManager::ToolWindowProperty props = - m_area->m_manager->toolWindowProperties(m_area->widget(0)); + m_area->m_manager->toolWindowProperties(m_area->widget(0)); bool tabClosable = (props & ToolWindowManager::HideCloseButton) == 0; - if (!tabClosable && !m_pin.rect.isEmpty()) + if(!tabClosable && !m_pin.rect.isEmpty()) buttonOpt.rect = m_close.rect; QStyle::State prevState = buttonOpt.state; @@ -173,13 +181,15 @@ void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { else if(m_pin.hover) buttonOpt.state |= QStyle::State_Raised | QStyle::State_MouseOver; - if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) { + if(style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) + { style()->drawPrimitive(QStyle::PE_PanelButtonTool, &buttonOpt, &p, this); } style()->drawComplexControl(QStyle::CC_ToolButton, &buttonOpt, &p, this); - if (m_tabsClosable && tabClosable) { + if(m_tabsClosable && tabClosable) + { buttonOpt.rect = m_close.rect; buttonOpt.icon = m_close.icon; @@ -198,10 +208,11 @@ void ToolWindowManagerTabBar::paintEvent(QPaintEvent *event) { QTabBar::paintEvent(event); } -void ToolWindowManagerTabBar::resizeEvent(QResizeEvent *event) { +void ToolWindowManagerTabBar::resizeEvent(QResizeEvent *event) +{ QTabBar::resizeEvent(event); - if (count() > 1 || floatingWindowChild()) + if(count() > 1 || floatingWindowChild()) return; m_titleRect = QRect(0, 0, size().width(), sizeHint().height()); @@ -222,95 +233,110 @@ void ToolWindowManagerTabBar::resizeEvent(QResizeEvent *event) { m_pin.rect = QRect(); } -void ToolWindowManagerTabBar::mousePressEvent(QMouseEvent *event) { +void ToolWindowManagerTabBar::mousePressEvent(QMouseEvent *event) +{ QTabBar::mousePressEvent(event); - if (count() > 1 || floatingWindowChild()) + if(count() > 1 || floatingWindowChild()) return; ButtonData prevPin = m_pin; ButtonData prevClose = m_close; ToolWindowManager::ToolWindowProperty props = - m_area->m_manager->toolWindowProperties(m_area->widget(0)); + m_area->m_manager->toolWindowProperties(m_area->widget(0)); bool tabClosable = (props & ToolWindowManager::HideCloseButton) == 0; QRect pinRect = m_pin.rect; QRect closeRect = m_close.rect; - if (!tabClosable) { - if (!pinRect.isEmpty()) + if(!tabClosable) + { + if(!pinRect.isEmpty()) pinRect = closeRect; closeRect = QRect(); } - if (pinRect.contains(mapFromGlobal(QCursor::pos())) && - event->buttons() & Qt::LeftButton) { + if(pinRect.contains(mapFromGlobal(QCursor::pos())) && event->buttons() & Qt::LeftButton) + { m_pin.clicked = true; - } else { + } + else + { m_pin.clicked = false; } - if (closeRect.contains(mapFromGlobal(QCursor::pos())) && - event->buttons() & Qt::LeftButton) { + if(closeRect.contains(mapFromGlobal(QCursor::pos())) && event->buttons() & Qt::LeftButton) + { m_close.clicked = true; - } else { + } + else + { m_close.clicked = false; } - if (prevPin != m_pin || prevClose != m_close) + if(prevPin != m_pin || prevClose != m_close) update(); event->accept(); } -void ToolWindowManagerTabBar::mouseMoveEvent(QMouseEvent *event) { +void ToolWindowManagerTabBar::mouseMoveEvent(QMouseEvent *event) +{ QTabBar::mouseMoveEvent(event); - if (count() > 1 || floatingWindowChild()) + if(count() > 1 || floatingWindowChild()) return; ButtonData prevPin = m_pin; ButtonData prevClose = m_close; ToolWindowManager::ToolWindowProperty props = - m_area->m_manager->toolWindowProperties(m_area->widget(0)); + m_area->m_manager->toolWindowProperties(m_area->widget(0)); bool tabClosable = (props & ToolWindowManager::HideCloseButton) == 0; QRect pinRect = m_pin.rect; QRect closeRect = m_close.rect; - if (!tabClosable) { - if (!pinRect.isEmpty()) + if(!tabClosable) + { + if(!pinRect.isEmpty()) pinRect = closeRect; closeRect = QRect(); } - if (pinRect.contains(mapFromGlobal(QCursor::pos()))) { + if(pinRect.contains(mapFromGlobal(QCursor::pos()))) + { m_pin.hover = true; - if (event->buttons() & Qt::LeftButton) + if(event->buttons() & Qt::LeftButton) m_pin.clicked = true; - } else { + } + else + { m_pin.hover = false; m_pin.clicked = false; } - if (closeRect.contains(mapFromGlobal(QCursor::pos()))) { + if(closeRect.contains(mapFromGlobal(QCursor::pos()))) + { m_close.hover = true; - if (event->buttons() & Qt::LeftButton) + if(event->buttons() & Qt::LeftButton) m_close.clicked = true; - } else { + } + else + { m_close.hover = false; m_close.clicked = false; } - if (prevPin != m_pin || prevClose != m_close) + if(prevPin != m_pin || prevClose != m_close) update(); } -void ToolWindowManagerTabBar::leaveEvent(QEvent *) { +void ToolWindowManagerTabBar::leaveEvent(QEvent *) +{ m_pin.hover = false; m_pin.clicked = false; @@ -320,27 +346,30 @@ void ToolWindowManagerTabBar::leaveEvent(QEvent *) { update(); } -void ToolWindowManagerTabBar::mouseReleaseEvent(QMouseEvent *event) { +void ToolWindowManagerTabBar::mouseReleaseEvent(QMouseEvent *event) +{ QTabBar::mouseReleaseEvent(event); - if (count() > 1 || floatingWindowChild()) + if(count() > 1 || floatingWindowChild()) return; ToolWindowManager::ToolWindowProperty props = - m_area->m_manager->toolWindowProperties(m_area->widget(0)); + m_area->m_manager->toolWindowProperties(m_area->widget(0)); bool tabClosable = (props & ToolWindowManager::HideCloseButton) == 0; QRect pinRect = m_pin.rect; QRect closeRect = m_close.rect; - if (!tabClosable) { - if (!pinRect.isEmpty()) + if(!tabClosable) + { + if(!pinRect.isEmpty()) pinRect = closeRect; closeRect = QRect(); } - if (pinRect.contains(mapFromGlobal(QCursor::pos()))) { + if(pinRect.contains(mapFromGlobal(QCursor::pos()))) + { // process a pin of these tabs m_pin.clicked = false; @@ -350,8 +379,9 @@ void ToolWindowManagerTabBar::mouseReleaseEvent(QMouseEvent *event) { event->accept(); } - if (closeRect.contains(mapFromGlobal(QCursor::pos()))) { - if (m_area) + if(closeRect.contains(mapFromGlobal(QCursor::pos()))) + { + if(m_area) m_area->tabCloseRequested(0); m_close.clicked = false; @@ -362,25 +392,31 @@ void ToolWindowManagerTabBar::mouseReleaseEvent(QMouseEvent *event) { } } -void ToolWindowManagerTabBar::tabInserted(int) { +void ToolWindowManagerTabBar::tabInserted(int) +{ updateClosable(); } -void ToolWindowManagerTabBar::tabRemoved(int) { +void ToolWindowManagerTabBar::tabRemoved(int) +{ updateClosable(); } -void ToolWindowManagerTabBar::updateClosable() { - QTabBar::setTabsClosable(m_tabsClosable && count() > 1); +void ToolWindowManagerTabBar::updateClosable() +{ + QTabBar::setTabsClosable(m_tabsClosable && !useMinimalBar()); } -bool ToolWindowManagerTabBar::floatingWindowChild() const { +bool ToolWindowManagerTabBar::floatingWindowChild() const +{ ToolWindowManagerArea *area = qobject_cast(parentWidget()); - if (area) { - ToolWindowManagerWrapper *wrapper = qobject_cast(area->parentWidget()); + if(area) + { + ToolWindowManagerWrapper *wrapper = + qobject_cast(area->parentWidget()); - if (wrapper && wrapper->floating()) + if(wrapper && wrapper->floating()) return true; } diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.h index 99f56d826..22f1df734 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerTabBar.h @@ -25,8 +25,8 @@ #ifndef TOOLWINDOWMANAGERTABBAR_H #define TOOLWINDOWMANAGERTABBAR_H -#include #include +#include class ToolWindowManager; class ToolWindowManagerArea; @@ -35,31 +35,36 @@ class ToolWindowManagerArea; * \brief The ToolWindowManagerTabBar class is a tab bar used to customise the painting * in the case that there's only only one child widget. */ -class ToolWindowManagerTabBar : public QTabBar { +class ToolWindowManagerTabBar : public QTabBar +{ Q_OBJECT public: //! Creates new tab bar. explicit ToolWindowManagerTabBar(QWidget *parent = 0); //! Destroys the tab bar. virtual ~ToolWindowManagerTabBar(); - + bool tabsClosable() const { return m_tabsClosable; } - void setTabsClosable(bool closable) { m_tabsClosable = closable; updateClosable(); } - + void setTabsClosable(bool closable) + { + m_tabsClosable = closable; + updateClosable(); + } + //! Reimplemented from QTabWidget::QTabBar to custom size for the single tab case. QSize sizeHint() const Q_DECL_OVERRIDE; bool useMinimalBar() const; QSize minimumSizeHint() const Q_DECL_OVERRIDE; - + //! is this point in a custom titlebar button bool inButton(QPoint pos); protected: //! Reimplemented from QTabWidget::QTabBar to custom paint for the single tab case. void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; - + //! Reimplemented from QTabWidget::QTabBar to cache painting parameters void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; //! Reimplemented from QTabWidget::QTabBar to implement hover/click status of buttons @@ -67,12 +72,12 @@ protected: void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE; void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; void leaveEvent(QEvent *) Q_DECL_OVERRIDE; - + //! Reimplemented from QTabWidget::QTabBar to enable/disable 'real' closable tabs. virtual void tabInserted(int index) Q_DECL_OVERRIDE; virtual void tabRemoved(int index) Q_DECL_OVERRIDE; - ToolWindowManagerArea* m_area; + ToolWindowManagerArea *m_area; bool m_tabsClosable; @@ -83,14 +88,12 @@ protected: bool clicked; bool hover; - bool operator ==(const ButtonData &o) { + bool operator==(const ButtonData &o) + { return rect == o.rect && clicked == o.clicked && hover == o.hover; } - bool operator !=(const ButtonData &o) { - return !(*this == o); - } - + bool operator!=(const ButtonData &o) { return !(*this == o); } } m_close, m_pin; QRect m_titleRect; @@ -99,4 +102,4 @@ protected: bool floatingWindowChild() const; }; -#endif // TOOLWINDOWMANAGERTABBAR_H +#endif // TOOLWINDOWMANAGERTABBAR_H diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp index a1865a5b0..cbc777774 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.cpp @@ -23,21 +23,20 @@ * */ #include "ToolWindowManagerWrapper.h" -#include "ToolWindowManager.h" -#include "ToolWindowManagerArea.h" -#include +#include +#include #include #include -#include -#include #include -#include -#include #include +#include +#include +#include +#include "ToolWindowManager.h" +#include "ToolWindowManagerArea.h" -ToolWindowManagerWrapper::ToolWindowManagerWrapper(ToolWindowManager *manager, bool floating) : - QWidget(manager) -, m_manager(manager) +ToolWindowManagerWrapper::ToolWindowManagerWrapper(ToolWindowManager *manager, bool floating) + : QWidget(manager), m_manager(manager) { Qt::WindowFlags flags = Qt::Tool; @@ -58,7 +57,7 @@ ToolWindowManagerWrapper::ToolWindowManagerWrapper(ToolWindowManager *manager, b m_floating = floating; - QVBoxLayout* mainLayout = new QVBoxLayout(this); + QVBoxLayout *mainLayout = new QVBoxLayout(this); mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setMargin(0); mainLayout->setSpacing(0); @@ -73,52 +72,61 @@ ToolWindowManagerWrapper::ToolWindowManagerWrapper(ToolWindowManager *manager, b m_frameWidth = 0; m_titleHeight = 0; - if (floating && (flags & Qt::FramelessWindowHint)) { + if(floating && (flags & Qt::FramelessWindowHint)) + { m_closeButtonSize = style()->pixelMetric(QStyle::PM_SmallIconSize, 0, this); QFontMetrics titleFontMetrics = fontMetrics(); int mw = style()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, 0, this); - m_titleHeight = qMax(m_closeButtonSize + 2, titleFontMetrics.height() + 2*mw); + m_titleHeight = qMax(m_closeButtonSize + 2, titleFontMetrics.height() + 2 * mw); m_frameWidth = style()->pixelMetric(QStyle::PM_DockWidgetFrameWidth, 0, this); - mainLayout->setContentsMargins(QMargins(m_frameWidth+4, m_frameWidth+4 + m_titleHeight, - m_frameWidth+4, m_frameWidth+4)); + mainLayout->setContentsMargins(QMargins(m_frameWidth + 4, m_frameWidth + 4 + m_titleHeight, + m_frameWidth + 4, m_frameWidth + 4)); } - if (floating) { + if(floating) + { installEventFilter(this); updateTitle(); } } -ToolWindowManagerWrapper::~ToolWindowManagerWrapper() { +ToolWindowManagerWrapper::~ToolWindowManagerWrapper() +{ m_manager->m_wrappers.removeOne(this); } -void ToolWindowManagerWrapper::updateTitle() { - if (!m_floating) +void ToolWindowManagerWrapper::updateTitle() +{ + if(!m_floating) return; // find the best candidate for a 'title' for this floating window. - if (layout()->count() > 0) { + if(layout()->count() > 0) + { QWidget *child = layout()->itemAt(0)->widget(); - while (child) { + while(child) + { // if we've found an area, use its currently selected tab's text - if (ToolWindowManagerArea* area = qobject_cast(child)) { + if(ToolWindowManagerArea *area = qobject_cast(child)) + { setWindowTitle(area->tabText(area->currentIndex())); return; } // otherwise we should have a splitter - if (QSplitter* splitter = qobject_cast(child)) { + if(QSplitter *splitter = qobject_cast(child)) + { // if it's empty, just bail - if (splitter->count() == 0) + if(splitter->count() == 0) break; // if it's vertical, we pick the first child and recurse - if (splitter->orientation() == Qt::Vertical) { + if(splitter->orientation() == Qt::Vertical) + { child = splitter->widget(0); continue; } @@ -128,8 +136,10 @@ void ToolWindowManagerWrapper::updateTitle() { QList sizes = splitter->sizes(); int maxIdx = 0; int maxSize = sizes[0]; - for (int i=1; i < sizes.count(); i++) { - if (sizes[i] > maxSize) { + for(int i = 1; i < sizes.count(); i++) + { + if(sizes[i] > maxSize) + { maxSize = sizes[i]; maxIdx = i; } @@ -148,22 +158,31 @@ void ToolWindowManagerWrapper::updateTitle() { setWindowTitle(QStringLiteral("Tool Window")); } -void ToolWindowManagerWrapper::closeEvent(QCloseEvent *event) { - QList toolWindows; - foreach(ToolWindowManagerArea* tabWidget, findChildren()) { - if (ToolWindowManager::managerOf(tabWidget) == m_manager) { +void ToolWindowManagerWrapper::closeEvent(QCloseEvent *event) +{ + // abort dragging caused by QEvent::NonClientAreaMouseButtonPress in eventFilter function + m_manager->abortDrag(); + + QList toolWindows; + foreach(ToolWindowManagerArea *tabWidget, findChildren()) + { + if(ToolWindowManager::managerOf(tabWidget) == m_manager) + { toolWindows << tabWidget->toolWindows(); } } - foreach(QWidget* toolWindow, toolWindows) { - if (!m_manager->allowClose(toolWindow)) { + foreach(QWidget *toolWindow, toolWindows) + { + if(!m_manager->allowClose(toolWindow)) + { event->ignore(); return; } } - foreach(QWidget* toolWindow, toolWindows) { + foreach(QWidget *toolWindow, toolWindows) + { if(m_manager->toolWindowProperties(toolWindow) & ToolWindowManager::HideOnClose) m_manager->hideToolWindow(toolWindow); else @@ -171,43 +190,48 @@ void ToolWindowManagerWrapper::closeEvent(QCloseEvent *event) { } } -bool ToolWindowManagerWrapper::eventFilter(QObject *object, QEvent *event) { +bool ToolWindowManagerWrapper::eventFilter(QObject *object, QEvent *event) +{ const Qt::CursorShape shapes[(int)ResizeDirection::Count] = { - Qt::SizeFDiagCursor, - Qt::SizeBDiagCursor, - Qt::SizeBDiagCursor, - Qt::SizeFDiagCursor, - Qt::SizeVerCursor, - Qt::SizeHorCursor, - Qt::SizeVerCursor, - Qt::SizeHorCursor, + Qt::SizeFDiagCursor, Qt::SizeBDiagCursor, Qt::SizeBDiagCursor, Qt::SizeFDiagCursor, + Qt::SizeVerCursor, Qt::SizeHorCursor, Qt::SizeVerCursor, Qt::SizeHorCursor, }; - if (object == this) { - if (event->type() == QEvent::MouseButtonRelease || - event->type() == QEvent::NonClientAreaMouseButtonRelease) { + if(object == this) + { + if(event->type() == QEvent::MouseButtonRelease || + event->type() == QEvent::NonClientAreaMouseButtonRelease) + { m_dragReady = false; m_dragDirection = ResizeDirection::Count; - if (!m_dragActive && m_closeRect.contains(mapFromGlobal(QCursor::pos()))) { + if(!m_dragActive && m_closeRect.contains(mapFromGlobal(QCursor::pos()))) + { // catch clicks on the close button close(); - } else { + } + else + { // if the mouse button is released, let the manager finish the drag and don't call any more // updates for any further move events m_dragActive = false; m_manager->updateDragPosition(); } - } else if (event->type() == QEvent::MouseMove || - event->type() == QEvent::NonClientAreaMouseMove) { + } + else if(event->type() == QEvent::MouseMove || event->type() == QEvent::NonClientAreaMouseMove) + { // if we're ready to start a drag, check how far we've moved and start the drag if past a // certain pixel threshold. - if (m_dragReady) { - if ((QCursor::pos() - m_dragStartCursor).manhattanLength() > 10) { + if(m_dragReady) + { + if((QCursor::pos() - m_dragStartCursor).manhattanLength() > 10) + { m_dragActive = true; m_dragReady = false; - QList toolWindows; - foreach(ToolWindowManagerArea* tabWidget, findChildren()) { - if (ToolWindowManager::managerOf(tabWidget) == m_manager) { + QList toolWindows; + foreach(ToolWindowManagerArea *tabWidget, findChildren()) + { + if(ToolWindowManager::managerOf(tabWidget) == m_manager) + { toolWindows << tabWidget->toolWindows(); } } @@ -215,109 +239,121 @@ bool ToolWindowManagerWrapper::eventFilter(QObject *object, QEvent *event) { } } // if the drag is active, update it in the manager. - if (m_dragActive) { + if(m_dragActive) + { m_manager->updateDragPosition(); - // on non-windows we have no native title bar, so we need to move the window ourselves +// on non-windows we have no native title bar, so we need to move the window ourselves #if !defined(Q_OS_WIN32) move(QCursor::pos() - (m_dragStartCursor - m_dragStartGeometry.topLeft())); #endif } - if (titleRect().contains(mapFromGlobal(QCursor::pos()))) { + if(titleRect().contains(mapFromGlobal(QCursor::pos()))) + { // if we're in the title bar, repaint to pick up motion over the close button update(); } - + ResizeDirection dir = checkResize(); - if (m_dragDirection != ResizeDirection::Count) { + if(m_dragDirection != ResizeDirection::Count) + { dir = m_dragDirection; QRect g = geometry(); - switch (dir) { - case ResizeDirection::NW: - g.setTopLeft(QCursor::pos()); - break; - case ResizeDirection::NE: - g.setTopRight(QCursor::pos()); - break; - case ResizeDirection::SW: - g.setBottomLeft(QCursor::pos()); - break; - case ResizeDirection::SE: - g.setBottomRight(QCursor::pos()); - break; - case ResizeDirection::N: - g.setTop(QCursor::pos().y()); - break; - case ResizeDirection::E: - g.setRight(QCursor::pos().x()); - break; - case ResizeDirection::S: - g.setBottom(QCursor::pos().y()); - break; - case ResizeDirection::W: - g.setLeft(QCursor::pos().x()); - break; - case ResizeDirection::Count: - break; + switch(dir) + { + case ResizeDirection::NW: g.setTopLeft(QCursor::pos()); break; + case ResizeDirection::NE: g.setTopRight(QCursor::pos()); break; + case ResizeDirection::SW: g.setBottomLeft(QCursor::pos()); break; + case ResizeDirection::SE: g.setBottomRight(QCursor::pos()); break; + case ResizeDirection::N: g.setTop(QCursor::pos().y()); break; + case ResizeDirection::E: g.setRight(QCursor::pos().x()); break; + case ResizeDirection::S: g.setBottom(QCursor::pos().y()); break; + case ResizeDirection::W: g.setLeft(QCursor::pos().x()); break; + case ResizeDirection::Count: break; } setGeometry(g); } - if (dir != ResizeDirection::Count) { + if(dir != ResizeDirection::Count) + { setCursor(shapes[(int)dir]); - + QObjectList children = this->children(); - for (int i = 0; i < children.size(); ++i) { - if (QWidget *w = qobject_cast(children.at(i))) { - if (!w->testAttribute(Qt::WA_SetCursor)) { + for(int i = 0; i < children.size(); ++i) + { + if(QWidget *w = qobject_cast(children.at(i))) + { + if(!w->testAttribute(Qt::WA_SetCursor)) + { w->setCursor(Qt::ArrowCursor); } } } - } else { + } + else + { unsetCursor(); } - - } else if (event->type() == QEvent::MouseButtonPress) { + } + else if(event->type() == QEvent::MouseButtonPress) + { ResizeDirection dir = checkResize(); m_dragStartCursor = QCursor::pos(); m_dragStartGeometry = geometry(); - if (dir == ResizeDirection::Count) + if(dir == ResizeDirection::Count) m_dragReady = true; else m_dragDirection = dir; - } else if (event->type() == QEvent::NonClientAreaMouseButtonPress) { + } + else if(event->type() == QEvent::NonClientAreaMouseButtonPress) + { m_dragActive = true; m_dragReady = false; m_dragStartCursor = QCursor::pos(); m_dragStartGeometry = geometry(); - QList toolWindows; - foreach(ToolWindowManagerArea* tabWidget, findChildren()) { - if (ToolWindowManager::managerOf(tabWidget) == m_manager) { + QList toolWindows; + foreach(ToolWindowManagerArea *tabWidget, findChildren()) + { + if(ToolWindowManager::managerOf(tabWidget) == m_manager) + { toolWindows << tabWidget->toolWindows(); } } m_manager->startDrag(toolWindows, this); - } else if (event->type() == QEvent::Move && m_dragActive) { + } + else if(event->type() == QEvent::Move && m_dragActive) + { m_manager->updateDragPosition(); m_moveTimeout->start(); - } else if (event->type() == QEvent::Leave) { + } + else if(event->type() == QEvent::Leave) + { unsetCursor(); - } else if (event->type() == QEvent::MouseButtonDblClick && - titleRect().contains(mapFromGlobal(QCursor::pos()))) { - if (isMaximized()) { + } + else if(event->type() == QEvent::MouseButtonDblClick && + titleRect().contains(mapFromGlobal(QCursor::pos()))) + { + if(isMaximized()) + { showNormal(); - } else { + } + else + { showMaximized(); } - } else if (event->type() == QEvent::NonClientAreaMouseButtonDblClick) { - if (isMaximized()) { + } + else if(event->type() == QEvent::NonClientAreaMouseButtonDblClick) + { + if(isMaximized()) + { showNormal(); - } else { + } + else + { showMaximized(); } } @@ -325,8 +361,9 @@ bool ToolWindowManagerWrapper::eventFilter(QObject *object, QEvent *event) { return QWidget::eventFilter(object, event); } -void ToolWindowManagerWrapper::paintEvent(QPaintEvent *) { - if (!m_floating || m_titleHeight == 0) +void ToolWindowManagerWrapper::paintEvent(QPaintEvent *) +{ + if(!m_floating || m_titleHeight == 0) return; { @@ -349,7 +386,7 @@ void ToolWindowManagerWrapper::paintEvent(QPaintEvent *) { titlebarOptions.verticalTitleBar = false; p.drawControl(QStyle::CE_DockWidgetTitle, titlebarOptions); - + QStyleOptionToolButton buttonOpt; buttonOpt.initFrom(this); @@ -358,16 +395,18 @@ void ToolWindowManagerWrapper::paintEvent(QPaintEvent *) { buttonOpt.activeSubControls = 0; buttonOpt.features = QStyleOptionToolButton::None; buttonOpt.arrowType = Qt::NoArrow; - buttonOpt.state = QStyle::State_Active|QStyle::State_Enabled|QStyle::State_AutoRaise; + buttonOpt.state = QStyle::State_Active | QStyle::State_Enabled | QStyle::State_AutoRaise; - if (m_closeRect.contains(mapFromGlobal(QCursor::pos()))) { - buttonOpt.state |= QStyle::State_MouseOver|QStyle::State_Raised; + if(m_closeRect.contains(mapFromGlobal(QCursor::pos()))) + { + buttonOpt.state |= QStyle::State_MouseOver | QStyle::State_Raised; } buttonOpt.rect = m_closeRect; buttonOpt.icon = m_closeIcon; - if (style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) { + if(style()->styleHint(QStyle::SH_DockWidget_ButtonsHaveFrame, 0, this)) + { style()->drawPrimitive(QStyle::PE_PanelButtonTool, &buttonOpt, &p, this); } @@ -377,6 +416,9 @@ void ToolWindowManagerWrapper::paintEvent(QPaintEvent *) { void ToolWindowManagerWrapper::resizeEvent(QResizeEvent *) { + // abort dragging caused by QEvent::NonClientAreaMouseButtonPress in eventFilter function + m_manager->abortDrag(); + QStyleOptionDockWidget option; option.initFrom(this); @@ -399,25 +441,34 @@ QRect ToolWindowManagerWrapper::titleRect() return ret; } -QVariantMap ToolWindowManagerWrapper::saveState() { - if (layout()->count() > 2) { +QVariantMap ToolWindowManagerWrapper::saveState() +{ + if(layout()->count() > 2) + { qWarning("too many children for wrapper"); return QVariantMap(); } - if (isWindow() && layout()->count() == 0) { + if(isWindow() && layout()->count() == 0) + { qWarning("empty top level wrapper"); return QVariantMap(); } QVariantMap result; result[QStringLiteral("geometry")] = saveGeometry().toBase64(); - QSplitter* splitter = findChild(QString(), Qt::FindDirectChildrenOnly); - if (splitter) { + QSplitter *splitter = findChild(QString(), Qt::FindDirectChildrenOnly); + if(splitter) + { result[QStringLiteral("splitter")] = m_manager->saveSplitterState(splitter); - } else { - ToolWindowManagerArea* area = findChild(); - if (area) { + } + else + { + ToolWindowManagerArea *area = findChild(); + if(area) + { result[QStringLiteral("area")] = area->saveState(); - } else if (layout()->count() > 0) { + } + else if(layout()->count() > 0) + { qWarning("unknown child"); return QVariantMap(); } @@ -425,59 +476,86 @@ QVariantMap ToolWindowManagerWrapper::saveState() { return result; } -void ToolWindowManagerWrapper::restoreState(const QVariantMap &savedData) { +void ToolWindowManagerWrapper::restoreState(const QVariantMap &savedData) +{ restoreGeometry(QByteArray::fromBase64(savedData[QStringLiteral("geometry")].toByteArray())); - if (layout()->count() > 1) { + if(layout()->count() > 1) + { qWarning("wrapper is not empty"); return; } - if (savedData.contains(QStringLiteral("splitter"))) { - layout()->addWidget(m_manager->restoreSplitterState(savedData[QStringLiteral("splitter")].toMap())); - } else if (savedData.contains(QStringLiteral("area"))) { - ToolWindowManagerArea* area = m_manager->createArea(); + if(savedData.contains(QStringLiteral("splitter"))) + { + layout()->addWidget( + m_manager->restoreSplitterState(savedData[QStringLiteral("splitter")].toMap())); + } + else if(savedData.contains(QStringLiteral("area"))) + { + ToolWindowManagerArea *area = m_manager->createArea(); area->restoreState(savedData[QStringLiteral("area")].toMap()); layout()->addWidget(area); } } -void ToolWindowManagerWrapper::moveTimeout() { +void ToolWindowManagerWrapper::moveTimeout() +{ m_manager->updateDragPosition(); - if (!m_manager->dragInProgress()) { + if(!m_manager->dragInProgress()) + { m_moveTimeout->stop(); } } -ToolWindowManagerWrapper::ResizeDirection ToolWindowManagerWrapper::checkResize() { - if (m_titleHeight == 0) +ToolWindowManagerWrapper::ResizeDirection ToolWindowManagerWrapper::checkResize() +{ + if(m_titleHeight == 0) return ResizeDirection::Count; // check if we should offer to resize QRect rect = this->rect(); QPoint testPos = mapFromGlobal(QCursor::pos()); - if (m_closeRect.contains(testPos)) + if(m_closeRect.contains(testPos)) return ResizeDirection::Count; const int resizeMargin = 4; - if (rect.contains(testPos)) { + if(rect.contains(testPos)) + { // check corners first, then horizontal/vertical - if (testPos.x() < rect.x() + resizeMargin*4 && testPos.y() < rect.y() + resizeMargin*4) { + if(testPos.x() < rect.x() + resizeMargin * 4 && testPos.y() < rect.y() + resizeMargin * 4) + { return ResizeDirection::NW; - } else if (testPos.x() > rect.width() - resizeMargin*4 && testPos.y() < rect.y() + resizeMargin*4) { + } + else if(testPos.x() > rect.width() - resizeMargin * 4 && testPos.y() < rect.y() + resizeMargin * 4) + { return ResizeDirection::NE; - } else if (testPos.x() < rect.x() + resizeMargin*4 && testPos.y() > rect.height() - resizeMargin*4) { + } + else if(testPos.x() < rect.x() + resizeMargin * 4 && + testPos.y() > rect.height() - resizeMargin * 4) + { return ResizeDirection::SW; - } else if (testPos.x() > rect.width() - resizeMargin*4 && testPos.y() > rect.height() - resizeMargin*4) { + } + else if(testPos.x() > rect.width() - resizeMargin * 4 && + testPos.y() > rect.height() - resizeMargin * 4) + { return ResizeDirection::SE; - } else if (testPos.x() < rect.x() + resizeMargin) { + } + else if(testPos.x() < rect.x() + resizeMargin) + { return ResizeDirection::W; - } else if (testPos.x() > rect.width() - resizeMargin) { + } + else if(testPos.x() > rect.width() - resizeMargin) + { return ResizeDirection::E; - } else if (testPos.y() < rect.y() + resizeMargin) { + } + else if(testPos.y() < rect.y() + resizeMargin) + { return ResizeDirection::N; - } else if (testPos.y() > rect.height() - resizeMargin) { + } + else if(testPos.y() > rect.height() - resizeMargin) + { return ResizeDirection::S; } } diff --git a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h index 339d7cf25..3a730bbcd 100644 --- a/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h +++ b/qrenderdoc/3rdparty/toolwindowmanager/ToolWindowManagerWrapper.h @@ -26,34 +26,35 @@ #define TOOLWINDOWMANAGERWRAPPER_H #include -#include #include +#include class ToolWindowManager; class QLabel; /*! * \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. + * 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 { +class ToolWindowManagerWrapper : public QWidget +{ Q_OBJECT public: //! Creates new wrapper. - explicit ToolWindowManagerWrapper(ToolWindowManager* manager, bool floating); + explicit ToolWindowManagerWrapper(ToolWindowManager *manager, bool floating); //! Removes the wrapper. virtual ~ToolWindowManagerWrapper(); - ToolWindowManager* manager() { return m_manager; } - + ToolWindowManager *manager() { return m_manager; } bool floating() { return m_floating; } - void updateTitle(); protected: - //! Reimplemented to register hiding of contained tool windows when user closes the floating window. + //! Reimplemented to register hiding of contained tool windows when user closes the floating + //! window. virtual void closeEvent(QCloseEvent *) Q_DECL_OVERRIDE; //! Event filter for grabbing and processing mouse drags as toolwindow drags. @@ -64,9 +65,10 @@ protected: virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE; private: - ToolWindowManager* m_manager; + ToolWindowManager *m_manager; - enum class ResizeDirection { + enum class ResizeDirection + { NW, NE, SW, @@ -88,19 +90,19 @@ private: int m_frameWidth; bool m_floating; - QTimer* m_moveTimeout; + QTimer *m_moveTimeout; - bool m_dragReady; // we've clicked and started moving but haven't moved enough yet - QPoint m_dragStartCursor; // cursor at the click to start a drag - QRect m_dragStartGeometry; // window geometry at the click to start a drag - bool m_dragActive; // whether a drag currently on-going - ResizeDirection m_dragDirection; // the current direction being dragged + bool m_dragReady; // we've clicked and started moving but haven't moved enough yet + QPoint m_dragStartCursor; // cursor at the click to start a drag + QRect m_dragStartGeometry; // window geometry at the click to start a drag + bool m_dragActive; // whether a drag currently on-going + ResizeDirection m_dragDirection; // the current direction being dragged - //dump content's layout to variable + // dump content's layout to variable QVariantMap saveState(); - //construct layout based on given dump - void restoreState(const QVariantMap& data); + // construct layout based on given dump + void restoreState(const QVariantMap &data); friend class ToolWindowManager; @@ -108,4 +110,4 @@ private slots: void moveTimeout(); }; -#endif // TOOLWINDOWMANAGERWRAPPER_H +#endif // TOOLWINDOWMANAGERWRAPPER_H