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();
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)