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

#include <kis_color_label_selector_widget.h>

+ Inheritance diagram for KisColorLabelSelectorWidget:

Classes

struct  Private
 

Public Types

enum  SelectionIndicationType { FillIn , Outline }
 

Public Slots

void setButtonChecked (int index, bool state)
 (Un)Check the button at the given position
 
void setCurrentIndex (int index)
 Set the currently selected button. It has no effect if the buttons are mutually exclusive.
 
void setSelection (const QList< int > &indices)
 Set the list of checked button indices.
 

Signals

void buttonToggled (int index, bool state)
 
void currentIndexChanged (int index)
 
void selectionChanged ()
 

Public Member Functions

int buttonSize () const
 Get the size of the buttons.
 
bool buttonWrapEnabled () const
 Get if the buttons should wrap in multiple lines if there is no enough space horizontally.
 
int currentIndex () const
 Get the index of the currently checked button. Returns -1 if there is no checked button and -2 if the buttons are not mutually exclusive.
 
bool exclusive () const
 Get if the button selection is mutually exclusive.
 
bool isButtonChecked (int index) const
 Get if the button at the given position is currently checked.
 
 KisColorLabelSelectorWidget (QWidget *parent=nullptr)
 
bool mouseDragEnabled () const
 Get if the user can drag to check/uncheck multiple buttons.
 
QList< int > selection () const
 Get the list of checked button indices.
 
SelectionIndicationType selectionIndicationType () const
 Get how the button is rendered.
 
void setButtonSize (int size)
 Set the size of the buttons.
 
void setButtonWrapEnabled (bool enabled)
 Set if the buttons should wrap in multiple lines if there is no enough space horizontally.
 
void setExclusive (bool exclusive)
 Set if the button selection is mutually exclusive. This allows switching between single or multiple selection.
 
void setMouseDragEnabled (bool enabled)
 Set if the user can drag to check/uncheck multiple buttons.
 
void setSelectionIndicationType (SelectionIndicationType type)
 Set how the button should be rendered.
 
 ~KisColorLabelSelectorWidget () override
 

Private Attributes

QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 16 of file kis_color_label_selector_widget.h.

Member Enumeration Documentation

◆ SelectionIndicationType

Enumerator
FillIn 

The buttons show a border and their interior is filled when selected and empty when not selected.

Outline 

The buttons have their interior filled and show a border if they are selected.

Definition at line 21 of file kis_color_label_selector_widget.h.

21 {
26 FillIn,
32 };
@ Outline
The buttons have their interior filled and show a border if they are selected.
@ FillIn
The buttons show a border and their interior is filled when selected and empty when not selected.

Constructor & Destructor Documentation

◆ KisColorLabelSelectorWidget()

KisColorLabelSelectorWidget::KisColorLabelSelectorWidget ( QWidget * parent = nullptr)

Definition at line 35 of file kis_color_label_selector_widget.cpp.

36 : QWidget(parent)
37 , m_d(new Private)
38{
40 m_d->colors = scm.allColorLabels();
41
42 QHBoxLayout *layout = new QHBoxLayout(this);
43 layout->setAlignment(Qt::AlignLeft);
44
45 layout->setContentsMargins(0,0,0,0);
46 layout->setSpacing(2);
47 {
48 m_d->colorButtonGroup = new KisColorLabelFilterGroup(this);
49 m_d->colorButtonGroup->setExclusive(true);
50 m_d->colorButtonGroup->setMinimumRequiredChecked(0);
51 QSet<int> viableColors;
52
53 for (int id = 0; id < m_d->colors.count(); id++) {
54 KisColorLabelButton* btn = new KisColorLabelButton(m_d->colors[id], m_d->buttonSize, this);
55 btn->setChecked(false);
57 m_d->colorButtonGroup->addButton(btn, id);
58 layout->addWidget(btn);
59 viableColors << id;
60 }
61
62 m_d->colorButtonGroup->setViableLabels(viableColors);
63
64 connect(m_d->colorButtonGroup, QOverload<QAbstractButton*, bool>::of(&QButtonGroup::buttonToggled),
65 [this](QAbstractButton *button, bool state)
66 {
67 const int index = m_d->colorButtonGroup->id(button);
68 Q_EMIT buttonToggled(index, state);
69 if (m_d->colorButtonGroup->exclusive()) {
70 if (!state) {
71 return;
72 }
73 Q_EMIT currentIndexChanged(index);
74 } else {
75 Q_EMIT selectionChanged();
76 }
77 }
78 );
79 }
80}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setSelectionVisType(SelectionIndicationType type)
QVector< QColor > allColorLabels() const
QString button(const QWheelEvent &ev)

