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

Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an optional primary widget. More...

#include <KisOptionCollectionWidget.h>

+ Inheritance diagram for KisOptionCollectionWidgetWithHeader:

Classes

struct  Private
 

Public Member Functions

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 the inserted widget.
 
bool containsWidget (const QString &id) const
 Get if the list contains a widget with the given id.
 
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. If the list contains some other KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, and they do as well, then they form a hierarchy tree, so the path is searched recursively through all those child widgets.
 
template<typename T >
findWidgetAs (const QString &path) const
 Get the widget that is at the given path casted to some other class.
 
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 the inserted widget.
 
 KisOptionCollectionWidgetWithHeader (const QString &title, QWidget *parent=nullptr)
 
QSize minimumSizeHint () const override
 
int numberOfVisibleWidgets () const
 Get the number of visible widgets in the list.
 
QWidget * primaryWidget () const
 Get the primary widget.
 
template<typename T >
primaryWidgetAs () const
 Get the primary widget casted to some other class.
 
void removePrimaryWidget ()
 Remove the primary widget. This also destroys it.
 
void removeWidget (const QString &id)
 Remove the widget that has the given id from the list. This also destroys the widget.
 
void removeWidget (int index)
 Remove the widget that is at the given position from the list. This also destroys the widget.
 
void setOrientation (Qt::Orientation orientation, bool recursive=false)
 Set the orientation of the list of widgets.
 
void setPrimaryWidget (QWidget *widget)
 Set the primary widget. The list widget takes ownership of it.
 
void setPrimaryWidgetVisible (bool visible)
 Set the visibility of the primary widget. Use this function instead of the widget one directly to get better visual results.
 
void setSeparatorsVisible (bool visible)
 Set the visibility of the separators.
 
void setWidgetsMargin (int margin)
 Set the margins of the widgets. This allows to indent the widgets with respect to the separators. The separators themselves are not changed.
 
void setWidgetVisible (const QString &id, bool visible)
 Set the visibility 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 size () const
 Get the number of widgets in the list.
 
QWidget * takePrimaryWidget ()
 Remove the primary widget. The widget is returned instead of being destroyed.
 
QWidget * takeWidget (const QString &id)
 Remove the widget that has the given id from the list. The widget is returned instead of being destroyed.
 
QWidget * takeWidget (int index)
 Remove the widget that is at the given position from the list. The widget is returned instead of being destroyed.
 
QWidget * widget (const QString &id) const
 Get the widget with the given id.
 
QWidget * widget (int index) const
 Get the widget that is at the given position.
 
template<typename T >
widgetAs (const QString &id) const
 Get the widget with the given id casted to some other class.
 
template<typename T >
widgetAs (int index) const
 Get the widget that is at the given position casted to some other class.
 
int widgetIndexFromId (const QString &id) const
 Get the index of the widget that has the given id.
 
 ~KisOptionCollectionWidgetWithHeader () override
 

Protected Member Functions

void resizeEvent (QResizeEvent *) override
 

Private Attributes

QScopedPointer< Privatem_d
 

Friends

class KisOptionCollectionWidget
 

Detailed Description

Wrapper class around a KisOptionCollectionWidget that also provide a header with a title label and an optional primary widget.

Definition at line 164 of file KisOptionCollectionWidget.h.

Constructor & Destructor Documentation

◆ KisOptionCollectionWidgetWithHeader()

KisOptionCollectionWidgetWithHeader::KisOptionCollectionWidgetWithHeader ( const QString & title,
QWidget * parent = nullptr )

Definition at line 474 of file KisOptionCollectionWidget.cpp.

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}

References KisOptionCollectionWidget, and m_d.

◆ ~KisOptionCollectionWidgetWithHeader()

KisOptionCollectionWidgetWithHeader::~KisOptionCollectionWidgetWithHeader ( )
override

Definition at line 507 of file KisOptionCollectionWidget.cpp.

508{}

Member Function Documentation

◆ appendWidget()

void KisOptionCollectionWidgetWithHeader::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 the inserted widget.

Definition at line 648 of file KisOptionCollectionWidget.cpp.

649{
650 m_d->widgetCollection->appendWidget(id, widget);
651 m_d->adjustWidgetCollection();
652}
QWidget * widget(int index) const
Get the widget that is at the given position.

References m_d, and widget().

◆ containsWidget()

bool KisOptionCollectionWidgetWithHeader::containsWidget ( const QString & id) const

Get if the list contains a widget with the given id.

Definition at line 622 of file KisOptionCollectionWidget.cpp.

623{
624 return m_d->widgetCollection->containsWidget(id);
625}

References m_d.

◆ findWidget()

QWidget * KisOptionCollectionWidgetWithHeader::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. If the list contains some other KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, and they do as well, then they form a hierarchy tree, so the path is searched recursively through all those child widgets.

Definition at line 637 of file KisOptionCollectionWidget.cpp.

