Krita Source Code Documentation
Loading...
Searching...
No Matches
KisWrappableHBoxLayout Class Reference

#include <KisWrappableHBoxLayout.h>

+ Inheritance diagram for KisWrappableHBoxLayout:

Public Member Functions

void addItem (QLayoutItem *item) override
 
int count () const override
 
bool hasHeightForWidth () const override
 
int heightForWidth (int width) const override
 
QLayoutItem * itemAt (int) const override
 
 KisWrappableHBoxLayout (QWidget *parent=nullptr)
 
QSize minimumSize () const override
 
void setGeometry (const QRect &rect) override
 
QSize sizeHint () const override
 
QLayoutItem * takeAt (int) override
 
 ~KisWrappableHBoxLayout () override
 

Protected Member Functions

int doLayout (const QRect &rect, bool testOnly) const
 

Private Attributes

QVector< QLayoutItem * > m_items
 
int m_lastWidth {-1}
 

Detailed Description

Definition at line 16 of file KisWrappableHBoxLayout.h.

Constructor & Destructor Documentation

◆ KisWrappableHBoxLayout()

KisWrappableHBoxLayout::KisWrappableHBoxLayout ( QWidget * parent = nullptr)
explicit

Definition at line 12 of file KisWrappableHBoxLayout.cpp.

13 : QLayout(parent)
14{
15 // Remove extra floating space.
16 setContentsMargins(0, 0, 0, 0);
17}

◆ ~KisWrappableHBoxLayout()

KisWrappableHBoxLayout::~KisWrappableHBoxLayout ( )
override

Definition at line 19 of file KisWrappableHBoxLayout.cpp.

20{
21 QLayoutItem *item;
22 while ((item = takeAt(0))) {
23 delete item;
24 }
25}
QLayoutItem * takeAt(int) override

References takeAt().

Member Function Documentation

◆ addItem()

void KisWrappableHBoxLayout::addItem ( QLayoutItem * item)
override

Definition at line 27 of file KisWrappableHBoxLayout.cpp.

28{
29 m_items.append(item);
30}
QVector< QLayoutItem * > m_items

References m_items.

◆ count()

int KisWrappableHBoxLayout::count ( ) const
override

Definition at line 64 of file KisWrappableHBoxLayout.cpp.

65{
66 return m_items.size();
67}

References m_items.

◆ doLayout()

int KisWrappableHBoxLayout::doLayout ( const QRect & rect,
bool testOnly ) const
protected

Definition at line 98 of file KisWrappableHBoxLayout.cpp.

99{
100 int left, top, right, bottom;
101 getContentsMargins(&left, &top, &right, &bottom);
102 QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
103 int x = effectiveRect.x();
104 int y = effectiveRect.y();
105 int lineHeight = 0;
106
107 for (QLayoutItem *item : std::as_const(m_items)) {
108 int nextX = x + item->sizeHint().width() + spacing();
109 if (nextX - spacing() > effectiveRect.right() && lineHeight > 0) {
110 x = effectiveRect.x();
111 y = y + lineHeight + spacing();
112 nextX = x + item->sizeHint().width() + spacing();
113 lineHeight = 0;
114 }
115
116 if (!testOnly) {
117 item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
118 }
119
120 x = nextX;
121 lineHeight = qMax(lineHeight, item->sizeHint().height());
122 }
123 return y + lineHeight - rect.y() + bottom;
124}

References m_items.

◆ hasHeightForWidth()

bool KisWrappableHBoxLayout::hasHeightForWidth ( ) const
override

Definition at line 87 of file KisWrappableHBoxLayout.cpp.

88{
89 return true;
90}

◆ heightForWidth()

int KisWrappableHBoxLayout::heightForWidth ( int width) const
override

Definition at line 92 of file KisWrappableHBoxLayout.cpp.

93{
94 int height = doLayout(QRect(0, 0, width, 0), true);
95 return height;
96}
int doLayout(const QRect &rect, bool testOnly) const

References doLayout().

◆ itemAt()

QLayoutItem * KisWrappableHBoxLayout::itemAt ( int idx) const
override

Definition at line 71 of file KisWrappableHBoxLayout.cpp.

72{
73 return m_items.value(idx);
74}

References m_items.

◆ minimumSize()

QSize KisWrappableHBoxLayout::minimumSize ( ) const
override

Definition at line 42 of file KisWrappableHBoxLayout.cpp.

43{
44 const QMargins margins = contentsMargins();
45 const QSize marginsSize = QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
46
47 QSize size;
48 for (const QLayoutItem *item : std::as_const(m_items))
49 size = size.expandedTo(item->minimumSize());
50
51 if (!geometry().isEmpty()) {
52 QSize optimal = QSize(geometry().width(), heightForWidth(geometry().width()));
53 int minimumWidth = size.width(); // cannot be smaller than the biggest item
54 int minimumHeight = qMax(size.height(), optimal.height());
55 QSize minimum = QSize(minimumWidth, minimumHeight);
56 return minimum;
57 }
58
59 size += marginsSize;
60 //size = QSize(size.width(), size.height()*5);
61 return size;
62}
int heightForWidth(int width) const override
QSize minimumSize() const override
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References heightForWidth(), and m_items.

◆ setGeometry()

void KisWrappableHBoxLayout::setGeometry ( const QRect & rect)
override

Definition at line 81 of file KisWrappableHBoxLayout.cpp.

82{
83 QLayout::setGeometry(rect);
84 doLayout(rect, false);
85}

References doLayout().

◆ sizeHint()

QSize KisWrappableHBoxLayout::sizeHint ( ) const
override

Definition at line 32 of file KisWrappableHBoxLayout.cpp.

33{
34 const QMargins margins = contentsMargins();
35 if (!geometry().isEmpty()) {
36 return QSize(geometry().width(), heightForWidth(geometry().width()))
37 + QSize(margins.left() + margins.right(), margins.top() + margins.bottom());
38 }
39 return minimumSize();
40}

References heightForWidth(), and minimumSize().

◆ takeAt()

QLayoutItem * KisWrappableHBoxLayout::takeAt ( int idx)
override

Definition at line 76 of file KisWrappableHBoxLayout.cpp.

77{
78 return idx >= 0 && idx < m_items.size() ? m_items.takeAt(idx) : 0;
79}

References m_items.

Member Data Documentation

◆ m_items

QVector<QLayoutItem*> KisWrappableHBoxLayout::m_items
private

Definition at line 38 of file KisWrappableHBoxLayout.h.

◆ m_lastWidth

int KisWrappableHBoxLayout::m_lastWidth {-1}
private

Definition at line 39 of file KisWrappableHBoxLayout.h.

39{-1};

The documentation for this class was generated from the following files: