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