Krita Source Code Documentation
Loading...
Searching...
No Matches
KisOptionCollectionWidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2022 Deif Lou <ginoba@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include <QWidget>
8#include <QFrame>
9#include <QLabel>
10#include <QScrollArea>
11#include <QVariant>
12#include <QBoxLayout>
13#include <QStringRef>
14
15#include <kis_assert.h>
16
18
20{
21 Q_OBJECT
22
23public:
24 KisOptionCollectionWidgetWrapper(QWidget *parent, QWidget *widget)
25 : QWidget(parent)
27 , m_margin(0)
28 {
29 m_widget->setParent(this);
30
31 setSizePolicy(widget->sizePolicy());
32
33 QBoxLayout *layoutWidget = new QBoxLayout(QBoxLayout::TopToBottom);
34 layoutWidget->setContentsMargins(m_margin, 0, m_margin, 0);
35 layoutWidget->setSpacing(0);
36 layoutWidget->addWidget(m_widget);
37
38 m_separator = new QFrame(this);
39 m_separator->setFrameShape(QFrame::HLine);
40 m_separator->setFrameShadow(QFrame::Sunken);
41 m_separator->setFixedHeight(10);
42
43 QBoxLayout *layoutMain = new QBoxLayout(QBoxLayout::LeftToRight);
44 layoutMain->setContentsMargins(0, 0, 0, 0);
45 layoutMain->setSpacing(0);
46 layoutMain->addLayout(layoutWidget);
47 layoutMain->addWidget(m_separator);
48
49 setLayout(layoutMain);
50 }
51
53
54 QWidget* widget() const
55 {
56 return m_widget;
57 }
58
59 void setSeparatorVisible(bool visible)
60 {
61 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
62 KIS_ASSERT(layoutMain);
63
64 const bool isVisible = layoutMain->count() > 1;
65 if (isVisible == visible) {
66 return;
67 }
68 if (isVisible) {
69 layoutMain->takeAt(1);
70 m_separator->setVisible(false);
71 } else {
72 layoutMain->insertWidget(1, m_separator);
73 m_separator->setVisible(true);
74 }
75 }
76
77 void setOrientation(Qt::Orientation orientation)
78 {
79 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
80 KIS_ASSERT(layoutMain);
81 QBoxLayout *layoutWidget = dynamic_cast<QBoxLayout*>(layoutMain->itemAt(0)->layout());
82 KIS_ASSERT(layoutWidget);
83
84 if (orientation == Qt::Vertical) {
85 if (layoutMain->direction() == QBoxLayout::TopToBottom) {
86 return;
87 }
88 layoutWidget->setContentsMargins(m_margin, 0, m_margin, 0);
89 m_separator->setFixedSize(QWIDGETSIZE_MAX, 10);
90 m_separator->setFrameShape(QFrame::HLine);
91 layoutMain->setDirection(QBoxLayout::TopToBottom);
92 } else {
93 if (layoutMain->direction() == QBoxLayout::LeftToRight) {
94 return;
95 }
96 layoutWidget->setContentsMargins(0, 0, 0, 0);
97 m_separator->setFixedSize(20, QWIDGETSIZE_MAX);
98 m_separator->setFrameShape(QFrame::VLine);
99 layoutMain->setDirection(QBoxLayout::LeftToRight);
100 }
101 }
102
103 void setWidgetMargin(int margin)
104 {
105 if (m_margin == margin) {
106 return;
107 }
108 m_margin = margin;
109 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
110 if (layoutMain->direction() == QBoxLayout::TopToBottom) {
111 QBoxLayout *layoutWidget = dynamic_cast<QBoxLayout*>(layoutMain->itemAt(0)->layout());
112 KIS_SAFE_ASSERT_RECOVER_RETURN(layoutWidget);
113 layoutWidget->setContentsMargins(margin, 0, margin, 0);
114 }
115 }
116
117private:
118 QWidget *m_widget;
119 QFrame *m_separator;
121};
122
124{
126 QLabel *label{nullptr};
127 QWidget *primaryWidget{nullptr};
129 QBoxLayout *layoutHeader{nullptr};
130 QBoxLayout *layoutPrimaryWidget{nullptr};
131 QBoxLayout *layoutWidgets{nullptr};
132 Qt::Orientation orientation{Qt::Vertical};
133
135
137 {
138 if (!primaryWidget || !primaryWidget->isVisible()) {
139 return;
140 }
141
142 if (orientation == Qt::Horizontal) {
143 if (layoutHeader->direction() == QBoxLayout::LeftToRight) {
144 return;
145 }
146 layoutHeader->setDirection(QBoxLayout::LeftToRight);
147 layoutHeader->setSpacing(10);
148 layoutPrimaryWidget->setContentsMargins(0, 0, 0, 0);
149 return;
150 }
151 // label.width + primaryWidget.size + 10px spacing + 4px extra (just in case)
152 const int minimumHeaderWidth = label->minimumSizeHint().width() +
153 primaryWidget->minimumSizeHint().width() +
154 10 + 4;
155 if (q->width() < minimumHeaderWidth) {
156 if (layoutHeader->direction() == QBoxLayout::TopToBottom) {
157 return;
158 }
159 layoutHeader->setDirection(QBoxLayout::TopToBottom);
160 layoutHeader->setSpacing(5);
161 layoutPrimaryWidget->setContentsMargins(5, 0, 0, 0);
162 } else {
163 if (layoutHeader->direction() == QBoxLayout::LeftToRight) {
164 return;
165 }
166 layoutHeader->setDirection(QBoxLayout::LeftToRight);
167 layoutHeader->setSpacing(10);
168 layoutPrimaryWidget->setContentsMargins(0, 0, 0, 0);
169 }
170 }
171
173 {
174 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(q->layout());
175 KIS_ASSERT(layoutMain);
176 if (layoutMain->indexOf(layoutWidgets) == -1) {
178 return;
179 }
180 layoutMain->insertLayout(1, layoutWidgets, 1);
181 widgetCollection->setVisible(true);
182 } else {
184 return;
185 }
186 layoutMain->takeAt(1);
187 widgetCollection->setVisible(false);
188 }
189 }
190
191};
192
194{
197 bool showSeparators{false};
198 Qt::Orientation orientation{Qt::Vertical};
200
202
203 void insertWidget(int index, const QString &id, QWidget *widget)
204 {
205 KisOptionCollectionWidgetWrapper *widgetWrapper =
207 widgetWrapper->setProperty("id", id);
208 widgetWrapper->setSeparatorVisible(showSeparators);
209 widgetWrapper->setOrientation(orientation);
210 widgetWrapper->setWidgetMargin(widgetsMargin);
211 widgetWrappers.insert(index, widgetWrapper);
212
213 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(q->layout());
214 KIS_ASSERT(layoutMain);
215
216 int indexLayout;
217 for (indexLayout = 0; indexLayout < layoutMain->count(); ++indexLayout) {
218 const QWidget *prevWidget = layoutMain->itemAt(indexLayout)->widget();
219 const int prevIndex = q->widgetIndexFromId(prevWidget->property("id").toString());
220 if (prevIndex >= index) {
221 break;
222 }
223 }
224 layoutMain->insertWidget(indexLayout, widgetWrapper);
226 }
227
229 {
230 if (q->layout()->count() == 0) {
231 return;
232 }
233 for (int i = 0; i < q->layout()->count() - 1; ++i) {
234 KisOptionCollectionWidgetWrapper *widgetWrapper =
235 qobject_cast<KisOptionCollectionWidgetWrapper*>(q->layout()->itemAt(i)->widget());
236 widgetWrapper->setSeparatorVisible(showSeparators);
237 }
238 KisOptionCollectionWidgetWrapper *lastWidgetWrapper =
239 qobject_cast<KisOptionCollectionWidgetWrapper*>(q->layout()->itemAt(q->layout()->count() - 1)->widget());
240 lastWidgetWrapper->setSeparatorVisible(false);
241 }
242
243 int widgetIndexFromId(QStringRef id) const
244 {
245 for (int i = 0; i < widgetWrappers.size(); ++i) {
246 if (widgetWrappers[i]->property("id").toString() == id) {
247 return i;
248 }
249 }
250 return -1;
251 }
252
253 bool containsWidget(QStringRef id) const
254 {
255 return widgetIndexFromId(id) != -1;
256 }
257
258 QWidget* widget(int index) const
259 {
260 return widgetWrappers[index]->widget();
261 }
262
263 QWidget* widget(QStringRef id) const
264 {
265 return widget(widgetIndexFromId(id));
266 }
267
268 QWidget* findWidget(QStringRef path, QWidget *candidate = nullptr) const
269 {
270 while (path.startsWith('/')) {
271 path = path.right(path.size() - 1);
272 }
273 if (path.isEmpty()) {
274 return candidate;
275 }
276 const int slashPosition = path.indexOf('/');
277 if (slashPosition == -1) {
278 return widget(path);
279 }
280 QWidget *nextCandidate = widget(path.left(slashPosition));
281 if (nextCandidate) {
282 KisOptionCollectionWidget *optionCollectionWidget =
283 qobject_cast<KisOptionCollectionWidget*>(nextCandidate);
284 if (optionCollectionWidget) {
285 return optionCollectionWidget->m_d->findWidget(path.right(path.size() - slashPosition), nextCandidate);
286 }
287 KisOptionCollectionWidgetWithHeader *optionCollectionWidgetWithHeader =
288 qobject_cast<KisOptionCollectionWidgetWithHeader*>(nextCandidate);
289 if (optionCollectionWidgetWithHeader) {
290 return optionCollectionWidgetWithHeader->m_d->widgetCollection->m_d->findWidget(path.right(path.size() - slashPosition), nextCandidate);
291 }
292 QStringRef rest = path.right(path.size() - slashPosition);
293 while (rest.startsWith('/')) {
294 rest = rest.right(rest.size() - 1);
295 }
296 if (rest.isEmpty()) {
297 return nextCandidate;
298 }
299 }
300 return nullptr;
301 }
302};
303
305 : QWidget(parent)
306 , m_d(new Private(this))
307{
308 QBoxLayout *layoutMain = new QBoxLayout(QBoxLayout::TopToBottom);
309 layoutMain->setSpacing(5);
310 layoutMain->setContentsMargins(0, 0, 0, 0);
311 setLayout(layoutMain);
312}
313
316
318{
319 return m_d->widgetIndexFromId(&id);
320}
321
322bool KisOptionCollectionWidget::containsWidget(const QString &id) const
323{
324 return m_d->containsWidget(&id);
325}
326
327QWidget* KisOptionCollectionWidget::widget(int index) const
328{
329 return m_d->widget(index);
330}
331
332QWidget* KisOptionCollectionWidget::widget(const QString &id) const
333{
334 return m_d->widget(&id);
335}
336
337QWidget* KisOptionCollectionWidget::findWidget(const QString &path) const
338{
339 return m_d->findWidget(&path);
340}
341
342void KisOptionCollectionWidget::insertWidget(int index, const QString &id, QWidget *widget)
343{
344 if (containsWidget(id)) {
345 return;
346 }
347 m_d->insertWidget(index, id, widget);
348}
349
350void KisOptionCollectionWidget::appendWidget(const QString &id, QWidget *widget)
351{
352 insertWidget(m_d->widgetWrappers.size(), id, widget);
353}
354
356{
357 delete takeWidget(index);
358}
359
364
366{
367 QWidget* widget = m_d->widgetWrappers[index]->widget();
368 widget->setParent(nullptr);
369 m_d->widgetWrappers.removeAt(index);
370 m_d->adjustSeparators();
371 return widget;
372}
373
374QWidget* KisOptionCollectionWidget::takeWidget(const QString &id)
375{
376 return takeWidget(widgetIndexFromId(id));
377}
378
380{
381 KisOptionCollectionWidgetWrapper *widgetWrapper = m_d->widgetWrappers[index];
382
383 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
385
386 if (visible) {
387 if (layoutMain->indexOf(widgetWrapper) != -1) {
388 return;
389 }
390 int indexLayout;
391 for (indexLayout = 0; indexLayout < layoutMain->count(); ++indexLayout) {
392 const QWidget *prevWidget = layoutMain->itemAt(indexLayout)->widget();
393 const int prevIndex = widgetIndexFromId(prevWidget->property("id").toString());
394 if (prevIndex >= index) {
395 break;
396 }
397 }
398 layoutMain->insertWidget(indexLayout, widgetWrapper);
399 widgetWrapper->setVisible(true);
400 } else {
401 if (layoutMain->indexOf(widgetWrapper) == -1) {
402 return;
403 }
404 layoutMain->takeAt(layoutMain->indexOf(widgetWrapper));
405 widgetWrapper->setVisible(false);
406 }
407
408 m_d->adjustSeparators();
409}
410
411void KisOptionCollectionWidget::setWidgetVisible(const QString &id, bool visible)
412{
414}
415
417{
418 if (margin == m_d->widgetsMargin) {
419 return;
420 }
421 m_d->widgetsMargin = margin;
422 for (KisOptionCollectionWidgetWrapper *widgetWrapper : m_d->widgetWrappers) {
423 widgetWrapper->setWidgetMargin(margin);
424 }
425}
426
428{
429 if (visible == m_d->showSeparators) {
430 return;
431 }
432 m_d->showSeparators = visible;
433 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
434 layoutMain->setSpacing(visible ? 0 : 5);
435 m_d->adjustSeparators();
436}
437
438void KisOptionCollectionWidget::setOrientation(Qt::Orientation orientation, bool recursive)
439{
440 if (orientation == m_d->orientation) {
441 return;
442 }
443 m_d->orientation = orientation;
444 for (KisOptionCollectionWidgetWrapper *widgetWrapper : m_d->widgetWrappers) {
445 widgetWrapper->setOrientation(orientation);
446 if (recursive) {
447 KisOptionCollectionWidget *optionCollectionWidget =
448 qobject_cast<KisOptionCollectionWidget*>(widgetWrapper->widget());
449 if (optionCollectionWidget) {
450 optionCollectionWidget->setOrientation(orientation, true);
451 continue;
452 }
453 KisOptionCollectionWidgetWithHeader *optionCollectionWidgetWithHeader =
454 qobject_cast<KisOptionCollectionWidgetWithHeader*>(widgetWrapper->widget());
455 if (optionCollectionWidgetWithHeader) {
456 optionCollectionWidgetWithHeader->setOrientation(orientation, true);
457 }
458 }
459 }
460 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
461 layoutMain->setDirection(orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
462}
463
465{
466 return m_d->widgetWrappers.size();
467}
468
470{
471 return layout()->count();
472}
473
475 QWidget *parent)
476 : QWidget(parent)
477 , m_d(new Private(this))
478{
479 m_d->label = new QLabel(title, this);
480
481 m_d->layoutPrimaryWidget = new QBoxLayout(QBoxLayout::LeftToRight);
482 m_d->layoutPrimaryWidget->setSpacing(0);
483 m_d->layoutPrimaryWidget->setContentsMargins(0, 0, 0, 0);
484
485 m_d->layoutHeader = new QBoxLayout(QBoxLayout::LeftToRight);
486 m_d->layoutHeader->setSpacing(10);
487 m_d->layoutHeader->setContentsMargins(0, 0, 0, 0);
488 m_d->layoutHeader->addWidget(m_d->label, 0);
489
490 m_d->widgetCollection = new KisOptionCollectionWidget(this);
491 m_d->widgetCollection->setWidgetsMargin(0);
492 m_d->widgetCollection->setVisible(false);
493
494 m_d->layoutWidgets = new QBoxLayout(QBoxLayout::TopToBottom);
495 m_d->layoutWidgets->setSpacing(0);
496 m_d->layoutWidgets->setContentsMargins(5, 0, 0, 0);
497 m_d->layoutWidgets->addWidget(m_d->widgetCollection);
498
499 QBoxLayout *layoutMain = new QBoxLayout(QBoxLayout::TopToBottom);
500 layoutMain->setSpacing(5);
501 layoutMain->setContentsMargins(0, 0, 0, 0);
502 layoutMain->addLayout(m_d->layoutHeader, 0);
503
504 setLayout(layoutMain);
505}
506
509
511{
512 if (m_d->orientation == Qt::Horizontal) {
513 return QWidget::minimumSizeHint();
514 }
515
516 const QSize widgetListMinimumSizeHint = m_d->layoutWidgets->minimumSize();
517 // label.width + primaryWidget.size + 10px spacing + 4px extra (just in case)
518 const int minimumHeaderWidth = m_d->label->minimumSizeHint().width() +
519 (m_d->primaryWidget ? m_d->primaryWidget->minimumSizeHint().width() + 10 + 4 : 0);
520 const QSize headerMinimumSizeHint =
521 QSize(
522 qMax(
523 m_d->label->minimumSizeHint().width(),
524 m_d->primaryWidget ? m_d->layoutPrimaryWidget->minimumSize().width() : 0
525 ),
526 width() < minimumHeaderWidth
527 ? m_d->label->minimumSizeHint().height() +
528 (m_d->primaryWidget && m_d->primaryWidget->isVisible()
529 ? m_d->layoutPrimaryWidget->minimumSize().height() + m_d->layoutHeader->spacing() : 0)
530 : qMax(
531 m_d->label->minimumSizeHint().height(),
532 m_d->primaryWidget && m_d->primaryWidget->isVisible()
533 ? m_d->layoutPrimaryWidget->minimumSize().height() : 0
534 )
535 );
536
537 return
538 QSize(
539 qMax(widgetListMinimumSizeHint.width(), headerMinimumSizeHint.width()),
540 headerMinimumSizeHint.height() +
541 (m_d->widgetCollection->numberOfVisibleWidgets() > 0 ? widgetListMinimumSizeHint.height() + layout()->spacing() : 0)
542 );
543}
544
546{
547 return m_d->primaryWidget;
548}
549
551{
552 if (widget == m_d->primaryWidget) {
553 return;
554 }
555 const bool wasPrimaryWidgetVisible =
556 m_d->primaryWidget ? m_d->primaryWidget->isVisible() : true;
558 if (!widget) {
559 return;
560 }
561 m_d->primaryWidget = widget;
562 widget->setParent(this);
563 m_d->layoutPrimaryWidget->insertWidget(0, widget);
564
565 if (!wasPrimaryWidgetVisible) {
566 widget->setVisible(false);
567 return;
568 }
569
570 m_d->layoutHeader->insertLayout(1, m_d->layoutPrimaryWidget, 1);
571 widget->setVisible(true);
572 m_d->adjustPrimaryWidget();
573}
574
576{
577 if (!m_d->primaryWidget) {
578 return;
579 }
580 delete takePrimaryWidget();
581}
582
584{
585 QWidget *widget = m_d->primaryWidget;
586 if (!widget) {
587 return nullptr;
588 }
589 m_d->primaryWidget = nullptr;
590 widget->setParent(nullptr);
591 m_d->layoutHeader->takeAt(1);
592 m_d->adjustPrimaryWidget();
593 return widget;
594
595}
596
598{
599 KIS_ASSERT_RECOVER_RETURN(m_d->primaryWidget);
600
601 if (visible) {
602 if (m_d->layoutHeader->count() == 2) {
603 return;
604 }
605 m_d->layoutHeader->insertLayout(1, m_d->layoutPrimaryWidget, 1);
606 m_d->primaryWidget->setVisible(true);
607 m_d->adjustPrimaryWidget();
608 } else {
609 if (m_d->layoutHeader->count() == 1) {
610 return;
611 }
612 m_d->layoutHeader->takeAt(1);
613 m_d->primaryWidget->setVisible(false);
614 }
615}
616
618{
619 return m_d->widgetCollection->widgetIndexFromId(id);
620}
621
623{
624 return m_d->widgetCollection->containsWidget(id);
625}
626
628{
629 return m_d->widgetCollection->widget(index);
630}
631
632QWidget* KisOptionCollectionWidgetWithHeader::widget(const QString &id) const
633{
634 return m_d->widgetCollection->widget(id);
635}
636
637QWidget* KisOptionCollectionWidgetWithHeader::findWidget(const QString &path) const
638{
639 return m_d->widgetCollection->findWidget(path);
640}
641
642void KisOptionCollectionWidgetWithHeader::insertWidget(int index, const QString &id, QWidget *widget)
643{
644 m_d->widgetCollection->insertWidget(index, id, widget);
645 m_d->adjustWidgetCollection();
646}
647
648void KisOptionCollectionWidgetWithHeader::appendWidget(const QString &id, QWidget *widget)
649{
650 m_d->widgetCollection->appendWidget(id, widget);
651 m_d->adjustWidgetCollection();
652}
653
655{
656 m_d->widgetCollection->removeWidget(index);
657 m_d->adjustWidgetCollection();
658}
659
661{
662 m_d->widgetCollection->removeWidget(id);
663 m_d->adjustWidgetCollection();
664}
665
667{
668 QWidget *w = m_d->widgetCollection->takeWidget(index);
669 m_d->adjustWidgetCollection();
670 return w;
671}
672
674{
675 QWidget *w = m_d->widgetCollection->takeWidget(id);
676 m_d->adjustWidgetCollection();
677 return w;
678}
679
681{
682 m_d->widgetCollection->setWidgetVisible(index, visible);
683 m_d->adjustWidgetCollection();
684}
685
686void KisOptionCollectionWidgetWithHeader::setWidgetVisible(const QString &id, bool visible)
687{
688 m_d->widgetCollection->setWidgetVisible(id, visible);
689 m_d->adjustWidgetCollection();
690}
691
693{
694 m_d->widgetCollection->setWidgetsMargin(margin);
695}
696
698{
699 m_d->widgetCollection->setSeparatorsVisible(visible);
700}
701
702void KisOptionCollectionWidgetWithHeader::setOrientation(Qt::Orientation orientation, bool recursive)
703{
704 if (orientation == m_d->orientation) {
705 return;
706 }
707 m_d->orientation = orientation;
708 m_d->adjustPrimaryWidget();
709 m_d->widgetCollection->setOrientation(orientation, recursive);
710 m_d->layoutWidgets->setDirection(orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
711 QBoxLayout *layoutMain = dynamic_cast<QBoxLayout*>(layout());
712 layoutMain->setDirection(orientation == Qt::Vertical ? QBoxLayout::TopToBottom : QBoxLayout::LeftToRight);
713}
714
716{
717 return m_d->widgetCollection->size();
718}
719
721{
722 return m_d->widgetCollection->numberOfVisibleWidgets();
723}
724
726{
727 m_d->adjustPrimaryWidget();
728}
729
730#include "KisOptionCollectionWidget.moc"
Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an...
void setPrimaryWidget(QWidget *widget)
Set the primary widget. The list widget takes ownership of it.
void appendWidget(const QString &id, QWidget *widget)
Insert the given widget with the given id at the end of the list. The list widget takes ownership of ...
QWidget * takeWidget(int index)
Remove the widget that is at the given position from the list. The widget is returned instead of bein...
int size() const
Get the number of widgets in the list.
QWidget * findWidget(const QString &path) const
Get the widget that is at the given path. The path must be a forward slash separated list of ids....
void removeWidget(int index)
Remove the widget that is at the given position from the list. This also destroys the widget.
void setWidgetsMargin(int margin)
Set the margins of the widgets. This allows to indent the widgets with respect to the separators....
void setSeparatorsVisible(bool visible)
Set the visibility of the separators.
void insertWidget(int index, const QString &id, QWidget *widget)
Insert the given widget with the given id at the given position. The list widget takes ownership of t...
void setPrimaryWidgetVisible(bool visible)
Set the visibility of the primary widget. Use this function instead of the widget one directly to get...
bool containsWidget(const QString &id) const
Get if the list contains a widget with the given id.
QWidget * primaryWidget() const
Get the primary widget.
KisOptionCollectionWidgetWithHeader(const QString &title, QWidget *parent=nullptr)
void removePrimaryWidget()
Remove the primary widget. This also destroys it.
int widgetIndexFromId(const QString &id) const
Get the index of the widget that has the given id.
void setWidgetVisible(int index, bool visible)
Set the visibility of the widget that is at the given position.
int numberOfVisibleWidgets() const
Get the number of visible widgets in the list.
QWidget * widget(int index) const
Get the widget that is at the given position.
void setOrientation(Qt::Orientation orientation, bool recursive=false)
Set the orientation of the list of widgets.
QWidget * takePrimaryWidget()
Remove the primary widget. The widget is returned instead of being destroyed.
KisOptionCollectionWidgetWrapper(QWidget *parent, QWidget *widget)
void setOrientation(Qt::Orientation orientation)
Class providing a list of widgets with some addons such as separators, orientation or individual widg...
int numberOfVisibleWidgets() const
Get the number of visible widgets in the list.
void insertWidget(int index, const QString &id, QWidget *widget)
Insert the given widget with the given id at the given position. The list widget takes ownership of t...
QWidget * widget(int index) const
Get the widget that is at the given position.
bool containsWidget(const QString &id) const
Get if the list contains a widget with the given id.
void setWidgetsMargin(int margin)
Set the margins of the widgets. This allows to indent the widgets with respect to the separators....
void setOrientation(Qt::Orientation orientation, bool recursive=false)
Set the orientation of the list of widgets.
KisOptionCollectionWidget(QWidget *parent=nullptr)
QWidget * findWidget(const QString &path) const
Get the widget that is at the given path. The path must be a forward slash separated list of ids....
int size() const
Get the number of widgets in the list.
void removeWidget(int index)
Remove the widget that is at the given position from the list. This also destroys the widget.
void setWidgetVisible(int index, bool visible)
Set the visibility of the widget that is at the given position. Use this function instead of the widg...
QWidget * takeWidget(int index)
Remove the widget that is at the given position from the list. The widget is returned instead of bein...
void appendWidget(const QString &id, QWidget *widget)
Insert the given widget with the given id at the end of the list. The list widget takes ownership of ...
void setSeparatorsVisible(bool visible)
Set the visibility of the separators.
int widgetIndexFromId(const QString &id) const
Get the index of the widget that has the given id.
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
Private(KisOptionCollectionWidgetWithHeader *q)
QWidget * findWidget(QStringRef path, QWidget *candidate=nullptr) const
QVector< KisOptionCollectionWidgetWrapper * > widgetWrappers
void insertWidget(int index, const QString &id, QWidget *widget)