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

#include <kis_size_group_p.h>

+ Inheritance diagram for KisSizeGroupPrivate:

Public Member Functions

void addWidget (QWidget *widget)
 
const QSize getSizeHint () const
 Returns the size hint for the widgets contained in the size group.
 
 KisSizeGroupPrivate (KisSizeGroup *q_ptr, KisSizeGroup::mode mode, bool ignoreHidden)
 
void removeWidget (QWidget *widget)
 
void scheduleSizeUpdate ()
 Schedules an update of all widgets size.
 

Public Attributes

bool m_ignoreHidden
 
KisSizeGroup::mode m_mode
 
KisSizeGroupq
 

Private Slots

void updateSize ()
 

Private Attributes

QList< GroupItem * > m_groupItems
 
QSize m_sizeHint
 
QTimer * m_updateTimer
 

Detailed Description

Definition at line 22 of file kis_size_group_p.h.

Constructor & Destructor Documentation

◆ KisSizeGroupPrivate()

KisSizeGroupPrivate::KisSizeGroupPrivate ( KisSizeGroup * q_ptr,
KisSizeGroup::mode mode,
bool ignoreHidden )

Definition at line 16 of file kis_size_group_p.cpp.

17 : QObject()
18 , q(q_ptr)
19 , m_mode(mode)
20 , m_ignoreHidden(ignoreHidden)
21 , m_updateTimer(new QTimer(q))
22 , m_sizeHint(0, 0)
23{
24 Q_ASSERT(q_ptr);
25
26 m_updateTimer->setSingleShot(true);
27 m_updateTimer->setInterval(0);
28 QObject::connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateSize()));
29}
KisSizeGroup::mode m_mode

References m_updateTimer, and updateSize().

Member Function Documentation

◆ addWidget()

void KisSizeGroupPrivate::addWidget ( QWidget * widget)

Definition at line 31 of file kis_size_group_p.cpp.

32{
33 Q_ASSERT(widget);
34
35 QWidget *parent = widget->parentWidget();
36 if (parent) {
37 QLayout *layout = parent->layout();
38 if (layout) {
39 // Search for the widget index and the QLayoutItem inside of the layout
40 QLayoutItem *layoutItem = 0;
41 int layoutWidgetIndex = 0;
42 for(int i = 0; i < layout->count(); ++i) {
43 layoutItem = layout->itemAt(layoutWidgetIndex);
44 if (layoutItem->widget() == widget) break;
45 ++layoutWidgetIndex;
46 }
47
48 // We need to replace the layoutItem with an instance of GroupItem
49 GroupItem *groupItem = dynamic_cast<GroupItem*>(layoutItem);
50 if (groupItem) {
51 // This widget is already inside of a group
52 // One widget inside multiple groups is not supported
53 Q_ASSERT(groupItem->getGroup() == this);
54 } else {
55 // LayoutItem is not an instance of WidgetItem
56 // We need to create a new one
57
58 groupItem = new GroupItem(widget);
59 groupItem->setGroup(this);
60
61 // Now we need to replace the layoutItem with the groupItem.
62 // This step depends on the actual layout specialization.
63
64 // Widget within a QFormLayout
65 QFormLayout* formLayout = qobject_cast<QFormLayout*>(layout);
66 if (formLayout) {
67 int row;
68 QFormLayout::ItemRole role;
69 formLayout->getItemPosition(layoutWidgetIndex, &row, &role);
70 formLayout->removeItem(layoutItem);
71 delete layoutItem;
72 formLayout->setItem(row, role, groupItem);
73 m_groupItems.append(groupItem);
74
75 return;
76 }
77
78 // Widget within a QGridLayout
79 QGridLayout *gridLayout = qobject_cast<QGridLayout*>(layout);
80 if (gridLayout) {
81 int row, column, rowspan, columnspan;
82 gridLayout->getItemPosition(layoutWidgetIndex, &row, &column, &rowspan, &columnspan);
83 gridLayout->removeItem(layoutItem);
84 delete layoutItem;
85 gridLayout->addItem(groupItem, row, column, rowspan, columnspan);
86 m_groupItems.append(groupItem);
87
88 return;
89 }
90
91 // Widget within a QBoxLayout
92 QBoxLayout *boxLayout = qobject_cast<QBoxLayout*>(layout);
93 if (boxLayout) {
94 boxLayout->removeItem(layoutItem);
95 delete layoutItem;
96 boxLayout->insertItem(layoutWidgetIndex, groupItem);
97 m_groupItems.append(groupItem);
98
99 return;
100 }
101 }
102 }
103 }
104
105}
KisSizeGroupPrivate * getGroup()
void setGroup(KisSizeGroupPrivate *group)
QList< GroupItem * > m_groupItems
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References GroupItem::getGroup(), m_groupItems, and GroupItem::setGroup().

◆ getSizeHint()

const QSize KisSizeGroupPrivate::getSizeHint ( ) const
inline

Returns the size hint for the widgets contained in the size group.

Definition at line 36 of file kis_size_group_p.h.

36{ return m_sizeHint; }

References m_sizeHint.

◆ removeWidget()

void KisSizeGroupPrivate::removeWidget ( QWidget * widget)

Definition at line 107 of file kis_size_group_p.cpp.

