source: trunk/doc/src/snippets/javastyle.cpp@ 1030

Last change on this file since 1030 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 110.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:BSD$
10** You may use this file under the terms of the BSD license as follows:
11**
12** "Redistribution and use in source and binary forms, with or without
13** modification, are permitted provided that the following conditions are
14** met:
15** * Redistributions of source code must retain the above copyright
16** notice, this list of conditions and the following disclaimer.
17** * Redistributions in binary form must reproduce the above copyright
18** notice, this list of conditions and the following disclaimer in
19** the documentation and/or other materials provided with the
20** distribution.
21** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22** the names of its contributors may be used to endorse or promote
23** products derived from this software without specific prior written
24** permission.
25**
26** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include <QtGui>
42
43#include "javastyle.h"
44#include <math.h>
45
46static const int windowsItemFrame = 2;
47static const int windowsSepHeight = 2;
48static const int windowsItemHMargin = 3;
49static const int windowsItemVMargin = 2;
50static const int windowsArrowHMargin = 6;
51static const int windowsTabSpacing = 12;
52static const int windowsCheckMarkHMargin = 2;
53static const int windowsRightBorder = 15;
54static const int windowsCheckMarkWidth = 12;
55
56JavaStyle::JavaStyle()
57{
58 qApp->setPalette(standardPalette());
59}
60
61
62inline QPoint JavaStyle::adjustScrollPoint(const QPoint &point,
63 Qt::Orientation orientation,
64 bool add) const
65{
66 int adder = add ? -1 : 1;
67 QPoint retPoint;
68
69 if (orientation == Qt::Horizontal) {
70 retPoint = QPoint(point.y() * adder, point.x());
71 } else {
72 retPoint = QPoint(point.x(), point.y() * adder);
73 }
74
75 return retPoint;
76}
77
78QPalette JavaStyle::standardPalette() const
79{
80 QPalette palette = QWindowsStyle::standardPalette();
81
82 palette.setBrush(QPalette::Active, QPalette::Button,
83 QColor(184, 207, 229));
84 palette.setBrush(QPalette::Active, QPalette::WindowText,
85 Qt::black);
86 palette.setBrush(QPalette::Active, QPalette::Background,
87 QColor(238, 238, 238));
88 palette.setBrush(QPalette::Active, QPalette::Window,
89 QColor(238 ,238, 238));
90 palette.setBrush(QPalette::Active, QPalette::Base, Qt::white);
91 palette.setBrush(QPalette::Active, QPalette::AlternateBase, QColor(238, 238, 238));
92 palette.setBrush(QPalette::Active, QPalette::Text, Qt::black);
93 palette.setBrush(QPalette::Active, QPalette::BrightText, Qt::white);
94
95 palette.setBrush(QPalette::Active, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor
96 palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor
97 palette.setBrush(QPalette::Active, QPalette::Dark, QColor(106, 104, 100));
98 palette.setBrush(QPalette::Active, QPalette::Mid, QColor(122, 138, 153)); //defaultFrameColor
99 palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame
100
101 palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(184, 207, 229));
102 palette.setBrush(QPalette::Active, QPalette::HighlightedText, Qt::black);
103
104 palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(184, 207, 229));
105 palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, Qt::black);
106
107 palette.setBrush(QPalette::Disabled, QPalette::Button,
108 QColor(238, 238, 238));
109 palette.setBrush(QPalette::Disabled, QPalette::WindowText,
110 QColor(153, 153, 153));
111 palette.setBrush(QPalette::Disabled, QPalette::Background, QColor(238, 238, 238));
112
113 palette.setBrush(QPalette::Inactive, QPalette::Button,
114 QColor(184, 207, 229));
115 palette.setBrush(QPalette::Inactive, QPalette::Background,
116 QColor(238, 238, 238));
117 palette.setBrush(QPalette::Inactive, QPalette::Window,
118 QColor(238 ,238, 238));
119 palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(163, 184, 204)); // focusFrameColor
120 palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(99, 130, 191)); // tabBarBorderColor
121 palette.setBrush(QPalette::Inactive, QPalette::Dark,QColor(106, 104, 100));
122 palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(122, 138, 153)); //defaultFrame
123 palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(122, 138, 153)); // defaultFrame
124
125 return palette;
126}
127
128inline void JavaStyle::drawScrollBarArrow(const QRect &rect, QPainter *painter,
129 const QStyleOptionSlider *option,
130 bool add) const
131{
132
133 painter->save();
134
135 Qt::Orientation orient = option->orientation;
136 QPoint offset;
137
138 if (add) {
139 if (orient == Qt::Vertical) {
140 offset = rect.bottomLeft();
141 } else {
142 offset = rect.topRight();
143 }
144 } else {
145 offset = rect.topLeft();
146 }
147
148 QPainterPath arrow;
149 arrow.moveTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
150 arrow.lineTo(offset + adjustScrollPoint(QPoint(7, 5), orient, add));
151 arrow.lineTo(offset + adjustScrollPoint(QPoint(8, 5), orient, add));
152 arrow.lineTo(offset + adjustScrollPoint(QPoint(11, 8), orient, add));
153 arrow.lineTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
154
155 QColor fillColor;
156 if (option->state & State_Sunken)
157 fillColor = QColor(option->palette.color(QPalette::Button));
158 else
159 fillColor = option->palette.color(QPalette::Background);
160
161 painter->fillRect(rect, fillColor);
162
163 painter->setPen(option->palette.color(QPalette::Base));
164 int adjust = option->state & State_Sunken ? 0 : 1;
165 painter->drawRect(rect.adjusted(adjust, adjust, -1, -1));
166 painter->setPen(option->palette.color(QPalette::Mid));
167 painter->drawRect(rect.adjusted(0, 0, -1, -1));
168
169 painter->setPen(option->palette.color(QPalette::WindowText));
170 painter->setBrush(option->palette.color(QPalette::WindowText));
171 painter->drawPath(arrow);
172
173 painter->restore();
174}
175
176inline QPoint JavaStyle::adjustScrollHandlePoint(Qt::Orientation orig,
177 const QPoint &point) const
178{
179 QPoint retPoint;
180
181 if (orig == Qt::Vertical)
182 retPoint = point;
183 else
184 retPoint = QPoint(point.y(), point.x());
185
186 return retPoint;
187}
188
189void JavaStyle::drawControl(ControlElement control, const QStyleOption *option,
190 QPainter *painter, const QWidget *widget) const
191{
192
193 painter->save();
194
195 switch (control) {
196 case CE_ToolBoxTabShape: {
197 const QStyleOptionToolBox *box =
198 qstyleoption_cast<const QStyleOptionToolBox *>(option);
199
200 painter->save();
201
202 if (box->direction == Qt::RightToLeft) {
203 painter->rotate(1);
204 painter->translate(box->rect.width(), -box->rect.height());
205 }
206
207 int textWidth = box->fontMetrics.width(box->text) + 20;
208
209 QPolygon innerLine;
210 innerLine << (box->rect.topLeft() + QPoint(0, 1)) <<
211 (box->rect.topLeft() + QPoint(textWidth, 1)) <<
212 (box->rect.bottomLeft() + QPoint(textWidth + 15, -3)) <<
213 (box->rect.bottomRight() + QPoint(0, -3)) <<
214 box->rect.bottomRight() <<
215 box->rect.bottomLeft() <<
216 box->rect.topLeft();
217
218 painter->setPen(box->palette.color(QPalette::Base));
219 painter->setBrush(QColor(200, 221, 242));
220 painter->drawPolygon(innerLine);
221
222 QPolygon outerLine;
223 outerLine << (box->rect.bottomRight() + QPoint(0, -3)) <<
224 box->rect.bottomRight() <<
225 box->rect.bottomLeft() <<
226 box->rect.topLeft() <<
227 (box->rect.topLeft() + QPoint(textWidth, 0)) <<
228 (box->rect.bottomLeft() + QPoint(textWidth + 15, -4)) <<
229 (box->rect.bottomRight() + QPoint(0, -4));
230
231 painter->setPen(box->palette.color(QPalette::Midlight));
232 painter->setBrush(Qt::NoBrush);
233 painter->drawPolyline(outerLine);
234
235 painter->restore();
236 break;
237 }
238 case CE_DockWidgetTitle: {
239 const QStyleOptionDockWidgetV2 *docker =
240 new QStyleOptionDockWidgetV2(
241 *qstyleoption_cast<const QStyleOptionDockWidget *>(option));
242
243 QRect rect = docker->rect;
244 QRect titleRect = rect;
245 if (docker->verticalTitleBar) {
246 QRect r = rect;
247 QSize s = r.size();
248 s.transpose();
249 r.setSize(s);
250
251 titleRect = QRect(r.left() + rect.bottom()
252 - titleRect.bottom(),
253 r.top() + titleRect.left() - rect.left(),
254 titleRect.height(), titleRect.width());
255
256 painter->translate(r.left(), r.top() + r.width());
257 painter->rotate(-90);
258 painter->translate(-r.left(), -r.top());
259
260 rect = r;
261 }
262
263 QLinearGradient gradient(rect.topLeft(),
264 rect.bottomLeft());
265 gradient.setColorAt(1.0, QColor(191, 212, 231));
266 gradient.setColorAt(0.3, Qt::white);
267 gradient.setColorAt(0.0, QColor(221, 232, 243));
268
269 painter->setPen(Qt::NoPen);
270 painter->setBrush(gradient);
271 painter->drawRect(rect.adjusted(0, 0, -1, -1));
272
273 if (!docker->title.isEmpty()) {
274 QRect textRect = docker->fontMetrics.boundingRect(docker->title);
275 textRect.moveCenter(rect.center());
276
277 QFont font = painter->font();
278 font.setPointSize(font.pointSize() - 1);
279 painter->setFont(font);
280 painter->setPen(docker->palette.text().color());
281 painter->drawText(textRect, docker->title,
282 QTextOption(Qt::AlignHCenter |
283 Qt::AlignVCenter));
284 }
285 break;
286 }
287 case CE_RubberBand: {
288 painter->setPen(option->palette.color(QPalette::Active,
289 QPalette::WindowText));
290 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
291 break;
292 }
293 case CE_SizeGrip: {
294 break;
295 }
296 case CE_HeaderSection: {
297 const QStyleOptionHeader *header =
298 qstyleoption_cast<const QStyleOptionHeader *>(option);
299
300 painter->setPen(Qt::NoPen);
301 painter->setBrush(option->palette.color(QPalette::Active,
302 QPalette::Background));
303 painter->drawRect(option->rect);
304
305 painter->setPen(header->palette.color(QPalette::Mid));
306 if (header->orientation == Qt::Horizontal) {
307 if (header->position == QStyleOptionHeader::Beginning ||
308 header->position == QStyleOptionHeader::OnlyOneSection) {
309 painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
310 painter->setPen(header->palette.color(QPalette::Base));
311 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
312 header->rect.topLeft() + QPoint(1, 1));
313 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
314 header->rect.topRight() + QPoint(-1, 1));
315 } else {
316 painter->drawLine(header->rect.bottomRight(),
317 header->rect.topRight());
318 painter->drawLine(header->rect.topLeft(),
319 header->rect.topRight());
320 painter->drawLine(header->rect.bottomLeft(),
321 header->rect.bottomRight());
322 painter->setPen(option->palette.color(QPalette::Base));
323 painter->drawLine(header->rect.bottomLeft() + QPoint(0, -1),
324 header->rect.topLeft() + QPoint(0, 1));
325 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
326 header->rect.topRight() + QPoint(-1, 1));
327 }
328 } else { // Vertical
329 if (header->position == QStyleOptionHeader::Beginning ||
330 header->position == QStyleOptionHeader::OnlyOneSection) {
331 painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
332 painter->setPen(header->palette.color(QPalette::Base));
333 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
334 header->rect.topLeft() + QPoint(1, 1));
335 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
336 header->rect.topRight() + QPoint(-1, 1));
337 } else {
338 painter->drawLine(header->rect.bottomLeft(),
339 header->rect.bottomRight());
340 painter->drawLine(header->rect.topLeft(),
341 header->rect.bottomLeft());
342 painter->drawLine(header->rect.topRight(),
343 header->rect.bottomRight());
344 painter->setPen(header->palette.color(QPalette::Base));
345 painter->drawLine(header->rect.topLeft(),
346 header->rect.topRight() + QPoint(-1, 0));
347 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
348 header->rect.topLeft() + QPoint(1, 0));
349 }
350 }
351 break;
352 }
353 case CE_ToolBar: {
354 QRect rect = option->rect;
355
356 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
357 gradient.setColorAt(1.0, QColor(221, 221, 221));
358 gradient.setColorAt(0.0, QColor(241, 241, 241));
359
360 if (option->state & State_Horizontal) {
361 painter->setPen(QColor(204, 204, 204));
362 painter->setBrush(gradient);
363 } else {
364 painter->setPen(Qt::NoPen);
365 painter->setBrush(option->palette.color(QPalette::Background));
366 }
367 painter->drawRect(rect.adjusted(0, 0, -1, -1));
368 break;
369 }
370 case CE_ProgressBar: {
371 const QStyleOptionProgressBar *bar1 =
372 qstyleoption_cast<const QStyleOptionProgressBar *>(option);
373
374 QStyleOptionProgressBarV2 *bar = new QStyleOptionProgressBarV2(*bar1);
375
376 QRect rect = bar->rect;
377 if (bar->orientation == Qt::Vertical) {
378 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width());
379 QMatrix m;
380 m.translate(rect.height()-1, 0);
381 m.rotate(90.0);
382 painter->setMatrix(m);
383 }
384
385 painter->setPen(bar->palette.color(QPalette::Mid));
386 painter->drawRect(rect.adjusted(0, 0, -1, -1));
387
388 QRect grooveRect = subElementRect(SE_ProgressBarGroove, bar,
389 widget);
390 if (bar->orientation == Qt::Vertical) {
391 grooveRect = QRect(grooveRect.left(), grooveRect.top(),
392 grooveRect.height(), grooveRect.width());
393 }
394
395 QStyleOptionProgressBar grooveBar = *bar;
396 grooveBar.rect = grooveRect;
397
398 drawControl(CE_ProgressBarGroove, &grooveBar, painter, widget);
399
400 QRect progressRect = subElementRect(SE_ProgressBarContents, bar,
401 widget);
402 if (bar->orientation == Qt::Vertical) {
403 progressRect = QRect(progressRect.left(), progressRect.top(),
404 progressRect.height(), progressRect.width());
405 progressRect.adjust(0, 0, 0, -1);
406 }
407 QStyleOptionProgressBar progressOpt = *bar;
408 progressOpt.rect = progressRect;
409 drawControl(CE_ProgressBarContents, &progressOpt, painter, widget);
410
411 QRect labelRect = subElementRect(SE_ProgressBarLabel, bar, widget);
412 if (bar->orientation == Qt::Vertical) {
413 labelRect = QRect(labelRect.left(), labelRect.top(),
414 labelRect.height(), labelRect.width());
415 }
416 QStyleOptionProgressBar subBar = *bar;
417 subBar.rect = labelRect;
418 if (bar->textVisible)
419 drawControl(CE_ProgressBarLabel, &subBar, painter, widget);
420
421 delete bar;
422 break;
423 }
424 case CE_ProgressBarGroove: {
425 painter->setBrush(option->palette.color(QPalette::Background));
426 painter->setPen(Qt::NoPen);
427 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
428
429 painter->setPen(option->palette.color(QPalette::Button));
430 painter->drawLine(option->rect.topLeft() + QPoint(0, 0),
431 option->rect.topRight() + QPoint(0, 0));
432 break;
433 }
434 case CE_ProgressBarContents: {
435 const QStyleOptionProgressBar *bar =
436 qstyleoption_cast<const QStyleOptionProgressBar *>(option);
437 int progress = int((double(bar->progress) /
438 double(bar->maximum - bar->minimum)) *
439 bar->rect.width());
440
441 painter->setBrush(bar->palette.color(QPalette::Light));
442 painter->setPen(Qt::NoPen);
443 QRect progressRect = QRect(bar->rect.topLeft(), QPoint(progress,
444 bar->rect.bottom()));
445 painter->drawRect(progressRect);
446
447 painter->setPen(bar->palette.color(QPalette::Midlight));
448 painter->setBrush(Qt::NoBrush);
449
450 painter->drawLine(bar->rect.bottomLeft(), bar->rect.topLeft());
451 painter->drawLine(bar->rect.topLeft(), QPoint(progress,
452 bar->rect.top()));
453 break;
454 }
455 case CE_ProgressBarLabel: {
456 painter->save();
457 const QStyleOptionProgressBar *bar =
458 qstyleoption_cast<const QStyleOptionProgressBar *>(option);
459
460 QRect rect = bar->rect;
461 QRect leftRect;
462
463 int progressIndicatorPos = int((double(bar->progress) /
464 double(bar->maximum - bar->minimum)) *
465 bar->rect.width());
466
467 QFont font;
468 font.setBold(true);
469 painter->setFont(font);
470 painter->setPen(bar->palette.color(QPalette::Midlight));
471
472 if (progressIndicatorPos >= 0 &&
473 progressIndicatorPos <= rect.width()) {
474 leftRect = QRect(bar->rect.topLeft(),
475 QPoint(progressIndicatorPos,
476 bar->rect.bottom()));
477 } else if (progressIndicatorPos > rect.width()) {
478 painter->setPen(bar->palette.color(QPalette::Base));
479 } else {
480 painter->setPen(bar->palette.color(QPalette::Midlight));
481 }
482
483 QRect textRect = QFontMetrics(font).boundingRect(bar->text);
484 textRect.moveCenter(option->rect.center());
485 painter->drawText(textRect, bar->text,
486 QTextOption(Qt::AlignCenter));
487 if (!leftRect.isNull()) {
488 painter->setPen(bar->palette.color(QPalette::Base));
489 painter->setClipRect(leftRect, Qt::IntersectClip);
490 painter->drawText(textRect, bar->text,
491 QTextOption(Qt::AlignCenter));
492 }
493
494 painter->restore();
495 break;
496 }
497 case CE_MenuBarEmptyArea: {
498 QRect emptyArea = option->rect.adjusted(0, 0, -1, -1);
499 QLinearGradient gradient(emptyArea.topLeft(), emptyArea.bottomLeft()
500 - QPoint(0, 1));
501 gradient.setColorAt(0.0, option->palette.color(QPalette::Base));
502 gradient.setColorAt(1.0, QColor(223, 223, 223));
503
504 painter->setPen(QColor(238, 238, 238));
505 painter->setBrush(gradient);
506 painter->drawRect(emptyArea.adjusted(0, 0, 0, -1));
507 break;
508 }
509 case CE_MenuBarItem: {
510 if (!(option->state & State_Sunken)) {
511 QLinearGradient gradient(option->rect.topLeft(),
512 option->rect.bottomLeft());
513 gradient.setColorAt(0.0, Qt::white);
514 gradient.setColorAt(1.0, QColor(223, 223, 223));
515
516 painter->setPen(Qt::NoPen);
517 painter->setBrush(gradient);
518 } else {
519 painter->setBrush(option->palette.color(QPalette::Light));
520 }
521
522 painter->drawRect(option->rect);
523 if (option->state & State_Sunken) {
524 painter->setPen(option->palette.color(QPalette::Mid));
525 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
526 painter->setPen(option->palette.color(QPalette::Base));
527 painter->setBrush(Qt::NoBrush);
528 painter->drawLine(option->rect.bottomRight() + QPoint(0, -1),
529 option->rect.topRight() + QPoint(0, -1));
530 }
531 QCommonStyle::drawControl(control, option, painter, widget);
532 break;
533 }
534 case CE_MenuItem: {
535 const QStyleOptionMenuItem *menuItem =
536 qstyleoption_cast<const QStyleOptionMenuItem *>(option);
537
538 bool selected = menuItem->state & State_Selected;
539 bool checkable = menuItem->checkType !=
540 QStyleOptionMenuItem::NotCheckable;
541 bool checked = menuItem->checked;
542
543 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
544 QPoint center = menuItem->rect.center();
545
546 painter->setPen(menuItem->palette.color(QPalette::Midlight));
547 painter->drawLine(QPoint(menuItem->rect.left() - 2, center.y()),
548 QPoint(menuItem->rect.right(), center.y()));
549 painter->setPen(menuItem->palette.color(QPalette::Base));
550 painter->drawLine(QPoint(menuItem->rect.left() - 2,
551 center.y() + 1),
552 QPoint(menuItem->rect.right(),
553 center.y() + 1));
554
555 break;
556 }
557
558 if (selected) {
559 painter->setBrush(menuItem->palette.color(QPalette::Light));
560 painter->setPen(Qt::NoPen);
561 painter->drawRect(menuItem->rect);
562 painter->setPen(menuItem->palette.color(QPalette::Midlight));
563 painter->drawLine(menuItem->rect.topLeft(),
564 menuItem->rect.topRight());
565 painter->setPen(menuItem->palette.color(QPalette::Base));
566 painter->drawLine(menuItem->rect.bottomLeft(),
567 menuItem->rect.bottomRight());
568 }
569
570 if (checkable) {
571 QRect checkRect(option->rect.left() + 5,
572 option->rect.center().y() - 5, 10, 10);
573 if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
574 QStyleOptionButton button;
575 button.rect = checkRect;
576 button.state = menuItem->state;
577 if (button.state & State_Sunken)
578 button.state ^= State_Sunken;
579 if (checked)
580 button.state |= State_On;
581 button.palette = menuItem->palette;
582 drawPrimitive(PE_IndicatorRadioButton, &button, painter,
583 widget);
584 } else {
585 QBrush buttonBrush = gradientBrush(option->rect);
586 painter->setBrush(buttonBrush);
587 painter->setPen(option->palette.color(QPalette::Mid));
588
589 painter->drawRect(checkRect);
590
591 if (checked) {
592 QImage image(":/images/checkboxchecked.png");
593 painter->drawImage(QPoint(option->rect.left() + 5,
594 option->rect.center().y() - 8), image);
595 }
596 }
597 }
598
599 bool dis = !(menuItem->state & State_Enabled);
600 bool act = menuItem->state & State_Selected;
601 const QStyleOption *opt = option;
602 const QStyleOptionMenuItem *menuitem = menuItem;
603 int checkcol = qMax(menuitem->maxIconWidth, 20);
604 if (menuItem->icon.isNull())
605 checkcol = 0;
606
607 QPainter *p = painter;
608 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
609 QRect(menuitem->rect.x(),
610 menuitem->rect.y(),
611 checkcol, menuitem->rect.height()));
612 if (!menuItem->icon.isNull()) {
613 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
614 if (act && !dis)
615 mode = QIcon::Active;
616 QPixmap pixmap;
617 if (checked)
618 pixmap = menuItem->icon.pixmap(
619 pixelMetric(PM_SmallIconSize), mode, QIcon::On);
620 else
621 pixmap = menuItem->icon.pixmap(
622 pixelMetric(PM_SmallIconSize), mode);
623 int pixw = pixmap.width();
624 int pixh = pixmap.height();
625
626 int adjustedIcon = checkable ? 15 : 0;
627 QRect pmr(0, 0, pixw, pixh);
628 pmr.moveCenter(vCheckRect.center());
629 painter->setPen(menuItem->palette.text().color());
630 if (checkable && checked)
631 painter->drawPixmap(QPoint(pmr.left() +
632 adjustedIcon, pmr.top() + 1), pixmap);
633 else
634 painter->drawPixmap(pmr.topLeft() +
635 QPoint(adjustedIcon, 0), pixmap);
636 }
637
638 if (selected) {
639 painter->setPen(menuItem->palette.highlightedText().color());
640 } else {
641 painter->setPen(menuItem->palette.text().color());
642 }
643 int x, y, w, h;
644 menuitem->rect.getRect(&x, &y, &w, &h);
645 int tab = menuitem->tabWidth;
646 QColor discol;
647 if (dis) {
648 discol = menuitem->palette.text().color();
649 p->setPen(discol);
650 }
651 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
652 int xpos = menuitem->rect.x() + xm;
653 QRect textRect;
654 if (!menuItem->icon.isNull())
655 textRect.setRect(xpos, y + windowsItemVMargin, w - xm -
656 windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
657 else
658 textRect.setRect(menuItem->rect.left() + 9,
659 y + windowsItemVMargin,
660 w - xm - windowsRightBorder - tab,
661 h - 2 * windowsItemVMargin);
662
663 if (checkable)
664 textRect.adjust(10, 0, 10, 0);
665
666 QRect vTextRect = visualRect(opt->direction, menuitem->rect,
667 textRect);
668 QString s = menuitem->text;
669 if (!s.isEmpty()) {
670 int t = s.indexOf(QLatin1Char('\t'));
671 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic |
672 Qt::TextDontClip | Qt::TextSingleLine;
673 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
674 text_flags |= Qt::TextHideMnemonic;
675 text_flags |= Qt::AlignLeft;
676 if (t >= 0) {
677 QRect vShortcutRect = visualRect(opt->direction,
678 menuitem->rect,
679 QRect(textRect.topRight(),
680 QPoint(menuitem->rect.right(), textRect.bottom())));
681 if (dis && !act) {
682 p->setPen(menuitem->palette.light().color());
683 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1),
684 text_flags,
685 s.mid(t + 1));
686 p->setPen(discol);
687 }
688 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
689 s = s.left(t);
690 }
691 QFont font = menuitem->font;
692 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
693 font.setBold(true);
694 p->setFont(font);
695 if (dis && !act) {
696 p->setPen(menuitem->palette.light().color());
697 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags,
698 s.left(t));
699 p->setPen(discol);
700 }
701 p->drawText(vTextRect, text_flags, s.left(t));
702 }
703
704 if (menuItem->menuItemType & QStyleOptionMenuItem::SubMenu) {
705 QPoint center = menuItem->rect.center();
706 QPoint drawStart(menuItem->rect.right() - 6, center.y() + 4);
707
708 QPainterPath arrow;
709 arrow.moveTo(drawStart);
710 arrow.lineTo(drawStart + QPoint(0, -8));
711 arrow.lineTo(drawStart + QPoint(4, -5));
712 arrow.lineTo(drawStart + QPoint(4, -4));
713 arrow.lineTo(drawStart + QPoint(0, 0));
714
715 painter->save();
716 painter->setBrush(menuItem->palette.color(QPalette::Text));
717 painter->setPen(Qt::NoPen);
718 painter->drawPath(arrow);
719 painter->restore();
720 }
721
722 break;
723 }
724 case CE_MenuVMargin: {
725 break;
726 }
727 case CE_MenuHMargin: {
728 break;
729 }
730 case CE_Splitter: {
731 drawSplitter(option, painter, option->state & State_Horizontal);
732 break;
733 }
734 case CE_ScrollBarAddPage: {
735 case CE_ScrollBarSubPage:
736 const QStyleOptionSlider *scrollBar =
737 qstyleoption_cast<const QStyleOptionSlider *>(option);
738 QRect myRect;
739 if (scrollBar->orientation == Qt::Horizontal) {
740 myRect = QRect(option->rect.topLeft(),
741 option->rect.bottomRight()).adjusted(0, 0, 1, -1);
742 } else {
743 myRect = option->rect;
744 }
745
746 painter->setPen(Qt::NoPen);
747 painter->setBrush(option->palette.color(QPalette::Background));
748 painter->drawRect(myRect);
749
750 painter->setBrush(Qt::NoBrush);
751 painter->setPen(scrollBar->palette.color(QPalette::Mid));
752 painter->drawRect(myRect.adjusted(0, 0, -1, 0));
753 painter->setPen(scrollBar->palette.color(QPalette::Button));
754 painter->drawLine(myRect.bottomLeft() + QPoint(1, 0),
755 myRect.topLeft() + QPoint(1, 1));
756 painter->drawLine(myRect.topLeft() + QPoint(1, 1),
757 myRect.topRight() + QPoint(-1, 1));
758 break;
759 }
760 case CE_ScrollBarSubLine: {
761 const QStyleOptionSlider *scrollBar =
762 qstyleoption_cast<const QStyleOptionSlider *>(option);
763 int scrollBarExtent = pixelMetric(PM_ScrollBarExtent);
764 QRect scrollBarSubLine = option->rect;
765
766 QRect button1;
767 QRect button2;
768
769 if (scrollBar->orientation == Qt::Horizontal) {
770 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
771 16, scrollBarExtent);
772 button2.setRect(scrollBarSubLine.right() - 15,
773 scrollBarSubLine.top(), 16, scrollBarExtent);
774 } else {
775 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
776 scrollBarExtent, 16);
777 button2.setRect(scrollBarSubLine.left(),
778 scrollBarSubLine.bottom() - 15, scrollBarExtent, 16);
779 }
780
781 painter->fillRect(button2, Qt::blue);
782
783 drawScrollBarArrow(button1, painter, scrollBar);
784 drawScrollBarArrow(button2, painter, scrollBar);
785 break;
786 }
787 case CE_ScrollBarAddLine: {
788 const QStyleOptionSlider *scrollBar =
789 qstyleoption_cast<const QStyleOptionSlider *>(option);
790 QRect button(option->rect.left(), option->rect.top(), 16, 16);
791 drawScrollBarArrow(button, painter, scrollBar, true);
792 break;
793 }
794 case CE_ScrollBarSlider: {
795 const QStyleOptionSlider *scrollBar =
796 qstyleoption_cast<const QStyleOptionSlider *>(option);
797
798 painter->setPen(scrollBar->palette.color(QPalette::Midlight));
799 painter->drawRect(scrollBar->rect.adjusted(-1, 0, -3, -1));
800
801 QPoint g1, g2;
802 if (scrollBar->orientation == Qt::Horizontal) {
803 g1 = option->rect.topLeft();
804 g2 = option->rect.bottomLeft();
805 } else {
806 g1 = option->rect.topLeft();
807 g2 = option->rect.topRight();
808 }
809
810 if (scrollBar->state & State_Enabled) {
811 QLinearGradient gradient(g1, g2);
812 gradient.setColorAt(1.0, QColor(188, 210, 230));
813 gradient.setColorAt(0.3, Qt::white);
814 gradient.setColorAt(0.0, QColor(223, 233, 243));
815 painter->setBrush(gradient);
816 } else {
817 painter->setPen(scrollBar->palette.buttonText().color());
818 painter->setBrush(scrollBar->palette.button());
819 }
820 painter->drawRect(scrollBar->rect.adjusted(0, 0, -1, -1));
821
822 int sliderLength = option->rect.height();
823 int drawPos = scrollBar->orientation == Qt::Vertical ?
824 (sliderLength / 2) + 1 : 1 - ((option->rect.width() / 2));
825
826 QPoint origin;
827 if (scrollBar->orientation == Qt::Vertical)
828 origin = option->rect.bottomLeft();
829 else
830 origin = option->rect.topLeft();
831
832 painter->setPen(scrollBar->palette.color(QPalette::Base));
833 painter->drawLine(origin + adjustScrollHandlePoint(
834 scrollBar->orientation,
835 QPoint(4, -drawPos)),
836 origin + adjustScrollHandlePoint(
837 scrollBar->orientation,
838 QPoint(13, -drawPos)));
839 painter->drawLine(origin + adjustScrollHandlePoint(
840 scrollBar->orientation,
841 QPoint(4, 2 - drawPos)),
842 origin + adjustScrollHandlePoint(
843 scrollBar->orientation,
844 QPoint(13, 2 - drawPos)));
845 painter->drawLine(origin + adjustScrollHandlePoint(
846 scrollBar->orientation,
847 QPoint(4, 4 - drawPos)),
848 origin + adjustScrollHandlePoint(
849 scrollBar->orientation,
850 QPoint(13, 4 - drawPos)));
851
852 painter->setPen(option->palette.color(QPalette::Midlight));
853 painter->drawLine(origin + adjustScrollHandlePoint(
854 scrollBar->orientation,
855 QPoint(3, -(drawPos + 1))),
856 origin + adjustScrollHandlePoint(
857 scrollBar->orientation,
858 QPoint(12, -(drawPos + 1))));
859 painter->drawLine(origin + adjustScrollHandlePoint(
860 scrollBar->orientation,
861 QPoint(3, 1 - drawPos)),
862 origin + adjustScrollHandlePoint(
863 scrollBar->orientation,
864 QPoint(12, 1 - drawPos)));
865 painter->drawLine(origin + adjustScrollHandlePoint(
866 scrollBar->orientation,
867 QPoint(3, 3 - drawPos)),
868 origin + adjustScrollHandlePoint(
869 scrollBar->orientation,
870 QPoint(12, 3 - drawPos)));
871
872 break;
873 }
874 case CE_TabBarTabLabel: {
875 QStyleOptionTab copy =
876 *qstyleoption_cast<const QStyleOptionTab *>(option);
877 if (copy.state & State_HasFocus)
878 copy.state ^= State_HasFocus;
879 painter->setBrush(Qt::NoBrush);
880 QWindowsStyle::drawControl(CE_TabBarTabLabel, &copy, painter,
881 widget);
882 break;
883 }
884 case CE_TabBarTabShape: {
885 const QStyleOptionTab *tab =
886 qstyleoption_cast<const QStyleOptionTab *>(option);
887 QRect myRect = option->rect;
888 QPoint bottomLeft, bottomRight, topLeft, topRight;
889
890 if ((tab->position == QStyleOptionTab::Beginning) ||
891 (tab->position == QStyleOptionTab::OnlyOneTab)) {
892 if (tab->shape == QTabBar::RoundedSouth ||
893 tab->shape == QTabBar::RoundedNorth) {
894 myRect = myRect.adjusted(2, 0, 0, 0);
895 } else {
896 myRect = myRect.adjusted(0, 2, 0, 0);
897 }
898 }
899
900 switch (tab->shape) {
901 case QTabBar::RoundedNorth:
902 topLeft = myRect.topLeft();
903 topRight = myRect.topRight();
904 bottomLeft = myRect.bottomLeft();
905 bottomRight = myRect.bottomRight();
906 break;
907 case QTabBar::RoundedSouth:
908 topLeft = myRect.bottomLeft();
909 topRight = myRect.bottomRight();
910 bottomLeft = myRect.topLeft();
911 bottomRight = myRect.topRight();
912 break;
913 case QTabBar::RoundedWest:
914 topLeft = myRect.topLeft();
915 topRight = myRect.bottomLeft();
916 bottomLeft = myRect.topRight();
917 bottomRight = myRect.bottomRight();
918 break;
919 case QTabBar::RoundedEast:
920 topLeft = myRect.topRight();
921 topRight = myRect.bottomRight();
922 bottomLeft = myRect.topLeft();
923 bottomRight = myRect.bottomLeft();
924 break;
925 default:
926 ;
927 }
928
929 QPainterPath outerPath;
930 outerPath.moveTo(bottomLeft + adjustTabPoint(QPoint(0, -2),
931 tab->shape));
932 outerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(0, -14),
933 tab->shape));
934 outerPath.lineTo(topLeft + adjustTabPoint(QPoint(6 , 0),
935 tab->shape));
936 outerPath.lineTo(topRight + adjustTabPoint(QPoint(0, 0),
937 tab->shape));
938 outerPath.lineTo(bottomRight + adjustTabPoint(QPoint(0, -2),
939 tab->shape));
940
941 if (tab->state & State_Selected ||
942 tab->position == QStyleOptionTab::OnlyOneTab) {
943 QPainterPath innerPath;
944 innerPath.moveTo(topLeft + adjustTabPoint(QPoint(6, 2),
945 tab->shape));
946 innerPath.lineTo(topRight + adjustTabPoint(QPoint(-1, 2),
947 tab->shape));
948 innerPath.lineTo(bottomRight + adjustTabPoint(QPoint(-1 , -2),
949 tab->shape));
950 innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -2),
951 tab->shape));
952 innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -14),
953 tab->shape));
954 innerPath.lineTo(topLeft + adjustTabPoint(QPoint(6, 2),
955 tab->shape));
956
957 QPainterPath whitePath;
958 whitePath.moveTo(bottomLeft + adjustTabPoint(QPoint(1, -2),
959 tab->shape));
960 whitePath.lineTo(bottomLeft + adjustTabPoint(QPoint(1, -14),
961 tab->shape));
962 whitePath.lineTo(topLeft + adjustTabPoint(QPoint(6, 1),
963 tab->shape));
964 whitePath.lineTo(topRight + adjustTabPoint(QPoint(-1, 1),
965 tab->shape));
966
967 painter->setPen(tab->palette.color(QPalette::Midlight));
968 painter->setBrush(QColor(200, 221, 242));
969 painter->drawPath(outerPath);
970 painter->setPen(QColor(200, 221, 242));
971 painter->drawRect(QRect(bottomLeft + adjustTabPoint(
972 QPoint(2, -3), tab->shape),
973 bottomRight + adjustTabPoint(
974 QPoint(-2, 0), tab->shape)));
975 painter->setPen(tab->palette.color(QPalette::Base));
976 painter->setBrush(Qt::NoBrush);
977 painter->drawPath(whitePath);
978
979 if (option->state & State_HasFocus) {
980 painter->setPen(option->palette.color(QPalette::Mid));
981 painter->drawPath(innerPath);
982 }
983 } else {
984 painter->setPen(tab->palette.color(QPalette::Mid));
985 painter->drawPath(outerPath);
986 }
987 break;
988 }
989 case CE_PushButtonLabel:
990 painter->save();
991
992 if (const QStyleOptionButton *button =
993 qstyleoption_cast<const QStyleOptionButton *>(option)) {
994 QRect ir = button->rect;
995 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
996 if (!styleHint(SH_UnderlineShortcut, button, widget))
997 tf |= Qt::TextHideMnemonic;
998
999 if (!button->icon.isNull()) {
1000 QPoint point;
1001
1002 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
1003 : QIcon::Disabled;
1004 if (mode == QIcon::Normal && button->state & State_HasFocus)
1005 mode = QIcon::Active;
1006 QIcon::State state = QIcon::Off;
1007 if (button->state & State_On)
1008 state = QIcon::On;
1009
1010 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode,
1011 state);
1012 int w = pixmap.width();
1013 int h = pixmap.height();
1014
1015 if (!button->text.isEmpty())
1016 w += button->fontMetrics.width(button->text) + 2;
1017
1018 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
1019 ir.y() + ir.height() / 2 - h / 2);
1020
1021 if (button->direction == Qt::RightToLeft)
1022 point.rx() += pixmap.width();
1023
1024 painter->drawPixmap(visualPos(button->direction, button->rect,
1025 point), pixmap);
1026
1027 if (button->direction == Qt::RightToLeft)
1028 ir.translate(-point.x() - 2, 0);
1029 else
1030 ir.translate(point.x() + pixmap.width(), 0);
1031
1032 if (!button->text.isEmpty())
1033 tf |= Qt::AlignLeft;
1034
1035 } else {
1036 tf |= Qt::AlignHCenter;
1037 }
1038
1039 if (button->fontMetrics.height() > 14)
1040 ir.translate(0, 1);
1041
1042 drawItemText(painter, ir, tf, button->palette, (button->state &
1043 State_Enabled),
1044 button->text, QPalette::ButtonText);
1045 }
1046
1047 painter->restore();
1048 break;
1049
1050 default:
1051 QWindowsStyle::drawControl(control, option, painter, widget);
1052 }
1053 painter->restore();
1054}
1055
1056inline QPoint JavaStyle::adjustTabPoint(const QPoint &point,
1057 QTabBar::Shape shape) const
1058{
1059 QPoint rPoint;
1060
1061 switch (shape) {
1062 case QTabBar::RoundedWest:
1063 rPoint = QPoint(point.y(), point.x());
1064 break;
1065 case QTabBar::RoundedSouth:
1066 rPoint = QPoint(point.x(), point.y() * -1);
1067 break;
1068 case QTabBar::RoundedEast:
1069 rPoint = QPoint(point.y() * -1, point.x());
1070 break;
1071 default:
1072 rPoint = point;
1073 }
1074 return rPoint;
1075}
1076
1077QRect JavaStyle::subControlRect(ComplexControl control,
1078 const QStyleOptionComplex *option,
1079 SubControl subControl,
1080 const QWidget *widget) const
1081{
1082 QRect rect = QWindowsStyle::subControlRect(control, option, subControl,
1083 widget);
1084
1085 switch (control) {
1086 case CC_TitleBar: {
1087 const QStyleOptionTitleBar *bar =
1088 qstyleoption_cast<const QStyleOptionTitleBar *>(option);
1089
1090 switch (subControl) {
1091 case SC_TitleBarMinButton: {
1092 rect = QRect(bar->rect.topRight() + QPoint(-68, 2),
1093 QSize(15, 15));
1094 break;
1095 }
1096 case SC_TitleBarMaxButton: {
1097 rect = QRect(bar->rect.topRight() + QPoint(-43, 3),
1098 QSize(15, 15));
1099 break;
1100 }
1101 case SC_TitleBarCloseButton: {
1102 rect = QRect(bar->rect.topRight() + QPoint(-18, 3),
1103 QSize(15, 15));
1104 break;
1105 }
1106 case SC_TitleBarLabel: {
1107 QRect labelRect = bar->fontMetrics.boundingRect(bar->text);
1108 rect = labelRect;
1109 rect.translate(bar->rect.left() + 30, 0);
1110 rect.moveTop(bar->rect.top());
1111 rect.adjust(0, 2, 2, 2);
1112 break;
1113 }
1114 case SC_TitleBarSysMenu: {
1115 rect = QRect(bar->rect.topLeft() + QPoint(6, 3),
1116 QSize(16, 16));
1117 break;
1118 }
1119 default:
1120 ;
1121 }
1122 break;
1123 }
1124 case CC_GroupBox: {
1125 const QStyleOptionGroupBox *box =
1126 qstyleoption_cast<const QStyleOptionGroupBox *>(option);
1127 bool hasCheckbox = box->subControls & SC_GroupBoxCheckBox;
1128 int checkAdjust = 13;
1129
1130 QRect textRect = box->fontMetrics.boundingRect(box->text);
1131
1132 switch (subControl) {
1133 case SC_GroupBoxFrame: {
1134 rect = box->rect;
1135 break;
1136 }
1137 case SC_GroupBoxCheckBox: {
1138 if (hasCheckbox) {
1139 rect = QRect(box->rect.topLeft() + QPoint(7, 4 +
1140 (textRect.height() / 2 - checkAdjust / 2)),
1141 QSize(checkAdjust, checkAdjust));
1142 }
1143 else {
1144 rect = QRect();
1145 }
1146 break;
1147 }
1148 case SC_GroupBoxLabel: {
1149 rect = QRect(box->rect.topLeft() + QPoint(7 + (hasCheckbox ?
1150 checkAdjust + 2 : 0), 4), textRect.size());
1151 break;
1152 }
1153 case SC_GroupBoxContents: {
1154 rect = box->rect.adjusted(10, 10 + textRect.height(), -10,
1155 -10);
1156 break;
1157 }
1158 default:
1159 ;
1160 }
1161 break;
1162 }
1163 case CC_SpinBox: {
1164 const QStyleOptionSpinBox *spinBox =
1165 qstyleoption_cast<const QStyleOptionSpinBox *>(option);
1166 int spinnerWidth = 16;
1167 QRect myRect = spinBox->rect;
1168 QPoint center = myRect.center();
1169 int frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spinBox, widget);
1170
1171 switch (subControl) {
1172 case SC_SpinBoxUp: {
1173 rect = QRect(myRect.topRight() + QPoint(-16, 0),
1174 QSize(16, center.y() - myRect.topRight().y()));
1175 break;
1176 }
1177 case SC_SpinBoxDown: {
1178 rect = QRect(QPoint(myRect.bottomRight().x() - 16,
1179 center.y() + 1),
1180 QSize(16, myRect.bottomRight().y() -
1181 center.y() - 1));
1182 break;
1183 }
1184 case SC_SpinBoxFrame: {
1185 rect = QRect(myRect.topLeft(), myRect.bottomRight() +
1186 QPoint(-16, 0));
1187 break;
1188 }
1189 case SC_SpinBoxEditField: {
1190 rect = QRect(myRect.topLeft() + QPoint(2, 2),
1191 myRect.bottomRight() + QPoint(-15 - frameWidth, -2));
1192 break;
1193 }
1194 default:
1195 ;
1196 }
1197 break;
1198 }
1199 case CC_ToolButton: {
1200 const QStyleOptionToolButton *button =
1201 qstyleoption_cast<const QStyleOptionToolButton *>(option);
1202
1203 switch (subControl) {
1204 case SC_ToolButton: {
1205 rect = option->rect.adjusted(1, 1, -1, -1);
1206 break;
1207 }
1208 case SC_ToolButtonMenu: {
1209 rect = QRect(option->rect.bottomRight() +
1210 QPoint(-11, -11), QSize(10, 10));
1211 break;
1212 }
1213 }
1214 break;
1215 }
1216 case CC_ComboBox: {
1217 const QStyleOptionComboBox *combo =
1218 qstyleoption_cast<const QStyleOptionComboBox *>(option);
1219
1220 bool reverse = combo->direction == Qt::RightToLeft;
1221
1222 switch (subControl) {
1223 case SC_ComboBoxFrame:
1224 rect = combo->rect;
1225 break;
1226 case SC_ComboBoxArrow:
1227 if (reverse) {
1228 rect = QRect(combo->rect.topLeft(),
1229 combo->rect.bottomLeft() + QPoint(17, 0));
1230 } else {
1231 rect = QRect(combo->rect.topRight() + QPoint(-17, 0),
1232 combo->rect.bottomRight());
1233 }
1234 break;
1235 case SC_ComboBoxEditField:
1236 if (reverse) {
1237 rect = QRect(combo->rect.topLeft() + QPoint(19, 2),
1238 combo->rect.bottomRight() + QPoint(-2, 2));
1239 } else {
1240 rect = QRect(combo->rect.topLeft() + QPoint(2, 2),
1241 combo->rect.bottomRight() + QPoint(-19, -2));
1242 }
1243 break;
1244 case SC_ComboBoxListBoxPopup:
1245 rect = combo->rect;
1246 break;
1247 }
1248 break;
1249 }
1250 case CC_ScrollBar: {
1251 const QStyleOptionSlider *scrollBar =
1252 qstyleoption_cast<const QStyleOptionSlider *>(option);
1253 int scrollBarExtent = pixelMetric(PM_ScrollBarExtent, scrollBar,
1254 widget);
1255 int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ?
1256 scrollBar->rect.width() :
1257 scrollBar->rect.height()) - (16 * 3);
1258 int sliderMinLength = pixelMetric(PM_ScrollBarSliderMin, scrollBar,
1259 widget);
1260 int sliderLength;
1261
1262 if (scrollBar->maximum != scrollBar->minimum) {
1263 uint valueRange = scrollBar->maximum - scrollBar->minimum;
1264 sliderLength = (scrollBar->pageStep * sliderMaxLength) /
1265 (valueRange + scrollBar->pageStep);
1266
1267 if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2)
1268 sliderLength = sliderMinLength;
1269 if (sliderLength > sliderMaxLength)
1270 sliderLength = sliderMaxLength;
1271 } else {
1272 sliderLength = sliderMaxLength;
1273 }
1274 int sliderStart = 16 + sliderPositionFromValue(scrollBar->minimum,
1275 scrollBar->maximum,
1276 scrollBar->sliderPosition,
1277 sliderMaxLength - sliderLength,
1278 scrollBar->upsideDown);
1279 QRect scrollBarRect = scrollBar->rect;
1280
1281 switch (subControl) {
1282 case SC_ScrollBarSubLine:
1283 if (scrollBar->orientation == Qt::Horizontal) {
1284 rect.setRect(scrollBarRect.left(), scrollBarRect.top(),
1285 scrollBarRect.width() - 16, scrollBarExtent);
1286 } else {
1287 rect.setRect(scrollBarRect.left(), scrollBarRect.top(),
1288 scrollBarExtent, scrollBarRect.height() - 16);
1289 }
1290 break;
1291 case SC_ScrollBarAddLine:
1292 if (scrollBar->orientation == Qt::Horizontal) {
1293 rect.setRect(scrollBarRect.right() - 15,
1294 scrollBarRect.top(), 16, scrollBarExtent);
1295 } else {
1296 rect.setRect(scrollBarRect.left(), scrollBarRect.bottom()
1297 - 15, scrollBarExtent, 16);
1298 }
1299 break;
1300 case SC_ScrollBarSubPage:
1301 if (scrollBar->orientation == Qt::Horizontal) {
1302 rect.setRect(scrollBarRect.left() + 16, scrollBarRect.top(),
1303 sliderStart - (scrollBarRect.left() + 16),
1304 scrollBarExtent);
1305 } else {
1306 rect.setRect(scrollBarRect.left(), scrollBarRect.top() + 16,
1307 scrollBarExtent,
1308 sliderStart - (scrollBarRect.left() + 16));
1309 }
1310 break;
1311 case SC_ScrollBarAddPage:
1312 if (scrollBar->orientation == Qt::Horizontal)
1313 rect.setRect(sliderStart + sliderLength, 0,
1314 sliderMaxLength - sliderStart -
1315 sliderLength + 16, scrollBarExtent);
1316 else
1317 rect.setRect(0, sliderStart + sliderLength,
1318 scrollBarExtent, sliderMaxLength -
1319 sliderStart - sliderLength + 16);
1320 break;
1321 case SC_ScrollBarGroove:
1322 if (scrollBar->orientation == Qt::Horizontal) {
1323 rect = scrollBarRect.adjusted(16, 0, -32, 0);
1324 } else {
1325 rect = scrollBarRect.adjusted(0, 16, 0, -32);
1326 }
1327 break;
1328 case SC_ScrollBarSlider:
1329 if (scrollBar->orientation == Qt::Horizontal) {
1330 rect.setRect(sliderStart, 0, sliderLength,
1331 scrollBarExtent);
1332 } else {
1333 rect.setRect(0, sliderStart, scrollBarExtent,
1334 sliderLength);
1335 }
1336 break;
1337 default:
1338 return QWindowsStyle::subControlRect(control, option,
1339 subControl, widget);
1340 }
1341 break;
1342 }
1343 case CC_Slider: {
1344 const QStyleOptionSlider *slider =
1345 qstyleoption_cast<const QStyleOptionSlider *>(option);
1346 rect = slider->rect;
1347 int tickSize = pixelMetric(PM_SliderTickmarkOffset, option, widget);
1348 int handleSize = pixelMetric(PM_SliderControlThickness, option,
1349 widget);
1350
1351 int dist = slider->orientation == Qt::Vertical ? slider->rect.height() :
1352 slider->rect.width();
1353 int pos = QStyle::sliderPositionFromValue(slider->minimum,
1354 slider->maximum, slider->sliderValue, dist - handleSize);
1355
1356 switch (subControl) {
1357 case SC_SliderGroove: {
1358 QPoint center = rect.center();
1359
1360 if (slider->orientation == Qt::Horizontal) {
1361 rect.setHeight(handleSize);
1362 if (slider->tickPosition == QSlider::TicksBelow) {
1363 center.ry() -= tickSize;
1364 }
1365 } else {
1366 rect.adjust(0, 0, 0, 0);
1367 rect.setWidth(handleSize);
1368 if (slider->tickPosition == QSlider::TicksBelow) {
1369 center.rx() -= tickSize;
1370 }
1371 }
1372 rect.moveCenter(center);
1373 break;
1374 }
1375 case SC_SliderHandle: {
1376 QPoint center = rect.center();
1377
1378 if (slider->orientation == Qt::Horizontal) {
1379 rect.setHeight(handleSize);
1380 if (slider->tickPosition == QSlider::TicksBelow) {
1381 center.ry() -= tickSize;
1382 }
1383
1384 rect.moveCenter(center);
1385
1386 if (slider->upsideDown)
1387 rect.setLeft(slider->rect.right() -
1388 pos - (handleSize - 1));
1389 else
1390 rect.setLeft(pos);
1391
1392 rect.setWidth(handleSize - 1);
1393 } else {
1394 rect.setWidth(handleSize);
1395 if (slider->tickPosition == QSlider::TicksBelow) {
1396 center.rx() -= tickSize;
1397 }
1398
1399 rect.moveCenter(center);
1400
1401 if (slider->upsideDown)
1402 rect.setTop(slider->rect.bottom() -
1403 ((pos + handleSize) - 2));
1404 else
1405 rect.setTop(slider->rect.top() + pos);
1406
1407 rect.setHeight(handleSize);
1408 }
1409 break;
1410 }
1411 case SC_SliderTickmarks: {
1412 QPoint center = slider->rect.center();
1413
1414 if (slider->tickPosition & QSlider::TicksBelow) {
1415 if (slider->orientation == Qt::Horizontal) {
1416 rect.setHeight(tickSize);
1417 center.ry() += tickSize / 2;
1418 rect.adjust(6, 0, -10, 0);
1419 } else {
1420 rect.setWidth(tickSize);
1421 center.rx() += tickSize / 2;
1422 rect.adjust(0, 6, 0, -10);
1423 }
1424 } else {
1425 rect = QRect();
1426 }
1427 rect.moveCenter(center);
1428 break;
1429 }
1430 default:
1431 ;
1432 }
1433 break;
1434 }
1435 default:
1436 return QWindowsStyle::subControlRect(control, option, subControl,
1437 widget);
1438 }
1439 return rect;
1440}
1441
1442static const char * const sliderHandleImage[] = {
1443 "15 16 7 1",
1444 " c None",
1445 "+ c #FFFFFF",
1446 "@ c #FFFFFF",
1447 "$ c #FFFFFF",
1448 "( c #E5EDF5",
1449 ") c #F2F6FA",
1450 "[ c #FFFFFF",
1451 " +++++++++++++ ",
1452 "+@@@@@@@@@@@@@+",
1453 "+@(((((((((((@+",
1454 "+@(((((((((((@+",
1455 "+@)))))))))))@+",
1456 "+@[[[[[[[[[[[@+",
1457 "+@[[[[[[[[[[[@+",
1458 "+@)))))))))))@+",
1459 "+@)))))))))))@+",
1460 " +@)))))))))@+ ",
1461 " +@(((((((@+ ",
1462 " +@(((((@+ ",
1463 " +@(((@+ ",
1464 " +@(@+ ",
1465 " +@+ ",
1466 " + "};
1467
1468
1469void JavaStyle::drawComplexControl(ComplexControl control,
1470 const QStyleOptionComplex *option,
1471 QPainter *painter,
1472 const QWidget *widget) const
1473{
1474 painter->save();
1475
1476 switch (control) {
1477 case CC_TitleBar: {
1478 const QStyleOptionTitleBar *bar =
1479 qstyleoption_cast<const QStyleOptionTitleBar *>(option);
1480
1481 bool sunken = bar->state & State_Sunken;
1482
1483 QLinearGradient gradient(bar->rect.bottomLeft(),
1484 bar->rect.topLeft());
1485 gradient.setColorAt(0.0, QColor(191, 212, 231));
1486 gradient.setColorAt(0.7, Qt::white);
1487 gradient.setColorAt(1.0, QColor(221, 232, 243));
1488
1489 painter->setPen(Qt::NoPen);
1490 if (bar->titleBarState & State_Active) {
1491 painter->setBrush(gradient);
1492 }
1493 else
1494 painter->setBrush(bar->palette.color(QPalette::Active,
1495 QPalette::Background));
1496
1497 painter->drawRect(bar->rect.adjusted(0, 0, -1, -1));
1498
1499 painter->setBrush(QColor(233, 233, 233));
1500 painter->drawRect(QRect(bar->rect.bottomLeft() + QPoint(0, 1),
1501 bar->rect.bottomRight() + QPoint(0, 2)));
1502
1503 QRect minButtonRect = subControlRect(control, bar,
1504 SC_TitleBarMinButton);
1505 QRect maxButtonRect = subControlRect(control, bar,
1506 SC_TitleBarMaxButton);
1507 QRect closeButtonRect = subControlRect(control, bar,
1508 SC_TitleBarCloseButton);
1509 QRect systemButtonRect = subControlRect(control, bar,
1510 SC_TitleBarSysMenu);
1511 QRect labelRect = subControlRect(control, bar, SC_TitleBarLabel);
1512 QRect gripRect = QRect(QPoint(labelRect.right() + 5, bar->rect.top() + 5),
1513 QPoint(minButtonRect.left() - 5,
1514 bar->rect.bottom() - 4));
1515
1516 QColor textColor = option->palette.color(QPalette::Text);
1517 painter->setPen(textColor);
1518 painter->setBrush(Qt::NoBrush);
1519
1520 drawItemText(painter, labelRect, Qt::TextShowMnemonic |
1521 Qt::AlignHCenter | Qt::AlignCenter,
1522 bar->palette, bar->state & State_Enabled, bar->text,
1523 textColor.isValid() ? QPalette::NoRole :
1524 QPalette::WindowText);
1525
1526 for (int i = 0; i < gripRect.width(); ++i) {
1527 painter->setPen(i % 2 ? bar->palette.color(QPalette::Midlight)
1528 : Qt::white);
1529
1530 for (int j = 0; j < 4; ++j) {
1531 painter->drawPoint(i + gripRect.left(),
1532 gripRect.top() - 2 + i % 4 + 4 * j);
1533 }
1534 }
1535
1536 QPixmap maximizePixmap(":/images/internalmaximize.png");
1537 QPixmap minimizePixmap(":/images/internalminimize.png");
1538 QPixmap closePixmap(":/images/internalclose.png");
1539 QPixmap internalPixmap(":/images/internalsystem.png");
1540 QPixmap internalCloseDownPixmap(":/images/internalclosedown.png");
1541 QPixmap minimizeDownPixmap(":/images/internalminimizedown.png");
1542 QPixmap maximizeDownPixmap(":/images/internalmaximizedown.png");
1543
1544 if (bar->activeSubControls & SC_TitleBarCloseButton &&
1545 bar->state & State_Sunken)
1546 painter->drawPixmap(closeButtonRect.topLeft(),
1547 internalCloseDownPixmap);
1548 else
1549 painter->drawPixmap(closeButtonRect.topLeft(), closePixmap);
1550
1551 if (bar->activeSubControls & SC_TitleBarMinButton &&
1552 bar->state & State_Sunken)
1553 painter->drawPixmap(minButtonRect.topLeft(),
1554 minimizeDownPixmap);
1555 else
1556 painter->drawPixmap(minButtonRect.topLeft(), minimizePixmap);
1557
1558 if (bar->activeSubControls & SC_TitleBarMaxButton &&
1559 bar->state & State_Sunken)
1560 painter->drawPixmap(maxButtonRect.topLeft(),
1561 maximizeDownPixmap);
1562 else
1563 painter->drawPixmap(maxButtonRect.topLeft(), maximizePixmap);
1564
1565 painter->drawPixmap(systemButtonRect.topLeft(), internalPixmap);
1566
1567 break;
1568 }
1569 case CC_GroupBox: {
1570 const QStyleOptionGroupBox *box =
1571 qstyleoption_cast<const QStyleOptionGroupBox *>(option);
1572
1573 QRect frameRect = subControlRect(control, box, SC_GroupBoxFrame);
1574 QRect labelRect = subControlRect(control, box, SC_GroupBoxLabel);
1575 QRect contentsRect = subControlRect(control, box,
1576 SC_GroupBoxContents);
1577 QRect checkerRect = subControlRect(control, box,
1578 SC_GroupBoxCheckBox);
1579
1580 int y = labelRect.center().y();
1581
1582 painter->setPen(box->palette.color(QPalette::Button));
1583 painter->drawRect(frameRect.adjusted(2, y - frameRect.top(), -2,
1584 -2));
1585
1586 painter->setPen(box->palette.color(QPalette::Background));
1587
1588 if (box->subControls & SC_GroupBoxCheckBox) {
1589 painter->drawLine(checkerRect.left() - 1, y,
1590 checkerRect.right() + 2, y);
1591 QStyleOptionButton checker;
1592 checker.QStyleOption::operator=(*box);
1593 checker.rect = checkerRect;
1594 drawPrimitive(PE_IndicatorCheckBox, &checker, painter, widget);
1595 }
1596
1597 if (box->subControls & SC_GroupBoxLabel && !box->text.isEmpty()) {
1598 painter->drawLine(labelRect.left() - 1, y,
1599 labelRect.right() +1, y);
1600
1601 QColor textColor = box->textColor;
1602 if (textColor.isValid())
1603 painter->setPen(textColor);
1604
1605 drawItemText(painter, labelRect, Qt::TextShowMnemonic |
1606 Qt::AlignHCenter | int(box->textAlignment),
1607 box->palette, box->state & State_Enabled,
1608 box->text, textColor.isValid() ? QPalette::NoRole :
1609 QPalette::WindowText);
1610 }
1611 break;
1612 }
1613 case CC_SpinBox: {
1614 const QStyleOptionSpinBox *spinner =
1615 qstyleoption_cast<const QStyleOptionSpinBox *>(option);
1616
1617 QRect frameRect = subControlRect(control, spinner, SC_SpinBoxFrame);
1618 QRect upRect = subControlRect(control, spinner, SC_SpinBoxUp);
1619 QRect downRect = subControlRect(control, spinner, SC_SpinBoxDown);
1620
1621 painter->setPen(Qt::white);
1622 painter->drawRect(frameRect.adjusted(1, 1, -1, -1));
1623 painter->drawPoint(frameRect.bottomLeft());
1624
1625 painter->setPen(spinner->palette.color(QPalette::Mid));
1626 painter->drawRect(frameRect.adjusted(0, 0, -1, -2));
1627
1628 bool isEnabled = (spinner->state & State_Enabled);
1629 bool hover = isEnabled && (spinner->state & State_MouseOver);
1630 bool sunken = (spinner->state & State_Sunken);
1631 bool upIsActive = (spinner->activeSubControls == SC_SpinBoxUp);
1632 bool downIsActive = (spinner->activeSubControls == SC_SpinBoxDown);
1633 bool stepUpEnabled = spinner->stepEnabled &
1634 QAbstractSpinBox::StepUpEnabled;
1635 bool stepDownEnabled = spinner->stepEnabled &
1636 QAbstractSpinBox::StepDownEnabled;
1637
1638 painter->setBrush(spinner->palette.color(QPalette::Background));
1639
1640 painter->drawRect(upRect);
1641 if (upIsActive && stepUpEnabled) {
1642 if (sunken) {
1643 drawSunkenButtonShadow(painter, upRect,
1644 spinner->palette.color(QPalette::Mid));
1645 } else if (hover) {
1646 drawButtonHoverFrame(painter, upRect,
1647 spinner->palette.color(QPalette::Mid),
1648 spinner->palette.color(QPalette::Button));
1649 }
1650 }
1651
1652 QStyleOptionSpinBox upSpin = *spinner;
1653 upSpin.rect = upRect;
1654 drawPrimitive(PE_IndicatorSpinUp, &upSpin, painter, widget);
1655
1656 painter->drawRect(downRect);
1657 if (downIsActive && stepDownEnabled) {
1658 if (sunken) {
1659 drawSunkenButtonShadow(painter, downRect,
1660 spinner->palette.color(QPalette::Mid));
1661 } else if (hover) {
1662 drawButtonHoverFrame(painter, downRect,
1663 spinner->palette.color(QPalette::Mid),
1664 spinner->palette.color(QPalette::Button));
1665 }
1666 }
1667
1668 QStyleOptionSpinBox downSpin = *spinner;
1669 downSpin.rect = downRect;
1670 drawPrimitive(PE_IndicatorSpinDown, &downSpin, painter, widget);
1671
1672 break;
1673 }
1674 case CC_ToolButton: {
1675 const QStyleOptionToolButton *button =
1676 qstyleoption_cast<const QStyleOptionToolButton *>(option);
1677
1678 painter->setPen(Qt::white);
1679 painter->drawRect(button->rect.adjusted(1, 1, -1, -1));
1680
1681 QStyleOptionToolButton panelOption = *button;
1682 QRect panelRect;
1683 if (!(button->state & State_MouseOver) &&
1684 !(button->state & State_On)) {
1685 painter->setPen(QColor(153, 153, 153));
1686 painter->drawRect(button->rect.adjusted(0, 0, -2, -2));
1687
1688 panelRect = subControlRect(control, option, SC_ToolButton);
1689 panelOption.rect = panelRect;
1690 } else {
1691 panelOption.rect.adjust(0, 0, -1, -1);
1692 }
1693
1694 QRect menuRect = subControlRect(control, option, SC_ToolButtonMenu);
1695
1696 drawPrimitive(PE_PanelButtonTool, &panelOption, painter, widget);
1697
1698 QStyleOptionToolButton menuOption = *button;
1699 menuOption.rect = menuRect;
1700
1701 QStyleOptionToolButton label = *button;
1702 int fw = 5;
1703
1704 drawControl(CE_ToolButtonLabel, &label, painter, widget);
1705 if (button->subControls & SC_ToolButtonMenu) {
1706 painter->setPen(button->palette.color(QPalette::WindowText));
1707 drawPrimitive(PE_IndicatorArrowDown, &menuOption, painter, widget);
1708 }
1709
1710 if (button->state & State_HasFocus) {
1711 QStyleOptionToolButton focusOption = *button;
1712 focusOption.rect = label.rect.adjusted(-1, -1, 1, 1);
1713
1714 drawPrimitive(PE_FrameFocusRect, &focusOption, painter, widget);
1715 }
1716
1717 break;
1718 }
1719 case CC_ComboBox: {
1720 const QStyleOptionComboBox *combo =
1721 qstyleoption_cast<const QStyleOptionComboBox *>(option);
1722
1723 QRect frameRect = subControlRect(control, option, SC_ComboBoxFrame,
1724 widget);
1725 painter->setPen(combo->palette.color(QPalette::Mid));
1726
1727 if (option->state & State_HasFocus)
1728 painter->setBrush(option->palette.color(QPalette::Light));
1729 else
1730 painter->setBrush(combo->palette.color(QPalette::Background));
1731
1732 painter->drawRect(frameRect.adjusted(0, 0, -1, -1));
1733
1734 QRect arrowRect = subControlRect(control, option, SC_ComboBoxArrow,
1735 widget);
1736 painter->setPen(combo->palette.color(QPalette::Button));
1737 painter->setBrush(Qt::NoBrush);
1738
1739 if (combo->direction == Qt::LeftToRight) {
1740 painter->drawRect(QRect(frameRect.topLeft() + QPoint(1, 1),
1741 arrowRect.bottomLeft() + QPoint(-2, -2)));
1742 } else {
1743 painter->drawRect(QRect(arrowRect.topLeft() + QPoint(1, 1),
1744 frameRect.bottomRight() + QPoint(-2, -2)));
1745 }
1746
1747 QStyleOptionButton button;
1748 button.rect = arrowRect;
1749 button.state = combo->state;
1750 button.palette = combo->palette;
1751
1752 if (button.state & State_On)
1753 button.state ^= State_On;
1754
1755 painter->save();
1756 drawButtonBackground(&button, painter, false);
1757 painter->restore();
1758
1759 QPoint center = arrowRect.center();
1760 QPoint offset = QPoint(arrowRect.bottomLeft().x() + 1,
1761 center.y() + 7);
1762 QPainterPath arrow;
1763 arrow.moveTo(offset + QPoint(4, -8));
1764 arrow.lineTo(offset + QPoint(7, -5));
1765 arrow.lineTo(offset + QPoint(8, -5));
1766 arrow.lineTo(offset + QPoint(11, -8));
1767 arrow.lineTo(offset + QPoint(4, -8));
1768
1769 painter->setBrush(combo->palette.color(QPalette::WindowText));
1770 painter->setPen(combo->palette.color(QPalette::WindowText));
1771
1772 painter->drawPath(arrow);
1773
1774 QRect fieldRect = subControlRect(control, option,
1775 SC_ComboBoxEditField, widget);
1776
1777 break;
1778 }
1779 case CC_Slider: {
1780 const QStyleOptionSlider *slider =
1781 qstyleoption_cast<const QStyleOptionSlider *>(option);
1782
1783 bool horizontal = slider->orientation == Qt::Horizontal;
1784
1785 QRect groove = subControlRect(control, option, SC_SliderGroove,
1786 widget);
1787 QRect ticks = subControlRect(control, option, SC_SliderTickmarks,
1788 widget);
1789 QRect handle = subControlRect(control, option, SC_SliderHandle,
1790 widget);
1791
1792 QRect afterHandle = QRect(handle.topLeft() + xySwitch(QPoint(4, 6), horizontal),
1793 groove.bottomRight() + xySwitch(QPoint(-4, -6), horizontal));
1794 QRect beforeHandle = QRect(groove.topLeft() + xySwitch(QPoint(4, 6), horizontal),
1795 handle.bottomRight() + xySwitch(QPoint(-4, -6), horizontal));
1796
1797 if (slider->upsideDown || !horizontal) {
1798 QRect remember;
1799 remember = afterHandle;
1800 afterHandle = beforeHandle;
1801 beforeHandle = remember;
1802 }
1803
1804 painter->setPen(slider->palette.color(QPalette::Mid));
1805 painter->setBrush(option->palette.color(QPalette::Background));
1806 painter->drawRect(afterHandle);
1807 painter->setPen(slider->palette.color(QPalette::Light));
1808 painter->drawLine(afterHandle.topLeft() + xySwitch(QPoint(0, 1), horizontal),
1809 afterHandle.topRight() + xySwitch(QPoint(0, 1), horizontal));
1810 painter->setPen(option->palette.color(QPalette::Midlight));
1811
1812 if (horizontal) {
1813 painter->setBrush(gradientBrush(QRect(QPoint(groove.x(),
1814 handle.y() + 1),
1815 QSize(groove.width(),
1816 handle.height() + 1))));
1817 } else {
1818 QRect rect = QRect(QPoint(groove.x(),
1819 handle.x() - 1),
1820 QSize(groove.height(),
1821 handle.width() + 1));
1822 QLinearGradient gradient(groove.bottomLeft(),
1823 groove.bottomRight());
1824 gradient.setColorAt(1.0, QColor(188, 210, 230));
1825 gradient.setColorAt(0.3, Qt::white);
1826 gradient.setColorAt(0.0, QColor(223, 233, 243));
1827
1828 painter->setBrush(gradient);
1829 }
1830
1831 painter->drawRect(beforeHandle);
1832
1833 QPainterPath handlePath;
1834 QPainterPath innerPath;
1835 QPoint topLeft, topRight, bottomLeft;
1836 if (horizontal) {
1837 topLeft = handle.topLeft();
1838 topRight = handle.topRight();
1839 bottomLeft = handle.bottomLeft();
1840 } else {
1841 topLeft = handle.bottomLeft();
1842 topRight = handle.topLeft();
1843 bottomLeft = handle.topRight();
1844 }
1845
1846 if (horizontal) {
1847 QImage image(sliderHandleImage);
1848
1849 image.setColor(1,
1850 option->palette.color(QPalette::Midlight).rgb());
1851 image.setColor(2,
1852 option->palette.color(QPalette::Button).rgb());
1853
1854 if (!(slider->state & State_Enabled)) {
1855 image.setColor(4, slider->palette.color(QPalette::Background).rgb());
1856 image.setColor(5, slider->palette.color(QPalette::Background).rgb());
1857 image.setColor(6, slider->palette.color(QPalette::Background).rgb());
1858 }
1859
1860 painter->drawImage(handle.topLeft(), image);
1861 } else {
1862 QImage image(":/images/verticalsliderhandle.png");
1863 painter->drawImage(handle.topLeft(), image);
1864 }
1865
1866 if (slider->tickPosition & QSlider::TicksBelow) {
1867 painter->setPen(slider->palette.color(QPalette::Light));
1868 int tickInterval = slider->tickInterval ? slider->tickInterval :
1869 slider->pageStep;
1870
1871 for (int i = 0; i <= slider->maximum; i += tickInterval) {
1872 if (horizontal) {
1873 int pos = int(((i / double(slider->maximum)) *
1874 ticks.width()) - 1);
1875 painter->drawLine(QPoint(ticks.left() + pos,
1876 ticks.top() + 2), QPoint(ticks.left() + pos, ticks.top() + 8));
1877 } else {
1878 int pos = int(((i / double(slider->maximum)) *
1879 ticks.height()) - 1);
1880 painter->drawLine(QPoint(ticks.left() + 2, ticks.bottom() - pos),
1881 QPoint(ticks.right() - 2, ticks.bottom() - pos));
1882 }
1883 }
1884 if (horizontal) {
1885 painter->drawLine(QPoint(ticks.right(), ticks.top() + 2),
1886 QPoint(ticks.right(), ticks.top() + 8));
1887 } else {
1888 painter->drawLine(QPoint(ticks.left() + 2, ticks.top()),
1889 QPoint(ticks.right() - 2, ticks.top()));
1890 }
1891 }
1892 break;
1893 }
1894 default:
1895 QWindowsStyle::drawComplexControl(control, option, painter, widget);
1896 }
1897 painter->restore();
1898}
1899
1900inline void JavaStyle::drawSunkenButtonShadow(QPainter *painter,
1901 QRect rect,
1902 const QColor &frameColor,
1903 bool reverse) const
1904{
1905 painter->save();
1906
1907 painter->setPen(frameColor);
1908
1909 if (!reverse) {
1910 painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y() + 1),
1911 QPoint(rect.x() + rect.width() - 1, rect.y() + 1)));
1912 painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y()),
1913 QPoint(rect.x() + 1, rect.y() + rect.height())));
1914 } else {
1915 painter->drawLine(QLine(QPoint(rect.right(), rect.bottom()),
1916 QPoint(rect.right(), rect.top())));
1917 painter->drawLine(QLine(QPoint(rect.left(), rect.top() + 1),
1918 QPoint(rect.right(), rect.top() + 1)));
1919 }
1920 painter->restore();
1921}
1922
1923inline void JavaStyle::drawButtonHoverFrame(QPainter *painter, QRect rect,
1924 const QColor &frameColor,
1925 const QColor &activeFrame) const
1926{
1927 painter->save();
1928
1929 painter->setPen(activeFrame);
1930 painter->drawRect(rect);
1931 rect.adjust(1, 1, -1, -1);
1932 painter->setPen(frameColor);
1933 painter->drawRect(rect);
1934 rect.adjust(1, 1, -1, -1);
1935 painter->setPen(activeFrame);
1936 painter->drawRect(rect);
1937
1938 painter->restore();
1939}
1940
1941QStyle::SubControl JavaStyle::hitTestComplexControl(ComplexControl control,
1942 const QStyleOptionComplex *option,
1943 const QPoint &pos,
1944 const QWidget *widget) const
1945{
1946 SubControl ret = SC_None;
1947
1948 switch (control) {
1949 case CC_TitleBar: {
1950 const QStyleOptionTitleBar *bar =
1951 qstyleoption_cast<const QStyleOptionTitleBar *>(option);
1952
1953 QRect maximize = subControlRect(control, bar, SC_TitleBarMaxButton);
1954 if (maximize.contains(pos)) {
1955 ret = SC_TitleBarMaxButton;
1956 break;
1957 }
1958 QRect minimize = subControlRect(control, bar, SC_TitleBarMinButton);
1959 if (minimize.contains(pos)) {
1960 ret = SC_TitleBarMinButton;
1961 break;
1962 }
1963 QRect close = subControlRect(control, bar, SC_TitleBarCloseButton);
1964 if (close.contains(pos)) {
1965 ret = SC_TitleBarCloseButton;
1966 break;
1967 }
1968 QRect system = subControlRect(control, bar, SC_TitleBarSysMenu);
1969 if (system.contains(pos)) {
1970 ret = SC_TitleBarSysMenu;
1971 break;
1972 }
1973 ret = SC_TitleBarLabel;
1974 break;
1975 }
1976 case CC_ScrollBar:
1977 if (const QStyleOptionSlider *scrollBar =
1978 qstyleoption_cast<const QStyleOptionSlider *>(option)) {
1979 QRect slider = subControlRect(control, scrollBar,
1980 SC_ScrollBarSlider, widget);
1981 if (slider.contains(pos)) {
1982 ret = SC_ScrollBarSlider;
1983 break;
1984 }
1985
1986 QRect scrollBarAddLine = subControlRect(control, scrollBar,
1987 SC_ScrollBarAddLine, widget);
1988 if (scrollBarAddLine.contains(pos)) {
1989 ret = SC_ScrollBarAddLine;
1990 break;
1991 }
1992
1993 QRect scrollBarSubPage = subControlRect(control, scrollBar,
1994 SC_ScrollBarSubPage, widget);
1995 if (scrollBarSubPage.contains(pos)) {
1996 ret = SC_ScrollBarSubPage;
1997 break;
1998 }
1999
2000 QRect scrollBarAddPage = subControlRect(control, scrollBar,
2001 SC_ScrollBarAddPage, widget);
2002 if (scrollBarAddPage.contains(pos)) {
2003 ret = SC_ScrollBarAddPage;
2004 break;
2005 }
2006
2007 QRect scrollBarSubLine = subControlRect(control, scrollBar,
2008 SC_ScrollBarSubLine, widget);
2009 if (scrollBarSubLine.contains(pos)) {
2010 ret = SC_ScrollBarSubLine;
2011 break;
2012 }
2013 }
2014 break;
2015
2016 default:
2017 ret = QWindowsStyle::hitTestComplexControl(control, option, pos,
2018 widget);
2019 }
2020 return ret;
2021}
2022
2023void JavaStyle::polish(QWidget *widget)
2024{
2025 if (qobject_cast<QCheckBox *>(widget) ||
2026 qobject_cast<QRadioButton *>(widget) ||
2027 qobject_cast<QPushButton *>(widget) ||
2028 qobject_cast<QToolButton *>(widget) ||
2029 qobject_cast<QSpinBox *>(widget) ||
2030 qobject_cast<QGroupBox *>(widget))
2031 widget->setAttribute(Qt::WA_Hover, true);
2032}
2033
2034void JavaStyle::unpolish(QWidget *widget)
2035{
2036 if (qobject_cast<QPushButton *>(widget) ||
2037 qobject_cast<QCheckBox *>(widget) ||
2038 qobject_cast<QRadioButton *>(widget) ||
2039 qobject_cast<QToolButton *>(widget) ||
2040 qobject_cast<QSpinBox *>(widget) ||
2041 qobject_cast<QGroupBox *>(widget))
2042 widget->setAttribute(Qt::WA_Hover, false);
2043}
2044
2045void JavaStyle::drawSplitter(const QStyleOption *option, QPainter *painter,
2046 bool horizontal) const
2047{
2048 QRect rect = option->rect;
2049
2050 painter->setPen(Qt::NoPen);
2051 painter->setBrush(option->palette.color(QPalette::Background));
2052
2053 painter->drawRect(rect);
2054
2055 QColor colors[] = { Qt::white, option->palette.color(QPalette::Mid) };
2056 int iterations = horizontal ? rect.height() - 1 : rect.width() - 1;
2057 for (int i = 0; i < iterations; ++i) {
2058 painter->setPen(colors[i % 2]);
2059 painter->drawPoint(xySwitch(QPoint(rect.x() + 0 + (i % 4),
2060 rect.y() + i), horizontal));
2061 }
2062}
2063
2064inline QPoint JavaStyle::xySwitch(const QPoint &point, bool horizontal) const
2065{
2066 QPoint retPoint = point;
2067
2068 if (!horizontal) {
2069 retPoint = QPoint(point.y(), point.x());
2070 }
2071
2072 return retPoint;
2073}
2074
2075void JavaStyle::drawPrimitive(PrimitiveElement element,
2076 const QStyleOption *option,
2077 QPainter *painter,
2078 const QWidget *widget) const
2079{
2080 painter->save();
2081
2082 switch (element) {
2083 case PE_PanelButtonBevel:
2084 case PE_FrameButtonBevel: {
2085 painter->save();
2086 painter->setBrush(option->palette.background());
2087 painter->setPen(Qt::NoPen);
2088 painter->drawRect(option->rect);
2089 painter->restore();
2090 break;
2091 }
2092 case PE_IndicatorBranch: {
2093 painter->save();
2094 QColor lineColor(204, 204, 255);
2095 QPixmap openPixmap(":/images/jtreeopen.png");
2096 QPixmap closedPixmap(":/images/jtreeclosed.png");
2097 QRect pixmapRect(QPoint(0, 0), QSize(12, 12));
2098 pixmapRect.moveCenter(option->rect.center());
2099 pixmapRect.translate(2, 0);
2100 QPoint center = option->rect.center();
2101
2102 painter->setPen(lineColor);
2103 painter->setBrush(Qt::NoBrush);
2104
2105 if (option->state & State_Item) {
2106 painter->drawLine(center,
2107 QPoint(option->rect.right(), center.y()));
2108
2109 painter->drawLine(center, QPoint(center.x(),
2110 option->rect.top()));
2111
2112 if (option->state & State_Sibling) {
2113 painter->drawLine(center, QPoint(center.x(),
2114 option->rect.bottom()));
2115 }
2116
2117 if (option->state & State_Children)
2118 if (option->state & State_Open)
2119 painter->drawPixmap(pixmapRect.topLeft(), closedPixmap);
2120 else
2121 painter->drawPixmap(pixmapRect.topLeft(), openPixmap);
2122 } else if (option->state & State_Sibling) {
2123 painter->drawLine(center.x(), option->rect.top(), center.x(),
2124 option->rect.bottom());
2125 }
2126
2127 painter->restore();
2128 break;
2129 }
2130 case PE_IndicatorViewItemCheck: {
2131 break;
2132 }
2133 case PE_FrameWindow: {
2134 painter->save();
2135 bool active = option->state & State_Active;
2136
2137 painter->setPen(Qt::NoPen);
2138 painter->setBrush(active ? option->palette.color(QPalette::Midlight)
2139 : option->palette.color(QPalette::Mid));
2140
2141 painter->drawRect(QRect(option->rect.topLeft(), option->rect.bottomLeft() + QPoint(5, 0)));
2142 painter->drawRect(QRect(option->rect.bottomLeft(), option->rect.bottomRight() + QPoint(0, -5)));
2143 painter->drawRect(QRect(option->rect.bottomRight() + QPoint(-5, 0), option->rect.topRight()));
2144 painter->drawRect(QRect(option->rect.topLeft(), option->rect.topRight() + QPoint(0, 4)));
2145
2146 painter->setBrush(Qt::NoBrush);
2147 painter->setPen(option->palette.color(QPalette::Active, QPalette::WindowText));
2148 painter->drawLine(option->rect.topLeft() + QPoint(2, 14),
2149 option->rect.bottomLeft() + QPoint(2, -14));
2150
2151 painter->drawLine(option->rect.topRight() + QPoint(-2, 14),
2152 option->rect.bottomRight() + QPoint(-2, -14));
2153
2154 painter->drawLine(option->rect.topLeft() + QPoint(14, 2),
2155 option->rect.topRight() + QPoint(-14, 2));
2156
2157 painter->drawLine(option->rect.bottomLeft() + QPoint(14, -2),
2158 option->rect.bottomRight() + QPoint(-14, -2));
2159
2160 painter->setPen(active ? option->palette.color(QPalette::Light) :
2161 option->palette.color(QPalette::Button));
2162 painter->drawLine(option->rect.topLeft() + QPoint(3, 15),
2163 option->rect.bottomLeft() + QPoint(3, -13));
2164
2165 painter->drawLine(option->rect.topRight() + QPoint(-1, 15),
2166 option->rect.bottomRight() + QPoint(-1, -13));
2167
2168 painter->drawLine(option->rect.topLeft() + QPoint(15, 3),
2169 option->rect.topRight() + QPoint(-13, 3));
2170
2171 painter->drawLine(option->rect.bottomLeft() + QPoint(15, -1),
2172 option->rect.bottomRight() + QPoint(-13, -1));
2173
2174 painter->restore();
2175 break;
2176 }
2177 case PE_IndicatorSpinUp: {
2178 const QStyleOptionSpinBox *spinner =
2179 qstyleoption_cast<const QStyleOptionSpinBox *>(option);
2180 int add = spinner->state & State_Sunken &&
2181 spinner->activeSubControls & SC_SpinBoxUp ? 1 : 0;
2182
2183 QPoint center = option->rect.center();
2184 painter->drawLine(center.x() + add, center.y() + 1 + add,
2185 center.x() + 2 + add, center.y() + 1 + add);
2186 painter->drawPoint(center.x() + 1 + add, center.y() + add);
2187 break;
2188 }
2189 case PE_IndicatorSpinDown: {
2190 const QStyleOptionSpinBox *spinner =
2191 qstyleoption_cast<const QStyleOptionSpinBox *>(option);
2192
2193 int add = spinner->state & State_Sunken &&
2194 spinner->activeSubControls & SC_SpinBoxDown ? 1 : 0;
2195 QPoint center = option->rect.center();
2196 painter->drawLine(center.x() + add, center.y() + add,
2197 center.x() + 2 + add, center.y() + add);
2198 painter->drawPoint(center.x() + 1 + add, center.y() + 1 + add);
2199 break;
2200 }
2201 case PE_FrameDockWidget: {
2202 drawPrimitive(PE_FrameWindow, option, painter, widget);
2203 break;
2204 }
2205 case PE_IndicatorToolBarHandle: {
2206 QPoint offset;
2207 bool horizontal = option->state & State_Horizontal;
2208
2209 if (horizontal)
2210 offset = option->rect.topLeft();
2211 else
2212 offset = option->rect.topLeft();
2213
2214 int iterations = horizontal ? option->rect.height() :
2215 option->rect.width();
2216
2217 for (int i = 0; i < iterations; ++i) {
2218 painter->setPen(i % 2 ? Qt::white :
2219 option->palette.color(QPalette::Mid));
2220 int add = i % 4;
2221 painter->drawPoint(offset + xySwitch(QPoint(add, i),
2222 horizontal));
2223 painter->drawPoint(offset + xySwitch(QPoint(add + 4, i),
2224 horizontal));
2225 if (add + 8 < 10)
2226 painter->drawPoint(offset + xySwitch(QPoint(add + 8, i),
2227 horizontal));
2228 }
2229
2230 break;
2231 }
2232 case PE_IndicatorToolBarSeparator: {
2233 break;
2234 }
2235 case PE_PanelButtonTool: {
2236 const QStyleOptionToolButton *button =
2237 qstyleoption_cast<const QStyleOptionToolButton *>(option);
2238
2239 if (!button) {
2240 painter->setPen(Qt::red);
2241 if (!(option->state & State_Enabled))
2242 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2243 drawButtonBackground(option, painter, false);
2244 break;
2245 }
2246
2247 if (button->state & State_MouseOver || button->state & State_On) {
2248 QStyleOptionButton bevel;
2249 bevel.state = button->state;
2250 bevel.rect = button->rect;
2251 bevel.palette = button->palette;
2252
2253 drawButtonBackground(&bevel, painter, false);
2254 } else {
2255 painter->setPen(Qt::NoPen);
2256 painter->setBrush(button->palette.color(QPalette::Background));
2257
2258 painter->drawRect(button->rect.adjusted(0, 0, -1, -1));
2259 }
2260 break;
2261 }
2262 case PE_FrameMenu: {
2263 painter->setPen(option->palette.color(QPalette::Midlight));
2264 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2265 break;
2266 }
2267 case PE_PanelButtonCommand: {
2268 const QStyleOptionButton *btn =
2269 qstyleoption_cast<const QStyleOptionButton *>(option);
2270 bool hover = (btn->state & State_Enabled) &&
2271 (btn->state & State_MouseOver);
2272 bool sunken = btn->state & State_Sunken;
2273 bool isDefault = btn->features & QStyleOptionButton::DefaultButton;
2274 bool on = option->state & State_On;
2275
2276 drawButtonBackground(option, painter, false);
2277
2278 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2279 if (hover && !sunken && !isDefault && !on) {
2280 drawButtonHoverFrame(painter, rect,
2281 btn->palette.color(QPalette::Mid),
2282 btn->palette.color(QPalette::Button));
2283 } else if (isDefault) {
2284 drawPrimitive(PE_FrameDefaultButton, option, painter, widget);
2285 }
2286 break;
2287 }
2288 case PE_FrameDefaultButton: {
2289 painter->setPen(option->palette.color(QPalette::Mid));
2290 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2291 painter->drawRect(rect);
2292 painter->drawRect(rect.adjusted(1, 1, -1, -1));
2293 break;
2294 }
2295//! [0]
2296 case PE_IndicatorCheckBox: {
2297 painter->save();
2298 drawButtonBackground(option, painter, true);
2299
2300 if (option->state & State_Enabled &&
2301 option->state & State_MouseOver &&
2302 !(option->state & State_Sunken)) {
2303 painter->setPen(option->palette.color(QPalette::Button));
2304 QRect rect = option->rect.adjusted(1, 1, -2, -2);
2305 painter->drawRect(rect);
2306 rect = rect.adjusted(1, 1, -1, -1);
2307 painter->drawRect(rect);
2308 }
2309
2310 if (option->state & State_On) {
2311 QImage image(":/images/checkboxchecked.png");
2312 painter->drawImage(option->rect.topLeft(), image);
2313 }
2314 painter->restore();
2315 break;
2316//! [0]
2317 }
2318 case PE_IndicatorRadioButton: {
2319 painter->save();
2320 QBrush radioBrush = option->palette.button();
2321
2322 if (!(option->state & State_Sunken) &&
2323 option->state & State_Enabled)
2324 radioBrush = gradientBrush(option->rect);
2325
2326 painter->setBrush(radioBrush);
2327 if (option->state & State_Enabled)
2328 painter->setPen(option->palette.color(QPalette::Mid));
2329 else
2330 painter->setPen(option->palette.color(QPalette::Disabled,
2331 QPalette::WindowText));
2332 painter->drawEllipse(option->rect.adjusted(0, 0, -1, -1));
2333
2334 if (option->state & State_MouseOver &&
2335 option->state & State_Enabled &&
2336 !(option->state & State_Sunken)) {
2337 gradientBrush(option->rect);
2338 painter->setPen(option->palette.color(QPalette::Button));
2339 painter->setBrush(Qt::NoBrush);
2340 QRect rect = option->rect.adjusted(1, 1, -2, -2);
2341 painter->drawEllipse(rect);
2342 rect = rect.adjusted(1, 1, -1, -1);
2343 painter->drawEllipse(rect);
2344 }
2345
2346 if (option->state & State_On) {
2347 painter->setBrush(option->palette.color(QPalette::Text));
2348 painter->setPen(Qt::NoPen);
2349 painter->drawEllipse(option->rect.adjusted(3, 3, -3, -3));
2350 }
2351 if (option->state & State_Sunken &&
2352 option->state & State_Enabled) {
2353 painter->setPen(option->palette.color(QPalette::Mid));
2354 painter->drawArc(option->rect.adjusted(1, 1, -2, -2), 80 * 16,
2355 100 * 16);
2356 }
2357 painter->restore();
2358 break;
2359 }
2360 case PE_FrameTabWidget: {
2361 painter->setPen(option->palette.color(QPalette::Midlight));
2362 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2363 painter->setPen(Qt::white);
2364 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
2365 break;
2366 }
2367 case PE_Frame:
2368 case PE_FrameLineEdit: {
2369 const QStyleOptionFrame *frame =
2370 qstyleoption_cast<const QStyleOptionFrame *>(option);
2371 const QStyleOptionFrameV2 frameV2(*frame);
2372
2373 painter->setPen(frame->palette.color(QPalette::Mid));
2374 painter->drawRect(frameV2.rect.adjusted(0, 0, -2, -2));
2375 painter->setPen(Qt::white);
2376 painter->drawRect(frameV2.rect.adjusted(1, 1, -1, -1));
2377 painter->setPen(frameV2.palette.color(QPalette::Active,
2378 QPalette::Background));
2379 painter->drawLine(frameV2.rect.bottomLeft(),
2380 frameV2.rect.bottomLeft() + QPoint(1, -1));
2381 painter->drawLine(frameV2.rect.topRight(),
2382 frameV2.rect.topRight() + QPoint(-1, 1));
2383 break;
2384 }
2385 case PE_FrameFocusRect: {
2386 painter->setPen(option->palette.color(QPalette::Light));
2387 painter->setBrush(Qt::NoBrush);
2388 QRect rect = option->rect;
2389 rect = rect.adjusted(0,0, -1, -1);
2390 painter->drawRect(rect);
2391 break;
2392 }
2393 default:
2394 QWindowsStyle::drawPrimitive(element, option, painter, widget);
2395 }
2396 painter->restore();
2397}
2398
2399//! [1]
2400void JavaStyle::drawButtonBackground(const QStyleOption *option,
2401 QPainter *painter, bool isCheckbox) const
2402{
2403 QBrush buttonBrush = option->palette.button();
2404 bool sunken = option->state & State_Sunken;
2405 bool disabled = !(option->state & State_Enabled);
2406 bool on = option->state & State_On;
2407
2408 if (!sunken && !disabled && (!on || isCheckbox))
2409 buttonBrush = gradientBrush(option->rect);
2410
2411 painter->fillRect(option->rect, buttonBrush);
2412
2413 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2414
2415 if (disabled)
2416 painter->setPen(option->palette.color(QPalette::Disabled,
2417 QPalette::WindowText));
2418 else
2419 painter->setPen(option->palette.color(QPalette::Mid));
2420
2421 painter->drawRect(rect);
2422
2423 if (sunken && !disabled) {
2424 drawSunkenButtonShadow(painter, rect,
2425 option->palette.color(QPalette::Mid),
2426 option->direction == Qt::RightToLeft);
2427 }
2428}
2429//! [1]
2430
2431QBrush JavaStyle::gradientBrush(const QRect &rect) const
2432{
2433 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
2434 gradient.setColorAt(1.0, QColor(188, 210, 230));
2435 gradient.setColorAt(0.3, Qt::white);
2436 gradient.setColorAt(0.0, QColor(223, 233, 243));
2437
2438 return QBrush(gradient);
2439}
2440
2441QRect JavaStyle::subElementRect(SubElement element,
2442 const QStyleOption *option,
2443 const QWidget *widget) const
2444{
2445 QRect rect;
2446
2447 switch (element) {
2448 case SE_ToolBoxTabContents: {
2449 const QStyleOptionToolBox *box =
2450 qstyleoption_cast<const QStyleOptionToolBox *>(option);
2451
2452 rect.moveTopLeft(box->rect.topLeft() + QPoint(0, 2));
2453 rect.setHeight(box->rect.height() - 4);
2454 rect.setWidth(box->fontMetrics.width(box->text) + 15);
2455 break;
2456 }
2457 case SE_ProgressBarLabel:
2458 case SE_ProgressBarGroove:
2459 case SE_ProgressBarContents: {
2460 rect = option->rect.adjusted(1, 1, -1, -1);
2461 break;
2462 }
2463 case SE_PushButtonFocusRect: {
2464 const QStyleOptionButton *btn =
2465 qstyleoption_cast<const QStyleOptionButton *>(option);
2466
2467 rect = btn->fontMetrics.boundingRect(btn->text);
2468 rect = QRect(0, 0, btn->fontMetrics.width(btn->text),
2469 rect.height());
2470
2471 if (!btn->icon.isNull()) {
2472 rect.adjust(0, 0, btn->iconSize.width(), btn->iconSize.height()
2473 > rect.height() ? btn->iconSize.height() - rect.height() : 0);
2474 rect.translate(-btn->iconSize.width(), 0);
2475 rect.adjust(-1, -1, 1, 1);
2476 }
2477 rect = QRect(int(ceil((btn->rect.width() - rect.width()) / 2.0)),
2478 int(ceil((btn->rect.height() - rect.height()) / 2.0)),
2479 rect.width() - 1, rect.height());
2480 rect.adjust(-1, 0, 1, 0);
2481
2482 break;
2483 }
2484 default:
2485 rect = QWindowsStyle::subElementRect(element, option, widget);
2486 }
2487 return rect;
2488}
2489
2490int JavaStyle::pixelMetric(PixelMetric metric,
2491 const QStyleOption* /* option */,
2492 const QWidget* /*widget*/) const
2493{
2494 int value = 0;
2495
2496 switch (metric) {
2497 case PM_ButtonShiftHorizontal:
2498 case PM_ButtonShiftVertical:
2499 case PM_TabBarTabShiftHorizontal:
2500 case PM_ButtonDefaultIndicator:
2501 case PM_TabBarTabShiftVertical:
2502 value = 0;
2503 break;
2504 case PM_TabBarBaseOverlap:
2505 case PM_DefaultFrameWidth:
2506 value = 2;
2507 break;
2508 case PM_TabBarTabVSpace:
2509 value = 4;
2510 break;
2511 case PM_ScrollBarExtent:
2512 value = 16;
2513 break;
2514 case PM_ScrollBarSliderMin:
2515 value = 26;
2516 break;
2517 case PM_SplitterWidth:
2518 value = 8;
2519 break;
2520 case PM_SliderThickness:
2521 value = 16;
2522 break;
2523 case PM_SliderControlThickness:
2524 value = 16;
2525 break;
2526 case PM_SliderTickmarkOffset:
2527 value = 10;
2528 break;
2529 case PM_SliderSpaceAvailable:
2530 break;
2531 case PM_MenuPanelWidth:
2532 value = 1;
2533 break;
2534 case PM_MenuVMargin:
2535 value = 2;
2536 break;
2537 case PM_MenuBarPanelWidth:
2538 value = 1;
2539 break;
2540 case PM_MenuBarItemSpacing:
2541 value = 0;
2542 break;
2543 case PM_MenuBarHMargin:
2544 value = 3;
2545 break;
2546 case PM_MenuBarVMargin:
2547 value = 0;
2548 break;
2549 case PM_ComboBoxFrameWidth:
2550 value = 1;
2551 break;
2552 case PM_MenuButtonIndicator:
2553 value = 15;
2554 break;
2555 case PM_ToolBarItemMargin:
2556 value = 3;
2557 break;
2558 case PM_ToolBarHandleExtent:
2559 value = 13;
2560 break;
2561 case PM_SpinBoxFrameWidth:
2562 value = 2;
2563 break;
2564 case PM_TitleBarHeight: {
2565 value = 21;
2566 break;
2567 case PM_MDIFrameWidth:
2568 value = 6;
2569 break;
2570 }
2571 case PM_DockWidgetFrameWidth: {
2572 value = 5;
2573 break;
2574 }
2575 default:
2576 value = QWindowsStyle::pixelMetric(metric);
2577 }
2578 return value;
2579}
2580
2581
2582int JavaStyle::styleHint(StyleHint hint, const QStyleOption *option,
2583 const QWidget *widget,
2584 QStyleHintReturn *returnData) const
2585{
2586 int ret;
2587
2588 switch (hint) {
2589 case SH_Table_GridLineColor: {
2590 ret = static_cast<int>(option->palette.color(QPalette::Mid).rgb());
2591 break;
2592 }
2593 case QStyle::SH_Menu_Scrollable:
2594 ret = 1;
2595 break;
2596 default:
2597 ret = QWindowsStyle::styleHint(hint, option, widget, returnData);
2598 }
2599 return ret;
2600}
2601
2602QPixmap JavaStyle::standardPixmap(StandardPixmap standardPixmap,
2603 const QStyleOption *option,
2604 const QWidget *widget) const
2605{
2606 QPixmap pixmap = QWindowsStyle::standardPixmap(standardPixmap, option,
2607 widget);
2608
2609 QPixmap maximizePixmap(":/images/internalmaximize.png");
2610 QPixmap minimizePixmap(":/images/internalminimize.png");
2611 QPixmap closePixmap(":/images/internalclose.png");
2612 QPixmap internalPixmap(":/images/internalsystem.png");
2613 QPixmap internalCloseDownPixmap(":/images/internalclosedown.png");
2614 QPixmap minimizeDownPixmap(":/images/internalminimizedown.png");
2615 QPixmap maximizeDownPixmap(":/images/internalmaximizedown.png");
2616 QPixmap dirOpenPixmap(":/images/open24.png");
2617 QPixmap filePixmap(":/images/file.png");
2618
2619 switch (standardPixmap) {
2620 case SP_DirLinkIcon:
2621 case SP_DirClosedIcon:
2622 case SP_DirIcon:
2623 case SP_DirOpenIcon: {
2624 pixmap = closePixmap;
2625 break;
2626 }
2627 case SP_FileIcon: {
2628 pixmap = filePixmap;
2629 break;
2630 }
2631 case SP_FileDialogBack: {
2632 pixmap = QPixmap(":/images/fileback.png");
2633 break;
2634 }
2635 case SP_FileDialogToParent: {
2636 pixmap = QPixmap(":/images/fileparent.png");
2637 break;
2638 }
2639 case SP_FileDialogNewFolder: {
2640 pixmap = QPixmap(":/images/open24.png");
2641 break;
2642 }
2643 case SP_FileDialogListView: {
2644 pixmap = QPixmap(":/images/filelist.png");
2645 break;
2646 }
2647 case SP_FileDialogDetailedView: {
2648 pixmap = QPixmap(":/images/filedetail.png");
2649 break;
2650 }
2651 case SP_MessageBoxInformation: {
2652 pixmap = QPixmap(":/images/information.png");
2653 break;
2654 }
2655 case SP_MessageBoxWarning: {
2656 pixmap = QPixmap(":/images/warning.png");
2657 }
2658 case SP_MessageBoxCritical: {
2659 pixmap = QPixmap(":/images/critical.png");
2660 break;
2661 }
2662 case SP_MessageBoxQuestion: {
2663 pixmap = QPixmap(":/images/question.png");
2664 break;
2665 }
2666 case SP_TitleBarNormalButton:
2667 pixmap = maximizePixmap;
2668 break;
2669 case SP_TitleBarCloseButton:
2670 pixmap = closePixmap;
2671 break;
2672 default:
2673 ;
2674 }
2675
2676 return pixmap;
2677}
2678
2679QSize JavaStyle::sizeFromContents(ContentsType type,
2680 const QStyleOption *option,
2681 const QSize &contentsSize,
2682 const QWidget *widget) const
2683{
2684 switch (type) {
2685 case CT_ComboBox: {
2686 return QSize(contentsSize.width() + 27, contentsSize.height());
2687 }
2688 case CT_Slider: {
2689 const QStyleOptionSlider *slider =
2690 qstyleoption_cast<const QStyleOptionSlider *>(option);
2691 if (slider->tickPosition == QSlider::TicksBelow) {
2692 return QSize(contentsSize.width(), contentsSize.height() + 15);
2693 } else {
2694 return contentsSize;
2695 }
2696 }
2697 case CT_MenuBarItem: {
2698 const QStyleOptionMenuItem *menuItem =
2699 qstyleoption_cast<const QStyleOptionMenuItem *>(option);
2700 QFontMetrics metrics(menuItem->font);
2701 QRect boundingRect = metrics.boundingRect(menuItem->text);
2702 int width = boundingRect.width() + 14;
2703 int height = boundingRect.height() + 3;
2704 if (height < 20)
2705 height = 20;
2706
2707 return QSize(width, height);
2708 }
2709 case CT_MenuItem: {
2710 const QStyleOptionMenuItem *menuItem =
2711 qstyleoption_cast<const QStyleOptionMenuItem *>(option);
2712 QSize defaultSize = QWindowsStyle::sizeFromContents(type, option,
2713 contentsSize, widget);
2714
2715 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
2716 return defaultSize;
2717
2718 int width = 30;
2719 int height = 0;
2720
2721 if (!menuItem->icon.isNull()) {
2722 width += 20;
2723 height += 20;
2724 }
2725 if (!menuItem->text.isEmpty()) {
2726 QFontMetrics metrics(menuItem->font);
2727 QString text = menuItem->text;
2728 text.remove(QLatin1Char('\t'));
2729 QRect textRect = metrics.boundingRect(text);
2730 width += textRect.width();
2731 if (height < textRect.height())
2732 height += textRect.height();
2733 }
2734 if (menuItem->checkType != QStyleOptionMenuItem::NotCheckable) {
2735 width += 10;
2736 if (height < 10)
2737 height = 10;
2738 }
2739 return QSize(width, height);
2740 }
2741 default:
2742 return QWindowsStyle::sizeFromContents(type, option, contentsSize,
2743 widget);
2744 }
2745}
Note: See TracBrowser for help on using the repository browser.