Qt 4.8
qplastiquestyle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qplastiquestyle.h"
43 
44 #if !defined(QT_NO_STYLE_PLASTIQUE) || defined(QT_PLUGIN)
45 
46 static const bool AnimateBusyProgressBar = true;
47 static const bool AnimateProgressBar = false;
48 // #define QPlastique_MaskButtons
49 static const int ProgressBarFps = 25;
50 static const int blueFrameWidth = 2; // with of line edit focus frame
51 
52 #include "qwindowsstyle_p.h"
53 #include <qapplication.h>
54 #include <qbitmap.h>
55 #include <qabstractitemview.h>
56 #include <qcheckbox.h>
57 #include <qcombobox.h>
58 #include <qdebug.h>
59 #include <qdialogbuttonbox.h>
60 #include <qformlayout.h>
61 #include <qgroupbox.h>
62 #include <qimage.h>
63 #include <qlineedit.h>
64 #include <qmainwindow.h>
65 #include <qmenu.h>
66 #include <qmenubar.h>
67 #include <qpainter.h>
68 #include <qpaintengine.h>
69 #include <qpainterpath.h>
70 #include <qpalette.h>
71 #include <qpen.h>
72 #include <qpixmap.h>
73 #include <qpixmapcache.h>
74 #include <qprogressbar.h>
75 #include <qpushbutton.h>
76 #include <qradiobutton.h>
77 #include <qscrollbar.h>
78 #include <qspinbox.h>
79 #include <qsplitter.h>
80 #include <qstyleoption.h>
81 #include <qtextedit.h>
82 #include <qelapsedtimer.h>
83 #include <qtoolbar.h>
84 #include <qtoolbox.h>
85 #include <qtoolbutton.h>
86 #include <qworkspace.h>
87 #include <qprocess.h>
88 #include <qvarlengtharray.h>
89 #include <limits.h>
90 #include <private/qstylehelper_p.h>
91 
93 
94 // from windows style
95 static const int windowsItemFrame = 2; // menu item frame width
96 static const int windowsSepHeight = 2; // separator item height
97 static const int windowsItemHMargin = 3; // menu item hor text margin
98 static const int windowsItemVMargin = 2; // menu item ver text margin
99 static const int windowsArrowHMargin = 6; // arrow horizontal margin
100 static const int windowsTabSpacing = 12; // space between text and tab
101 static const int windowsRightBorder = 15; // right border on windows
102 static const int windowsCheckMarkWidth = 12; // checkmarks width on windows
103 
104 static const char * const qt_plastique_slider_verticalhandle[] = {
105  "15 11 6 1",
106  " c None",
107  "+ c #979797",
108  "@ c #C9C9C9",
109  "$ c #C1C1C1",
110  "b c None",
111  "d c None",
112  " $++++++++$ ",
113  "$+bbbbbbbb+$ ",
114  "+b $$ +$ ",
115  "+b $@ +$ ",
116  "+b +$",
117  "+b d+",
118  "+b d+$",
119  "+b $$ d+$ ",
120  "+b $@ d+$ ",
121  "$+dddddddd+$ ",
122  " $++++++++$ "};
123 
124 static const char * const qt_plastique_slider_verticalhandle_left[] = {
125  "15 11 6 1",
126  " c None",
127  "+ c #979797",
128  "@ c #C9C9C9",
129  "$ c #C1C1C1",
130  "b c None",
131  "d c None",
132  " $++++++++$ ",
133  " $+bbbbbbbb+$",
134  " $+b $$ d+",
135  " $+b $@ d+",
136  "$+b d+",
137  "+b d+",
138  "$+ d+",
139  " $+ $$ d+",
140  " $+ $@ d+",
141  " $+dddddddd+$",
142  " $++++++++$ "};
143 
144 static const char * const qt_plastique_slider_horizontalhandle[] = {
145  "11 15 6 1",
146  " c None",
147  "+ c #979797",
148  "@ c #C9C9C9",
149  "$ c #C1C1C1",
150  "b c None",
151  "d c None",
152  " $+++++++$ ",
153  "$+bbbbbbb+$",
154  "+b d+",
155  "+b$$ $$d+",
156  "+b$@ $@d+",
157  "+b d+",
158  "+b d+",
159  "+b d+",
160  "+b d+",
161  "+b d+",
162  "$+ d+$",
163  " $+ d+$ ",
164  " $+ d+$ ",
165  " $+d+$ ",
166  " $+$ "};
167 
168 static const char * const qt_plastique_slider_horizontalhandle_up[] = {
169  "11 15 6 1",
170  " c None",
171  "+ c #979797",
172  "@ c #C9C9C9",
173  "$ c #C1C1C1",
174  "b c None",
175  "d c None",
176  " $+$ ",
177  " $+b+$ ",
178  " $+b +$ ",
179  " $+b +$ ",
180  "$+b +$",
181  "+b d+",
182  "+b d+",
183  "+b d+",
184  "+b d+",
185  "+b d+",
186  "+b$$ $$d+",
187  "+b$@ $@d+",
188  "+b d+",
189  "$+ddddddd+$",
190  " $+++++++$ "};
191 
192 static const char * const qt_scrollbar_button_arrow_left[] = {
193  "4 7 2 1",
194  " c None",
195  "* c #BFBFBF",
196  " *",
197  " **",
198  " ***",
199  "****",
200  " ***",
201  " **",
202  " *"};
203 
204 static const char * const qt_scrollbar_button_arrow_right[] = {
205  "4 7 2 1",
206  " c None",
207  "* c #BFBFBF",
208  "* ",
209  "** ",
210  "*** ",
211  "****",
212  "*** ",
213  "** ",
214  "* "};
215 
216 static const char * const qt_scrollbar_button_arrow_up[] = {
217  "7 4 2 1",
218  " c None",
219  "* c #BFBFBF",
220  " * ",
221  " *** ",
222  " ***** ",
223  "*******"};
224 
225 static const char * const qt_scrollbar_button_arrow_down[] = {
226  "7 4 2 1",
227  " c None",
228  "* c #BFBFBF",
229  "*******",
230  " ***** ",
231  " *** ",
232  " * "};
233 
234 static const char * const qt_scrollbar_button_left[] = {
235  "16 16 6 1",
236  " c None",
237  ". c #BFBFBF",
238  "+ c #979797",
239  "# c #FAFAFA",
240  "< c #FAFAFA",
241  "* c #FAFAFA",
242  " .+++++++++++++.",
243  ".+#############+",
244  "+# <+",
245  "+# <+",
246  "+# <+",
247  "+# <+",
248  "+# <+",
249  "+# <+",
250  "+# <+",
251  "+# <+",
252  "+# <+",
253  "+# <+",
254  "+# <+",
255  "+# <+",
256  ".+<<<<<<<<<<<<<+",
257  " .+++++++++++++."};
258 
259 static const char * const qt_scrollbar_button_right[] = {
260  "16 16 6 1",
261  " c None",
262  ". c #BFBFBF",
263  "+ c #979797",
264  "# c #FAFAFA",
265  "< c #FAFAFA",
266  "* c #FAFAFA",
267  ".+++++++++++++. ",
268  "+#############+.",
269  "+# <+",
270  "+# <+",
271  "+# <+",
272  "+# <+",
273  "+# <+",
274  "+# <+",
275  "+# <+",
276  "+# <+",
277  "+# <+",
278  "+# <+",
279  "+# <+",
280  "+# <+",
281  "+<<<<<<<<<<<<<+.",
282  ".+++++++++++++. "};
283 
284 static const char * const qt_scrollbar_button_up[] = {
285  "16 16 6 1",
286  " c None",
287  ". c #BFBFBF",
288  "+ c #979797",
289  "# c #FAFAFA",
290  "< c #FAFAFA",
291  "* c #FAFAFA",
292  " .++++++++++++. ",
293  ".+############+.",
294  "+# <+",
295  "+# <+",
296  "+# <+",
297  "+# <+",
298  "+# <+",
299  "+# <+",
300  "+# <+",
301  "+# <+",
302  "+# <+",
303  "+# <+",
304  "+# <+",
305  "+# <+",
306  "+<<<<<<<<<<<<<<+",
307  ".++++++++++++++."};
308 
309 static const char * const qt_scrollbar_button_down[] = {
310  "16 16 6 1",
311  " c None",
312  ". c #BFBFBF",
313  "+ c #979797",
314  "# c #FAFAFA",
315  "< c #FAFAFA",
316  "* c #FAFAFA",
317  "++++++++++++++++",
318  "+##############+",
319  "+# <+",
320  "+# <+",
321  "+# <+",
322  "+# <+",
323  "+# <+",
324  "+# <+",
325  "+# <+",
326  "+# <+",
327  "+# <+",
328  "+# <+",
329  "+# <+",
330  "+# <+",
331  ".+<<<<<<<<<<<<+.",
332  " .++++++++++++. "};
333 
334 static const char * const qt_scrollbar_slider_pattern_vertical[] = {
335  "10 18 3 1",
336  " c None",
337  ". c #BFBFBF",
338  "+ c #979797",
339  ".. .. ..",
340  ".+ .+ .+",
341  " ",
342  " ",
343  ".. .. ..",
344  ".+ .+ .+",
345  " ",
346  " ",
347  ".. .. ..",
348  ".+ .+ .+",
349  " ",
350  " ",
351  ".. .. ..",
352  ".+ .+ .+",
353  " ",
354  " ",
355  ".. .. ..",
356  ".+ .+ .+"};
357 
358 static const char * const qt_scrollbar_slider_pattern_horizontal[] = {
359  "18 10 3 1",
360  " c None",
361  ". c #BFBFBF",
362  "+ c #979797",
363  ".. .. .. .. ..",
364  ".+ .+ .+ .+ .+",
365  " ",
366  " ",
367  ".. .. .. .. ..",
368  ".+ .+ .+ .+ .+",
369  " ",
370  " ",
371  ".. .. .. .. ..",
372  ".+ .+ .+ .+ .+"};
373 
374 static const char * const qt_toolbarhandle[] = {
375  "6 6 4 1",
376  " c None",
377  ". c #C5C5C5",
378  "+ c #EEEEEE",
379  "@ c #FAFAFA",
380  ".. ",
381  ".+@ ",
382  " @@ ",
383  " .. ",
384  " .+@",
385  " @@"};
386 
387 static const char * const qt_simple_toolbarhandle[] = {
388  "3 3 4 1",
389  " c None",
390  ". c #C5C5C5",
391  "+ c #EEEEEE",
392  "@ c #FAFAFA",
393  ".. ",
394  ".+@",
395  " @@"};
396 
397 static const char * const qt_titlebar_context_help[] = {
398 "27 27 5 1",
399 " c None",
400 ". c #0A0C12",
401 "+ c #1B202D",
402 "@ c #293144",
403 "# c #3C435D",
404 " ",
405 " ",
406 " ",
407 " ",
408 " ",
409 " ",
410 " ",
411 " ",
412 " +@##@+ ",
413 " .@@@.+@@.. ",
414 " .##+ +@@+. ",
415 " .##@ @#@+. ",
416 " .... +@+.. ",
417 " .@+@@.. ",
418 " +#@@+ ",
419 " .##. ",
420 " .++. ",
421 " .++. ",
422 " +##+ ",
423 " .@@. ",
424 " ",
425 " ",
426 " ",
427 " ",
428 " ",
429 " ",
430 " "};
431 
432 static QLinearGradient qMapGradientToRect(const QLinearGradient &gradient, const QRectF &rect)
433 {
434  QLinearGradient tmpGrad(rect.center().x(), rect.top(),
435  rect.center().x(), rect.bottom());
436  tmpGrad.setStops(gradient.stops());
437  return tmpGrad;
438 }
439 
440 static QBrush qMapBrushToRect(const QBrush &brush, const QRectF &rect)
441 {
442  if (!brush.gradient())
443  return brush;
444 
445  // ### Ugly assumption that it's a linear gradient
446  QBrush tmp(qMapGradientToRect(*static_cast<const QLinearGradient *>(brush.gradient()), rect));
447  return tmp;
448 }
449 
450 static void qBrushSetAlphaF(QBrush *brush, qreal alpha)
451 {
452  if (const QGradient *gradient = brush->gradient()) {
453  // Use the gradient. Call QColor::setAlphaF() on all color stops.
454  QGradientStops stops = gradient->stops();
455  QMutableVectorIterator<QGradientStop> it(stops);
456  QColor tmpColor;
457  while (it.hasNext()) {
458  it.next();
459  tmpColor = it.value().second;
460  tmpColor.setAlphaF(alpha * tmpColor.alphaF());
461  it.setValue(QPair<qreal, QColor>(it.value().first, tmpColor));
462  }
463 
464  switch (gradient->type()) {
466  QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
467  grad.setStops(stops);
468  *brush = QBrush(grad);
469  break;
470  }
472  QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
473  grad.setStops(stops);
474  *brush = QBrush(grad);
475  break;
476  }
477  default:
478  qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
479  " - falling back to QLinearGradient");
481  QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
482  grad.setStops(stops);
483  *brush = QBrush(grad);
484  break;
485  }
486  }
487  } else if (!brush->texture().isNull()) {
488  // Modify the texture - ridiculously expensive.
489  QPixmap texture = brush->texture();
490  QPixmap pixmap;
491  QString name = QLatin1Literal("qbrushtexture-alpha")
492  % HexString<qreal>(alpha)
493  % HexString<qint64>(texture.cacheKey());
494  if (!QPixmapCache::find(name, pixmap)) {
495  QImage image = texture.toImage();
496  QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
497  int pixels = image.width() * image.height();
498  QColor tmpColor;
499  while (pixels--) {
500  tmpColor.setRgb(*rgb);
501  tmpColor.setAlphaF(alpha * tmpColor.alphaF());
502  *rgb++ = tmpColor.rgba();
503  }
504  pixmap = QPixmap::fromImage(image);
505  QPixmapCache::insert(name, pixmap);
506  }
507  brush->setTexture(pixmap);
508  } else {
509  // Use the color
510  QColor tmpColor = brush->color();
511  tmpColor.setAlphaF(alpha * tmpColor.alphaF());
512  brush->setColor(tmpColor);
513  }
514 }
515 
516 static QBrush qBrushLight(QBrush brush, int light)
517 {
518  if (const QGradient *gradient = brush.gradient()) {
519  // Use the gradient. Call QColor::lighter() on all color stops.
520  QGradientStops stops = gradient->stops();
521  QMutableVectorIterator<QGradientStop> it(stops);
522  while (it.hasNext()) {
523  it.next();
524  it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.lighter(light)));
525  }
526 
527  switch (gradient->type()) {
529  QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
530  grad.setStops(stops);
531  brush = QBrush(grad);
532  break;
533  }
535  QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
536  grad.setStops(stops);
537  brush = QBrush(grad);
538  break;
539  }
540  default:
541  qWarning("QPlastiqueStyle::qBrushLight() - unknown gradient type"
542  " - falling back to QLinearGradient");
544  QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
545  grad.setStops(stops);
546  brush = QBrush(grad);
547  break;
548  }
549  }
550  } else if (!brush.texture().isNull()) {
551  // Modify the texture - ridiculously expensive.
552  QPixmap texture = brush.texture();
553  QPixmap pixmap;
554  QString name = QLatin1Literal("qbrushtexture-light")
555  % HexString<int>(light)
556  % HexString<qint64>(texture.cacheKey());
557 
558  if (!QPixmapCache::find(name, pixmap)) {
559  QImage image = texture.toImage();
560  QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
561  int pixels = image.width() * image.height();
562  QColor tmpColor;
563  while (pixels--) {
564  tmpColor.setRgb(*rgb);
565  *rgb++ = tmpColor.lighter(light).rgba();
566  }
567  pixmap = QPixmap::fromImage(image);
568  QPixmapCache::insert(name, pixmap);
569  }
570  brush.setTexture(pixmap);
571  } else {
572  // Use the color
573  brush.setColor(brush.color().lighter(light));
574  }
575  return brush;
576 }
577 
578 static QBrush qBrushDark(QBrush brush, int dark)
579 {
580  if (const QGradient *gradient = brush.gradient()) {
581  // Use the gradient. Call QColor::darker() on all color stops.
582  QGradientStops stops = gradient->stops();
583  QMutableVectorIterator<QGradientStop> it(stops);
584  while (it.hasNext()) {
585  it.next();
586  it.setValue(QPair<qreal, QColor>(it.value().first, it.value().second.darker(dark)));
587  }
588 
589  switch (gradient->type()) {
591  QRadialGradient grad = *static_cast<const QRadialGradient *>(gradient);
592  grad.setStops(stops);
593  brush = QBrush(grad);
594  break;
595  }
597  QConicalGradient grad = *static_cast<const QConicalGradient *>(gradient);
598  grad.setStops(stops);
599  brush = QBrush(grad);
600  break;
601  }
602  default:
603  qWarning("QPlastiqueStyle::qBrushDark() - unknown gradient type"
604  " - falling back to QLinearGradient");
606  QLinearGradient grad = *static_cast<const QLinearGradient *>(gradient);
607  grad.setStops(stops);
608  brush = QBrush(grad);
609  break;
610  }
611  }
612  } else if (!brush.texture().isNull()) {
613  // Modify the texture - ridiculously expensive.
614  QPixmap texture = brush.texture();
615  QPixmap pixmap;
616  QString name = QLatin1Literal("qbrushtexture-dark")
617  % HexString<int>(dark)
618  % HexString<qint64>(texture.cacheKey());
619 
620  if (!QPixmapCache::find(name, pixmap)) {
621  QImage image = texture.toImage();
622  QRgb *rgb = reinterpret_cast<QRgb *>(image.bits());
623  int pixels = image.width() * image.height();
624  QColor tmpColor;
625  while (pixels--) {
626  tmpColor.setRgb(*rgb);
627  *rgb++ = tmpColor.darker(dark).rgba();
628  }
629  pixmap = QPixmap::fromImage(image);
630  QPixmapCache::insert(name, pixmap);
631  }
632  brush.setTexture(pixmap);
633  } else {
634  // Use the color
635  brush.setColor(brush.color().darker(dark));
636  }
637  return brush;
638 }
639 
640 /*
641  Draws a rounded frame using the provided brush for 1, and adds 0.5 alpha
642  for 0.
643 
644  0111111110
645  01 10
646  1 1
647  1 1
648  1 1
649  01 10
650  0111111110
651 */
652 static void qt_plastique_draw_frame(QPainter *painter, const QRect &rect, const QStyleOption *option,
653  QFrame::Shadow shadow = QFrame::Plain)
654 {
655  QPen oldPen = painter->pen();
656  QBrush border;
657  QBrush corner;
658  QBrush innerTopLeft;
659  QBrush innerBottomRight;
660 
661  if (shadow != QFrame::Plain && (option->state & QStyle::State_HasFocus)) {
662  border = option->palette.highlight();
663  qBrushSetAlphaF(&border, qreal(0.8));
664  corner = option->palette.highlight();
665  qBrushSetAlphaF(&corner, 0.5);
666  innerTopLeft = qBrushDark(option->palette.highlight(), 125);
667  innerBottomRight = option->palette.highlight();
668  qBrushSetAlphaF(&innerBottomRight, qreal(0.65));
669  } else {
670  border = option->palette.shadow();
671  qBrushSetAlphaF(&border, qreal(0.4));
672  corner = option->palette.shadow();
673  qBrushSetAlphaF(&corner, 0.25);
674  innerTopLeft = option->palette.shadow();
675  innerBottomRight = option->palette.shadow();
676  if (shadow == QFrame::Sunken) {
677  qBrushSetAlphaF(&innerTopLeft, qreal(0.23));
678  qBrushSetAlphaF(&innerBottomRight, qreal(0.075));
679  } else {
680  qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
681  qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
682  }
683  }
684 
685  QLine lines[4];
686  QPoint points[8];
687 
688  // Opaque corner lines
689  painter->setPen(QPen(border, 0));
690  lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
691  lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
692  lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
693  lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
694  painter->drawLines(lines, 4);
695 
696  // Opaque corner dots
697  points[0] = QPoint(rect.left() + 1, rect.top() + 1);
698  points[1] = QPoint(rect.left() + 1, rect.bottom() - 1);
699  points[2] = QPoint(rect.right() - 1, rect.top() + 1);
700  points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
701  painter->drawPoints(points, 4);
702 
703  // Shaded corner dots
704  painter->setPen(QPen(corner, 0));
705  points[0] = QPoint(rect.left(), rect.top() + 1);
706  points[1] = QPoint(rect.left(), rect.bottom() - 1);
707  points[2] = QPoint(rect.left() + 1, rect.top());
708  points[3] = QPoint(rect.left() + 1, rect.bottom());
709  points[4] = QPoint(rect.right(), rect.top() + 1);
710  points[5] = QPoint(rect.right(), rect.bottom() - 1);
711  points[6] = QPoint(rect.right() - 1, rect.top());
712  points[7] = QPoint(rect.right() - 1, rect.bottom());
713  painter->drawPoints(points, 8);
714 
715  // Shadows
716  if (shadow != QFrame::Plain) {
717  painter->setPen(QPen(innerTopLeft, 0));
718  lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
719  lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
720  painter->drawLines(lines, 2);
721  painter->setPen(QPen(innerBottomRight, 0));
722  lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
723  lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
724  painter->drawLines(lines, 2);
725  }
726 
727  painter->setPen(oldPen);
728 }
729 
730 static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor = 50)
731 {
732  const int maxFactor = 100;
733  QColor tmp = colorA;
734  tmp.setRed((tmp.red() * factor) / maxFactor + (colorB.red() * (maxFactor - factor)) / maxFactor);
735  tmp.setGreen((tmp.green() * factor) / maxFactor + (colorB.green() * (maxFactor - factor)) / maxFactor);
736  tmp.setBlue((tmp.blue() * factor) / maxFactor + (colorB.blue() * (maxFactor - factor)) / maxFactor);
737  return tmp;
738 }
739 
740 static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart,
741  const QColor &gradientStop)
742 {
743  QString gradientName = QLatin1Literal("qplastique-g")
744  % HexString<int>(rect.width())
745  % HexString<int>(rect.height())
746  % HexString<QRgb>(gradientStart.rgba())
747  % HexString<QRgb>(gradientStop.rgba());
748 
749  QPixmap cache;
750  QPainter *p = painter;
751  QRect r = rect;
752 
753  bool doPixmapCache = painter->deviceTransform().isIdentity()
754  && painter->worldMatrix().isIdentity();
755  if (doPixmapCache && QPixmapCache::find(gradientName, cache)) {
756  painter->drawPixmap(rect, cache);
757  } else {
758  if (doPixmapCache) {
759  cache = QPixmap(rect.size());
760  cache.fill(Qt::transparent);
761  p = new QPainter(&cache);
762  r = QRect(0, 0, rect.width(), rect.height());
763  }
764 
765  int x = r.center().x();
766  QLinearGradient gradient(x, r.top(), x, r.bottom());
767  gradient.setColorAt(0, gradientStart);
768  gradient.setColorAt(1, gradientStop);
769  p->fillRect(r, gradient);
770 
771  if (doPixmapCache) {
772  p->end();
773  delete p;
774  painter->drawPixmap(rect, cache);
775  QPixmapCache::insert(gradientName, cache);
776  }
777  }
778 }
779 
780 static void qt_plastique_drawFrame(QPainter *painter, const QStyleOption *option, const QWidget *widget)
781 {
782  QRect rect = option->rect;
783  QPen oldPen = painter->pen();
784 
785  QColor borderColor = option->palette.background().color().darker(178);
786  QColor gradientStartColor = option->palette.button().color().lighter(104);
787  QColor gradientStopColor = option->palette.button().color().darker(105);
788  QColor alphaCornerColor;
789  if (widget) {
790  // ### backgroundrole/foregroundrole should be part of the style option
791  alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
792  } else {
793  alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
794  }
795 
796  QLine lines[4];
797  QPoint points[8];
798 
799  // outline / border
800  painter->setPen(borderColor);
801  lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
802  lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
803  lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
804  lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
805  painter->drawLines(lines, 4);
806 
807  points[0] = QPoint(rect.left() + 1, rect.top() + 1);
808  points[1] = QPoint(rect.right() - 1, rect.top() + 1);
809  points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
810  points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
811  painter->drawPoints(points, 4);
812 
813  painter->setPen(alphaCornerColor);
814 
815  points[0] = QPoint(rect.left() + 1, rect.top());
816  points[1] = QPoint(rect.right() - 1, rect.top());
817  points[2] = QPoint(rect.left() + 1, rect.bottom());
818  points[3] = QPoint(rect.right() - 1, rect.bottom());
819  points[4] = QPoint(rect.left(), rect.top() + 1);
820  points[5] = QPoint(rect.right(), rect.top() + 1);
821  points[6] = QPoint(rect.left(), rect.bottom() - 1);
822  points[7] = QPoint(rect.right(), rect.bottom() - 1);
823  painter->drawPoints(points, 8);
824 
825  // inner border
826  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
827  painter->setPen(option->palette.button().color().darker(118));
828  else
829  painter->setPen(gradientStartColor);
830 
831  lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, option->rect.top() + 1);
832  lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, option->rect.bottom() - 2);
833  painter->drawLines(lines, 2);
834 
835  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
836  painter->setPen(option->palette.button().color().darker(110));
837  else
838  painter->setPen(gradientStopColor.darker(102));
839 
840  lines[0] = QLine(rect.left() + 2, rect.bottom() - 1, rect.right() - 2, rect.bottom() - 1);
841  lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
842  painter->drawLines(lines, 2);
843 
844  painter->setPen(oldPen);
845 }
846 
847 static void qt_plastique_drawShadedPanel(QPainter *painter, const QStyleOption *option, bool base,
848  const QWidget *widget)
849 {
850  QRect rect = option->rect;
851  QPen oldPen = painter->pen();
852 
853  QColor gradientStartColor = option->palette.button().color().lighter(104);
854  QColor gradientStopColor = option->palette.button().color().darker(105);
855 
856  // gradient fill
857  if ((option->state & QStyle::State_Enabled) || !(option->state & QStyle::State_AutoRaise)) {
858  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) {
859  qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
860  option->palette.button().color().darker(114),
861  option->palette.button().color().darker(106));
862  } else {
863  qt_plastique_draw_gradient(painter, rect.adjusted(1, 1, -1, -1),
864  base ? option->palette.background().color().lighter(105) : gradientStartColor,
865  base ? option->palette.background().color().darker(102) : gradientStopColor);
866  }
867  }
868 
869  qt_plastique_drawFrame(painter, option, widget);
870 
871  painter->setPen(oldPen);
872 }
873 
874 static void qt_plastique_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
875 {
876  if (tmp.isNull())
877  return;
878  bool active = (option->titleBarState & QStyle::State_Active);
879 
880  // ### use palette colors instead
881  QColor mdiButtonGradientStartColor;
882  QColor mdiButtonGradientStopColor;
883  if (active) {
884  mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x7d8bb1 : 0x55689a);
885  mdiButtonGradientStopColor = QColor((hover || sunken) ? 0x939ebe : 0x7381ab);
886  } else {
887  mdiButtonGradientStartColor = QColor((hover || sunken) ? 0x9e9e9e : 0x818181);
888  mdiButtonGradientStopColor = QColor((hover || sunken) ? 0xababab : 0x929292);
889  }
890 
891  qt_plastique_draw_gradient(painter, tmp.adjusted(1, 1, -1, -1),
892  mdiButtonGradientStartColor, mdiButtonGradientStopColor);
893 
894  QColor mdiButtonBorderColor;
895  if (active) {
896  mdiButtonBorderColor = (hover || sunken) ? QColor(0x627097) : QColor(0x324577);
897  } else {
898  mdiButtonBorderColor = (hover || sunken) ? QColor(0x838383) : QColor(0x5e5e5e);
899  }
900  painter->setPen(QPen(mdiButtonBorderColor, 1));
901 
902  const QLine lines[4] = {
903  QLine(tmp.left() + 2, tmp.top(), tmp.right() - 2, tmp.top()),
904  QLine(tmp.left() + 2, tmp.bottom(), tmp.right() - 2, tmp.bottom()),
905  QLine(tmp.left(), tmp.top() + 2, tmp.left(), tmp.bottom() - 2),
906  QLine(tmp.right(), tmp.top() + 2, tmp.right(), tmp.bottom() - 2) };
907  painter->drawLines(lines, 4);
908 
909  const QPoint points[4] = {
910  QPoint(tmp.left() + 1, tmp.top() + 1),
911  QPoint(tmp.right() - 1, tmp.top() + 1),
912  QPoint(tmp.left() + 1, tmp.bottom() - 1),
913  QPoint(tmp.right() - 1, tmp.bottom() - 1) };
914  painter->drawPoints(points, 4);
915 }
916 
917 #ifndef QT_NO_DOCKWIDGET
918 static QString elliditide(const QString &text, const QFontMetrics &fontMetrics, const QRect &rect, int *textWidth = 0)
919 {
920  // Chop and insert ellide into title if text is too wide
921  QString title = text;
922  int width = textWidth ? *textWidth : fontMetrics.width(text);
923  QString ellipsis = QLatin1String("...");
924  if (width > rect.width()) {
925  QString leftHalf = title.left(title.size() / 2);
926  QString rightHalf = title.mid(leftHalf.size() + 1);
927  while (!leftHalf.isEmpty() && !rightHalf.isEmpty()) {
928  leftHalf.chop(1);
929  int width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
930  if (width < rect.width()) {
931  title = leftHalf + ellipsis + rightHalf;
932  width = width;
933  break;
934  }
935  rightHalf.remove(0, 1);
936  width = fontMetrics.width(leftHalf + ellipsis + rightHalf);
937  if (width < rect.width()) {
938  title = leftHalf + ellipsis + rightHalf;
939  width = width;
940  break;
941  }
942  }
943  }
944  if (textWidth)
945  *textWidth = width;
946  return title;
947 }
948 #endif
949 
950 #if !defined(QT_NO_DOCKWIDGET) || !defined(QT_NO_SPLITTER)
951 static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option,
952  const QRect &rect, Qt::Orientation orientation,
953  const QWidget *widget)
954 {
955  QColor borderColor = option->palette.background().color().darker(178);
956  QColor alphaCornerColor;
957  if (widget) {
958  // ### backgroundrole/foregroundrole should be part of the style option
959  alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
960  } else {
961  alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
962  }
964  alphaCornerColor.setAlpha(170);
965  handle.setColor(1, alphaCornerColor.rgba());
966  handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
967  handle.setColor(3, option->palette.light().color().rgba());
968 
969  const int spacing = 2;
970 
971  if (orientation == Qt::Vertical) {
972  int nchunks = rect.width() / (handle.width() + spacing);
973  for (int i = 0; i < nchunks; ++i)
974  painter->drawImage(QPoint(rect.left() + i * (handle.width() + spacing), rect.top()), handle);
975  } else {
976  int nchunks = rect.height() / (handle.height() + spacing);
977  for (int i = 0; i < nchunks; ++i)
978  painter->drawImage(QPoint(rect.left(), rect.top() + i * (handle.height() + spacing)), handle);
979  }
980 }
981 #endif
982 
984 {
986 public:
988  virtual ~QPlastiqueStylePrivate();
989  void drawPartialFrame(QPainter *painter, const QStyleOptionComplex *option,
990  const QRect &rect, const QWidget *widget) const;
991 
992 #ifndef QT_NO_PROGRESSBAR
996 #endif
997 };
998 
1004 #ifndef QT_NO_PROGRESSBAR
1006 #endif
1007 {
1008 }
1009 
1014 {
1015 }
1016 
1038 {
1039  setObjectName(QLatin1String("Plastique"));
1040 }
1041 
1046 {
1047 }
1048 
1049 /*
1050  Used by spin- and combo box.
1051  Draws a rounded frame around rect but omits the right hand edge
1052 */
1054  const QRect &rect, const QWidget *widget) const
1055 {
1056  Q_Q(const QPlastiqueStyle);
1057  bool reverse = option->direction == Qt::RightToLeft;
1058  QStyleOptionFrame frameOpt;
1059 #ifndef QT_NO_LINEEDIT
1060  if (QLineEdit *lineedit = widget->findChild<QLineEdit *>())
1061  frameOpt.initFrom(lineedit);
1062 #else
1063  Q_UNUSED(widget)
1064 #endif // QT_NO_LINEEDIT
1065 
1066  frameOpt.rect = rect;
1067  painter->save();
1068  frameOpt.rect.adjust(-blueFrameWidth + (reverse ? 1 : 0), -blueFrameWidth,
1069  blueFrameWidth + (reverse ? 0 : -1), blueFrameWidth);
1070  painter->setClipRect(frameOpt.rect);
1071  frameOpt.rect.adjust(reverse ? -2 : 0, 0, reverse ? 0 : 2, 0);
1072  frameOpt.lineWidth = q->pixelMetric(QStyle::PM_DefaultFrameWidth);
1073  frameOpt.midLineWidth = 0;
1074  frameOpt.state = option->state | QStyle::State_Sunken;
1075  frameOpt.palette = option->palette;
1076  q->drawPrimitive(QStyle::PE_PanelLineEdit, &frameOpt, painter, widget);
1077  painter->restore();
1078 
1079  // Draw a two pixel highlight on the flat edge
1080  if (option->state & QStyle::State_HasFocus) {
1081  painter->setPen(QPen(option->palette.highlight(), 0));
1082  QBrush focusBorder = option->palette.highlight();
1083  qBrushSetAlphaF(&focusBorder, qreal(0.65));
1084  if (!reverse) {
1085  painter->drawLine(rect.topRight() + QPoint(1, -1),
1086  rect.bottomRight() + QPoint(1, 1));
1087  painter->setPen(QPen(focusBorder, 0));
1088  painter->drawLine(rect.topRight(),
1089  rect.bottomRight());
1090  }
1091  else {
1092  painter->drawLine(rect.topLeft() + QPoint(-1, -1),
1093  rect.bottomLeft() + QPoint(-1, 1));
1094  painter->setPen(QPen(focusBorder, 0));
1095  painter->drawLine(rect.topLeft(),
1096  rect.bottomLeft());
1097  }
1098  }
1099 }
1100 
1105  QPainter *painter, const QWidget *widget) const
1106 {
1107  Q_ASSERT(option);
1108 
1109  QColor borderColor = option->palette.background().color().darker(178);
1110  QColor alphaCornerColor;
1111  if (widget) {
1112  // ### backgroundrole/foregroundrole should be part of the style option
1113  alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
1114  } else {
1115  alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
1116  }
1117  QColor alphaTextColor = mergedColors(option->palette.background().color(), option->palette.text().color());
1118 
1119  switch (element) {
1121  proxy()->drawPrimitive(PE_PanelButtonTool, option, painter, widget);
1122  break;
1123  case PE_FrameDefaultButton: {
1124  if (!(option->state & QStyle::State_Enabled))
1125  break;
1126  painter->setPen(QPen(QColor(0, 0, 0, 127), 0));
1127  const QLine lines[4] = {
1128  QLine(option->rect.left() + 2, option->rect.top(),
1129  option->rect.right() - 2, option->rect.top()),
1130  QLine(option->rect.left() + 2, option->rect.bottom(),
1131  option->rect.right() - 2, option->rect.bottom()),
1132  QLine(option->rect.left(), option->rect.top() + 2,
1133  option->rect.left(), option->rect.bottom() - 2),
1134  QLine(option->rect.right(), option->rect.top() + 2,
1135  option->rect.right(), option->rect.bottom() - 2) };
1136  painter->drawLines(lines, 4);
1137 
1138  QPoint points[8];
1139  points[0] = QPoint(option->rect.left() + 1, option->rect.top() + 1);
1140  points[1] = QPoint(option->rect.right() - 1, option->rect.top() + 1);
1141  points[2] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
1142  points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
1143  painter->drawPoints(points, 4);
1144 
1145  painter->setPen(QPen(QColor(0, 0, 0, 63), 0));
1146  points[0] = QPoint(option->rect.left() + 1, option->rect.top());
1147  points[1] = QPoint(option->rect.right() - 1, option->rect.top());
1148  points[2] = QPoint(option->rect.left(), option->rect.top() + 1);
1149  points[3] = QPoint(option->rect.right(), option->rect.top() + 1);
1150  points[4] = QPoint(option->rect.left() + 1, option->rect.bottom());
1151  points[5] = QPoint(option->rect.right() - 1, option->rect.bottom());
1152  points[6] = QPoint(option->rect.left(), option->rect.bottom() - 1);
1153  points[7] = QPoint(option->rect.right(), option->rect.bottom() - 1);
1154  painter->drawPoints(points, 8);
1155 
1156  break;
1157  }
1158 #ifndef QT_NO_TABWIDGET
1159  case PE_FrameTabWidget:
1160  if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
1161  if (twf->shape != QTabBar::RoundedNorth && twf->shape != QTabBar::RoundedWest &&
1162  twf->shape != QTabBar::RoundedSouth && twf->shape != QTabBar::RoundedEast) {
1163  QWindowsStyle::drawPrimitive(element, option, painter, widget);
1164  break;
1165  }
1166 
1167  int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, twf, widget);
1168  bool reverse = (twf->direction == Qt::RightToLeft);
1169 
1170  painter->save();
1171 
1172  // Start by filling the contents of the tab widget frame (which is
1173  // actually a panel).
1174  painter->fillRect(option->rect.adjusted(1, 1, -1, -1), option->palette.window());
1175 
1176  QRect tabBarRect;
1177  switch (twf->shape) {
1178  case QTabBar::RoundedNorth:
1179  if (reverse)
1180  tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1, twf->rect.top(), twf->tabBarSize.width(), borderThickness);
1181  else
1182  tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(), twf->rect.top(), twf->tabBarSize.width(), borderThickness);
1183  break ;
1184  case QTabBar::RoundedWest:
1185  tabBarRect = QRect(twf->rect.left(), twf->rect.top() + twf->leftCornerWidgetSize.height(), borderThickness, twf->tabBarSize.height());
1186  break ;
1187  case QTabBar::RoundedEast:
1188  tabBarRect = QRect(twf->rect.right() - borderThickness + 1, twf->rect.top() + twf->leftCornerWidgetSize.height(),
1189  borderThickness, twf->tabBarSize.height());
1190  break ;
1191  case QTabBar::RoundedSouth:
1192  if (reverse)
1193  tabBarRect = QRect(twf->rect.right() - twf->leftCornerWidgetSize.width() - twf->tabBarSize.width() + 1,
1194  twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
1195  else
1196  tabBarRect = QRect(twf->rect.left() + twf->leftCornerWidgetSize.width(),
1197  twf->rect.bottom() - borderThickness + 1, twf->tabBarSize.width(), borderThickness);
1198  break ;
1199  default:
1200  break;
1201  }
1202 
1203  QRegion region(twf->rect);
1204  region -= tabBarRect;
1205  painter->setClipRegion(region);
1206 
1207  // Outer border
1208  QLine leftLine = QLine(twf->rect.topLeft() + QPoint(0, 2), twf->rect.bottomLeft() - QPoint(0, 2));
1209  QLine rightLine = QLine(twf->rect.topRight() + QPoint(0, 2), twf->rect.bottomRight() - QPoint(0, 2));
1210  QLine bottomLine = QLine(twf->rect.bottomLeft() + QPoint(2, 0), twf->rect.bottomRight() - QPoint(2, 0));
1211  QLine topLine = QLine(twf->rect.topLeft() + QPoint(2, 0), twf->rect.topRight() - QPoint(2, 0));
1212 
1213  QBrush border = option->palette.shadow();
1214  qBrushSetAlphaF(&border, qreal(0.4));
1215  painter->setPen(QPen(border, 0));
1216 
1219 
1220  lines.append(topLine);
1221 
1222  // Inner border
1223  QLine innerLeftLine = QLine(leftLine.p1() + QPoint(1, 0), leftLine.p2() + QPoint(1, 0));
1224  QLine innerRightLine = QLine(rightLine.p1() - QPoint(1, 0), rightLine.p2() - QPoint(1, 0));
1225  QLine innerBottomLine = QLine(bottomLine.p1() - QPoint(0, 1), bottomLine.p2() - QPoint(0, 1));
1226  QLine innerTopLine = QLine(topLine.p1() + QPoint(0, 1), topLine.p2() + QPoint(0, 1));
1227 
1228  // Rounded Corner
1229  QPoint leftBottomOuterCorner = QPoint(innerLeftLine.p2() + QPoint(0, 1));
1230  QPoint leftBottomInnerCorner1 = QPoint(leftLine.p2() + QPoint(0, 1));
1231  QPoint leftBottomInnerCorner2 = QPoint(bottomLine.p1() - QPoint(1, 0));
1232  QPoint rightBottomOuterCorner = QPoint(innerRightLine.p2() + QPoint(0, 1));
1233  QPoint rightBottomInnerCorner1 = QPoint(rightLine.p2() + QPoint(0, 1));
1234  QPoint rightBottomInnerCorner2 = QPoint(bottomLine.p2() + QPoint(1, 0));
1235  QPoint rightTopOuterCorner = QPoint(innerRightLine.p1() - QPoint(0, 1));
1236  QPoint rightTopInnerCorner1 = QPoint(rightLine.p1() - QPoint(0, 1));
1237  QPoint rightTopInnerCorner2 = QPoint(topLine.p2() + QPoint(1, 0));
1238  QPoint leftTopOuterCorner = QPoint(innerLeftLine.p1() - QPoint(0, 1));
1239  QPoint leftTopInnerCorner1 = QPoint(leftLine.p1() - QPoint(0, 1));
1240  QPoint leftTopInnerCorner2 = QPoint(topLine.p1() - QPoint(1, 0));
1241 
1242  lines.append(leftLine);
1243  lines.append(rightLine);
1244  lines.append(bottomLine);
1245 
1246  painter->drawLines(lines.constData(), lines.size());
1247  lines.clear();
1248 
1249  points.append(leftBottomOuterCorner);
1250  points.append(rightBottomOuterCorner);
1251  points.append(rightTopOuterCorner);
1252  points.append(leftTopOuterCorner);
1253 
1254  painter->drawPoints(points.constData(), points.size());
1255  points.clear();
1256 
1257  QBrush innerTopLeft = option->palette.shadow();
1258  qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
1259  painter->setPen(QPen(innerTopLeft, 0));
1260 
1261  lines.append(innerLeftLine);
1262  lines.append(innerTopLine);
1263  painter->drawLines(lines.constData(), lines.size());
1264  lines.clear();
1265 
1266  QBrush innerBottomRight = option->palette.shadow();
1267  qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
1268  painter->setPen(QPen(innerBottomRight, 0));
1269  lines.append(innerRightLine);
1270  lines.append(innerBottomLine);
1271  painter->drawLines(lines.constData(), lines.size());
1272  lines.clear();
1273 
1274  QBrush corner = option->palette.shadow();
1275  qBrushSetAlphaF(&corner, 0.25);
1276  painter->setPen(QPen(corner, 0));
1277  points.append(leftBottomInnerCorner1);
1278  points.append(leftBottomInnerCorner2);
1279  points.append(rightBottomInnerCorner1);
1280  points.append(rightBottomInnerCorner2);
1281  points.append(rightTopInnerCorner1);
1282  points.append(rightTopInnerCorner2);
1283  points.append(leftTopInnerCorner1);
1284  points.append(leftTopInnerCorner2);
1285  painter->drawPoints(points.constData(), points.size());
1286  points.clear();
1287 
1288  painter->restore();
1289  }
1290  break ;
1291 #endif // QT_NO_TABWIDGET
1292 #ifndef QT_NO_TABBAR
1293  case PE_FrameTabBarBase:
1294  if (const QStyleOptionTabBarBase *tbb = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1295  if (tbb->shape != QTabBar::RoundedNorth && tbb->shape != QTabBar::RoundedWest &&
1296  tbb->shape != QTabBar::RoundedSouth && tbb->shape != QTabBar::RoundedEast) {
1297  QWindowsStyle::drawPrimitive(element, option, painter, widget);
1298  break;
1299  }
1300 
1301  painter->save();
1302 
1303  QRegion region(tbb->rect);
1304  region -= tbb->tabBarRect;
1305  painter->setClipRegion(region);
1306 
1307  QLine topLine = QLine(tbb->rect.bottomLeft() - QPoint(0, 1), tbb->rect.bottomRight() - QPoint(0, 1));
1308  QLine bottomLine = QLine(tbb->rect.bottomLeft(), tbb->rect.bottomRight());
1309 
1310  QBrush border = option->palette.shadow();
1311  qBrushSetAlphaF(&border, qreal(0.4));
1312  QBrush innerTopLeft = option->palette.shadow();
1313  qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
1314  QBrush innerBottomRight = option->palette.shadow();
1315  qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
1316  QBrush corner = option->palette.shadow();
1317  qBrushSetAlphaF(&corner, 0.25);
1318 
1319  if (tbb->shape == QTabBar::RoundedSouth)
1320  painter->setPen(QPen(corner, 0));
1321  else
1322  painter->setPen(QPen(border, 0));
1323  painter->drawLine(topLine);
1324 
1325  if (tbb->shape != QTabBar::RoundedSouth)
1326  painter->setPen(QPen(innerTopLeft, 0));
1327  else
1328  painter->setPen(QPen(border, 0));
1329  painter->drawLine(bottomLine);
1330 
1331  painter->restore();
1332  }
1333  break ;
1334 #endif // QT_NO_TABBAR
1335 #ifndef QT_NO_GROUPBOX
1336  case PE_FrameGroupBox:
1337  if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1338  QStyleOptionFrameV2 frameV2(*frame);
1339  if (frameV2.features & QStyleOptionFrameV2::Flat) {
1340  QPen oldPen = painter->pen();
1341  painter->setPen(borderColor);
1342  painter->drawLine(frameV2.rect.topLeft(), frameV2.rect.topRight());
1343  painter->setPen(oldPen);
1344  } else {
1345  frameV2.state &= ~(State_Sunken | State_HasFocus);
1346  proxy()->drawPrimitive(PE_Frame, &frameV2, painter, widget);
1347  }
1348  }
1349  break;
1350 #endif // QT_NO_GROUPBOX
1351  case PE_Frame: {
1352  QFrame::Shadow shadow = QFrame::Plain;
1353  if (option->state & State_Sunken)
1354  shadow = QFrame::Sunken;
1355  else if (option->state & State_Raised)
1356  shadow = QFrame::Raised;
1357  qt_plastique_draw_frame(painter, option->rect, option, shadow);
1358  break;
1359  }
1360 #ifndef QT_NO_LINEEDIT
1361  case PE_FrameLineEdit:
1362  qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
1363  break;
1364  case PE_PanelLineEdit:
1365  if (const QStyleOptionFrame *lineEdit = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1366  // Panel of a line edit inside combo box or spin box is drawn in CC_ComboBox and CC_SpinBox
1367  if (widget) {
1368 #ifndef QT_NO_SPINBOX
1369  // Spinbox doesn't need a separate palette for the lineedit
1370  if (qobject_cast<const QAbstractSpinBox *>(widget->parentWidget()))
1371  break;
1372 #endif
1373  }
1374 
1375  painter->save();
1376 
1377  // Fill the line edit insides
1378  QRect filledRect = lineEdit->rect.adjusted(1, 1, -1, -1);
1379  QBrush baseBrush = qMapBrushToRect(lineEdit->palette.base(), filledRect);
1380  painter->setBrushOrigin(filledRect.topLeft());
1381  painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);
1382 
1383  painter->setPen(QPen(baseBrush, 0));
1384  const QLine lines[4] = {
1385  QLine(filledRect.left(), filledRect.top() + 1,
1386  filledRect.left(), filledRect.bottom() - 1),
1387  QLine(filledRect.right(), filledRect.top() + 1,
1388  filledRect.right(), filledRect.bottom() - 1),
1389  QLine(filledRect.left() + 1, filledRect.top(),
1390  filledRect.right() - 1, filledRect.top()),
1391  QLine(filledRect.left() + 1, filledRect.bottom(),
1392  filledRect.right() - 1, filledRect.bottom()) };
1393  painter->drawLines(lines, 4);
1394 
1395  if (lineEdit->lineWidth != 0)
1396  qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
1397 
1398  painter->restore();
1399  break;
1400  }
1401 #endif // QT_NO_LINEEDIT
1402  case PE_FrameDockWidget:
1403  case PE_FrameMenu:
1404  case PE_FrameStatusBarItem: {
1405  // Draws the frame around a popup menu.
1406  QPen oldPen = painter->pen();
1407  painter->setPen(borderColor);
1408  painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
1409  painter->setPen(alphaCornerColor);
1410  const QPoint points[4] = {
1411  QPoint(option->rect.topLeft()),
1412  QPoint(option->rect.topRight()),
1413  QPoint(option->rect.bottomLeft()),
1414  QPoint(option->rect.bottomRight()) };
1415  painter->drawPoints(points, 4);
1416  painter->setPen(oldPen);
1417  break;
1418  }
1419 #ifdef QT3_SUPPORT
1420  case PE_Q3DockWindowSeparator: {
1421  QPen oldPen = painter->pen();
1422  painter->setPen(alphaCornerColor);
1423  QRect rect = option->rect;
1424  if (option->state & State_Horizontal) {
1425  painter->drawLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 1);
1426  } else {
1427  painter->drawLine(rect.left() + 2, rect.bottom(), rect.right() - 1, rect.bottom());
1428  }
1429  painter->setPen(oldPen);
1430  break;
1431  }
1432  case PE_Q3Separator: {
1433  QPen oldPen = painter->pen();
1434  painter->setPen(alphaCornerColor);
1435  if ((option->state & State_Horizontal) == 0)
1436  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
1437  else
1438  painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
1439  painter->setPen(option->palette.background().color().lighter(104));
1440  if ((option->state & State_Horizontal) == 0)
1441  painter->drawLine(option->rect.topLeft(), option->rect.topRight());
1442  else
1443  painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
1444  painter->setPen(oldPen);
1445  break;
1446  }
1447 #endif // QT3_SUPPORT
1448 #ifndef QT_NO_MAINWINDOW
1449  case PE_PanelMenuBar:
1450  if ((widget && qobject_cast<const QMainWindow *>(widget->parentWidget()))
1451 #ifdef QT3_SUPPORT
1452  || (widget && widget->parentWidget() && widget->parentWidget()->inherits("Q3MainWindow"))
1453 #endif
1454  ) {
1455  // Draws the light line above and the dark line below menu bars and
1456  // tool bars.
1457  QPen oldPen = painter->pen();
1458  if (element == PE_PanelMenuBar || (option->state & State_Horizontal)) {
1459  painter->setPen(alphaCornerColor);
1460  painter->drawLine(option->rect.left(), option->rect.bottom(),
1461  option->rect.right(), option->rect.bottom());
1462  painter->setPen(option->palette.background().color().lighter(104));
1463  painter->drawLine(option->rect.left(), option->rect.top(),
1464  option->rect.right(), option->rect.top());
1465  } else {
1466  painter->setPen(option->palette.background().color().lighter(104));
1467  painter->drawLine(option->rect.left(), option->rect.top(),
1468  option->rect.left(), option->rect.bottom());
1469  painter->setPen(alphaCornerColor);
1470  painter->drawLine(option->rect.right(), option->rect.top(),
1471  option->rect.right(), option->rect.bottom());
1472  }
1473  painter->setPen(oldPen);
1474  }
1475  break;
1476 #endif // QT_NO_MAINWINDOW
1477  case PE_IndicatorHeaderArrow: {
1478  bool usedAntialiasing = painter->renderHints() & QPainter::Antialiasing;
1479  if (!usedAntialiasing)
1481  QWindowsStyle::drawPrimitive(element, option, painter, widget);
1482  if (!usedAntialiasing)
1483  painter->setRenderHint(QPainter::Antialiasing, false);
1484  break;
1485  }
1486  case PE_PanelButtonTool:
1487  // Draws a tool button (f.ex., in QToolBar and QTabBar)
1488  if ((option->state & State_Enabled || option->state & State_On) || !(option->state & State_AutoRaise))
1489  qt_plastique_drawShadedPanel(painter, option, true, widget);
1490  break;
1491 #ifndef QT_NO_TOOLBAR
1493  QPixmap cache;
1494  QRect rect = option->rect;
1495 #ifdef QT3_SUPPORT
1496  if (widget && widget->inherits("Q3DockWindowHandle") && widget->parentWidget()->inherits("Q3DockWindow")) {
1497  if (!(option->state & State_Horizontal))
1498  rect.adjust(2, 0, -2, 0);
1499  }
1500 #endif
1501  QString pixmapName = QStyleHelper::uniqueName(QLatin1String("toolbarhandle"), option, rect.size());
1502  if (!QPixmapCache::find(pixmapName, cache)) {
1503  cache = QPixmap(rect.size());
1504  cache.fill(Qt::transparent);
1505  QPainter cachePainter(&cache);
1506  QRect cacheRect(QPoint(0, 0), rect.size());
1507  if (widget)
1508  cachePainter.fillRect(cacheRect, option->palette.brush(widget->backgroundRole()));
1509  else
1510  cachePainter.fillRect(cacheRect, option->palette.background());
1511 
1512  QImage handle(qt_toolbarhandle);
1513  alphaCornerColor.setAlpha(170);
1514  handle.setColor(1, alphaCornerColor.rgba());
1515  handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
1516  handle.setColor(3, option->palette.light().color().rgba());
1517 
1518  if (option->state & State_Horizontal) {
1519  int nchunks = cacheRect.height() / handle.height();
1520  int indent = (cacheRect.height() - (nchunks * handle.height())) / 2;
1521  for (int i = 0; i < nchunks; ++i)
1522  cachePainter.drawImage(QPoint(cacheRect.left() + 3, cacheRect.top() + indent + i * handle.height()),
1523  handle);
1524  } else {
1525  int nchunks = cacheRect.width() / handle.width();
1526  int indent = (cacheRect.width() - (nchunks * handle.width())) / 2;
1527  for (int i = 0; i < nchunks; ++i)
1528  cachePainter.drawImage(QPoint(cacheRect.left() + indent + i * handle.width(), cacheRect.top() + 3),
1529  handle);
1530  }
1531  cachePainter.end();
1532  QPixmapCache::insert(pixmapName, cache);
1533  }
1534  painter->drawPixmap(rect.topLeft(), cache);
1535  break;
1536  }
1538  QPen oldPen = painter->pen();
1539  painter->setPen(alphaCornerColor);
1540  if (option->state & State_Horizontal) {
1541  painter->drawLine(option->rect.left(), option->rect.top() + 1, option->rect.left(), option->rect.bottom() - 2);
1542  painter->setPen(option->palette.base().color());
1543  painter->drawLine(option->rect.right(), option->rect.top() + 1, option->rect.right(), option->rect.bottom() - 2);
1544  } else {
1545  painter->drawLine(option->rect.left() + 1, option->rect.top(), option->rect.right() - 2, option->rect.top());
1546  painter->setPen(option->palette.base().color());
1547  painter->drawLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 2, option->rect.bottom());
1548  }
1549  painter->setPen(oldPen);
1550  break;
1551  }
1552 #endif // QT_NO_TOOLBAR
1553  case PE_PanelButtonCommand:
1554  if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1555  bool sunken = (button->state & State_Sunken) || (button->state & State_On);
1556  if ((button->features & QStyleOptionButton::Flat) && !sunken)
1557  break;
1558 
1559  bool defaultButton = (button->features & (QStyleOptionButton::DefaultButton
1561 
1562  BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("pushbutton-%1").arg(defaultButton))
1563 
1564  QPen oldPen = p->pen();
1565  bool hover = (button->state & State_Enabled) && (button->state & State_MouseOver);
1566 
1567  // Give the painter a different brush origin for sunken buttons
1568  if (sunken) {
1569  // ### No such function
1570  // p->setPenOrigin(rect.left() + 1, rect.top() + 1);
1571  p->setBrushOrigin(rect.left() + 1, rect.top() + 1);
1572  }
1573 
1574  // Draw border
1575  qt_plastique_draw_frame(p, rect, option);
1576 
1577  // Fill the panel
1578  QRectF fillRect = rect.adjusted(2, 2, -2, -2);
1579 
1580  // Button colors
1581  QBrush alphaCornerBrush = qMapBrushToRect(qBrushDark(option->palette.button(), 165), rect);
1582  qBrushSetAlphaF(&alphaCornerBrush, 0.5);
1583  QBrush buttonGradientBrush;
1584  QBrush leftLineGradientBrush;
1585  QBrush rightLineGradientBrush;
1586  QBrush sunkenButtonGradientBrush;
1587  QBrush sunkenLeftLineGradientBrush;
1588  QBrush sunkenRightLineGradientBrush;
1589  QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
1590  if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
1591  buttonGradientBrush = buttonBrush;
1592  sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
1593  leftLineGradientBrush = qBrushLight(buttonBrush, 105);
1594  rightLineGradientBrush = qBrushDark(buttonBrush, 105);
1595  sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
1596  sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
1597  } else {
1598  // Generate gradients
1599  QLinearGradient buttonGradient(rect.topLeft(), rect.bottomLeft());
1600  if (hover) {
1601  buttonGradient.setColorAt(0.0, mergedColors(option->palette.highlight().color(),
1602  buttonBrush.color().lighter(104), 6));
1603  buttonGradient.setColorAt(1.0, mergedColors(option->palette.highlight().color(),
1604  buttonBrush.color().darker(110), 6));
1605  } else {
1606  buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
1607  buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
1608  }
1609  buttonGradientBrush = QBrush(buttonGradient);
1610 
1611  QLinearGradient buttonGradient2(rect.topLeft(), rect.bottomLeft());
1612  buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
1613  buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
1614  sunkenButtonGradientBrush = QBrush(buttonGradient2);
1615 
1616  QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
1617  buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
1618  buttonGradient3.setColorAt(1.0, buttonBrush.color());
1619  leftLineGradientBrush = QBrush(buttonGradient3);
1620 
1621  QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
1622  buttonGradient4.setColorAt(0.0, buttonBrush.color());
1623  buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
1624  rightLineGradientBrush = QBrush(buttonGradient4);
1625 
1626  QLinearGradient buttonGradient5(rect.topLeft(), rect.bottomLeft());
1627  buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
1628  buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
1629  sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
1630 
1631  QLinearGradient buttonGradient6(rect.topLeft(), rect.bottomLeft());
1632  buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
1633  buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
1634  sunkenRightLineGradientBrush = QBrush(buttonGradient6);
1635  }
1636 
1637  // Main fill
1638  p->fillRect(fillRect,
1639  qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1640  : buttonGradientBrush, rect));
1641 
1642  // Top line
1643  p->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1644  : buttonGradientBrush, rect), 105), 0));
1645  p->drawLine(QPointF(rect.left() + 2, rect.top() + 1),
1646  QPointF(rect.right() - 2, rect.top() + 1));
1647 
1648  // Bottom line
1649  p->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
1650  : buttonGradientBrush, rect), 105), 0));
1651  p->drawLine(QPointF(rect.left() + 2, rect.bottom() - 1),
1652  QPointF(rect.right() - 2, rect.bottom() - 1));
1653 
1654  // Left line
1655  p->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
1656  : leftLineGradientBrush, rect), 1));
1657  p->drawLine(QPointF(rect.left() + 1, rect.top() + 2),
1658  QPointF(rect.left() + 1, rect.bottom() - 2));
1659 
1660  // Right line
1661  p->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
1662  : rightLineGradientBrush, rect), 1));
1663  p->drawLine(QPointF(rect.right() - 1, rect.top() + 2),
1664  QPointF(rect.right() - 1, rect.bottom() - 2));
1665 
1666  // Hovering
1667  if (hover && !sunken) {
1668  QBrush hover = qMapBrushToRect(option->palette.highlight(), rect);
1669  QBrush hoverOuter = hover;
1670  qBrushSetAlphaF(&hoverOuter, qreal(0.7));
1671 
1672  QLine lines[2];
1673 
1674  p->setPen(QPen(hoverOuter, 0));
1675  lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
1676  lines[1] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
1677  p->drawLines(lines, 2);
1678 
1679  QBrush hoverInner = hover;
1680  qBrushSetAlphaF(&hoverInner, qreal(0.45));
1681  p->setPen(QPen(hoverInner, 0));
1682  lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.right() - 1, rect.top() + 2);
1683  lines[1] = QLine(rect.left() + 1, rect.bottom() - 2, rect.right() - 1, rect.bottom() - 2);
1684  p->drawLines(lines, 2);
1685 
1686  QBrush hoverSide = hover;
1687  qBrushSetAlphaF(&hoverSide, qreal(0.075));
1688  p->setPen(QPen(hoverSide, 0));
1689  lines[0] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
1690  lines[1] = QLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
1691  p->drawLines(lines, 2);
1692  }
1693 
1694  p->setPen(oldPen);
1695 
1697  }
1698  break;
1699  case PE_IndicatorCheckBox:
1700  if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1702 
1703  p->save();
1704 
1705  // Outline
1706  QBrush border = option->palette.shadow();
1707  qBrushSetAlphaF(&border, qreal(0.4));
1708  p->setPen(QPen(border, 0));
1709  const QLine lines[4] = {
1710  QLine(rect.left() + 1, rect.top(), rect.right() - 1, rect.top()),
1711  QLine(rect.left() + 1, rect.bottom(), rect.right() - 1, rect.bottom()),
1712  QLine(rect.left(), rect.top() + 1, rect.left(), rect.bottom() - 1),
1713  QLine(rect.right(), rect.top() + 1, rect.right(), rect.bottom() - 1) };
1714  p->drawLines(lines, 4);
1715 
1716  QBrush corner = option->palette.shadow();
1717  qBrushSetAlphaF(&corner, qreal(0.2));
1718  p->setPen(QPen(corner, 0));
1719  const QPoint points[4] = {
1720  rect.topLeft(), rect.topRight(),
1721  rect.bottomLeft(), rect.bottomRight() };
1722  p->drawPoints(points, 4);
1723 
1724  // Fill
1725  QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
1726  if (!baseBrush.gradient() && baseBrush.texture().isNull()) {
1727  QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
1728  gradient.setColorAt(0, baseBrush.color());
1729  gradient.setColorAt(1, baseBrush.color().darker(105));
1730  baseBrush = gradient;
1731  }
1732  p->fillRect(rect.adjusted(1, 1, -1, -1), baseBrush);
1733 
1734  // Hover
1735  if ((button->state & State_Enabled) && (button->state & State_MouseOver)) {
1736  QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
1737  qBrushSetAlphaF(&pen, qreal(0.8));
1738  p->setPen(QPen(pen, 0));
1739  p->drawRect(rect.adjusted(1, 1, -2, -2));
1740  qBrushSetAlphaF(&pen, 0.5);
1741  p->setPen(QPen(pen, 0));
1742  p->drawRect(rect.adjusted(2, 2, -3, -3));
1743 
1744  qBrushSetAlphaF(&pen, qreal(0.2));
1745  p->setBrush(pen);
1746  p->drawRect(rect.adjusted(2, 2, -3, -3));
1747  }
1748 
1749  // Indicator
1750  bool on = button->state & State_On;
1751  bool sunken = button->state & State_Sunken;
1752  bool unchanged = button->state & State_NoChange;
1753  bool enabled = button->state & State_Enabled;
1754  if (on || (enabled && sunken) || unchanged) {
1755  p->setRenderHint(QPainter::Antialiasing);
1756  QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
1757  if (sunken)
1758  qBrushSetAlphaF(&pointBrush, qreal(0.5));
1759  else if (unchanged)
1760  qBrushSetAlphaF(&pointBrush, qreal(0.3));
1761  p->setPen(QPen(pointBrush, 3));
1762  const QLine lines[2] = {
1763  QLine(rect.left() + 4, rect.top() + 4, rect.right() - 3, rect.bottom() - 3),
1764  QLine(rect.right() - 3, rect.top() + 4, rect.left() + 4, rect.bottom() - 3) };
1765  p->drawLines(lines, 2);
1766  }
1767 
1768  p->restore();
1770  }
1771  break;
1773  if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1774  BEGIN_STYLE_PIXMAPCACHE(QLatin1String("radiobutton"))
1775 
1776  p->save();
1777  p->setRenderHint(QPainter::Antialiasing);
1778 
1779  // The the filled ellipse
1780  QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
1781  qBrushSetAlphaF(&border, qreal(0.51));
1782  p->setPen(QPen(border, 0));
1783 
1784  QBrush baseBrush = qMapBrushToRect(button->palette.base(), rect);
1785  if (!baseBrush.gradient() && baseBrush.texture().isNull()) {
1786  QLinearGradient gradient(rect.center().x(), rect.top(), rect.center().x(), rect.bottom());
1787  gradient.setColorAt(0, baseBrush.color());
1788  gradient.setColorAt(1, baseBrush.color().darker(105));
1789  baseBrush = gradient;
1790  }
1791  p->setBrush(baseBrush);
1792  p->drawEllipse(QRectF(rect).adjusted(1, 1, -1, -1));
1793 
1794  // Hover
1795  if ((button->state & State_Enabled) && (button->state & State_MouseOver)) {
1796  QBrush pen = qMapBrushToRect(button->palette.highlight(), rect);
1797  qBrushSetAlphaF(&pen, qreal(0.8));
1798  p->setPen(QPen(pen, 0));
1799  qBrushSetAlphaF(&pen, qreal(0.2));
1800  p->setBrush(pen);
1801  p->drawEllipse(QRectF(rect).adjusted(2, 2, -2, -2));
1802  }
1803 
1804  // Indicator
1805  bool on = button->state & State_On;
1806  bool sunken = button->state & State_Sunken;
1807  bool enabled = button->state & State_Enabled;
1808  if (on || (enabled && sunken)) {
1809  p->setPen(Qt::NoPen);
1810  QBrush pointBrush = qMapBrushToRect(button->palette.text(), rect);
1811  if (sunken)
1812  qBrushSetAlphaF(&pointBrush, 0.5);
1813  p->setBrush(pointBrush);
1814  p->drawEllipse(QRectF(rect).adjusted(3, 3, -3, -3));
1815  }
1816 
1817  p->restore();
1819  }
1820  break;
1821 #ifndef QT_NO_DOCKWIDGET
1823  if ((option->state & State_Enabled) && (option->state & State_MouseOver))
1824  painter->fillRect(option->rect, QColor(255, 255, 255, 128));
1825  if (option->state & State_Horizontal) {
1826  int width = option->rect.width() / 3;
1827  QRect rect(option->rect.center().x() - width / 2,
1828  option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
1829  qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
1830  } else {
1831  int height = option->rect.height() / 3;
1832  QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
1833  option->rect.center().y() - height / 2, 3, height);
1834  qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
1835  }
1836  break;
1837 #endif // QT_NO_DOCKWIDGET
1839  QStyleOptionButton button;
1840  button.QStyleOption::operator=(*option);
1841  button.state &= ~State_MouseOver;
1842  proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
1843  break;
1844  }
1845  case PE_FrameWindow: {
1846  painter->save();
1847  bool active = (option->state & State_Active);
1848  int titleBarStop = option->rect.top() + proxy()->pixelMetric(PM_TitleBarHeight, option, widget);
1849 
1850  QPalette palette = option->palette;
1851  if (!active)
1853 
1854  // Frame and rounded corners
1855  painter->setPen(mergedColors(palette.highlight().color(), Qt::black, 50));
1856 
1857  QLine lines[3];
1858  QPoint points[4];
1859 
1860  // bottom border line
1861  lines[0] = QLine(option->rect.left() + 1, option->rect.bottom(), option->rect.right() - 1, option->rect.bottom());
1862 
1863  // bottom left and right side border lines
1864  lines[1] = QLine(option->rect.left(), titleBarStop, option->rect.left(), option->rect.bottom() - 1);
1865  lines[2] = QLine(option->rect.right(), titleBarStop, option->rect.right(), option->rect.bottom() - 1);
1866  painter->drawLines(lines, 3);
1867  points[0] = QPoint(option->rect.left() + 1, option->rect.bottom() - 1);
1868  points[1] = QPoint(option->rect.right() - 1, option->rect.bottom() - 1);
1869  painter->drawPoints(points, 2);
1870 
1871 #ifdef QT3_SUPPORT
1872  if (widget && widget->inherits("Q3DockWindow")) {
1873  // also draw the frame on the title bar
1874  lines[0] = QLine(option->rect.left() + 1, option->rect.top(),
1875  option->rect.right() - 1, option->rect.top());
1876  lines[1] = QLine(option->rect.left(), option->rect.top() + 1,
1877  option->rect.left(), titleBarStop);
1878  lines[2] = QLine(option->rect.right(), option->rect.top() + 1,
1879  option->rect.right(), titleBarStop);
1880  painter->drawLines(lines, 3);
1881  }
1882 #endif
1883 
1884  // alpha corners
1885  painter->setPen(mergedColors(palette.highlight().color(), palette.background().color(), 55));
1886  points[0] = QPoint(option->rect.left() + 2, option->rect.bottom() - 1);
1887  points[1] = QPoint(option->rect.left() + 1, option->rect.bottom() - 2);
1888  points[2] = QPoint(option->rect.right() - 2, option->rect.bottom() - 1);
1889  points[3] = QPoint(option->rect.right() - 1, option->rect.bottom() - 2);
1890  painter->drawPoints(points, 4);
1891 
1892 #ifdef QT3_SUPPORT
1893  if (widget && widget->inherits("Q3DockWindow")) {
1894  // also draw the frame on the title bar
1895  points[0] = option->rect.topLeft();
1896  points[1] = option->rect.topRight();
1897  painter->drawPoints(points, 2);
1898  }
1899 #endif
1900 
1901  // upper and lower left inner
1902  painter->setPen(active ? mergedColors(palette.highlight().color(), palette.background().color()) : palette.background().color().darker(120));
1903  painter->drawLine(option->rect.left() + 1, titleBarStop, option->rect.left() + 1, option->rect.bottom() - 2);
1904 
1905 #ifdef QT3_SUPPORT
1906  if (widget && widget->inherits("Q3DockWindow")) {
1907  // also draw the frame on the title bar
1908  lines[0] = QLine(option->rect.left() + 1, option->rect.top() + 1,
1909  option->rect.left() + 1, titleBarStop);
1910  lines[1] = QLine(option->rect.right() - 1, option->rect.top() + 1,
1911  option->rect.right() - 1, titleBarStop);
1912  lines[2] = QLine(option->rect.left() + 1, option->rect.top() + 1,
1913  option->rect.right() - 1, option->rect.top() + 1);
1914  painter->drawLines(lines, 3);
1915  }
1916 #endif
1917 
1918  painter->setPen(active ? mergedColors(palette.highlight().color(), palette.background().color(), 57) : palette.background().color().darker(130));
1919  lines[0] = QLine(option->rect.right() - 1, titleBarStop, option->rect.right() - 1, option->rect.bottom() - 2);
1920  lines[1] = QLine(option->rect.left() + 1, option->rect.bottom() - 1, option->rect.right() - 1, option->rect.bottom() - 1);
1921  painter->drawLines(lines, 2);
1922 
1923  painter->restore();
1924  }
1925  break;
1926  case PE_IndicatorBranch: {
1927  int mid_h = option->rect.x() + option->rect.width() / 2;
1928  int mid_v = option->rect.y() + option->rect.height() / 2;
1929  int bef_h = mid_h;
1930  int bef_v = mid_v;
1931  int aft_h = mid_h;
1932  int aft_v = mid_v;
1933  QBrush brush(option->palette.dark().color(), Qt::Dense4Pattern);
1934  if (option->state & State_Item) {
1935  if (option->direction == Qt::RightToLeft)
1936  painter->fillRect(option->rect.left(), mid_v, bef_h - option->rect.left(), 1, brush);
1937  else
1938  painter->fillRect(aft_h, mid_v, option->rect.right() - aft_h + 1, 1, brush);
1939  }
1940  if (option->state & State_Sibling)
1941  painter->fillRect(mid_h, aft_v, 1, option->rect.bottom() - aft_v + 1, brush);
1942  if (option->state & (State_Open | State_Children | State_Item | State_Sibling))
1943  painter->fillRect(mid_h, option->rect.y(), 1, bef_v - option->rect.y(), brush);
1944 
1945  if (option->state & State_Children) {
1946  painter->save();
1947  QPoint center = option->rect.center();
1948  // border
1949  QRect fullRect(center.x() - 4, center.y() - 4, 9, 9);
1950  painter->setPen(borderColor);
1951 
1952  const QLine lines[4] = {
1953  QLine(fullRect.left() + 1, fullRect.top(),
1954  fullRect.right() - 1, fullRect.top()),
1955  QLine(fullRect.left() + 1, fullRect.bottom(),
1956  fullRect.right() - 1, fullRect.bottom()),
1957  QLine(fullRect.left(), fullRect.top() + 1,
1958  fullRect.left(), fullRect.bottom() - 1),
1959  QLine(fullRect.right(), fullRect.top() + 1,
1960  fullRect.right(), fullRect.bottom() - 1) };
1961  painter->drawLines(lines, 4);
1962 
1963  // "antialiased" corners
1964  painter->setPen(alphaCornerColor);
1965  const QPoint points[4] = {
1966  fullRect.topLeft(),
1967  fullRect.topRight(),
1968  fullRect.bottomLeft(),
1969  fullRect.bottomRight() };
1970  painter->drawPoints(points, 4);
1971 
1972  // fill
1973  QRect adjustedRect = fullRect;
1974  QRect gradientRect(adjustedRect.left() + 1, adjustedRect.top() + 1,
1975  adjustedRect.right() - adjustedRect.left() - 1,
1976  adjustedRect.bottom() - adjustedRect.top() - 1);
1977  if (option->palette.base().style() == Qt::SolidPattern) {
1978  QColor baseGradientStartColor = option->palette.base().color().darker(101);
1979  QColor baseGradientStopColor = option->palette.base().color().darker(106);
1980  qt_plastique_draw_gradient(painter, gradientRect, baseGradientStartColor, baseGradientStopColor);
1981  } else {
1982  painter->fillRect(gradientRect, option->palette.base());
1983  }
1984  // draw "+" or "-"
1985  painter->setPen(alphaTextColor);
1986  painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
1987  if (!(option->state & State_Open))
1988  painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
1989  painter->restore();
1990  }
1991  }
1992  break;
1993  default:
1994  QWindowsStyle::drawPrimitive(element, option, painter, widget);
1995  break;
1996  }
1997 }
1998 
2003  QPainter *painter, const QWidget *widget) const
2004 {
2005  QColor borderColor = option->palette.background().color().darker(178);
2006  QColor alphaCornerColor;
2007  if (widget) {
2008  // ### backgroundrole/foregroundrole should be part of the style option
2009  alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
2010  } else {
2011  alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
2012  }
2013 
2014  QColor gradientStartColor = option->palette.button().color().lighter(104);
2015  QColor gradientStopColor = option->palette.button().color().darker(105);
2016 
2017  QColor highlightedGradientStartColor = option->palette.button().color().lighter(101);
2018  QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85);
2019 
2020  QColor lightShadowGradientStartColor = highlightedGradientStartColor.lighter(105);
2021  QColor lightShadowGradientStopColor = highlightedGradientStopColor.lighter(105);
2022 
2023  QColor highlightedDarkInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 35);
2024  QColor highlightedLightInnerBorderColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 58);
2025 
2026  QColor alphaInnerColor = mergedColors(highlightedDarkInnerBorderColor, option->palette.base().color());
2027 
2028  switch (element) {
2029 #ifndef QT_NO_TABBAR
2030  case CE_TabBarTabShape:
2031  if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2032 
2033  if (tab->shape != QTabBar::RoundedNorth && tab->shape != QTabBar::RoundedWest &&
2034  tab->shape != QTabBar::RoundedSouth && tab->shape != QTabBar::RoundedEast) {
2035  QWindowsStyle::drawControl(element, option, painter, widget);
2036  break;
2037  }
2038 
2039  painter->save();
2040 
2041  // Set up some convenience variables
2042  bool disabled = !(tab->state & State_Enabled);
2043  bool onlyTab = tab->position == QStyleOptionTab::OnlyOneTab;
2044  bool selected = tab->state & State_Selected;
2045  bool mouseOver = (tab->state & State_MouseOver) && !selected && !disabled;
2046  bool previousSelected = tab->selectedPosition == QStyleOptionTab::PreviousIsSelected;
2047  bool nextSelected = tab->selectedPosition == QStyleOptionTab::NextIsSelected;
2048  bool leftCornerWidget = (tab->cornerWidgets & QStyleOptionTab::LeftCornerWidget);
2049  bool reverse = (tab->direction == Qt::RightToLeft);
2050 
2051  int lowerTop = selected ? 0 : 3; // to make the selected tab bigger than the rest
2052  bool atEnd = (tab->position == QStyleOptionTab::End) || onlyTab;
2053  bool atBeginning = ((tab->position == QStyleOptionTab::Beginning) || onlyTab)
2054  && !leftCornerWidget;
2055  bool reverseShadow = false;
2056 
2057  int borderThickness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
2058  int marginLeft = 0;
2059  if ((atBeginning && !selected) || (selected && leftCornerWidget && ((tab->position == QStyleOptionTab::Beginning) || onlyTab))) {
2060  marginLeft = 1;
2061  }
2062 
2063  // I've set the names based on the natural coordinate system. Vectors are used to rotate everything
2064  // if the orientation of the tab bare is different than north.
2065  {
2066  // Coordinates of corners of rectangle for transformation
2067  QPoint topLeft;
2068  QPoint topRight;
2069  QPoint bottomLeft;
2070  QPoint bottomRight;
2071 
2072  // Fill with normalized vectors in the direction of the coordinate system
2073  // (down and right should be complement of up and left, or it will look odd)
2074  QPoint vectorUp;
2075  QPoint vectorDown;
2076  QPoint vectorLeft;
2077  QPoint vectorRight;
2078 
2079  QBrush border = option->palette.shadow();
2080  qBrushSetAlphaF(&border, qreal(0.4));
2081  QBrush innerTopLeft = option->palette.shadow();
2082  qBrushSetAlphaF(&innerTopLeft, qreal(0.075));
2083  QBrush innerBottomRight = option->palette.shadow();
2084  qBrushSetAlphaF(&innerBottomRight, qreal(0.23));
2085  QBrush corner = option->palette.shadow();
2086  qBrushSetAlphaF(&corner, qreal(0.25));
2087 
2088  QBrush baseColor1;
2089  QBrush baseColor2;
2090 
2091  switch (tab->shape) {
2092  case QTabBar::RoundedNorth:
2093  vectorUp = QPoint(0, -1);
2094  vectorDown = QPoint(0, 1);
2095 
2096  if (reverse) {
2097  vectorLeft = QPoint(1, 0);
2098  vectorRight = QPoint(-1, 0);
2099  reverseShadow = true;
2100  } else {
2101  vectorLeft = QPoint(-1, 0);
2102  vectorRight = QPoint(1, 0);
2103  }
2104 
2105  if (reverse) {
2106  topLeft = tab->rect.topRight();
2107  topRight = tab->rect.topLeft();
2108  bottomLeft = tab->rect.bottomRight();
2109  bottomRight = tab->rect.bottomLeft();
2110  } else {
2111  topLeft = tab->rect.topLeft();
2112  topRight = tab->rect.topRight();
2113  bottomLeft = tab->rect.bottomLeft();
2114  bottomRight = tab->rect.bottomRight();
2115  }
2116 
2117 
2118  baseColor1 = border;
2119  baseColor2 = innerTopLeft;
2120  break ;
2121  case QTabBar::RoundedWest:
2122  vectorUp = QPoint(-1, 0);
2123  vectorDown = QPoint(1, 0);
2124  vectorLeft = QPoint(0, -1);
2125  vectorRight = QPoint(0, 1);
2126 
2127  topLeft = tab->rect.topLeft();
2128  topRight = tab->rect.bottomLeft();
2129  bottomLeft = tab->rect.topRight();
2130  bottomRight = tab->rect.bottomRight();
2131 
2132  baseColor1 = border;
2133  baseColor2 = innerTopLeft;
2134  break ;
2135  case QTabBar::RoundedEast:
2136  vectorUp = QPoint(1, 0);
2137  vectorDown = QPoint(-1, 0);
2138  vectorLeft = QPoint(0, -1);
2139  vectorRight = QPoint(0, 1);
2140 
2141  topLeft = tab->rect.topRight();
2142  topRight = tab->rect.bottomRight();
2143  bottomLeft = tab->rect.topLeft();
2144  bottomRight = tab->rect.bottomLeft();
2145 
2146  baseColor1 = border;
2147  baseColor2 = innerBottomRight;
2148  break ;
2149  case QTabBar::RoundedSouth:
2150  vectorUp = QPoint(0, 1);
2151  vectorDown = QPoint(0, -1);
2152 
2153  if (reverse) {
2154  vectorLeft = QPoint(1, 0);
2155  vectorRight = QPoint(-1, 0);
2156  reverseShadow = true;
2157 
2158  topLeft = tab->rect.bottomRight();
2159  topRight = tab->rect.bottomLeft();
2160  bottomLeft = tab->rect.topRight();
2161  bottomRight = tab->rect.topLeft();
2162  } else {
2163  vectorLeft = QPoint(-1, 0);
2164  vectorRight = QPoint(1, 0);
2165 
2166  topLeft = tab->rect.bottomLeft();
2167  topRight = tab->rect.bottomRight();
2168  bottomLeft = tab->rect.topLeft();
2169  bottomRight = tab->rect.topRight();
2170  }
2171 
2172  baseColor1 = border;
2173  baseColor2 = innerBottomRight;
2174  break ;
2175  default:
2176  break;
2177  }
2178 
2179  // Make the tab smaller when it's at the end, so that we are able to draw the corner
2180  if (atEnd) {
2181  topRight += vectorLeft;
2182  bottomRight += vectorLeft;
2183  }
2184 
2185  {
2186  // Outer border
2187  QLine topLine;
2188  {
2189  QPoint adjustTopLineLeft = (vectorRight * (marginLeft + (previousSelected ? 0 : 1))) +
2190  (vectorDown * lowerTop);
2191  QPoint adjustTopLineRight = (vectorDown * lowerTop);
2192  if (atBeginning || selected)
2193  adjustTopLineLeft += vectorRight;
2194  if (atEnd || selected)
2195  adjustTopLineRight += 2 * vectorLeft;
2196 
2197  topLine = QLine(topLeft + adjustTopLineLeft, topRight + adjustTopLineRight);
2198  }
2199 
2200  QLine leftLine;
2201  {
2202  QPoint adjustLeftLineTop = (vectorRight * marginLeft) + (vectorDown * (lowerTop + 1));
2203  QPoint adjustLeftLineBottom = (vectorRight * marginLeft) + (vectorUp * borderThickness);
2204  if (atBeginning || selected)
2205  adjustLeftLineTop += vectorDown; // Make place for rounded corner
2206  if (atBeginning && selected)
2207  adjustLeftLineBottom += borderThickness * vectorDown;
2208  else if (selected)
2209  adjustLeftLineBottom += vectorUp;
2210 
2211  leftLine = QLine(topLeft + adjustLeftLineTop, bottomLeft + adjustLeftLineBottom);
2212  }
2213 
2214  QLine rightLine;
2215  {
2216  QPoint adjustRightLineTop = vectorDown * (2 + lowerTop);
2217  QPoint adjustRightLineBottom = vectorUp * borderThickness;
2218  if (selected)
2219  adjustRightLineBottom += vectorUp;
2220 
2221  rightLine = QLine(topRight + adjustRightLineTop, bottomRight + adjustRightLineBottom);
2222  }
2223 
2224  // Background
2225  QPoint startPoint = topLine.p1() + vectorDown + vectorLeft;
2226  if (mouseOver)
2227  startPoint += vectorDown;
2228  QPoint endPoint = rightLine.p2();
2229 
2230  if (tab->state & State_Enabled) {
2231  QRect fillRect = QRect(startPoint, endPoint).normalized();
2232  if (fillRect.isValid()) {
2233  if (selected) {
2234  fillRect = QRect(startPoint, endPoint + vectorLeft + vectorDown * 3).normalized();
2235  painter->fillRect(fillRect, option->palette.window());
2236 
2237  // Connect to the base
2238  painter->setPen(QPen(option->palette.window(), 0));
2240  points.append(rightLine.p2() + vectorDown);
2241  points.append(rightLine.p2() + vectorDown + vectorDown);
2242  points.append(rightLine.p2() + vectorDown + vectorDown + vectorRight);
2243  if (tab->position != QStyleOptionTab::Beginning) {
2244  points.append(leftLine.p2() + vectorDown);
2245  points.append(leftLine.p2() + vectorDown + vectorDown);
2246  points.append(leftLine.p2() + vectorDown + vectorDown + vectorLeft);
2247  }
2248  painter->drawPoints(points.constData(), points.size());
2249  } else {
2250  QBrush buttonGradientBrush;
2251  QBrush buttonBrush = qMapBrushToRect(option->palette.button(), fillRect);
2252  if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2253  buttonGradientBrush = buttonBrush;
2254  } else {
2255  // Generate gradients
2256  QLinearGradient buttonGradient(fillRect.topLeft(), fillRect.bottomLeft());
2257  buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
2258  buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
2259  buttonGradientBrush = QBrush(buttonGradient);
2260  }
2261 
2262  painter->fillRect(fillRect, buttonGradientBrush);
2263  }
2264  }
2265  }
2266 
2267  QPoint rightCornerDot = topRight + vectorLeft + (lowerTop + 1)*vectorDown;
2268  QPoint leftCornerDot = topLeft + (marginLeft + 1)*vectorRight + (lowerTop + 1)*vectorDown;
2269  QPoint bottomRightConnectToBase = rightLine.p2() + vectorRight + vectorDown;
2270  QPoint bottomLeftConnectToBase = leftLine.p2() + vectorLeft + vectorDown;
2271 
2272  painter->setPen(QPen(border, 0));
2273 
2276 
2277  lines.append(topLine);
2278 
2279  if (mouseOver) {
2280  painter->drawLines(lines.constData(), lines.count());
2281  lines.clear();
2282 
2283  QLine secondHoverLine = QLine(topLine.p1() + vectorDown * 2 + vectorLeft, topLine.p2() + vectorDown * 2 + vectorRight);
2284  painter->setPen(highlightedLightInnerBorderColor);
2285  painter->drawLine(secondHoverLine);
2286  }
2287 
2288  if (mouseOver)
2289  painter->setPen(QPen(border, 0));
2290 
2291  if (!previousSelected)
2292  lines.append(leftLine);
2293  if (atEnd || selected) {
2294  lines.append(rightLine);
2295  points.append(rightCornerDot);
2296  }
2297  if (atBeginning || selected)
2298  points.append(leftCornerDot);
2299  if (selected) {
2300  points.append(bottomRightConnectToBase);
2301  points.append(bottomLeftConnectToBase);
2302  }
2303  if (lines.size() > 0) {
2304  painter->drawLines(lines.constData(), lines.size());
2305  lines.clear();
2306  }
2307  if (points.size() > 0) {
2308  painter->drawPoints(points.constData(), points.size());
2309  points.clear();
2310  }
2311 
2312  // Antialiasing
2313  painter->setPen(QPen(corner, 0));
2314  if (atBeginning || selected)
2315  points.append(topLine.p1() + vectorLeft);
2316  if (!previousSelected)
2317  points.append(leftLine.p1() + vectorUp);
2318  if (atEnd || selected) {
2319  points.append(topLine.p2() + vectorRight);
2320  points.append(rightLine.p1() + vectorUp);
2321  }
2322 
2323  if (selected) {
2324  points.append(bottomRightConnectToBase + vectorLeft);
2325  if (!atBeginning) {
2326  points.append(bottomLeftConnectToBase + vectorRight);
2327 
2328  if (((tab->position == QStyleOptionTab::Beginning) || onlyTab) && leftCornerWidget) {
2329  // A special case: When the first tab is selected and
2330  // has a left corner widget, it needs to do more work
2331  // to connect to the base
2332  QPoint p1 = bottomLeftConnectToBase + vectorDown;
2333 
2334  points.append(p1);
2335  }
2336  }
2337  }
2338  if (points.size() > 0) {
2339  painter->drawPoints(points.constData(), points.size());
2340  points.clear();
2341  }
2342 
2343  // Inner border
2344  QLine innerTopLine = QLine(topLine.p1() + vectorDown, topLine.p2() + vectorDown);
2345  if (!selected) {
2346  QLinearGradient topLineGradient(innerTopLine.p1(),innerTopLine.p2());
2347  topLineGradient.setColorAt(0, lightShadowGradientStartColor);
2348  topLineGradient.setColorAt(1, lightShadowGradientStopColor);
2349  painter->setPen(QPen(mouseOver ? QBrush(highlightedDarkInnerBorderColor) : QBrush(topLineGradient), 1));
2350  } else {
2351  painter->setPen(QPen(innerTopLeft, 0));
2352  }
2353  painter->drawLine(innerTopLine);
2354 
2355  QLine innerLeftLine = QLine(leftLine.p1() + vectorRight + vectorDown, leftLine.p2() + vectorRight);
2356  QLine innerRightLine = QLine(rightLine.p1() + vectorLeft + vectorDown, rightLine.p2() + vectorLeft);
2357 
2358  if (selected) {
2359  innerRightLine = QLine(innerRightLine.p1() + vectorUp, innerRightLine.p2());
2360  innerLeftLine = QLine(innerLeftLine.p1() + vectorUp, innerLeftLine.p2());
2361  }
2362 
2363  if (selected || atBeginning) {
2364  QBrush leftLineGradientBrush;
2365  QRect rect = QRect(innerLeftLine.p1(), innerLeftLine.p2()).normalized();
2366  QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
2367  if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2368  leftLineGradientBrush = qBrushLight(buttonBrush, 105);
2369  } else {
2370  QLinearGradient buttonGradient3(rect.topLeft(), rect.bottomLeft());
2371  buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
2372  buttonGradient3.setColorAt(1.0, buttonBrush.color());
2373  leftLineGradientBrush = QBrush(buttonGradient3);
2374  }
2375 
2376  if (!selected)
2377  painter->setPen(QPen(leftLineGradientBrush, 0));
2378 
2379  // Assume the sun is on the same side in Right-To-Left layouts and draw the
2380  // light shadow on the left side always (the right line is on the left side in
2381  // reverse layouts for north and south)
2382  if (reverseShadow)
2383  painter->drawLine(innerRightLine);
2384  else
2385  painter->drawLine(innerLeftLine);
2386  }
2387 
2388  if (atEnd || selected) {
2389  if (!selected) {
2390  QBrush rightLineGradientBrush;
2391  QRect rect = QRect(innerRightLine.p1(), innerRightLine.p2()).normalized();
2392  QBrush buttonBrush = qMapBrushToRect(option->palette.button(), rect);
2393  if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
2394  rightLineGradientBrush = qBrushDark(buttonBrush, 105);
2395  } else {
2396  QLinearGradient buttonGradient4(rect.topLeft(), rect.bottomLeft());
2397  buttonGradient4.setColorAt(0.0, buttonBrush.color());
2398  buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
2399  rightLineGradientBrush = QBrush(buttonGradient4);
2400  }
2401 
2402  painter->setPen(QPen(rightLineGradientBrush, 0));
2403  } else {
2404  painter->setPen(QPen(innerBottomRight, 0));
2405  }
2406 
2407  if (reverseShadow)
2408  painter->drawLine(innerLeftLine);
2409  else
2410  painter->drawLine(innerRightLine);
2411  }
2412 
2413 
2414  // Base
2415  QLine baseLine = QLine(bottomLeft + marginLeft * 2 * vectorRight, bottomRight);
2416  {
2417 
2418  QPoint adjustedLeft;
2419  QPoint adjustedRight;
2420 
2421  if (atEnd && !selected) {
2422  baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorRight);
2423  }
2424 
2425  if (nextSelected) {
2426  adjustedRight += vectorLeft;
2427  baseLine = QLine(baseLine.p1(), baseLine.p2() + vectorLeft);
2428  }
2429  if (previousSelected) {
2430  adjustedLeft += vectorRight;
2431  baseLine = QLine(baseLine.p1() + vectorRight, baseLine.p2());
2432  }
2433  if (atBeginning)
2434  adjustedLeft += vectorRight;
2435 
2436  painter->setPen(QPen(baseColor2, 0));
2437  if (!selected)
2438  painter->drawLine(baseLine);
2439 
2440  if (atEnd && !selected)
2441  painter->drawPoint(baseLine.p2() + vectorRight);
2442 
2443  if (atBeginning && !selected)
2444  adjustedLeft = vectorRight;
2445  else
2446  adjustedLeft = QPoint(0, 0);
2447  painter->setPen(QPen(baseColor1, 0));
2448  if (!selected)
2449  painter->drawLine(bottomLeft + vectorUp + adjustedLeft, baseLine.p2() + vectorUp);
2450 
2451  QPoint endPoint = bottomRight + vectorUp;
2452  if (atEnd && !selected)
2453  painter->drawPoint(endPoint);
2454 
2455  // For drawing a lower left "fake" corner on the base when the first tab is unselected
2456  if (atBeginning && !selected) {
2457  painter->drawPoint(baseLine.p1() + vectorLeft);
2458  }
2459 
2460  painter->setPen(QPen(corner, 0));
2461  if (nextSelected)
2462  painter->drawPoint(endPoint);
2463  else if (selected)
2464  painter->drawPoint(endPoint + vectorRight);
2465 
2466  // For drawing a lower left "fake" corner on the base when the first tab is unselected
2467  if (atBeginning && !selected) {
2468  painter->drawPoint(baseLine.p1() + 2 * vectorLeft);
2469  }
2470  }
2471  }
2472  }
2473 
2474  // Yay we're done
2475 
2476  painter->restore();
2477  }
2478  break;
2479 #endif // QT_NO_TABBAR
2480 #ifndef QT_NO_PROGRESSBAR
2481  case CE_ProgressBarGroove:
2482  if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2483  QRect rect = bar->rect;
2484  QPen oldPen = painter->pen();
2485 
2486  QLine lines[4];
2487 
2488  // outline
2489  painter->setPen(borderColor);
2490  lines[0] = QLine(rect.left() + 2, rect.top(), rect.right() - 2, rect.top());
2491  lines[1] = QLine(rect.left() + 2, rect.bottom(), rect.right() - 2, rect.bottom());
2492  lines[2] = QLine(rect.left(), rect.top() + 2, rect.left(), rect.bottom() - 2);
2493  lines[3] = QLine(rect.right(), rect.top() + 2, rect.right(), rect.bottom() - 2);
2494  painter->drawLines(lines, 4);
2495 
2496  QPoint points[8];
2497  points[0] = QPoint(rect.left() + 1, rect.top() + 1);
2498  points[1] = QPoint(rect.right() - 1, rect.top() + 1);
2499  points[2] = QPoint(rect.left() + 1, rect.bottom() - 1);
2500  points[3] = QPoint(rect.right() - 1, rect.bottom() - 1);
2501  painter->drawPoints(points, 4);
2502 
2503  // alpha corners
2504  painter->setPen(alphaCornerColor);
2505  points[0] = QPoint(rect.left(), rect.top() + 1);
2506  points[1] = QPoint(rect.left() + 1, rect.top());
2507  points[2] = QPoint(rect.right(), rect.top() + 1);
2508  points[3] = QPoint(rect.right() - 1, rect.top());
2509  points[4] = QPoint(rect.left(), rect.bottom() - 1);
2510  points[5] = QPoint(rect.left() + 1, rect.bottom());
2511  points[6] = QPoint(rect.right(), rect.bottom() - 1);
2512  points[7] = QPoint(rect.right() - 1, rect.bottom());
2513  painter->drawPoints(points, 8);
2514 
2515  // inner outline, north-west
2516  painter->setPen(gradientStartColor.darker(105));
2517  lines[0] = QLine(rect.left() + 2, rect.top() + 1, rect.right() - 2, rect.top() + 1);
2518  lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
2519  painter->drawLines(lines, 2);
2520 
2521  // base of the groove
2522  painter->setPen(QPen());
2523  painter->fillRect(rect.adjusted(2, 2, -2, -1), QBrush(bar->palette.base().color()));
2524  painter->setPen(bar->palette.base().color());
2525  painter->drawLine(rect.right() - 1, rect.top() + 2, rect.right() - 1, rect.bottom() - 2);
2526 
2527  painter->setPen(oldPen);
2528  }
2529  break;
2530  case CE_ProgressBarLabel:
2531  if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2532  // The busy indicator doesn't draw a label
2533  if (bar->minimum == 0 && bar->maximum == 0)
2534  return;
2535 
2536  painter->save();
2537 
2538  QRect rect = bar->rect;
2539  QRect leftRect;
2540 
2541  QFont font;
2542  font.setBold(true);
2543  painter->setFont(font);
2544  painter->setPen(bar->palette.text().color());
2545 
2546  bool vertical = false;
2547  bool inverted = false;
2548  bool bottomToTop = false;
2549  // Get extra style options if version 2
2550  if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2551  vertical = (bar2->orientation == Qt::Vertical);
2552  inverted = bar2->invertedAppearance;
2553  bottomToTop = bar2->bottomToTop;
2554  }
2555 
2556  if (vertical) {
2557  rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2558  QTransform m;
2559  if (bottomToTop) {
2560  m.translate(0.0, rect.width());
2561  m.rotate(-90);
2562  } else {
2563  m.translate(rect.height(), 0.0);
2564  m.rotate(90);
2565  }
2566  painter->setTransform(m, true);
2567  }
2568 
2569  int progressIndicatorPos = (bar->progress - qreal(bar->minimum)) / qMax(qreal(1.0), qreal(bar->maximum) - bar->minimum) * rect.width();
2570 
2571  bool flip = (!vertical && (((bar->direction == Qt::RightToLeft) && !inverted)
2572  || ((bar->direction == Qt::LeftToRight) && inverted))) || (vertical && ((!inverted && !bottomToTop) || (inverted && bottomToTop)));
2573  if (flip) {
2574  int indicatorPos = rect.width() - progressIndicatorPos;
2575  if (indicatorPos >= 0 && indicatorPos <= rect.width()) {
2576  painter->setPen(bar->palette.base().color());
2577  leftRect = QRect(rect.left(), rect.top(), indicatorPos, rect.height());
2578  } else if (indicatorPos > rect.width()) {
2579  painter->setPen(bar->palette.text().color());
2580  } else {
2581  painter->setPen(bar->palette.base().color());
2582  }
2583  } else {
2584  if (progressIndicatorPos >= 0 && progressIndicatorPos <= rect.width()) {
2585  leftRect = QRect(rect.left(), rect.top(), progressIndicatorPos, rect.height());
2586  } else if (progressIndicatorPos > rect.width()) {
2587  painter->setPen(bar->palette.base().color());
2588  } else {
2589  painter->setPen(bar->palette.text().color());
2590  }
2591  }
2592 
2593  QRegion rightRect = rect;
2594  rightRect = rightRect.subtracted(leftRect);
2595  painter->setClipRegion(rightRect);
2597  if (!leftRect.isNull()) {
2598  painter->setPen(flip ? bar->palette.text().color() : bar->palette.base().color());
2599  painter->setClipRect(leftRect);
2601  }
2602 
2603  painter->restore();
2604  }
2605  break;
2607  if (const QStyleOptionProgressBar *bar = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2608  Q_D(const QPlastiqueStyle);
2609  QRect rect = bar->rect;
2610  bool vertical = false;
2611  bool inverted = false;
2612  bool indeterminate = (bar->minimum == 0 && bar->maximum == 0);
2613  if (!indeterminate && bar->progress == -1)
2614  break;
2615 
2616  painter->save();
2617 
2618  // Get extra style options if version 2
2619  if (const QStyleOptionProgressBarV2 *bar2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(option)) {
2620  vertical = (bar2->orientation == Qt::Vertical);
2621  inverted = bar2->invertedAppearance;
2622  }
2623 
2624  // If the orientation is vertical, we use a transform to rotate
2625  // the progress bar 90 degrees clockwise. This way we can use the
2626  // same rendering code for both orientations.
2627  if (vertical) {
2628  rect = QRect(rect.left(), rect.top(), rect.height(), rect.width()); // flip width and height
2629  QTransform m = QTransform::fromTranslate(rect.height()-1, 0);
2630  m.rotate(90.0);
2631  painter->setTransform(m, true);
2632  }
2633 
2634  int maxWidth = rect.width() - 4;
2635  int minWidth = 4;
2636  qint64 progress = qMax<qint64>(bar->progress, bar->minimum); // workaround for bug in QProgressBar
2637  double vc6_workaround = ((progress - qint64(bar->minimum)) / qMax(double(1.0), double(qint64(bar->maximum) - qint64(bar->minimum))) * maxWidth);
2638  int width = indeterminate ? maxWidth : qMax(int(vc6_workaround), minWidth);
2639  bool reverse = (!vertical && (bar->direction == Qt::RightToLeft)) || vertical;
2640  if (inverted)
2641  reverse = !reverse;
2642 
2643  QRect progressBar;
2644  if (!indeterminate) {
2645  if (!reverse) {
2646  progressBar.setRect(rect.left() + 2, rect.top() + 2, width, rect.height() - 4);
2647  } else {
2648  progressBar.setRect(rect.right() - 1 - width, rect.top() + 2, width, rect.height() - 4);
2649  }
2650  } else {
2651  int slideWidth = ((rect.width() - 4) * 2) / 3;
2652  int step = ((d->animateStep * slideWidth) / ProgressBarFps) % slideWidth;
2653  if ((((d->animateStep * slideWidth) / ProgressBarFps) % (2 * slideWidth)) >= slideWidth)
2654  step = slideWidth - step;
2655  progressBar.setRect(rect.left() + 2 + step, rect.top() + 2,
2656  slideWidth / 2, rect.height() - 4);
2657  }
2658 
2659  // outline
2660  painter->setPen(highlightedDarkInnerBorderColor);
2661 
2664  if (!reverse) {
2665  if (width == minWidth) {
2666  points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2667  points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2668  } else {
2669  if (indeterminate) {
2670  lines.append(QLine(progressBar.left() + 2, progressBar.top(),
2671  progressBar.right() - 2, progressBar.top()));
2672  lines.append(QLine(progressBar.left() + 2, progressBar.bottom(),
2673  progressBar.right() - 2, progressBar.bottom()));
2674  } else {
2675  lines.append(QLine(progressBar.left() + 1, progressBar.top(),
2676  progressBar.right() - 2, progressBar.top()));
2677  lines.append(QLine(progressBar.left() + 1, progressBar.bottom(),
2678  progressBar.right() - 2, progressBar.bottom()));
2679  }
2680  }
2681 
2682  if (indeterminate) {
2683  lines.append(QLine(progressBar.left(), progressBar.top() + 2,
2684  progressBar.left(), progressBar.bottom() - 2));
2685  } else {
2686  lines.append(QLine(progressBar.left(), progressBar.top() + 1,
2687  progressBar.left(), progressBar.bottom() - 1));
2688  }
2689  lines.append(QLine(progressBar.right(), progressBar.top() + 2,
2690  progressBar.right(), progressBar.bottom() - 2));
2691  } else {
2692  if (width == minWidth) {
2693  points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2694  points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2695  } else {
2696  if (indeterminate) {
2697  lines.append(QLine(progressBar.right() - 2, progressBar.top(),
2698  progressBar.left() + 2, progressBar.top()));
2699  lines.append(QLine(progressBar.right() - 2, progressBar.bottom(),
2700  progressBar.left() + 2, progressBar.bottom()));
2701  } else {
2702  lines.append(QLine(progressBar.right() - 1, progressBar.top(),
2703  progressBar.left() + 2, progressBar.top()));
2704  lines.append(QLine(progressBar.right() - 1, progressBar.bottom(),
2705  progressBar.left() + 2, progressBar.bottom()));
2706  }
2707  }
2708  if (indeterminate) {
2709  lines.append(QLine(progressBar.right(), progressBar.top() + 2,
2710  progressBar.right(), progressBar.bottom() - 2));
2711  } else {
2712  lines.append(QLine(progressBar.right(), progressBar.top() + 1,
2713  progressBar.right(), progressBar.bottom() - 1));
2714  }
2715  lines.append(QLine(progressBar.left(), progressBar.top() + 2,
2716  progressBar.left(), progressBar.bottom() - 2));
2717  }
2718 
2719  if (points.size() > 0) {
2720  painter->drawPoints(points.constData(), points.size());
2721  points.clear();
2722  }
2723  painter->drawLines(lines.constData(), lines.size());
2724  lines.clear();
2725 
2726  // alpha corners
2727  painter->setPen(alphaInnerColor);
2728  if (!reverse) {
2729  if (indeterminate) {
2730  points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2731  points.append(QPoint(progressBar.left(), progressBar.top() + 1));
2732  points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2733  points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
2734  } else {
2735  points.append(QPoint(progressBar.left(), progressBar.top()));
2736  points.append(QPoint(progressBar.left(), progressBar.bottom()));
2737  }
2738  points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2739  points.append(QPoint(progressBar.right(), progressBar.top() + 1));
2740  points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2741  points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
2742  } else {
2743  if (indeterminate) {
2744  points.append(QPoint(progressBar.right() - 1, progressBar.top()));
2745  points.append(QPoint(progressBar.right(), progressBar.top() + 1));
2746  points.append(QPoint(progressBar.right() - 1, progressBar.bottom()));
2747  points.append(QPoint(progressBar.right(), progressBar.bottom() - 1));
2748  } else {
2749  points.append(QPoint(progressBar.right(), progressBar.top()));
2750  points.append(QPoint(progressBar.right(), progressBar.bottom()));
2751  }
2752  points.append(QPoint(progressBar.left() + 1, progressBar.top()));
2753  points.append(QPoint(progressBar.left(), progressBar.top() + 1));
2754  points.append(QPoint(progressBar.left() + 1, progressBar.bottom()));
2755  points.append(QPoint(progressBar.left(), progressBar.bottom() - 1));
2756  }
2757 
2758  painter->drawPoints(points.constData(), points.size());
2759  points.clear();
2760 
2761  // contents
2762  painter->setPen(QPen());
2763 
2764  QString progressBarName = QStyleHelper::uniqueName(QLatin1String("progressBarContents"),
2765  option, rect.size());
2766  QPixmap cache;
2767  if (!QPixmapCache::find(progressBarName, cache) && rect.height() > 7) {
2768  QSize size = rect.size();
2769  cache = QPixmap(QSize(size.width() - 6 + 30, size.height() - 6));
2770  cache.fill(Qt::white);
2771  QPainter cachePainter(&cache);
2772  QRect pixmapRect(0, 0, cache.width(), cache.height());
2773 
2774  int leftEdge = 0;
2775  bool flip = false;
2776  while (leftEdge < cache.width() + 1) {
2777  QColor rectColor = option->palette.highlight().color();
2778  QColor lineColor = option->palette.highlight().color();
2779  if (flip) {
2780  flip = false;
2781  rectColor = rectColor.lighter(105);
2782  lineColor = lineColor.lighter(105);
2783  } else {
2784  flip = true;
2785  }
2786 
2787  cachePainter.setPen(lineColor);
2788  const QLine cacheLines[2] = {
2789  QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.top(),
2790  pixmapRect.left() + leftEdge + 9, pixmapRect.top()),
2791  QLine(pixmapRect.left() + leftEdge - 1, pixmapRect.bottom(),
2792  pixmapRect.left() + leftEdge + 9, pixmapRect.bottom()) };
2793  cachePainter.drawLines(cacheLines, 2);
2794  cachePainter.fillRect(QRect(pixmapRect.left() + leftEdge, pixmapRect.top(),
2795  10, pixmapRect.height()), rectColor);
2796 
2797  leftEdge += 10;
2798  }
2799 
2800  QPixmapCache::insert(progressBarName, cache);
2801  }
2802  painter->setClipRect(progressBar.adjusted(1, 0, -1, -1));
2803 
2804  if (!vertical)
2805  progressBar.adjust(0, 1, 0, 1);
2806  if (!indeterminate) {
2807  int step = (AnimateProgressBar || (indeterminate && AnimateBusyProgressBar)) ? (d->animateStep % 20) : 0;
2808  if (reverse)
2809  painter->drawPixmap(progressBar.left() - 25 + step, progressBar.top(), cache);
2810  else
2811  painter->drawPixmap(progressBar.left() - 25 - step + width % 20, progressBar.top(), cache);
2812  } else {
2813  painter->drawPixmap(progressBar.left(), progressBar.top(), cache);
2814  }
2815 
2816  painter->restore();
2817  }
2818  break;
2819 #endif // QT_NO_PROGRESSBAR
2820  case CE_HeaderSection:
2821  // Draws the header in tables.
2822  if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2823  QPixmap cache;
2824  QString pixmapName = QStyleHelper::uniqueName(QLatin1String("headersection"), option, option->rect.size());
2825  pixmapName += QString::number(- int(header->position));
2826  pixmapName += QString::number(- int(header->orientation));
2827 
2828  if (!QPixmapCache::find(pixmapName, cache)) {
2829  cache = QPixmap(option->rect.size());
2830  cache.fill(Qt::white);
2831  QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
2832  QPainter cachePainter(&cache);
2833 
2834  bool sunken = (header->state & State_Enabled) && (header->state & State_Sunken);
2835 
2836  QColor headerGradientStart = sunken ? option->palette.background().color().darker(114) : gradientStartColor;
2837  QColor headerGradientStop = sunken ? option->palette.background().color().darker(106) : gradientStopColor;
2838 
2839  QColor lightLine = sunken ? option->palette.background().color().darker(118) : gradientStartColor;
2840  QColor darkLine = sunken ? option->palette.background().color().darker(110) : gradientStopColor.darker(105);
2841 
2842  qt_plastique_draw_gradient(&cachePainter, pixmapRect,
2843  headerGradientStart, headerGradientStop);
2844 
2845  cachePainter.setPen(borderColor);
2846  cachePainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
2847  cachePainter.setPen(alphaCornerColor);
2848 
2849  const QPoint points[4] = {
2850  pixmapRect.topLeft(), pixmapRect.topRight(),
2851  pixmapRect.bottomLeft(), pixmapRect.bottomRight() };
2852  cachePainter.drawPoints(points, 4);
2853 
2854  QLine lines[2];
2855 
2856  // inner lines
2857  cachePainter.setPen(lightLine);
2858  lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.top() + 1,
2859  pixmapRect.right() - 2, pixmapRect.top() + 1);
2860  lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
2861  pixmapRect.left() + 1, pixmapRect.bottom() - 2);
2862  cachePainter.drawLines(lines, 2);
2863 
2864  cachePainter.setPen(darkLine);
2865  lines[0] = QLine(pixmapRect.left() + 2, pixmapRect.bottom() - 1,
2866  pixmapRect.right() - 2, pixmapRect.bottom() - 1);
2867  lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.bottom() - 2,
2868  pixmapRect.right() - 1, pixmapRect.top() + 2);
2869  cachePainter.drawLines(lines, 2);
2870 
2871  cachePainter.end();
2872  QPixmapCache::insert(pixmapName, cache);
2873  }
2874  painter->drawPixmap(option->rect.topLeft(), cache);
2875 
2876  }
2877  break;
2878 #ifndef QT_NO_MENU
2879  case CE_MenuItem:
2880  // Draws one item in a popup menu.
2881  if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2882  painter->save();
2883  QBrush textBrush;
2884  if (option->palette.resolve() & (1 << QPalette::ButtonText))
2885  textBrush = option->palette.buttonText();
2886  else
2887  textBrush = option->palette.windowText(); // KDE uses windowText rather than buttonText for menus
2888 
2889  if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
2890  painter->fillRect(menuItem->rect, option->palette.background().color().lighter(103));
2891 
2892  int w = 0;
2893  if (!menuItem->text.isEmpty()) {
2894  painter->setFont(menuItem->font);
2895  proxy()->drawItemText(painter, menuItem->rect.adjusted(5, 0, -5, 0), Qt::AlignLeft | Qt::AlignVCenter,
2896  menuItem->palette, menuItem->state & State_Enabled, menuItem->text,
2897  QPalette::Text);
2898  w = menuItem->fontMetrics.width(menuItem->text) + 5;
2899  }
2900 
2901  painter->setPen(alphaCornerColor);
2902  bool reverse = menuItem->direction == Qt::RightToLeft;
2903  painter->drawLine(menuItem->rect.left() + 5 + (reverse ? 0 : w), menuItem->rect.center().y(),
2904  menuItem->rect.right() - 5 - (reverse ? w : 0), menuItem->rect.center().y());
2905 
2906  painter->restore();
2907  break;
2908  }
2909 
2910  bool selected = menuItem->state & State_Selected;
2911  bool checkable = menuItem->checkType != QStyleOptionMenuItem::NotCheckable;
2912  bool checked = menuItem->checked;
2913 
2914  if (selected) {
2915  qt_plastique_draw_gradient(painter, menuItem->rect,
2916  option->palette.highlight().color().lighter(105),
2917  option->palette.highlight().color().darker(110));
2918 
2919  painter->setPen(option->palette.highlight().color().lighter(110));
2920  painter->drawLine(option->rect.topLeft(), option->rect.topRight());
2921  painter->setPen(option->palette.highlight().color().darker(115));
2922  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
2923  } else {
2924  painter->fillRect(option->rect, option->palette.background().color().lighter(103));
2925  }
2926 
2927  // Check
2928  QRect checkRect(option->rect.left() + 7, option->rect.center().y() - 6, 13, 13);
2929  checkRect = visualRect(menuItem->direction, menuItem->rect, checkRect);
2930  if (checkable) {
2931  if ((menuItem->checkType & QStyleOptionMenuItem::Exclusive) && menuItem->icon.isNull()) {
2932  QStyleOptionButton button;
2933  button.rect = checkRect;
2934  button.state = menuItem->state;
2935  if (checked)
2936  button.state |= State_On;
2937  button.palette = menuItem->palette;
2938  proxy()->drawPrimitive(PE_IndicatorRadioButton, &button, painter, widget);
2939  } else {
2940  if (menuItem->icon.isNull()) {
2941  QStyleOptionButton button;
2942  button.rect = checkRect;
2943  button.state = menuItem->state;
2944  if (checked)
2945  button.state |= State_On;
2946  button.palette = menuItem->palette;
2947  proxy()->drawPrimitive(PE_IndicatorCheckBox, &button, painter, widget);
2948  } else if (checked) {
2949  int iconSize = qMax(menuItem->maxIconWidth, 20);
2950  QRect sunkenRect(option->rect.left() + 1,
2951  option->rect.top() + (option->rect.height() - iconSize) / 2 + 1,
2952  iconSize, iconSize);
2953  sunkenRect = visualRect(menuItem->direction, menuItem->rect, sunkenRect);
2954 
2955  QStyleOption opt = *option;
2956  opt.state |= State_Sunken;
2957  opt.rect = sunkenRect;
2958  qt_plastique_drawShadedPanel(painter, &opt, false, widget);
2959  }
2960  }
2961  }
2962 
2963  // Text and icon, ripped from windows style
2964  bool dis = !(menuItem->state & State_Enabled);
2965  bool act = menuItem->state & State_Selected;
2966  const QStyleOption *opt = option;
2967  const QStyleOptionMenuItem *menuitem = menuItem;
2968  int checkcol = qMax(menuitem->maxIconWidth, 20);
2969  QPainter *p = painter;
2970  QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
2971  QRect(menuitem->rect.x(), menuitem->rect.y(),
2972  checkcol, menuitem->rect.height()));
2973  if (!menuItem->icon.isNull()) {
2974  QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
2975  if (act && !dis)
2976  mode = QIcon::Active;
2977  QPixmap pixmap;
2978  if (checked)
2979  pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode, QIcon::On);
2980  else
2981  pixmap = menuItem->icon.pixmap(pixelMetric(PM_SmallIconSize, option, widget), mode);
2982  int pixw = pixmap.width();
2983  int pixh = pixmap.height();
2984 
2985  QRect pmr(0, 0, pixw, pixh);
2986  pmr.moveCenter(vCheckRect.center());
2987  painter->setPen(textBrush.color());
2988  if (checkable && checked)
2989  painter->drawPixmap(QPoint(pmr.left() + 1, pmr.top() + 1), pixmap);
2990  else
2991  painter->drawPixmap(pmr.topLeft(), pixmap);
2992  }
2993 
2994  if (selected) {
2995  painter->setPen(menuItem->palette.highlightedText().color());
2996  } else {
2997  painter->setPen(textBrush.color());
2998  }
2999  int x, y, w, h;
3000  menuitem->rect.getRect(&x, &y, &w, &h);
3001  int tab = menuitem->tabWidth;
3002  QColor discol;
3003  if (dis) {
3004  discol = textBrush.color();
3005  p->setPen(discol);
3006  }
3007  int xm = windowsItemFrame + checkcol + windowsItemHMargin;
3008  int xpos = menuitem->rect.x() + xm;
3009  QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
3010  QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
3011  QString s = menuitem->text;
3012  if (!s.isEmpty()) { // draw text
3013  p->save();
3014  int t = s.indexOf(QLatin1Char('\t'));
3016  if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
3017  text_flags |= Qt::TextHideMnemonic;
3018  text_flags |= Qt::AlignLeft;
3019  if (t >= 0) {
3020  QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
3021  QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
3022  if (dis && !act && styleHint(SH_EtchDisabledText, option, widget)) {
3023  p->setPen(menuitem->palette.light().color());
3024  p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
3025  p->setPen(discol);
3026  }
3027  p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
3028  s = s.left(t);
3029  }
3030  QFont font = menuitem->font;
3032  font.setBold(true);
3033  p->setFont(font);
3034  if (dis && !act && styleHint(SH_EtchDisabledText, option, widget)) {
3035  p->setPen(menuitem->palette.light().color());
3036  p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
3037  p->setPen(discol);
3038  }
3039  p->drawText(vTextRect, text_flags, s.left(t));
3040  p->restore();
3041  }
3042 
3043  // Arrow
3044  if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
3045  int dim = (menuItem->rect.height() - 4) / 2;
3046  PrimitiveElement arrow;
3048  int xpos = menuItem->rect.left() + menuItem->rect.width() - 6 - 2 - dim;
3049  QRect vSubMenuRect = visualRect(option->direction, menuItem->rect,
3050  QRect(xpos, menuItem->rect.top() + menuItem->rect.height() / 2 - dim / 2, dim, dim));
3051  QStyleOptionMenuItem newMI = *menuItem;
3052  newMI.rect = vSubMenuRect;
3053  newMI.state = option->state & State_Enabled;
3054  if (selected)
3056  newMI.palette.highlightedText().color());
3057  else
3058  newMI.palette.setColor(QPalette::ButtonText, textBrush.color());
3059  proxy()->drawPrimitive(arrow, &newMI, painter, widget);
3060  }
3061 
3062  painter->restore();
3063  }
3064  break;
3065 #endif // QT_NO_MENU
3066 #ifndef QT_NO_MENUBAR
3067  case CE_MenuBarItem:
3068  // Draws a menu bar item; File, Edit, Help etc..
3069  if ((option->state & State_Selected)) {
3070  QPixmap cache;
3071  QString pixmapName = QStyleHelper::uniqueName(QLatin1String("menubaritem"), option, option->rect.size());
3072  if (!QPixmapCache::find(pixmapName, cache)) {
3073  cache = QPixmap(option->rect.size());
3074  cache.fill(Qt::white);
3075  QRect pixmapRect(0, 0, option->rect.width(), option->rect.height());
3076  QPainter cachePainter(&cache);
3077 
3078  QRect rect = pixmapRect;
3079 
3080  // gradient fill
3081  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On)) {
3082  qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
3083  option->palette.button().color().darker(114),
3084  option->palette.button().color().darker(106));
3085  } else {
3086  qt_plastique_draw_gradient(&cachePainter, rect.adjusted(1, 1, -1, -1),
3087  option->palette.background().color().lighter(105),
3088  option->palette.background().color().darker(102));
3089  }
3090 
3091  // outer border and corners
3092  cachePainter.setPen(borderColor);
3093  cachePainter.drawRect(rect.adjusted(0, 0, -1, -1));
3094  cachePainter.setPen(alphaCornerColor);
3095 
3096  const QPoint points[4] = {
3097  rect.topLeft(),
3098  rect.topRight(),
3099  rect.bottomLeft(),
3100  rect.bottomRight() };
3101  cachePainter.drawPoints(points, 4);
3102 
3103  // inner border
3104  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
3105  cachePainter.setPen(option->palette.button().color().darker(118));
3106  else
3107  cachePainter.setPen(gradientStartColor);
3108 
3109  QLine lines[2];
3110  lines[0] = QLine(rect.left() + 1, rect.top() + 1, rect.right() - 1, rect.top() + 1);
3111  lines[1] = QLine(rect.left() + 1, rect.top() + 2, rect.left() + 1, rect.bottom() - 2);
3112  cachePainter.drawLines(lines, 2);
3113 
3114  if ((option->state & QStyle::State_Sunken) || (option->state & QStyle::State_On))
3115  cachePainter.setPen(option->palette.button().color().darker(114));
3116  else
3117  cachePainter.setPen(gradientStopColor.darker(102));
3118  lines[0] = QLine(rect.left() + 1, rect.bottom() - 1, rect.right() - 1, rect.bottom() - 1);
3119  lines[1] = QLine(rect.right() - 1, rect.top() + 1, rect.right() - 1, rect.bottom() - 2);
3120  cachePainter.drawLines(lines, 2);
3121  cachePainter.end();
3122  QPixmapCache::insert(pixmapName, cache);
3123  }
3124  painter->drawPixmap(option->rect.topLeft(), cache);
3125  } else {
3126  painter->fillRect(option->rect, option->palette.background());
3127  }
3128 
3129  if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
3130  QStyleOptionMenuItem newMI = *mbi;
3131  if (!(option->palette.resolve() & (1 << QPalette::ButtonText))) //KDE uses windowText rather than buttonText for menus
3133  QCommonStyle::drawControl(element, &newMI, painter, widget);
3134  }
3135  break;
3136 
3137 #ifndef QT_NO_MAINWINDOW
3138  case CE_MenuBarEmptyArea:
3139  if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
3140  painter->fillRect(option->rect, option->palette.window());
3141  QPen oldPen = painter->pen();
3142  painter->setPen(QPen(option->palette.dark().color()));
3143  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3144  painter->setPen(oldPen);
3145  }
3146  break;
3147 #endif // QT_NO_MAINWINDOW
3148 
3149 #endif // QT_NO_MENUBAR
3150 
3151 #ifndef QT_NO_TOOLBOX
3152  case CE_ToolBoxTabShape:
3153  if (const QStyleOptionToolBox *toolBox = qstyleoption_cast<const QStyleOptionToolBox *>(option)) {
3154  painter->save();
3155 
3156  int width = toolBox->rect.width();
3157  int diag = toolBox->rect.height() - 2;
3158 
3159  // The essential points
3160  QPoint rightMost;
3161  QPoint rightEdge;
3162  QPoint leftEdge;
3163  QPoint leftMost;
3164  QPoint leftOne;
3165  QPoint rightOne;
3166  QPoint upOne(0, -1);
3167  QPoint downOne(0, 1);
3168 
3169  if (toolBox->direction != Qt::RightToLeft) {
3170  rightMost = QPoint(toolBox->rect.right(), toolBox->rect.bottom() - 2);
3171  rightEdge = QPoint(toolBox->rect.right() - width / 10, toolBox->rect.bottom() - 2);
3172  leftEdge = QPoint(toolBox->rect.right() - width / 10 - diag, toolBox->rect.top());
3173  leftMost = QPoint(toolBox->rect.left(), toolBox->rect.top());
3174  leftOne = QPoint(-1, 0);
3175  rightOne = QPoint(1, 0);
3176  } else {
3177  rightMost = QPoint(toolBox->rect.left(), toolBox->rect.bottom() - 2);
3178  rightEdge = QPoint(toolBox->rect.left() + width / 10, toolBox->rect.bottom() - 2);
3179  leftEdge = QPoint(toolBox->rect.left() + width / 10 + diag, toolBox->rect.top());
3180  leftMost = QPoint(toolBox->rect.right(), toolBox->rect.top());
3181  leftOne = QPoint(1, 0);
3182  rightOne = QPoint(-1, 0);
3183  }
3184 
3185  QLine lines[3];
3186 
3187  // Draw the outline
3188  painter->setPen(borderColor);
3189  lines[0] = QLine(rightMost, rightEdge);
3190  lines[1] = QLine(rightEdge + leftOne, leftEdge);
3191  lines[2] = QLine(leftEdge + leftOne, leftMost);
3192  painter->drawLines(lines, 3);
3193  painter->setPen(toolBox->palette.base().color());
3194  lines[0] = QLine(rightMost + downOne, rightEdge + downOne);
3195  lines[1] = QLine(rightEdge + leftOne + downOne, leftEdge + downOne);
3196  lines[2] = QLine(leftEdge + leftOne + downOne, leftMost + downOne);
3197  painter->drawLines(lines, 3);
3198 
3199  painter->restore();
3200  }
3201  break;
3202 #endif // QT_NO_TOOLBOX
3203 #ifndef QT_NO_SPLITTER
3204  case CE_Splitter:
3205  if ((option->state & State_Enabled) && (option->state & State_MouseOver))
3206  painter->fillRect(option->rect, QColor(255, 255, 255, 128));
3207  if (option->state & State_Horizontal) {
3208  int height = option->rect.height() / 3;
3209  QRect rect(option->rect.left() + (option->rect.width() / 2 - 1),
3210  option->rect.center().y() - height / 2, 3, height);
3211  qt_plastique_draw_handle(painter, option, rect, Qt::Horizontal, widget);
3212  } else {
3213  int width = option->rect.width() / 3;
3214  QRect rect(option->rect.center().x() - width / 2,
3215  option->rect.top() + (option->rect.height() / 2) - 1, width, 3);
3216  qt_plastique_draw_handle(painter, option, rect, Qt::Vertical, widget);
3217  }
3218  break;
3219 #endif // QT_NO_SPLITTER
3220 #ifndef QT_NO_DOCKWIDGET
3221  case CE_DockWidgetTitle:
3222  if (const QStyleOptionDockWidget *dockWidget = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) {
3223  painter->save();
3224 
3225  const QStyleOptionDockWidgetV2 *v2
3226  = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(dockWidget);
3227  bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
3228 
3229  // Find text width and title rect
3230  int textWidth = option->fontMetrics.width(dockWidget->title);
3231  int margin = 4;
3232  QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
3233  QRect rect = dockWidget->rect;
3234 
3235  if (verticalTitleBar) {
3236  QRect r = rect;
3237  QSize s = r.size();
3238  s.transpose();
3239  r.setSize(s);
3240 
3241  titleRect = QRect(r.left() + rect.bottom()
3242  - titleRect.bottom(),
3243  r.top() + titleRect.left() - rect.left(),
3244  titleRect.height(), titleRect.width());
3245 
3246  painter->translate(r.left(), r.top() + r.width());
3247  painter->rotate(-90);
3248  painter->translate(-r.left(), -r.top());
3249 
3250  rect = r;
3251  }
3252 
3253  // Chop and insert ellide into title if text is too wide
3254  QString title = elliditide(dockWidget->title, dockWidget->fontMetrics, titleRect, &textWidth);
3255 
3256  // Draw the toolbar handle pattern to the left and right of the text
3257  QImage handle(qt_toolbarhandle);
3258  alphaCornerColor.setAlpha(170);
3259  handle.setColor(1, alphaCornerColor.rgba());
3260  handle.setColor(2, mergedColors(alphaCornerColor, option->palette.light().color()).rgba());
3261  handle.setColor(3, option->palette.light().color().rgba());
3262 
3263  if (title.isEmpty()) {
3264  // Joint handle if there's no title
3265  QRect r;
3266 #ifdef QT3_SUPPORT
3267  // Q3DockWindow doesn't need space for buttons
3268  if (widget && widget->inherits("Q3DockWindowTitleBar")) {
3269  r = rect;
3270  } else
3271 #endif
3272  r.setRect(titleRect.left(), titleRect.top(), titleRect.width(), titleRect.bottom());
3273  int nchunks = (r.width() / handle.width()) - 1;
3274  int indent = (r.width() - (nchunks * handle.width())) / 2;
3275  for (int i = 0; i < nchunks; ++i) {
3276  painter->drawImage(QPoint(r.left() + indent + i * handle.width(),
3277  r.center().y() - handle.height() / 2),
3278  handle);
3279  }
3280  } else {
3281  // Handle pattern to the left of the title
3282  QRect leftSide(titleRect.left(), titleRect.top(),
3283  titleRect.width() / 2 - textWidth / 2 - margin, titleRect.bottom());
3284  int nchunks = leftSide.width() / handle.width();
3285  int indent = (leftSide.width() - (nchunks * handle.width())) / 2;
3286  for (int i = 0; i < nchunks; ++i) {
3287  painter->drawImage(QPoint(leftSide.left() + indent
3288  + i * handle.width(),
3289  leftSide.center().y()
3290  - handle.height() / 2),
3291  handle);
3292  }
3293 
3294  // Handle pattern to the right of the title
3295  QRect rightSide = titleRect.adjusted(titleRect.width() / 2 + textWidth / 2 + margin, 0, 0, 0);
3296  nchunks = rightSide.width() / handle.width();
3297  indent = (rightSide.width() - (nchunks * handle.width())) / 2;
3298  for (int j = 0; j < nchunks; ++j) {
3299  painter->drawImage(QPoint(rightSide.left() + indent + j * handle.width(),
3300  rightSide.center().y() - handle.height() / 2),
3301  handle);
3302  }
3303  }
3304 
3305  // Draw the text centered
3306  QFont font = painter->font();
3307  font.setPointSize(QFontInfo(font).pointSize() - 1);
3308  painter->setFont(font);
3309  painter->setPen(dockWidget->palette.windowText().color());
3310  painter->drawText(titleRect,
3312  title);
3313 
3314  painter->restore();
3315  }
3316 
3317  break;
3318 #endif // QT_NO_DOCKWIDGET
3319 #ifndef QT_NO_TOOLBAR
3320  case CE_ToolBar:
3321  if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(option)) {
3322  // Draws the light line above and the dark line below menu bars and
3323  // tool bars.
3324  QPen oldPen = painter->pen();
3325  if (toolBar->toolBarArea == Qt::TopToolBarArea) {
3326  if (toolBar->positionOfLine == QStyleOptionToolBar::End
3327  || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3328  // The end and onlyone top toolbar lines draw a double
3329  // line at the bottom to blend with the central
3330  // widget.
3331  painter->setPen(option->palette.background().color().lighter(104));
3332  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3333  painter->setPen(alphaCornerColor);
3334  painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
3335  option->rect.right(), option->rect.bottom() - 1);
3336  } else {
3337  // All others draw a single dark line at the bottom.
3338  painter->setPen(alphaCornerColor);
3339  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3340  }
3341  // All top toolbar lines draw a light line at the top.
3342  painter->setPen(option->palette.background().color().lighter(104));
3343  painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3344  } else if (toolBar->toolBarArea == Qt::BottomToolBarArea) {
3345  if (toolBar->positionOfLine == QStyleOptionToolBar::End
3346  || toolBar->positionOfLine == QStyleOptionToolBar::Middle) {
3347  // The end and middle bottom tool bar lines draw a dark
3348  // line at the bottom.
3349  painter->setPen(alphaCornerColor);
3350  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3351  }
3352  if (toolBar->positionOfLine == QStyleOptionToolBar::Beginning
3353  || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3354  // The beginning and only one tool bar lines draw a
3355  // double line at the bottom to blend with the
3356  // status bar.
3357  // ### The styleoption could contain whether the
3358  // main window has a menu bar and a status bar, and
3359  // possibly dock widgets.
3360  painter->setPen(alphaCornerColor);
3361  painter->drawLine(option->rect.left(), option->rect.bottom() - 1,
3362  option->rect.right(), option->rect.bottom() - 1);
3363  painter->setPen(option->palette.background().color().lighter(104));
3364  painter->drawLine(option->rect.bottomLeft(), option->rect.bottomRight());
3365  }
3366  if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
3367  painter->setPen(alphaCornerColor);
3368  painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3369  painter->setPen(option->palette.background().color().lighter(104));
3370  painter->drawLine(option->rect.left(), option->rect.top() + 1,
3371  option->rect.right(), option->rect.top() + 1);
3372 
3373  } else {
3374  // All other bottom toolbars draw a light line at the top.
3375  painter->setPen(option->palette.background().color().lighter(104));
3376  painter->drawLine(option->rect.topLeft(), option->rect.topRight());
3377  }
3378  }
3379  if (toolBar->toolBarArea == Qt::LeftToolBarArea) {
3380  if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
3381  || toolBar->positionOfLine == QStyleOptionToolBar::End) {
3382  // The middle and left end toolbar lines draw a light
3383  // line to the left.
3384  painter->setPen(option->palette.background().color().lighter(104));
3385  painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3386  }
3387  if (toolBar->positionOfLine == QStyleOptionToolBar::End) {
3388  // All other left toolbar lines draw a dark line to the right
3389  painter->setPen(alphaCornerColor);
3390  painter->drawLine(option->rect.right() - 1, option->rect.top(),
3391  option->rect.right() - 1, option->rect.bottom());
3392  painter->setPen(option->palette.background().color().lighter(104));
3393  painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3394  } else {
3395  // All other left toolbar lines draw a dark line to the right
3396  painter->setPen(alphaCornerColor);
3397  painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3398  }
3399  } else if (toolBar->toolBarArea == Qt::RightToolBarArea) {
3400  if (toolBar->positionOfLine == QStyleOptionToolBar::Middle
3401  || toolBar->positionOfLine == QStyleOptionToolBar::End) {
3402  // Right middle and end toolbar lines draw the dark right line
3403  painter->setPen(alphaCornerColor);
3404  painter->drawLine(option->rect.topRight(), option->rect.bottomRight());
3405  }
3406  if (toolBar->positionOfLine == QStyleOptionToolBar::End
3407  || toolBar->positionOfLine == QStyleOptionToolBar::OnlyOne) {
3408  // The right end and single toolbar draws the dark
3409  // line on its left edge
3410  painter->setPen(alphaCornerColor);
3411  painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3412  // And a light line next to it
3413  painter->setPen(option->palette.background().color().lighter(104));
3414  painter->drawLine(option->rect.left() + 1, option->rect.top(),
3415  option->rect.left() + 1, option->rect.bottom());
3416  } else {
3417  // Other right toolbars draw a light line on its left edge
3418  painter->setPen(option->palette.background().color().lighter(104));
3419  painter->drawLine(option->rect.topLeft(), option->rect.bottomLeft());
3420  }
3421  }
3422  painter->setPen(oldPen);
3423  }
3424  break;
3425 #endif // QT_NO_TOOLBAR
3426 #ifndef QT_NO_SCROLLBAR
3427  case CE_ScrollBarAddLine:
3428  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3429 
3430  bool horizontal = scrollBar->orientation == Qt::Horizontal;
3431  bool reverse = scrollBar->direction == Qt::RightToLeft;
3432  bool sunken = scrollBar->state & State_Sunken;
3433 
3434  QString addLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_addline"), option, option->rect.size());
3435  QPixmap cache;
3436  if (!QPixmapCache::find(addLinePixmapName, cache)) {
3437  cache = QPixmap(option->rect.size());
3438  cache.fill(Qt::white);
3439  QRect pixmapRect(0, 0, cache.width(), cache.height());
3440  QPainter addLinePainter(&cache);
3441  addLinePainter.fillRect(pixmapRect, option->palette.background());
3442 
3443  if (option->state & State_Enabled) {
3444  // Gradient
3445  QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top() + 2,
3446  pixmapRect.center().x(), pixmapRect.bottom() - 2);
3447  if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3448  gradient.setColorAt(0, gradientStopColor);
3449  gradient.setColorAt(1, gradientStopColor);
3450  } else {
3451  gradient.setColorAt(0, gradientStartColor.lighter(105));
3452  gradient.setColorAt(1, gradientStopColor);
3453  }
3454  addLinePainter.fillRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3455  pixmapRect.right() - 3, pixmapRect.bottom() - 3,
3456  gradient);
3457  }
3458 
3459  // Details
3460  QImage addButton;
3461  if (horizontal) {
3463  } else {
3464  addButton = QImage(qt_scrollbar_button_down);
3465  }
3466  addButton.setColor(1, alphaCornerColor.rgba());
3467  addButton.setColor(2, borderColor.rgba());
3468  if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken) {
3469  addButton.setColor(3, gradientStopColor.rgba());
3470  addButton.setColor(4, gradientStopColor.rgba());
3471  } else {
3472  addButton.setColor(3, gradientStartColor.lighter(105).rgba());
3473  addButton.setColor(4, gradientStopColor.rgba());
3474  }
3475  addButton.setColor(5, scrollBar->palette.text().color().rgba());
3476  addLinePainter.drawImage(pixmapRect, addButton);
3477 
3478  // Arrow
3479  if (horizontal) {
3481  arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3482 
3483  if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
3484  addLinePainter.translate(1, 1);
3485  addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
3486  } else {
3488  arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3489 
3490  if ((scrollBar->activeSubControls & SC_ScrollBarAddLine) && sunken)
3491  addLinePainter.translate(1, 1);
3492  addLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
3493  }
3494  addLinePainter.end();
3495  QPixmapCache::insert(addLinePixmapName, cache);
3496  }
3497  painter->drawPixmap(option->rect.topLeft(), cache);
3498  }
3499  break;
3500  case CE_ScrollBarSubPage:
3501  case CE_ScrollBarAddPage:
3502  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3503  bool sunken = scrollBar->state & State_Sunken;
3504  bool horizontal = scrollBar->orientation == Qt::Horizontal;
3505 
3506  QString groovePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_groove"), option, option->rect.size());
3507  if (sunken)
3508  groovePixmapName += QLatin1String("-sunken");
3509  if (element == CE_ScrollBarAddPage)
3510  groovePixmapName += QLatin1String("-addpage");
3511 
3512  QPixmap cache;
3513  if (!QPixmapCache::find(groovePixmapName, cache)) {
3514  cache = QPixmap(option->rect.size());
3515  cache.fill(option->palette.background().color());
3516  QPainter groovePainter(&cache);
3517  QRect pixmapRect = QRect(0, 0, option->rect.width(), option->rect.height());
3518  QColor color = scrollBar->palette.base().color().darker(sunken ? 125 : 100);
3519  groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 0,
3520  (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 0);
3521  groovePainter.fillRect(pixmapRect, QBrush(color, Qt::Dense4Pattern));
3522 
3523  QColor edgeColor = scrollBar->palette.base().color().darker(125);
3524  if (horizontal) {
3525  groovePainter.setBrushOrigin((element == CE_ScrollBarAddPage) ? pixmapRect.width() : 1, 0);
3526  groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(pixmapRect.width(), 1)),
3527  QBrush(edgeColor, Qt::Dense4Pattern));
3528  groovePainter.fillRect(QRect(pixmapRect.bottomLeft(), QSize(pixmapRect.width(), 1)),
3529  QBrush(edgeColor, Qt::Dense4Pattern));
3530  } else {
3531  groovePainter.setBrushOrigin(0, (element == CE_ScrollBarAddPage) ? pixmapRect.height() : 1);
3532  groovePainter.fillRect(QRect(pixmapRect.topLeft(), QSize(1, pixmapRect.height())),
3533  QBrush(edgeColor, Qt::Dense4Pattern));
3534  groovePainter.fillRect(QRect(pixmapRect.topRight(), QSize(1, pixmapRect.height())),
3535  QBrush(edgeColor, Qt::Dense4Pattern));
3536  }
3537 
3538  groovePainter.end();
3539  QPixmapCache::insert(groovePixmapName, cache);
3540  }
3541  painter->drawPixmap(option->rect.topLeft(), cache);
3542  }
3543  break;
3544  case CE_ScrollBarSubLine:
3545  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3546  QRect scrollBarSubLine = scrollBar->rect;
3547 
3548  bool horizontal = scrollBar->orientation == Qt::Horizontal;
3549  bool isEnabled = scrollBar->state & State_Enabled;
3550  bool reverse = scrollBar->direction == Qt::RightToLeft;
3551  bool sunken = scrollBar->state & State_Sunken;
3552 
3553  // The SubLine (up/left) buttons
3554  QRect button1;
3555  QRect button2;
3556  int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
3557  if (horizontal) {
3558  button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
3559  button2.setRect(scrollBarSubLine.right() - (scrollBarExtent - 1), scrollBarSubLine.top(), scrollBarExtent, scrollBarSubLine.height());
3560  } else {
3561  button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(), scrollBarSubLine.width(), scrollBarExtent);
3562  button2.setRect(scrollBarSubLine.left(), scrollBarSubLine.bottom() - (scrollBarExtent - 1), scrollBarSubLine.width(), scrollBarExtent);
3563  }
3564 
3565  QString subLinePixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_subline"), option, button1.size());
3566  QPixmap cache;
3567  if (!QPixmapCache::find(subLinePixmapName, cache)) {
3568  cache = QPixmap(button1.size());
3569  cache.fill(Qt::white);
3570  QRect pixmapRect(0, 0, cache.width(), cache.height());
3571  QPainter subLinePainter(&cache);
3572  subLinePainter.fillRect(pixmapRect, option->palette.background());
3573 
3574  if (isEnabled) {
3575  // Gradients
3576  if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3577  qt_plastique_draw_gradient(&subLinePainter,
3578  QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3579  pixmapRect.right() - 3, pixmapRect.bottom() - 3),
3580  gradientStopColor,
3581  gradientStopColor);
3582  } else {
3583  qt_plastique_draw_gradient(&subLinePainter,
3584  QRect(pixmapRect.left() + 2, pixmapRect.top() + 2,
3585  pixmapRect.right() - 3, pixmapRect.bottom() - 3),
3586  gradientStartColor.lighter(105),
3587  gradientStopColor);
3588  }
3589  }
3590 
3591  // Details
3592  QImage subButton;
3593  if (horizontal) {
3595  } else {
3596  subButton = QImage(qt_scrollbar_button_up);
3597  }
3598  subButton.setColor(1, alphaCornerColor.rgba());
3599  subButton.setColor(2, borderColor.rgba());
3600  if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken) {
3601  subButton.setColor(3, gradientStopColor.rgba());
3602  subButton.setColor(4, gradientStopColor.rgba());
3603  } else {
3604  subButton.setColor(3, gradientStartColor.lighter(105).rgba());
3605  subButton.setColor(4, gradientStopColor.rgba());
3606  }
3607  subButton.setColor(5, scrollBar->palette.text().color().rgba());
3608  subLinePainter.drawImage(pixmapRect, subButton);
3609 
3610  // Arrows
3611  if (horizontal) {
3613  arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3614 
3615  if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
3616  subLinePainter.translate(1, 1);
3617  subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 2, pixmapRect.center().y() - 3), arrow);
3618  } else {
3620  arrow.setColor(1, scrollBar->palette.foreground().color().rgba());
3621 
3622  if ((scrollBar->activeSubControls & SC_ScrollBarSubLine) && sunken)
3623  subLinePainter.translate(1, 1);
3624  subLinePainter.drawImage(QPoint(pixmapRect.center().x() - 3, pixmapRect.center().y() - 2), arrow);
3625  }
3626  subLinePainter.end();
3627  QPixmapCache::insert(subLinePixmapName, cache);
3628  }
3629  painter->drawPixmap(button1.topLeft(), cache);
3630  painter->drawPixmap(button2.topLeft(), cache);
3631  }
3632  break;
3633  case CE_ScrollBarSlider:
3634  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3635  bool horizontal = scrollBar->orientation == Qt::Horizontal;
3636  bool isEnabled = scrollBar->state & State_Enabled;
3637 
3638  // The slider
3639  if (option->rect.isValid()) {
3640  QString sliderPixmapName = QStyleHelper::uniqueName(QLatin1String("scrollbar_slider"), option, option->rect.size());
3641  if (horizontal)
3642  sliderPixmapName += QLatin1String("-horizontal");
3643 
3644  QPixmap cache;
3645  if (!QPixmapCache::find(sliderPixmapName, cache)) {
3646  cache = QPixmap(option->rect.size());
3647  cache.fill(Qt::white);
3648  QRect pixmapRect(0, 0, cache.width(), cache.height());
3649  QPainter sliderPainter(&cache);
3650  bool sunken = (scrollBar->state & State_Sunken);
3651 
3652  if (isEnabled) {
3653  QLinearGradient gradient(pixmapRect.left(), pixmapRect.center().y(),
3654  pixmapRect.right(), pixmapRect.center().y());
3655  if (horizontal)
3656  gradient = QLinearGradient(pixmapRect.center().x(), pixmapRect.top(),
3657  pixmapRect.center().x(), pixmapRect.bottom());
3658 
3659  if (sunken) {
3660  gradient.setColorAt(0, gradientStartColor.lighter(110));
3661  gradient.setColorAt(1, gradientStopColor.lighter(105));
3662  } else {
3663  gradient.setColorAt(0, gradientStartColor.lighter(105));
3664  gradient.setColorAt(1, gradientStopColor);
3665  }
3666  sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), gradient);
3667  } else {
3668  sliderPainter.fillRect(pixmapRect.adjusted(2, 2, -2, -2), option->palette.background());
3669  }
3670 
3671  sliderPainter.setPen(borderColor);
3672  sliderPainter.drawRect(pixmapRect.adjusted(0, 0, -1, -1));
3673  sliderPainter.setPen(alphaCornerColor);
3674  QPoint points[4] = {
3675  QPoint(pixmapRect.left(), pixmapRect.top()),
3676  QPoint(pixmapRect.left(), pixmapRect.bottom()),
3677  QPoint(pixmapRect.right(), pixmapRect.top()),
3678  QPoint(pixmapRect.right(), pixmapRect.bottom()) };
3679  sliderPainter.drawPoints(points, 4);
3680 
3681  QLine lines[2];
3682  sliderPainter.setPen(sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105));
3683  lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 1,
3684  pixmapRect.right() - 1, pixmapRect.top() + 1);
3685  lines[1] = QLine(pixmapRect.left() + 1, pixmapRect.top() + 2,
3686  pixmapRect.left() + 1, pixmapRect.bottom() - 2);
3687  sliderPainter.drawLines(lines, 2);
3688 
3689  sliderPainter.setPen(sunken ? gradientStopColor.lighter(105) : gradientStopColor);
3690  lines[0] = QLine(pixmapRect.left() + 1, pixmapRect.bottom() - 1,
3691  pixmapRect.right() - 1, pixmapRect.bottom() - 1);
3692  lines[1] = QLine(pixmapRect.right() - 1, pixmapRect.top() + 2,
3693  pixmapRect.right() - 1, pixmapRect.bottom() - 1);
3694  sliderPainter.drawLines(lines, 2);
3695 
3696  int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
3697  if ((horizontal && scrollBar->rect.width() > sliderMinLength)
3698  || (!horizontal && scrollBar->rect.height() > sliderMinLength)) {
3699  QImage pattern(horizontal ? qt_scrollbar_slider_pattern_horizontal
3701  pattern.setColor(1, alphaCornerColor.rgba());
3702  pattern.setColor(2, (sunken ? gradientStartColor.lighter(110) : gradientStartColor.lighter(105)).rgba());
3703 
3704  if (horizontal) {
3705  sliderPainter.drawImage(pixmapRect.center().x() - pattern.width() / 2 + 1,
3706  pixmapRect.center().y() - 4,
3707  pattern);
3708  } else {
3709  sliderPainter.drawImage(pixmapRect.center().x() - 4,
3710  pixmapRect.center().y() - pattern.height() / 2 + 1,
3711  pattern);
3712  }
3713  }
3714  sliderPainter.end();
3715  // insert the slider into the cache
3716  QPixmapCache::insert(sliderPixmapName, cache);
3717  }
3718  painter->drawPixmap(option->rect.topLeft(), cache);
3719  }
3720  }
3721  break;
3722 #endif
3723 #ifndef QT_NO_COMBOBOX
3724  case CE_ComboBoxLabel:
3725  if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
3726  painter->save();
3727  if (!comboBox->editable) {
3728  // Plastique's non-editable combo box is drawn as a button, so
3729  // we need the label to be drawn using ButtonText where it
3730  // would usually use Text.
3731  painter->setPen(QPen(comboBox->palette.buttonText(), 0));
3732  QWindowsStyle::drawControl(element, option, painter, widget);
3733  } else if (!comboBox->currentIcon.isNull()) {
3734  {
3735  QRect editRect = proxy()->subControlRect(CC_ComboBox, comboBox, SC_ComboBoxEditField, widget);
3736  if (comboBox->direction == Qt::RightToLeft)
3737  editRect.adjust(0, 2, -2, -2);
3738  else
3739  editRect.adjust(2, 2, 0, -2);
3740  painter->save();
3741  painter->setClipRect(editRect);
3742  if (!comboBox->currentIcon.isNull()) {
3743  QIcon::Mode mode = comboBox->state & State_Enabled ? QIcon::Normal
3744  : QIcon::Disabled;
3745  QPixmap pixmap = comboBox->currentIcon.pixmap(comboBox->iconSize, mode);
3746  QRect iconRect(editRect);
3747  iconRect.setWidth(comboBox->iconSize.width() + 5);
3748  iconRect = alignedRect(comboBox->direction,
3750  iconRect.size(), editRect);
3751  painter->fillRect(iconRect, option->palette.brush(QPalette::Base));
3752  proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pixmap);
3753  }
3754  painter->restore();
3755  }
3756  } else {
3757  QWindowsStyle::drawControl(element, option, painter, widget);
3758  }
3759 
3760  painter->restore();
3761  }
3762  break;
3763 #endif
3764  default:
3765  QWindowsStyle::drawControl(element, option, painter, widget);
3766  break;
3767  }
3768 }
3769 
3774  QPainter *painter, const QWidget *widget) const
3775 {
3776  QColor borderColor = option->palette.background().color().darker(178);
3777  QColor alphaCornerColor;
3778  if (widget) {
3779  // ### backgroundrole/foregroundrole should be part of the style option
3780  alphaCornerColor = mergedColors(option->palette.color(widget->backgroundRole()), borderColor);
3781  } else {
3782  alphaCornerColor = mergedColors(option->palette.background().color(), borderColor);
3783  }
3784  QColor gradientStartColor = option->palette.button().color().lighter(104);
3785  QColor gradientStopColor = option->palette.button().color().darker(105);
3786 
3787  switch (control) {
3788 #ifndef QT_NO_SLIDER
3789  case CC_Slider:
3790  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
3791  QRect grooveRegion = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
3792  QRect handle = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
3793  bool horizontal = slider->orientation == Qt::Horizontal;
3794  bool ticksAbove = slider->tickPosition & QSlider::TicksAbove;
3795  bool ticksBelow = slider->tickPosition & QSlider::TicksBelow;
3796 
3797  QRect groove;
3798  //The clickable region is 5 px wider than the visible groove for improved usability
3799  if (grooveRegion.isValid())
3800  groove = horizontal ? grooveRegion.adjusted(0, 5, 0, -5) : grooveRegion.adjusted(5, 0, -5, 0);
3801 
3802 
3803  QPixmap cache;
3804 
3805  if ((option->subControls & SC_SliderGroove) && groove.isValid()) {
3806  BEGIN_STYLE_PIXMAPCACHE(QString::fromLatin1("slider_groove-%0-%1").arg(ticksAbove).arg(ticksBelow))
3807  p->fillRect(groove, option->palette.background());
3808 
3809  // draw groove
3810  if (horizontal) {
3811  p->setPen(borderColor);
3812  const QLine lines[4] = {
3813  QLine(groove.left() + 1, groove.top(),
3814  groove.right() - 1, groove.top()),
3815  QLine(groove.left() + 1, groove.bottom(),
3816  groove.right() - 1, groove.bottom()),
3817  QLine(groove.left(), groove.top() + 1,
3818  groove.left(), groove.bottom() - 1),
3819  QLine(groove.right(), groove.top() + 1,
3820  groove.right(), groove.bottom() - 1) };
3821  p->drawLines(lines, 4);
3822 
3823  p->setPen(alphaCornerColor);
3824  const QPoint points[4] = {
3825  QPoint(groove.left(), groove.top()),
3826  QPoint(groove.left(), groove.bottom()),
3827  QPoint(groove.right(), groove.top()),
3828  QPoint(groove.right(), groove.bottom()) };
3829  p->drawPoints(points, 4);
3830  } else {
3831  p->setPen(borderColor);
3832  const QLine lines[4] = {
3833  QLine(groove.left() + 1, groove.top(),
3834  groove.right() - 1, groove.top()),
3835  QLine(groove.left() + 1, groove.bottom(),
3836  groove.right() - 1, groove.bottom()),
3837  QLine(groove.left(), groove.top() + 1,
3838  groove.left(), groove.bottom() - 1),
3839  QLine(groove.right(), groove.top() + 1,
3840  groove.right(), groove.bottom() - 1) };
3841  p->drawLines(lines, 4);
3842 
3843  p->setPen(alphaCornerColor);
3844  const QPoint points[4] = {
3845  QPoint(groove.left(), groove.top()),
3846  QPoint(groove.right(), groove.top()),
3847  QPoint(groove.left(), groove.bottom()),
3848  QPoint(groove.right(), groove.bottom()) };
3849  p->drawPoints(points, 4);
3850  }
3852  }
3853 
3854  if ((option->subControls & SC_SliderHandle) && handle.isValid()) {
3855  QString handlePixmapName = QStyleHelper::uniqueName(QLatin1String("slider_handle"), option, handle.size());
3856  if (ticksAbove && !ticksBelow)
3857  handlePixmapName += QLatin1String("-flipped");
3858  if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken))
3859  handlePixmapName += QLatin1String("-sunken");
3860 
3861  if (!QPixmapCache::find(handlePixmapName, cache)) {
3862  cache = QPixmap(handle.size());
3863  cache.fill(Qt::white);
3864  QRect pixmapRect(0, 0, handle.width(), handle.height());
3865  QPainter handlePainter(&cache);
3866  handlePainter.fillRect(pixmapRect, option->palette.background());
3867 
3868  // draw handle
3869  if (horizontal) {
3870  QPainterPath path;
3871  if (ticksAbove && !ticksBelow) {
3872  path.moveTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3873  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom() - 10));
3874  path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.bottom() - 14));
3875  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom() - 10));
3876  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
3877  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3878  } else {
3879  path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3880  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 10));
3881  path.lineTo(QPoint(pixmapRect.right() - 5, pixmapRect.top() + 14));
3882  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 10));
3883  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3884  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3885  }
3886  if (slider->state & State_Enabled) {
3887  QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3888  pixmapRect.center().x(), pixmapRect.bottom());
3889  if ((option->activeSubControls & SC_SliderHandle) && (option->state & State_Sunken)) {
3890  gradient.setColorAt(0, gradientStartColor.lighter(110));
3891  gradient.setColorAt(1, gradientStopColor.lighter(110));
3892  } else {
3893  gradient.setColorAt(0, gradientStartColor);
3894  gradient.setColorAt(1, gradientStopColor);
3895  }
3896  handlePainter.fillPath(path, gradient);
3897  } else {
3898  handlePainter.fillPath(path, slider->palette.background());
3899  }
3900  } else {
3901  QPainterPath path;
3902  if (ticksAbove && !ticksBelow) {
3903  path.moveTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3904  path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.top() + 1));
3905  path.lineTo(QPoint(pixmapRect.right() - 14, pixmapRect.top() + 5));
3906  path.lineTo(QPoint(pixmapRect.right() - 10, pixmapRect.bottom()));
3907  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.bottom()));
3908  path.lineTo(QPoint(pixmapRect.right(), pixmapRect.top() + 1));
3909  } else {
3910  path.moveTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3911  path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.top() + 1));
3912  path.lineTo(QPoint(pixmapRect.left() + 14, pixmapRect.top() + 5));
3913  path.lineTo(QPoint(pixmapRect.left() + 10, pixmapRect.bottom()));
3914  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.bottom()));
3915  path.lineTo(QPoint(pixmapRect.left() + 1, pixmapRect.top() + 1));
3916  }
3917  if (slider->state & State_Enabled) {
3918  QLinearGradient gradient(pixmapRect.center().x(), pixmapRect.top(),
3919  pixmapRect.center().x(), pixmapRect.bottom());
3920  gradient.setColorAt(0, gradientStartColor);
3921  gradient.setColorAt(1, gradientStopColor);
3922  handlePainter.fillPath(path, gradient);
3923  } else {
3924  handlePainter.fillPath(path, slider->palette.background());
3925  }
3926  }
3927 
3928  QImage image;
3929  if (horizontal) {
3931  } else {
3933  }
3934 
3935  image.setColor(1, borderColor.rgba());
3936  image.setColor(2, gradientStartColor.rgba());
3937  image.setColor(3, alphaCornerColor.rgba());
3938  if (option->state & State_Enabled) {
3939  image.setColor(4, 0x80ffffff);
3940  image.setColor(5, 0x25000000);
3941  }
3942  handlePainter.drawImage(pixmapRect, image);
3943  handlePainter.end();
3944  QPixmapCache::insert(handlePixmapName, cache);
3945  }
3946 
3947  painter->drawPixmap(handle.topLeft(), cache);
3948 
3949  if (slider->state & State_HasFocus) {
3950  QStyleOptionFocusRect fropt;
3951  fropt.QStyleOption::operator=(*slider);
3952  fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
3953  proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
3954  }
3955  }
3956 
3957  if (option->subControls & SC_SliderTickmarks) {
3958  QPen oldPen = painter->pen();
3959  painter->setPen(borderColor);
3960  int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
3961  int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3962  int interval = slider->tickInterval;
3963  if (interval <= 0) {
3964  interval = slider->singleStep;
3965  if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3966  available)
3967  - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3968  0, available) < 3)
3969  interval = slider->pageStep;
3970  }
3971  if (interval <= 0)
3972  interval = 1;
3973 
3974  int v = slider->minimum;
3975  int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3977  while (v <= slider->maximum + 1) {
3978  if (v == slider->maximum + 1 && interval == 1)
3979  break;
3980  const int v_ = qMin(v, slider->maximum);
3981  int pos = sliderPositionFromValue(slider->minimum, slider->maximum,
3982  v_, (horizontal
3983  ? slider->rect.width()
3984  : slider->rect.height()) - len,
3985  slider->upsideDown) + len / 2;
3986 
3987  int extra = 2 - ((v_ == slider->minimum || v_ == slider->maximum) ? 1 : 0);
3988 
3989  if (horizontal) {
3990  if (ticksAbove) {
3991  lines.append(QLine(pos, slider->rect.top() + extra,
3992  pos, slider->rect.top() + tickSize));
3993  }
3994  if (ticksBelow) {
3995  lines.append(QLine(pos, slider->rect.bottom() - extra,
3996  pos, slider->rect.bottom() - tickSize));
3997  }
3998  } else {
3999  if (ticksAbove) {
4000  lines.append(QLine(slider->rect.left() + extra, pos,
4001  slider->rect.left() + tickSize, pos));
4002  }
4003  if (ticksBelow) {
4004  lines.append(QLine(slider->rect.right() - extra, pos,
4005  slider->rect.right() - tickSize, pos));
4006  }
4007  }
4008 
4009  // in the case where maximum is max int
4010  int nextInterval = v + interval;
4011  if (nextInterval < v)
4012  break;
4013  v = nextInterval;
4014  }
4015  painter->drawLines(lines.constData(), lines.size());
4016  painter->setPen(oldPen);
4017  }
4018  }
4019  break;
4020 #endif // QT_NO_SLIDER
4021 #ifndef QT_NO_SPINBOX
4022  case CC_SpinBox:
4023  if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
4024  painter->save();
4025  bool upSunken = (spinBox->activeSubControls & SC_SpinBoxUp) && (spinBox->state & (State_Sunken | State_On));
4026  bool downSunken = (spinBox->activeSubControls & SC_SpinBoxDown) && (spinBox->state & (State_Sunken | State_On));
4027  bool reverse = (spinBox->direction == Qt::RightToLeft);
4028 
4029  // Rects
4030  QRect upRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget);
4031  QRect downRect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
4032  QRect buttonRect = upRect | downRect;
4033 
4034  // Brushes
4035  QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4036  qBrushSetAlphaF(&corner, qreal(0.25));
4037  QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
4038  qBrushSetAlphaF(&border, qreal(0.4));
4039 
4041 
4042  Q_D(const QPlastiqueStyle);
4043  if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4044  QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
4045  QBrush baseBrush = qMapBrushToRect(option->palette.base(), filledRect);
4046  painter->setBrushOrigin(filledRect.topLeft());
4047  painter->fillRect(filledRect.adjusted(1, 1, -1, -1), baseBrush);
4048  qt_plastique_draw_frame(painter, option->rect, option, QFrame::Sunken);
4049  } else {
4050  d->drawPartialFrame(painter,
4051  option,
4052  proxy()->subControlRect(CC_SpinBox, spinBox, SC_SpinBoxEditField, widget),
4053  widget);
4054  }
4055  // Paint buttons
4056  if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4057  painter->restore();
4058  break;
4059  }
4060  // Button outlines
4061  painter->setPen(QPen(border, 0));
4062  if (!reverse)
4063  painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
4064  else
4065  painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));
4066 
4067  if (!reverse) {
4068  const QLine lines[4] = {
4069  QLine(upRect.left(), upRect.top(), upRect.right() - 2, upRect.top()),
4070  QLine(upRect.left() + 1, upRect.bottom(), upRect.right() - 1, upRect.bottom()),
4071  QLine(downRect.left(), downRect.bottom(), downRect.right() - 2, downRect.bottom()),
4072  QLine(buttonRect.right(), buttonRect.top() + 2, buttonRect.right(), buttonRect.bottom() - 2) };
4073  painter->drawLines(lines, 4);
4074 
4075  points.append(QPoint(upRect.right() - 1, upRect.top() + 1));
4076  points.append(QPoint(downRect.right() - 1, downRect.bottom() - 1));
4077  painter->drawPoints(points.constData(), points.size());
4078  points.clear();
4079  painter->setPen(QPen(corner, 0));
4080  points.append(QPoint(upRect.right() - 1, upRect.top()));
4081  points.append(QPoint(upRect.right(), upRect.top() + 1));
4082  points.append(QPoint(upRect.right(), downRect.bottom() - 1));
4083  points.append(QPoint(upRect.right() - 1, downRect.bottom()));
4084  } else {
4085  const QLine lines[4] = {
4086  QLine(upRect.right(), upRect.top(), upRect.left() + 2, upRect.top()),
4087  QLine(upRect.right() - 1, upRect.bottom(), upRect.left() + 1, upRect.bottom()),
4088  QLine(downRect.right(), downRect.bottom(), downRect.left() + 2, downRect.bottom()),
4089  QLine(buttonRect.left(), buttonRect.top() + 2, buttonRect.left(), buttonRect.bottom() - 2) };
4090  painter->drawLines(lines, 4);
4091 
4092  points.append(QPoint(upRect.left() + 1, upRect.top() + 1));
4093  points.append(QPoint(downRect.left() + 1, downRect.bottom() - 1));
4094  painter->drawPoints(points.constData(), points.size());
4095  points.clear();
4096  painter->setPen(QPen(corner, 0));
4097  points.append(QPoint(upRect.left() + 1, upRect.top()));
4098  points.append(QPoint(upRect.left(), upRect.top() + 1));
4099  points.append(QPoint(upRect.left(), downRect.bottom() - 1));
4100  points.append(QPoint(upRect.left() + 1, downRect.bottom()));
4101  }
4102  painter->drawPoints(points.constData(), points.size());
4103  points.clear();
4104 
4105  // Button colors
4106  QBrush buttonGradientBrush;
4107  QBrush leftLineGradientBrush;
4108  QBrush rightLineGradientBrush;
4109  QBrush sunkenButtonGradientBrush;
4110  QBrush sunkenLeftLineGradientBrush;
4111  QBrush sunkenRightLineGradientBrush;
4112  QBrush buttonBrush = qMapBrushToRect(option->palette.button(), buttonRect);
4113  if (buttonBrush.gradient() || !buttonBrush.texture().isNull()) {
4114  buttonGradientBrush = buttonBrush;
4115  sunkenButtonGradientBrush = qBrushDark(buttonBrush, 108);
4116  leftLineGradientBrush = qBrushLight(buttonBrush, 105);
4117  rightLineGradientBrush = qBrushDark(buttonBrush, 105);
4118  sunkenLeftLineGradientBrush = qBrushDark(buttonBrush, 110);
4119  sunkenRightLineGradientBrush = qBrushDark(buttonBrush, 106);
4120  } else {
4121  // Generate gradients
4122  QLinearGradient buttonGradient(buttonRect.topLeft(), buttonRect.bottomLeft());
4123  buttonGradient.setColorAt(0.0, buttonBrush.color().lighter(104));
4124  buttonGradient.setColorAt(1.0, buttonBrush.color().darker(110));
4125  buttonGradientBrush = QBrush(buttonGradient);
4126 
4127  QLinearGradient buttonGradient2(buttonRect.topLeft(), buttonRect.bottomLeft());
4128  buttonGradient2.setColorAt(0.0, buttonBrush.color().darker(113));
4129  buttonGradient2.setColorAt(1.0, buttonBrush.color().darker(103));
4130  sunkenButtonGradientBrush = QBrush(buttonGradient2);
4131 
4132  QLinearGradient buttonGradient3(buttonRect.topLeft(), buttonRect.bottomLeft());
4133  buttonGradient3.setColorAt(0.0, buttonBrush.color().lighter(105));
4134  buttonGradient3.setColorAt(1.0, buttonBrush.color());
4135  leftLineGradientBrush = QBrush(buttonGradient3);
4136 
4137  QLinearGradient buttonGradient4(buttonRect.topLeft(), buttonRect.bottomLeft());
4138  buttonGradient4.setColorAt(0.0, buttonBrush.color());
4139  buttonGradient4.setColorAt(1.0, buttonBrush.color().darker(110));
4140  rightLineGradientBrush = QBrush(buttonGradient4);
4141 
4142  QLinearGradient buttonGradient5(buttonRect.topLeft(), buttonRect.bottomLeft());
4143  buttonGradient5.setColorAt(0.0, buttonBrush.color().darker(113));
4144  buttonGradient5.setColorAt(1.0, buttonBrush.color().darker(107));
4145  sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
4146 
4147  QLinearGradient buttonGradient6(buttonRect.topLeft(), buttonRect.bottomLeft());
4148  buttonGradient6.setColorAt(0.0, buttonBrush.color().darker(108));
4149  buttonGradient6.setColorAt(1.0, buttonBrush.color().darker(103));
4150  sunkenRightLineGradientBrush = QBrush(buttonGradient6);
4151  }
4152 
4153  // Main fill
4154  painter->fillRect(upRect.adjusted(2, 2, -2, -2),
4155  qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4156  : buttonGradientBrush, upRect));
4157  painter->fillRect(downRect.adjusted(2, 2, -2, -2),
4158  qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4159  : buttonGradientBrush, downRect));
4160 
4161  // Top line
4162  painter->setPen(QPen(qBrushLight(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4163  : buttonGradientBrush, upRect), 105), 0));
4164  if (!reverse) {
4165  painter->drawLine(upRect.left() + 1, upRect.top() + 1,
4166  upRect.right() - 2, upRect.top() + 1);
4167  } else {
4168  painter->drawLine(upRect.right() - 1, upRect.top() + 1,
4169  upRect.left() + 2, upRect.top() + 1);
4170  }
4171  painter->setPen(QPen(qBrushLight(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4172  : buttonGradientBrush, downRect), 105), 0));
4173  if (!reverse) {
4174  painter->drawLine(downRect.left() + 1, downRect.top() + 1,
4175  downRect.right() - 1, downRect.top() + 1);
4176  } else {
4177  painter->drawLine(downRect.right() - 1, downRect.top() + 1,
4178  downRect.left() + 1, downRect.top() + 1);
4179  }
4180 
4181  // Left line
4182  painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenLeftLineGradientBrush
4183  : leftLineGradientBrush, upRect), 1));
4184  if (!reverse) {
4185  painter->drawLine(upRect.left() + 1, upRect.top() + 2,
4186  upRect.left() + 1, upRect.bottom() - 1);
4187  } else {
4188  painter->drawLine(upRect.left() + 1, upRect.top() + 2,
4189  upRect.left() + 1, upRect.bottom() - 1);
4190  }
4191  painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenLeftLineGradientBrush
4192  : leftLineGradientBrush, downRect), 1));
4193  if (!reverse) {
4194  painter->drawLine(downRect.left() + 1, downRect.top() + 2,
4195  downRect.left() + 1, downRect.bottom() - 1);
4196  } else {
4197  painter->drawLine(downRect.left() + 1, downRect.top() + 1,
4198  downRect.left() + 1, downRect.bottom() - 2);
4199  }
4200 
4201  // Bottom line
4202  painter->setPen(QPen(qBrushDark(qMapBrushToRect(upSunken ? sunkenButtonGradientBrush
4203  : buttonGradientBrush, upRect), 105), 0));
4204  if (!reverse) {
4205  painter->drawLine(upRect.left() + 2, upRect.bottom() - 1,
4206  upRect.right() - 1, upRect.bottom() - 1);
4207  } else {
4208  painter->drawLine(upRect.right() - 2, upRect.bottom() - 1,
4209  upRect.left() + 1, upRect.bottom() - 1);
4210  }
4211  painter->setPen(QPen(qBrushDark(qMapBrushToRect(downSunken ? sunkenButtonGradientBrush
4212  : buttonGradientBrush, downRect), 105), 0));
4213  if (!reverse) {
4214  painter->drawLine(downRect.left() + 2, downRect.bottom() - 1,
4215  downRect.right() - 2, downRect.bottom() - 1);
4216  } else {
4217  painter->drawLine(downRect.right() - 2, downRect.bottom() - 1,
4218  downRect.left() + 2, downRect.bottom() - 1);
4219  }
4220 
4221  // Right line
4222  painter->setPen(QPen(qMapBrushToRect(upSunken ? sunkenRightLineGradientBrush
4223  : rightLineGradientBrush, upRect), 1));
4224  if (!reverse) {
4225  painter->drawLine(upRect.right() - 1, upRect.top() + 2,
4226  upRect.right() - 1, upRect.bottom() - 1);
4227  } else {
4228  painter->drawLine(upRect.right() - 1, upRect.top() + 2,
4229  upRect.right() - 1, upRect.bottom() - 1);
4230  }
4231  painter->setPen(QPen(qMapBrushToRect(downSunken ? sunkenRightLineGradientBrush
4232  : rightLineGradientBrush, downRect), 1));
4233  if (!reverse) {
4234  painter->drawLine(downRect.right() - 1, downRect.top() + 1,
4235  downRect.right() - 1, downRect.bottom() - 2);
4236  } else {
4237  painter->drawLine(downRect.right() - 1, downRect.top() + 2,
4238  downRect.right() - 1, downRect.bottom() - 1);
4239  }
4240 
4241  QBrush indicatorBrush = qMapBrushToRect(option->palette.buttonText(), buttonRect);
4242  painter->setPen(QPen(indicatorBrush, 0));
4243  if (spinBox->buttonSymbols == QAbstractSpinBox::PlusMinus) {
4244  QPoint center;
4245  if (spinBox->subControls & SC_SpinBoxUp) {
4246  // .......
4247  // ...X...
4248  // ...X...
4249  // .XXXXX.
4250  // ...X...
4251  // ...X...
4252  // .......
4253  center = upRect.center();
4254  if (upSunken) {
4255  ++center.rx();
4256  ++center.ry();
4257  }
4258  painter->drawLine(center.x(), center.y() - 2, center.x(), center.y() + 2);
4259  painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
4260  }
4261  if (spinBox->subControls & SC_SpinBoxDown) {
4262  // .......
4263  // .......
4264  // .......
4265  // .XXXXX.
4266  // .......
4267  // .......
4268  // .......
4269  center = downRect.center();
4270  if (downSunken) {
4271  ++center.rx();
4272  ++center.ry();
4273  }
4274  painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y());
4275  }
4276  } else {
4277  int offset;
4278  int centerX;
4279  if (spinBox->subControls & SC_SpinBoxUp) {
4280  // ...........
4281  // .....X.....
4282  // ....XXX....
4283  // ...XXXXX...
4284  // ..XXXXXXX..
4285  // ...........
4286  offset = upSunken ? 1 : 0;
4287  QRect upArrowRect(upRect.center().x() - 3 + offset, upRect.center().y() - 2 + offset, 7, 4);
4288  centerX = upArrowRect.center().x();
4289  painter->drawPoint(centerX, upArrowRect.top());
4290  const QLine lines[3] = {
4291  QLine(centerX - 1, upArrowRect.top() + 1, centerX + 1, upArrowRect.top() + 1),
4292  QLine(centerX - 2, upArrowRect.top() + 2, centerX + 2, upArrowRect.top() + 2),
4293  QLine(centerX - 3, upArrowRect.top() + 3, centerX + 3, upArrowRect.top() + 3) };
4294  painter->drawLines(lines, 3);
4295  }
4296  if (spinBox->subControls & SC_SpinBoxDown) {
4297  // ...........
4298  // ..XXXXXXX..
4299  // ...XXXXX...
4300  // ....XXX....
4301  // .....X.....
4302  // ...........
4303  offset = downSunken ? 1 : 0;
4304  QRect downArrowRect(downRect.center().x() - 3 + offset, downRect.center().y() - 2 + offset + 1, 7, 4);
4305  centerX = downArrowRect.center().x();
4306  const QLine lines[3] = {
4307  QLine(centerX - 3, downArrowRect.top(), centerX + 3, downArrowRect.top()),
4308  QLine(centerX - 2, downArrowRect.top() + 1, centerX + 2, downArrowRect.top() + 1),
4309  QLine(centerX - 1, downArrowRect.top() + 2, centerX + 1, downArrowRect.top() + 2) };
4310  painter->drawLines(lines, 3);
4311  painter->drawPoint(centerX, downArrowRect.top() + 3);
4312  }
4313  }
4314  painter->restore();
4315  }
4316  break;
4317 #endif // QT_NO_SPINBOX
4318 #ifndef QT_NO_COMBOBOX
4319  case CC_ComboBox:
4320  if (const QStyleOptionComboBox *comboBox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
4321  bool sunken = comboBox->state & State_On; // play dead if combobox has no items
4322  bool reverse = comboBox->direction == Qt::RightToLeft;
4323  int menuButtonWidth = 16;
4324  int xoffset = sunken ? (reverse ? -1 : 1) : 0;
4325  int yoffset = sunken ? 1 : 0;
4326  QRect rect = comboBox->rect;
4327  QPen oldPen = painter->pen();
4328 
4329  // Fill
4330  if (comboBox->editable) {
4331  // Button colors
4332  QBrush alphaCornerBrush = qBrushDark(option->palette.button(), 165);
4333  qBrushSetAlphaF(&alphaCornerBrush, 0.5);
4334  QBrush buttonGradientBrush;
4335  QBrush leftLineGradientBrush;
4336  QBrush rightLineGradientBrush;
4337  QBrush sunkenButtonGradientBrush;
4338  QBrush sunkenLeftLineGradientBrush;
4339  QBrush sunkenRightLineGradientBrush;
4340  QBrush button = option->palette.button();
4341  if (button.gradient() || !button.texture().isNull()) {
4342  buttonGradientBrush = button;
4343  sunkenButtonGradientBrush = qBrushDark(button, 108);
4344  leftLineGradientBrush = qBrushLight(button, 105);
4345  rightLineGradientBrush = qBrushDark(button, 105);
4346  sunkenLeftLineGradientBrush = qBrushDark(button, 110);
4347  sunkenRightLineGradientBrush = qBrushDark(button, 106);
4348  } else {
4349  // Generate gradients
4350  QLinearGradient buttonGradient(option->rect.topLeft(), option->rect.bottomLeft());
4351  buttonGradient.setColorAt(0.0, button.color().lighter(104));
4352  buttonGradient.setColorAt(1.0, button.color().darker(110));
4353  buttonGradientBrush = QBrush(buttonGradient);
4354 
4355  QLinearGradient buttonGradient2(option->rect.topLeft(), option->rect.bottomLeft());
4356  buttonGradient2.setColorAt(0.0, button.color().darker(113));
4357  buttonGradient2.setColorAt(1.0, button.color().darker(103));
4358  sunkenButtonGradientBrush = QBrush(buttonGradient2);
4359 
4360  QLinearGradient buttonGradient3(option->rect.topLeft(), option->rect.bottomLeft());
4361  buttonGradient3.setColorAt(0.0, button.color().lighter(105));
4362  buttonGradient3.setColorAt(1.0, button.color());
4363  leftLineGradientBrush = QBrush(buttonGradient3);
4364 
4365  QLinearGradient buttonGradient4(option->rect.topLeft(), option->rect.bottomLeft());
4366  buttonGradient4.setColorAt(0.0, button.color());
4367  buttonGradient4.setColorAt(1.0, button.color().darker(110));
4368  rightLineGradientBrush = QBrush(buttonGradient4);
4369 
4370  QLinearGradient buttonGradient5(option->rect.topLeft(), option->rect.bottomLeft());
4371  buttonGradient5.setColorAt(0.0, button.color().darker(113));
4372  buttonGradient5.setColorAt(1.0, button.color().darker(107));
4373  sunkenLeftLineGradientBrush = QBrush(buttonGradient5);
4374 
4375  QLinearGradient buttonGradient6(option->rect.topLeft(), option->rect.bottomLeft());
4376  buttonGradient6.setColorAt(0.0, button.color().darker(108));
4377  buttonGradient6.setColorAt(1.0, button.color().darker(103));
4378  sunkenRightLineGradientBrush = QBrush(buttonGradient6);
4379  }
4380 
4381  // ComboBox starts with a lineedit in place already.
4382  QRect buttonRect;
4383  if (!reverse) {
4384  buttonRect.setRect(rect.right() - menuButtonWidth, rect.top(), menuButtonWidth + 1, rect.height());
4385  } else {
4386  buttonRect.setRect(rect.left(), rect.top(), menuButtonWidth + 1, rect.height());
4387  }
4388 
4389  Q_D(const QPlastiqueStyle);
4390  d->drawPartialFrame(painter,
4391  option,
4393  widget);
4394 
4395  QBrush border = qMapBrushToRect(option->palette.shadow(), buttonRect);
4396  qBrushSetAlphaF(&border, qreal(0.4));
4397  painter->setPen(QPen(border, 0));
4398  if (!reverse)
4399  painter->drawLine(buttonRect.topLeft() + QPoint(0, 1), buttonRect.bottomLeft() + QPoint(0, -1));
4400  else
4401  painter->drawLine(buttonRect.topRight() + QPoint(0, -1), buttonRect.bottomRight() + QPoint(0, 1));
4402 
4403  // Outline the button border
4404  if (!reverse) {
4405  const QLine lines[3] = {
4406  QLine(buttonRect.left(), buttonRect.top(),
4407  buttonRect.right() - 2, buttonRect.top()),
4408  QLine(buttonRect.right(), buttonRect.top() + 2,
4409  buttonRect.right(), buttonRect.bottom() - 2),
4410  QLine(buttonRect.left(), buttonRect.bottom(),
4411  buttonRect.right() - 2, buttonRect.bottom()) };
4412  painter->drawLines(lines, 3);
4413  {
4414  const QPoint points[2] = {
4415  QPoint(buttonRect.right() - 1, buttonRect.top() + 1),
4416  QPoint(buttonRect.right() - 1, buttonRect.bottom() - 1) };
4417  painter->drawPoints(points, 2);
4418  }
4419 
4420  QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4421  qBrushSetAlphaF(&corner, qreal(0.16));
4422  painter->setPen(QPen(corner, 0));
4423  {
4424  const QPoint points[4] = {
4425  QPoint(buttonRect.right() - 1, buttonRect.top()),
4426  QPoint(buttonRect.right() - 1, buttonRect.bottom()),
4427  QPoint(buttonRect.right(), buttonRect.top() + 1),
4428  QPoint(buttonRect.right(), buttonRect.bottom() - 1) };
4429  painter->drawPoints(points, 4);
4430  }
4431  } else {
4432  const QLine lines[3] = {
4433  QLine(buttonRect.right(), buttonRect.top(),
4434  buttonRect.left() + 2, buttonRect.top()),
4435  QLine(buttonRect.left(), buttonRect.top() + 2,
4436  buttonRect.left(), buttonRect.bottom() - 2),
4437  QLine(buttonRect.right(), buttonRect.bottom(),
4438  buttonRect.left() + 2, buttonRect.bottom()) };
4439  painter->drawLines(lines, 3);
4440  {
4441  const QPoint points[2] = {
4442  QPoint(buttonRect.left() + 1, buttonRect.top() + 1),
4443  QPoint(buttonRect.left() + 1, buttonRect.bottom() - 1) };
4444  painter->drawPoints(points, 2);
4445  }
4446 
4447  QBrush corner = qMapBrushToRect(option->palette.shadow(), buttonRect);
4448  qBrushSetAlphaF(&corner, qreal(0.16));
4449  painter->setPen(QPen(corner, 0));
4450  {
4451  const QPoint points[4] = {
4452  QPoint(buttonRect.left() + 1, buttonRect.top()),
4453  QPoint(buttonRect.left() + 1, buttonRect.bottom()),
4454  QPoint(buttonRect.left(), buttonRect.top() + 1),
4455  QPoint(buttonRect.left(), buttonRect.bottom() - 1) };
4456  painter->drawPoints(points, 4);
4457  }
4458  }
4459 
4460  QRect fillRect = buttonRect.adjusted(2, 2, -2, -2);
4461  // Main fill
4462  painter->fillRect(fillRect,
4463  qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4464  : buttonGradientBrush, option->rect));
4465 
4466  // Top line
4467  painter->setPen(QPen(qBrushLight(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4468  : buttonGradientBrush, option->rect), 105), 0));
4469  if (!reverse) {
4470  painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 1),
4471  QPointF(buttonRect.right() - 2, buttonRect.top() + 1));
4472  } else {
4473  painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 1),
4474  QPointF(buttonRect.left() + 2, buttonRect.top() + 1));
4475  }
4476 
4477  // Bottom line
4478  painter->setPen(QPen(qBrushDark(qMapBrushToRect(sunken ? sunkenButtonGradientBrush
4479  : buttonGradientBrush, option->rect), 105), 0));
4480  if (!reverse) {
4481  painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.bottom() - 1),
4482  QPointF(buttonRect.right() - 2, buttonRect.bottom() - 1));
4483  } else {
4484  painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.bottom() - 1),
4485  QPointF(buttonRect.left() + 2, buttonRect.bottom() - 1));
4486  }
4487 
4488  // Left line
4489  painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenLeftLineGradientBrush
4490  : leftLineGradientBrush, option->rect), 1));
4491  if (!reverse) {
4492  painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
4493  QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
4494  } else {
4495  painter->drawLine(QPointF(buttonRect.left() + 1, buttonRect.top() + 2),
4496  QPointF(buttonRect.left() + 1, buttonRect.bottom() - 2));
4497  }
4498 
4499  // Right line
4500  painter->setPen(QPen(qMapBrushToRect(sunken ? sunkenRightLineGradientBrush
4501  : rightLineGradientBrush, option->rect), 1));
4502  if (!reverse) {
4503  painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
4504  QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
4505  } else {
4506  painter->drawLine(QPointF(buttonRect.right() - 1, buttonRect.top() + 2),
4507  QPointF(buttonRect.right() - 1, buttonRect.bottom() - 2));
4508  }
4509  } else {
4510  // Start with a standard panel button fill
4511  QStyleOptionButton buttonOption;
4512  buttonOption.QStyleOption::operator=(*comboBox);
4513  if (!sunken) {
4514  buttonOption.state &= ~State_Sunken;
4515  }
4516  proxy()->drawPrimitive(PE_PanelButtonCommand, &buttonOption, painter, widget);
4517 
4518  // Draw the menu button separator line
4519  QBrush border = qMapBrushToRect(option->palette.shadow(), rect);
4520  qBrushSetAlphaF(&border, qreal(0.35));
4521  painter->setPen(QPen(border, 0));
4522  if (!reverse) {
4523  painter->drawLine(rect.right() - menuButtonWidth + xoffset, rect.top() + 1,
4524  rect.right() - menuButtonWidth + xoffset, rect.bottom() - 1);
4525  } else {
4526  painter->drawLine(rect.left() + menuButtonWidth + xoffset, rect.top() + 1,
4527  rect.left() + menuButtonWidth + xoffset, rect.bottom() - 1);
4528  }
4529  }
4530 
4531  // Draw the little arrow
4532  if (comboBox->subControls & SC_ComboBoxArrow) {
4533  int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
4534  int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
4535  QRect arrowRect((left + right) / 2 - 3 + xoffset,
4536  rect.center().y() - 1 + yoffset, 7, 4);
4537  painter->setPen(QPen(qMapBrushToRect(option->palette.buttonText(), rect), 0));
4538  const QLine lines[3] = {
4539  QLine(arrowRect.topLeft(), arrowRect.topRight()),
4540  QLine(arrowRect.left() + 1, arrowRect.top() + 1,
4541  arrowRect.right() - 1, arrowRect.top() + 1),
4542  QLine(arrowRect.left() + 2, arrowRect.top() + 2,
4543  arrowRect.right() - 2, arrowRect.top() + 2) };
4544  painter->drawLines(lines, 3);
4545  painter->drawPoint(arrowRect.center().x(), arrowRect.bottom());
4546  }
4547 
4548  // Draw the focus rect
4549  if ((option->state & State_HasFocus) && !comboBox->editable
4550  && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget))) {
4551  QStyleOptionFocusRect focus;
4552  focus.rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxEditField, widget)
4553  .adjusted(-2, 0, 2, 0);
4554  proxy()->drawPrimitive(PE_FrameFocusRect, &focus, painter, widget);
4555  }
4556 
4557  painter->setPen(oldPen);
4558  }
4559  break;
4560 #endif // QT_NO_COMBOBOX
4561  case CC_TitleBar:
4562  if (const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
4563  painter->save();
4564  bool active = (titleBar->titleBarState & State_Active);
4565  QRect fullRect = titleBar->rect;
4566 
4567  // ### use palette colors instead
4568  QColor titleBarGradientStart(active ? 0x3b508a : 0x6e6e6e);
4569  QColor titleBarGradientStop(active ? 0x5d6e9e : 0x818181);
4570  QColor titleBarFrameBorder(0x393939);
4571  QColor titleBarAlphaCorner(active ? 0x4b5e7f : 0x6a6a6a);
4572  QColor titleBarInnerTopLine(active ? 0x8e98ba : 0xa4a4a4);
4573  QColor titleBarInnerInnerTopLine(active ? 0x57699b : 0x808080);
4574  QColor leftCorner(active ? 0x6f7ea8 : 0x8e8e8e);
4575  QColor rightCorner(active ? 0x44537d : 0x676767);
4576  QColor textColor(active ? 0x282e40 : 0x282e40);
4577  QColor textAlphaColor(active ? 0x3f4862 : 0x3f4862);
4578 
4579 #ifdef QT3_SUPPORT
4580  if (widget && widget->inherits("Q3DockWindowTitleBar")) {
4581  QStyleOptionDockWidgetV2 dockwidget;
4582  dockwidget.QStyleOption::operator=(*option);
4583  dockwidget.title = titleBar->text;
4584  proxy()->drawControl(CE_DockWidgetTitle, &dockwidget, painter, widget);
4585  } else
4586 #endif // QT3_SUPPORT
4587 
4588  {
4589  // Fill title bar gradient
4590  qt_plastique_draw_gradient(painter, option->rect.adjusted(1, 1, -1, 0),
4591  titleBarGradientStart,
4592  titleBarGradientStop);
4593 
4594  // Frame and rounded corners
4595  painter->setPen(titleBarFrameBorder);
4596 
4597  // top border line
4598  {
4599  const QLine lines[3] = {
4600  QLine(fullRect.left() + 2, fullRect.top(), fullRect.right() - 2, fullRect.top()),
4601  QLine(fullRect.left(), fullRect.top() + 2, fullRect.left(), fullRect.bottom()),
4602  QLine(fullRect.right(), fullRect.top() + 2, fullRect.right(), fullRect.bottom()) };
4603  painter->drawLines(lines, 3);
4604  const QPoint points[2] = {
4605  QPoint(fullRect.left() + 1, fullRect.top() + 1),
4606  QPoint(fullRect.right() - 1, fullRect.top() + 1) };
4607  painter->drawPoints(points, 2);
4608  }
4609 
4610  // alpha corners
4611  painter->setPen(titleBarAlphaCorner);
4612  {
4613  const QPoint points[4] = {
4614  QPoint(fullRect.left() + 2, fullRect.top() + 1),
4615  QPoint(fullRect.left() + 1, fullRect.top() + 2),
4616  QPoint(fullRect.right() - 2, fullRect.top() + 1),
4617  QPoint(fullRect.right() - 1, fullRect.top() + 2) };
4618  painter->drawPoints(points, 4);
4619  }
4620 
4621  // inner top line
4622  painter->setPen(titleBarInnerTopLine);
4623  painter->drawLine(fullRect.left() + 3, fullRect.top() + 1, fullRect.right() - 3, fullRect.top() + 1);
4624 
4625  // inner inner top line
4626  painter->setPen(titleBarInnerInnerTopLine);
4627  painter->drawLine(fullRect.left() + 2, fullRect.top() + 2, fullRect.right() - 2, fullRect.top() + 2);
4628 
4629  // left and right inner
4630  painter->setPen(leftCorner);
4631  painter->drawLine(fullRect.left() + 1, fullRect.top() + 3, fullRect.left() + 1, fullRect.bottom());
4632  painter->setPen(rightCorner);
4633  painter->drawLine(fullRect.right() - 1, fullRect.top() + 3, fullRect.right() - 1, fullRect.bottom());
4634 
4635  if (titleBar->titleBarState & Qt::WindowMinimized) {
4636  painter->setPen(titleBarFrameBorder);
4637  painter->drawLine(fullRect.left() + 2, fullRect.bottom(), fullRect.right() - 2, fullRect.bottom());
4638  {
4639  const QPoint points[2] = {
4640  QPoint(fullRect.left() + 1, fullRect.bottom() - 1),
4641  QPoint(fullRect.right() - 1, fullRect.bottom() - 1) };
4642  painter->drawPoints(points, 2);
4643  }
4644  painter->setPen(rightCorner);
4645  painter->drawLine(fullRect.left() + 2, fullRect.bottom() - 1, fullRect.right() - 2, fullRect.bottom() - 1);
4646  painter->setPen(titleBarAlphaCorner);
4647  {
4648  const QPoint points[4] = {
4649  QPoint(fullRect.left() + 1, fullRect.bottom() - 2),
4650  QPoint(fullRect.left() + 2, fullRect.bottom() - 1),
4651  QPoint(fullRect.right() - 1, fullRect.bottom() - 2),
4652  QPoint(fullRect.right() - 2, fullRect.bottom() - 1) };
4653  painter->drawPoints(points, 4);
4654  }
4655  }
4656  // draw title
4657  QRect textRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarLabel, widget);
4658 
4659  QFont font = painter->font();
4660  font.setBold(true);
4661  painter->setFont(font);
4662  painter->setPen(titleBar->palette.text().color());
4663 
4664  // Attempt to align left if there is not enough room for the title
4665  // text. Otherwise, align center. QWorkspace does elliding for us,
4666  // and it doesn't know about the bold title, so we need to work
4667  // around some of the width mismatches.
4668  bool tooWide = (QFontMetrics(font).width(titleBar->text) > textRect.width());
4671 
4672  painter->drawText(textRect.adjusted(1, 1, 1, 1), titleBar->text, option);
4673  painter->setPen(titleBar->palette.highlightedText().color());
4674  painter->drawText(textRect, titleBar->text, option);
4675  }
4676 
4677  // min button
4678  if ((titleBar->subControls & SC_TitleBarMinButton)
4679  && (titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint)
4680  && !(titleBar->titleBarState & Qt::WindowMinimized)) {
4681  bool hover = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_MouseOver);
4682  bool sunken = (titleBar->activeSubControls & SC_TitleBarMinButton) && (titleBar->state & State_Sunken);
4683 
4684  QRect minButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMinButton, widget);
4685  qt_plastique_draw_mdibutton(painter, titleBar, minButtonRect, hover, sunken);
4686 
4687  int xoffset = minButtonRect.width() / 3;
4688  int yoffset = minButtonRect.height() / 3;
4689 
4690  QRect minButtonIconRect(minButtonRect.left() + xoffset, minButtonRect.top() + yoffset,
4691  minButtonRect.width() - xoffset * 2, minButtonRect.height() - yoffset * 2);
4692 
4693  painter->setPen(textColor);
4694  {
4695  const QLine lines[2] = {
4696  QLine(minButtonIconRect.center().x() - 2,
4697  minButtonIconRect.center().y() + 3,
4698  minButtonIconRect.center().x() + 3,
4699  minButtonIconRect.center().y() + 3),
4700  QLine(minButtonIconRect.center().x() - 2,
4701  minButtonIconRect.center().y() + 4,
4702  minButtonIconRect.center().x() + 3,
4703  minButtonIconRect.center().y() + 4) };
4704  painter->drawLines(lines, 2);
4705  }
4706  painter->setPen(textAlphaColor);
4707  {
4708  const QLine lines[2] = {
4709  QLine(minButtonIconRect.center().x() - 3,
4710  minButtonIconRect.center().y() + 3,
4711  minButtonIconRect.center().x() - 3,
4712  minButtonIconRect.center().y() + 4),
4713  QLine(minButtonIconRect.center().x() + 4,
4714  minButtonIconRect.center().y() + 3,
4715  minButtonIconRect.center().x() + 4,
4716  minButtonIconRect.center().y() + 4) };
4717  painter->drawLines(lines, 2);
4718  }
4719  }
4720 
4721  // max button
4722  if ((titleBar->subControls & SC_TitleBarMaxButton)
4723  && (titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint)
4724  && !(titleBar->titleBarState & Qt::WindowMaximized)) {
4725  bool hover = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_MouseOver);
4726  bool sunken = (titleBar->activeSubControls & SC_TitleBarMaxButton) && (titleBar->state & State_Sunken);
4727 
4728  QRect maxButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarMaxButton, widget);
4729  qt_plastique_draw_mdibutton(painter, titleBar, maxButtonRect, hover, sunken);
4730 
4731  int xoffset = maxButtonRect.width() / 3;
4732  int yoffset = maxButtonRect.height() / 3;
4733 
4734  QRect maxButtonIconRect(maxButtonRect.left() + xoffset, maxButtonRect.top() + yoffset,
4735  maxButtonRect.width() - xoffset * 2, maxButtonRect.height() - yoffset * 2);
4736 
4737  painter->setPen(textColor);
4738  painter->drawRect(maxButtonIconRect.adjusted(0, 0, -1, -1));
4739  painter->drawLine(maxButtonIconRect.left() + 1, maxButtonIconRect.top() + 1,
4740  maxButtonIconRect.right() - 1, maxButtonIconRect.top() + 1);
4741  painter->setPen(textAlphaColor);
4742  const QPoint points[4] = {
4743  maxButtonIconRect.topLeft(), maxButtonIconRect.topRight(),
4744  maxButtonIconRect.bottomLeft(), maxButtonIconRect.bottomRight() };
4745  painter->drawPoints(points, 4);
4746  }
4747 
4748  // close button
4749  if (titleBar->subControls & SC_TitleBarCloseButton && titleBar->titleBarFlags & Qt::WindowSystemMenuHint) {
4750  bool hover = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_MouseOver);
4751  bool sunken = (titleBar->activeSubControls & SC_TitleBarCloseButton) && (titleBar->state & State_Sunken);
4752 
4753  QRect closeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarCloseButton, widget);
4754  qt_plastique_draw_mdibutton(painter, titleBar, closeButtonRect, hover, sunken);
4755 
4756  int xoffset = closeButtonRect.width() / 3;
4757  int yoffset = closeButtonRect.height() / 3;
4758 
4759  QRect closeIconRect(closeButtonRect.left() + xoffset, closeButtonRect.top() + yoffset,
4760  closeButtonRect.width() - xoffset * 2, closeButtonRect.height() - yoffset * 2);
4761 
4762  painter->setPen(textAlphaColor);
4763  {
4764  const QLine lines[4] = {
4765  QLine(closeIconRect.left() + 1, closeIconRect.top(),
4766  closeIconRect.right(), closeIconRect.bottom() - 1),
4767  QLine(closeIconRect.left(), closeIconRect.top() + 1,
4768  closeIconRect.right() - 1, closeIconRect.bottom()),
4769  QLine(closeIconRect.right() - 1, closeIconRect.top(),
4770  closeIconRect.left(), closeIconRect.bottom() - 1),
4771  QLine(closeIconRect.right(), closeIconRect.top() + 1,
4772  closeIconRect.left() + 1, closeIconRect.bottom()) };
4773  painter->drawLines(lines, 4);
4774  const QPoint points[4] = {
4775  closeIconRect.topLeft(), closeIconRect.topRight(),
4776  closeIconRect.bottomLeft(), closeIconRect.bottomRight() };
4777  painter->drawPoints(points, 4);
4778  }
4779  painter->setPen(textColor);
4780  {
4781  const QLine lines[2] = {
4782  QLine(closeIconRect.left() + 1, closeIconRect.top() + 1,
4783  closeIconRect.right() - 1, closeIconRect.bottom() - 1),
4784  QLine(closeIconRect.left() + 1, closeIconRect.bottom() - 1,
4785  closeIconRect.right() - 1, closeIconRect.top() + 1) };
4786  painter->drawLines(lines, 2);
4787  }
4788  }
4789 
4790  // normalize button
4791  if ((titleBar->subControls & SC_TitleBarNormalButton) &&
4792  (((titleBar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
4793  (titleBar->titleBarState & Qt::WindowMinimized)) ||
4794  ((titleBar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
4795  (titleBar->titleBarState & Qt::WindowMaximized)))) {
4796  bool hover = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_MouseOver);
4797  bool sunken = (titleBar->activeSubControls & SC_TitleBarNormalButton) && (titleBar->state & State_Sunken);
4798 
4799  QRect normalButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarNormalButton, widget);
4800  qt_plastique_draw_mdibutton(painter, titleBar, normalButtonRect, hover, sunken);
4801  int xoffset = int(normalButtonRect.width() / 3.5);
4802  int yoffset = int(normalButtonRect.height() / 3.5);
4803 
4804  QRect normalButtonIconRect(normalButtonRect.left() + xoffset, normalButtonRect.top() + yoffset,
4805  normalButtonRect.width() - xoffset * 2, normalButtonRect.height() - yoffset * 2);
4806 
4807  QRect frontWindowRect = normalButtonIconRect.adjusted(0, 3, -3, 0);
4808  painter->setPen(textColor);
4809  painter->drawRect(frontWindowRect.adjusted(0, 0, -1, -1));
4810  painter->drawLine(frontWindowRect.left() + 1, frontWindowRect.top() + 1,
4811  frontWindowRect.right() - 1, frontWindowRect.top() + 1);
4812  painter->setPen(textAlphaColor);
4813  {
4814  const QPoint points[4] = {
4815  frontWindowRect.topLeft(), frontWindowRect.topRight(),
4816  frontWindowRect.bottomLeft(), frontWindowRect.bottomRight() };
4817  painter->drawPoints(points, 4);
4818  }
4819 
4820  QRect backWindowRect = normalButtonIconRect.adjusted(3, 0, 0, -3);
4821  QRegion clipRegion = backWindowRect;
4822  clipRegion -= frontWindowRect;
4823  painter->save();
4824  painter->setClipRegion(clipRegion);
4825  painter->setPen(textColor);
4826  painter->drawRect(backWindowRect.adjusted(0, 0, -1, -1));
4827  painter->drawLine(backWindowRect.left() + 1, backWindowRect.top() + 1,
4828  backWindowRect.right() - 1, backWindowRect.top() + 1);
4829  painter->setPen(textAlphaColor);
4830  {
4831  const QPoint points[4] = {
4832  backWindowRect.topLeft(), backWindowRect.topRight(),
4833  backWindowRect.bottomLeft(), backWindowRect.bottomRight() };
4834  painter->drawPoints(points, 4);
4835  }
4836  painter->restore();
4837  }
4838 
4839  // context help button
4840  if (titleBar->subControls & SC_TitleBarContextHelpButton
4841  && (titleBar->titleBarFlags & Qt::WindowContextHelpButtonHint)) {
4842  bool hover = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_MouseOver);
4843  bool sunken = (titleBar->activeSubControls & SC_TitleBarContextHelpButton) && (titleBar->state & State_Sunken);
4844 
4845  QRect contextHelpButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarContextHelpButton, widget);
4846 
4847  qt_plastique_draw_mdibutton(painter, titleBar, contextHelpButtonRect, hover, sunken);
4848 
4849  QColor blend;
4850  // ### Use palette colors
4851  if (active) {
4852  blend = mergedColors(QColor(hover ? 0x7d8bb1 : 0x55689a),
4853  QColor(hover ? 0x939ebe : 0x7381ab));
4854  } else {
4855  blend = mergedColors(QColor(hover ? 0x9e9e9e : 0x818181),
4856  QColor(hover ? 0xababab : 0x929292));
4857  }
4859  image.setColor(4, textColor.rgba());
4860  image.setColor(3, mergedColors(blend, textColor, 30).rgba());
4861  image.setColor(2, mergedColors(blend, textColor, 70).rgba());
4862  image.setColor(1, mergedColors(blend, textColor, 90).rgba());
4863 
4864  painter->drawImage(contextHelpButtonRect, image);
4865  }
4866 
4867  // shade button
4868  if (titleBar->subControls & SC_TitleBarShadeButton) {
4869  bool hover = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_MouseOver);
4870  bool sunken = (titleBar->activeSubControls & SC_TitleBarShadeButton) && (titleBar->state & State_Sunken);
4871 
4872  QRect shadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarShadeButton, widget);
4873  qt_plastique_draw_mdibutton(painter, titleBar, shadeButtonRect, hover, sunken);
4874 
4875  int xoffset = shadeButtonRect.width() / 3;
4876  int yoffset = shadeButtonRect.height() / 3;
4877 
4878  QRect shadeButtonIconRect(shadeButtonRect.left() + xoffset, shadeButtonRect.top() + yoffset,
4879  shadeButtonRect.width() - xoffset * 2, shadeButtonRect.height() - yoffset * 2);
4880 
4881  QPainterPath path(shadeButtonIconRect.bottomLeft());
4882  path.lineTo(shadeButtonIconRect.center().x(), shadeButtonIconRect.bottom() - shadeButtonIconRect.height() / 2);
4883  path.lineTo(shadeButtonIconRect.bottomRight());
4884  path.lineTo(shadeButtonIconRect.bottomLeft());
4885 
4886  painter->setPen(textAlphaColor);
4887  painter->setBrush(textColor);
4888  painter->drawPath(path);
4889  }
4890 
4891  // unshade button
4892  if (titleBar->subControls & SC_TitleBarUnshadeButton) {
4893  bool hover = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_MouseOver);
4894  bool sunken = (titleBar->activeSubControls & SC_TitleBarUnshadeButton) && (titleBar->state & State_Sunken);
4895 
4896  QRect unshadeButtonRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarUnshadeButton, widget);
4897  qt_plastique_draw_mdibutton(painter, titleBar, unshadeButtonRect, hover, sunken);
4898 
4899  int xoffset = unshadeButtonRect.width() / 3;
4900  int yoffset = unshadeButtonRect.height() / 3;
4901 
4902  QRect unshadeButtonIconRect(unshadeButtonRect.left() + xoffset, unshadeButtonRect.top() + yoffset,
4903  unshadeButtonRect.width() - xoffset * 2, unshadeButtonRect.height() - yoffset * 2);
4904 
4905  int midY = unshadeButtonIconRect.bottom() - unshadeButtonIconRect.height() / 2;
4906  QPainterPath path(QPoint(unshadeButtonIconRect.left(), midY));
4907  path.lineTo(unshadeButtonIconRect.right(), midY);
4908  path.lineTo(unshadeButtonIconRect.center().x(), unshadeButtonIconRect.bottom());
4909  path.lineTo(unshadeButtonIconRect.left(), midY);
4910 
4911  painter->setPen(textAlphaColor);
4912  painter->setBrush(textColor);
4913  painter->drawPath(path);
4914  }
4915 
4916  // from qwindowsstyle.cpp
4917  if ((titleBar->subControls & SC_TitleBarSysMenu) && (titleBar->titleBarFlags & Qt::WindowSystemMenuHint)) {
4918  bool hover = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_MouseOver);
4919  bool sunken = (titleBar->activeSubControls & SC_TitleBarSysMenu) && (titleBar->state & State_Sunken);
4920 
4921  QRect iconRect = proxy()->subControlRect(CC_TitleBar, titleBar, SC_TitleBarSysMenu, widget);
4922  if (hover)
4923  qt_plastique_draw_mdibutton(painter, titleBar, iconRect, hover, sunken);
4924 
4925  if (!titleBar->icon.isNull()) {
4926  titleBar->icon.paint(painter, iconRect);
4927  } else {
4928  QStyleOption tool(0);
4929  tool.palette = titleBar->palette;
4930  QPixmap pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
4931  tool.rect = iconRect;
4932  painter->save();
4933  proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
4934  painter->restore();
4935  }
4936  }
4937  painter->restore();
4938  }
4939  break;
4940 #ifndef QT_NO_DIAL
4941  case CC_Dial:
4942  if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(option))
4943  QStyleHelper::drawDial(dial, painter);
4944  break;
4945 #endif // QT_NO_DIAL
4946  default:
4947  QWindowsStyle::drawComplexControl(control, option, painter, widget);
4948  break;
4949  }
4950 }
4951 
4956  const QSize &size, const QWidget *widget) const
4957 {
4958  QSize newSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
4959 
4960  switch (type) {
4961  case CT_RadioButton:
4962  ++newSize.rheight();
4963  ++newSize.rwidth();
4964  break;
4965 #ifndef QT_NO_SLIDER
4966  case CT_Slider:
4967  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
4968  int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
4969  if (slider->tickPosition & QSlider::TicksBelow) {
4970  if (slider->orientation == Qt::Horizontal)
4971  newSize.rheight() += tickSize;
4972  else
4973  newSize.rwidth() += tickSize;
4974  }
4975  if (slider->tickPosition & QSlider::TicksAbove) {
4976  if (slider->orientation == Qt::Horizontal)
4977  newSize.rheight() += tickSize;
4978  else
4979  newSize.rwidth() += tickSize;
4980  }
4981  }
4982  break;
4983 #endif // QT_NO_SLIDER
4984 #ifndef QT_NO_SCROLLBAR
4985  case CT_ScrollBar:
4986  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
4987  int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, option, widget);
4988  int scrollBarSliderMinimum = proxy()->pixelMetric(PM_ScrollBarSliderMin, option, widget);
4989  if (scrollBar->orientation == Qt::Horizontal) {
4990  newSize = QSize(scrollBarExtent * 3 + scrollBarSliderMinimum, scrollBarExtent);
4991  } else {
4992  newSize = QSize(scrollBarExtent, scrollBarExtent * 3 + scrollBarSliderMinimum);
4993  }
4994  }
4995  break;
4996 #endif // QT_NO_SCROLLBAR
4997 #ifndef QT_NO_SPINBOX
4998  case CT_SpinBox:
4999  // Make sure the size is odd
5000  newSize.setHeight(sizeFromContents(CT_LineEdit, option, size, widget).height());
5001  newSize.rheight() -= ((1 - newSize.rheight()) & 1);
5002  break;
5003 #endif
5004 #ifndef QT_NO_TOOLBUTTON
5005  case CT_ToolButton:
5006  newSize.rheight() += 3;
5007  newSize.rwidth() += 3;
5008  break;
5009 #endif
5010 #ifndef QT_NO_COMBOBOX
5011  case CT_ComboBox:
5012  newSize = sizeFromContents(CT_PushButton, option, size, widget);
5013  newSize.rwidth() += 30; // Make room for drop-down indicator
5014  newSize.rheight() += 4;
5015  break;
5016 #endif
5017  case CT_MenuItem:
5018  if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
5019  if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
5020  newSize.setHeight(menuItem->text.isEmpty() ? 2 : menuItem->fontMetrics.height());
5021  }
5022  break;
5023  case CT_MenuBarItem:
5024  newSize.setHeight(newSize.height());
5025  break;
5026  default:
5027  break;
5028  }
5029 
5030  return newSize;
5031 }
5032 
5037 {
5038  QRect rect;
5039  switch (element) {
5041  rect = visualRect(option->direction, option->rect,
5042  QWindowsStyle::subElementRect(element, option, widget)).adjusted(0, 0, 1, 1);
5043  break;
5044 #ifndef QT_NO_PROGRESSBAR
5045  case SE_ProgressBarLabel:
5047  case SE_ProgressBarGroove:
5048  return option->rect;
5049 #endif // QT_NO_PROGRESSBAR
5050  default:
5051  return QWindowsStyle::subElementRect(element, option, widget);
5052  }
5053 
5054  return visualRect(option->direction, option->rect, rect);
5055 }
5056 
5061  SubControl subControl, const QWidget *widget) const
5062 {
5063  QRect rect = QWindowsStyle::subControlRect(control, option, subControl, widget);
5064 
5065  switch (control) {
5066 #ifndef QT_NO_SLIDER
5067  case CC_Slider:
5068  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5069  int tickSize = proxy()->pixelMetric(PM_SliderTickmarkOffset, option, widget);
5070 
5071  switch (subControl) {
5072  case SC_SliderHandle:
5073  if (slider->orientation == Qt::Horizontal) {
5074  rect.setWidth(11);
5075  rect.setHeight(15);
5076  int centerY = slider->rect.center().y() - rect.height() / 2;
5077  if (slider->tickPosition & QSlider::TicksAbove)
5078  centerY += tickSize;
5079  if (slider->tickPosition & QSlider::TicksBelow)
5080  centerY -= tickSize;
5081  rect.moveTop(centerY);
5082  } else {
5083  rect.setWidth(15);
5084  rect.setHeight(11);
5085  int centerX = slider->rect.center().x() - rect.width() / 2;
5086  if (slider->tickPosition & QSlider::TicksAbove)
5087  centerX += tickSize;
5088  if (slider->tickPosition & QSlider::TicksBelow)
5089  centerX -= tickSize;
5090  rect.moveLeft(centerX);
5091  }
5092  break;
5093  case SC_SliderGroove: {
5094  QPoint grooveCenter = slider->rect.center();
5095  if (slider->orientation == Qt::Horizontal) {
5096  rect.setHeight(14);
5097  --grooveCenter.ry();
5098  if (slider->tickPosition & QSlider::TicksAbove)
5099  grooveCenter.ry() += tickSize;
5100  if (slider->tickPosition & QSlider::TicksBelow)
5101  grooveCenter.ry() -= tickSize;
5102  } else {
5103  rect.setWidth(14);
5104  --grooveCenter.rx();
5105  if (slider->tickPosition & QSlider::TicksAbove)
5106  grooveCenter.rx() += tickSize;
5107  if (slider->tickPosition & QSlider::TicksBelow)
5108  grooveCenter.rx() -= tickSize;
5109  }
5110  rect.moveCenter(grooveCenter);
5111  break;
5112  }
5113  default:
5114  break;
5115  }
5116  }
5117  break;
5118 #endif // QT_NO_SLIDER
5119 #ifndef QT_NO_SCROLLBAR
5120  case CC_ScrollBar:
5121  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5122  int scrollBarExtent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollBar, widget);
5123  int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ?
5124  scrollBar->rect.width() : scrollBar->rect.height()) - (scrollBarExtent * 3);
5125  int sliderMinLength = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollBar, widget);
5126  int sliderLength;
5127 
5128  // calculate slider length
5129  if (scrollBar->maximum != scrollBar->minimum) {
5130  uint valueRange = scrollBar->maximum - scrollBar->minimum;
5131  sliderLength = (scrollBar->pageStep * sliderMaxLength) / (valueRange + scrollBar->pageStep);
5132 
5133  if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2)
5134  sliderLength = sliderMinLength;
5135  if (sliderLength > sliderMaxLength)
5136  sliderLength = sliderMaxLength;
5137  } else {
5138  sliderLength = sliderMaxLength;
5139  }
5140 
5141  int sliderStart = scrollBarExtent + sliderPositionFromValue(scrollBar->minimum,
5142  scrollBar->maximum,
5143  scrollBar->sliderPosition,
5144  sliderMaxLength - sliderLength,
5145  scrollBar->upsideDown);
5146 
5147  QRect scrollBarRect = scrollBar->rect;
5148 
5149  switch (subControl) {
5150  case SC_ScrollBarSubLine: // top/left button
5151  if (scrollBar->orientation == Qt::Horizontal) {
5152  rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width() - scrollBarExtent, scrollBarRect.height());
5153  } else {
5154  rect.setRect(scrollBarRect.left(), scrollBarRect.top(), scrollBarRect.width(), scrollBarRect.height() - scrollBarExtent);
5155  }
5156  break;
5157  case SC_ScrollBarAddLine: // bottom/right button
5158  if (scrollBar->orientation == Qt::Horizontal) {
5159  rect.setRect(scrollBarRect.right() - (scrollBarExtent - 1), scrollBarRect.top(), scrollBarExtent, scrollBarRect.height());
5160  } else {
5161  rect.setRect(scrollBarRect.left(), scrollBarRect.bottom() - (scrollBarExtent - 1), scrollBarRect.width(), scrollBarExtent);
5162  }
5163  break;
5164  case SC_ScrollBarSubPage:
5165  if (scrollBar->orientation == Qt::Horizontal) {
5166  rect.setRect(scrollBarRect.left() + scrollBarExtent, scrollBarRect.top(),
5167  sliderStart - (scrollBarRect.left() + scrollBarExtent), scrollBarRect.height());
5168  } else {
5169  rect.setRect(scrollBarRect.left(), scrollBarRect.top() + scrollBarExtent,
5170  scrollBarRect.width(), sliderStart - (scrollBarRect.left() + scrollBarExtent));
5171  }
5172  break;
5173  case SC_ScrollBarAddPage:
5174  if (scrollBar->orientation == Qt::Horizontal)
5175  rect.setRect(sliderStart + sliderLength, 0,
5176  sliderMaxLength - sliderStart - sliderLength + scrollBarExtent, scrollBarRect.height());
5177  else
5178  rect.setRect(0, sliderStart + sliderLength,
5179  scrollBarRect.width(), sliderMaxLength - sliderStart - sliderLength + scrollBarExtent);
5180  break;
5181  case SC_ScrollBarGroove:
5182  if (scrollBar->orientation == Qt::Horizontal) {
5183  rect = scrollBarRect.adjusted(scrollBarExtent, 0, -2 * scrollBarExtent, 0);
5184  } else {
5185  rect = scrollBarRect.adjusted(0, scrollBarExtent, 0, -2 * scrollBarExtent);
5186  }
5187  break;
5188  case SC_ScrollBarSlider:
5189  if (scrollBar->orientation == Qt::Horizontal) {
5190  rect.setRect(sliderStart, 0, sliderLength, scrollBarRect.height());
5191  } else {
5192  rect.setRect(0, sliderStart, scrollBarRect.width(), sliderLength);
5193  }
5194  break;
5195  default:
5196  break;
5197  }
5198  rect = visualRect(scrollBar->direction, scrollBarRect, rect);
5199  }
5200  break;
5201 #endif // QT_NO_SCROLLBAR
5202 #ifndef QT_NO_SPINBOX
5203  case CC_SpinBox:
5204  if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
5205  int center = spinBox->rect.height() / 2;
5206  switch (subControl) {
5207  case SC_SpinBoxUp:
5208  if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
5209  return QRect();
5210  rect = visualRect(spinBox->direction, spinBox->rect, rect);
5211  rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top(), 17, center + 1);
5212  rect = visualRect(spinBox->direction, spinBox->rect, rect);
5213  break;
5214  case SC_SpinBoxDown:
5215  if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
5216  return QRect();
5217  rect = visualRect(spinBox->direction, spinBox->rect, rect);
5218  rect.setRect(spinBox->rect.right() - 16, spinBox->rect.top() + center, 17, spinBox->rect.height() - center);
5219  rect = visualRect(spinBox->direction, spinBox->rect, rect);
5220  break;
5221  case SC_SpinBoxEditField:
5222  if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
5223  rect = spinBox->rect.adjusted(0, 0, -16, 0);
5224  } else {
5225  rect = spinBox->rect;
5226  }
5228  rect = visualRect(spinBox->direction, spinBox->rect, rect);
5229  break;
5230  default:
5231  break;
5232  }
5233  }
5234  break;
5235 #endif // QT_NO_SPINBOX
5236 #ifndef QT_NO_COMBOBOX
5237  case CC_ComboBox:
5238  switch (subControl) {
5239  case SC_ComboBoxArrow:
5240  rect = visualRect(option->direction, option->rect, rect);
5241  rect.setRect(rect.right() - 17, rect.top() - 2,
5242  19, rect.height() + 4);
5243  rect = visualRect(option->direction, option->rect, rect);
5244  break;
5245  case SC_ComboBoxEditField: {
5246  if (const QStyleOptionComboBox *box = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
5247  int frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth);
5248  rect = visualRect(option->direction, option->rect, rect);
5249 
5250  if (box->editable) {
5252  rect.setRight(rect.right() - 16); // Overlaps the combobox button by 2 pixels
5253  } else {
5254  rect.setRect(option->rect.left() + frameWidth, option->rect.top() + frameWidth,
5255  option->rect.width() - 16 - 2 * frameWidth,
5256  option->rect.height() - 2 * frameWidth);
5257  rect.setLeft(rect.left() + 2);
5258  rect.setRight(rect.right() - 2);
5259  if (box->state & (State_Sunken | State_On))
5260  rect.translate(1, 1);
5261  }
5262  rect = visualRect(option->direction, option->rect, rect);
5263  }
5264  break;
5265  }
5266  default:
5267  break;
5268  }
5269  break;
5270 #endif // QT_NO_COMBOBOX
5271  case CC_TitleBar:
5272  if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
5273  SubControl sc = subControl;
5274  QRect &ret = rect;
5275  const int indent = 3;
5276  const int controlTopMargin = 4;
5277  const int controlBottomMargin = 3;
5278  const int controlWidthMargin = 1;
5279  const int controlHeight = tb->rect.height() - controlTopMargin - controlBottomMargin;
5280  const int delta = controlHeight + controlWidthMargin;
5281  int offset = 0;
5282 
5283  bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
5284  bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
5285 
5286  switch (sc) {
5287  case SC_TitleBarLabel:
5288  if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
5289  ret = tb->rect;
5290  if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
5291  ret.adjust(delta, 0, -delta, 0);
5292  if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
5293  ret.adjust(0, 0, -delta, 0);
5294  if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
5295  ret.adjust(0, 0, -delta, 0);
5296  if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
5297  ret.adjust(0, 0, -delta, 0);
5298  if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
5299  ret.adjust(0, 0, -delta, 0);
5300  ret.adjusted(indent, 0, -indent, 0);
5301  }
5302  break;
5304  if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
5305  offset += delta;
5306  case SC_TitleBarMinButton:
5307  if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
5308  offset += delta;
5309  else if (sc == SC_TitleBarMinButton)
5310  break;
5312  if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
5313  offset += delta;
5314  else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
5315  offset += delta;
5316  else if (sc == SC_TitleBarNormalButton)
5317  break;
5318  case SC_TitleBarMaxButton:
5319  if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
5320  offset += delta;
5321  else if (sc == SC_TitleBarMaxButton)
5322  break;
5324  if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
5325  offset += delta;
5326  else if (sc == SC_TitleBarShadeButton)
5327  break;
5329  if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
5330  offset += delta;
5331  else if (sc == SC_TitleBarUnshadeButton)
5332  break;
5334  if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
5335  offset += delta;
5336  else if (sc == SC_TitleBarCloseButton)
5337  break;
5338  ret.setRect(tb->rect.right() - indent - offset, tb->rect.top() + controlTopMargin,
5339  controlHeight, controlHeight);
5340  break;
5341  case SC_TitleBarSysMenu:
5342  if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
5343  ret.setRect(tb->rect.left() + controlWidthMargin + indent, tb->rect.top() + controlTopMargin,
5344  controlHeight, controlHeight);
5345  }
5346  break;
5347  default:
5348  break;
5349  }
5350  ret = visualRect(tb->direction, tb->rect, ret);
5351  }
5352  break;
5353  default:
5354  break;
5355  }
5356 
5357  return rect;
5358 }
5359 
5364  QStyleHintReturn *returnData) const
5365 {
5366  int ret = 0;
5367  switch (hint) {
5368  case SH_WindowFrame_Mask:
5369  ret = 1;
5370  if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask *>(returnData)) {
5371  mask->region = option->rect;
5372  mask->region -= QRect(option->rect.left(), option->rect.top(), 2, 1);
5373  mask->region -= QRect(option->rect.right() - 1, option->rect.top(), 2, 1);
5374  mask->region -= QRect(option->rect.left(), option->rect.top() + 1, 1, 1);
5375  mask->region -= QRect(option->rect.right(), option->rect.top() + 1, 1, 1);
5376 
5377  const QStyleOptionTitleBar *titleBar = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
5378  if (titleBar && (titleBar->titleBarState & Qt::WindowMinimized)) {
5379  mask->region -= QRect(option->rect.left(), option->rect.bottom(), 2, 1);
5380  mask->region -= QRect(option->rect.right() - 1, option->rect.bottom(), 2, 1);
5381  mask->region -= QRect(option->rect.left(), option->rect.bottom() - 1, 1, 1);
5382  mask->region -= QRect(option->rect.right(), option->rect.bottom() - 1, 1, 1);
5383  } else {
5384  mask->region -= QRect(option->rect.bottomLeft(), QSize(1, 1));
5385  mask->region -= QRect(option->rect.bottomRight(), QSize(1, 1));
5386  }
5387  }
5388  break;
5389  case SH_TitleBar_NoBorder:
5390  ret = 1;
5391  break;
5392  case SH_TitleBar_AutoRaise:
5393  ret = 1;
5394  break;
5396  ret = true;
5397  break;
5400  ret = true;
5401  break;
5403  ret = 0;
5404  break;
5407  break;
5410  break;
5412  ret = Qt::AlignLeft | Qt::AlignTop;
5413  break;
5415  ret = Qt::AlignRight;
5416  break;
5419  break;
5421  ret = QCommonStyle::styleHint(hint, option, widget, returnData);
5422  break;
5424  ret = true;
5425  break;
5427  ret = 96; // from Plastik
5428  break;
5429 #ifdef Q_WS_X11
5431  ret = true;
5432  break;
5433 #endif
5434 #ifndef Q_OS_WIN
5436  ret = false;
5437  break;
5438 #endif
5439  default:
5440  ret = QWindowsStyle::styleHint(hint, option, widget, returnData);
5441  break;
5442  }
5443  return ret;
5444 }
5445 
5450  const QPoint &pos, const QWidget *widget) const
5451 {
5452  SubControl ret = SC_None;
5453  switch (control) {
5454 #ifndef QT_NO_SCROLLBAR
5455  case CC_ScrollBar:
5456  if (const QStyleOptionSlider *scrollBar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5457  QRect slider = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSlider, widget);
5458  if (slider.contains(pos)) {
5459  ret = SC_ScrollBarSlider;
5460  break;
5461  }
5462 
5463  QRect scrollBarAddLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddLine, widget);
5464  if (scrollBarAddLine.contains(pos)) {
5465  ret = SC_ScrollBarAddLine;
5466  break;
5467  }
5468 
5469  QRect scrollBarSubPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubPage, widget);
5470  if (scrollBarSubPage.contains(pos)) {
5471  ret = SC_ScrollBarSubPage;
5472  break;
5473  }
5474 
5475  QRect scrollBarAddPage = proxy()->subControlRect(control, scrollBar, SC_ScrollBarAddPage, widget);
5476  if (scrollBarAddPage.contains(pos)) {
5477  ret = SC_ScrollBarAddPage;
5478  break;
5479  }
5480 
5481  QRect scrollBarSubLine = proxy()->subControlRect(control, scrollBar, SC_ScrollBarSubLine, widget);
5482  if (scrollBarSubLine.contains(pos)) {
5483  ret = SC_ScrollBarSubLine;
5484  break;
5485  }
5486  }
5487  break;
5488 #endif // QT_NO_SCROLLBAR
5489  default:
5490  break;
5491  }
5492 
5493  return ret != SC_None ? ret : QWindowsStyle::hitTestComplexControl(control, option, pos, widget);
5494 }
5495 
5499 int QPlastiqueStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
5500 {
5501  int ret = -1;
5502  switch (metric) {
5503  case PM_MenuVMargin:
5504  case PM_MenuHMargin:
5505  ret = 0;
5506  break;
5509  ret = 1;
5510  break;
5512  ret = 0;
5513  break;
5514 #ifndef QT_NO_SLIDER
5515  case PM_SliderThickness:
5516  ret = 15;
5517  break;
5518  case PM_SliderLength:
5520  ret = 11;
5521  break;
5523  ret = 5;
5524  break;
5526  if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
5527  int size = 15;
5528  if (slider->tickPosition & QSlider::TicksBelow)
5529  ++size;
5530  if (slider->tickPosition & QSlider::TicksAbove)
5531  ++size;
5532  ret = size;
5533  break;
5534  }
5535 #endif // QT_NO_SLIDER
5536  case PM_ScrollBarExtent:
5537  ret = 16;
5538  break;
5539  case PM_ScrollBarSliderMin:
5540  ret = 26;
5541  break;
5543  ret = 1;
5544  break;
5545  case PM_MenuBarItemSpacing:
5546  ret = 3;
5547  break;
5548  case PM_MenuBarVMargin:
5549  ret = 2;
5550  break;
5551  case PM_MenuBarHMargin:
5552  ret = 0;
5553  break;
5554  case PM_MenuBarPanelWidth:
5555  ret = 1;
5556  break;
5558  ret = 9;
5559  break;
5561  ret = 2;
5562  break;
5563  case PM_ToolBarItemSpacing:
5564  ret = 1;
5565  break;
5566  case PM_ToolBarItemMargin:
5567  ret = 1;
5568  break;
5569  case PM_ToolBarFrameWidth:
5570  ret = 2;
5571  break;
5572  case PM_SplitterWidth:
5573  ret = 6;
5574  break;
5576  ret = 6;
5577  break;
5579  ret = 20;
5580  break;
5581  case PM_DefaultFrameWidth:
5582 #ifndef QT_NO_MENU
5583  if (qobject_cast<const QMenu *>(widget)) {
5584  ret = 1;
5585  break;
5586  }
5587 #endif
5588  ret = 2;
5589  break;
5591  ret = 4;
5592  break;
5593  case PM_TitleBarHeight:
5594 #ifdef QT3_SUPPORT
5595  if (widget && widget->inherits("Q3DockWindowTitleBar")) {
5596  // Q3DockWindow has smaller title bars than QDockWidget
5597  ret = qMax(widget->fontMetrics().height(), 20);
5598  } else
5599 #endif
5600  ret = qMax(widget ? widget->fontMetrics().height() :
5601  (option ? option->fontMetrics.height() : 0), 30);
5602  break;
5604  return -1;
5606  return 2;
5609  return -1; // rely on layoutHorizontalSpacing()
5610  case PM_LayoutLeftMargin:
5611  case PM_LayoutTopMargin:
5612  case PM_LayoutRightMargin:
5613  case PM_LayoutBottomMargin:
5614  {
5615  bool isWindow = false;
5616  if (option) {
5617  isWindow = (option->state & State_Window);
5618  } else if (widget) {
5619  isWindow = widget->isWindow();
5620  }
5621 
5622  if (isWindow) {
5623  ret = 11;
5624  } else {
5625  ret = 9;
5626  }
5627  }
5628  default:
5629  break;
5630  }
5631 
5632  return ret != -1 ? ret : QWindowsStyle::pixelMetric(metric, option, widget);
5633 }
5634 
5639 {
5640  QPalette palette;
5641 
5643  palette.setBrush(QPalette::Disabled, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5644  palette.setBrush(QPalette::Disabled, QPalette::Light, QColor(QRgb(0xffffffff)));
5645  palette.setBrush(QPalette::Disabled, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5646  palette.setBrush(QPalette::Disabled, QPalette::Dark, QColor(QRgb(0xff555555)));
5647  palette.setBrush(QPalette::Disabled, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5648  palette.setBrush(QPalette::Disabled, QPalette::Text, QColor(QRgb(0xffc7c7c7)));
5651  palette.setBrush(QPalette::Disabled, QPalette::Base, QColor(QRgb(0xffefefef)));
5653  palette.setBrush(QPalette::Disabled, QPalette::Window, QColor(QRgb(0xffefefef)));
5654  palette.setBrush(QPalette::Disabled, QPalette::Shadow, QColor(QRgb(0xff000000)));
5655  palette.setBrush(QPalette::Disabled, QPalette::Highlight, QColor(QRgb(0xff567594)));
5657  palette.setBrush(QPalette::Disabled, QPalette::Link, QColor(QRgb(0xff0000ee)));
5659  palette.setBrush(QPalette::Active, QPalette::WindowText, QColor(QRgb(0xff000000)));
5660  palette.setBrush(QPalette::Active, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5661  palette.setBrush(QPalette::Active, QPalette::Light, QColor(QRgb(0xffffffff)));
5662  palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5663  palette.setBrush(QPalette::Active, QPalette::Dark, QColor(QRgb(0xff555555)));
5664  palette.setBrush(QPalette::Active, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5665  palette.setBrush(QPalette::Active, QPalette::Text, QColor(QRgb(0xff000000)));
5666  palette.setBrush(QPalette::Active, QPalette::BrightText, QColor(QRgb(0xffffffff)));
5667  palette.setBrush(QPalette::Active, QPalette::ButtonText, QColor(QRgb(0xff000000)));
5668  palette.setBrush(QPalette::Active, QPalette::Base, QColor(QRgb(0xffffffff)));
5670  palette.setBrush(QPalette::Active, QPalette::Window, QColor(QRgb(0xffefefef)));
5671  palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(QRgb(0xff000000)));
5672  palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(QRgb(0xff678db2)));
5674  palette.setBrush(QPalette::Active, QPalette::Link, QColor(QRgb(0xff0000ee)));
5675  palette.setBrush(QPalette::Active, QPalette::LinkVisited, QColor(QRgb(0xff52188b)));
5677  palette.setBrush(QPalette::Inactive, QPalette::Button, QColor(QRgb(0xffdddfe4)));
5678  palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(QRgb(0xffffffff)));
5679  palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(QRgb(0xffffffff)));
5680  palette.setBrush(QPalette::Inactive, QPalette::Dark, QColor(QRgb(0xff555555)));
5681  palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(QRgb(0xffc7c7c7)));
5682  palette.setBrush(QPalette::Inactive, QPalette::Text, QColor(QRgb(0xff000000)));
5685  palette.setBrush(QPalette::Inactive, QPalette::Base, QColor(QRgb(0xffffffff)));
5687  palette.setBrush(QPalette::Inactive, QPalette::Window, QColor(QRgb(0xffefefef)));
5688  palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(QRgb(0xff000000)));
5689  palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(QRgb(0xff678db2)));
5691  palette.setBrush(QPalette::Inactive, QPalette::Link, QColor(QRgb(0xff0000ee)));
5693  return palette;
5694 }
5695 
5700 {
5701  if (qobject_cast<QPushButton *>(widget)
5702 #ifndef QT_NO_COMBOBOX
5703  || qobject_cast<QComboBox *>(widget)
5704 #endif
5705 #ifndef QT_NO_SPINBOX
5706  || qobject_cast<QAbstractSpinBox *>(widget)
5707 #endif
5708  || qobject_cast<QCheckBox *>(widget)
5709 #ifndef QT_NO_GROUPBOX
5710  || qobject_cast<QGroupBox *>(widget)
5711 #endif
5712  || qobject_cast<QRadioButton *>(widget)
5713 #ifndef QT_NO_SPLITTER
5714  || qobject_cast<QSplitterHandle *>(widget)
5715 #endif
5716 #ifndef QT_NO_TABBAR
5717  || qobject_cast<QTabBar *>(widget)
5718 #endif
5719  ) {
5720  widget->setAttribute(Qt::WA_Hover);
5721  }
5722 
5723  if (widget->inherits("QWorkspaceTitleBar")
5724  || widget->inherits("QDockSeparator")
5725  || widget->inherits("QDockWidgetSeparator")
5726  || widget->inherits("Q3DockWindowResizeHandle")) {
5727  widget->setAttribute(Qt::WA_Hover);
5728  }
5729 
5730  if (false // to simplify the #ifdefs
5731 #ifndef QT_NO_MENUBAR
5732  || qobject_cast<QMenuBar *>(widget)
5733 #endif
5734 #ifdef QT3_SUPPORT
5735  || widget->inherits("Q3ToolBar")
5736 #endif
5737 #ifndef QT_NO_TOOLBAR
5739  || (widget && qobject_cast<QToolBar *>(widget->parent()))
5740 #endif
5741  ) {
5743  }
5744 
5745 #ifndef QT_NO_PROGRESSBAR
5746  if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget))
5747  widget->installEventFilter(this);
5748 #endif
5749 
5750 #if defined QPlastique_MaskButtons
5751  if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
5752  widget->installEventFilter(this);
5753 #endif
5754 }
5755 
5760 {
5761  if (qobject_cast<QPushButton *>(widget)
5762 #ifndef QT_NO_COMBOBOX
5763  || qobject_cast<QComboBox *>(widget)
5764 #endif
5765 #ifndef QT_NO_SPINBOX
5766  || qobject_cast<QAbstractSpinBox *>(widget)
5767 #endif
5768  || qobject_cast<QCheckBox *>(widget)
5769 #ifndef QT_NO_GROUPBOX
5770  || qobject_cast<QGroupBox *>(widget)
5771 #endif
5772 #ifndef QT_NO_SPLITTER
5773  || qobject_cast<QSplitterHandle *>(widget)
5774 #endif
5775 #ifndef QT_NO_TABBAR
5776  || qobject_cast<QTabBar *>(widget)
5777 #endif
5778  || qobject_cast<QRadioButton *>(widget)) {
5779  widget->setAttribute(Qt::WA_Hover, false);
5780  }
5781 
5782  if (widget->inherits("QWorkspaceTitleBar")
5783  || widget->inherits("QDockSeparator")
5784  || widget->inherits("QDockWidgetSeparator")
5785  || widget->inherits("Q3DockWindowResizeHandle")) {
5786  widget->setAttribute(Qt::WA_Hover, false);
5787  }
5788 
5789  if (false // to simplify the #ifdefs
5790 #ifndef QT_NO_MENUBAR
5791  || qobject_cast<QMenuBar *>(widget)
5792 #endif
5793 #ifndef QT_NO_TOOLBOX
5794  || qobject_cast<QToolBox *>(widget)
5795 #endif
5796 #ifdef QT3_SUPPORT
5797  || widget->inherits("Q3ToolBar")
5798 #endif
5799 #ifndef QT_NO_TOOLBAR
5801  || (widget && qobject_cast<QToolBar *>(widget->parent()))
5802 #endif
5803  ) {
5805  }
5806 
5807 #ifndef QT_NO_PROGRESSBAR
5808  if (AnimateBusyProgressBar && qobject_cast<QProgressBar *>(widget)) {
5810  widget->removeEventFilter(this);
5811  d->bars.removeAll(static_cast<QProgressBar*>(widget));
5812  }
5813 #endif
5814 
5815 #if defined QPlastique_MaskButtons
5816  if (qobject_cast<QPushButton *>(widget) || qobject_cast<QToolButton *>(widget))
5817  widget->removeEventFilter(this);
5818 #endif
5819 }
5820 
5825 {
5826  QWindowsStyle::polish(app);
5827 }
5828 
5833 {
5834  QWindowsStyle::polish(pal);
5835 #ifdef Q_WS_MAC
5837 #endif
5838 }
5839 
5844 {
5846 }
5847 
5852  const QWidget *widget) const
5853 {
5854  return QWindowsStyle::standardIconImplementation(standardIcon, option, widget);
5855 }
5856 
5861  const QWidget *widget) const
5862 {
5863  return QWindowsStyle::standardPixmap(standardPixmap, opt, widget);
5864 }
5865 
5866 // this works as long as we have at most 16 different control types
5867 #define CT1(c) CT2(c, c)
5868 #define CT2(c1, c2) (((uint)c1 << 16) | (uint)c2)
5869 
5874  QSizePolicy::ControlType control2,
5875  Qt::Orientation orientation,
5876  const QStyleOption * /* option */,
5877  const QWidget * /* widget */) const
5878 {
5880 
5881  if (control2 == QSizePolicy::ButtonBox)
5882  return 11;
5883 
5884  if ((control1 | control2) & ButtonMask)
5885  return (orientation == Qt::Horizontal) ? 10 : 9;
5886 
5887  switch (CT2(control1, control2)) {
5888  case CT1(QSizePolicy::Label):
5897  return 5;
5900  case CT1(QSizePolicy::CheckBox):
5901  if (orientation == Qt::Vertical)
5902  return 2;
5904  if (orientation == Qt::Vertical)
5905  return 1;
5906  }
5907 
5908  if (orientation == Qt::Horizontal
5909  && (control2 & (QSizePolicy::CheckBox | QSizePolicy::RadioButton)))
5910  return 8;
5911 
5912  if ((control1 | control2) & (QSizePolicy::Frame
5915  return 11;
5916  }
5917 
5918  if ((control1 | control2) & (QSizePolicy::Line | QSizePolicy::Slider
5921  return 7;
5922 
5923  return 6;
5924 }
5925 
5930 {
5931 #ifndef QT_NO_PROGRESSBAR
5933 
5934  switch (event->type()) {
5935  case QEvent::Show:
5936  if (QProgressBar *bar = qobject_cast<QProgressBar *>(watched)) {
5937  d->bars.append(bar);
5938  if (d->bars.size() == 1) {
5939  Q_ASSERT(ProgressBarFps > 0);
5940  d->timer.start();
5941  d->progressBarAnimateTimer = startTimer(1000 / ProgressBarFps);
5942  }
5943  }
5944  break;
5945  case QEvent::Destroy:
5946  case QEvent::Hide:
5947  if(!d->bars.isEmpty()) {
5948  d->bars.removeAll(reinterpret_cast<QProgressBar*>(watched));
5949  if (d->bars.isEmpty()) {
5950  killTimer(d->progressBarAnimateTimer);
5951  d->progressBarAnimateTimer = 0;
5952  }
5953  }
5954  break;
5955 #if defined QPlastique_MaskButtons
5956  case QEvent::Resize:
5957  if (qobject_cast<QPushButton *>(watched) || qobject_cast<QToolButton *>(watched)) {
5958  QWidget *widget = qobject_cast<QWidget *>(watched);
5959  QRect rect = widget->rect();
5960  QRegion region(rect);
5961  region -= QRect(rect.left(), rect.top(), 2, 1);
5962  region -= QRect(rect.left(), rect.top() + 1, 1, 1);
5963  region -= QRect(rect.left(), rect.bottom(), 2, 1);
5964  region -= QRect(rect.left(), rect.bottom() - 1, 1, 1);
5965  region -= QRect(rect.right() - 1, rect.top(), 2, 1);
5966  region -= QRect(rect.right(), rect.top() + 1, 1, 1);
5967  region -= QRect(rect.right() - 1, rect.bottom(), 2, 1);
5968  region -= QRect(rect.right(), rect.bottom() - 1, 1, 1);
5969  widget->setMask(region);
5970  }
5971  break;
5972 #endif
5973  default:
5974  break;
5975  }
5976 #endif // QT_NO_PROGRESSBAR
5977 
5978  return QWindowsStyle::eventFilter(watched, event);
5979 }
5980 
5985 {
5986 #ifndef QT_NO_PROGRESSBAR
5988 
5989  if (event->timerId() == d->progressBarAnimateTimer) {
5990  Q_ASSERT(ProgressBarFps > 0);
5991  d->animateStep = d->timer.elapsed() / (1000 / ProgressBarFps);
5992  foreach (QProgressBar *bar, d->bars) {
5993  if (AnimateProgressBar || (bar->minimum() == 0 && bar->maximum() == 0))
5994  bar->update();
5995  }
5996  }
5997 #endif // QT_NO_PROGRESSBAR
5998  event->ignore();
5999 }
6000 
6002 
6003 #endif // !defined(QT_NO_STYLE_PLASTIQUE) || defined(QT_PLUGIN)
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
#define BEGIN_STYLE_PIXMAPCACHE(a)
Definition: qstyle_p.h:76
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
Definition: qobject.cpp:1623
void setTransform(const QTransform &transform, bool combine=false)
Sets the world transformation matrix.
Definition: qpainter.cpp:9547
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void setRed(int red)
Sets the red color component of this color to red.
Definition: qcolor.cpp:1143
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
void setPointSize(int)
Sets the point size to pointSize.
Definition: qfont.cpp:1099
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
Definition: qstyle.cpp:2120
static const char *const qt_plastique_slider_horizontalhandle_up[]
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget=0) const
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
void polish(QApplication *)
Reimplemented Function
void setRgb(int r, int g, int b, int a=255)
Sets the RGB value to r, g, b and the alpha value to a.
Definition: qcolor.cpp:980
void unpolish(QApplication *)
Reimplemented Function
const T * constData() const
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
#define QT_NO_GROUPBOX
const QBrush & highlight() const
Returns the highlight brush of the current color group.
Definition: qpalette.h:140
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition: qpixmap.cpp:2197
bool eventFilter(QObject *watched, QEvent *event)
Reimplemented Function
int width(const QString &, int len=-1) const
Returns the width in pixels of the first len characters of text.
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling...
Definition: qpainter.cpp:3502
unsigned int QRgb
Definition: qrgb.h:53
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
static QLinearGradient qMapGradientToRect(const QLinearGradient &gradient, const QRectF &rect)
static QBrush qBrushDark(QBrush brush, int dark)
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
static void qt_plastique_drawFrame(QPainter *painter, const QStyleOption *option, const QWidget *widget)
const QBrush & base() const
Returns the base brush of the current color group.
Definition: qpalette.h:130
int type
Definition: qmetatype.cpp:239
static QColor mergedColors(const QColor &colorA, const QColor &colorB, int factor=50)
static QBrush qMapBrushToRect(const QBrush &brush, const QRectF &rect)
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
void setColor(int i, QRgb c)
Sets the color at the given index in the color table, to the given to colorValue. ...
Definition: qimage.cpp:1850
StyleHint
This enum describes the available style hints.
Definition: qstyle.h:640
double qreal
Definition: qglobal.h:1193
#define disabled
The QStyleHintReturn class provides style hints that return more than basic data types.
Definition: qstyleoption.h:907
static const char *const qt_plastique_slider_verticalhandle_left[]
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
Definition: qbrush.cpp:1475
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QStyleOptionDockWidget class is used to describe the parameters for drawing a dock widget...
Definition: qstyleoption.h:504
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static void qt_plastique_drawShadedPanel(QPainter *painter, const QStyleOption *option, bool base, const QWidget *widget)
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QPointer< QWidget > widget
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:57
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
void drawPoints(const QPointF *points, int pointCount)
Draws the first pointCount points in the array points using the current pen&#39;s color.
Definition: qpainter.cpp:3816
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=0) const
Reimplemented Function
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
#define it(className, varName)
The QStyleOptionMenuItem class is used to describe the parameter necessary for drawing a menu item...
Definition: qstyleoption.h:435
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:251
#define QT_NO_SPLITTER
bool isWindow() const
Returns true if the widget is an independent window, otherwise returns false.
Definition: qwidget.h:945
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
QPoint p1() const
Returns the line&#39;s start point.
Definition: qline.h:132
static const char *const qt_toolbarhandle[]
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget=0) const =0
Returns the rectangle containing the specified subControl of the given complex control (with the styl...
void rotate(qreal a)
Rotates the coordinate system the given angle clockwise.
Definition: qpainter.cpp:3287
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
QFont font
the font used for the menu item text
Definition: qstyleoption.h:454
ComplexControl
This enum describes the available complex controls.
Definition: qstyle.h:386
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
Reimplemented Function
QPoint p2() const
Returns the line&#39;s end point.
Definition: qline.h:137
static C reverse(const C &l)
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
The QConicalGradient class is used in combination with QBrush to specify a conical gradient brush...
Definition: qbrush.h:329
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
bool eventFilter(QObject *o, QEvent *e)
Reimplemented Function
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
void removeEventFilter(QObject *)
Removes an event filter object obj from this object.
Definition: qobject.cpp:2099
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
Reimplemented Function
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
void setGreen(int green)
Sets the green color component of this color to green.
Definition: qcolor.cpp:1170
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
QRect normalized() const
Returns a normalized rectangle; i.e., a rectangle that has a non-negative width and height...
Definition: qrect.cpp:322
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt=0, const QWidget *widget=0) const
#define END_STYLE_PIXMAPCACHE
Definition: qstyle_p.h:96
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int maxIconWidth
the maximum icon width for the icon in the menu item
Definition: qstyleoption.h:452
The QStyleOptionToolBar class is used to describe the parameters for drawing a toolbar.
Definition: qstyleoption.h:369
int & ry()
Returns a reference to the y coordinate of this point.
Definition: qpoint.h:143
QPalette::ColorRole backgroundRole() const
Returns the background role of the widget.
Definition: qwidget.cpp:4677
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int styleHint(StyleHint hint, const QStyleOption *option=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const
Reimplemented Function
~QPlastiqueStyle()
Destructs the QPlastiqueStyle object.
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
Definition: qstyle.cpp:532
QStyle::SubControls activeSubControls
This variable holds a bitwise OR of the sub-controls that are active for the complex control...
Definition: qstyleoption.h:694
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const
Reimplemented Function
QTransform & translate(qreal dx, qreal dy)
Moves the coordinate system dx along the x axis and dy along the y axis, and returns a reference to t...
Definition: qtransform.cpp:417
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
The QProgressBar widget provides a horizontal or vertical progress bar.
Definition: qprogressbar.h:58
#define QT_NO_MENUBAR
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
The QString class provides a Unicode character string.
Definition: qstring.h:83
QFontMetrics fontMetrics
the font metrics that should be used when drawing text in the control
Definition: qstyleoption.h:91
void setHeight(int h)
Sets the height to the given height.
Definition: qsize.h:135
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QStyleOptionToolBox class is used to describe the parameters needed for drawing a tool box...
Definition: qstyleoption.h:633
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
static const char *const qt_scrollbar_slider_pattern_horizontal[]
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
#define Q_D(Class)
Definition: qglobal.h:2482
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
QPlastiqueStyle()
Constructs a QPlastiqueStyle object.
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static const uint base
Definition: qurl.cpp:268
void append(const T &t)
void drawPoint(const QPointF &pt)
Draws a single point at the given position using the current pen&#39;s color.
Definition: qpainter.h:676
static void qt_plastique_draw_frame(QPainter *painter, const QRect &rect, const QStyleOption *option, QFrame::Shadow shadow=QFrame::Plain)
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
QString text
the text for the menu item
Definition: qstyleoption.h:450
static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown=false)
Converts the given logicalValue to a pixel position.
Definition: qstyle.cpp:2176
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
void drawPartialFrame(QPainter *painter, const QStyleOptionComplex *option, const QRect &rect, const QWidget *widget) const
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
static QPixmap * find(const QString &key)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static const char *const qt_simple_toolbarhandle[]
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
bool isIdentity() const
Returns true if the matrix is the identity matrix, otherwise returns false.
Definition: qtransform.h:204
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
QGradientStops stops() const
Returns the stop points for this gradient.
Definition: qbrush.cpp:1520
void timerEvent(QTimerEvent *event)
Reimplemented Function
void setCurrentColorGroup(ColorGroup cg)
Set the palette&#39;s current color group to cg.
Definition: qpalette.h:105
QColor darker(int f=200) const
Returns a darker (or lighter) color, but does not change this object.
Definition: qcolor.h:301
static const char *const qt_scrollbar_button_arrow_right[]
static const char *const qt_scrollbar_slider_pattern_vertical[]
int lineWidth
the line width for drawing the frame
Definition: qstyleoption.h:124
The QStyleOptionProgressBarV2 class is used to describe the parameters necessary for drawing a progre...
Definition: qstyleoption.h:417
int width() const
Returns the width.
Definition: qsize.h:126
void drawText(const QPointF &p, const QString &s)
Draws the given text with the currently defined text direction, beginning at the given position...
Definition: qpainter.cpp:6231
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
void setBackgroundRole(QPalette::ColorRole)
Sets the background role of the widget to role.
Definition: qwidget.cpp:4708
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
void polish(QWidget *widget)
Reimplemented Function
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static const char *const qt_plastique_slider_horizontalhandle[]
ushort value
Returns the value color component of this color.
Definition: qcolor.h:252
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
void drawDial(const QStyleOptionSlider *option, QPainter *painter)
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static const int windowsTabSpacing
static const int windowsRightBorder
void setBold(bool)
If enable is true sets the font&#39;s weight to QFont::Bold ; otherwise sets the weight to QFont::Normal...
Definition: qfont.h:352
QPoint bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:291
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
Reimplemented Function
static const char *const qt_scrollbar_button_arrow_left[]
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
void drawLines(const QLineF *lines, int lineCount)
Draws the first lineCount lines in the array lines using the current pen.
Definition: qpainter.cpp:4873
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static const int blueFrameWidth
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static QBrush qBrushLight(QBrush brush, int light)
Shadow
This enum type defines the types of shadow that are used to give a 3D effect to frames.
Definition: qframe.h:96
ContentsType
This enum describes the available contents types.
Definition: qstyle.h:602
The QToolBar class provides a movable panel that contains a set of controls.
Definition: qtoolbar.h:62
The QStyleOptionSpinBox class is used to describe the parameters necessary for drawing a spin box...
Definition: qstyleoption.h:729
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
const QFont & font() const
Returns the currently set font used for drawing text.
Definition: qpainter.cpp:4312
const char * name
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
Reimplemented Function
static const int windowsItemVMargin
QTransform & rotate(qreal a, Qt::Axis axis=Qt::ZAxis)
Rotates the coordinate system counterclockwise by the given angle about the specified axis and return...
Definition: qtransform.cpp:615
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434
int layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
int maximum
the progress bar&#39;s maximum value
Definition: qprogressbar.h:63
void setRight(int pos)
Sets the right edge of the rectangle to the given x coordinate.
Definition: qrect.h:264
QFontMetrics fontMetrics() const
Returns the font metrics for the widget&#39;s current font.
Definition: qwidget.h:984
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given primitive element with the provided painter using the style options specified by opti...
The QStyleOptionFocusRect class is used to describe the parameters for drawing a focus rectangle with...
Definition: qstyleoption.h:103
Q_CORE_EXPORT void qWarning(const char *,...)
int & rx()
Returns a reference to the x coordinate of this point.
Definition: qpoint.h:140
void setSize(const QSize &s)
Sets the size of the rectangle to the given size.
Definition: qrect.h:448
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
Definition: qcoreevent.h:346
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
void transpose()
Swaps the width and height values.
Definition: qsize.cpp:196
The QStyleOptionFrame class is used to describe the parameters for drawing a frame.
Definition: qstyleoption.h:118
unsigned int uint
Definition: qglobal.h:996
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
T findChild(const QString &aName=QString()) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object.
Definition: qobject.h:158
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
Definition: qpainter.cpp:9579
int pixelMetric(PixelMetric pm, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
The QStyleOptionTabWidgetFrame class is used to describe the parameters for drawing the frame around ...
Definition: qstyleoption.h:175
The QRegion class specifies a clip region for a painter.
Definition: qregion.h:68
The QStyleOptionTabBarBase class is used to describe the base of a tab bar, i.e.
Definition: qstyleoption.h:218
static const char *const qt_scrollbar_button_down[]
__int64 qint64
Definition: qglobal.h:942
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
MenuItemType menuItemType
the type of menu item
Definition: qstyleoption.h:445
int count() const
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
Definition: qobject.h:275
static const int windowsArrowHMargin
void setMask(const QBitmap &)
Causes only the pixels of the widget for which bitmap has a corresponding 1 bit to be visible...
Definition: qwidget.cpp:13309
void setBlue(int blue)
Sets the blue color component of this color to blue.
Definition: qcolor.cpp:1199
The QFontInfo class provides general information about fonts.
Definition: qfontinfo.h:54
static const int windowsItemHMargin
FrameFeatures features
a bitwise OR of the features that describe this frame.
Definition: qstyleoption.h:143
bool contains(const QPoint &p, bool proper=false) const
Returns true if the given point is inside or on the edge of the rectangle, otherwise returns false...
Definition: qrect.cpp:1101
static void qt_plastique_draw_mdibutton(QPainter *painter, const QStyleOptionTitleBar *option, const QRect &tmp, bool hover, bool sunken)
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
static const int windowsSepHeight
void moveCenter(const QPoint &p)
Moves the rectangle, leaving the center point at the given position.
Definition: qrect.cpp:840
#define rgb(r, g, b)
Definition: qcolor_p.cpp:130
int styleHint(StyleHint hint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const
Reimplemented Function
Q_CORE_EXPORT QTextStream & center(QTextStream &s)
QPoint topRight() const
Returns the position of the rectangle&#39;s top-right corner.
Definition: qrect.h:294
QList< QProgressBar * > bars
void fill(const QColor &fillColor=Qt::white)
Fills the pixmap with the given color.
Definition: qpixmap.cpp:1080
void setColor(const QColor &color)
Sets the brush color to the given color.
Definition: qbrush.cpp:725
#define QT_NO_PROGRESSBAR
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QPoint center() const
Returns the center point of the rectangle.
Definition: qrect.h:300
const QBrush & shadow() const
Returns the shadow brush of the current color group.
Definition: qpalette.h:139
static const bool AnimateBusyProgressBar
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter.
Definition: qstyle.cpp:570
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition: qpalette.h:124
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
void setTexture(const QPixmap &pixmap)
Sets the brush pixmap to pixmap.
Definition: qbrush.cpp:802
The QStyleHintReturnMask class provides style hints that return a QRegion.
Definition: qstyleoption.h:923
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
static const char *const qt_scrollbar_button_arrow_up[]
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction...
Definition: qstyle.cpp:2087
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
void setClipRegion(const QRegion &, Qt::ClipOperation op=Qt::ReplaceClip)
Sets the clip region to the given region using the specified clip operation.
Definition: qpainter.cpp:2917
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
QPoint bottomLeft() const
Returns the position of the rectangle&#39;s bottom-left corner.
Definition: qrect.h:297
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
static const int ProgressBarFps
void setAlphaF(qreal alpha)
Sets the alpha of this color to alpha.
Definition: qcolor.cpp:1117
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
void setLeft(int pos)
Sets the left edge of the rectangle to the given x coordinate.
Definition: qrect.h:258
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:168
The QLinearGradient class is used in combination with QBrush to specify a linear gradient brush...
Definition: qbrush.h:280
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
const QBrush & highlightedText() const
Returns the highlighted text brush of the current color group.
Definition: qpalette.h:141
#define QT_NO_SPINBOX
int midLineWidth
the mid-line width for drawing the frame
Definition: qstyleoption.h:125
static void qt_plastique_draw_handle(QPainter *painter, const QStyleOption *option, const QRect &rect, Qt::Orientation orientation, const QWidget *widget)
T qstyleoption_cast(const QStyleOption *opt)
Definition: qstyleoption.h:885
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=0) const
Reimplemented Function
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
static const bool AnimateProgressBar
int tabWidth
the tab width for the menu item
Definition: qstyleoption.h:453
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
static QString elliditide(const QString &text, const QFontMetrics &fontMetrics, const QRect &rect, int *textWidth=0)
static const char *const qt_scrollbar_button_left[]
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
void setRect(int x, int y, int w, int h)
Sets the coordinates of the rectangle&#39;s top-left corner to ({x}, {y}), and its size to the given widt...
Definition: qrect.h:400
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201
void installEventFilter(QObject *)
Installs an event filter filterObj on this object.
Definition: qobject.cpp:2070
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setStops(const QGradientStops &stops)
Replaces the current set of stop points with the given stopPoints.
Definition: qbrush.cpp:1504
static void qt_plastique_draw_gradient(QPainter *painter, const QRect &rect, const QColor &gradientStart, const QColor &gradientStop)
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const =0
Draws the given element with the provided painter with the style options specified by option...
void setAlpha(int alpha)
Sets the alpha of this color to alpha.
Definition: qcolor.cpp:1094
The QStyleOptionComboBox class is used to describe the parameter for drawing a combobox.
Definition: qstyleoption.h:796
int & rheight()
Returns a reference to the height.
Definition: qsize.h:144
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
static const char *const qt_titlebar_context_help[]
int height() const
Returns the height.
Definition: qsize.h:129
Qt::LayoutDirection direction
the text layout direction that should be used when drawing text in the control
Definition: qstyleoption.h:89
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static const int windowsItemFrame
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=0) const
Reimplemented Function
The QTextOption class provides a description of general rich text properties.
Definition: qtextoption.h:59
void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle&#39;s top-left corner to *x and *y, and its dimensions to *width a...
Definition: qrect.h:392
#define QT_NO_TOOLBOX
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QStyleOptionFrameV2 class is used to describe the parameters necessary for drawing a frame in Qt ...
Definition: qstyleoption.h:134
int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
void setAttribute(Qt::WidgetAttribute, bool on=true)
Sets the attribute attribute on this widget if on is true; otherwise clears the attribute.
Definition: qwidget.cpp:11087
const QStyle * proxy() const
Definition: qstyle.cpp:2546
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
QString title
the title of the dock window
Definition: qstyleoption.h:510
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QPlastiqueStyle class provides a widget style similar to the Plastik style available in KDE...
The QStyleOptionTab class is used to describe the parameters for drawing a tab bar.
Definition: qstyleoption.h:304
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const
Reimplemented Function
ControlElement
This enum represents a control element.
Definition: qstyle.h:217
The QStyleOptionSlider class is used to describe the parameters needed for drawing a slider...
Definition: qstyleoption.h:701
void setWrapMode(WrapMode wrap)
Sets the option&#39;s text wrap mode to the given mode.
Definition: qtextoption.h:109
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static void qBrushSetAlphaF(QBrush *brush, qreal alpha)
void setFont(const QFont &f)
Sets the painter&#39;s font to the given font.
Definition: qpainter.cpp:4288
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis...
Definition: qtransform.cpp:462
bool isIdentity() const
Returns true if the matrix is the identity matrix, otherwise returns false.
Definition: qmatrix.h:166
const QBrush & buttonText() const
Returns the button text foreground brush of the current color group.
Definition: qpalette.h:138
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
RenderHints renderHints() const
Returns a flag that specifies the rendering hints that are set for this painter.
Definition: qpainter.cpp:7675
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRegion subtracted(const QRegion &r) const
Returns a region which is r subtracted from this region.
Definition: qregion.h:114
The QWindowsStyle class provides a Microsoft Windows-like look and feel.
Definition: qwindowsstyle.h:57
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
int minimum
the progress bar&#39;s minimum value
Definition: qprogressbar.h:62
void unpolish(QWidget *widget)
Reimplemented Function
static const char *const qt_plastique_slider_verticalhandle[]
static const char *const qt_scrollbar_button_arrow_down[]
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
static const char *const qt_scrollbar_button_up[]
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
The QStyleOptionProgressBar class is used to describe the parameters necessary for drawing a progress...
Definition: qstyleoption.h:396
int height() const
Returns the height of the font.
bool isValid() const
Returns true if the rectangle is valid, otherwise returns false.
Definition: qrect.h:237
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298
void translate(int dx, int dy)
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position...
Definition: qrect.h:312
const QBrush & button() const
Returns the button brush of the current color group.
Definition: qpalette.h:125
int titleBarState
the state of the title bar
Definition: qstyleoption.h:824
Orientation
Definition: qnamespace.h:174
const QMatrix & worldMatrix() const
Returns the world transformation matrix.
Definition: qpainter.cpp:3024
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
#define QT_NO_COMBOBOX
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
QPointF center() const
Returns the center point of the rectangle.
Definition: qrect.h:686
The QStyleOptionButton class is used to describe the parameters for drawing buttons.
Definition: qstyleoption.h:279
QPalette standardPalette() const
Reimplemented Function
#define CT1(c)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
static const int windowsCheckMarkWidth
const QBrush & window() const
Returns the window (general background) brush of the current color group.
Definition: qpalette.h:135
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
static float pointSize(const QFontDef &fd, int dpi)
Definition: qfont_win.cpp:90
#define INT_MAX
QStyle::SubControls subControls
This variable holds a bitwise OR of the sub-controls to be drawn for the complex control.
Definition: qstyleoption.h:693
#define enabled
bool end()
Ends painting.
Definition: qpainter.cpp:1929
#define QT_NO_TABBAR
int & rwidth()
Returns a reference to the width.
Definition: qsize.h:141
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
#define text
Definition: qobjectdefs.h:80
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=0) const
Reimplemented Function
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition: qpalette.h:129
static const char *const qt_scrollbar_button_right[]
int size() const
SubElement
This enum represents a sub-area of a widget.
Definition: qstyle.h:289
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
#define CT2(c1, c2)
int styleHint(StyleHint sh, const QStyleOption *opt=0, const QWidget *w=0, QStyleHintReturn *shret=0) const
Reimplemented Function
QPalette resolve(const QPalette &) const
Returns a new QPalette that has attributes copied from other.
Definition: qpalette.cpp:1101
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60