From 2483fd776ad4bf48035bd757673ce13df6e756d9 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 21 Nov 2016 12:35:38 +0100 Subject: [PATCH] Add option for the flow layout to keep a fixed grid size --- qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp | 32 +++++++++++++++---- qrenderdoc/3rdparty/flowlayout/FlowLayout.h | 4 +++ qrenderdoc/Windows/Dialogs/CaptureDialog.cpp | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp b/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp index af33c170d..89a22b154 100644 --- a/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp +++ b/qrenderdoc/3rdparty/flowlayout/FlowLayout.cpp @@ -43,13 +43,13 @@ #include "FlowLayout.h" FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing) - : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing) + : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing), m_fixedGrid(false) { setContentsMargins(margin, margin, margin, margin); } FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing) - : m_hSpace(hSpacing), m_vSpace(vSpacing) + : m_hSpace(hSpacing), m_vSpace(vSpacing), m_fixedGrid(false) { setContentsMargins(margin, margin, margin, margin); } @@ -84,6 +84,16 @@ int FlowLayout::verticalSpacing() const } } +bool FlowLayout::fixedGrid() const +{ + return m_fixedGrid; +} + +void FlowLayout::setFixedGrid(bool fixedgrid) +{ + m_fixedGrid = fixedgrid; +} + int FlowLayout::count() const { return itemList.size(); @@ -151,10 +161,20 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const int x = effectiveRect.x(); int y = effectiveRect.y(); int lineHeight = 0; - + QSize fixedSize; + QLayoutItem *item; + if(m_fixedGrid) { + foreach (item, itemList) { + fixedSize = fixedSize.expandedTo(item->sizeHint()); + } + } + foreach (item, itemList) { QWidget *wid = item->widget(); + + QSize size = m_fixedGrid ? fixedSize : item->sizeHint(); + int spaceX = horizontalSpacing(); if (spaceX == -1) spaceX = wid->style()->layoutSpacing( @@ -163,11 +183,11 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const if (spaceY == -1) spaceY = wid->style()->layoutSpacing( QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical); - int nextX = x + item->sizeHint().width() + spaceX; + int nextX = x + size.width() + spaceX; if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { x = effectiveRect.x(); y = y + lineHeight + spaceY; - nextX = x + item->sizeHint().width() + spaceX; + nextX = x + size.width() + spaceX; lineHeight = 0; } @@ -175,7 +195,7 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); x = nextX; - lineHeight = qMax(lineHeight, item->sizeHint().height()); + lineHeight = qMax(lineHeight, size.height()); } return y + lineHeight - rect.y() + bottom; } diff --git a/qrenderdoc/3rdparty/flowlayout/FlowLayout.h b/qrenderdoc/3rdparty/flowlayout/FlowLayout.h index 6e61ef9cf..5d2512b52 100644 --- a/qrenderdoc/3rdparty/flowlayout/FlowLayout.h +++ b/qrenderdoc/3rdparty/flowlayout/FlowLayout.h @@ -64,11 +64,15 @@ public: QSize sizeHint() const Q_DECL_OVERRIDE; QLayoutItem *takeAt(int index) Q_DECL_OVERRIDE; + bool fixedGrid() const; + void setFixedGrid(bool fixedgrid); + private: int doLayout(const QRect &rect, bool testOnly) const; int smartSpacing(QStyle::PixelMetric pm) const; QList itemList; + bool m_fixedGrid; int m_hSpace; int m_vSpace; }; diff --git a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp index 62fa56c0a..d552da5b9 100644 --- a/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp +++ b/qrenderdoc/Windows/Dialogs/CaptureDialog.cpp @@ -126,6 +126,8 @@ CaptureDialog::CaptureDialog(CaptureContext *ctx, OnCaptureMethod captureCallbac FlowLayout *optionsFlow = new FlowLayout(ui->optionsGroup, -1, 3, 3); + optionsFlow->setFixedGrid(true); + for(QObject *o : options) optionsFlow->addWidget(qobject_cast(o));