Debian Codegraph @

src/Gui/QSint/actionpanel/actionpanelscheme.cpp

raw
1 // SPDX-License-Identifier: LGPL-3.0-only
2 /***************************************************************************
3 * *
4 * Copyright: https://code.google.com/p/qsint/ *
5 * License: LGPL *
6 * *
7 ***************************************************************************/
8
9 #include "actionpanelscheme.h"
10
11
12 namespace QSint
13 {
14
15 QPixmap ActionPanelScheme::drawFoldIcon(const QPalette& palette, bool fold, bool hover) const
16 {
17 QSize bSize = headerButtonSize;
18 QImage img(bSize.width(), bSize.height(), QImage::Format_ARGB32_Premultiplied);
19 img.fill(Qt::transparent);
20
21 QPainter painter(&img);
22
23 painter.setRenderHint(QPainter::Antialiasing);
24
25 qreal penWidth = bSize.width() / 14.0;
26 qreal lef_X = 0.25 * bSize.width();
27 qreal mid_X = 0.50 * bSize.width();
28 qreal rig_X = 0.75 * bSize.width();
29 qreal bot_Y = 0.40 * bSize.height();
30 qreal top_Y = 0.64 * bSize.height();
31
32 QPolygon chevron;
33 if (fold) {
34 // Upward
35 chevron << QPoint(lef_X, top_Y)
36 << QPoint(mid_X, bot_Y)
37 << QPoint(rig_X, top_Y);
38 } else {
39 // Downward
40 chevron << QPoint(lef_X, bot_Y)
41 << QPoint(mid_X, top_Y)
42 << QPoint(rig_X, bot_Y);
43 }
44
45 painter.setBrush(Qt::NoBrush);
46 // Outline
47 QColor outlineColor = palette.color(QPalette::Button);
48 painter.setPen(QPen(outlineColor, penWidth * 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
49 painter.drawPolyline(chevron);
50
51 // Chevron
52 if (hover) {
53 penWidth *= 1.8;
54 }
55 QColor mainColor = palette.color(QPalette::Text);
56 painter.setPen(QPen(mainColor, penWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
57 painter.drawPolyline(chevron);
58
59 painter.end();
60 return QPixmap::fromImage(img);
61 }
62
63 ActionPanelScheme::ActionPanelScheme()
64 {
65 QFontMetrics fm(QApplication::font());
66 headerSize = fm.height() + 10;
67
68 QPalette p = QApplication::palette();
69
70 int iconSize = fm.height();
71 headerButtonSize = QSize(iconSize, iconSize);
72 builtinFold = drawFoldIcon(p, true, false);
73 builtinFoldOver = drawFoldIcon(p, true, true);
74 builtinUnfold = drawFoldIcon(p, false, false);
75 builtinUnfoldOver = drawFoldIcon(p, false, true);
76
77 if (qApp->styleSheet().isEmpty()) {
78 headerButtonFold = builtinFold;
79 headerButtonFoldOver = builtinFoldOver;
80 headerButtonUnfold = builtinUnfold;
81 headerButtonUnfoldOver = builtinUnfoldOver;
82 } else {
83 headerButtonFold = QPixmap();
84 headerButtonFoldOver = QPixmap();
85 headerButtonUnfold = QPixmap();
86 headerButtonUnfoldOver = QPixmap();
87 }
88
89 groupFoldSteps = 20;
90 groupFoldDelay = 15;
91 groupFoldEffect = NoFolding;
92 groupFoldThaw = true;
93 }
94
95 ActionPanelScheme* ActionPanelScheme::defaultScheme()
96 {
97 static ActionPanelScheme scheme;
98 return &scheme;
99 }
100
101 void ActionPanelScheme::clearActionStyle()
102 {
103 headerButtonFold = QPixmap();
104 headerButtonFoldOver = QPixmap();
105 headerButtonUnfold = QPixmap();
106 headerButtonUnfoldOver = QPixmap();
107 }
108
109 void ActionPanelScheme::restoreActionStyle()
110 {
111 headerButtonFold = builtinFold;
112 headerButtonFoldOver = builtinFoldOver;
113 headerButtonUnfold = builtinUnfold;
114 headerButtonUnfoldOver = builtinUnfoldOver;
115 }
116
117 } // namespace QSint