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

#include <kis_color_label_button.h>

+ Inheritance diagram for KisColorLabelButton:

Classes

struct  Private
 

Public Types

enum  SelectionIndicationType { FillIn , Outline }
 

Public Member Functions

void enterEvent (QEnterEvent *event) override
 
 KisColorLabelButton (QColor color, uint sizeSquared=32, QWidget *parent=nullptr)
 
void leaveEvent (QEvent *event) override
 
void nextCheckState () override
 
void paintEvent (QPaintEvent *event) override
 
SelectionIndicationType selectionVisType () const
 
void setSelectionVisType (SelectionIndicationType type)
 
void setSize (uint size)
 
QSize sizeHint () const override
 
 ~KisColorLabelButton () override
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

Definition at line 16 of file kis_color_label_button.h.

Member Enumeration Documentation

◆ SelectionIndicationType

Constructor & Destructor Documentation

◆ KisColorLabelButton()

KisColorLabelButton::KisColorLabelButton ( QColor color,
uint sizeSquared = 32,
QWidget * parent = nullptr )

Definition at line 42 of file kis_color_label_button.cpp.

42 : QAbstractButton(parent), m_d(new Private(color, sizeSquared))
43{
44 setCheckable(true);
45 setChecked(true);
46 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
47}
const QScopedPointer< Private > m_d

◆ ~KisColorLabelButton()

KisColorLabelButton::~KisColorLabelButton ( )
override

Definition at line 49 of file kis_color_label_button.cpp.

49{}

Member Function Documentation

◆ enterEvent()

void KisColorLabelButton::enterEvent ( QEnterEvent * event)
override

Definition at line 153 of file kis_color_label_button.cpp.

153 {
154#endif
155 Q_UNUSED(event);
156 update();
157}
bool update(QSpinBox *spinBox)

◆ leaveEvent()

void KisColorLabelButton::leaveEvent ( QEvent * event)
override

Definition at line 159 of file kis_color_label_button.cpp.

159 {
160 Q_UNUSED(event);
161 update();
162}

◆ nextCheckState()

void KisColorLabelButton::nextCheckState ( )
override

Definition at line 188 of file kis_color_label_button.cpp.

189{
190 KisColorLabelFilterGroup* colorLabelFilterGroup = dynamic_cast<KisColorLabelFilterGroup*>(group());
191
192 if (!colorLabelFilterGroup || (colorLabelFilterGroup->countCheckedViableButtons() > colorLabelFilterGroup->minimumRequiredChecked() || !isChecked())) {
193 setChecked(!isChecked());
194 } else {
195 setChecked(isChecked());
196 }
197}

References KisColorLabelFilterGroup::countCheckedViableButtons(), and KisColorLabelFilterGroup::minimumRequiredChecked().

◆ paintEvent()

void KisColorLabelButton::paintEvent ( QPaintEvent * event)
override

Definition at line 51 of file kis_color_label_button.cpp.

