11#include <KColorScheme>
12#include <KConfigGroup>
13#include <KSharedConfig>
20 : QQuickImageProvider(Pixmap)
26 int origSize = requestedSize.isValid() ? std::min(requestedSize.width(), requestedSize.height()) : 10;
28 *size = QSize(origSize, origSize);
30 QStringList idParts =
id.split(QStringLiteral(
"/"));
31 if (idParts.isEmpty()) {
33 return QQuickImageProvider::requestPixmap(
id, size, requestedSize);
38 if (idParts.length() > 1 && idParts.at(1) == QStringLiteral(
"true")) {
41 if (idParts.length() > 2 && idParts.at(2) == QStringLiteral(
"true")) {
44 if (idParts.length() > 3 && idParts.at(3) == QStringLiteral(
"true")) {
48 switch (
static_cast<DecorationButton
>(idParts[0].toInt())) {
49 case DecorationButtonClose:
52 case DecorationButtonMaximizeRestore:
54 button = MaxRestoreIcon;
59 case DecorationButtonMinimize:
62 case DecorationButtonQuickHelp:
65 case DecorationButtonOnAllDesktops:
67 button = NotOnAllDesktopsIcon;
69 button = OnAllDesktopsIcon;
72 case DecorationButtonKeepAbove:
74 button = NoKeepAboveIcon;
76 button = KeepAboveIcon;
79 case DecorationButtonKeepBelow:
81 button = NoKeepBelowIcon;
83 button = KeepBelowIcon;
86 case DecorationButtonShade:
93 case DecorationButtonApplicationMenu:
98 return QQuickImageProvider::requestPixmap(
id, size, requestedSize);
100 return icon(button, origSize, active, shadow);
103QPixmap PlastikButtonProvider::icon(ButtonIcon icon,
int size,
bool active,
bool shadow)
109 QPixmap image(size, size);
110 image.fill(Qt::transparent);
112 KConfigGroup wmConfig(KSharedConfig::openConfig(QStringLiteral(
"kdeglobals")), QStringLiteral(
"WM"));
113 const QColor color = wmConfig.readEntry(
"activeForeground", QPalette().color(QPalette::Active, QPalette::HighlightedText));
116 p.setPen(KColorScheme::shade(color, KColorScheme::ShadowShade));
121 const QRect r = image.rect();
125 if (r.width() > 16) {
127 }
else if (r.width() > 4) {
131 if (r.width() > 16) {
133 }
else if (r.width() > 7) {
140 if (r.width() > 16) {
142 }
else if (r.width() > 4) {
146 drawObject(p, DiagonalLine, r.x(), r.y(), r.width(), lineWidth);
147 drawObject(p, CrossDiagonalLine, r.x(), r.bottom(), r.width(), lineWidth);
154 if (r.width() > 16) {
156 }
else if (r.width() > 4) {
160 drawObject(p, HorizontalLine, r.x(), r.top(), r.width(), lwTitleBar);
161 drawObject(p, HorizontalLine, r.x(), r.bottom() - (lineWidth2 - 1), r.width(), lineWidth2);
162 drawObject(p, VerticalLine, r.x(), r.top(), r.height(), lineWidth2);
163 drawObject(p, VerticalLine, r.right() - (lineWidth2 - 1), r.top(), r.height(), lineWidth2);
168 case MaxRestoreIcon: {
170 if (r.width() > 16) {
172 }
else if (r.width() > 4) {
176 int margin1, margin2;
177 margin1 = margin2 = lineWidth2 * 2;
183 drawObject(p, HorizontalLine, r.x() + margin1, r.top(), r.width() - margin1, lineWidth2);
184 drawObject(p, HorizontalLine, r.right() - margin2, r.bottom() - (lineWidth2 - 1) - margin1, margin2, lineWidth2);
185 drawObject(p, VerticalLine, r.x() + margin1, r.top(), margin2, lineWidth2);
186 drawObject(p, VerticalLine, r.right() - (lineWidth2 - 1), r.top(), r.height() - margin1, lineWidth2);
189 drawObject(p, HorizontalLine, r.x(), r.top() + margin2, r.width() - margin2, lwTitleBar);
190 drawObject(p, HorizontalLine, r.x(), r.bottom() - (lineWidth2 - 1), r.width() - margin2, lineWidth2);
191 drawObject(p, VerticalLine, r.x(), r.top() + margin2, r.height(), lineWidth2);
192 drawObject(p, VerticalLine, r.right() - (lineWidth2 - 1) - margin2, r.top() + margin2, r.height(), lineWidth2);
198 drawObject(p, HorizontalLine, r.x(), r.bottom() - (lwTitleBar - 1), r.width(), lwTitleBar);
204 int center = r.x() + r.width() / 2 - 1;
205 int side = r.width() / 4;
209 if (r.width() > 16) {
213 drawObject(p, HorizontalLine, center - side + 3, r.y(), 2 * side - 3 - 1, lineWidth);
215 drawObject(p, CrossDiagonalLine, center - side - 1, r.y() + 5, 6, lineWidth);
216 drawObject(p, DiagonalLine, center + side - 3, r.y(), 5, lineWidth);
218 drawObject(p, VerticalLine, center + side + 2 - lineWidth, r.y() + 3, r.height() - (2 * lineWidth + side + 2 + 1), lineWidth);
220 drawObject(p, CrossDiagonalLine, center, r.bottom() - 2 * lineWidth, side + 2, lineWidth);
221 drawObject(p, HorizontalLine, center, r.bottom() - 3 * lineWidth + 2, lineWidth, lineWidth);
223 drawObject(p, HorizontalLine, center, r.bottom() - (lineWidth - 1), lineWidth, lineWidth);
224 }
else if (r.width() > 8) {
228 drawObject(p, HorizontalLine, center - (side - 1), r.y(), 2 * side - 1, lineWidth);
231 drawObject(p, CrossDiagonalLine, center - side - 1, r.y() + 3, 3, lineWidth);
233 drawObject(p, CrossDiagonalLine, center - side - 1, r.y() + 2, 3, lineWidth);
235 drawObject(p, DiagonalLine, center + side - 1, r.y(), 3, lineWidth);
237 drawObject(p, VerticalLine, center + side + 2 - lineWidth, r.y() + 2, r.height() - (2 * lineWidth + side + 1), lineWidth);
239 drawObject(p, CrossDiagonalLine, center, r.bottom() - 2 * lineWidth + 1, side + 2, lineWidth);
241 drawObject(p, HorizontalLine, center, r.bottom() - (lineWidth - 1), lineWidth, lineWidth);
246 drawObject(p, HorizontalLine, center - (side - 1), r.y(), 2 * side, lineWidth);
248 drawObject(p, CrossDiagonalLine, center - side - 1, r.y() + 1, 2, lineWidth);
250 drawObject(p, VerticalLine, center + side + 1, r.y(), r.height() - (side + 2 + 1), lineWidth);
252 drawObject(p, CrossDiagonalLine, center, r.bottom() - 2, side + 2, lineWidth);
254 drawObject(p, HorizontalLine, center, r.bottom(), 1, 1);
260 case NotOnAllDesktopsIcon: {
261 int lwMark = r.width() - lwTitleBar * 2 - 2;
266 drawObject(p, HorizontalLine, r.x() + (r.width() - lwMark) / 2, r.y() + (r.height() - lwMark) / 2, lwMark, lwMark);
271 case OnAllDesktopsIcon: {
273 drawObject(p, HorizontalLine, r.x() + lwTitleBar, r.y(), r.width() - 2 * lwTitleBar, lwTitleBar);
274 drawObject(p, HorizontalLine, r.x() + lwTitleBar, r.bottom() - (lwTitleBar - 1), r.width() - 2 * lwTitleBar, lwTitleBar);
276 drawObject(p, VerticalLine, r.x(), r.y() + lwTitleBar, r.height() - 2 * lwTitleBar, lwTitleBar);
277 drawObject(p, VerticalLine, r.right() - (lwTitleBar - 1), r.y() + lwTitleBar, r.height() - 2 * lwTitleBar, lwTitleBar);
282 case NoKeepAboveIcon: {
283 int center = r.x() + r.width() / 2;
286 drawObject(p, CrossDiagonalLine, r.x(), center + 2 * lwArrow, center - r.x(), lwArrow);
287 drawObject(p, DiagonalLine, r.x() + center, r.y() + 1 + 2 * lwArrow, center - r.x(), lwArrow);
289 drawObject(p, HorizontalLine, center - (lwArrow - 2), r.y() + 2 * lwArrow, (lwArrow - 2) * 2, lwArrow);
295 case KeepAboveIcon: {
296 int center = r.x() + r.width() / 2;
299 drawObject(p, CrossDiagonalLine, r.x(), center, center - r.x(), lwArrow);
300 drawObject(p, DiagonalLine, r.x() + center, r.y() + 1, center - r.x(), lwArrow);
302 drawObject(p, HorizontalLine, center - (lwArrow - 2), r.y(), (lwArrow - 2) * 2, lwArrow);
308 case NoKeepBelowIcon: {
309 int center = r.x() + r.width() / 2;
312 drawObject(p, DiagonalLine, r.x(), center - 2 * lwArrow, center - r.x(), lwArrow);
313 drawObject(p, CrossDiagonalLine, r.x() + center, r.bottom() - 1 - 2 * lwArrow, center - r.x(), lwArrow);
315 drawObject(p, HorizontalLine, center - (lwArrow - 2), r.bottom() - (lwArrow - 1) - 2 * lwArrow, (lwArrow - 2) * 2, lwArrow);
321 case KeepBelowIcon: {
322 int center = r.x() + r.width() / 2;
325 drawObject(p, DiagonalLine, r.x(), center, center - r.x(), lwArrow);
326 drawObject(p, CrossDiagonalLine, r.x() + center, r.bottom() - 1, center - r.x(), lwArrow);
328 drawObject(p, HorizontalLine, center - (lwArrow - 2), r.bottom() - (lwArrow - 1), (lwArrow - 2) * 2, lwArrow);
335 drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lwTitleBar);
343 if (r.width() > 16) {
346 }
else if (r.width() > 7) {
351 int h = std::max((r.width() / 2), (lw1 + 2 * lw2));
354 drawObject(p, HorizontalLine, r.x(), r.y(), r.width(), lw1);
355 drawObject(p, HorizontalLine, r.x(), r.x() + h - (lw2 - 1), r.width(), lw2);
357 drawObject(p, VerticalLine, r.x(), r.y(), h, lw2);
358 drawObject(p, VerticalLine, r.right() - (lw2 - 1), r.y(), h, lw2);
363 drawObject(p, HorizontalLine, r.x(), r.top() + (lwTitleBar - 1), r.width(), lwTitleBar);
364 drawObject(p, HorizontalLine, r.x(), r.center().y(), r.width(), lwTitleBar);
365 drawObject(p, HorizontalLine, r.x(), r.bottom() - (lwTitleBar - 1), r.width(), lwTitleBar);
378void PlastikButtonProvider::drawObject(QPainter &p, Object
object,
int x,
int y,
int length,
int lineWidth)
382 if (lineWidth <= 1) {
383 for (
int i = 0; i < length; ++i) {
384 p.drawPoint(x + i, y + i);
386 }
else if (lineWidth <= 2) {
387 for (
int i = 0; i < length; ++i) {
388 p.drawPoint(x + i, y + i);
390 for (
int i = 0; i < (length - 1); ++i) {
391 p.drawPoint(x + 1 + i, y + i);
392 p.drawPoint(x + i, y + 1 + i);
395 for (
int i = 1; i < (length - 1); ++i) {
396 p.drawPoint(x + i, y + i);
398 for (
int i = 0; i < (length - 1); ++i) {
399 p.drawPoint(x + 1 + i, y + i);
400 p.drawPoint(x + i, y + 1 + i);
402 for (
int i = 0; i < (length - 2); ++i) {
403 p.drawPoint(x + 2 + i, y + i);
404 p.drawPoint(x + i, y + 2 + i);
408 case CrossDiagonalLine:
409 if (lineWidth <= 1) {
410 for (
int i = 0; i < length; ++i) {
411 p.drawPoint(x + i, y - i);
413 }
else if (lineWidth <= 2) {
414 for (
int i = 0; i < length; ++i) {
415 p.drawPoint(x + i, y - i);
417 for (
int i = 0; i < (length - 1); ++i) {
418 p.drawPoint(x + 1 + i, y - i);
419 p.drawPoint(x + i, y - 1 - i);
422 for (
int i = 1; i < (length - 1); ++i) {
423 p.drawPoint(x + i, y - i);
425 for (
int i = 0; i < (length - 1); ++i) {
426 p.drawPoint(x + 1 + i, y - i);
427 p.drawPoint(x + i, y - 1 - i);
429 for (
int i = 0; i < (length - 2); ++i) {
430 p.drawPoint(x + 2 + i, y - i);
431 p.drawPoint(x + i, y - 2 - i);
436 for (
int i = 0; i < lineWidth; ++i) {
437 p.drawLine(x, y + i, x + length - 1, y + i);
441 for (
int i = 0; i < lineWidth; ++i) {
442 p.drawLine(x + i, y, x + i, y + length - 1);