21 qApp->setPalette(standardPalette());
25inline QPoint JavaStyle::adjustScrollPoint(
const QPoint &point,
26 Qt::Orientation orientation,
29 int adder = add ? -1 : 1;
32 if (orientation == Qt::Horizontal) {
33 retPoint = QPoint(point.y() * adder, point.x());
35 retPoint = QPoint(point.x(), point.y() * adder);
41QPalette JavaStyle::standardPalette()
const
43 QPalette palette = QCommonStyle::standardPalette();
45 palette.setBrush(QPalette::Active, QPalette::Button,
46 QColor(184, 207, 229));
47 palette.setBrush(QPalette::Active, QPalette::WindowText,
49 palette.setBrush(QPalette::Active, QPalette::Background,
50 QColor(238, 238, 238));
51 palette.setBrush(QPalette::Active, QPalette::Window,
52 QColor(238 ,238, 238));
53 palette.setBrush(QPalette::Active, QPalette::Base, Qt::white);
54 palette.setBrush(QPalette::Active, QPalette::AlternateBase, QColor(238, 238, 238));
55 palette.setBrush(QPalette::Active, QPalette::Text, Qt::black);
56 palette.setBrush(QPalette::Active, QPalette::BrightText, Qt::white);
58 palette.setBrush(QPalette::Active, QPalette::Light, QColor(163, 184, 204));
59 palette.setBrush(QPalette::Active, QPalette::Midlight, QColor(99, 130, 191));
60 palette.setBrush(QPalette::Active, QPalette::Dark, QColor(106, 104, 100));
61 palette.setBrush(QPalette::Active, QPalette::Mid, QColor(122, 138, 153));
62 palette.setBrush(QPalette::Active, QPalette::Shadow, QColor(122, 138, 153));
64 palette.setBrush(QPalette::Active, QPalette::Highlight, QColor(184, 207, 229));
65 palette.setBrush(QPalette::Active, QPalette::HighlightedText, Qt::black);
67 palette.setBrush(QPalette::Inactive, QPalette::Highlight, QColor(184, 207, 229));
68 palette.setBrush(QPalette::Inactive, QPalette::HighlightedText, Qt::black);
70 palette.setBrush(QPalette::Disabled, QPalette::Button,
71 QColor(238, 238, 238));
72 palette.setBrush(QPalette::Disabled, QPalette::WindowText,
73 QColor(153, 153, 153));
74 palette.setBrush(QPalette::Disabled, QPalette::Background, QColor(238, 238, 238));
76 palette.setBrush(QPalette::Inactive, QPalette::Button,
77 QColor(184, 207, 229));
78 palette.setBrush(QPalette::Inactive, QPalette::Background,
79 QColor(238, 238, 238));
80 palette.setBrush(QPalette::Inactive, QPalette::Window,
81 QColor(238 ,238, 238));
82 palette.setBrush(QPalette::Inactive, QPalette::Light, QColor(163, 184, 204));
83 palette.setBrush(QPalette::Inactive, QPalette::Midlight, QColor(99, 130, 191));
84 palette.setBrush(QPalette::Inactive, QPalette::Dark,QColor(106, 104, 100));
85 palette.setBrush(QPalette::Inactive, QPalette::Mid, QColor(122, 138, 153));
86 palette.setBrush(QPalette::Inactive, QPalette::Shadow, QColor(122, 138, 153));
91inline void JavaStyle::drawScrollBarArrow(
const QRect &rect, QPainter *painter,
92 const QStyleOptionSlider *option,
98 Qt::Orientation orient = option->orientation;
102 if (orient == Qt::Vertical) {
103 offset = rect.bottomLeft();
105 offset = rect.topRight();
108 offset = rect.topLeft();
112 arrow.moveTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
113 arrow.lineTo(offset + adjustScrollPoint(QPoint(7, 5), orient, add));
114 arrow.lineTo(offset + adjustScrollPoint(QPoint(8, 5), orient, add));
115 arrow.lineTo(offset + adjustScrollPoint(QPoint(11, 8), orient, add));
116 arrow.lineTo(offset + adjustScrollPoint(QPoint(4, 8), orient, add));
119 if (option->state & State_Sunken)
120 fillColor = QColor(option->palette.color(QPalette::Button));
122 fillColor = option->palette.color(QPalette::Background);
124 painter->fillRect(rect, fillColor);
126 painter->setPen(option->palette.color(QPalette::Base));
127 int adjust = option->state & State_Sunken ? 0 : 1;
128 painter->drawRect(rect.adjusted(adjust, adjust, -1, -1));
129 painter->setPen(option->palette.color(QPalette::Mid));
130 painter->drawRect(rect.adjusted(0, 0, -1, -1));
132 painter->setPen(option->palette.color(QPalette::WindowText));
133 painter->setBrush(option->palette.color(QPalette::WindowText));
134 painter->drawPath(arrow);
139inline QPoint JavaStyle::adjustScrollHandlePoint(Qt::Orientation orig,
140 const QPoint &point)
const
144 if (orig == Qt::Vertical)
147 retPoint = QPoint(point.y(), point.x());
152void JavaStyle::drawControl(ControlElement control,
const QStyleOption *option,
153 QPainter *painter,
const QWidget *widget)
const
159 case CE_ToolBoxTabShape: {
160 const QStyleOptionToolBox *box =
161 qstyleoption_cast<
const QStyleOptionToolBox *>(option);
165 if (box->direction == Qt::RightToLeft) {
167 painter->translate(box->rect.width(), -box->rect.height());
170 int textWidth = box->fontMetrics.horizontalAdvance(box->text) + 20;
173 innerLine << (box->rect.topLeft() + QPoint(0, 1)) <<
174 (box->rect.topLeft() + QPoint(textWidth, 1)) <<
175 (box->rect.bottomLeft() + QPoint(textWidth + 15, -3)) <<
176 (box->rect.bottomRight() + QPoint(0, -3)) <<
177 box->rect.bottomRight() <<
178 box->rect.bottomLeft() <<
181 painter->setPen(box->palette.color(QPalette::Base));
182 painter->setBrush(QColor(200, 221, 242));
183 painter->drawPolygon(innerLine);
186 outerLine << (box->rect.bottomRight() + QPoint(0, -3)) <<
187 box->rect.bottomRight() <<
188 box->rect.bottomLeft() <<
189 box->rect.topLeft() <<
190 (box->rect.topLeft() + QPoint(textWidth, 0)) <<
191 (box->rect.bottomLeft() + QPoint(textWidth + 15, -4)) <<
192 (box->rect.bottomRight() + QPoint(0, -4));
194 painter->setPen(box->palette.color(QPalette::Midlight));
195 painter->setBrush(Qt::NoBrush);
196 painter->drawPolyline(outerLine);
201 case CE_DockWidgetTitle: {
202 const QStyleOptionDockWidget *docker =
203 qstyleoption_cast<
const QStyleOptionDockWidget *>(option);
205 QRect rect = docker->rect;
206 QRect titleRect = rect;
207 if (docker->verticalTitleBar) {
208 QRect r = rect.transposed();
210 titleRect = QRect(r.left() + rect.bottom()
211 - titleRect.bottom(),
212 r.top() + titleRect.left() - rect.left(),
213 titleRect.height(), titleRect.width());
215 painter->translate(r.left(), r.top() + r.width());
216 painter->rotate(-90);
217 painter->translate(-r.left(), -r.top());
222 QLinearGradient gradient(rect.topLeft(),
224 gradient.setColorAt(1.0, QColor(191, 212, 231));
225 gradient.setColorAt(0.3, Qt::white);
226 gradient.setColorAt(0.0, QColor(221, 232, 243));
228 painter->setPen(Qt::NoPen);
229 painter->setBrush(gradient);
230 painter->drawRect(rect.adjusted(0, 0, -1, -1));
232 if (!docker->title.isEmpty()) {
233 QRect textRect = docker->fontMetrics.boundingRect(docker->title);
234 textRect.moveCenter(rect.center());
236 QFont font = painter->font();
237 font.setPointSize(font.pointSize() - 1);
238 painter->setFont(font);
239 painter->setPen(docker->palette.text().color());
240 painter->drawText(textRect, docker->title,
241 QTextOption(Qt::AlignHCenter |
246 case CE_RubberBand: {
247 painter->setPen(option->palette.color(QPalette::Active,
248 QPalette::WindowText));
249 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
255 case CE_HeaderSection: {
256 const QStyleOptionHeader *header =
257 qstyleoption_cast<
const QStyleOptionHeader *>(option);
259 painter->setPen(Qt::NoPen);
260 painter->setBrush(option->palette.color(QPalette::Active,
261 QPalette::Background));
262 painter->drawRect(option->rect);
264 painter->setPen(header->palette.color(QPalette::Mid));
265 if (header->orientation == Qt::Horizontal) {
266 if (header->position == QStyleOptionHeader::Beginning ||
267 header->position == QStyleOptionHeader::OnlyOneSection) {
268 painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
269 painter->setPen(header->palette.color(QPalette::Base));
270 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
271 header->rect.topLeft() + QPoint(1, 1));
272 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
273 header->rect.topRight() + QPoint(-1, 1));
275 painter->drawLine(header->rect.bottomRight(),
276 header->rect.topRight());
277 painter->drawLine(header->rect.topLeft(),
278 header->rect.topRight());
279 painter->drawLine(header->rect.bottomLeft(),
280 header->rect.bottomRight());
281 painter->setPen(option->palette.color(QPalette::Base));
282 painter->drawLine(header->rect.bottomLeft() + QPoint(0, -1),
283 header->rect.topLeft() + QPoint(0, 1));
284 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
285 header->rect.topRight() + QPoint(-1, 1));
288 if (header->position == QStyleOptionHeader::Beginning ||
289 header->position == QStyleOptionHeader::OnlyOneSection) {
290 painter->drawRect(header->rect.adjusted(0, 0, -1, -1));
291 painter->setPen(header->palette.color(QPalette::Base));
292 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
293 header->rect.topLeft() + QPoint(1, 1));
294 painter->drawLine(header->rect.topLeft() + QPoint(1, 1),
295 header->rect.topRight() + QPoint(-1, 1));
297 painter->drawLine(header->rect.bottomLeft(),
298 header->rect.bottomRight());
299 painter->drawLine(header->rect.topLeft(),
300 header->rect.bottomLeft());
301 painter->drawLine(header->rect.topRight(),
302 header->rect.bottomRight());
303 painter->setPen(header->palette.color(QPalette::Base));
304 painter->drawLine(header->rect.topLeft(),
305 header->rect.topRight() + QPoint(-1, 0));
306 painter->drawLine(header->rect.bottomLeft() + QPoint(1, -1),
307 header->rect.topLeft() + QPoint(1, 0));
313 QRect rect = option->rect;
315 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
316 gradient.setColorAt(1.0, QColor(221, 221, 221));
317 gradient.setColorAt(0.0, QColor(241, 241, 241));
319 if (option->state & State_Horizontal) {
320 painter->setPen(QColor(204, 204, 204));
321 painter->setBrush(gradient);
323 painter->setPen(Qt::NoPen);
324 painter->setBrush(option->palette.color(QPalette::Background));
326 painter->drawRect(rect.adjusted(0, 0, -1, -1));
329 case CE_ProgressBar: {
330 const QStyleOptionProgressBar *bar =
331 qstyleoption_cast<
const QStyleOptionProgressBar *>(option);
333 QRect rect = bar->rect;
334 if (bar->orientation == Qt::Vertical) {
335 rect = QRect(rect.left(), rect.top(), rect.height(), rect.width());
337 m.translate(rect.height()-1, 0);
339 painter->setTransform(m);
342 painter->setPen(bar->palette.color(QPalette::Mid));
343 painter->drawRect(rect.adjusted(0, 0, -1, -1));
345 QRect grooveRect = subElementRect(SE_ProgressBarGroove, bar,
347 if (bar->orientation == Qt::Vertical) {
348 grooveRect = QRect(grooveRect.left(), grooveRect.top(),
349 grooveRect.height(), grooveRect.width());
352 QStyleOptionProgressBar grooveBar = *bar;
353 grooveBar.rect = grooveRect;
355 drawControl(CE_ProgressBarGroove, &grooveBar, painter, widget);
357 QRect progressRect = subElementRect(SE_ProgressBarContents, bar,
359 if (bar->orientation == Qt::Vertical) {
360 progressRect = QRect(progressRect.left(), progressRect.top(),
361 progressRect.height(), progressRect.width());
362 progressRect.adjust(0, 0, 0, -1);
364 QStyleOptionProgressBar progressOpt = *bar;
365 progressOpt.rect = progressRect;
366 drawControl(CE_ProgressBarContents, &progressOpt, painter, widget);
368 QRect labelRect = subElementRect(SE_ProgressBarLabel, bar, widget);
369 if (bar->orientation == Qt::Vertical) {
370 labelRect = QRect(labelRect.left(), labelRect.top(),
371 labelRect.height(), labelRect.width());
373 QStyleOptionProgressBar subBar = *bar;
374 subBar.rect = labelRect;
375 if (bar->textVisible)
376 drawControl(CE_ProgressBarLabel, &subBar, painter, widget);
380 case CE_ProgressBarGroove: {
381 painter->setBrush(option->palette.color(QPalette::Background));
382 painter->setPen(Qt::NoPen);
383 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
385 painter->setPen(option->palette.color(QPalette::Button));
386 painter->drawLine(option->rect.topLeft() + QPoint(0, 0),
387 option->rect.topRight() + QPoint(0, 0));
390 case CE_ProgressBarContents: {
391 const QStyleOptionProgressBar *bar =
392 qstyleoption_cast<
const QStyleOptionProgressBar *>(option);
393 int progress =
int((
double(bar->progress) /
394 double(bar->maximum - bar->minimum)) *
397 painter->setBrush(bar->palette.color(QPalette::Light));
398 painter->setPen(Qt::NoPen);
399 QRect progressRect = QRect(bar->rect.topLeft(), QPoint(progress,
400 bar->rect.bottom()));
401 painter->drawRect(progressRect);
403 painter->setPen(bar->palette.color(QPalette::Midlight));
404 painter->setBrush(Qt::NoBrush);
406 painter->drawLine(bar->rect.bottomLeft(), bar->rect.topLeft());
407 painter->drawLine(bar->rect.topLeft(), QPoint(progress,
411 case CE_ProgressBarLabel: {
413 const QStyleOptionProgressBar *bar =
414 qstyleoption_cast<
const QStyleOptionProgressBar *>(option);
416 QRect rect = bar->rect;
419 int progressIndicatorPos =
int((
double(bar->progress) /
420 double(bar->maximum - bar->minimum)) *
425 painter->setFont(font);
426 painter->setPen(bar->palette.color(QPalette::Midlight));
428 if (progressIndicatorPos >= 0 &&
429 progressIndicatorPos <= rect.width()) {
430 leftRect = QRect(bar->rect.topLeft(),
431 QPoint(progressIndicatorPos,
432 bar->rect.bottom()));
433 }
else if (progressIndicatorPos > rect.width()) {
434 painter->setPen(bar->palette.color(QPalette::Base));
436 painter->setPen(bar->palette.color(QPalette::Midlight));
439 QRect textRect = QFontMetrics(font).boundingRect(bar->text);
440 textRect.moveCenter(option->rect.center());
441 painter->drawText(textRect, bar->text,
442 QTextOption(Qt::AlignCenter));
443 if (!leftRect.isNull()) {
444 painter->setPen(bar->palette.color(QPalette::Base));
445 painter->setClipRect(leftRect, Qt::IntersectClip);
446 painter->drawText(textRect, bar->text,
447 QTextOption(Qt::AlignCenter));
453 case CE_MenuBarEmptyArea: {
454 QRect emptyArea = option->rect.adjusted(0, 0, -1, -1);
455 QLinearGradient gradient(emptyArea.topLeft(), emptyArea.bottomLeft()
457 gradient.setColorAt(0.0, option->palette.color(QPalette::Base));
458 gradient.setColorAt(1.0, QColor(223, 223, 223));
460 painter->setPen(QColor(238, 238, 238));
461 painter->setBrush(gradient);
462 painter->drawRect(emptyArea.adjusted(0, 0, 0, -1));
465 case CE_MenuBarItem: {
466 if (!(option->state & State_Sunken)) {
467 QLinearGradient gradient(option->rect.topLeft(),
468 option->rect.bottomLeft());
469 gradient.setColorAt(0.0, Qt::white);
470 gradient.setColorAt(1.0, QColor(223, 223, 223));
472 painter->setPen(Qt::NoPen);
473 painter->setBrush(gradient);
475 painter->setBrush(option->palette.color(QPalette::Light));
478 painter->drawRect(option->rect);
479 if (option->state & State_Sunken) {
480 painter->setPen(option->palette.color(QPalette::Mid));
481 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
482 painter->setPen(option->palette.color(QPalette::Base));
483 painter->setBrush(Qt::NoBrush);
484 painter->drawLine(option->rect.bottomRight() + QPoint(0, -1),
485 option->rect.topRight() + QPoint(0, -1));
487 QCommonStyle::drawControl(control, option, painter, widget);
491 const QStyleOptionMenuItem *menuItem =
492 qstyleoption_cast<
const QStyleOptionMenuItem *>(option);
494 bool selected = menuItem->state & State_Selected;
495 bool checkable = menuItem->checkType !=
496 QStyleOptionMenuItem::NotCheckable;
497 bool checked = menuItem->checked;
499 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
500 QPoint center = menuItem->rect.center();
502 painter->setPen(menuItem->palette.color(QPalette::Midlight));
503 painter->drawLine(QPoint(menuItem->rect.left() - 2, center.y()),
504 QPoint(menuItem->rect.right(), center.y()));
505 painter->setPen(menuItem->palette.color(QPalette::Base));
506 painter->drawLine(QPoint(menuItem->rect.left() - 2,
508 QPoint(menuItem->rect.right(),
515 painter->setBrush(menuItem->palette.color(QPalette::Light));
516 painter->setPen(Qt::NoPen);
517 painter->drawRect(menuItem->rect);
518 painter->setPen(menuItem->palette.color(QPalette::Midlight));
519 painter->drawLine(menuItem->rect.topLeft(),
520 menuItem->rect.topRight());
521 painter->setPen(menuItem->palette.color(QPalette::Base));
522 painter->drawLine(menuItem->rect.bottomLeft(),
523 menuItem->rect.bottomRight());
527 QRect checkRect(option->rect.left() + 5,
528 option->rect.center().y() - 5, 10, 10);
529 if (menuItem->checkType & QStyleOptionMenuItem::Exclusive) {
530 QStyleOptionButton button;
531 button.rect = checkRect;
532 button.state = menuItem->state;
533 if (button.state & State_Sunken)
534 button.state ^= State_Sunken;
536 button.state |= State_On;
537 button.palette = menuItem->palette;
538 drawPrimitive(PE_IndicatorRadioButton, &button, painter,
541 QBrush buttonBrush = gradientBrush(option->rect);
542 painter->setBrush(buttonBrush);
543 painter->setPen(option->palette.color(QPalette::Mid));
545 painter->drawRect(checkRect);
548 QImage image(
":/images/checkboxchecked.png");
549 painter->drawImage(QPoint(option->rect.left() + 5,
550 option->rect.center().y() - 8), image);
555 bool dis = !(menuItem->state & State_Enabled);
556 bool act = menuItem->state & State_Selected;
557 const QStyleOption *opt = option;
558 const QStyleOptionMenuItem *menuitem = menuItem;
559 int checkcol = qMax(menuitem->maxIconWidth, 20);
560 if (menuItem->icon.isNull())
563 QPainter *p = painter;
564 QRect vCheckRect = visualRect(opt->direction, menuitem->rect,
565 QRect(menuitem->rect.x(),
567 checkcol, menuitem->rect.height()));
568 if (!menuItem->icon.isNull()) {
569 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
571 mode = QIcon::Active;
574 pixmap = menuItem->icon.pixmap(
575 pixelMetric(PM_SmallIconSize), mode, QIcon::On);
577 pixmap = menuItem->icon.pixmap(
578 pixelMetric(PM_SmallIconSize), mode);
579 int pixw = pixmap.width();
580 int pixh = pixmap.height();
582 int adjustedIcon = checkable ? 15 : 0;
583 QRect pmr(0, 0, pixw, pixh);
584 pmr.moveCenter(vCheckRect.center());
585 painter->setPen(menuItem->palette.text().color());
586 if (checkable && checked)
587 painter->drawPixmap(QPoint(pmr.left() +
588 adjustedIcon, pmr.top() + 1), pixmap);
590 painter->drawPixmap(pmr.topLeft() +
591 QPoint(adjustedIcon, 0), pixmap);
595 painter->setPen(menuItem->palette.highlightedText().color());
597 painter->setPen(menuItem->palette.text().color());
600 menuitem->rect.getRect(&x, &y, &w, &h);
601 int tab = menuitem->tabWidth;
604 discol = menuitem->palette.text().color();
607 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
608 int xpos = menuitem->rect.x() + xm;
610 if (!menuItem->icon.isNull())
611 textRect.setRect(xpos, y + windowsItemVMargin, w - xm -
612 windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
614 textRect.setRect(menuItem->rect.left() + 9,
615 y + windowsItemVMargin,
616 w - xm - windowsRightBorder - tab,
617 h - 2 * windowsItemVMargin);
620 textRect.adjust(10, 0, 10, 0);
622 QRect vTextRect = visualRect(opt->direction, menuitem->rect,
624 QString s = menuitem->text;
626 qsizetype t = s.indexOf(u'\t');
627 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic |
628 Qt::TextDontClip | Qt::TextSingleLine;
629 if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
630 text_flags |= Qt::TextHideMnemonic;
631 text_flags |= Qt::AlignLeft;
633 QRect vShortcutRect = visualRect(opt->direction,
635 QRect(textRect.topRight(),
636 QPoint(menuitem->rect.right(), textRect.bottom())));
638 p->setPen(menuitem->palette.light().color());
639 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1),
644 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
647 QFont font = menuitem->font;
648 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
652 p->setPen(menuitem->palette.light().color());
653 p->drawText(vTextRect.adjusted(1,1,1,1), text_flags,
657 p->drawText(vTextRect, text_flags, s.left(t));
660 if (menuItem->menuItemType & QStyleOptionMenuItem::SubMenu) {
661 QPoint center = menuItem->rect.center();
662 QPoint drawStart(menuItem->rect.right() - 6, center.y() + 4);
665 arrow.moveTo(drawStart);
666 arrow.lineTo(drawStart + QPoint(0, -8));
667 arrow.lineTo(drawStart + QPoint(4, -5));
668 arrow.lineTo(drawStart + QPoint(4, -4));
669 arrow.lineTo(drawStart + QPoint(0, 0));
672 painter->setBrush(menuItem->palette.color(QPalette::Text));
673 painter->setPen(Qt::NoPen);
674 painter->drawPath(arrow);
680 case CE_MenuVMargin: {
683 case CE_MenuHMargin: {
687 drawSplitter(option, painter, option->state & State_Horizontal);
690 case CE_ScrollBarAddPage: {
691 case CE_ScrollBarSubPage:
692 const QStyleOptionSlider *scrollBar =
693 qstyleoption_cast<
const QStyleOptionSlider *>(option);
695 if (scrollBar->orientation == Qt::Horizontal) {
696 myRect = QRect(option->rect.topLeft(),
697 option->rect.bottomRight()).adjusted(0, 0, 1, -1);
699 myRect = option->rect;
702 painter->setPen(Qt::NoPen);
703 painter->setBrush(option->palette.color(QPalette::Background));
704 painter->drawRect(myRect);
706 painter->setBrush(Qt::NoBrush);
707 painter->setPen(scrollBar->palette.color(QPalette::Mid));
708 painter->drawRect(myRect.adjusted(0, 0, -1, 0));
709 painter->setPen(scrollBar->palette.color(QPalette::Button));
710 painter->drawLine(myRect.bottomLeft() + QPoint(1, 0),
711 myRect.topLeft() + QPoint(1, 1));
712 painter->drawLine(myRect.topLeft() + QPoint(1, 1),
713 myRect.topRight() + QPoint(-1, 1));
716 case CE_ScrollBarSubLine: {
717 const QStyleOptionSlider *scrollBar =
718 qstyleoption_cast<
const QStyleOptionSlider *>(option);
719 int scrollBarExtent = pixelMetric(PM_ScrollBarExtent);
720 QRect scrollBarSubLine = option->rect;
725 if (scrollBar->orientation == Qt::Horizontal) {
726 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
727 16, scrollBarExtent);
728 button2.setRect(scrollBarSubLine.right() - 15,
729 scrollBarSubLine.top(), 16, scrollBarExtent);
731 button1.setRect(scrollBarSubLine.left(), scrollBarSubLine.top(),
732 scrollBarExtent, 16);
733 button2.setRect(scrollBarSubLine.left(),
734 scrollBarSubLine.bottom() - 15, scrollBarExtent, 16);
737 painter->fillRect(button2, Qt::blue);
739 drawScrollBarArrow(button1, painter, scrollBar);
740 drawScrollBarArrow(button2, painter, scrollBar);
743 case CE_ScrollBarAddLine: {
744 const QStyleOptionSlider *scrollBar =
745 qstyleoption_cast<
const QStyleOptionSlider *>(option);
746 QRect button(option->rect.left(), option->rect.top(), 16, 16);
747 drawScrollBarArrow(button, painter, scrollBar,
true);
750 case CE_ScrollBarSlider: {
751 const QStyleOptionSlider *scrollBar =
752 qstyleoption_cast<
const QStyleOptionSlider *>(option);
754 painter->setPen(scrollBar->palette.color(QPalette::Midlight));
755 painter->drawRect(scrollBar->rect.adjusted(-1, 0, -3, -1));
758 if (scrollBar->orientation == Qt::Horizontal) {
759 g1 = option->rect.topLeft();
760 g2 = option->rect.bottomLeft();
762 g1 = option->rect.topLeft();
763 g2 = option->rect.topRight();
766 if (scrollBar->state & State_Enabled) {
767 QLinearGradient gradient(g1, g2);
768 gradient.setColorAt(1.0, QColor(188, 210, 230));
769 gradient.setColorAt(0.3, Qt::white);
770 gradient.setColorAt(0.0, QColor(223, 233, 243));
771 painter->setBrush(gradient);
773 painter->setPen(scrollBar->palette.buttonText().color());
774 painter->setBrush(scrollBar->palette.button());
776 painter->drawRect(scrollBar->rect.adjusted(0, 0, -1, -1));
778 int sliderLength = option->rect.height();
779 int drawPos = scrollBar->orientation == Qt::Vertical ?
780 (sliderLength / 2) + 1 : 1 - ((option->rect.width() / 2));
783 if (scrollBar->orientation == Qt::Vertical)
784 origin = option->rect.bottomLeft();
786 origin = option->rect.topLeft();
788 painter->setPen(scrollBar->palette.color(QPalette::Base));
789 painter->drawLine(origin + adjustScrollHandlePoint(
790 scrollBar->orientation,
791 QPoint(4, -drawPos)),
792 origin + adjustScrollHandlePoint(
793 scrollBar->orientation,
794 QPoint(13, -drawPos)));
795 painter->drawLine(origin + adjustScrollHandlePoint(
796 scrollBar->orientation,
797 QPoint(4, 2 - drawPos)),
798 origin + adjustScrollHandlePoint(
799 scrollBar->orientation,
800 QPoint(13, 2 - drawPos)));
801 painter->drawLine(origin + adjustScrollHandlePoint(
802 scrollBar->orientation,
803 QPoint(4, 4 - drawPos)),
804 origin + adjustScrollHandlePoint(
805 scrollBar->orientation,
806 QPoint(13, 4 - drawPos)));
808 painter->setPen(option->palette.color(QPalette::Midlight));
809 painter->drawLine(origin + adjustScrollHandlePoint(
810 scrollBar->orientation,
811 QPoint(3, -(drawPos + 1))),
812 origin + adjustScrollHandlePoint(
813 scrollBar->orientation,
814 QPoint(12, -(drawPos + 1))));
815 painter->drawLine(origin + adjustScrollHandlePoint(
816 scrollBar->orientation,
817 QPoint(3, 1 - drawPos)),
818 origin + adjustScrollHandlePoint(
819 scrollBar->orientation,
820 QPoint(12, 1 - drawPos)));
821 painter->drawLine(origin + adjustScrollHandlePoint(
822 scrollBar->orientation,
823 QPoint(3, 3 - drawPos)),
824 origin + adjustScrollHandlePoint(
825 scrollBar->orientation,
826 QPoint(12, 3 - drawPos)));
830 case CE_TabBarTabLabel: {
831 QStyleOptionTab copy =
832 *qstyleoption_cast<
const QStyleOptionTab *>(option);
833 if (copy.state & State_HasFocus)
834 copy.state ^= State_HasFocus;
835 painter->setBrush(Qt::NoBrush);
836 QCommonStyle::drawControl(CE_TabBarTabLabel, ©, painter,
840 case CE_TabBarTabShape: {
841 const QStyleOptionTab *tab =
842 qstyleoption_cast<
const QStyleOptionTab *>(option);
843 QRect myRect = option->rect;
844 QPoint bottomLeft, bottomRight, topLeft, topRight;
846 if ((tab->position == QStyleOptionTab::Beginning) ||
847 (tab->position == QStyleOptionTab::OnlyOneTab)) {
848 if (tab->shape == QTabBar::RoundedSouth ||
849 tab->shape == QTabBar::RoundedNorth) {
850 myRect = myRect.adjusted(2, 0, 0, 0);
852 myRect = myRect.adjusted(0, 2, 0, 0);
856 switch (tab->shape) {
857 case QTabBar::RoundedNorth:
858 topLeft = myRect.topLeft();
859 topRight = myRect.topRight();
860 bottomLeft = myRect.bottomLeft();
861 bottomRight = myRect.bottomRight();
863 case QTabBar::RoundedSouth:
864 topLeft = myRect.bottomLeft();
865 topRight = myRect.bottomRight();
866 bottomLeft = myRect.topLeft();
867 bottomRight = myRect.topRight();
869 case QTabBar::RoundedWest:
870 topLeft = myRect.topLeft();
871 topRight = myRect.bottomLeft();
872 bottomLeft = myRect.topRight();
873 bottomRight = myRect.bottomRight();
875 case QTabBar::RoundedEast:
876 topLeft = myRect.topRight();
877 topRight = myRect.bottomRight();
878 bottomLeft = myRect.topLeft();
879 bottomRight = myRect.bottomLeft();
885 QPainterPath outerPath;
886 outerPath.moveTo(bottomLeft + adjustTabPoint(QPoint(0, -2),
888 outerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(0, -14),
890 outerPath.lineTo(topLeft + adjustTabPoint(QPoint(6 , 0),
892 outerPath.lineTo(topRight + adjustTabPoint(QPoint(0, 0),
894 outerPath.lineTo(bottomRight + adjustTabPoint(QPoint(0, -2),
897 if (tab->state & State_Selected ||
898 tab->position == QStyleOptionTab::OnlyOneTab) {
899 QPainterPath innerPath;
900 innerPath.moveTo(topLeft + adjustTabPoint(QPoint(6, 2),
902 innerPath.lineTo(topRight + adjustTabPoint(QPoint(-1, 2),
904 innerPath.lineTo(bottomRight + adjustTabPoint(QPoint(-1 , -2),
906 innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -2),
908 innerPath.lineTo(bottomLeft + adjustTabPoint(QPoint(2 , -14),
910 innerPath.lineTo(topLeft + adjustTabPoint(QPoint(6, 2),
913 QPainterPath whitePath;
914 whitePath.moveTo(bottomLeft + adjustTabPoint(QPoint(1, -2),
916 whitePath.lineTo(bottomLeft + adjustTabPoint(QPoint(1, -14),
918 whitePath.lineTo(topLeft + adjustTabPoint(QPoint(6, 1),
920 whitePath.lineTo(topRight + adjustTabPoint(QPoint(-1, 1),
923 painter->setPen(tab->palette.color(QPalette::Midlight));
924 painter->setBrush(QColor(200, 221, 242));
925 painter->drawPath(outerPath);
926 painter->setPen(QColor(200, 221, 242));
927 painter->drawRect(QRect(bottomLeft + adjustTabPoint(
928 QPoint(2, -3), tab->shape),
929 bottomRight + adjustTabPoint(
930 QPoint(-2, 0), tab->shape)));
931 painter->setPen(tab->palette.color(QPalette::Base));
932 painter->setBrush(Qt::NoBrush);
933 painter->drawPath(whitePath);
935 if (option->state & State_HasFocus) {
936 painter->setPen(option->palette.color(QPalette::Mid));
937 painter->drawPath(innerPath);
940 painter->setPen(tab->palette.color(QPalette::Mid));
941 painter->drawPath(outerPath);
945 case CE_PushButtonLabel:
948 if (
const QStyleOptionButton *button =
949 qstyleoption_cast<
const QStyleOptionButton *>(option)) {
950 QRect ir = button->rect;
951 uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
952 if (!styleHint(SH_UnderlineShortcut, button, widget))
953 tf |= Qt::TextHideMnemonic;
955 if (!button->icon.isNull()) {
958 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal
960 if (mode == QIcon::Normal && button->state & State_HasFocus)
961 mode = QIcon::Active;
962 QIcon::State state = QIcon::Off;
963 if (button->state & State_On)
966 QPixmap pixmap = button->icon.pixmap(button->iconSize, mode,
968 int w = pixmap.width();
969 int h = pixmap.height();
971 if (!button->text.isEmpty())
972 w += button->fontMetrics.horizontalAdvance(button->text) + 2;
974 point = QPoint(ir.x() + ir.width() / 2 - w / 2,
975 ir.y() + ir.height() / 2 - h / 2);
977 if (button->direction == Qt::RightToLeft)
978 point.rx() += pixmap.width();
980 painter->drawPixmap(visualPos(button->direction, button->rect,
983 if (button->direction == Qt::RightToLeft)
984 ir.translate(-point.x() - 2, 0);
986 ir.translate(point.x() + pixmap.width(), 0);
988 if (!button->text.isEmpty())
992 tf |= Qt::AlignHCenter;
995 if (button->fontMetrics.height() > 14)
998 drawItemText(painter, ir, tf, button->palette, (button->state &
1000 button->text, QPalette::ButtonText);
1007 QCommonStyle::drawControl(control, option, painter, widget);
1012inline QPoint JavaStyle::adjustTabPoint(
const QPoint &point,
1013 QTabBar::Shape shape)
const
1018 case QTabBar::RoundedWest:
1019 rPoint = QPoint(point.y(), point.x());
1021 case QTabBar::RoundedSouth:
1022 rPoint = QPoint(point.x(), point.y() * -1);
1024 case QTabBar::RoundedEast:
1025 rPoint = QPoint(point.y() * -1, point.x());
1033QRect JavaStyle::subControlRect(ComplexControl control,
1034 const QStyleOptionComplex *option,
1035 SubControl subControl,
1036 const QWidget *widget)
const
1038 QRect rect = QCommonStyle::subControlRect(control, option, subControl,
1043 const QStyleOptionTitleBar *bar =
1044 qstyleoption_cast<
const QStyleOptionTitleBar *>(option);
1046 switch (subControl) {
1047 case SC_TitleBarMinButton: {
1048 rect = QRect(bar->rect.topRight() + QPoint(-68, 2),
1052 case SC_TitleBarMaxButton: {
1053 rect = QRect(bar->rect.topRight() + QPoint(-43, 3),
1057 case SC_TitleBarCloseButton: {
1058 rect = QRect(bar->rect.topRight() + QPoint(-18, 3),
1062 case SC_TitleBarLabel: {
1063 QRect labelRect = bar->fontMetrics.boundingRect(bar->text);
1065 rect.translate(bar->rect.left() + 30, 0);
1066 rect.moveTop(bar->rect.top());
1067 rect.adjust(0, 2, 2, 2);
1070 case SC_TitleBarSysMenu: {
1071 rect = QRect(bar->rect.topLeft() + QPoint(6, 3),
1081 const QStyleOptionGroupBox *box =
1082 qstyleoption_cast<
const QStyleOptionGroupBox *>(option);
1083 bool hasCheckbox = box->subControls & SC_GroupBoxCheckBox;
1084 int checkAdjust = 13;
1086 QRect textRect = box->fontMetrics.boundingRect(box->text);
1088 switch (subControl) {
1089 case SC_GroupBoxFrame: {
1093 case SC_GroupBoxCheckBox: {
1095 rect = QRect(box->rect.topLeft() + QPoint(7, 4 +
1096 (textRect.height() / 2 - checkAdjust / 2)),
1097 QSize(checkAdjust, checkAdjust));
1104 case SC_GroupBoxLabel: {
1105 rect = QRect(box->rect.topLeft() + QPoint(7 + (hasCheckbox ?
1106 checkAdjust + 2 : 0), 4), textRect.size());
1109 case SC_GroupBoxContents: {
1110 rect = box->rect.adjusted(10, 10 + textRect.height(), -10,
1120 const QStyleOptionSpinBox *spinBox =
1121 qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
1122 int spinnerWidth = 16;
1123 QRect myRect = spinBox->rect;
1124 QPoint center = myRect.center();
1125 int frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spinBox, widget);
1127 switch (subControl) {
1128 case SC_SpinBoxUp: {
1129 rect = QRect(myRect.topRight() + QPoint(-16, 0),
1130 QSize(16, center.y() - myRect.topRight().y()));
1133 case SC_SpinBoxDown: {
1134 rect = QRect(QPoint(myRect.bottomRight().x() - 16,
1136 QSize(16, myRect.bottomRight().y() -
1140 case SC_SpinBoxFrame: {
1141 rect = QRect(myRect.topLeft(), myRect.bottomRight() +
1145 case SC_SpinBoxEditField: {
1146 rect = QRect(myRect.topLeft() + QPoint(2, 2),
1147 myRect.bottomRight() + QPoint(-15 - frameWidth, -2));
1155 case CC_ToolButton: {
1156 const QStyleOptionToolButton *button =
1157 qstyleoption_cast<
const QStyleOptionToolButton *>(option);
1159 switch (subControl) {
1160 case SC_ToolButton: {
1161 rect = option->rect.adjusted(1, 1, -1, -1);
1164 case SC_ToolButtonMenu: {
1165 rect = QRect(option->rect.bottomRight() +
1166 QPoint(-11, -11), QSize(10, 10));
1173 const QStyleOptionComboBox *combo =
1174 qstyleoption_cast<
const QStyleOptionComboBox *>(option);
1176 bool reverse = combo->direction == Qt::RightToLeft;
1178 switch (subControl) {
1179 case SC_ComboBoxFrame:
1182 case SC_ComboBoxArrow:
1184 rect = QRect(combo->rect.topLeft(),
1185 combo->rect.bottomLeft() + QPoint(17, 0));
1187 rect = QRect(combo->rect.topRight() + QPoint(-17, 0),
1188 combo->rect.bottomRight());
1191 case SC_ComboBoxEditField:
1193 rect = QRect(combo->rect.topLeft() + QPoint(19, 2),
1194 combo->rect.bottomRight() + QPoint(-2, 2));
1196 rect = QRect(combo->rect.topLeft() + QPoint(2, 2),
1197 combo->rect.bottomRight() + QPoint(-19, -2));
1200 case SC_ComboBoxListBoxPopup:
1206 case CC_ScrollBar: {
1207 const QStyleOptionSlider *scrollBar =
1208 qstyleoption_cast<
const QStyleOptionSlider *>(option);
1209 int scrollBarExtent = pixelMetric(PM_ScrollBarExtent, scrollBar,
1211 int sliderMaxLength = ((scrollBar->orientation == Qt::Horizontal) ?
1212 scrollBar->rect.width() :
1213 scrollBar->rect.height()) - (16 * 3);
1214 int sliderMinLength = pixelMetric(PM_ScrollBarSliderMin, scrollBar,
1218 if (scrollBar->maximum != scrollBar->minimum) {
1219 uint valueRange = scrollBar->maximum - scrollBar->minimum;
1220 sliderLength = (scrollBar->pageStep * sliderMaxLength) /
1221 (valueRange + scrollBar->pageStep);
1223 if (sliderLength < sliderMinLength || valueRange > INT_MAX / 2)
1224 sliderLength = sliderMinLength;
1225 if (sliderLength > sliderMaxLength)
1226 sliderLength = sliderMaxLength;
1228 sliderLength = sliderMaxLength;
1230 int sliderStart = 16 + sliderPositionFromValue(scrollBar->minimum,
1232 scrollBar->sliderPosition,
1233 sliderMaxLength - sliderLength,
1234 scrollBar->upsideDown);
1235 QRect scrollBarRect = scrollBar->rect;
1237 switch (subControl) {
1238 case SC_ScrollBarSubLine:
1239 if (scrollBar->orientation == Qt::Horizontal) {
1240 rect.setRect(scrollBarRect.left(), scrollBarRect.top(),
1241 scrollBarRect.width() - 16, scrollBarExtent);
1243 rect.setRect(scrollBarRect.left(), scrollBarRect.top(),
1244 scrollBarExtent, scrollBarRect.height() - 16);
1247 case SC_ScrollBarAddLine:
1248 if (scrollBar->orientation == Qt::Horizontal) {
1249 rect.setRect(scrollBarRect.right() - 15,
1250 scrollBarRect.top(), 16, scrollBarExtent);
1252 rect.setRect(scrollBarRect.left(), scrollBarRect.bottom()
1253 - 15, scrollBarExtent, 16);
1256 case SC_ScrollBarSubPage:
1257 if (scrollBar->orientation == Qt::Horizontal) {
1258 rect.setRect(scrollBarRect.left() + 16, scrollBarRect.top(),
1259 sliderStart - (scrollBarRect.left() + 16),
1262 rect.setRect(scrollBarRect.left(), scrollBarRect.top() + 16,
1264 sliderStart - (scrollBarRect.left() + 16));
1267 case SC_ScrollBarAddPage:
1268 if (scrollBar->orientation == Qt::Horizontal)
1269 rect.setRect(sliderStart + sliderLength, 0,
1270 sliderMaxLength - sliderStart -
1271 sliderLength + 16, scrollBarExtent);
1273 rect.setRect(0, sliderStart + sliderLength,
1274 scrollBarExtent, sliderMaxLength -
1275 sliderStart - sliderLength + 16);
1277 case SC_ScrollBarGroove:
1278 if (scrollBar->orientation == Qt::Horizontal) {
1279 rect = scrollBarRect.adjusted(16, 0, -32, 0);
1281 rect = scrollBarRect.adjusted(0, 16, 0, -32);
1284 case SC_ScrollBarSlider:
1285 if (scrollBar->orientation == Qt::Horizontal) {
1286 rect.setRect(sliderStart, 0, sliderLength,
1289 rect.setRect(0, sliderStart, scrollBarExtent,
1294 return QCommonStyle::subControlRect(control, option,
1295 subControl, widget);
1300 const QStyleOptionSlider *slider =
1301 qstyleoption_cast<
const QStyleOptionSlider *>(option);
1302 rect = slider->rect;
1303 int tickSize = pixelMetric(PM_SliderTickmarkOffset, option, widget);
1304 int handleSize = pixelMetric(PM_SliderControlThickness, option,
1307 int dist = slider->orientation == Qt::Vertical ? slider->rect.height() :
1308 slider->rect.width();
1309 int pos = QStyle::sliderPositionFromValue(slider->minimum,
1310 slider->maximum, slider->sliderValue, dist - handleSize);
1312 switch (subControl) {
1313 case SC_SliderGroove: {
1314 QPoint center = rect.center();
1316 if (slider->orientation == Qt::Horizontal) {
1317 rect.setHeight(handleSize);
1318 if (slider->tickPosition == QSlider::TicksBelow) {
1319 center.ry() -= tickSize;
1322 rect.adjust(0, 0, 0, 0);
1323 rect.setWidth(handleSize);
1324 if (slider->tickPosition == QSlider::TicksBelow) {
1325 center.rx() -= tickSize;
1328 rect.moveCenter(center);
1331 case SC_SliderHandle: {
1332 QPoint center = rect.center();
1334 if (slider->orientation == Qt::Horizontal) {
1335 rect.setHeight(handleSize);
1336 if (slider->tickPosition == QSlider::TicksBelow) {
1337 center.ry() -= tickSize;
1340 rect.moveCenter(center);
1342 if (slider->upsideDown)
1343 rect.setLeft(slider->rect.right() -
1344 pos - (handleSize - 1));
1348 rect.setWidth(handleSize - 1);
1350 rect.setWidth(handleSize);
1351 if (slider->tickPosition == QSlider::TicksBelow) {
1352 center.rx() -= tickSize;
1355 rect.moveCenter(center);
1357 if (slider->upsideDown)
1358 rect.setTop(slider->rect.bottom() -
1359 ((pos + handleSize) - 2));
1361 rect.setTop(slider->rect.top() + pos);
1363 rect.setHeight(handleSize);
1367 case SC_SliderTickmarks: {
1368 QPoint center = slider->rect.center();
1370 if (slider->tickPosition & QSlider::TicksBelow) {
1371 if (slider->orientation == Qt::Horizontal) {
1372 rect.setHeight(tickSize);
1373 center.ry() += tickSize / 2;
1374 rect.adjust(6, 0, -10, 0);
1376 rect.setWidth(tickSize);
1377 center.rx() += tickSize / 2;
1378 rect.adjust(0, 6, 0, -10);
1383 rect.moveCenter(center);
1392 return QCommonStyle::subControlRect(control, option, subControl,
1425void JavaStyle::drawComplexControl(ComplexControl control,
1426 const QStyleOptionComplex *option,
1428 const QWidget *widget)
const
1434 const QStyleOptionTitleBar *bar =
1435 qstyleoption_cast<
const QStyleOptionTitleBar *>(option);
1437 bool sunken = bar->state & State_Sunken;
1439 QLinearGradient gradient(bar->rect.bottomLeft(),
1440 bar->rect.topLeft());
1441 gradient.setColorAt(0.0, QColor(191, 212, 231));
1442 gradient.setColorAt(0.7, Qt::white);
1443 gradient.setColorAt(1.0, QColor(221, 232, 243));
1445 painter->setPen(Qt::NoPen);
1446 if (bar->titleBarState & State_Active) {
1447 painter->setBrush(gradient);
1450 painter->setBrush(bar->palette.color(QPalette::Active,
1451 QPalette::Background));
1453 painter->drawRect(bar->rect.adjusted(0, 0, -1, -1));
1455 painter->setBrush(QColor(233, 233, 233));
1456 painter->drawRect(QRect(bar->rect.bottomLeft() + QPoint(0, 1),
1457 bar->rect.bottomRight() + QPoint(0, 2)));
1459 QRect minButtonRect = subControlRect(control, bar,
1460 SC_TitleBarMinButton);
1461 QRect maxButtonRect = subControlRect(control, bar,
1462 SC_TitleBarMaxButton);
1463 QRect closeButtonRect = subControlRect(control, bar,
1464 SC_TitleBarCloseButton);
1465 QRect systemButtonRect = subControlRect(control, bar,
1466 SC_TitleBarSysMenu);
1467 QRect labelRect = subControlRect(control, bar, SC_TitleBarLabel);
1468 QRect gripRect = QRect(QPoint(labelRect.right() + 5, bar->rect.top() + 5),
1469 QPoint(minButtonRect.left() - 5,
1470 bar->rect.bottom() - 4));
1472 QColor textColor = option->palette.color(QPalette::Text);
1473 painter->setPen(textColor);
1474 painter->setBrush(Qt::NoBrush);
1476 drawItemText(painter, labelRect, Qt::TextShowMnemonic |
1477 Qt::AlignHCenter | Qt::AlignCenter,
1478 bar->palette, bar->state & State_Enabled, bar->text,
1479 textColor.isValid() ? QPalette::NoRole :
1480 QPalette::WindowText);
1482 for (
int i = 0; i < gripRect.width(); ++i) {
1483 painter->setPen(i % 2 ? bar->palette.color(QPalette::Midlight)
1486 for (
int j = 0; j < 4; ++j) {
1487 painter->drawPoint(i + gripRect.left(),
1488 gripRect.top() - 2 + i % 4 + 4 * j);
1492 QPixmap maximizePixmap(
":/images/internalmaximize.png");
1493 QPixmap minimizePixmap(
":/images/internalminimize.png");
1494 QPixmap closePixmap(
":/images/internalclose.png");
1495 QPixmap internalPixmap(
":/images/internalsystem.png");
1496 QPixmap internalCloseDownPixmap(
":/images/internalclosedown.png");
1497 QPixmap minimizeDownPixmap(
":/images/internalminimizedown.png");
1498 QPixmap maximizeDownPixmap(
":/images/internalmaximizedown.png");
1500 if (bar->activeSubControls & SC_TitleBarCloseButton &&
1501 bar->state & State_Sunken)
1502 painter->drawPixmap(closeButtonRect.topLeft(),
1503 internalCloseDownPixmap);
1505 painter->drawPixmap(closeButtonRect.topLeft(), closePixmap);
1507 if (bar->activeSubControls & SC_TitleBarMinButton &&
1508 bar->state & State_Sunken)
1509 painter->drawPixmap(minButtonRect.topLeft(),
1510 minimizeDownPixmap);
1512 painter->drawPixmap(minButtonRect.topLeft(), minimizePixmap);
1514 if (bar->activeSubControls & SC_TitleBarMaxButton &&
1515 bar->state & State_Sunken)
1516 painter->drawPixmap(maxButtonRect.topLeft(),
1517 maximizeDownPixmap);
1519 painter->drawPixmap(maxButtonRect.topLeft(), maximizePixmap);
1521 painter->drawPixmap(systemButtonRect.topLeft(), internalPixmap);
1526 const QStyleOptionGroupBox *box =
1527 qstyleoption_cast<
const QStyleOptionGroupBox *>(option);
1529 QRect frameRect = subControlRect(control, box, SC_GroupBoxFrame);
1530 QRect labelRect = subControlRect(control, box, SC_GroupBoxLabel);
1531 QRect contentsRect = subControlRect(control, box,
1532 SC_GroupBoxContents);
1533 QRect checkerRect = subControlRect(control, box,
1534 SC_GroupBoxCheckBox);
1536 int y = labelRect.center().y();
1538 painter->setPen(box->palette.color(QPalette::Button));
1539 painter->drawRect(frameRect.adjusted(2, y - frameRect.top(), -2,
1542 painter->setPen(box->palette.color(QPalette::Background));
1544 if (box->subControls & SC_GroupBoxCheckBox) {
1545 painter->drawLine(checkerRect.left() - 1, y,
1546 checkerRect.right() + 2, y);
1547 QStyleOptionButton checker;
1548 checker.QStyleOption::operator=(*box);
1549 checker.rect = checkerRect;
1550 drawPrimitive(PE_IndicatorCheckBox, &checker, painter, widget);
1553 if (box->subControls & SC_GroupBoxLabel && !box->text.isEmpty()) {
1554 painter->drawLine(labelRect.left() - 1, y,
1555 labelRect.right() +1, y);
1557 QColor textColor = box->textColor;
1558 if (textColor.isValid())
1559 painter->setPen(textColor);
1561 drawItemText(painter, labelRect, Qt::TextShowMnemonic |
1562 Qt::AlignHCenter |
int(box->textAlignment),
1563 box->palette, box->state & State_Enabled,
1564 box->text, textColor.isValid() ? QPalette::NoRole :
1565 QPalette::WindowText);
1570 const QStyleOptionSpinBox *spinner =
1571 qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
1573 QRect frameRect = subControlRect(control, spinner, SC_SpinBoxFrame);
1574 QRect upRect = subControlRect(control, spinner, SC_SpinBoxUp);
1575 QRect downRect = subControlRect(control, spinner, SC_SpinBoxDown);
1577 painter->setPen(Qt::white);
1578 painter->drawRect(frameRect.adjusted(1, 1, -1, -1));
1579 painter->drawPoint(frameRect.bottomLeft());
1581 painter->setPen(spinner->palette.color(QPalette::Mid));
1582 painter->drawRect(frameRect.adjusted(0, 0, -1, -2));
1584 bool isEnabled = (spinner->state & State_Enabled);
1585 bool hover = isEnabled && (spinner->state & State_MouseOver);
1586 bool sunken = (spinner->state & State_Sunken);
1587 bool upIsActive = (spinner->activeSubControls == SC_SpinBoxUp);
1588 bool downIsActive = (spinner->activeSubControls == SC_SpinBoxDown);
1589 bool stepUpEnabled = spinner->stepEnabled &
1590 QAbstractSpinBox::StepUpEnabled;
1591 bool stepDownEnabled = spinner->stepEnabled &
1592 QAbstractSpinBox::StepDownEnabled;
1594 painter->setBrush(spinner->palette.color(QPalette::Background));
1596 painter->drawRect(upRect);
1597 if (upIsActive && stepUpEnabled) {
1599 drawSunkenButtonShadow(painter, upRect,
1600 spinner->palette.color(QPalette::Mid));
1602 drawButtonHoverFrame(painter, upRect,
1603 spinner->palette.color(QPalette::Mid),
1604 spinner->palette.color(QPalette::Button));
1608 QStyleOptionSpinBox upSpin = *spinner;
1609 upSpin.rect = upRect;
1610 drawPrimitive(PE_IndicatorSpinUp, &upSpin, painter, widget);
1612 painter->drawRect(downRect);
1613 if (downIsActive && stepDownEnabled) {
1615 drawSunkenButtonShadow(painter, downRect,
1616 spinner->palette.color(QPalette::Mid));
1618 drawButtonHoverFrame(painter, downRect,
1619 spinner->palette.color(QPalette::Mid),
1620 spinner->palette.color(QPalette::Button));
1624 QStyleOptionSpinBox downSpin = *spinner;
1625 downSpin.rect = downRect;
1626 drawPrimitive(PE_IndicatorSpinDown, &downSpin, painter, widget);
1630 case CC_ToolButton: {
1631 const QStyleOptionToolButton *button =
1632 qstyleoption_cast<
const QStyleOptionToolButton *>(option);
1634 painter->setPen(Qt::white);
1635 painter->drawRect(button->rect.adjusted(1, 1, -1, -1));
1637 QStyleOptionToolButton panelOption = *button;
1639 if (!(button->state & State_MouseOver) &&
1640 !(button->state & State_On)) {
1641 painter->setPen(QColor(153, 153, 153));
1642 painter->drawRect(button->rect.adjusted(0, 0, -2, -2));
1644 panelRect = subControlRect(control, option, SC_ToolButton);
1645 panelOption.rect = panelRect;
1647 panelOption.rect.adjust(0, 0, -1, -1);
1650 QRect menuRect = subControlRect(control, option, SC_ToolButtonMenu);
1652 drawPrimitive(PE_PanelButtonTool, &panelOption, painter, widget);
1654 QStyleOptionToolButton menuOption = *button;
1655 menuOption.rect = menuRect;
1657 QStyleOptionToolButton label = *button;
1660 drawControl(CE_ToolButtonLabel, &label, painter, widget);
1661 if (button->subControls & SC_ToolButtonMenu) {
1662 painter->setPen(button->palette.color(QPalette::WindowText));
1663 drawPrimitive(PE_IndicatorArrowDown, &menuOption, painter, widget);
1666 if (button->state & State_HasFocus) {
1667 QStyleOptionToolButton focusOption = *button;
1668 focusOption.rect = label.rect.adjusted(-1, -1, 1, 1);
1670 drawPrimitive(PE_FrameFocusRect, &focusOption, painter, widget);
1676 const QStyleOptionComboBox *combo =
1677 qstyleoption_cast<
const QStyleOptionComboBox *>(option);
1679 QRect frameRect = subControlRect(control, option, SC_ComboBoxFrame,
1681 painter->setPen(combo->palette.color(QPalette::Mid));
1683 if (option->state & State_HasFocus)
1684 painter->setBrush(option->palette.color(QPalette::Light));
1686 painter->setBrush(combo->palette.color(QPalette::Background));
1688 painter->drawRect(frameRect.adjusted(0, 0, -1, -1));
1690 QRect arrowRect = subControlRect(control, option, SC_ComboBoxArrow,
1692 painter->setPen(combo->palette.color(QPalette::Button));
1693 painter->setBrush(Qt::NoBrush);
1695 if (combo->direction == Qt::LeftToRight) {
1696 painter->drawRect(QRect(frameRect.topLeft() + QPoint(1, 1),
1697 arrowRect.bottomLeft() + QPoint(-2, -2)));
1699 painter->drawRect(QRect(arrowRect.topLeft() + QPoint(1, 1),
1700 frameRect.bottomRight() + QPoint(-2, -2)));
1703 QStyleOptionButton button;
1704 button.rect = arrowRect;
1705 button.state = combo->state;
1706 button.palette = combo->palette;
1708 if (button.state & State_On)
1709 button.state ^= State_On;
1712 drawButtonBackground(&button, painter,
false);
1715 QPoint center = arrowRect.center();
1716 QPoint offset = QPoint(arrowRect.bottomLeft().x() + 1,
1719 arrow.moveTo(offset + QPoint(4, -8));
1720 arrow.lineTo(offset + QPoint(7, -5));
1721 arrow.lineTo(offset + QPoint(8, -5));
1722 arrow.lineTo(offset + QPoint(11, -8));
1723 arrow.lineTo(offset + QPoint(4, -8));
1725 painter->setBrush(combo->palette.color(QPalette::WindowText));
1726 painter->setPen(combo->palette.color(QPalette::WindowText));
1728 painter->drawPath(arrow);
1730 QRect fieldRect = subControlRect(control, option,
1731 SC_ComboBoxEditField, widget);
1736 const QStyleOptionSlider *slider =
1737 qstyleoption_cast<
const QStyleOptionSlider *>(option);
1739 bool horizontal = slider->orientation == Qt::Horizontal;
1741 QRect groove = subControlRect(control, option, SC_SliderGroove,
1743 QRect ticks = subControlRect(control, option, SC_SliderTickmarks,
1745 QRect handle = subControlRect(control, option, SC_SliderHandle,
1748 QRect afterHandle = QRect(handle.topLeft() + xySwitch(QPoint(4, 6), horizontal),
1749 groove.bottomRight() + xySwitch(QPoint(-4, -6), horizontal));
1750 QRect beforeHandle = QRect(groove.topLeft() + xySwitch(QPoint(4, 6), horizontal),
1751 handle.bottomRight() + xySwitch(QPoint(-4, -6), horizontal));
1753 if (slider->upsideDown || !horizontal) {
1755 remember = afterHandle;
1756 afterHandle = beforeHandle;
1757 beforeHandle = remember;
1760 painter->setPen(slider->palette.color(QPalette::Mid));
1761 painter->setBrush(option->palette.color(QPalette::Background));
1762 painter->drawRect(afterHandle);
1763 painter->setPen(slider->palette.color(QPalette::Light));
1764 painter->drawLine(afterHandle.topLeft() + xySwitch(QPoint(0, 1), horizontal),
1765 afterHandle.topRight() + xySwitch(QPoint(0, 1), horizontal));
1766 painter->setPen(option->palette.color(QPalette::Midlight));
1769 painter->setBrush(gradientBrush(QRect(QPoint(groove.x(),
1771 QSize(groove.width(),
1772 handle.height() + 1))));
1774 QRect rect = QRect(QPoint(groove.x(),
1776 QSize(groove.height(),
1777 handle.width() + 1));
1778 QLinearGradient gradient(groove.bottomLeft(),
1779 groove.bottomRight());
1780 gradient.setColorAt(1.0, QColor(188, 210, 230));
1781 gradient.setColorAt(0.3, Qt::white);
1782 gradient.setColorAt(0.0, QColor(223, 233, 243));
1784 painter->setBrush(gradient);
1787 painter->drawRect(beforeHandle);
1789 QPainterPath handlePath;
1790 QPainterPath innerPath;
1791 QPoint topLeft, topRight, bottomLeft;
1793 topLeft = handle.topLeft();
1794 topRight = handle.topRight();
1795 bottomLeft = handle.bottomLeft();
1797 topLeft = handle.bottomLeft();
1798 topRight = handle.topLeft();
1799 bottomLeft = handle.topRight();
1803 QImage image(sliderHandleImage);
1806 option->palette.color(QPalette::Midlight).rgb());
1808 option->palette.color(QPalette::Button).rgb());
1810 if (!(slider->state & State_Enabled)) {
1811 image.setColor(4, slider->palette.color(QPalette::Background).rgb());
1812 image.setColor(5, slider->palette.color(QPalette::Background).rgb());
1813 image.setColor(6, slider->palette.color(QPalette::Background).rgb());
1816 painter->drawImage(handle.topLeft(), image);
1818 QImage image(
":/images/verticalsliderhandle.png");
1819 painter->drawImage(handle.topLeft(), image);
1822 if (slider->tickPosition & QSlider::TicksBelow) {
1823 painter->setPen(slider->palette.color(QPalette::Light));
1824 int tickInterval = slider->tickInterval ? slider->tickInterval :
1827 for (
int i = 0; i <= slider->maximum; i += tickInterval) {
1829 int pos =
int(((i /
double(slider->maximum)) *
1830 ticks.width()) - 1);
1831 painter->drawLine(QPoint(ticks.left() + pos,
1832 ticks.top() + 2), QPoint(ticks.left() + pos, ticks.top() + 8));
1834 int pos =
int(((i /
double(slider->maximum)) *
1835 ticks.height()) - 1);
1836 painter->drawLine(QPoint(ticks.left() + 2, ticks.bottom() - pos),
1837 QPoint(ticks.right() - 2, ticks.bottom() - pos));
1841 painter->drawLine(QPoint(ticks.right(), ticks.top() + 2),
1842 QPoint(ticks.right(), ticks.top() + 8));
1844 painter->drawLine(QPoint(ticks.left() + 2, ticks.top()),
1845 QPoint(ticks.right() - 2, ticks.top()));
1851 QCommonStyle::drawComplexControl(control, option, painter, widget);
1856inline void JavaStyle::drawSunkenButtonShadow(QPainter *painter,
1858 const QColor &frameColor,
1863 painter->setPen(frameColor);
1866 painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y() + 1),
1867 QPoint(rect.x() + rect.width() - 1, rect.y() + 1)));
1868 painter->drawLine(QLine(QPoint(rect.x() + 1, rect.y()),
1869 QPoint(rect.x() + 1, rect.y() + rect.height())));
1871 painter->drawLine(QLine(QPoint(rect.right(), rect.bottom()),
1872 QPoint(rect.right(), rect.top())));
1873 painter->drawLine(QLine(QPoint(rect.left(), rect.top() + 1),
1874 QPoint(rect.right(), rect.top() + 1)));
1879inline void JavaStyle::drawButtonHoverFrame(QPainter *painter, QRect rect,
1880 const QColor &frameColor,
1881 const QColor &activeFrame)
const
1885 painter->setPen(activeFrame);
1886 painter->drawRect(rect);
1887 rect.adjust(1, 1, -1, -1);
1888 painter->setPen(frameColor);
1889 painter->drawRect(rect);
1890 rect.adjust(1, 1, -1, -1);
1891 painter->setPen(activeFrame);
1892 painter->drawRect(rect);
1897QStyle::SubControl JavaStyle::hitTestComplexControl(ComplexControl control,
1898 const QStyleOptionComplex *option,
1900 const QWidget *widget)
const
1902 SubControl ret = SC_None;
1906 const QStyleOptionTitleBar *bar =
1907 qstyleoption_cast<
const QStyleOptionTitleBar *>(option);
1909 QRect maximize = subControlRect(control, bar, SC_TitleBarMaxButton);
1910 if (maximize.contains(pos)) {
1911 ret = SC_TitleBarMaxButton;
1914 QRect minimize = subControlRect(control, bar, SC_TitleBarMinButton);
1915 if (minimize.contains(pos)) {
1916 ret = SC_TitleBarMinButton;
1919 QRect close = subControlRect(control, bar, SC_TitleBarCloseButton);
1920 if (close.contains(pos)) {
1921 ret = SC_TitleBarCloseButton;
1924 QRect system = subControlRect(control, bar, SC_TitleBarSysMenu);
1925 if (system.contains(pos)) {
1926 ret = SC_TitleBarSysMenu;
1929 ret = SC_TitleBarLabel;
1933 if (
const QStyleOptionSlider *scrollBar =
1934 qstyleoption_cast<
const QStyleOptionSlider *>(option)) {
1935 QRect slider = subControlRect(control, scrollBar,
1936 SC_ScrollBarSlider, widget);
1937 if (slider.contains(pos)) {
1938 ret = SC_ScrollBarSlider;
1942 QRect scrollBarAddLine = subControlRect(control, scrollBar,
1943 SC_ScrollBarAddLine, widget);
1944 if (scrollBarAddLine.contains(pos)) {
1945 ret = SC_ScrollBarAddLine;
1949 QRect scrollBarSubPage = subControlRect(control, scrollBar,
1950 SC_ScrollBarSubPage, widget);
1951 if (scrollBarSubPage.contains(pos)) {
1952 ret = SC_ScrollBarSubPage;
1956 QRect scrollBarAddPage = subControlRect(control, scrollBar,
1957 SC_ScrollBarAddPage, widget);
1958 if (scrollBarAddPage.contains(pos)) {
1959 ret = SC_ScrollBarAddPage;
1963 QRect scrollBarSubLine = subControlRect(control, scrollBar,
1964 SC_ScrollBarSubLine, widget);
1965 if (scrollBarSubLine.contains(pos)) {
1966 ret = SC_ScrollBarSubLine;
1973 ret = QCommonStyle::hitTestComplexControl(control, option, pos,
1979void JavaStyle::polish(QWidget *widget)
1981 if (qobject_cast<QCheckBox *>(widget) ||
1982 qobject_cast<QRadioButton *>(widget) ||
1983 qobject_cast<QPushButton *>(widget) ||
1984 qobject_cast<QToolButton *>(widget) ||
1985 qobject_cast<QSpinBox *>(widget) ||
1986 qobject_cast<QGroupBox *>(widget))
1987 widget->setAttribute(Qt::WA_Hover,
true);
1990void JavaStyle::unpolish(QWidget *widget)
1992 if (qobject_cast<QPushButton *>(widget) ||
1993 qobject_cast<QCheckBox *>(widget) ||
1994 qobject_cast<QRadioButton *>(widget) ||
1995 qobject_cast<QToolButton *>(widget) ||
1996 qobject_cast<QSpinBox *>(widget) ||
1997 qobject_cast<QGroupBox *>(widget))
1998 widget->setAttribute(Qt::WA_Hover,
false);
2001void JavaStyle::drawSplitter(
const QStyleOption *option, QPainter *painter,
2002 bool horizontal)
const
2004 QRect rect = option->rect;
2006 painter->setPen(Qt::NoPen);
2007 painter->setBrush(option->palette.color(QPalette::Background));
2009 painter->drawRect(rect);
2011 QColor colors[] = { Qt::white, option->palette.color(QPalette::Mid) };
2012 int iterations = horizontal ? rect.height() - 1 : rect.width() - 1;
2013 for (
int i = 0; i < iterations; ++i) {
2014 painter->setPen(colors[i % 2]);
2015 painter->drawPoint(xySwitch(QPoint(rect.x() + 0 + (i % 4),
2016 rect.y() + i), horizontal));
2020inline QPoint JavaStyle::xySwitch(
const QPoint &point,
bool horizontal)
const
2022 QPoint retPoint = point;
2025 retPoint = QPoint(point.y(), point.x());
2031void JavaStyle::drawPrimitive(PrimitiveElement element,
2032 const QStyleOption *option,
2034 const QWidget *widget)
const
2039 case PE_PanelButtonBevel:
2040 case PE_FrameButtonBevel: {
2042 painter->setBrush(option->palette.background());
2043 painter->setPen(Qt::NoPen);
2044 painter->drawRect(option->rect);
2048 case PE_IndicatorBranch: {
2050 QColor lineColor(204, 204, 255);
2051 QPixmap openPixmap(
":/images/jtreeopen.png");
2052 QPixmap closedPixmap(
":/images/jtreeclosed.png");
2053 QRect pixmapRect(QPoint(0, 0), QSize(12, 12));
2054 pixmapRect.moveCenter(option->rect.center());
2055 pixmapRect.translate(2, 0);
2056 QPoint center = option->rect.center();
2058 painter->setPen(lineColor);
2059 painter->setBrush(Qt::NoBrush);
2061 if (option->state & State_Item) {
2062 painter->drawLine(center,
2063 QPoint(option->rect.right(), center.y()));
2065 painter->drawLine(center, QPoint(center.x(),
2066 option->rect.top()));
2068 if (option->state & State_Sibling) {
2069 painter->drawLine(center, QPoint(center.x(),
2070 option->rect.bottom()));
2073 if (option->state & State_Children)
2074 if (option->state & State_Open)
2075 painter->drawPixmap(pixmapRect.topLeft(), closedPixmap);
2077 painter->drawPixmap(pixmapRect.topLeft(), openPixmap);
2078 }
else if (option->state & State_Sibling) {
2079 painter->drawLine(center.x(), option->rect.top(), center.x(),
2080 option->rect.bottom());
2086 case PE_IndicatorItemViewItemCheck: {
2089 case PE_FrameWindow: {
2091 bool active = option->state & State_Active;
2093 painter->setPen(Qt::NoPen);
2094 painter->setBrush(active ? option->palette.color(QPalette::Midlight)
2095 : option->palette.color(QPalette::Mid));
2097 painter->drawRect(QRect(option->rect.topLeft(), option->rect.bottomLeft() + QPoint(5, 0)));
2098 painter->drawRect(QRect(option->rect.bottomLeft(), option->rect.bottomRight() + QPoint(0, -5)));
2099 painter->drawRect(QRect(option->rect.bottomRight() + QPoint(-5, 0), option->rect.topRight()));
2100 painter->drawRect(QRect(option->rect.topLeft(), option->rect.topRight() + QPoint(0, 4)));
2102 painter->setBrush(Qt::NoBrush);
2103 painter->setPen(option->palette.color(QPalette::Active, QPalette::WindowText));
2104 painter->drawLine(option->rect.topLeft() + QPoint(2, 14),
2105 option->rect.bottomLeft() + QPoint(2, -14));
2107 painter->drawLine(option->rect.topRight() + QPoint(-2, 14),
2108 option->rect.bottomRight() + QPoint(-2, -14));
2110 painter->drawLine(option->rect.topLeft() + QPoint(14, 2),
2111 option->rect.topRight() + QPoint(-14, 2));
2113 painter->drawLine(option->rect.bottomLeft() + QPoint(14, -2),
2114 option->rect.bottomRight() + QPoint(-14, -2));
2116 painter->setPen(active ? option->palette.color(QPalette::Light) :
2117 option->palette.color(QPalette::Button));
2118 painter->drawLine(option->rect.topLeft() + QPoint(3, 15),
2119 option->rect.bottomLeft() + QPoint(3, -13));
2121 painter->drawLine(option->rect.topRight() + QPoint(-1, 15),
2122 option->rect.bottomRight() + QPoint(-1, -13));
2124 painter->drawLine(option->rect.topLeft() + QPoint(15, 3),
2125 option->rect.topRight() + QPoint(-13, 3));
2127 painter->drawLine(option->rect.bottomLeft() + QPoint(15, -1),
2128 option->rect.bottomRight() + QPoint(-13, -1));
2133 case PE_IndicatorSpinUp: {
2134 const QStyleOptionSpinBox *spinner =
2135 qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
2136 int add = spinner->state & State_Sunken &&
2137 spinner->activeSubControls & SC_SpinBoxUp ? 1 : 0;
2139 QPoint center = option->rect.center();
2140 painter->drawLine(center.x() + add, center.y() + 1 + add,
2141 center.x() + 2 + add, center.y() + 1 + add);
2142 painter->drawPoint(center.x() + 1 + add, center.y() + add);
2145 case PE_IndicatorSpinDown: {
2146 const QStyleOptionSpinBox *spinner =
2147 qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
2149 int add = spinner->state & State_Sunken &&
2150 spinner->activeSubControls & SC_SpinBoxDown ? 1 : 0;
2151 QPoint center = option->rect.center();
2152 painter->drawLine(center.x() + add, center.y() + add,
2153 center.x() + 2 + add, center.y() + add);
2154 painter->drawPoint(center.x() + 1 + add, center.y() + 1 + add);
2157 case PE_FrameDockWidget: {
2158 drawPrimitive(PE_FrameWindow, option, painter, widget);
2161 case PE_IndicatorToolBarHandle: {
2163 bool horizontal = option->state & State_Horizontal;
2166 offset = option->rect.topLeft();
2168 offset = option->rect.topLeft();
2170 int iterations = horizontal ? option->rect.height() :
2171 option->rect.width();
2173 for (
int i = 0; i < iterations; ++i) {
2174 painter->setPen(i % 2 ? Qt::white :
2175 option->palette.color(QPalette::Mid));
2177 painter->drawPoint(offset + xySwitch(QPoint(add, i),
2179 painter->drawPoint(offset + xySwitch(QPoint(add + 4, i),
2182 painter->drawPoint(offset + xySwitch(QPoint(add + 8, i),
2188 case PE_IndicatorToolBarSeparator: {
2191 case PE_PanelButtonTool: {
2192 const QStyleOptionToolButton *button =
2193 qstyleoption_cast<
const QStyleOptionToolButton *>(option);
2196 painter->setPen(Qt::red);
2197 if (!(option->state & State_Enabled))
2198 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2199 drawButtonBackground(option, painter,
false);
2203 if (button->state & State_MouseOver || button->state & State_On) {
2204 QStyleOptionButton bevel;
2205 bevel.state = button->state;
2206 bevel.rect = button->rect;
2207 bevel.palette = button->palette;
2209 drawButtonBackground(&bevel, painter,
false);
2211 painter->setPen(Qt::NoPen);
2212 painter->setBrush(button->palette.color(QPalette::Background));
2214 painter->drawRect(button->rect.adjusted(0, 0, -1, -1));
2218 case PE_FrameMenu: {
2219 painter->setPen(option->palette.color(QPalette::Midlight));
2220 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2223 case PE_PanelButtonCommand: {
2224 const QStyleOptionButton *btn =
2225 qstyleoption_cast<
const QStyleOptionButton *>(option);
2226 bool hover = (btn->state & State_Enabled) &&
2227 (btn->state & State_MouseOver);
2228 bool sunken = btn->state & State_Sunken;
2229 bool isDefault = btn->features & QStyleOptionButton::DefaultButton;
2230 bool on = option->state & State_On;
2232 drawButtonBackground(option, painter,
false);
2234 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2235 if (hover && !sunken && !isDefault && !on) {
2236 drawButtonHoverFrame(painter, rect,
2237 btn->palette.color(QPalette::Mid),
2238 btn->palette.color(QPalette::Button));
2239 }
else if (isDefault) {
2240 drawPrimitive(PE_FrameDefaultButton, option, painter, widget);
2244 case PE_FrameDefaultButton: {
2245 painter->setPen(option->palette.color(QPalette::Mid));
2246 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2247 painter->drawRect(rect);
2248 painter->drawRect(rect.adjusted(1, 1, -1, -1));
2252 case PE_IndicatorCheckBox: {
2254 drawButtonBackground(option, painter,
true);
2256 if (option->state & State_Enabled &&
2257 option->state & State_MouseOver &&
2258 !(option->state & State_Sunken)) {
2259 painter->setPen(option->palette.color(QPalette::Button));
2260 QRect rect = option->rect.adjusted(1, 1, -2, -2);
2261 painter->drawRect(rect);
2262 rect = rect.adjusted(1, 1, -1, -1);
2263 painter->drawRect(rect);
2266 if (option->state & State_On) {
2267 QImage image(
":/images/checkboxchecked.png");
2268 painter->drawImage(option->rect.topLeft(), image);
2274 case PE_IndicatorRadioButton: {
2276 QBrush radioBrush = option->palette.button();
2278 if (!(option->state & State_Sunken) &&
2279 option->state & State_Enabled)
2280 radioBrush = gradientBrush(option->rect);
2282 painter->setBrush(radioBrush);
2283 if (option->state & State_Enabled)
2284 painter->setPen(option->palette.color(QPalette::Mid));
2286 painter->setPen(option->palette.color(QPalette::Disabled,
2287 QPalette::WindowText));
2288 painter->drawEllipse(option->rect.adjusted(0, 0, -1, -1));
2290 if (option->state & State_MouseOver &&
2291 option->state & State_Enabled &&
2292 !(option->state & State_Sunken)) {
2293 gradientBrush(option->rect);
2294 painter->setPen(option->palette.color(QPalette::Button));
2295 painter->setBrush(Qt::NoBrush);
2296 QRect rect = option->rect.adjusted(1, 1, -2, -2);
2297 painter->drawEllipse(rect);
2298 rect = rect.adjusted(1, 1, -1, -1);
2299 painter->drawEllipse(rect);
2302 if (option->state & State_On) {
2303 painter->setBrush(option->palette.color(QPalette::Text));
2304 painter->setPen(Qt::NoPen);
2305 painter->drawEllipse(option->rect.adjusted(3, 3, -3, -3));
2307 if (option->state & State_Sunken &&
2308 option->state & State_Enabled) {
2309 painter->setPen(option->palette.color(QPalette::Mid));
2310 painter->drawArc(option->rect.adjusted(1, 1, -2, -2), 80 * 16,
2316 case PE_FrameTabWidget: {
2317 painter->setPen(option->palette.color(QPalette::Midlight));
2318 painter->drawRect(option->rect.adjusted(0, 0, -1, -1));
2319 painter->setPen(Qt::white);
2320 painter->drawRect(option->rect.adjusted(1, 1, -2, -2));
2324 case PE_FrameLineEdit: {
2325 const QStyleOptionFrame *frame =
2326 qstyleoption_cast<
const QStyleOptionFrame *>(option);
2328 painter->setPen(frame->palette.color(QPalette::Mid));
2329 painter->drawRect(frame->rect.adjusted(0, 0, -2, -2));
2330 painter->setPen(Qt::white);
2331 painter->drawRect(frame->rect.adjusted(1, 1, -1, -1));
2332 painter->setPen(frame->palette.color(QPalette::Active,
2333 QPalette::Background));
2334 painter->drawLine(frame->rect.bottomLeft(),
2335 frame->rect.bottomLeft() + QPoint(1, -1));
2336 painter->drawLine(frame->rect.topRight(),
2337 frame->rect.topRight() + QPoint(-1, 1));
2340 case PE_FrameFocusRect: {
2341 painter->setPen(option->palette.color(QPalette::Light));
2342 painter->setBrush(Qt::NoBrush);
2343 QRect rect = option->rect;
2344 rect = rect.adjusted(0,0, -1, -1);
2345 painter->drawRect(rect);
2349 QCommonStyle::drawPrimitive(element, option, painter, widget);
2355void JavaStyle::drawButtonBackground(
const QStyleOption *option,
2356 QPainter *painter,
bool isCheckbox)
const
2358 QBrush buttonBrush = option->palette.button();
2359 bool sunken = option->state & State_Sunken;
2360 bool disabled = !(option->state & State_Enabled);
2361 bool on = option->state & State_On;
2363 if (!sunken && !disabled && (!on || isCheckbox))
2364 buttonBrush = gradientBrush(option->rect);
2366 painter->fillRect(option->rect, buttonBrush);
2368 QRect rect = option->rect.adjusted(0, 0, -1, -1);
2371 painter->setPen(option->palette.color(QPalette::Disabled,
2372 QPalette::WindowText));
2374 painter->setPen(option->palette.color(QPalette::Mid));
2376 painter->drawRect(rect);
2378 if (sunken && !disabled) {
2379 drawSunkenButtonShadow(painter, rect,
2380 option->palette.color(QPalette::Mid),
2381 option->direction == Qt::RightToLeft);
2386QBrush JavaStyle::gradientBrush(
const QRect &rect)
const
2388 QLinearGradient gradient(rect.topLeft(), rect.bottomLeft());
2389 gradient.setColorAt(1.0, QColor(188, 210, 230));
2390 gradient.setColorAt(0.3, Qt::white);
2391 gradient.setColorAt(0.0, QColor(223, 233, 243));
2393 return QBrush(gradient);
2396QRect JavaStyle::subElementRect(SubElement element,
2397 const QStyleOption *option,
2398 const QWidget *widget)
const
2403 case SE_ToolBoxTabContents: {
2404 const QStyleOptionToolBox *box =
2405 qstyleoption_cast<
const QStyleOptionToolBox *>(option);
2407 rect.moveTopLeft(box->rect.topLeft() + QPoint(0, 2));
2408 rect.setHeight(box->rect.height() - 4);
2409 rect.setWidth(box->fontMetrics.horizontalAdvance(box->text) + 15);
2412 case SE_ProgressBarLabel:
2413 case SE_ProgressBarGroove:
2414 case SE_ProgressBarContents: {
2415 rect = option->rect.adjusted(1, 1, -1, -1);
2418 case SE_PushButtonFocusRect: {
2419 const QStyleOptionButton *btn =
2420 qstyleoption_cast<
const QStyleOptionButton *>(option);
2422 rect = btn->fontMetrics.boundingRect(btn->text);
2423 rect = QRect(0, 0, btn->fontMetrics.horizontalAdvance(btn->text),
2426 if (!btn->icon.isNull()) {
2427 rect.adjust(0, 0, btn->iconSize.width(), btn->iconSize.height()
2428 > rect.height() ? btn->iconSize.height() - rect.height() : 0);
2429 rect.translate(-btn->iconSize.width(), 0);
2430 rect.adjust(-1, -1, 1, 1);
2432 rect = QRect(
int(ceil((btn->rect.width() - rect.width()) / 2.0)),
2433 int(ceil((btn->rect.height() - rect.height()) / 2.0)),
2434 rect.width() - 1, rect.height());
2435 rect.adjust(-1, 0, 1, 0);
2440 rect = QCommonStyle::subElementRect(element, option, widget);
2445int JavaStyle::pixelMetric(PixelMetric metric,
2446 const QStyleOption* ,
2447 const QWidget* )
const
2452 case PM_ButtonShiftHorizontal:
2453 case PM_ButtonShiftVertical:
2454 case PM_TabBarTabShiftHorizontal:
2455 case PM_ButtonDefaultIndicator:
2456 case PM_TabBarTabShiftVertical:
2459 case PM_TabBarBaseOverlap:
2460 case PM_DefaultFrameWidth:
2463 case PM_TabBarTabVSpace:
2466 case PM_ScrollBarExtent:
2469 case PM_ScrollBarSliderMin:
2472 case PM_SplitterWidth:
2475 case PM_SliderThickness:
2478 case PM_SliderControlThickness:
2481 case PM_SliderTickmarkOffset:
2484 case PM_SliderSpaceAvailable:
2486 case PM_MenuPanelWidth:
2489 case PM_MenuVMargin:
2492 case PM_MenuBarPanelWidth:
2495 case PM_MenuBarItemSpacing:
2498 case PM_MenuBarHMargin:
2501 case PM_MenuBarVMargin:
2504 case PM_ComboBoxFrameWidth:
2507 case PM_MenuButtonIndicator:
2510 case PM_ToolBarItemMargin:
2513 case PM_ToolBarHandleExtent:
2516 case PM_SpinBoxFrameWidth:
2519 case PM_TitleBarHeight: {
2522 case PM_MDIFrameWidth:
2526 case PM_DockWidgetFrameWidth: {
2531 value = QCommonStyle::pixelMetric(metric);
2537int JavaStyle::styleHint(StyleHint hint,
const QStyleOption *option,
2538 const QWidget *widget,
2539 QStyleHintReturn *returnData)
const
2544 case SH_Table_GridLineColor: {
2545 ret =
static_cast<
int>(option->palette.color(QPalette::Mid).rgba());
2548 case QStyle::SH_Menu_Scrollable:
2552 ret = QCommonStyle::styleHint(hint, option, widget, returnData);
2557QPixmap JavaStyle::standardPixmap(StandardPixmap standardPixmap,
2558 const QStyleOption *option,
2559 const QWidget *widget)
const
2561 QPixmap pixmap = QCommonStyle::standardPixmap(standardPixmap, option,
2564 QPixmap maximizePixmap(
":/images/internalmaximize.png");
2565 QPixmap minimizePixmap(
":/images/internalminimize.png");
2566 QPixmap closePixmap(
":/images/internalclose.png");
2567 QPixmap internalPixmap(
":/images/internalsystem.png");
2568 QPixmap internalCloseDownPixmap(
":/images/internalclosedown.png");
2569 QPixmap minimizeDownPixmap(
":/images/internalminimizedown.png");
2570 QPixmap maximizeDownPixmap(
":/images/internalmaximizedown.png");
2571 QPixmap dirOpenPixmap(
":/images/open24.png");
2572 QPixmap filePixmap(
":/images/file.png");
2574 switch (standardPixmap) {
2575 case SP_DirLinkIcon:
2576 case SP_DirClosedIcon:
2578 case SP_DirOpenIcon: {
2579 pixmap = closePixmap;
2583 pixmap = filePixmap;
2586 case SP_FileDialogBack: {
2587 pixmap = QPixmap(
":/images/fileback.png");
2590 case SP_FileDialogToParent: {
2591 pixmap = QPixmap(
":/images/fileparent.png");
2594 case SP_FileDialogNewFolder: {
2595 pixmap = QPixmap(
":/images/open24.png");
2598 case SP_FileDialogListView: {
2599 pixmap = QPixmap(
":/images/filelist.png");
2602 case SP_FileDialogDetailedView: {
2603 pixmap = QPixmap(
":/images/filedetail.png");
2606 case SP_MessageBoxInformation: {
2607 pixmap = QPixmap(
":/images/information.png");
2610 case SP_MessageBoxWarning: {
2611 pixmap = QPixmap(
":/images/warning.png");
2613 case SP_MessageBoxCritical: {
2614 pixmap = QPixmap(
":/images/critical.png");
2617 case SP_MessageBoxQuestion: {
2618 pixmap = QPixmap(
":/images/question.png");
2621 case SP_TitleBarNormalButton:
2622 pixmap = maximizePixmap;
2624 case SP_TitleBarCloseButton:
2625 pixmap = closePixmap;
2634QSize JavaStyle::sizeFromContents(ContentsType type,
2635 const QStyleOption *option,
2636 const QSize &contentsSize,
2637 const QWidget *widget)
const
2641 return QSize(contentsSize.width() + 27, contentsSize.height());
2644 const QStyleOptionSlider *slider =
2645 qstyleoption_cast<
const QStyleOptionSlider *>(option);
2646 if (slider->tickPosition == QSlider::TicksBelow) {
2647 return QSize(contentsSize.width(), contentsSize.height() + 15);
2649 return contentsSize;
2652 case CT_MenuBarItem: {
2653 const QStyleOptionMenuItem *menuItem =
2654 qstyleoption_cast<
const QStyleOptionMenuItem *>(option);
2655 QFontMetrics metrics(menuItem->font);
2656 QRect boundingRect = metrics.boundingRect(menuItem->text);
2657 int width = boundingRect.width() + 14;
2658 int height = boundingRect.height() + 3;
2662 return QSize(width, height);
2665 const QStyleOptionMenuItem *menuItem =
2666 qstyleoption_cast<
const QStyleOptionMenuItem *>(option);
2667 QSize defaultSize = QCommonStyle::sizeFromContents(type, option,
2668 contentsSize, widget);
2670 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator)
2676 if (!menuItem->icon.isNull()) {
2680 if (!menuItem->text.isEmpty()) {
2681 QFontMetrics metrics(menuItem->font);
2682 QString text = menuItem->text;
2684 QRect textRect = metrics.boundingRect(text);
2685 width += textRect.width();
2686 if (height < textRect.height())
2687 height += textRect.height();
2689 if (menuItem->checkType != QStyleOptionMenuItem::NotCheckable) {
2694 return QSize(width, height);
2697 return QCommonStyle::sizeFromContents(type, option, contentsSize,
static const int windowsSepHeight
static const int windowsTabSpacing
static const int windowsItemHMargin
static const int windowsItemVMargin
static const int windowsCheckMarkWidth
static const int windowsArrowHMargin
static const int windowsCheckMarkHMargin
static const int windowsRightBorder
static const char *const sliderHandleImage[]
static const int windowsItemFrame