| 1 |
// Copyright (C) 2016 The Qt Company Ltd. |
| 2 |
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause |
| 3 |
|
| 4 |
#ifndef FLOWLAYOUT_H |
| 5 |
#define FLOWLAYOUT_H |
| 6 |
|
| 7 |
#include <QGraphicsLayout> |
| 8 |
|
| 9 |
class FlowLayout : public QGraphicsLayout |
| 10 |
{ |
| 11 |
public: |
| 12 |
FlowLayout(QGraphicsLayoutItem *parent = nullptr); |
| 13 |
inline void addItem(QGraphicsLayoutItem *item); |
| 14 |
void insertItem(int index, QGraphicsLayoutItem *item); |
| 15 |
void setSpacing(Qt::Orientations o, qreal spacing); |
| 16 |
qreal spacing(Qt::Orientation o) const; |
| 17 |
|
| 18 |
// inherited functions |
| 19 |
void setGeometry(const QRectF &geom) override; |
| 20 |
|
| 21 |
int count() const override; |
| 22 |
QGraphicsLayoutItem *itemAt(int index) const override; |
| 23 |
void removeAt(int index) override; |
| 24 |
|
| 25 |
protected: |
| 26 |
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override; |
| 27 |
|
| 28 |
private: |
| 29 |
qreal doLayout(const QRectF &geom, bool applyNewGeometry) const; |
| 30 |
QSizeF minSize(const QSizeF &constraint) const; |
| 31 |
QSizeF prefSize() const; |
| 32 |
QSizeF maxSize() const; |
| 33 |
|
| 34 |
QList<QGraphicsLayoutItem *> m_items; |
| 35 |
qreal m_spacing[2] = {6, 6}; |
| 36 |
}; |
| 37 |
|
| 38 |
|
| 39 |
inline void FlowLayout::addItem(QGraphicsLayoutItem *item) |
| 40 |
{ |
| 41 |
insertItem(-1, item); |
| 42 |
} |
| 43 |
|
| 44 |
#endif // FLOWLAYOUT_H |