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

#include <KoToolBoxLayout_p.h>

+ Inheritance diagram for SectionLayout:

Public Member Functions

void addButton (QAbstractButton *button, int priority)
 
void addItem (QLayoutItem *) override
 
const QSize & buttonSize () const
 
int count () const override
 
QLayoutItem * itemAt (int i) const override
 
 SectionLayout (QWidget *parent)
 
void setButtonSize (const QSize size)
 
void setGeometry (const QRect &rect) override
 
void setOnset (int onset)
 
void setOrientation (Qt::Orientation orientation)
 
QSize sizeHint () const override
 
QLayoutItem * takeAt (int i) override
 
 ~SectionLayout () override
 

Private Attributes

QSize m_buttonSize
 
QList< QWidgetItem * > m_items
 
int m_onset
 
Qt::Orientation m_orientation
 
QMap< QAbstractButton *, int > m_priorities
 

Detailed Description

Definition at line 19 of file KoToolBoxLayout_p.h.

Constructor & Destructor Documentation

◆ SectionLayout()

SectionLayout::SectionLayout ( QWidget * parent)
inlineexplicit

Definition at line 22 of file KoToolBoxLayout_p.h.

23 : QLayout(parent)
24 , m_orientation(Qt::Vertical)
25 , m_onset(0)
26 {
27 }
Qt::Orientation m_orientation

◆ ~SectionLayout()

SectionLayout::~SectionLayout ( )
inlineoverride

Definition at line 29 of file KoToolBoxLayout_p.h.

30 {
31 qDeleteAll( m_items );
32 m_items.clear();
33 }
QList< QWidgetItem * > m_items

References m_items.

Member Function Documentation

◆ addButton()

void SectionLayout::addButton ( QAbstractButton * button,
int priority )
inline

Definition at line 35 of file KoToolBoxLayout_p.h.

36 {
37 addChildWidget(button);
38 if (m_priorities.values().contains(priority)) {
39 qWarning() << "Button" << button << "has a conflicting priority";
40 }
41
42 m_priorities.insert(button, priority);
43 int index = 1;
44 Q_FOREACH (QWidgetItem *item, m_items) {
45 if (m_priorities.value(static_cast<QAbstractButton*>(item->widget())) > priority)
46 break;
47 index++;
48 }
49 m_items.insert(index-1, new QWidgetItem(button));
50 }
QMap< QAbstractButton *, int > m_priorities
QString button(const QWheelEvent &ev)

References button(), m_items, and m_priorities.

◆ addItem()

void SectionLayout::addItem ( QLayoutItem * )
inlineoverride

Definition at line 63 of file KoToolBoxLayout_p.h.

63{ Q_ASSERT(0); }

◆ buttonSize()

const QSize & SectionLayout::buttonSize ( ) const
inline

Definition at line 114 of file KoToolBoxLayout_p.h.

115 {
116 return m_buttonSize;
117 }

References m_buttonSize.

◆ count()

int SectionLayout::count ( ) const
inlineoverride

Definition at line 74 of file KoToolBoxLayout_p.h.

74{ return m_items.count(); }

References m_items.

◆ itemAt()

QLayoutItem * SectionLayout::itemAt ( int i) const
inlineoverride

Definition at line 65 of file KoToolBoxLayout_p.h.

66 {
67 if (m_items.count() <= i)
68 return 0;
69 return m_items.at(i);
70 }

References m_items.

◆ setButtonSize()

void SectionLayout::setButtonSize ( const QSize size)
inline

Definition at line 109 of file KoToolBoxLayout_p.h.

110 {
112 }
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_buttonSize.

◆ setGeometry()

void SectionLayout::setGeometry ( const QRect & rect)
inlineoverride

Definition at line 76 of file KoToolBoxLayout_p.h.

77 {
78 // the names of the variables assume a vertical orientation,
79 // but all calculations are done based on the real orientation
80 const bool isVertical = m_orientation == Qt::Vertical;
81 const bool isLeftToRight = parentWidget()->isLeftToRight();
82
83 const QSize &size = buttonSize();
84 const int maxWidth = isVertical ? rect.width() : rect.height();
85 const int iconWidth = isVertical ? size.width() : size.height();
86 const int iconHeight = isVertical ? size.height() : size.width();
87
88 int x = iconWidth * m_onset;
89 int y = 0;
90 foreach (QWidgetItem* w, m_items) {
91 if (w->isEmpty()) {
92 continue;
93 }
94 if (isVertical) {
95 const int realX = isLeftToRight ? x : rect.width() - x - size.width();
96 w->widget()->setGeometry(QRect(realX, y, size.width(), size.height()));
97 } else {
98 const int realX = isLeftToRight ? y : rect.width() - y - size.width();
99 w->widget()->setGeometry(QRect(realX, x, size.width(), size.height()));
100 }
101 x += iconWidth;
102 if (x + iconWidth > maxWidth) {
103 x = 0;
104 y += iconHeight;
105 }
106 }
107 }
const QSize & buttonSize() const

References buttonSize(), m_items, m_onset, and m_orientation.

◆ setOnset()

void SectionLayout::setOnset ( int onset)
inline

Definition at line 124 of file KoToolBoxLayout_p.h.

125 {
126 m_onset = onset;
127 }

References m_onset.

◆ setOrientation()

void SectionLayout::setOrientation ( Qt::Orientation orientation)
inline

Definition at line 119 of file KoToolBoxLayout_p.h.

120 {
121 m_orientation = orientation;
122 }

References m_orientation.

◆ sizeHint()

QSize SectionLayout::sizeHint ( ) const
inlineoverride

Definition at line 52 of file KoToolBoxLayout_p.h.

53 {
54 // This is implemented just to not freak out GammaRay, in practice
55 // this doesn't have any effect on the layout.
56 if (m_orientation == Qt::Vertical) {
57 return QSize(m_buttonSize.width(), m_buttonSize.height() * count());
58 } else {
59 return QSize(m_buttonSize.width() * count(), m_buttonSize.height());
60 }
61 }
int count() const override

References count(), m_buttonSize, and m_orientation.

◆ takeAt()

QLayoutItem * SectionLayout::takeAt ( int i)
inlineoverride

Definition at line 72 of file KoToolBoxLayout_p.h.

72{ return m_items.takeAt(i); }

References m_items.

Member Data Documentation

◆ m_buttonSize

QSize SectionLayout::m_buttonSize
private

Definition at line 130 of file KoToolBoxLayout_p.h.

◆ m_items

QList<QWidgetItem*> SectionLayout::m_items
private

Definition at line 132 of file KoToolBoxLayout_p.h.

◆ m_onset

int SectionLayout::m_onset
private

Definition at line 134 of file KoToolBoxLayout_p.h.

◆ m_orientation

Qt::Orientation SectionLayout::m_orientation
private

Definition at line 133 of file KoToolBoxLayout_p.h.

◆ m_priorities

QMap<QAbstractButton*, int> SectionLayout::m_priorities
private

Definition at line 131 of file KoToolBoxLayout_p.h.


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