Mercurial > projects > qtd
comparison demos/shared/arthurstyle.d @ 162:4bbd9f3d9add
a few fixes
author | mwarning |
---|---|
date | Wed, 17 Jun 2009 22:40:56 +0000 |
parents | 691e68637348 |
children | ab01453c9d56 |
comparison
equal
deleted
inserted
replaced
161:849b66609571 | 162:4bbd9f3d9add |
---|---|
36 ** If you are unsure which license is appropriate for your use, please | 36 ** If you are unsure which license is appropriate for your use, please |
37 ** contact the sales department at qt-sales@nokia.com. | 37 ** contact the sales department at qt-sales@nokia.com. |
38 ** $QT_END_LICENSE$ | 38 ** $QT_END_LICENSE$ |
39 ** | 39 ** |
40 ****************************************************************************/ | 40 ****************************************************************************/ |
41 | 41 module arthurstyle; |
42 | 42 |
43 //import arthurwidgets; | 43 |
44 import | 44 import |
45 qt.gui.QLayout, | 45 qt.gui.QLayout, |
46 qt.gui.QWindowsStyle, | 46 qt.gui.QWindowsStyle, |
47 qt.gui.QPainter, | 47 qt.gui.QPainter, |
48 qt.gui.QPainterPath, | 48 qt.gui.QPainterPath, |
49 qt.gui.QPixmapCache, | 49 qt.gui.QPixmapCache, |
50 qt.gui.QRadioButton, | 50 qt.gui.QRadioButton, |
51 qt.gui.QPushButton, | 51 qt.gui.QPushButton, |
52 qt.gui.QGroupBox, | 52 qt.gui.QGroupBox, |
53 qt.gui.QLinearGradient, | 53 qt.gui.QLinearGradient, |
54 qt.gui.QstyleOptionFrameV2, | 54 qt.gui.QStyleOption, |
55 qt.gui.QStyleOption; | 55 qt.gui.QStyleOptionFrameV2; |
56 | |
56 | 57 |
57 class ArthurStyle : QWindowsStyle | 58 class ArthurStyle : QWindowsStyle |
58 { | 59 { |
59 QPixmap cached(string img) | 60 QPixmap cached(string img) |
60 { | 61 { |
72 | 73 |
73 this() | 74 this() |
74 { | 75 { |
75 //Q_INIT_RESOURCE(shared); | 76 //Q_INIT_RESOURCE(shared); |
76 } | 77 } |
77 | 78 |
78 | |
79 void drawHoverRect(QPainter painter, QRect r) | 79 void drawHoverRect(QPainter painter, QRect r) |
80 { | 80 { |
81 qreal h = r.height(); | 81 qreal h = r.height(); |
82 qreal h2 = r.height() / 2.0; | 82 qreal h2 = r.height() / 2.0; |
83 QPainterPath path; | 83 QPainterPath path = new QPainterPath; |
84 path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height()); | 84 path.addRect(r.x() + h2, r.y() + 0, r.width() - h2 * 2, r.height()); |
85 path.addEllipse(r.x(), r.y(), h, h); | 85 path.addEllipse(r.x(), r.y(), h, h); |
86 path.addEllipse(r.x() + r.width() - h, r.y(), h, h); | 86 path.addEllipse(r.x() + r.width() - h, r.y(), h, h); |
87 path.setFillRule(Qt.WindingFill); | 87 path.setFillRule(Qt.WindingFill); |
88 painter.setPen(Qt.NoPen); | 88 painter.setPen(Qt.NoPen); |
89 painter.setBrush(new QColor(191, 215, 191)); | 89 painter.setBrush(new QColor(191, 215, 191)); |
90 painter.setRenderHint(QPainter.Antialiasing); | 90 painter.setRenderHint(QPainter.Antialiasing); |
91 painter.drawPath(path); | 91 painter.drawPath(path); |
92 } | 92 } |
93 | 93 |
94 | 94 override void drawPrimitive(PrimitiveElement element, QStyleOption option, QPainter painter, QWidget widget) |
95 override void drawPrimitive(PrimitiveElement element, QStyleOption option, | |
96 QPainter painter, QWidget widget) | |
97 { | 95 { |
98 assert(option); | 96 assert(option); |
99 switch (element) | 97 switch (element) |
100 { | 98 { |
101 case PE_FrameFocusRect: | 99 case PE_FrameFocusRect: |
151 left = cached(":res/images/button_normal_cap_left.png"); | 149 left = cached(":res/images/button_normal_cap_left.png"); |
152 right = cached(":res/images/button_normal_cap_right.png"); | 150 right = cached(":res/images/button_normal_cap_right.png"); |
153 mid = cached(":res/images/button_normal_stretch.png"); | 151 mid = cached(":res/images/button_normal_stretch.png"); |
154 } | 152 } |
155 painter.drawPixmap(button.rect.topLeft, left); | 153 painter.drawPixmap(button.rect.topLeft, left); |
156 painter.drawTiledPixmap(new QRect(button.rect.x + left.width, | 154 painter.drawTiledPixmap(QRect(button.rect.x + left.width, |
157 button.rect.y, | 155 button.rect.y, |
158 button.rect.width - left.width - right.width, | 156 button.rect.width - left.width - right.width, |
159 left.height), | 157 left.height), |
160 mid); | 158 mid); |
161 painter.drawPixmap(button.rect.x + button.rect.width - right.width, | 159 painter.drawPixmap(button.rect.x + button.rect.width - right.width, |
166 painter.restore; | 164 painter.restore; |
167 } | 165 } |
168 break; | 166 break; |
169 | 167 |
170 case PE_FrameGroupBox: | 168 case PE_FrameGroupBox: |
171 if (QStyleOptionFrameV2 group | 169 if (QStyleOptionFrameV2 group = cast(QStyleOptionFrameV2)(option)) { |
172 = cast(QStyleOptionFrameV2)(option)) { | |
173 auto r = group.rect; | 170 auto r = group.rect; |
174 | 171 |
175 painter.save(); | 172 painter.save(); |
176 int radius = 14; | 173 int radius = 14; |
177 int radius2 = radius*2; | 174 int radius2 = radius*2; |
199 painter.drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0)); | 196 painter.drawRect(r.adjusted(0, titleStretch.height()/2, 0, 0)); |
200 painter.setClipping(false); | 197 painter.setClipping(false); |
201 | 198 |
202 int topFrameOffset = titleStretch.height()/2 - 2; | 199 int topFrameOffset = titleStretch.height()/2 - 2; |
203 painter.drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft); | 200 painter.drawPixmap(r.topLeft() + QPoint(0, topFrameOffset), topLeft); |
204 painter.drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0) | 201 painter.drawPixmap(r.topRight() - QPoint(topRight.width()-1, 0) + QPoint(0, topFrameOffset), topRight); |
205 + QPoint(0, topFrameOffset), topRight); | |
206 painter.drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft); | 202 painter.drawPixmap(r.bottomLeft() - QPoint(0, bottomLeft.height()-1), bottomLeft); |
207 painter.drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1, | 203 painter.drawPixmap(r.bottomRight() - QPoint(bottomRight.width()-1, bottomRight.height()-1), bottomRight); |
208 bottomRight.height()-1), bottomRight); | |
209 | 204 |
210 QRect left = r; | 205 QRect left = r; |
211 left.setY(r.y() + topLeft.height() + topFrameOffset); | 206 left.setY(r.y() + topLeft.height() + topFrameOffset); |
212 left.setWidth(leftStretch.width()); | 207 left.setWidth(leftStretch.width()); |
213 left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset); | 208 left.setHeight(r.height() - topLeft.height() - bottomLeft.height() - topFrameOffset); |
222 | 217 |
223 QRect right = r; | 218 QRect right = r; |
224 right.setX(r.right() - rightStretch.width()+1); | 219 right.setX(r.right() - rightStretch.width()+1); |
225 right.setY(r.y() + topRight.height() + topFrameOffset); | 220 right.setY(r.y() + topRight.height() + topFrameOffset); |
226 right.setWidth(rightStretch.width()); | 221 right.setWidth(rightStretch.width()); |
227 right.setHeight(r.height() - topRight.height() | 222 right.setHeight(r.height() - topRight.height() - bottomRight.height() - topFrameOffset); |
228 - bottomRight.height() - topFrameOffset); | |
229 painter.drawTiledPixmap(right, rightStretch); | 223 painter.drawTiledPixmap(right, rightStretch); |
230 | 224 |
231 QRect bottom = r; | 225 QRect bottom = r; |
232 bottom.setX(r.x() + bottomLeft.width()); | 226 bottom.setX(r.x() + bottomLeft.width()); |
233 bottom.setY(r.bottom() - bottomStretch.height()+1); | 227 bottom.setY(r.bottom() - bottomStretch.height()+1); |
262 drawHoverRect(painter, moderated); | 256 drawHoverRect(painter, moderated); |
263 } | 257 } |
264 | 258 |
265 if ((option.subControls & SC_SliderGroove) && groove.isValid()) { | 259 if ((option.subControls & SC_SliderGroove) && groove.isValid()) { |
266 QPixmap grv = cached(":res/images/slider_bar.png"); | 260 QPixmap grv = cached(":res/images/slider_bar.png"); |
267 painter.drawPixmap(new QRect(groove.x() + 5, groove.y(), | 261 painter.drawPixmap(QRect(groove.x() + 5, groove.y(), |
268 groove.width() - 10, grv.height()), | 262 groove.width() - 10, grv.height()), |
269 grv); | 263 grv); |
270 } | 264 } |
271 if ((option.subControls & SC_SliderHandle) && handle.isValid()) { | 265 if ((option.subControls & SC_SliderHandle) && handle.isValid()) { |
272 QPixmap hndl = cached(":res/images/slider_thumb_on.png"); | 266 QPixmap hndl = cached(":res/images/slider_thumb_on.png"); |
342 case SC_GroupBoxLabel: | 336 case SC_GroupBoxLabel: |
343 QPixmap titleLeft = cached(":res/images/title_cap_left.png"); | 337 QPixmap titleLeft = cached(":res/images/title_cap_left.png"); |
344 QPixmap titleRight = cached(":res/images/title_cap_right.png"); | 338 QPixmap titleRight = cached(":res/images/title_cap_right.png"); |
345 QPixmap titleStretch = cached(":res/images/title_stretch.png"); | 339 QPixmap titleStretch = cached(":res/images/title_stretch.png"); |
346 int txt_width = group.fontMetrics.width(group.text) + 20; | 340 int txt_width = group.fontMetrics.width(group.text) + 20; |
347 rect = new QRect(group.rect.center().x() - txt_width/2 + titleLeft.width(), 0, | 341 rect = QRect(group.rect.center().x() - txt_width/2 + titleLeft.width(), 0, |
348 txt_width - titleLeft.width() - titleRight.width(), | 342 txt_width - titleLeft.width() - titleRight.width(), |
349 titleStretch.height()); | 343 titleStretch.height()); |
350 break; | 344 break; |
351 } | 345 } |
352 } | 346 } |
396 } | 390 } |
397 | 391 |
398 override void polish(QWidget widget) | 392 override void polish(QWidget widget) |
399 { | 393 { |
400 if (widget.layout() && cast(QGroupBox)(widget)) { | 394 if (widget.layout() && cast(QGroupBox)(widget)) { |
401 if (widget.findChildren!(QGroupBox).length == 0) { | 395 if (qFindChildren!(QGroupBox)(widget).length == 0) { |
402 widget.layout().setWidgetSpacing(0); // Why setSpacing was renamed to setWidgetSpacing? | 396 widget.layout().setWidgetSpacing(0); // Why setSpacing was renamed to setWidgetSpacing? |
403 widget.layout().setMargin(12); | 397 widget.layout().setMargin(12); |
404 } else { | 398 } else { |
405 widget.layout().setMargin(13); | 399 widget.layout().setMargin(13); |
406 } | 400 } |
415 QPalette pal = widget.palette(); | 409 QPalette pal = widget.palette(); |
416 if (widget.isWindow()) { | 410 if (widget.isWindow()) { |
417 pal.setColor(QPalette.Window, new QColor(241, 241, 241)); | 411 pal.setColor(QPalette.Window, new QColor(241, 241, 241)); |
418 widget.setPalette(pal); | 412 widget.setPalette(pal); |
419 } | 413 } |
420 | |
421 } | 414 } |
422 | 415 |
423 override void unpolish(QWidget widget) | 416 override void unpolish(QWidget widget) |
424 { | 417 { |
425 if (cast(QPushButton)(widget) | 418 if (cast(QPushButton)(widget) |