638{
639 return m_d->widgetCollection->findWidget(path);
640}

References m_d.

◆ findWidgetAs()

template<typename T >
T KisOptionCollectionWidgetWithHeader::findWidgetAs ( const QString & path) const
inline

Get the widget that is at the given path casted to some other class.

See also
findWidget

Definition at line 253 of file KisOptionCollectionWidget.h.

254 {
255 return qobject_cast<T>(findWidget(path));
256 }
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....

◆ insertWidget()

void KisOptionCollectionWidgetWithHeader::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 the inserted widget.

Definition at line 642 of file KisOptionCollectionWidget.cpp.

643{
644 m_d->widgetCollection->insertWidget(index, id, widget);
645 m_d->adjustWidgetCollection();
646}

References m_d, and widget().

◆ minimumSizeHint()

QSize KisOptionCollectionWidgetWithHeader::minimumSizeHint ( ) const
override

Definition at line 510 of file KisOptionCollectionWidget.cpp.

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}
QWidget * primaryWidget() const
Get the primary widget.

References m_d.

◆ numberOfVisibleWidgets()

int KisOptionCollectionWidgetWithHeader::numberOfVisibleWidgets ( ) const

Get the number of visible widgets in the list.

Definition at line 720 of file KisOptionCollectionWidget.cpp.

721{
722 return m_d->widgetCollection->numberOfVisibleWidgets();
723}

References m_d.

◆ primaryWidget()

QWidget * KisOptionCollectionWidgetWithHeader::primaryWidget ( ) const

Get the primary widget.

Definition at line 545 of file KisOptionCollectionWidget.cpp.

546{
547 return m_d->primaryWidget;
548}

References m_d.

◆ primaryWidgetAs()

template<typename T >
T KisOptionCollectionWidgetWithHeader::primaryWidgetAs ( ) const
inline

Get the primary widget casted to some other class.

Definition at line 181 of file KisOptionCollectionWidget.h.

182 {
183 return qobject_cast<T>(primaryWidget());
184 }

◆ removePrimaryWidget()

void KisOptionCollectionWidgetWithHeader::removePrimaryWidget ( )

Remove the primary widget. This also destroys it.

Definition at line 575 of file KisOptionCollectionWidget.cpp.

576{
577 if (!m_d->primaryWidget) {
578 return;
579 }
580 delete takePrimaryWidget();
581}
QWidget * takePrimaryWidget()
Remove the primary widget. The widget is returned instead of being destroyed.

References m_d, and takePrimaryWidget().

◆ removeWidget() [1/2]

void KisOptionCollectionWidgetWithHeader::removeWidget ( const QString & id)

Remove the widget that has the given id from the list. This also destroys the widget.

Definition at line 660 of file KisOptionCollectionWidget.cpp.

661{
662 m_d->widgetCollection->removeWidget(id);
663 m_d->adjustWidgetCollection();
664}

References m_d.

◆ removeWidget() [2/2]

void KisOptionCollectionWidgetWithHeader::removeWidget ( int index)

Remove the widget that is at the given position from the list. This also destroys the widget.

Definition at line 654 of file KisOptionCollectionWidget.cpp.

655{
656 m_d->widgetCollection->removeWidget(index);
657 m_d->adjustWidgetCollection();
658}

References m_d.

◆ resizeEvent()

void KisOptionCollectionWidgetWithHeader::resizeEvent ( QResizeEvent * )
overrideprotected

Definition at line 725 of file KisOptionCollectionWidget.cpp.

726{
727 m_d->adjustPrimaryWidget();
728}

References m_d.

◆ setOrientation()

void KisOptionCollectionWidgetWithHeader::setOrientation ( Qt::Orientation orientation,
bool recursive = false )

Set the orientation of the list of widgets.

Parameters
recursiveIf set to true and the list contains some KisOptionCollectionWidget or KisOptionCollectionWidgetWithHeader, then the orientation of those child widgets is also set, with the same recursive value

Definition at line 702 of file KisOptionCollectionWidget.cpp.

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}

References m_d.

◆ setPrimaryWidget()

void KisOptionCollectionWidgetWithHeader::setPrimaryWidget ( QWidget * widget)

Set the primary widget. The list widget takes ownership of it.

Definition at line 550 of file KisOptionCollectionWidget.cpp.

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}
void removePrimaryWidget()
Remove the primary widget. This also destroys it.

References m_d, removePrimaryWidget(), and widget().

◆ setPrimaryWidgetVisible()

void KisOptionCollectionWidgetWithHeader::setPrimaryWidgetVisible ( bool visible)

Set the visibility of the primary widget. Use this function instead of the widget one directly to get better visual results.

Definition at line 597 of file KisOptionCollectionWidget.cpp.

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}
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75

References KIS_ASSERT_RECOVER_RETURN, and m_d.

◆ setSeparatorsVisible()