References KisNodeViewColorScheme::allColorLabels(), button(), connect(), m_d, KisColorLabelButton::Outline, and KisColorLabelButton::setSelectionVisType().

◆ ~KisColorLabelSelectorWidget()

KisColorLabelSelectorWidget::~KisColorLabelSelectorWidget ( )
override

Definition at line 82 of file kis_color_label_selector_widget.cpp.

83{}

Member Function Documentation

◆ buttonSize()

int KisColorLabelSelectorWidget::buttonSize ( ) const

Get the size of the buttons.

Definition at line 232 of file kis_color_label_selector_widget.cpp.

233{
234 return m_d->buttonSize;
235}

References m_d.

◆ buttonToggled

void KisColorLabelSelectorWidget::buttonToggled ( int index,
bool state )
signal

◆ buttonWrapEnabled()

bool KisColorLabelSelectorWidget::buttonWrapEnabled ( ) const

Get if the buttons should wrap in multiple lines if there is no enough space horizontally.

Definition at line 158 of file kis_color_label_selector_widget.cpp.

159{
160 return dynamic_cast<KisWrappableHBoxLayout*>(layout());
161}

◆ currentIndex()

int KisColorLabelSelectorWidget::currentIndex ( ) const

Get the index of the currently checked button. Returns -1 if there is no checked button and -2 if the buttons are not mutually exclusive.

Definition at line 95 of file kis_color_label_selector_widget.cpp.

96{
97 if (!m_d->colorButtonGroup->exclusive()) {
98 return -2;
99 }
100 return m_d->colorButtonGroup->checkedId();
101}

References m_d.

◆ currentIndexChanged

void KisColorLabelSelectorWidget::currentIndexChanged ( int index)
signal

◆ exclusive()

bool KisColorLabelSelectorWidget::exclusive ( ) const

Get if the button selection is mutually exclusive.

Definition at line 148 of file kis_color_label_selector_widget.cpp.

149{
150 return m_d->colorButtonGroup->exclusive();
151}

References m_d.

◆ isButtonChecked()

bool KisColorLabelSelectorWidget::isButtonChecked ( int index) const

Get if the button at the given position is currently checked.

Definition at line 85 of file kis_color_label_selector_widget.cpp.

86{
87 return m_d->colorButtonGroup->button(index)->isChecked();
88}

References m_d.

◆ mouseDragEnabled()

bool KisColorLabelSelectorWidget::mouseDragEnabled ( ) const

Get if the user can drag to check/uncheck multiple buttons.

Definition at line 186 of file kis_color_label_selector_widget.cpp.

187{
188 return m_d->dragFilter;
189}

References m_d.

◆ selection()

QList< int > KisColorLabelSelectorWidget::selection ( ) const

Get the list of checked button indices.

Definition at line 125 of file kis_color_label_selector_widget.cpp.

126{
127 QList<int> indices;
128 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
129 if (button->isChecked()) {
130 indices << m_d->colorButtonGroup->id(button);
131 }
132 }
133 return indices;
134}
QString buttons(const T &ev)

References button(), and m_d.

◆ selectionChanged

void KisColorLabelSelectorWidget::selectionChanged ( )
signal

◆ selectionIndicationType()

KisColorLabelSelectorWidget::SelectionIndicationType KisColorLabelSelectorWidget::selectionIndicationType ( ) const

Get how the button is rendered.

Definition at line 213 of file kis_color_label_selector_widget.cpp.

214{
215 return
216 static_cast<SelectionIndicationType>(
217 qobject_cast<KisColorLabelButton*>(
218 m_d->colorButtonGroup->button(0)
219 )->selectionVisType()
220 );
221}

References m_d.

◆ setButtonChecked

void KisColorLabelSelectorWidget::setButtonChecked ( int index,
bool state )
slot

(Un)Check the button at the given position

Definition at line 90 of file kis_color_label_selector_widget.cpp.

91{
92 m_d->colorButtonGroup->button(index)->setChecked(state);
93}

References m_d.

◆ setButtonSize()

void KisColorLabelSelectorWidget::setButtonSize ( int size)

Set the size of the buttons.

Definition at line 237 of file kis_color_label_selector_widget.cpp.

