mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Improve FlowLayout to support vertical alignment
This commit is contained in:
parent
b953d223e4
commit
d629c77184
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "flowlayout.h"
|
#include "flowlayout.h"
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "base/global.h"
|
#include "base/global.h"
|
||||||
@ -142,6 +143,7 @@ int FlowLayout::doLayout(const QRect &rect, const bool testOnly) const
|
|||||||
int y = effectiveRect.y();
|
int y = effectiveRect.y();
|
||||||
int lineHeight = 0;
|
int lineHeight = 0;
|
||||||
|
|
||||||
|
QHash<QLayoutItem *, QPoint> lineItems;
|
||||||
for (QLayoutItem *item : asConst(m_itemList))
|
for (QLayoutItem *item : asConst(m_itemList))
|
||||||
{
|
{
|
||||||
const QWidget *wid = item->widget();
|
const QWidget *wid = item->widget();
|
||||||
@ -163,6 +165,12 @@ int FlowLayout::doLayout(const QRect &rect, const bool testOnly) const
|
|||||||
int nextX = x + item->sizeHint().width() + spaceX;
|
int nextX = x + item->sizeHint().width() + spaceX;
|
||||||
if (((nextX - spaceX) > effectiveRect.right()) && (lineHeight > 0))
|
if (((nextX - spaceX) > effectiveRect.right()) && (lineHeight > 0))
|
||||||
{
|
{
|
||||||
|
if (!testOnly)
|
||||||
|
{
|
||||||
|
applyItemsGeometry(lineItems, lineHeight);
|
||||||
|
lineItems.clear();
|
||||||
|
}
|
||||||
|
|
||||||
x = effectiveRect.x();
|
x = effectiveRect.x();
|
||||||
y = y + lineHeight + spaceY;
|
y = y + lineHeight + spaceY;
|
||||||
nextX = x + item->sizeHint().width() + spaceX;
|
nextX = x + item->sizeHint().width() + spaceX;
|
||||||
@ -170,12 +178,15 @@ int FlowLayout::doLayout(const QRect &rect, const bool testOnly) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!testOnly)
|
if (!testOnly)
|
||||||
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
lineItems[item] = QPoint(x, y);
|
||||||
|
|
||||||
x = nextX;
|
x = nextX;
|
||||||
lineHeight = std::max(lineHeight, item->sizeHint().height());
|
lineHeight = std::max(lineHeight, item->sizeHint().height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!testOnly)
|
||||||
|
applyItemsGeometry(lineItems, lineHeight);
|
||||||
|
|
||||||
return y + lineHeight - rect.y() + bottom;
|
return y + lineHeight - rect.y() + bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,3 +204,20 @@ int FlowLayout::smartSpacing(const QStyle::PixelMetric pm) const
|
|||||||
|
|
||||||
return static_cast<QLayout *>(parent)->spacing();
|
return static_cast<QLayout *>(parent)->spacing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlowLayout::applyItemsGeometry(const QHash<QLayoutItem *, QPoint> &items, const int lineHeight) const
|
||||||
|
{
|
||||||
|
for (auto it = items.cbegin(); it != items.cend(); ++it)
|
||||||
|
{
|
||||||
|
QLayoutItem *item = it.key();
|
||||||
|
QPoint point = it.value();
|
||||||
|
|
||||||
|
const auto alignment = item->alignment();
|
||||||
|
const int vSpace = lineHeight - item->sizeHint().height();
|
||||||
|
if (alignment & Qt::AlignVCenter)
|
||||||
|
point.ry() += vSpace / 2;
|
||||||
|
else if (alignment & Qt::AlignBottom)
|
||||||
|
point.ry() += vSpace;
|
||||||
|
item->setGeometry(QRect(point, item->sizeHint()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -56,6 +56,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
int doLayout(const QRect &rect, bool testOnly) const;
|
int doLayout(const QRect &rect, bool testOnly) const;
|
||||||
int smartSpacing(QStyle::PixelMetric pm) const;
|
int smartSpacing(QStyle::PixelMetric pm) const;
|
||||||
|
void applyItemsGeometry(const QHash<QLayoutItem *, QPoint> &items, int lineHeight) const;
|
||||||
|
|
||||||
QList<QLayoutItem *> m_itemList;
|
QList<QLayoutItem *> m_itemList;
|
||||||
int m_hSpace;
|
int m_hSpace;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user