108{
109 Q_ASSERT(widget);
110
111 QWidget *parent = widget->parentWidget();
112 if (parent) {
113 QLayout *layout = parent->layout();
114 if (layout) {
115 // Search the GroupItem of the widget inside of the GroupItem list
116 GroupItem *widgetGroupItem = 0;
117 Q_FOREACH(GroupItem * groupItem, m_groupItems) {
118 if (groupItem->widget() == widget) {
119 widgetGroupItem = groupItem;
120 break;
121 }
122 }
123
124 if (widgetGroupItem) {
125 m_groupItems.removeAll(widgetGroupItem);
126
127 int layoutWidgetIndex = layout->indexOf(widget);
128
129 // Now we need to replace the GroupItem with a QWidgetItem for the widget.
130 // This step depends on the actual layout specialization.
131
132 // Widget within a QFormLayout
133 QFormLayout* formLayout = qobject_cast<QFormLayout*>(layout);
134 if (formLayout) {
135 int row;
136 QFormLayout::ItemRole role;
137 formLayout->getItemPosition(layoutWidgetIndex, &row, &role);
138 formLayout->removeItem(widgetGroupItem);
139 delete widgetGroupItem;
140 formLayout->setWidget(row, role, widget);
141
142 return;
143 }
144
145 // Widget within a QGridLayout
146 QGridLayout *gridLayout = qobject_cast<QGridLayout*>(layout);
147 if (gridLayout) {
148 int row, column, rowspan, columnspan;
149 gridLayout->getItemPosition(layoutWidgetIndex, &row, &column, &rowspan, &columnspan);
150 gridLayout->removeItem(widgetGroupItem);
151 delete widgetGroupItem;
152 QWidgetItem *widgetItem = new QWidgetItem(widget);
153 gridLayout->addItem(widgetItem, row, column, rowspan, columnspan);
154
155 return;
156 }
157
158 // Widget within a QBoxLayout
159 QBoxLayout *boxLayout = qobject_cast<QBoxLayout*>(layout);
160 if (boxLayout) {
161 boxLayout->removeItem(widgetGroupItem);
162 delete widgetGroupItem;
163 QWidgetItem *widgetItem = new QWidgetItem(widget);
164 boxLayout->insertItem(layoutWidgetIndex, widgetItem);
165
166 return;
167 }
168 }
169 }
170 }
171}

References m_groupItems.

◆ scheduleSizeUpdate()

void KisSizeGroupPrivate::scheduleSizeUpdate ( )

Schedules an update of all widgets size.

Definition at line 173 of file kis_size_group_p.cpp.

174{
175 m_updateTimer->start();
176}

References m_updateTimer.

◆ updateSize

void KisSizeGroupPrivate::updateSize ( )
privateslot

Definition at line 178 of file kis_size_group_p.cpp.

179{
181 // restore original widget size in each GroupItem
182 Q_FOREACH(GroupItem *groupItem, m_groupItems) {
183 groupItem->setSize(groupItem->widget()->sizeHint());
184 groupItem->widget()->updateGeometry();
185 }
186 } else {
187 // compute widgets size
188 int width = 0;
189 int height = 0;
190 Q_FOREACH(GroupItem *groupItem, m_groupItems) {
191 if (m_ignoreHidden && groupItem->hidden())
192 continue;
193
194 const QWidget *widget = groupItem->widget();
195 width = qMax(widget->sizeHint().width(), width);
196 height = qMax(widget->sizeHint().height(), height);
197 }
198
199 m_sizeHint.setWidth(width);
200 m_sizeHint.setHeight(height);
201
202 // update groupItem size
203 Q_FOREACH(GroupItem *groupItem, m_groupItems) {
204 if (m_ignoreHidden && groupItem->hidden())
205 continue;
206
207 switch(m_mode) {
209 groupItem->setWidth(width);
210 break;
211
213 groupItem->setHeight(height);
214 break;
215
217 groupItem->setWidth(width);
218 groupItem->setHeight(height);
219 break;
220
221 default:
222 break;
223 }
224
225 // update layout to the new groupItem size
226 groupItem->widget()->updateGeometry();
227
228 }
229 }
230}
bool hidden() const
void setSize(const QSize &size)
QSize sizeHint() const override
void setHeight(int height)
void setWidth(int width)
@ KIS_SIZE_GROUP_BOTH
group affects vertical size
@ KIS_SIZE_GROUP_VERTICAL
group affects horizontal size
@ KIS_SIZE_GROUP_HORIZONTAL
group has no effect

References GroupItem::hidden(), KisSizeGroup::KIS_SIZE_GROUP_BOTH, KisSizeGroup::KIS_SIZE_GROUP_HORIZONTAL, KisSizeGroup::KIS_SIZE_GROUP_NONE, KisSizeGroup::KIS_SIZE_GROUP_VERTICAL, m_groupItems, m_ignoreHidden, m_mode, m_sizeHint, GroupItem::setHeight(), GroupItem::setSize(), GroupItem::setWidth(), and GroupItem::sizeHint().

Member Data Documentation

◆ m_groupItems

QList<GroupItem*> KisSizeGroupPrivate::m_groupItems
private

Definition at line 49 of file kis_size_group_p.h.

◆ m_ignoreHidden

bool KisSizeGroupPrivate::m_ignoreHidden

Definition at line 45 of file kis_size_group_p.h.

◆ m_mode

KisSizeGroup::mode KisSizeGroupPrivate::m_mode

Definition at line 44 of file kis_size_group_p.h.

◆ m_sizeHint

QSize KisSizeGroupPrivate::m_sizeHint
private

Definition at line 50 of file kis_size_group_p.h.

◆ m_updateTimer

QTimer* KisSizeGroupPrivate::m_updateTimer
private

Definition at line 48 of file kis_size_group_p.h.

◆ q

KisSizeGroup* KisSizeGroupPrivate::q

Definition at line 43 of file kis_size_group_p.h.


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