mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-12 21:10:42 +00:00
Add option for the flow layout to keep a fixed grid size
This commit is contained in:
+26
-6
@@ -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;
|
||||
}
|
||||
|
||||
+4
@@ -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<QLayoutItem *> itemList;
|
||||
bool m_fixedGrid;
|
||||
int m_hSpace;
|
||||
int m_vSpace;
|
||||
};
|
||||
|
||||
@@ -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<QWidget *>(o));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user