annotate examples/widgets/styles/norwegianwoodstyle.d @ 156:37cf6fd1ee85

add styles example, still buggs
author mandel
date Tue, 16 Jun 2009 21:28:16 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
156
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
1 /****************************************************************************
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
2 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
4 ** Contact: Qt Software Information (qt-info@nokia.com)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
5 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
6 ** This file is part of the examples of the Qt Toolkit.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
7 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
8 ** $QT_BEGIN_LICENSE:LGPL$
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
9 ** Commercial Usage
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
10 ** Licensees holding valid Qt Commercial licenses may use this file in
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
11 ** accordance with the Qt Commercial License Agreement provided with the
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
12 ** Software or, alternatively, in accordance with the terms contained in
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
13 ** a written agreement between you and Nokia.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
14 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
15 ** GNU Lesser General Public License Usage
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
17 ** General Public License version 2.1 as published by the Free Software
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
19 ** packaging of this file. Please review the following information to
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
22 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
23 ** In addition, as a special exception, Nokia gives you certain
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
24 ** additional rights. These rights are described in the Nokia Qt LGPL
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
26 ** package.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
27 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
28 ** GNU General Public License Usage
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
29 ** Alternatively, this file may be used under the terms of the GNU
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
30 ** General Public License version 3.0 as published by the Free Software
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
31 ** Foundation and appearing in the file LICENSE.GPL included in the
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
32 ** packaging of this file. Please review the following information to
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
33 ** ensure the GNU General Public License version 3.0 requirements will be
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
34 ** met: http://www.gnu.org/copyleft/gpl.html.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
35 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
36 ** If you are unsure which license is appropriate for your use, please
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
37 ** contact the sales department at qt-sales@nokia.com.
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
38 ** $QT_END_LICENSE$
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
39 **
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
40 ****************************************************************************/
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
41 module norwegianwoodstyle;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
42
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
43
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
44 import qt.gui.QMotifStyle;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
45 import qt.gui.QPalette;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
46 import qt.gui.QPainterPath;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
47 import qt.gui.QPushButton;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
48 import qt.gui.QComboBox;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
49
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
50
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
51 class NorwegianWoodStyle : public QMotifStyle
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
52 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
53 public:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
54
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
55 this() {}
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
56
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
57 void polish(QPalette palette)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
58 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
59 auto brown = new QColor(212, 140, 95);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
60 auto beige = new QColor(236, 182, 120);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
61 auto slightlyOpaqueBlack = new QColor(0, 0, 0, 63);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
62
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
63 auto backgroundImage = new QPixmap(":/images/woodbackground.png");
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
64 auto buttonImage = new QPixmap(":/images/woodbutton.png");
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
65 QPixmap midImage = buttonImage;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
66
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
67 auto painter = new QPainter;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
68 painter.begin(midImage);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
69 painter.setPen(Qt.NoPen);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
70 painter.fillRect(midImage.rect(), slightlyOpaqueBlack);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
71 painter.end();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
72
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
73 palette = new QPalette(brown);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
74
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
75 palette.setBrush(QPalette.BrightText, new QBrush(QColor.White));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
76 palette.setBrush(QPalette.Base, new QBrush(beige));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
77 palette.setBrush(QPalette.Highlight, new QBrush(QColor.DarkGreen));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
78 setTexture(palette, QPalette.Button, buttonImage);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
79 setTexture(palette, QPalette.Mid, midImage);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
80 setTexture(palette, QPalette.Window, backgroundImage);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
81
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
82 QBrush brush = palette.brush(QPalette.Window); //.background();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
83 brush.setColor(brush.color().darker());
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
84
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
85 palette.setBrush(QPalette.Disabled, QPalette.WindowText, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
86 palette.setBrush(QPalette.Disabled, QPalette.Text, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
87 palette.setBrush(QPalette.Disabled, QPalette.ButtonText, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
88 palette.setBrush(QPalette.Disabled, QPalette.Base, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
89 palette.setBrush(QPalette.Disabled, QPalette.Button, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
90 palette.setBrush(QPalette.Disabled, QPalette.Mid, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
91 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
92
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
93 void polish(QWidget widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
94 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
95 if (cast(QPushButton) widget || cast(QComboBox) widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
96 widget.setAttribute(Qt.WA_Hover, true);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
97 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
98
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
99 void unpolish(QWidget widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
100 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
101 if (cast(QPushButton) widget || cast(QComboBox) widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
102 widget.setAttribute(Qt.WA_Hover, false);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
103 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
104
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
105 int pixelMetric(PixelMetric metric, QStyleOption option, QWidget widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
106 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
107 switch (metric) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
108 case PM_ComboBoxFrameWidth:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
109 return 8;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
110 case PM_ScrollBarExtent:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
111 return QMotifStyle.pixelMetric(metric, option, widget) + 4;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
112 default:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
113 return QMotifStyle.pixelMetric(metric, option, widget);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
114 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
115 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
116
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
117 int styleHint(StyleHint hint, QStyleOption option, QWidget widget, QStyleHintReturn returnData)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
118 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
119 switch (hint) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
120 case SH_DitherDisabledText:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
121 return cast(int) false;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
122 case SH_EtchDisabledText:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
123 return cast(int) true;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
124 default:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
125 return QMotifStyle.styleHint(hint, option, widget, returnData);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
126 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
127 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
128
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
129 void drawPrimitive(PrimitiveElement element, QStyleOption option, QPainter painter, QWidget widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
130 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
131 switch (element) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
132 case PE_PanelButtonCommand:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
133 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
134 int delta = (option.state & State_MouseOver) ? 64 : 0;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
135 auto slightlyOpaqueBlack = new QColor(0, 0, 0, 63);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
136 auto semiTransparentWhite = new QColor(255, 255, 255, 127 + delta);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
137 auto semiTransparentBlack = new QColor(0, 0, 0, 127 - delta);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
138
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
139 int x, y, width, height;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
140 option.rect.getRect(&x, &y, &width, &height);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
141
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
142 QPainterPath roundRect = roundRectPath(option.rect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
143 int radius = qMin(width, height) / 2;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
144
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
145 QBrush brush;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
146 bool darker;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
147
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
148 QStyleOptionButton buttonOption = cast(QStyleOptionButton) option;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
149 if (buttonOption && (buttonOption.features & QStyleOptionButton.Flat)) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
150 brush = option.palette.brush(QPalette.Window); //background();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
151 darker = cast(bool) (option.state & (State_Sunken | State_On));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
152 } else {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
153 if (option.state & (State_Sunken | State_On)) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
154 brush = option.palette.mid();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
155 darker = !(option.state & State_Sunken);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
156 } else {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
157 brush = option.palette.button();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
158 darker = false;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
159 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
160 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
161
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
162 painter.save();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
163 painter.setRenderHint(QPainter.Antialiasing, true);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
164 painter.fillPath(roundRect, brush);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
165 if (darker)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
166 painter.fillPath(roundRect, new QBrush(slightlyOpaqueBlack));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
167
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
168 int penWidth;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
169
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
170 if (radius < 10)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
171 penWidth = 3;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
172 else if (radius < 20)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
173 penWidth = 5;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
174 else
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
175 penWidth = 7;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
176
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
177 auto topPen = new QPen(semiTransparentWhite);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
178 auto bottomPen = new QPen(semiTransparentBlack);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
179
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
180 topPen.setWidth(penWidth);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
181 bottomPen.setWidth(penWidth);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
182
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
183 if (option.state & (State_Sunken | State_On))
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
184 qSwap(topPen, bottomPen);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
185
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
186 int x1 = x;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
187 int x2 = x + radius;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
188 int x3 = x + width - radius;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
189 int x4 = x + width;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
190
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
191 if (option.direction == Qt.RightToLeft) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
192 qSwap(x1, x4);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
193 qSwap(x2, x3);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
194 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
195
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
196 auto topHalf = new QPolygon();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
197 topHalf.append(QPoint(x1, y));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
198 topHalf.append(QPoint(x4, y));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
199 topHalf.append(QPoint(x3, y + radius));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
200 topHalf.append(QPoint(x2, y + height - radius));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
201 topHalf.append(QPoint(x1, y + height));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
202
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
203 painter.setClipPath(roundRect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
204 painter.setClipRegion(new QRegion(topHalf), Qt.IntersectClip);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
205 painter.setPen(topPen);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
206 painter.drawPath(roundRect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
207
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
208 QPolygon bottomHalf = topHalf;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
209 bottomHalf.replace(0, QPoint(x4, y + height));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
210
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
211 painter.setClipPath(roundRect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
212 painter.setClipRegion(new QRegion(bottomHalf), Qt.IntersectClip);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
213 painter.setPen(bottomPen);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
214 painter.drawPath(roundRect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
215
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
216 painter.setPen(option.palette.brush(QPalette.WindowText).color());
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
217 painter.setClipping(false);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
218 painter.drawPath(roundRect);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
219
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
220 painter.restore();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
221 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
222 break;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
223 default:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
224 QMotifStyle.drawPrimitive(element, option, painter, widget);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
225 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
226 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
227
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
228 void drawControl(ControlElement element, QStyleOption option, QPainter painter, QWidget widget)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
229 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
230 switch (element) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
231 case CE_PushButtonLabel:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
232 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
233 QStyleOptionButton myButtonOption;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
234 QStyleOptionButton buttonOption = cast(QStyleOptionButton) option;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
235 if (buttonOption) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
236 myButtonOption = buttonOption;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
237 if (myButtonOption.palette.currentColorGroup() != QPalette.Disabled) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
238 if (myButtonOption.state & (State_Sunken | State_On)) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
239 myButtonOption.palette.setBrush(QPalette.ButtonText,
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
240 myButtonOption.palette.brightText());
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
241 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
242 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
243 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
244 QMotifStyle.drawControl(element, myButtonOption, painter, widget);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
245 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
246 break;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
247 default:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
248 QMotifStyle.drawControl(element, option, painter, widget);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
249 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
250 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
251
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
252 private:
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
253
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
254 static void setTexture(QPalette palette, QPalette.ColorRole role, QPixmap pixmap)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
255 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
256 for (int i = 0; i < QPalette.NColorGroups; ++i) {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
257 QColor color = palette.brush(cast(QPalette.ColorGroup) i, role).color();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
258 palette.setBrush(cast(QPalette.ColorGroup) i, role, new QBrush(color, pixmap));
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
259 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
260 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
261
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
262 static QPainterPath roundRectPath(QRect rect)
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
263 {
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
264 int radius = qMin(rect.width(), rect.height()) / 2;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
265 int diam = 2 * radius;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
266
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
267 int x1, y1, x2, y2;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
268 rect.getCoords(&x1, &y1, &x2, &y2);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
269
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
270 auto path = new QPainterPath;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
271 path.moveTo(x2, y1 + radius);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
272 path.arcTo(QRectF(x2 - diam, y1, diam, diam), 0.0, +90.0);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
273 path.lineTo(x1 + radius, y1);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
274 path.arcTo(QRectF(x1, y1, diam, diam), 90.0, +90.0);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
275 path.lineTo(x1, y2 - radius);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
276 path.arcTo(QRectF(x1, y2 - diam, diam, diam), 180.0, +90.0);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
277 path.lineTo(x1 + radius, y2);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
278 path.arcTo(QRectF(x2 - diam, y2 - diam, diam, diam), 270.0, +90.0);
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
279 path.closeSubpath();
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
280 return path;
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
281 }
37cf6fd1ee85 add styles example, still buggs
mandel
parents:
diff changeset
282 }