void KisOptionCollectionWidgetWithHeader::setSeparatorsVisible ( bool visible)

Set the visibility of the separators.

Definition at line 697 of file KisOptionCollectionWidget.cpp.

698{
699 m_d->widgetCollection->setSeparatorsVisible(visible);
700}

References m_d.

◆ setWidgetsMargin()

void KisOptionCollectionWidgetWithHeader::setWidgetsMargin ( int margin)

Set the margins of the widgets. This allows to indent the widgets with respect to the separators. The separators themselves are not changed.

Definition at line 692 of file KisOptionCollectionWidget.cpp.

693{
694 m_d->widgetCollection->setWidgetsMargin(margin);
695}

References m_d.

◆ setWidgetVisible() [1/2]

void KisOptionCollectionWidgetWithHeader::setWidgetVisible ( const QString & id,
bool visible )

Set the visibility of the widget that has the given id.

Definition at line 686 of file KisOptionCollectionWidget.cpp.

687{
688 m_d->widgetCollection->setWidgetVisible(id, visible);
689 m_d->adjustWidgetCollection();
690}

References m_d.

◆ setWidgetVisible() [2/2]

void KisOptionCollectionWidgetWithHeader::setWidgetVisible ( int index,
bool visible )

Set the visibility of the widget that is at the given position.

Definition at line 680 of file KisOptionCollectionWidget.cpp.

681{
682 m_d->widgetCollection->setWidgetVisible(index, visible);
683 m_d->adjustWidgetCollection();
684}

References m_d.

◆ size()

int KisOptionCollectionWidgetWithHeader::size ( ) const

Get the number of widgets in the list.

Definition at line 715 of file KisOptionCollectionWidget.cpp.

716{
717 return m_d->widgetCollection->size();
718}

References m_d.

◆ takePrimaryWidget()

QWidget * KisOptionCollectionWidgetWithHeader::takePrimaryWidget ( )

Remove the primary widget. The widget is returned instead of being destroyed.

Definition at line 583 of file KisOptionCollectionWidget.cpp.

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}

References m_d, and widget().

◆ takeWidget() [1/2]

QWidget * KisOptionCollectionWidgetWithHeader::takeWidget ( const QString & id)

Remove the widget that has the given id from the list. The widget is returned instead of being destroyed.

Definition at line 673 of file KisOptionCollectionWidget.cpp.

674{
675 QWidget *w = m_d->widgetCollection->takeWidget(id);
676 m_d->adjustWidgetCollection();
677 return w;
678}

References m_d.

◆ takeWidget() [2/2]

QWidget * KisOptionCollectionWidgetWithHeader::takeWidget ( int index)

Remove the widget that is at the given position from the list. The widget is returned instead of being destroyed.

Definition at line 666 of file KisOptionCollectionWidget.cpp.

667{
668 QWidget *w = m_d->widgetCollection->takeWidget(index);
669 m_d->adjustWidgetCollection();
670 return w;
671}

References m_d.

◆ widget() [1/2]

QWidget * KisOptionCollectionWidgetWithHeader::widget ( const QString & id) const

Get the widget with the given id.

Definition at line 632 of file KisOptionCollectionWidget.cpp.

633{
634 return m_d->widgetCollection->widget(id);
635}

References m_d.

◆ widget() [2/2]

QWidget * KisOptionCollectionWidgetWithHeader::widget ( int index) const

Get the widget that is at the given position.

Definition at line 627 of file KisOptionCollectionWidget.cpp.

628{
629 return m_d->widgetCollection->widget(index);
630}

References m_d.

◆ widgetAs() [1/2]

template<typename T >
T KisOptionCollectionWidgetWithHeader::widgetAs ( const QString & id) const
inline

Get the widget with the given id casted to some other class.

Definition at line 234 of file KisOptionCollectionWidget.h.

235 {
236 return qobject_cast<T>(widget(id));
237 }

◆ widgetAs() [2/2]

template<typename T >
T KisOptionCollectionWidgetWithHeader::widgetAs ( int index) const
inline

Get the widget that is at the given position casted to some other class.

Definition at line 221 of file KisOptionCollectionWidget.h.

222 {
223 return qobject_cast<T>(widget(index));
224 }

◆ widgetIndexFromId()

int KisOptionCollectionWidgetWithHeader::widgetIndexFromId ( const QString & id) const

Get the index of the widget that has the given id.

Definition at line 617 of file KisOptionCollectionWidget.cpp.

618{
619 return m_d->widgetCollection->widgetIndexFromId(id);
620}

References m_d.

Friends And Related Symbol Documentation

◆ KisOptionCollectionWidget

friend class KisOptionCollectionWidget
friend

Definition at line 334 of file KisOptionCollectionWidget.h.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisOptionCollectionWidgetWithHeader::m_d
private

Definition at line 333 of file KisOptionCollectionWidget.h.


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