52{
53 QWidget::paintEvent(event);
54
55 QStylePainter painter(this);
56 QStyleOptionButton styleOption;
57 styleOption.initFrom(this);
58
59 if (isDown() || isChecked()){
60 styleOption.state |= QStyle::State_On;
61 }
62
63 const QRect rect = this->rect();
64 QRect interiorRect = kisGrowRect(rect, -3);
65 const QColor borderColor = QColor(0, 0, 0, 128);
66
67 if (!isEnabled()) {
68 const int w = qMin(interiorRect.width(), qMax(8, interiorRect.width() / 2));
69 const int h = qMin(interiorRect.height(), qMax(8, interiorRect.height() / 2));
70 const int marginX = (interiorRect.width() - w) / 2;
71 const int marginY = (interiorRect.height() - h) / 2;
72 interiorRect.adjust(marginX, marginY, -marginX, -marginY);
73 }
74
75 if (m_d->m_color.alpha() > 0) {
76 QColor fillColor = m_d->m_color;
77
78 painter.setBrush(Qt::NoBrush);
79 painter.setPen(QPen(borderColor, 1));
80
81 if (!isEnabled()) {
82 fillColor.setAlpha(32);
83 } else if (!isChecked() && (styleOption.state & QStyle::State_MouseOver) == 0) {
84 fillColor.setAlpha(192);
85 }
86
87 if (isEnabled() && (m_d->selectionVis == FillIn || isChecked())) {
88 painter.fillRect(rect, fillColor);
89 painter.drawRect(rect.adjusted(0, 0, -1, -1));
90 }
91 painter.fillRect(interiorRect,
92 !isEnabled() || m_d->selectionVis == Outline || isChecked()
93 ? fillColor
94 : styleOption.palette.window().color());
95 painter.drawRect(interiorRect.adjusted(0, 0, -1, -1));
96
97 } else {
98 QColor white = QColor(255,255,255);
99 QColor greyOutside = QColor(200,200,200);
100 QColor greyInside = greyOutside;
101 QColor xColor = QColor(0, 0, 0, 128);
102
103 if (!isEnabled()) {
104 white.setAlpha(32);
105 greyInside.setAlpha(32);
106 xColor.setAlpha(32);
107 } else if (!isChecked()) {
108 if ((styleOption.state & QStyle::State_MouseOver) == 0) {
109 greyOutside.setAlpha(128);
110 greyInside.setAlpha(128);
111 } else if (m_d->selectionVis == FillIn) {
112 greyInside.setAlpha(128);
113 }
114 white.setAlpha(128);
115 xColor.setAlpha(64);
116 }
117
118 painter.setBrush(Qt::NoBrush);
119 painter.setPen(QPen(borderColor, 1));
120
121 if (isEnabled() && (m_d->selectionVis == FillIn || isChecked())) {
122 painter.fillRect(QRect(rect.topLeft(), rect.topRight() + QPoint(0, 2)), greyOutside);
123 painter.fillRect(QRect(rect.bottomLeft() + QPoint(0, -2), rect.bottomRight()), greyOutside);
124 painter.fillRect(QRect(rect.topLeft() + QPoint(0, 3), rect.bottomLeft() + QPoint(2, -3)), greyOutside);
125 painter.fillRect(QRect(rect.topRight() + QPoint(-2, 3), rect.bottomRight() + QPoint(0, -3)), greyOutside);
126 painter.drawRect(rect.adjusted(0, 0, -1, -1));
127 }
128 painter.fillRect(interiorRect, greyInside);
129 const int tileWidth = interiorRect.width() / 2;
130 const int tileHeight = interiorRect.height() / 2;
131 painter.fillRect(interiorRect.adjusted(0, 0, -tileWidth, -tileHeight), white);
132 painter.fillRect(interiorRect.adjusted(tileWidth, tileHeight, 0, 0), white);
133 painter.drawRect(interiorRect.adjusted(0, 0, -1, -1));
134 QRect xRect = interiorRect.adjusted(4, 4, -3, -3);
135 while (xRect.width() <= 8 || xRect.height() <= 8) {
136 xRect.adjust(-1, -1, 1, 1);
137 }
138 xRect = xRect.intersected(interiorRect);
139 if (xRect.width() <= 8 || xRect.height() <= 8) {
140 xRect = interiorRect;
141 painter.setPen(QPen(xColor, 1));
142 } else {
143 painter.setPen(QPen(xColor, 2));
144 }
145 painter.drawLine(xRect.topLeft(), xRect.bottomRight());
146 painter.drawLine(xRect.bottomLeft(), xRect.topRight());
147 }
148}
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186

References FillIn, kisGrowRect(), m_d, and Outline.

◆ selectionVisType()

KisColorLabelButton::SelectionIndicationType KisColorLabelButton::selectionVisType ( ) const

Definition at line 169 of file kis_color_label_button.cpp.

170{
171 return m_d->selectionVis;
172}

References m_d.

◆ setSelectionVisType()

void KisColorLabelButton::setSelectionVisType ( KisColorLabelButton::SelectionIndicationType type)

Definition at line 174 of file kis_color_label_button.cpp.

175{
176 m_d->selectionVis = type;
177}

References m_d.

◆ setSize()

void KisColorLabelButton::setSize ( uint size)

Definition at line 179 of file kis_color_label_button.cpp.

180{
181 if (size == m_d->m_sizeSquared) {
182 return;
183 }
184 m_d->m_sizeSquared = size;
185 update();
186}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References m_d.

◆ sizeHint()

QSize KisColorLabelButton::sizeHint ( ) const
override

Definition at line 164 of file kis_color_label_button.cpp.

165{
166 return QSize(m_d->m_sizeSquared,m_d->m_sizeSquared);
167}

References m_d.

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisColorLabelButton::m_d
private

Definition at line 44 of file kis_color_label_button.h.


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