238{
239 if (size == m_d->buttonSize) {
240 return;
241 }
242 m_d->buttonSize = size;
243 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
244 qobject_cast<KisColorLabelButton*>(button)->setSize(static_cast<uint>(size));
245 }
246 update();
247}
unsigned int uint
int size(const Forest< T > &forest)
Definition KisForest.h:1232
bool update(QSpinBox *spinBox)

References button(), and m_d.

◆ setButtonWrapEnabled()

void KisColorLabelSelectorWidget::setButtonWrapEnabled ( bool enabled)

Set if the buttons should wrap in multiple lines if there is no enough space horizontally.

Definition at line 163 of file kis_color_label_selector_widget.cpp.

164{
165 QLayout *newLayout;
166 if (enabled) {
167 if (dynamic_cast<KisWrappableHBoxLayout*>(layout())) {
168 return;
169 }
170 newLayout = new KisWrappableHBoxLayout;
171 } else {
172 if (dynamic_cast<QHBoxLayout*>(layout())) {
173 return;
174 }
175 newLayout = new QHBoxLayout;
176 }
177 newLayout->setContentsMargins(0,0,0,0);
178 newLayout->setSpacing(2);
179 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
180 newLayout->addWidget(button);
181 }
182 delete layout();
183 setLayout(newLayout);
184}

References button(), and m_d.

◆ setCurrentIndex

void KisColorLabelSelectorWidget::setCurrentIndex ( int index)
slot

Set the currently selected button. It has no effect if the buttons are mutually exclusive.

Definition at line 103 of file kis_color_label_selector_widget.cpp.

104{
105 if (!m_d->colorButtonGroup->exclusive()) {
106 return;
107 }
108 if (index == -1) {
109 QAbstractButton* btn = m_d->colorButtonGroup->checkedButton();
110 if (btn) {
111 btn->group()->setExclusive(false);
112 btn->setChecked(false);
113 btn->group()->setExclusive(true);
114 }
115 } else if (index != m_d->colorButtonGroup->checkedId()) {
116 QAbstractButton* btn = m_d->colorButtonGroup->button(index);
117 if (btn) {
118 btn->setChecked(true);
119 }
120 }
121
122 Q_EMIT currentIndexChanged(index);
123}
void currentIndexChanged(int index)

References currentIndexChanged(), and m_d.

◆ setExclusive()

void KisColorLabelSelectorWidget::setExclusive ( bool exclusive)

Set if the button selection is mutually exclusive. This allows switching between single or multiple selection.

Definition at line 153 of file kis_color_label_selector_widget.cpp.

154{
155 m_d->colorButtonGroup->setExclusive(exclusive);
156}
bool exclusive() const
Get if the button selection is mutually exclusive.

References exclusive(), and m_d.

◆ setMouseDragEnabled()

void KisColorLabelSelectorWidget::setMouseDragEnabled ( bool enabled)

Set if the user can drag to check/uncheck multiple buttons.

Definition at line 191 of file kis_color_label_selector_widget.cpp.

192{
193 if (enabled) {
194 if (m_d->dragFilter) {
195 return;
196 }
197 m_d->dragFilter = new KisColorLabelMouseDragFilter(this);
198 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
199 button->installEventFilter(m_d->dragFilter);
200 }
201 } else {
202 if (!m_d->dragFilter) {
203 return;
204 }
205 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
206 button->removeEventFilter(m_d->dragFilter);
207 }
208 delete m_d->dragFilter;
209 m_d->dragFilter = nullptr;
210 }
211}

References button(), and m_d.

◆ setSelection

void KisColorLabelSelectorWidget::setSelection ( const QList< int > & indices)
slot

Set the list of checked button indices.

Definition at line 136 of file kis_color_label_selector_widget.cpp.

137{
138 KisSignalsBlocker blocker(m_d->colorButtonGroup);
139 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
140 button->setChecked(false);
141 }
142 for (int index : indices) {
143 m_d->colorButtonGroup->button(index)->setChecked(true);
144 }
145 Q_EMIT selectionChanged();
146}

References button(), m_d, and selectionChanged().

◆ setSelectionIndicationType()

void KisColorLabelSelectorWidget::setSelectionIndicationType ( SelectionIndicationType type)

Set how the button should be rendered.

Definition at line 223 of file kis_color_label_selector_widget.cpp.

224{
225 for (QAbstractButton *button : m_d->colorButtonGroup->buttons()) {
226 qobject_cast<KisColorLabelButton*>(button)->setSelectionVisType(
228 );
229 }
230}

References button(), and m_d.

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisColorLabelSelectorWidget::m_d
private

Definition at line 122 of file kis_color_label_selector_widget.h.


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