diff --git a/qrenderdoc/Widgets/Extended/RDHeaderView.cpp b/qrenderdoc/Widgets/Extended/RDHeaderView.cpp new file mode 100644 index 000000000..8656285a3 --- /dev/null +++ b/qrenderdoc/Widgets/Extended/RDHeaderView.cpp @@ -0,0 +1,136 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2016-2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#include "RDHeaderView.h" +#include +#include +#include +#include + +RDHeaderView::RDHeaderView(Qt::Orientation orient, QWidget *parent) : QHeaderView(orient, parent) +{ + m_sectionPreview = new QLabel(this); +} + +RDHeaderView::~RDHeaderView() +{ +} + +void RDHeaderView::mousePressEvent(QMouseEvent *event) +{ + int mousePos = event->x(); + int idx = logicalIndexAt(mousePos); + + if(idx >= 0 && event->buttons() == Qt::LeftButton) + { + int secSize = sectionSize(idx); + int secPos = sectionViewportPosition(idx); + + int handleWidth = style()->pixelMetric(QStyle::PM_HeaderGripMargin, 0, this); + + if(secPos >= 0 && secSize > 0 && mousePos >= secPos + handleWidth && + mousePos <= secPos + secSize - handleWidth) + { + m_movingSection = idx; + + m_sectionPreview->resize(secSize, height()); + + QPixmap preview(m_sectionPreview->size()); + preview.fill(QColor::fromRgba(qRgba(0, 0, 0, 100))); + + QPainter painter(&preview); + painter.setOpacity(0.75f); + paintSection(&painter, QRect(QPoint(0, 0), m_sectionPreview->size()), idx); + painter.end(); + + m_sectionPreview->setPixmap(preview); + + m_sectionPreviewOffset = mousePos - secPos; + + m_sectionPreview->move(mousePos - m_sectionPreviewOffset, 0); + m_sectionPreview->show(); + + return; + } + } + + QHeaderView::mousePressEvent(event); +} + +void RDHeaderView::mouseMoveEvent(QMouseEvent *event) +{ + if(m_movingSection >= 0) + { + m_sectionPreview->move(event->x() - m_sectionPreviewOffset, 0); + return; + } + + QHeaderView::mouseMoveEvent(event); +} + +void RDHeaderView::mouseReleaseEvent(QMouseEvent *event) +{ + if(m_movingSection >= 0) + { + int mousePos = event->x(); + int idx = logicalIndexAt(mousePos); + + if(idx >= 0) + { + int secSize = sectionSize(idx); + int secPos = sectionPosition(idx); + + int srcSection = visualIndex(m_movingSection); + int dstSection = visualIndex(idx); + + if(srcSection >= 0 && dstSection >= 0 && srcSection != dstSection) + { + // the half-way point of the section decides whether we're dropping to the left + // or the right of it. + if(mousePos < secPos + secSize / 2) + { + // if we're moving from the left, place it to the left of dstSection + if(srcSection < dstSection) + moveSection(srcSection, dstSection - 1); + else + moveSection(srcSection, dstSection); + } + else + { + // if we're moving it from the right, place it to the right of dstSection + if(srcSection > dstSection) + moveSection(srcSection, dstSection + 1); + else + moveSection(srcSection, dstSection); + } + } + } + + m_sectionPreview->hide(); + } + + m_movingSection = -1; + + QHeaderView::mouseReleaseEvent(event); +} diff --git a/qrenderdoc/Widgets/Extended/RDHeaderView.h b/qrenderdoc/Widgets/Extended/RDHeaderView.h new file mode 100644 index 000000000..9f5a095d3 --- /dev/null +++ b/qrenderdoc/Widgets/Extended/RDHeaderView.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * The MIT License (MIT) + * + * Copyright (c) 2016-2017 Baldur Karlsson + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + ******************************************************************************/ + +#pragma once + +#include + +class QLabel; + +class RDHeaderView : public QHeaderView +{ +private: + Q_OBJECT +public: + explicit RDHeaderView(Qt::Orientation orient, QWidget *parent = 0); + ~RDHeaderView(); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + + int m_movingSection = -1; + QLabel *m_sectionPreview; + int m_sectionPreviewOffset = 0; +}; diff --git a/qrenderdoc/Widgets/Extended/RDTreeWidget.cpp b/qrenderdoc/Widgets/Extended/RDTreeWidget.cpp index 792465183..936b0123f 100644 --- a/qrenderdoc/Widgets/Extended/RDTreeWidget.cpp +++ b/qrenderdoc/Widgets/Extended/RDTreeWidget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -416,6 +417,8 @@ RDTreeWidget::RDTreeWidget(QWidget *parent) : RDTreeView(parent) // we'll call this ourselves in drawBranches() RDTreeView::enableBranchRectFill(false); + header()->setSectionsMovable(false); + m_root = new RDTreeWidgetItem; m_root->m_widget = this; diff --git a/qrenderdoc/Windows/EventBrowser.cpp b/qrenderdoc/Windows/EventBrowser.cpp index 2d0c43476..b0e86c99a 100644 --- a/qrenderdoc/Windows/EventBrowser.cpp +++ b/qrenderdoc/Windows/EventBrowser.cpp @@ -31,6 +31,7 @@ #include "Code/CaptureContext.h" #include "Code/QRDUtils.h" #include "Code/Resources.h" +#include "Widgets/Extended/RDHeaderView.h" #include "ui_EventBrowser.h" struct EventItemTag @@ -73,9 +74,15 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent) ui->events->setColumns( {tr("Name"), lit("EID"), lit("Duration - replaced in UpdateDurationColumn")}); + ui->events->setHeader(new RDHeaderView(Qt::Horizontal, this)); + ui->events->header()->setStretchLastSection(true); + ui->events->header()->setDefaultAlignment(Qt::AlignLeft | Qt::AlignVCenter); + ui->events->header()->resizeSection(COL_EID, 80); - ui->events->header()->setSectionResizeMode(COL_NAME, QHeaderView::Stretch); + ui->events->header()->setMinimumSectionSize(40); + + ui->events->header()->setSectionResizeMode(COL_NAME, QHeaderView::Interactive); ui->events->header()->setSectionResizeMode(COL_EID, QHeaderView::Interactive); ui->events->header()->setSectionResizeMode(COL_DURATION, QHeaderView::Interactive); @@ -83,9 +90,9 @@ EventBrowser::EventBrowser(ICaptureContext &ctx, QWidget *parent) // expand/collapse widgets. Then we need to put them back in order ui->events->header()->moveSection(COL_NAME, COL_EID); - // Qt doesn't allow moving the column with the expand/collapse widgets, so this - // becomes quickly infuriating to rearrange, just disable until that can be fixed. - ui->events->header()->setSectionsMovable(false); + ui->events->header()->setSectionsMovable(true); + + ui->events->header()->setCascadingSectionResizes(false); ui->events->setItemVerticalMargin(3); diff --git a/qrenderdoc/Windows/EventBrowser.ui b/qrenderdoc/Windows/EventBrowser.ui index 89fbfa569..803fd75eb 100644 --- a/qrenderdoc/Windows/EventBrowser.ui +++ b/qrenderdoc/Windows/EventBrowser.ui @@ -542,9 +542,6 @@ Qt::ScrollBarAlwaysOn - - Qt::ScrollBarAlwaysOff - QAbstractItemView::NoEditTriggers diff --git a/qrenderdoc/qrenderdoc.pro b/qrenderdoc/qrenderdoc.pro index 3e0bb7532..6e67c2e21 100644 --- a/qrenderdoc/qrenderdoc.pro +++ b/qrenderdoc/qrenderdoc.pro @@ -170,6 +170,7 @@ SOURCES += Code/qrenderdoc.cpp \ Widgets/Extended/RDLineEdit.cpp \ Widgets/Extended/RDTextEdit.cpp \ Widgets/Extended/RDLabel.cpp \ + Widgets/Extended/RDHeaderView.cpp \ Widgets/Extended/RDToolButton.cpp \ Widgets/Extended/RDDoubleSpinBox.cpp \ Widgets/Extended/RDListView.cpp \ @@ -229,6 +230,7 @@ HEADERS += Code/CaptureContext.h \ Widgets/Extended/RDLineEdit.h \ Widgets/Extended/RDTextEdit.h \ Widgets/Extended/RDLabel.h \ + Widgets/Extended/RDHeaderView.h \ Widgets/Extended/RDToolButton.h \ Widgets/Extended/RDDoubleSpinBox.h \ Widgets/Extended/RDListView.h \ diff --git a/qrenderdoc/qrenderdoc_local.vcxproj b/qrenderdoc/qrenderdoc_local.vcxproj index b7b6f52f2..23ea29da9 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj +++ b/qrenderdoc/qrenderdoc_local.vcxproj @@ -595,6 +595,7 @@ + @@ -655,6 +656,7 @@ + @@ -930,6 +932,12 @@ MOC %(Filename).h $(IntDir)generated\moc_%(Filename).cpp + + %(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs) + $(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe -DUNICODE -DWIN32 -DWIN64 -D_WIN32 -D_WIN64 -DRENDERDOC_PLATFORM_WIN32 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1900 -I$(ProjectDir) -I$(SolutionDir)\renderdoc\api\replay -I$(ProjectDir)3rdparty\qt\$(Platform)\mkspecs/win32-msvc2015 -I$(ProjectDir)3rdparty\qt\$(Platform)\include -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtWidgets -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtGui -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtCore %(Fullpath) -o $(IntDir)generated\moc_%(Filename).cpp + MOC %(Filename).h + $(IntDir)generated\moc_%(Filename).cpp + %(Fullpath);$(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe;%(AdditionalInputs) $(ProjectDir)3rdparty\qt\$(Platform)\bin\moc.exe -DUNICODE -DWIN32 -DWIN64 -D_WIN32 -D_WIN64 -DRENDERDOC_PLATFORM_WIN32 -DSCINTILLA_QT=1 -DSCI_LEXER=1 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D_MSC_VER=1900 -I$(ProjectDir) -I$(SolutionDir)\renderdoc\api\replay -I$(ProjectDir)3rdparty\qt\$(Platform)\mkspecs/win32-msvc2015 -I$(ProjectDir)3rdparty\qt\$(Platform)\include -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtWidgets -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtGui -I$(ProjectDir)3rdparty\qt\$(Platform)\include\QtCore %(Fullpath) -o $(IntDir)generated\moc_%(Filename).cpp diff --git a/qrenderdoc/qrenderdoc_local.vcxproj.filters b/qrenderdoc/qrenderdoc_local.vcxproj.filters index bec3ea017..1a19e12d3 100644 --- a/qrenderdoc/qrenderdoc_local.vcxproj.filters +++ b/qrenderdoc/qrenderdoc_local.vcxproj.filters @@ -606,6 +606,18 @@ 3rdparty\ToolWindowManager + + 3rdparty\ToolWindowManager + + + Generated Files + + + Generated Files + + + Widgets\Extended + @@ -1379,5 +1391,11 @@ 3rdparty\ToolWindowManager + + 3rdparty\ToolWindowManager + + + Widgets\Extended + \ No newline at end of file