Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickcommonstyle.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickcommonstyle.h"
7
8#include "qquickstyleoption.h"
9#include "qquickdrawutil.h"
10#include "qquickstylehelper_p.h"
11
12#include <QtGui/QWindow>
13#include <qfile.h>
14#include <private/qguiapplication_p.h>
15#include <qpa/qplatformtheme.h>
16#include <qbitmap.h>
17#include <qcache.h>
18#include <qmath.h>
19#include <qpainter.h>
20#include <qpaintengine.h>
21#include <qpainterpath.h>
22#include <private/qmath_p.h>
23#include <qdebug.h>
24#include <qtextformat.h>
25#include <qfileinfo.h>
26#include <qdir.h>
27#if QT_CONFIG(settings)
28#include <qsettings.h>
29#endif
30#include <qvariant.h>
31#include <qpixmapcache.h>
32#include <qmatrix4x4.h>
33
34#include <limits.h>
35
36#include <private/qtextengine_p.h>
37#include <QtGui/private/qhexstring_p.h>
38
40
41static inline qreal dpr(const QWindow *w)
42{
43 return w != nullptr ? w->devicePixelRatio() : qApp->devicePixelRatio();
44}
45
70namespace QQC2 {
71
75
79
82
84{
85 Q_D(const QCommonStyle);
86 switch (pe) {
90 opt->state & (State_Sunken | State_On), 1, 0);
91 break;
99 break;
102 break;
104 if (opt->state & State_NoChange) {
105 p->setPen(opt->palette.windowText().color());
106 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
107 p->drawRect(opt->rect);
108 p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
109 } else {
113 }
114 break;
116 QRect ir = opt->rect;
117 p->setPen(opt->palette.dark().color());
118 p->drawArc(opt->rect, 0, 5760);
119 if (opt->state & (State_Sunken | State_On)) {
120 ir.adjust(2, 2, -2, -2);
121 p->setBrush(opt->palette.windowText());
122 p->drawEllipse(ir);
123 }
124 break; }
126 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
127 QColor bg = fropt->backgroundColor;
128 QPen oldPen = p->pen();
129 if (bg.isValid()) {
130 int h, s, v;
131 bg.getHsv(&h, &s, &v);
132 if (v >= 128)
133 p->setPen(Qt::black);
134 else
135 p->setPen(Qt::white);
136 } else {
137 p->setPen(opt->palette.windowText().color());
138 }
139 QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
140 p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
141 p->setPen(oldPen);
142 }
143 break;
145 const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();
146 const int markH = markW;
147 int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;
148 int posY = opt->rect.y() + (opt->rect.height() - markH)/2;
149
150 QVector<QLineF> a;
151 a.reserve(markH);
152
153 int i, xx, yy;
154 xx = posX;
155 yy = 3 + posY;
156 for (i = 0; i < markW/2; ++i) {
157 a << QLineF(xx, yy, xx, yy + 2);
158 ++xx;
159 ++yy;
160 }
161 yy -= 2;
162 for (; i < markH; ++i) {
163 a << QLineF(xx, yy, xx, yy + 2);
164 ++xx;
165 --yy;
166 }
167 if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
168 p->save();
169 p->translate(1, 1);
170 p->setPen(opt->palette.light().color());
171 p->drawLines(a);
172 p->restore();
173 }
174 p->setPen((opt->state & State_On) ? opt->palette.highlightedText().color() : opt->palette.text().color());
175 p->drawLines(a);
176 break; }
177 case PE_Frame:
178 case PE_FrameMenu:
179 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
180 if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {
183 } else {
185 }
186 }
187 break;
188 case PE_PanelMenuBar:
189 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)){
192
193 }
194 else if (const QStyleOptionToolBar *frame = qstyleoption_cast<const QStyleOptionToolBar *>(opt)){
197 }
198
199 break;
200 case PE_PanelMenu:
201 break;
202 case PE_PanelToolBar:
203 break;
205 {
206 p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,
208 }
209 break;
210 case PE_IndicatorBranch: {
211 static const int decoration_size = 9;
212 int mid_h = opt->rect.x() + opt->rect.width() / 2;
213 int mid_v = opt->rect.y() + opt->rect.height() / 2;
214 int bef_h = mid_h;
215 int bef_v = mid_v;
216 int aft_h = mid_h;
217 int aft_v = mid_v;
218 if (opt->state & State_Children) {
219 int delta = decoration_size / 2;
220 bef_h -= delta;
221 bef_v -= delta;
222 aft_h += delta;
223 aft_v += delta;
224 p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
225 if (!(opt->state & State_Open))
226 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
227 QPen oldPen = p->pen();
228 p->setPen(opt->palette.dark().color());
229 p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
230 p->setPen(oldPen);
231 }
233 if (opt->state & State_Item) {
235 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
236 else
237 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
238 }
239 if (opt->state & State_Sibling)
240 p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
242 p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
243 break; }
245 qDrawShadeRect(p, opt->rect, opt->palette, true, 1, 0, nullptr);
246 break;
248 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
249 QPen oldPen = p->pen();
250 if (header->sortIndicator & QStyleOptionHeader::SortUp) {
251 p->setPen(QPen(opt->palette.light(), 0));
252 p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(),
253 opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height());
254 p->setPen(QPen(opt->palette.dark(), 0));
255 const QPoint points[] = {
256 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()),
257 QPoint(opt->rect.x(), opt->rect.y()),
258 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()),
259 };
260 p->drawPolyline(points, sizeof points / sizeof *points);
261 } else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
262 p->setPen(QPen(opt->palette.light(), 0));
263 const QPoint points[] = {
264 QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()),
265 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()),
266 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()),
267 };
268 p->drawPolyline(points, sizeof points / sizeof *points);
269 p->setPen(QPen(opt->palette.dark(), 0));
270 p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(),
271 opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
272 }
273 p->setPen(oldPen);
274 }
275 break;
277 if (const QStyleOptionTabBarBase *tbb
278 = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
279 p->save();
280 switch (tbb->shape) {
283 p->setPen(QPen(tbb->palette.light(), 0));
284 p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
285 break;
288 p->setPen(QPen(tbb->palette.light(), 0));
289 p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
290 break;
293 p->setPen(QPen(tbb->palette.shadow(), 0));
294 p->drawLine(tbb->rect.left(), tbb->rect.bottom(),
295 tbb->rect.right(), tbb->rect.bottom());
296 p->setPen(QPen(tbb->palette.dark(), 0));
297 p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1,
298 tbb->rect.right() - 1, tbb->rect.bottom() - 1);
299 break;
302 p->setPen(QPen(tbb->palette.dark(), 0));
303 p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
304 break;
305 }
306 p->restore();
307 }
308 break;
310 if (d->tabBarcloseButtonIcon.isNull()) {
311 d->tabBarcloseButtonIcon.addPixmap(QPixmap(
312 QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-16.png")),
314 d->tabBarcloseButtonIcon.addPixmap(QPixmap(
315 QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-down-16.png")),
317 d->tabBarcloseButtonIcon.addPixmap(QPixmap(
318 QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-closetab-hover-16.png")),
320 }
321
326 if (!(opt->state & State_Raised)
327 && !(opt->state & State_Sunken)
330
332 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(size, size), dpr(opt->window), mode, state);
334 break;
335 }
337 case PE_FrameWindow:
338 qDrawWinPanel(p, opt->rect, opt->palette, false, nullptr);
339 break;
340 case PE_FrameLineEdit:
342 break;
343 case PE_FrameGroupBox:
344 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
345 if (frame->features & QStyleOptionFrame::Flat) {
346 QRect fr = frame->rect;
347 QPoint p1(fr.x(), fr.y() + 1);
348 QPoint p2(fr.x() + fr.width(), p1.y());
349 qDrawShadeLine(p, p1, p2, frame->palette, true,
351 } else {
353 frame->rect.height(), frame->palette, true,
355 }
356 }
357 break;
359 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
360 int lw = frame->lineWidth;
361 if (lw <= 0)
363
364 qDrawShadePanel(p, frame->rect, frame->palette, false, lw);
365 }
366 break;
368 p->save();
369 p->translate(opt->rect.x(), opt->rect.y());
370 if (opt->state & State_Horizontal) {
371 int x = opt->rect.width() / 3;
373 x -= 2;
374 if (opt->rect.height() > 4) {
375 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
376 opt->palette, false, 1, nullptr);
377 qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4,
378 opt->palette, false, 1, nullptr);
379 }
380 } else {
381 if (opt->rect.width() > 4) {
382 int y = opt->rect.height() / 3;
383 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
384 opt->palette, false, 1, nullptr);
385 qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3,
386 opt->palette, false, 1, nullptr);
387 }
388 }
389 p->restore();
390 break;
392 {
393 QPoint p1, p2;
394 if (opt->state & State_Horizontal) {
395 p1 = QPoint(opt->rect.width()/2, 0);
396 p2 = QPoint(p1.x(), opt->rect.height());
397 } else {
398 p1 = QPoint(0, opt->rect.height()/2);
399 p2 = QPoint(opt->rect.width(), p1.y());
400 }
401 qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
402 break;
403 }
406 QRect r = opt->rect;
408 QRect br = r.adjusted(fw, fw, -fw, -fw);
409
410 int offset = (opt->state & State_Sunken) ? 1 : 0;
411 int step = (br.width() + 4) / 5;
412 p->fillRect(br.x() + offset, br.y() + offset +br.height() / 2 - step / 2,
413 br.width(), step,
415 if (pe == PE_IndicatorSpinPlus)
416 p->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset,
417 step, br.height(),
419
420 break; }
423 QRect r = opt->rect;
425 // QRect br = r.adjusted(fw, fw, -fw, -fw);
426 int x = r.x(), y = r.y(), w = r.width(), h = r.height();
427 int sw = w-4;
428 if (sw < 3)
429 break;
430 else if (!(sw & 1))
431 sw--;
432 sw -= (sw / 7) * 2; // Empty border
433 int sh = sw/2 + 2; // Must have empty row at foot of arrow
434
435 int sx = x + w / 2 - sw / 2;
436 int sy = y + h / 2 - sh / 2;
437
438 if (pe == PE_IndicatorSpinUp && fw)
439 --sy;
440
441 int bsx = 0;
442 int bsy = 0;
443 if (opt->state & State_Sunken) {
446 }
447 p->save();
448 p->translate(sx + bsx, sy + bsy);
449 p->setPen(opt->palette.buttonText().color());
450 p->setBrush(opt->palette.buttonText());
451 if (pe == PE_IndicatorSpinDown) {
452 const QPoint points[] = { QPoint(0, 1), QPoint(sw-1, 1), QPoint(sh-2, sh-1) };
453 p->drawPolygon(points, sizeof points / sizeof *points);
454 } else {
455 const QPoint points[] = { QPoint(0, sh-1), QPoint(sw-1, sh-1), QPoint(sh-2, 1) };
456 p->drawPolygon(points, sizeof points / sizeof *points);
457 }
458 p->restore();
459 break; }
460 case PE_PanelTipLabel: {
463 break;
464 }
466 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
467 bool rtl = tab->direction == Qt::RightToLeft;
468 const bool horizontal = tab->rect.height() > tab->rect.width();
469 const int margin = 4;
471
472 if (horizontal) {
473 QRect rect = tab->rect.adjusted(rtl ? margin : 0, 0, rtl ? 1 : -margin, 0);
474 rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));
475 rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));
476
477 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
478 int count = 4;
479 for (int jags = 1; jags <= count; ++jags, rtl = !rtl)
480 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
481 } else {
482 QRect rect = tab->rect.adjusted(0, 0, 0, -margin);
483 rect.setLeft(rect.left() + ((tab->state & State_Selected) ? 1 : 3));
484 rect.setRight(rect.right() - ((tab->state & State_Selected) ? 0 : 2));
485
486 path.moveTo(QPoint(rect.left(), rect.top()));
487 int count = 4;
488 for (int jags = 1; jags <= count; ++jags, rtl = !rtl)
489 path.lineTo(QPoint(rect.left() + jags * rect.width()/count, rtl ? rect.top() : rect.bottom()));
490 }
491
492 p->setPen(QPen(tab->palette.dark(), qreal(.8)));
493 p->setBrush(tab->palette.window());
494 p->setRenderHint(QPainter::Antialiasing);
495 p->drawPath(path);
496 }
497 break;
498 case PE_PanelLineEdit:
499 if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
500 p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth),
502
503 if (panel->lineWidth > 0)
505 }
506 break;
507#if QT_CONFIG(quick_itemview)
509 if (const QStyleOptionViewItem *viewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
510 bool reverse = (viewOpt->direction == Qt::RightToLeft);
511 p->save();
513 int x = viewOpt->rect.x() + 1;
514 int offset = (viewOpt->rect.height() / 3);
515 int height = (viewOpt->rect.height()) - offset * 2;
516 if (height % 2 == 1)
517 --height;
518 int x2 = x + height - 1;
519 if (reverse) {
520 x = viewOpt->rect.x() + viewOpt->rect.width() - 1;
521 x2 = x - height + 1;
522 }
523 path.moveTo(x, viewOpt->rect.y() + offset);
524 path.lineTo(x, viewOpt->rect.y() + offset + height);
525 path.lineTo(x2, viewOpt->rect.y() + offset+height/2);
526 path.closeSubpath();
527 if (viewOpt->state & QStyle::State_Selected ) {
528 if (viewOpt->showDecorationSelected) {
529 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText);
530 p->setPen(color);
531 p->setBrush(color);
532 } else {
533 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText);
534 p->setPen(color);
535 p->setBrush(color);
536 }
537
538 } else {
539 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid);
540 p->setPen(color);
541 p->setBrush(color);
542 }
543 p->drawPath(path);
544
545 // draw the vertical and top triangle line
546 if (!(viewOpt->state & QStyle::State_Selected)) {
547 QPainterPath lines;
548 lines.moveTo(x, viewOpt->rect.y() + offset);
549 lines.lineTo(x, viewOpt->rect.y() + offset + height);
550 lines.moveTo(x, viewOpt->rect.y() + offset);
551 lines.lineTo(x2, viewOpt->rect.y() + offset+height/2);
552 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark);
553 p->setPen(color);
554 p->drawPath(lines);
555 }
556 p->restore();
557 }
558 break; }
560 QRect rect = opt->rect;
561 if (opt->rect.height() == 0)
562 p->drawLine(rect.topLeft(), rect.topRight());
563 else
564 p->drawRect(rect);
565 break; }
567 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
569 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
571
573 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
574 else if (vopt->features & QStyleOptionViewItem::Alternate)
575 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
576 }
577 break;
579 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
581 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
583
584 if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) {
585 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
586 } else {
587 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
588 QPointF oldBO = p->brushOrigin();
589 p->setBrushOrigin(vopt->rect.topLeft());
590 p->fillRect(vopt->rect, vopt->backgroundBrush);
591 p->setBrushOrigin(oldBO);
592 }
593
594 if (vopt->state & QStyle::State_Selected) {
596 p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight));
597 }
598 }
599 }
600 break;
601#endif // QT_CONFIG(quick_itemview)
604 p->fillRect(opt->rect, brush);
605 } break;
610 {
611 if (opt->rect.width() <= 1 || opt->rect.height() <= 1)
612 break;
613 QRect r = opt->rect;
614 int size = qMin(r.height(), r.width());
616 QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-")
618 % HexString<uint>(pe);
619 if (!QPixmapCache::find(pixmapName, &pixmap)) {
620 qreal pixelRatio = p->device()->devicePixelRatioF();
621 int border = qRound(pixelRatio*(size/5));
622 int sqsize = qRound(pixelRatio*(2*(size/2)));
624 image.fill(0);
625 QPainter imagePainter(&image);
626
627 QPolygon a;
628 switch (pe) {
630 a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2);
631 break;
633 a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2);
634 break;
636 a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
637 break;
639 a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
640 break;
641 default:
642 break;
643 }
644
645 int bsx = 0;
646 int bsy = 0;
647
648 if (opt->state & State_Sunken) {
651 }
652
653 QRect bounds = a.boundingRect();
654 int sx = sqsize / 2 - bounds.center().x() - 1;
655 int sy = sqsize / 2 - bounds.center().y() - 1;
656 imagePainter.translate(sx + bsx, sy + bsy);
657 imagePainter.setPen(opt->palette.buttonText().color());
658 imagePainter.setBrush(opt->palette.buttonText());
659
660 if (!(opt->state & State_Enabled)) {
661 imagePainter.translate(1, 1);
662 imagePainter.setBrush(opt->palette.light().color());
663 imagePainter.setPen(opt->palette.light().color());
664 imagePainter.drawPolygon(a);
665 imagePainter.translate(-1, -1);
666 imagePainter.setBrush(opt->palette.mid().color());
667 imagePainter.setPen(opt->palette.mid().color());
668 }
669
670 imagePainter.drawPolygon(a);
671 imagePainter.end();
672 pixmap = QPixmap::fromImage(std::move(image));
673 pixmap.setDevicePixelRatio(pixelRatio);
674 QPixmapCache::insert(pixmapName, pixmap);
675 }
676 int xOffset = r.x() + (r.width() - size)/2;
677 int yOffset = r.y() + (r.height() - size)/2;
678 p->drawPixmap(xOffset, yOffset, pixmap);
679 }
680 break;
681 default:
682 break;
683 }
684}
685
686static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton,
687 const QRect &rect, QPainter *painter)
688{
690 switch (toolbutton->arrowType) {
691 case Qt::LeftArrow:
693 break;
694 case Qt::RightArrow:
696 break;
697 case Qt::UpArrow:
699 break;
700 case Qt::DownArrow:
702 break;
703 default:
704 return;
705 }
706 QStyleOption arrowOpt = *toolbutton;
707 arrowOpt.rect = rect;
708 style->drawPrimitive(pe, &arrowOpt, painter);
709}
710
711static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth, int maxHeight = -1, int *lastVisibleLine = nullptr)
712{
713 if (lastVisibleLine)
714 *lastVisibleLine = -1;
715 qreal height = 0;
716 qreal widthUsed = 0;
717 textLayout.beginLayout();
718 int i = 0;
719 while (true) {
720 QTextLine line = textLayout.createLine();
721 if (!line.isValid())
722 break;
723 line.setLineWidth(lineWidth);
724 line.setPosition(QPointF(0, height));
725 height += line.height();
726 widthUsed = qMax(widthUsed, line.naturalTextWidth());
727 // we assume that the height of the next line is the same as the current one
728 if (maxHeight > 0 && lastVisibleLine && height + line.height() > maxHeight) {
729 const QTextLine nextLine = textLayout.createLine();
730 *lastVisibleLine = nextLine.isValid() ? i : -1;
731 break;
732 }
733 ++i;
734 }
735 textLayout.endLayout();
736 return QSizeF(widthUsed, height);
737}
738
740 const QFont &font, const QRect &textRect, const Qt::Alignment valign,
741 Qt::TextElideMode textElideMode, int flags,
742 bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const
743{
744 QTextLayout textLayout(text, font);
745 textLayout.setTextOption(textOption);
746
747 // In AlignVCenter mode when more than one line is displayed and the height only allows
748 // some of the lines it makes no sense to display those. From a users perspective it makes
749 // more sense to see the start of the text instead something inbetween.
750 const bool vAlignmentOptimization = paintStartPosition && valign.testFlag(Qt::AlignVCenter);
751
752 int lastVisibleLine = -1;
753 viewItemTextLayout(textLayout, textRect.width(), vAlignmentOptimization ? textRect.height() : -1, &lastVisibleLine);
754
755 const QRectF boundingRect = textLayout.boundingRect();
756 // don't care about LTR/RTL here, only need the height
757 const QRect layoutRect = QStyle::alignedRect(Qt::LayoutDirectionAuto, valign,
758 boundingRect.size().toSize(), textRect);
759
760 if (paintStartPosition)
761 *paintStartPosition = QPointF(textRect.x(), layoutRect.top());
762
763 QString ret;
764 qreal height = 0;
765 const int lineCount = textLayout.lineCount();
766 for (int i = 0; i < lineCount; ++i) {
767 const QTextLine line = textLayout.lineAt(i);
768 height += line.height();
769
770 // above visible rect
771 if (height + layoutRect.top() <= textRect.top()) {
772 if (paintStartPosition)
773 paintStartPosition->ry() += line.height();
774 continue;
775 }
776
777 const int start = line.textStart();
778 const int length = line.textLength();
779 const bool drawElided = line.naturalTextWidth() > textRect.width();
780 bool elideLastVisibleLine = lastVisibleLine == i;
781 if (!drawElided && i + 1 < lineCount && lastVisibleLineShouldBeElided) {
782 const QTextLine nextLine = textLayout.lineAt(i + 1);
783 const int nextHeight = height + nextLine.height() / 2;
784 // elide when less than the next half line is visible
785 if (nextHeight + layoutRect.top() > textRect.height() + textRect.top())
786 elideLastVisibleLine = true;
787 }
788
789 QString text = textLayout.text().mid(start, length);
790 if (drawElided || elideLastVisibleLine) {
791 if (elideLastVisibleLine) {
792 if (text.endsWith(QChar::LineSeparator))
793 text.chop(1);
794 text += QChar(0x2026);
795 }
797 ret += engine.elidedText(textElideMode, textRect.width(), flags);
798
799 // no newline for the last line (last visible or real)
800 // sometimes drawElided is true but no eliding is done so the text ends
801 // with QChar::LineSeparator - don't add another one. This happened with
802 // arabic text in the testcase for QTBUG-72805
803 if (i < lineCount - 1 &&
804 !ret.endsWith(QChar::LineSeparator))
805 ret += QChar::LineSeparator;
806 } else {
807 ret += text;
808 }
809
810 // below visible text, can stop
811 if ((height + layoutRect.top() >= textRect.bottom()) ||
812 (lastVisibleLine >= 0 && lastVisibleLine == i))
813 break;
814 }
815 return ret;
816}
817
818#if QT_CONFIG(quick_itemview)
819QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int role) const
820{
821 switch (role) {
823 if (option->features & QStyleOptionViewItem::HasCheckIndicator)
826 break;
827 case Qt::DisplayRole:
828 if (option->features & QStyleOptionViewItem::HasDisplay) {
829 QTextOption textOption;
831 QTextLayout textLayout(option->text, option->font);
832 textLayout.setTextOption(textOption);
833 const bool wrapText = option->features & QStyleOptionViewItem::WrapText;
834 const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, option) + 1;
835 QRect bounds = option->rect;
836 switch (option->decorationPosition) {
837 case QStyleOptionViewItem::Left:
838 case QStyleOptionViewItem::Right: {
839 if (wrapText && bounds.isValid()) {
840 int width = bounds.width() - 2 * textMargin;
841 if (option->features & QStyleOptionViewItem::HasDecoration)
842 width -= option->decorationSize.width() + 2 * textMargin;
843 bounds.setWidth(width);
844 } else
845 bounds.setWidth(QFIXED_MAX);
846 break;
847 }
848 case QStyleOptionViewItem::Top:
849 case QStyleOptionViewItem::Bottom:
850 if (wrapText)
851 bounds.setWidth(bounds.isValid() ? bounds.width() - 2 * textMargin : option->decorationSize.width());
852 else
853 bounds.setWidth(QFIXED_MAX);
854 break;
855 default:
856 break;
857 }
858
859 if (wrapText && option->features & QStyleOptionViewItem::HasCheckIndicator)
860 bounds.setWidth(bounds.width() - proxyStyle->pixelMetric(QStyle::PM_IndicatorWidth) - 2 * textMargin);
861
862 const int lineWidth = bounds.width();
863 const QSizeF size = viewItemTextLayout(textLayout, lineWidth);
864 return QSize(qCeil(size.width()) + 2 * textMargin, qCeil(size.height()));
865 }
866 break;
868 if (option->features & QStyleOptionViewItem::HasDecoration) {
869 return option->decorationSize;
870 }
871 break;
872 default:
873 break;
874 }
875
876 return QSize(0, 0);
877}
878
879void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const
880{
881 const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, nullptr) + 1;
882
883 QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
884 const bool wrapText = option->features & QStyleOptionViewItem::WrapText;
885 QTextOption textOption;
886 textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap);
887 textOption.setTextDirection(option->direction);
888 textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment));
889
890 QPointF paintPosition;
891 const QString newText = calculateElidedText(option->text, textOption,
892 option->font, textRect, option->displayAlignment,
893 option->textElideMode, 0,
894 true, &paintPosition);
895
896 QTextLayout textLayout(newText, option->font);
897 textLayout.setTextOption(textOption);
898 viewItemTextLayout(textLayout, textRect.width());
899 textLayout.draw(p, paintPosition);
900}
901
910void QCommonStylePrivate::viewItemLayout(const QStyleOptionViewItem *opt, QRect *checkRect,
911 QRect *pixmapRect, QRect *textRect, bool sizehint) const
912{
913 Q_ASSERT(checkRect && pixmapRect && textRect);
914 *pixmapRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DecorationRole));
915 *textRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::DisplayRole));
916 *checkRect = QRect(QPoint(0, 0), viewItemSize(opt, Qt::CheckStateRole));
917
918 const bool hasCheck = checkRect->isValid();
919 const bool hasPixmap = pixmapRect->isValid();
920 const bool hasText = textRect->isValid();
921 const bool hasMargin = (hasText | hasPixmap | hasCheck);
922 const int frameHMargin = hasMargin ?
924 const int textMargin = hasText ? frameHMargin : 0;
925 const int pixmapMargin = hasPixmap ? frameHMargin : 0;
926 const int checkMargin = hasCheck ? frameHMargin : 0;
927 const int x = opt->rect.left();
928 const int y = opt->rect.top();
929 int w, h;
930
931 if (textRect->height() == 0 && (!hasPixmap || !sizehint)) {
932 //if there is no text, we still want to have a decent height for the item sizeHint and the editor size
934 }
935
936 QSize pm(0, 0);
937 if (hasPixmap) {
938 pm = pixmapRect->size();
939 pm.rwidth() += 2 * pixmapMargin;
940 }
941 if (sizehint) {
942 h = qMax(checkRect->height(), qMax(textRect->height(), pm.height()));
943 if (opt->decorationPosition == QStyleOptionViewItem::Left
944 || opt->decorationPosition == QStyleOptionViewItem::Right) {
945 w = textRect->width() + pm.width();
946 } else {
947 w = qMax(textRect->width(), pm.width());
948 }
949 } else {
950 w = opt->rect.width();
951 h = opt->rect.height();
952 }
953
954 int cw = 0;
955 QRect check;
956 if (hasCheck) {
957 cw = checkRect->width() + 2 * checkMargin;
958 if (sizehint) w += cw;
959 if (opt->direction == Qt::RightToLeft) {
960 check.setRect(x + w - cw, y, cw, h);
961 } else {
962 check.setRect(x, y, cw, h);
963 }
964 }
965
968 switch (opt->decorationPosition) {
969 case QStyleOptionViewItem::Top: {
970 if (hasPixmap)
971 pm.setHeight(pm.height() + pixmapMargin); // add space
972 h = sizehint ? textRect->height() : h - pm.height();
973
974 if (opt->direction == Qt::RightToLeft) {
975 decoration.setRect(x, y, w - cw, pm.height());
976 display.setRect(x, y + pm.height(), w - cw, h);
977 } else {
978 decoration.setRect(x + cw, y, w - cw, pm.height());
979 display.setRect(x + cw, y + pm.height(), w - cw, h);
980 }
981 break; }
982 case QStyleOptionViewItem::Bottom: {
983 if (hasText)
984 textRect->setHeight(textRect->height() + textMargin); // add space
985 h = sizehint ? textRect->height() + pm.height() : h;
986
987 if (opt->direction == Qt::RightToLeft) {
988 display.setRect(x, y, w - cw, textRect->height());
989 decoration.setRect(x, y + textRect->height(), w - cw, h - textRect->height());
990 } else {
991 display.setRect(x + cw, y, w - cw, textRect->height());
992 decoration.setRect(x + cw, y + textRect->height(), w - cw, h - textRect->height());
993 }
994 break; }
995 case QStyleOptionViewItem::Left: {
996 if (opt->direction == Qt::LeftToRight) {
997 decoration.setRect(x + cw, y, pm.width(), h);
998 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h);
999 } else {
1000 display.setRect(x, y, w - pm.width() - cw, h);
1001 decoration.setRect(display.right() + 1, y, pm.width(), h);
1002 }
1003 break; }
1004 case QStyleOptionViewItem::Right: {
1005 if (opt->direction == Qt::LeftToRight) {
1006 display.setRect(x + cw, y, w - pm.width() - cw, h);
1007 decoration.setRect(display.right() + 1, y, pm.width(), h);
1008 } else {
1009 decoration.setRect(x, y, pm.width(), h);
1010 display.setRect(decoration.right() + 1, y, w - pm.width() - cw, h);
1011 }
1012 break; }
1013 default:
1014 qWarning("doLayout: decoration position is invalid");
1015 decoration = *pixmapRect;
1016 break;
1017 }
1018
1019 if (!sizehint) { // we only need to do the internal layout if we are going to paint
1021 checkRect->size(), check);
1022 *pixmapRect = QStyle::alignedRect(opt->direction, opt->decorationAlignment,
1023 pixmapRect->size(), decoration);
1024 // the text takes up all available space, unless the decoration is not shown as selected
1025 if (opt->showDecorationSelected)
1026 *textRect = display;
1027 else
1028 *textRect = QStyle::alignedRect(opt->direction, opt->displayAlignment,
1029 textRect->size().boundedTo(display.size()), display);
1030 } else {
1031 *checkRect = check;
1032 *pixmapRect = decoration;
1033 *textRect = display;
1034 }
1035}
1036#endif // QT_CONFIG(quick_itemview)
1037
1039 const QRect &textRect, int flags) const
1040{
1041 if (option->fontMetrics.horizontalAdvance(option->text) <= textRect.width())
1042 return option->text;
1043
1044 QString text = option->text;
1045 text.replace(QLatin1Char('\n'), QChar::LineSeparator);
1046 QTextOption textOption;
1048 textOption.setTextDirection(option->direction);
1049
1050 return calculateElidedText(text, textOption,
1053 false, nullptr);
1054}
1055
1062{
1064 Q_ASSERT(iconRect);
1065 QRect tr = opt->rect;
1070 if (verticalTabs)
1071 tr.setRect(0, 0, tr.height(), tr.width()); // 0, 0 as we will have a translate transform
1072
1078 verticalShift = -verticalShift;
1079 tr.adjust(hpadding, verticalShift - vpadding, horizontalShift - hpadding, vpadding);
1080 bool selected = opt->state & QStyle::State_Selected;
1081 if (selected) {
1082 tr.setTop(tr.top() - verticalShift);
1083 tr.setRight(tr.right() - horizontalShift);
1084 }
1085
1086 // left widget
1087 if (!opt->leftButtonSize.isEmpty()) {
1088 tr.setLeft(tr.left() + 4 +
1089 (verticalTabs ? opt->leftButtonSize.height() : opt->leftButtonSize.width()));
1090 }
1091 // right widget
1092 if (!opt->rightButtonSize.isEmpty()) {
1093 tr.setRight(tr.right() - 4 -
1094 (verticalTabs ? opt->rightButtonSize.height() : opt->rightButtonSize.width()));
1095 }
1096
1097 // icon
1098 if (!opt->icon.isNull()) {
1100 if (!iconSize.isValid()) {
1102 iconSize = QSize(iconExtent, iconExtent);
1103 }
1104 QSize tabIconSize = opt->icon.actualSize(iconSize,
1107 // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize
1108 tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height()));
1109
1110 const int offsetX = (iconSize.width() - tabIconSize.width()) / 2;
1111 *iconRect = QRect(tr.left() + offsetX, tr.center().y() - tabIconSize.height() / 2,
1112 tabIconSize.width(), tabIconSize.height());
1113 if (!verticalTabs)
1114 *iconRect = QStyle::visualRect(opt->direction, opt->rect, *iconRect);
1115 tr.setLeft(tr.left() + tabIconSize.width() + 4);
1116 }
1117
1118 if (!verticalTabs)
1120
1121 *textRect = tr;
1122}
1123
1128{
1129 Q_D(const QCommonStyle);
1130
1131 // TODO: Set opt->window manually for now before calling any of the drawing functions. opt->window is
1132 // pulled of the widget is QStyle. But now that we have no widget, we need some other
1133 // solution.
1134 Q_ASSERT(opt->window);
1135
1136 switch (element) {
1137
1138 case CE_PushButton:
1139 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1144 }
1145 break;
1146 case CE_PushButtonBevel:
1147 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1148 QRect br = btn->rect;
1153 br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
1155 || btn->state & (State_Sunken | State_On)
1157 QStyleOptionButton tmpBtn = *btn;
1158 tmpBtn.rect = br;
1160 }
1163 QRect ir = btn->rect;
1164 QStyleOptionButton newBtn = *btn;
1165 newBtn.rect = QRect(ir.right() - mbi + 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
1167 }
1168 if (btn->state & State_HasFocus) {
1170 fropt.QStyleOption::operator=(*btn);
1173 }
1174 }
1175 break;
1176 case CE_PushButtonLabel:
1177 if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1182
1183 if (!button->icon.isNull()) {
1184 //Center both icon and text
1186 if (mode == QIcon::Normal && button->state & State_HasFocus)
1189 if (button->state & State_On)
1190 state = QIcon::On;
1191
1193 int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
1194 int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
1195 int labelWidth = pixmapWidth;
1196 int labelHeight = pixmapHeight;
1197 int iconSpacing = 4;//### 4 is currently hardcoded in QPushButton::sizeHint()
1198 if (!button->text.isEmpty()) {
1199 int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
1200 labelWidth += (textWidth + iconSpacing);
1201 }
1202
1203 QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
1204 textRect.y() + (textRect.height() - labelHeight) / 2,
1205 pixmapWidth, pixmapHeight);
1206
1207 iconRect = visualRect(button->direction, textRect, iconRect);
1208
1209 if (button->direction == Qt::RightToLeft) {
1210 tf |= Qt::AlignRight;
1211 textRect.setRight(iconRect.left() - iconSpacing);
1212 } else {
1213 tf |= Qt::AlignLeft; //left align, we adjust the text-rect instead
1214 textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing);
1215 }
1216
1217 if (button->state & (State_On | State_Sunken))
1218 iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt),
1220 p->drawPixmap(iconRect, pixmap);
1221 } else {
1222 tf |= Qt::AlignHCenter;
1223 }
1224 if (button->state & (State_On | State_Sunken))
1227
1228 if (button->features & QStyleOptionButton::HasMenu) {
1229 int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button);
1230 if (button->direction == Qt::LeftToRight)
1231 textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
1232 else
1233 textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
1234 }
1237 }
1238 break;
1239 case CE_RadioButton:
1240 case CE_CheckBox:
1241 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1242 bool isRadio = (element == CE_RadioButton);
1247 &subopt, p);
1251 if (btn->state & State_HasFocus) {
1253 fropt.QStyleOption::operator=(*btn);
1257 }
1258 }
1259 break;
1261 case CE_CheckBoxLabel:
1262 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1264
1267 QPixmap pix;
1269 if (!btn->icon.isNull()) {
1274 else
1276 }
1277 if (!btn->text.isEmpty()){
1280 }
1281 }
1282 break;
1283 case CE_MenuScroller: {
1284 QStyleOption arrowOpt = *opt;
1285 arrowOpt.state |= State_Enabled;
1287 break; }
1288 case CE_MenuTearoff:
1289 if (opt->state & State_Selected)
1290 p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
1291 else
1292 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
1293 p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
1294 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,
1295 opt->rect.x() + opt->rect.width() - 4,
1296 opt->rect.y() + opt->rect.height() / 2 - 1);
1297 p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
1298 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,
1299 opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);
1300 break;
1301 case CE_MenuBarItem:
1302 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1305 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi))
1307 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
1308 QPixmap pix = mbi->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
1309 mbi->state.testFlag(State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1310 if (!pix.isNull())
1311 proxy()->drawItemPixmap(p,mbi->rect, alignment, pix);
1312 else
1313 proxy()->drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
1314 mbi->text, QPalette::ButtonText);
1315 }
1316 break;
1318 break;
1319 case CE_ProgressBar:
1320 if (const QStyleOptionProgressBar *pb
1321 = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1327 if (pb->textVisible) {
1330 }
1331 }
1332 break;
1334 if (opt->rect.isValid())
1335 qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
1337 break;
1339 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1341 if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible
1342 && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) {
1343 textRole = QPalette::HighlightedText;
1344 //Draw text shadow, This will increase readability when the background of same color
1345 QRect shadowRect(pb->rect);
1346 shadowRect.translate(1,1);
1347 QColor shadowColor = (pb->palette.color(textRole).value() <= 128)
1348 ? QColor(255,255,255,160) : QColor(0,0,0,160);
1349 QPalette shadowPalette = pb->palette;
1350 shadowPalette.setColor(textRole, shadowColor);
1351 proxy()->drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette,
1352 pb->state & State_Enabled, pb->text, textRole);
1353 }
1354 proxy()->drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,
1355 pb->state & State_Enabled, pb->text, textRole);
1356 }
1357 break;
1359 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1360
1361 QRect rect = pb->rect;
1362 const bool inverted = pb->invertedAppearance;
1363 qint64 minimum = qint64(pb->minimum);
1364 qint64 maximum = qint64(pb->maximum);
1365 qint64 progress = qint64(pb->progress);
1366
1367 QPalette pal2 = pb->palette;
1368 // Correct the highlight color if it is the same as the background
1369 if (pal2.highlight() == pal2.window())
1370 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1372 bool reverse = pb->direction == Qt::RightToLeft;
1373 if (inverted)
1374 reverse = !reverse;
1375 int w = rect.width();
1376 if (pb->minimum == 0 && pb->maximum == 0) {
1377 // draw busy indicator
1378 int x = (progress - minimum) % (w * 2);
1379 if (x > w)
1380 x = 2 * w - x;
1381 x = reverse ? rect.right() - x : x + rect.x();
1382 p->setPen(QPen(pal2.highlight().color(), 4));
1383 p->drawLine(x, rect.y(), x, rect.height());
1384 } else {
1385 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb);
1386 if (!unit_width)
1387 return;
1388
1389 int u;
1390 if (unit_width > 1)
1391 u = ((rect.width() + unit_width) / unit_width);
1392 else
1393 u = w / unit_width;
1394 qint64 p_v = progress - minimum;
1395 qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1);
1396
1397 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1398 // scale down to something usable.
1399 p_v /= u;
1400 t_s /= u;
1401 }
1402
1403 // nu < tnu, if last chunk is only a partial chunk
1404 int tnu, nu;
1405 tnu = nu = p_v * u / t_s;
1406
1407 if (nu * unit_width > w)
1408 --nu;
1409
1410 // Draw nu units out of a possible u of unit_width
1411 // width, each a rectangle bordered by background
1412 // color, all in a sunken panel with a percentage text
1413 // display at the end.
1414 int x = 0;
1415 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0)
1416 : rect.x();
1417
1418 QStyleOptionProgressBar pbBits = *pb;
1419 pbBits.rect = rect;
1420 pbBits.palette = pal2;
1421 int myY = pbBits.rect.y();
1422 int myHeight = pbBits.rect.height();
1423 pbBits.state = State_Horizontal;
1424 for (int i = 0; i < nu; ++i) {
1425 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1427 x += reverse ? -unit_width : unit_width;
1428 }
1429
1430 // Draw the last partial chunk to fill up the
1431 // progress bar entirely
1432 if (nu < tnu) {
1433 int pixels_left = w - (nu * unit_width);
1434 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1435 pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
1437 }
1438 }
1439 }
1440 break;
1441 case CE_HeaderLabel:
1442 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
1443 QRect rect = header->rect;
1444 if (!header->icon.isNull()) {
1445 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
1447 = header->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
1448 header->state.testFlag(State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1449 int pixw = pixmap.width() / pixmap.devicePixelRatio();
1450
1451 QRect aligned = alignedRect(header->direction, QFlag(header->iconAlignment), pixmap.size() / pixmap.devicePixelRatio(), rect);
1452 QRect inter = aligned.intersected(rect);
1453 p->drawPixmap(inter.x(), inter.y(), pixmap,
1454 inter.x() - aligned.x(), inter.y() - aligned.y(),
1455 aligned.width() * pixmap.devicePixelRatio(),
1456 pixmap.height() * pixmap.devicePixelRatio());
1457
1458 const int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt);
1459 if (header->direction == Qt::LeftToRight)
1460 rect.setLeft(rect.left() + pixw + margin);
1461 else
1462 rect.setRight(rect.right() - pixw - margin);
1463 }
1464 if (header->state & QStyle::State_On) {
1465 QFont fnt = p->font();
1466 fnt.setBold(true);
1467 p->setFont(fnt);
1468 }
1469 proxy()->drawItemText(p, rect, header->textAlignment, header->palette,
1470 (header->state & State_Enabled), header->text, QPalette::ButtonText);
1471 }
1472 break;
1473 case CE_ToolButtonLabel:
1474 if (const QStyleOptionToolButton *toolbutton
1475 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
1476 QRect rect = toolbutton->rect;
1477 int shiftX = 0;
1478 int shiftY = 0;
1479 if (toolbutton->state & (State_Sunken | State_On)) {
1480 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton);
1481 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton);
1482 }
1483 // Arrow type always overrules and is always shown
1484 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
1485 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
1486 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
1490 rect.translate(shiftX, shiftY);
1491 p->setFont(toolbutton->font);
1492 proxy()->drawItemText(p, rect, alignment, toolbutton->palette,
1493 opt->state & State_Enabled, toolbutton->text,
1495 } else {
1496 QPixmap pm;
1497 QSize pmSize = toolbutton->iconSize;
1498 if (!toolbutton->icon.isNull()) {
1499 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
1501 if (!(toolbutton->state & State_Enabled))
1503 else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
1505 else
1507 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize),
1508 dpr(opt->window), mode, state);
1509 pmSize = pm.size() / pm.devicePixelRatio();
1510 }
1511
1512 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
1513 p->setFont(toolbutton->font);
1514 QRect pr = rect,
1515 tr = rect;
1519
1520 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
1521 pr.setHeight(pmSize.height() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
1522 tr.adjust(0, pr.height() - 1, 0, -1);
1523 pr.translate(shiftX, shiftY);
1524 if (!hasArrow) {
1526 } else {
1527 drawArrow(proxy(), toolbutton, pr, p);
1528 }
1530 } else {
1531 pr.setWidth(pmSize.width() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
1532 tr.adjust(pr.width(), 0, 0, 0);
1533 pr.translate(shiftX, shiftY);
1534 if (!hasArrow) {
1536 } else {
1537 drawArrow(proxy(), toolbutton, pr, p);
1538 }
1540 }
1541 tr.translate(shiftX, shiftY);
1542 const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
1543 proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
1544 toolbutton->state & State_Enabled, text,
1546 } else {
1547 rect.translate(shiftX, shiftY);
1548 if (hasArrow) {
1549 drawArrow(proxy(), toolbutton, rect, p);
1550 } else {
1552 }
1553 }
1554 }
1555 }
1556 break;
1557 case CE_ToolBoxTab:
1558 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
1561 }
1562 break;
1563 case CE_ToolBoxTabShape:
1564 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
1565 p->setPen(tb->palette.mid().color().darker(150));
1566 int d = 20 + tb->rect.height() - 3;
1567 if (tb->direction != Qt::RightToLeft) {
1568 const QPoint points[] = {
1569 QPoint(-1, tb->rect.height() + 1),
1570 QPoint(-1, 1),
1571 QPoint(tb->rect.width() - d, 1),
1572 QPoint(tb->rect.width() - 20, tb->rect.height() - 2),
1573 QPoint(tb->rect.width() - 1, tb->rect.height() - 2),
1574 QPoint(tb->rect.width() - 1, tb->rect.height() + 1),
1575 QPoint(-1, tb->rect.height() + 1),
1576 };
1577 p->drawPolygon(points, sizeof points / sizeof *points);
1578 } else {
1579 const QPoint points[] = {
1580 QPoint(tb->rect.width(), tb->rect.height() + 1),
1581 QPoint(tb->rect.width(), 1),
1582 QPoint(d - 1, 1),
1583 QPoint(20 - 1, tb->rect.height() - 2),
1584 QPoint(0, tb->rect.height() - 2),
1585 QPoint(0, tb->rect.height() + 1),
1586 QPoint(tb->rect.width(), tb->rect.height() + 1),
1587 };
1588 p->drawPolygon(points, sizeof points / sizeof *points);
1589 }
1590 p->setPen(tb->palette.light().color());
1591 if (tb->direction != Qt::RightToLeft) {
1592 p->drawLine(0, 2, tb->rect.width() - d, 2);
1593 p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);
1594 p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,
1595 tb->rect.width(), tb->rect.height() - 1);
1596 } else {
1597 p->drawLine(tb->rect.width() - 1, 2, d - 1, 2);
1598 p->drawLine(d, 2, 20, tb->rect.height() - 1);
1599 p->drawLine(19, tb->rect.height() - 1,
1600 -1, tb->rect.height() - 1);
1601 }
1602 p->setBrush(Qt::NoBrush);
1603 }
1604 break;
1605 case CE_TabBarTab:
1606 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1609 }
1610 break;
1611 case CE_TabBarTabShape:
1612 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1613 p->save();
1614
1615 QRect rect(tab->rect);
1616 bool selected = tab->state & State_Selected;
1617 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1618 int tabOverlap = onlyOne ? 0 : proxy()->pixelMetric(PM_TabBarTabOverlap, opt);
1619
1620 if (!selected) {
1621 switch (tab->shape) {
1623 rect.adjust(0, 0, 0, -tabOverlap);
1624 if(!selected)
1625 rect.adjust(1, 1, -1, 0);
1626 break;
1628 rect.adjust(0, tabOverlap, 0, 0);
1629 if(!selected)
1630 rect.adjust(1, 0, -1, -1);
1631 break;
1633 rect.adjust(tabOverlap, 0, 0, 0);
1634 if(!selected)
1635 rect.adjust(0, 1, -1, -1);
1636 break;
1638 rect.adjust(0, 0, -tabOverlap, 0);
1639 if(!selected)
1640 rect.adjust(1, 1, 0, -1);
1641 break;
1642 default:
1643 break;
1644 }
1645 }
1646
1647 p->setPen(QPen(tab->palette.windowText(), 0));
1648 if (selected) {
1649 p->setBrush(tab->palette.base());
1650 } else {
1651 p->setBrush(tab->palette.window());
1652 }
1653
1654 int y;
1655 int x;
1656 QPolygon a(10);
1657 switch (tab->shape) {
1660 a.setPoint(0, 0, -1);
1661 a.setPoint(1, 0, 0);
1662 y = rect.height() - 2;
1663 x = y / 3;
1664 a.setPoint(2, x++, y - 1);
1665 ++x;
1666 a.setPoint(3, x++, y++);
1667 a.setPoint(4, x, y);
1668
1669 int i;
1670 int right = rect.width() - 1;
1671 for (i = 0; i < 5; ++i)
1672 a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());
1673 if (tab->shape == QStyleOptionTab::TriangularNorth)
1674 for (i = 0; i < 10; ++i)
1675 a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y());
1676
1677 a.translate(rect.left(), rect.top());
1678 p->setRenderHint(QPainter::Antialiasing);
1679 p->translate(0, 0.5);
1680
1682 path.addPolygon(a);
1683 p->drawPath(path);
1684 break; }
1687 a.setPoint(0, -1, 0);
1688 a.setPoint(1, 0, 0);
1689 x = rect.width() - 2;
1690 y = x / 3;
1691 a.setPoint(2, x - 1, y++);
1692 ++y;
1693 a.setPoint(3, x++, y++);
1694 a.setPoint(4, x, y);
1695 int i;
1696 int bottom = rect.height() - 1;
1697 for (i = 0; i < 5; ++i)
1698 a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());
1699 if (tab->shape == QStyleOptionTab::TriangularWest)
1700 for (i = 0; i < 10; ++i)
1701 a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y());
1702 a.translate(rect.left(), rect.top());
1703 p->setRenderHint(QPainter::Antialiasing);
1704 p->translate(0.5, 0);
1706 path.addPolygon(a);
1707 p->drawPath(path);
1708 break; }
1709 default:
1710 break;
1711 }
1712 p->restore();
1713 }
1714 break;
1715 case CE_ToolBoxTabLabel:
1716 if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
1717 bool enabled = tb->state & State_Enabled;
1718 bool selected = tb->state & State_Selected;
1719 int iconExtent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb);
1720 QPixmap pm = tb->icon.pixmap(QSize(iconExtent, iconExtent), dpr(opt->window),
1722
1724 QRect tr, ir;
1725 int ih = 0;
1726 if (pm.isNull()) {
1727 tr = cr;
1728 tr.adjust(4, 0, -8, 0);
1729 } else {
1730 int iw = pm.width() / pm.devicePixelRatio() + 4;
1731 ih = pm.height()/ pm.devicePixelRatio();
1732 ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
1733 tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
1734 }
1735
1737 QFont f(p->font());
1738 f.setBold(true);
1739 p->setFont(f);
1740 }
1741
1742 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());
1743
1744 if (ih)
1745 p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);
1746
1751
1752 if (!txt.isEmpty() && opt->state & State_HasFocus) {
1754 opt.rect = tr;
1755 opt.palette = tb->palette;
1758 }
1759 }
1760 break;
1761 case CE_TabBarTabLabel:
1762 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1763 QRect tr = tab->rect;
1764 bool verticalTabs = tab->shape == QStyleOptionTab::RoundedEast
1765 || tab->shape == QStyleOptionTab::RoundedWest
1766 || tab->shape == QStyleOptionTab::TriangularEast
1767 || tab->shape == QStyleOptionTab::TriangularWest;
1768
1772
1773 if (verticalTabs) {
1774 p->save();
1775 int newX, newY, newRot;
1776 if (tab->shape == QStyleOptionTab::RoundedEast || tab->shape == QStyleOptionTab::TriangularEast) {
1777 newX = tr.width() + tr.x();
1778 newY = tr.y();
1779 newRot = 90;
1780 } else {
1781 newX = tr.x();
1782 newY = tr.y() + tr.height();
1783 newRot = -90;
1784 }
1786 m.rotate(newRot);
1787 p->setTransform(m, true);
1788 }
1789 QRect iconRect;
1790 d->tabLayout(tab, &tr, &iconRect);
1791 tr = proxy()->subElementRect(SE_TabBarTabText, opt); //we compute tr twice because the style may override subElementRect
1792
1793 if (!tab->icon.isNull()) {
1794 QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, dpr(opt->window),
1795 (tab->state & State_Enabled) ? QIcon::Normal
1797 (tab->state & State_Selected) ? QIcon::On
1798 : QIcon::Off);
1799 p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
1800 }
1801
1802 proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText);
1803 if (verticalTabs)
1804 p->restore();
1805
1806 if (tab->state & State_HasFocus) {
1807 const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth);
1808
1809 int x1, x2;
1810 x1 = tab->rect.left();
1811 x2 = tab->rect.right() - 1;
1812
1814 fropt.QStyleOption::operator=(*tab);
1815 fropt.rect.setRect(x1 + 1 + OFFSET, tab->rect.y() + OFFSET,
1816 x2 - x1 - 2*OFFSET, tab->rect.height() - 2*OFFSET);
1818 }
1819 }
1820 break;
1821 case CE_SizeGrip: {
1822 p->save();
1823 int x, y, w, h;
1824 opt->rect.getRect(&x, &y, &w, &h);
1825
1826 int sw = qMin(h, w);
1827 if (h > w)
1828 p->translate(0, h - w);
1829 else
1830 p->translate(w - h, 0);
1831
1832 int sx = x;
1833 int sy = y;
1834 int s = sw / 3;
1835
1836 Qt::Corner corner;
1837 if (const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<const QStyleOptionSizeGrip *>(opt))
1838 corner = sgOpt->corner;
1839 else if (opt->direction == Qt::RightToLeft)
1840 corner = Qt::BottomLeftCorner;
1841 else
1842 corner = Qt::BottomRightCorner;
1843
1844 if (corner == Qt::BottomLeftCorner) {
1845 sx = x + sw;
1846 for (int i = 0; i < 4; ++i) {
1847 p->setPen(QPen(opt->palette.light().color(), 1));
1848 p->drawLine(x, sy - 1 , sx + 1, sw);
1849 p->setPen(QPen(opt->palette.dark().color(), 1));
1850 p->drawLine(x, sy, sx, sw);
1851 p->setPen(QPen(opt->palette.dark().color(), 1));
1852 p->drawLine(x, sy + 1, sx - 1, sw);
1853 sx -= s;
1854 sy += s;
1855 }
1856 } else if (corner == Qt::BottomRightCorner) {
1857 for (int i = 0; i < 4; ++i) {
1858 p->setPen(QPen(opt->palette.light().color(), 1));
1859 p->drawLine(sx - 1, sw, sw, sy - 1);
1860 p->setPen(QPen(opt->palette.dark().color(), 1));
1861 p->drawLine(sx, sw, sw, sy);
1862 p->setPen(QPen(opt->palette.dark().color(), 1));
1863 p->drawLine(sx + 1, sw, sw, sy + 1);
1864 sx += s;
1865 sy += s;
1866 }
1867 } else if (corner == Qt::TopRightCorner) {
1868 sy = y + sw;
1869 for (int i = 0; i < 4; ++i) {
1870 p->setPen(QPen(opt->palette.light().color(), 1));
1871 p->drawLine(sx - 1, y, sw, sy + 1);
1872 p->setPen(QPen(opt->palette.dark().color(), 1));
1873 p->drawLine(sx, y, sw, sy);
1874 p->setPen(QPen(opt->palette.dark().color(), 1));
1875 p->drawLine(sx + 1, y, sw, sy - 1);
1876 sx += s;
1877 sy -= s;
1878 }
1879 } else if (corner == Qt::TopLeftCorner) {
1880 for (int i = 0; i < 4; ++i) {
1881 p->setPen(QPen(opt->palette.light().color(), 1));
1882 p->drawLine(x, sy - 1, sx - 1, y);
1883 p->setPen(QPen(opt->palette.dark().color(), 1));
1884 p->drawLine(x, sy, sx, y);
1885 p->setPen(QPen(opt->palette.dark().color(), 1));
1886 p->drawLine(x, sy + 1, sx + 1, y);
1887 sx += s;
1888 sy += s;
1889 }
1890 }
1891 p->restore();
1892 break; }
1893 case CE_RubberBand: {
1894 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
1895 QPixmap tiledPixmap(16, 16);
1896 QPainter pixmapPainter(&tiledPixmap);
1897 pixmapPainter.setPen(Qt::NoPen);
1898 pixmapPainter.setBrush(Qt::Dense4Pattern);
1899 pixmapPainter.setBackground(QBrush(opt->palette.base()));
1900 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1901 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1902 pixmapPainter.end();
1903 // ### workaround for borked XRENDER
1904 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1905
1906 p->save();
1907 QRect r = opt->rect;
1910 p->setClipRegion(mask.region);
1911 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1913 p->setBrush(Qt::NoBrush);
1914 p->drawRect(r.adjusted(0, 0, -1, -1));
1915 if (rbOpt->shape == QStyleOptionRubberBand::Rectangle)
1916 p->drawRect(r.adjusted(3, 3, -4, -4));
1917 p->restore();
1918 }
1919 break; }
1920 case CE_DockWidgetTitle:
1921 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
1922 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
1923 if (dwOpt->movable) {
1924 p->setPen(dwOpt->palette.color(QPalette::Dark));
1925 p->drawRect(r);
1926 }
1927
1928 if (!dwOpt->title.isEmpty()) {
1929 const bool verticalTitleBar = dwOpt->verticalTitleBar;
1930
1931 if (verticalTitleBar) {
1932 r = r.transposed();
1933
1934 p->save();
1935 p->translate(r.left(), r.top() + r.width());
1936 p->rotate(-90);
1937 p->translate(-r.left(), -r.top());
1938 }
1939
1940 const int indent = p->fontMetrics().descent();
1941 proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
1942 Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
1943 dwOpt->state & State_Enabled, dwOpt->title,
1945
1946 if (verticalTitleBar)
1947 p->restore();
1948 }
1949 }
1950 break;
1951 case CE_Header:
1952 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
1953 QRegion clipRegion = p->clipRegion();
1954 p->setClipRect(opt->rect);
1958 if (subopt.rect.isValid())
1960 if (header->sortIndicator != QStyleOptionHeader::None) {
1963 }
1964 p->setClipRegion(clipRegion);
1965 }
1966 break;
1967 case CE_FocusFrame:
1968 p->fillRect(opt->rect, opt->palette.windowText());
1969 break;
1970 case CE_HeaderSection:
1972 opt->state & State_Sunken, 1,
1974 break;
1975 case CE_HeaderEmptyArea:
1976 p->fillRect(opt->rect, opt->palette.window());
1977 break;
1978 case CE_ComboBoxLabel:
1979 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1981 p->save();
1982 p->setClipRect(editRect);
1983 if (!cb->currentIcon.isNull()) {
1986 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, dpr(opt->window), mode);
1987 QRect iconRect(editRect);
1988 iconRect.setWidth(cb->iconSize.width() + 4);
1989 iconRect = alignedRect(cb->direction,
1991 iconRect.size(), editRect);
1992 if (cb->editable)
1993 p->fillRect(iconRect, opt->palette.brush(QPalette::Base));
1995
1996 if (cb->direction == Qt::RightToLeft)
1997 editRect.translate(-4 - cb->iconSize.width(), 0);
1998 else
1999 editRect.translate(cb->iconSize.width() + 4, 0);
2000 }
2001 if (!cb->currentText.isEmpty() && !cb->editable) {
2002 proxy()->drawItemText(p, editRect.adjusted(1, 0, -1, 0),
2004 cb->palette, cb->state & State_Enabled, cb->currentText);
2005 }
2006 p->restore();
2007 }
2008 break;
2009 case CE_ToolBar:
2010 if (const QStyleOptionToolBar *toolBar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
2011 // Compatibility with styles that use PE_PanelToolBar
2013 frame.QStyleOption::operator=(*toolBar);
2014 frame.lineWidth = toolBar->lineWidth;
2015 frame.midLineWidth = toolBar->midLineWidth;
2017
2018 qDrawShadePanel(p, toolBar->rect, toolBar->palette, false, toolBar->lineWidth,
2019 &toolBar->palette.brush(QPalette::Button));
2020 }
2021 break;
2022 case CE_ColumnViewGrip: {
2023 // draw background gradients
2024 QLinearGradient g(0, 0, opt->rect.width(), 0);
2025 g.setColorAt(0, opt->palette.color(QPalette::Active, QPalette::Mid));
2026 g.setColorAt(0.5, Qt::white);
2027 p->fillRect(QRect(0, 0, opt->rect.width(), opt->rect.height()), g);
2028
2029 // draw the two lines
2030 QPen pen(p->pen());
2031 pen.setWidth(opt->rect.width()/20);
2033 p->setPen(pen);
2034
2035 int line1starting = opt->rect.width()*8 / 20;
2036 int line2starting = opt->rect.width()*13 / 20;
2037 int top = opt->rect.height()*20/75;
2038 int bottom = opt->rect.height() - 1 - top;
2039 p->drawLine(line1starting, top, line1starting, bottom);
2040 p->drawLine(line2starting, top, line2starting, bottom);
2041 }
2042 break;
2043#if QT_CONFIG(quick_itemview)
2044 case CE_ItemViewItem:
2045 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
2046 p->save();
2047 p->setClipRect(opt->rect);
2048
2052
2053 // draw the background
2055
2056 // draw the check mark
2057 if (vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
2058 QStyleOptionViewItem option(*vopt);
2059 option.rect = checkRect;
2060 option.state = option.state & ~QStyle::State_HasFocus;
2061
2062 switch (vopt->checkState) {
2063 case Qt::Unchecked:
2064 option.state |= QStyle::State_Off;
2065 break;
2068 break;
2069 case Qt::Checked:
2070 option.state |= QStyle::State_On;
2071 break;
2072 }
2074 }
2075
2076 // draw the icon
2078 if (!(vopt->state & QStyle::State_Enabled))
2080 else if (vopt->state & QStyle::State_Selected)
2083 vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state);
2084
2085 // draw the text
2086 if (!vopt->text.isEmpty()) {
2089 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2090 cg = QPalette::Inactive;
2091
2092 if (vopt->state & QStyle::State_Selected) {
2093 p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
2094 } else {
2095 p->setPen(vopt->palette.color(cg, QPalette::Text));
2096 }
2097 if (vopt->state & QStyle::State_Editing) {
2098 p->setPen(vopt->palette.color(cg, QPalette::Text));
2099 p->drawRect(textRect.adjusted(0, 0, -1, -1));
2100 }
2101
2102 d->viewItemDrawText(p, vopt, textRect);
2103 }
2104
2105 // draw the focus rect
2106 if (vopt->state & QStyle::State_HasFocus) {
2108 o.QStyleOption::operator=(*vopt);
2111 o.state |= QStyle::State_Item;
2112 QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled)
2114 o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected)
2117 }
2118
2119 p->restore();
2120 }
2121 break;
2122#endif // QT_CONFIG(quick_itemview)
2123 case CE_ShapedFrame:
2124 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2125 int frameShape = f->frameShape;
2126 int frameShadow = QStyleOptionFrame::Plain;
2127 if (f->state & QStyle::State_Sunken) {
2128 frameShadow = QStyleOptionFrame::Sunken;
2129 } else if (f->state & QStyle::State_Raised) {
2130 frameShadow = QStyleOptionFrame::Raised;
2131 }
2132
2133 int lw = f->lineWidth;
2134 int mlw = f->midLineWidth;
2136
2137 switch (frameShape) {
2139 if (frameShadow == QStyleOptionFrame::Plain) {
2140 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2141 } else {
2142 qDrawShadeRect(p, f->rect, f->palette, frameShadow == QStyleOptionFrame::Sunken, lw, mlw);
2143 }
2144 break;
2147 break;
2149 if (frameShadow == QStyleOptionFrame::Plain) {
2150 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2151 } else {
2152 qDrawShadePanel(p, f->rect, f->palette, frameShadow == QStyleOptionFrame::Sunken, lw);
2153 }
2154 break;
2156 if (frameShadow == QStyleOptionFrame::Plain) {
2157 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2158 } else {
2159 qDrawWinPanel(p, f->rect, f->palette, frameShadow == QStyleOptionFrame::Sunken);
2160 }
2161 break;
2164 QPoint p1, p2;
2165 if (frameShape == QStyleOptionFrame::HLine) {
2166 p1 = QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height() / 2);
2167 p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y());
2168 } else {
2169 p1 = QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
2170 p2 = QPoint(p1.x(), p1.y() + opt->rect.height());
2171 }
2172 if (frameShadow == QStyleOptionFrame::Plain) {
2173 QPen oldPen = p->pen();
2174 p->setPen(QPen(opt->palette.brush(foregroundRole), lw));
2175 p->drawLine(p1, p2);
2176 p->setPen(oldPen);
2177 } else {
2178 qDrawShadeLine(p, p1, p2, f->palette, frameShadow == QStyleOptionFrame::Sunken, lw, mlw);
2179 }
2180 break;
2181 }
2182 }
2183 }
2184 break;
2185 default:
2186 break;
2187 }
2188}
2189
2191{
2192 Q_D(const QCommonStyle);
2193 QRect r;
2194 switch (sr) {
2196 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2197 int dx1, dx2;
2201 dx2 = dx1 * 2;
2202 r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2,
2203 opt->rect.height() - dx2);
2205 }
2206 break;
2208 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2209 int dbw1 = 0, dbw2 = 0;
2212 dbw2 = dbw1 * 2;
2213 }
2214
2215 int dfw1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn) + 1,
2216 dfw2 = dfw1 * 2;
2217
2218 r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1,
2219 btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2);
2221 }
2222 break;
2224 {
2226 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2229 }
2230 break;
2231
2233 {
2234 // Deal with the logical first, then convert it back to screen coords.
2238 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2239 opt->rect.height());
2241 }
2242 break;
2243
2245 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2246 if (btn->icon.isNull() && btn->text.isEmpty()) {
2248 r.adjust(1, 1, -1, -1);
2249 break;
2250 }
2251 // As above, deal with the logical first, then convert it back to screen coords.
2253
2254 QRect iconRect, textRect;
2255 if (!btn->text.isEmpty()) {
2259 }
2260 if (!btn->icon.isNull()) {
2263 btn->icon.pixmap(btn->iconSize, dpr(opt->window), QIcon::Normal));
2264 if (!textRect.isEmpty())
2265 textRect.translate(iconRect.right() + 4, 0);
2266 }
2267 r = iconRect | textRect;
2268 r.adjust(-3, -2, 3, 2);
2269 r = r.intersected(btn->rect);
2271 }
2272 break;
2273
2275 {
2277 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2280 }
2281 break;
2282
2284 {
2288 r.setRect(ir.left() + ir.width() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2289 opt->rect.height());
2291 break;
2292 }
2293
2295 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2296 if (btn->icon.isNull() && btn->text.isEmpty()) {
2298 r.adjust(1, 1, -1, -1);
2299 break;
2300 }
2302
2303 QRect iconRect, textRect;
2304 if (!btn->text.isEmpty()){
2307 }
2308 if (!btn->icon.isNull()) {
2310 btn->icon.pixmap(btn->iconSize, dpr(opt->window), QIcon::Normal));
2311 if (!textRect.isEmpty())
2312 textRect.translate(iconRect.right() + 4, 0);
2313 }
2314 r = iconRect | textRect;
2315 r.adjust(-3, -2, 3, 2);
2316 r = r.intersected(btn->rect);
2318 }
2319 break;
2320 case SE_SliderFocusRect:
2321 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2322 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider);
2323 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider);
2324 if (slider->orientation == Qt::Horizontal)
2325 r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2);
2326 else
2327 r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height());
2328 r = r.intersected(slider->rect);
2330 }
2331 break;
2335 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
2336 int textw = 0;
2337 if (pb->textVisible)
2338 textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(QLatin1String("100%"))) + 6;
2339
2340 if ((pb->textAlignment & Qt::AlignCenter) == 0) {
2341 if (sr != SE_ProgressBarLabel)
2342 r.setCoords(pb->rect.left(), pb->rect.top(),
2343 pb->rect.right() - textw, pb->rect.bottom());
2344 else
2345 r.setCoords(pb->rect.right() - textw, pb->rect.top(),
2346 pb->rect.right(), pb->rect.bottom());
2347 } else {
2348 r = pb->rect;
2349 }
2350 r = visualRect(pb->direction, pb->rect, r);
2351 }
2352 break;
2354 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2355 int margin = cb->frame ? 3 : 0;
2356 r.setRect(opt->rect.left() + margin, opt->rect.top() + margin,
2357 opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin);
2359 }
2360 break;
2362 r = opt->rect;
2363 r.adjust(0, 0, -30, 0);
2364 break;
2365 case SE_HeaderLabel: {
2366 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt);
2367 r.setRect(opt->rect.x() + margin, opt->rect.y() + margin,
2368 opt->rect.width() - margin * 2, opt->rect.height() - margin * 2);
2369
2370 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
2371 // Subtract width needed for arrow, if there is one
2372 if (header->sortIndicator != QStyleOptionHeader::None) {
2373 if (opt->state & State_Horizontal)
2374 r.setWidth(r.width() - (opt->rect.height() / 2) - (margin * 2));
2375 else
2376 r.setHeight(r.height() - (opt->rect.width() / 2) - (margin * 2));
2377 }
2378 }
2380 break; }
2381 case SE_HeaderArrow: {
2382 int h = opt->rect.height();
2383 int w = opt->rect.width();
2384 int x = opt->rect.x();
2385 int y = opt->rect.y();
2386 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt);
2387
2388 if (opt->state & State_Horizontal) {
2389 int horiz_size = h / 2;
2390 r.setRect(x + w - margin * 2 - horiz_size, y + 5,
2391 horiz_size, h - margin * 2 - 5);
2392 } else {
2393 int vert_size = w / 2;
2394 r.setRect(x + 5, y + h - margin * 2 - vert_size,
2395 w - margin * 2 - 5, vert_size);
2396 }
2398 break; }
2399
2403 break;
2407 break;
2408 case SE_TabWidgetTabBar:
2409 if (const QStyleOptionTabWidgetFrame *twf
2410 = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
2411 r.setSize(twf->tabBarSize);
2412 const uint alingMask = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter;
2413 switch (twf->shape) {
2416 // Constrain the size now, otherwise, center could get off the page
2417 // This of course repeated for all the other directions
2418 r.setWidth(qMin(r.width(), twf->rect.width()
2419 - twf->leftCornerWidgetSize.width()
2420 - twf->rightCornerWidgetSize.width()));
2421 switch (proxy()->styleHint(SH_TabBar_Alignment, twf) & alingMask) {
2422 default:
2423 case Qt::AlignLeft:
2424 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
2425 break;
2426 case Qt::AlignHCenter:
2427 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2428 + (twf->leftCornerWidgetSize.width() / 2)
2429 - (twf->rightCornerWidgetSize.width() / 2), 0));
2430 break;
2431 case Qt::AlignRight:
2432 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2433 - twf->rightCornerWidgetSize.width(), 0));
2434 break;
2435 }
2436 r = visualRect(twf->direction, twf->rect, r);
2437 break;
2440 r.setWidth(qMin(r.width(), twf->rect.width()
2441 - twf->leftCornerWidgetSize.width()
2442 - twf->rightCornerWidgetSize.width()));
2443 switch (proxy()->styleHint(SH_TabBar_Alignment, twf) & alingMask) {
2444 default:
2445 case Qt::AlignLeft:
2446 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
2447 twf->rect.height() - twf->tabBarSize.height()));
2448 break;
2449 case Qt::AlignHCenter:
2450 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2451 + (twf->leftCornerWidgetSize.width() / 2)
2452 - (twf->rightCornerWidgetSize.width() / 2),
2453 twf->rect.height() - twf->tabBarSize.height()));
2454 break;
2455 case Qt::AlignRight:
2456 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2457 - twf->rightCornerWidgetSize.width(),
2458 twf->rect.height() - twf->tabBarSize.height()));
2459 break;
2460 }
2461 r = visualRect(twf->direction, twf->rect, r);
2462 break;
2465 r.setHeight(qMin(r.height(), twf->rect.height()
2466 - twf->leftCornerWidgetSize.height()
2467 - twf->rightCornerWidgetSize.height()));
2468 switch (proxy()->styleHint(SH_TabBar_Alignment, twf) & alingMask) {
2469 default:
2470 case Qt::AlignLeft:
2471 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2472 twf->leftCornerWidgetSize.height()));
2473 break;
2474 case Qt::AlignHCenter:
2475 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2476 twf->rect.center().y() - r.height() / 2));
2477 break;
2478 case Qt::AlignRight:
2479 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2480 twf->rect.height() - twf->tabBarSize.height()
2481 - twf->rightCornerWidgetSize.height()));
2482 break;
2483 }
2484 break;
2487 r.setHeight(qMin(r.height(), twf->rect.height()
2488 - twf->leftCornerWidgetSize.height()
2489 - twf->rightCornerWidgetSize.height()));
2490 switch (proxy()->styleHint(SH_TabBar_Alignment, twf) & alingMask) {
2491 default:
2492 case Qt::AlignLeft:
2493 r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
2494 break;
2495 case Qt::AlignHCenter:
2496 r.moveTopLeft(QPoint(0, twf->rect.center().y() - r.height() / 2));
2497 break;
2498 case Qt::AlignRight:
2499 r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
2500 - twf->rightCornerWidgetSize.height()));
2501 break;
2502 }
2503 break;
2504 }
2505 }
2506 break;
2509 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
2510 QStyleOptionTab tabopt;
2511 tabopt.shape = twf->shape;
2512 int overlap = proxy()->pixelMetric(PM_TabBarBaseOverlap, &tabopt);
2513 if (twf->lineWidth == 0)
2514 overlap = 0;
2515 switch (twf->shape) {
2518 r = QRect(QPoint(0,qMax(twf->tabBarSize.height() - overlap, 0)),
2519 QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2520 break;
2523 r = QRect(QPoint(0,0), QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2524 break;
2527 r = QRect(QPoint(0, 0), QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2528 break;
2531 r = QRect(QPoint(qMax(twf->tabBarSize.width() - overlap, 0), 0),
2532 QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2533 break;
2534 }
2535 if (sr == SE_TabWidgetTabContents && twf->lineWidth > 0)
2536 r.adjust(2, 2, -2, -2);
2537 }
2538 break;
2540 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
2541 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf);
2542 switch (twf->shape) {
2545 r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()),
2546 twf->leftCornerWidgetSize);
2547 break;
2550 r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
2551 break;
2552 default:
2553 break;
2554 }
2555 r = visualRect(twf->direction, twf->rect, r);
2556 }
2557 break;
2559 if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
2560 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf);
2561 switch (twf->shape) {
2564 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2565 paneRect.y() - twf->rightCornerWidgetSize.height()),
2566 twf->rightCornerWidgetSize);
2567 break;
2570 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2571 paneRect.height()), twf->rightCornerWidgetSize);
2572 break;
2573 default:
2574 break;
2575 }
2576 r = visualRect(twf->direction, twf->rect, r);
2577 }
2578 break;
2579 case SE_TabBarTabText:
2580 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
2581 QRect dummyIconRect;
2582 d->tabLayout(tab, &r, &dummyIconRect);
2583 }
2584 break;
2587 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
2588 bool selected = tab->state & State_Selected;
2589 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab);
2590 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab);
2591 int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt) / 2;
2592 hpadding = qMax(hpadding, 4); //workaround KStyle returning 0 because they workaround an old bug in Qt
2593
2594 bool verticalTabs = tab->shape == QStyleOptionTab::RoundedEast
2595 || tab->shape == QStyleOptionTab::RoundedWest
2596 || tab->shape == QStyleOptionTab::TriangularEast
2597 || tab->shape == QStyleOptionTab::TriangularWest;
2598
2599 QRect tr = tab->rect;
2600 if (tab->shape == QStyleOptionTab::RoundedSouth || tab->shape == QStyleOptionTab::TriangularSouth)
2601 verticalShift = -verticalShift;
2602 if (verticalTabs) {
2603 qSwap(horizontalShift, verticalShift);
2604 horizontalShift *= -1;
2605 verticalShift *= -1;
2606 }
2607 if (tab->shape == QStyleOptionTab::RoundedWest || tab->shape == QStyleOptionTab::TriangularWest)
2608 horizontalShift = -horizontalShift;
2609
2610 tr.adjust(0, 0, horizontalShift, verticalShift);
2611 if (selected)
2612 {
2613 tr.setBottom(tr.bottom() - verticalShift);
2614 tr.setRight(tr.right() - horizontalShift);
2615 }
2616
2617 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
2618 int w = size.width();
2619 int h = size.height();
2620 int midHeight = static_cast<int>(qCeil(float(tr.height() - h) / 2));
2621 int midWidth = ((tr.width() - w) / 2);
2622
2623 bool atTheTop = true;
2624 switch (tab->shape) {
2627 atTheTop = (sr == SE_TabBarTabLeftButton);
2628 break;
2631 atTheTop = (sr == SE_TabBarTabRightButton);
2632 break;
2633 default:
2634 if (sr == SE_TabBarTabLeftButton)
2635 r = QRect(tab->rect.x() + hpadding, midHeight, w, h);
2636 else
2637 r = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
2638 r = visualRect(tab->direction, tab->rect, r);
2639 }
2640 if (verticalTabs) {
2641 if (atTheTop)
2642 r = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
2643 else
2644 r = QRect(midWidth, tr.y() + hpadding, w, h);
2645 }
2646 }
2647
2648 break;
2650 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
2651 switch (tab->shape) {
2656 r.setRect(tab->rect.left(), tab->rect.top(), 8, opt->rect.height());
2657 break;
2662 r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 8);
2663 break;
2664 default:
2665 break;
2666 }
2668 }
2669 break;
2671 const bool vertical = opt->rect.width() < opt->rect.height();
2672 const Qt::LayoutDirection ld = opt->direction;
2673 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, nullptr);
2674 const int buttonOverlap = proxy()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap, nullptr);
2675
2676 r = vertical ? QRect(0, opt->rect.height() - (buttonWidth * 2) + buttonOverlap, opt->rect.width(), buttonWidth)
2677 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - (buttonWidth * 2) + buttonOverlap, 0, buttonWidth, opt->rect.height()));
2678 break; }
2680 const bool vertical = opt->rect.width() < opt->rect.height();
2681 const Qt::LayoutDirection ld = opt->direction;
2682 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth, nullptr);
2683
2684 r = vertical ? QRect(0, opt->rect.height() - buttonWidth, opt->rect.width(), buttonWidth)
2685 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - buttonWidth, 0, buttonWidth, opt->rect.height()));
2686 break; }
2688 r = opt->rect;
2689 break;
2691 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2692 r = f->rect.adjusted(f->lineWidth, f->lineWidth, -f->lineWidth, -f->lineWidth);
2694 }
2695 break;
2696 case SE_FrameContents:
2697 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2699 r = opt->rect.adjusted(fw, fw, -fw, -fw);
2701 }
2702 break;
2704 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
2705 int frameShape = f->frameShape;
2706 int frameShadow = QStyleOptionFrame::Plain;
2707 if (f->state & QStyle::State_Sunken) {
2708 frameShadow = QStyleOptionFrame::Sunken;
2709 } else if (f->state & QStyle::State_Raised) {
2710 frameShadow = QStyleOptionFrame::Raised;
2711 }
2712
2713 int frameWidth = 0;
2714
2715 switch (frameShape) {
2717 frameWidth = 0;
2718 break;
2719
2723 switch (frameShadow) {
2725 frameWidth = f->lineWidth;
2726 break;
2729 frameWidth = (short)(f->lineWidth*2 + f->midLineWidth);
2730 break;
2731 }
2732 break;
2733
2735 //keep the compatibility with Qt 4.4 if there is a proxy style.
2736 //be sure to call drawPrimitive(QStyle::SE_FrameContents) on the proxy style
2738
2740 frameWidth = 2;
2741 break;
2742
2744 switch (frameShadow) {
2748 frameWidth = f->lineWidth;
2749 break;
2750 }
2751 break;
2752 }
2753 r = f->rect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
2754 }
2755 break;
2759 case SE_DockWidgetIcon: {
2762 QRect rect = opt->rect;
2763
2764 const QStyleOptionDockWidget *dwOpt
2765 = qstyleoption_cast<const QStyleOptionDockWidget*>(opt);
2766 bool canClose = dwOpt == nullptr ? true : dwOpt->closable;
2767 bool canFloat = dwOpt == nullptr ? false : dwOpt->floatable;
2768
2769 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
2770
2771 // If this is a vertical titlebar, we transpose and work as if it was
2772 // horizontal, then transpose again.
2773
2774 if (verticalTitleBar)
2775 rect = rect.transposed();
2776
2777 do {
2778 int right = rect.right();
2779 int left = rect.left();
2780
2781 QRect closeRect;
2782 if (canClose) {
2784 opt).actualSize(QSize(iconSize, iconSize));
2785 sz += QSize(buttonMargin, buttonMargin);
2786 if (verticalTitleBar)
2787 sz = sz.transposed();
2788 closeRect = QRect(right - sz.width(),
2789 rect.center().y() - sz.height()/2,
2790 sz.width(), sz.height());
2791 right = closeRect.left() - 1;
2792 }
2793 if (sr == SE_DockWidgetCloseButton) {
2794 r = closeRect;
2795 break;
2796 }
2797
2798 QRect floatRect;
2799 if (canFloat) {
2801 opt).actualSize(QSize(iconSize, iconSize));
2802 sz += QSize(buttonMargin, buttonMargin);
2803 if (verticalTitleBar)
2804 sz = sz.transposed();
2805 floatRect = QRect(right - sz.width(),
2806 rect.center().y() - sz.height()/2,
2807 sz.width(), sz.height());
2808 right = floatRect.left() - 1;
2809 }
2810 if (sr == SE_DockWidgetFloatButton) {
2811 r = floatRect;
2812 break;
2813 }
2814
2815 QRect iconRect;
2816 if (sr == SE_DockWidgetIcon) {
2817 r = iconRect;
2818 break;
2819 }
2820
2821 QRect textRect = QRect(left, rect.top(),
2822 right - left, rect.height());
2823 if (sr == SE_DockWidgetTitleBarText) {
2824 r = textRect;
2825 break;
2826 }
2827
2828 } while (false);
2829
2830 if (verticalTitleBar) {
2831 r = QRect(rect.left() + r.top() - rect.top(),
2832 rect.top() + rect.right() - r.right(),
2833 r.height(), r.width());
2834 } else {
2836 }
2837 break;
2838 }
2839#if QT_CONFIG(quick_itemview)
2841 if (!qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
2843 break;
2844 }
2845 Q_FALLTHROUGH();
2849 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
2850 if (!d->isViewItemCached(*vopt)) {
2851 d->viewItemLayout(vopt, &d->checkRect, &d->decorationRect, &d->displayRect, false);
2852 if (d->cachedOption) {
2853 delete d->cachedOption;
2854 d->cachedOption = nullptr;
2855 }
2856 d->cachedOption = new QStyleOptionViewItem(*vopt);
2857 }
2859 r = d->checkRect;
2860 else if (sr == SE_ItemViewItemDecoration)
2861 r = d->decorationRect;
2862 else if (sr == SE_ItemViewItemText || sr == SE_ItemViewItemFocusRect)
2863 r = d->displayRect;
2864 }
2865 break;
2866#endif // QT_CONFIG(quick_itemview)
2867 case SE_ToolBarHandle:
2868 if (const QStyleOptionToolBar *tbopt = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
2869 if (tbopt->features & QStyleOptionToolBar::Movable) {
2871 //have all the information we need (ie. the layout's margin)
2872 const QMargins margins(2, 2, 2, 2);
2873 const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt);
2874 if (tbopt->state & QStyle::State_Horizontal) {
2875 r = QRect(margins.left(), margins.top(),
2876 handleExtent,
2877 tbopt->rect.height() - (margins.top() + margins.bottom()));
2878 r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
2879 } else {
2880 r = QRect(margins.left(), margins.top(),
2881 tbopt->rect.width() - (margins.left() + margins.right()),
2882 handleExtent);
2883 }
2884 }
2885 }
2886 break;
2887 default:
2888 break;
2889 }
2890 return r;
2891}
2892
2893// in lieu of std::array, minimal API
2894template <int N>
2896{
2898
2899 Q_DECL_CONSTEXPR int size() const { return N; }
2900 Q_DECL_CONSTEXPR const QPointF *cbegin() const { return data; }
2901 Q_DECL_CONSTEXPR const QPointF &operator[](int idx) const { return data[idx]; }
2902};
2903
2904static StaticPolygonF<3> calcArrow(const QStyleOptionSlider *dial, qreal &a)
2905{
2906 int width = dial->rect.width();
2907 int height = dial->rect.height();
2908 int r = qMin(width, height) / 2;
2909 int currentSliderPosition = dial->upsideDown ? dial->sliderPosition : (dial->maximum - dial->sliderPosition);
2910
2911 qreal startAngle = (90. - dial->startAngle) * Q_PI / 180.;
2912 qreal spanAngle = (dial->endAngle - dial->startAngle) * Q_PI / 180.;
2913 if (dial->maximum == dial->minimum)
2914 a = Q_PI / 2;
2915 else
2916 a = (startAngle - (currentSliderPosition - dial->minimum) * spanAngle
2917 / (dial->maximum - dial->minimum));
2918
2919 int xc = width / 2;
2920 int yc = height / 2;
2921
2922 int len = r - QStyleHelper::calcBigLineSize(r) - 5;
2923 if (len < 5)
2924 len = 5;
2925 int back = len / 2;
2926
2927 StaticPolygonF<3> arrow = {{
2928 QPointF(0.5 + xc + len * qCos(a),
2929 0.5 + yc - len * qSin(a)),
2930 QPointF(0.5 + xc + back * qCos(a + Q_PI * 5 / 6),
2931 0.5 + yc - back * qSin(a + Q_PI * 5 / 6)),
2932 QPointF(0.5 + xc + back * qCos(a - Q_PI * 5 / 6),
2933 0.5 + yc - back * qSin(a - Q_PI * 5 / 6)),
2934 }};
2935 return arrow;
2936}
2937
2939{
2940 switch (cc) {
2941 case CC_Slider:
2942 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2943 if (slider->subControls == SC_SliderTickmarks) {
2944 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider);
2945 int ticks = slider->tickPosition;
2946 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider);
2947 int len = proxy()->pixelMetric(PM_SliderLength, slider);
2948 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider);
2949 int interval = slider->tickInterval;
2950 if (interval <= 0) {
2951 interval = slider->singleStep;
2952 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
2953 available)
2954 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
2955 0, available) < 3)
2956 interval = slider->pageStep;
2957 }
2958 if (!interval)
2959 interval = 1;
2960 int fudge = len / 2;
2961 int pos;
2962 // Since there is no subrect for tickmarks do a translation here.
2963 p->save();
2964 p->translate(slider->rect.x(), slider->rect.y());
2965 p->setPen(slider->palette.windowText().color());
2966 int v = slider->minimum;
2967 while (v <= slider->maximum + 1) {
2968 if (v == slider->maximum + 1 && interval == 1)
2969 break;
2970 const int v_ = qMin(v, slider->maximum);
2971 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
2972 v_, available) + fudge;
2973 if (slider->orientation == Qt::Horizontal) {
2975 p->drawLine(pos, 0, pos, tickOffset - 2);
2977 p->drawLine(pos, tickOffset + thickness + 1, pos,
2978 slider->rect.height()-1);
2979 } else {
2981 p->drawLine(0, pos, tickOffset - 2, pos);
2983 p->drawLine(tickOffset + thickness + 1, pos,
2984 slider->rect.width()-1, pos);
2985 }
2986 // in the case where maximum is max int
2987 int nextInterval = v + interval;
2988 if (nextInterval < v)
2989 break;
2990 v = nextInterval;
2991 }
2992 p->restore();
2993 }
2994 }
2995 break;
2996 case CC_ScrollBar:
2997 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2998 // Make a copy here and reset it for each primitive.
2999 QStyleOptionSlider newScrollbar = *scrollbar;
3000 State saveFlags = scrollbar->state;
3001
3002 if (scrollbar->subControls & SC_ScrollBarSubLine) {
3003 newScrollbar.state = saveFlags;
3004 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine);
3005 if (newScrollbar.rect.isValid()) {
3006 if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
3007 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3008 proxy()->drawControl(CE_ScrollBarSubLine, &newScrollbar, p);
3009 }
3010 }
3011 if (scrollbar->subControls & SC_ScrollBarAddLine) {
3012 newScrollbar.rect = scrollbar->rect;
3013 newScrollbar.state = saveFlags;
3014 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine);
3015 if (newScrollbar.rect.isValid()) {
3016 if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
3017 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3018 proxy()->drawControl(CE_ScrollBarAddLine, &newScrollbar, p);
3019 }
3020 }
3021 if (scrollbar->subControls & SC_ScrollBarSubPage) {
3022 newScrollbar.rect = scrollbar->rect;
3023 newScrollbar.state = saveFlags;
3024 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage);
3025 if (newScrollbar.rect.isValid()) {
3026 if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage))
3027 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3028 proxy()->drawControl(CE_ScrollBarSubPage, &newScrollbar, p);
3029 }
3030 }
3031 if (scrollbar->subControls & SC_ScrollBarAddPage) {
3032 newScrollbar.rect = scrollbar->rect;
3033 newScrollbar.state = saveFlags;
3034 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage);
3035 if (newScrollbar.rect.isValid()) {
3036 if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage))
3037 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3038 proxy()->drawControl(CE_ScrollBarAddPage, &newScrollbar, p);
3039 }
3040 }
3041 if (scrollbar->subControls & SC_ScrollBarFirst) {
3042 newScrollbar.rect = scrollbar->rect;
3043 newScrollbar.state = saveFlags;
3044 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarFirst);
3045 if (newScrollbar.rect.isValid()) {
3046 if (!(scrollbar->activeSubControls & SC_ScrollBarFirst))
3047 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3048 proxy()->drawControl(CE_ScrollBarFirst, &newScrollbar, p);
3049 }
3050 }
3051 if (scrollbar->subControls & SC_ScrollBarLast) {
3052 newScrollbar.rect = scrollbar->rect;
3053 newScrollbar.state = saveFlags;
3054 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarLast);
3055 if (newScrollbar.rect.isValid()) {
3056 if (!(scrollbar->activeSubControls & SC_ScrollBarLast))
3057 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3058 proxy()->drawControl(CE_ScrollBarLast, &newScrollbar, p);
3059 }
3060 }
3061 if (scrollbar->subControls & SC_ScrollBarSlider) {
3062 newScrollbar.rect = scrollbar->rect;
3063 newScrollbar.state = saveFlags;
3064 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSlider);
3065 if (newScrollbar.rect.isValid()) {
3066 if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
3067 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3068 proxy()->drawControl(CE_ScrollBarSlider, &newScrollbar, p);
3069
3070 if (scrollbar->state & State_HasFocus) {
3072 fropt.QStyleOption::operator=(newScrollbar);
3073 fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2,
3074 newScrollbar.rect.width() - 5,
3075 newScrollbar.rect.height() - 5);
3077 }
3078 }
3079 }
3080 }
3081 break;
3082 case CC_SpinBox:
3083 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
3086
3087 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
3089 qDrawWinPanel(p, r, sb->palette, true);
3090 }
3091
3092 if (sb->subControls & SC_SpinBoxUp) {
3093 copy.subControls = SC_SpinBoxUp;
3094 QPalette pal2 = sb->palette;
3095 if (!(sb->stepEnabled & QStyleOptionSpinBox::StepUpEnabled)) {
3097 copy.state &= ~State_Enabled;
3098 }
3099
3100 copy.palette = pal2;
3101
3102 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
3103 copy.state |= State_On;
3104 copy.state |= State_Sunken;
3105 } else {
3106 copy.state |= State_Raised;
3107 copy.state &= ~State_Sunken;
3108 }
3109 pe = (sb->buttonSymbols == QStyleOptionSpinBox::PlusMinus ? PE_IndicatorSpinPlus
3111
3114 copy.rect.adjust(3, 0, -4, 0);
3115 proxy()->drawPrimitive(pe, &copy, p);
3116 }
3117
3118 if (sb->subControls & SC_SpinBoxDown) {
3119 copy.subControls = SC_SpinBoxDown;
3120 copy.state = sb->state;
3121 QPalette pal2 = sb->palette;
3122 if (!(sb->stepEnabled & QStyleOptionSpinBox::StepDownEnabled)) {
3124 copy.state &= ~State_Enabled;
3125 }
3126 copy.palette = pal2;
3127
3128 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
3129 copy.state |= State_On;
3130 copy.state |= State_Sunken;
3131 } else {
3132 copy.state |= State_Raised;
3133 copy.state &= ~State_Sunken;
3134 }
3135 pe = (sb->buttonSymbols == QStyleOptionSpinBox::PlusMinus ? PE_IndicatorSpinMinus
3137
3140 copy.rect.adjust(3, 0, -4, 0);
3141 proxy()->drawPrimitive(pe, &copy, p);
3142 }
3143 }
3144 break;
3145 case CC_ToolButton:
3146 if (const QStyleOptionToolButton *toolbutton
3147 = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3148 QRect button, menuarea;
3149 button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton);
3150 menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu);
3151
3152 State bflags = toolbutton->state & ~State_Sunken;
3153
3154 if (bflags & State_AutoRaise) {
3155 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
3156 bflags &= ~State_Raised;
3157 }
3158 }
3159 State mflags = bflags;
3160 if (toolbutton->state & State_Sunken) {
3161 if (toolbutton->activeSubControls & SC_ToolButton)
3162 bflags |= State_Sunken;
3163 mflags |= State_Sunken;
3164 }
3165
3166 QStyleOption tool = *toolbutton;
3167 if (toolbutton->subControls & SC_ToolButton) {
3168 if (bflags & (State_Sunken | State_On | State_Raised)) {
3169 tool.rect = button;
3170 tool.state = bflags;
3172 }
3173 }
3174
3175 if (toolbutton->state & State_HasFocus) {
3177 fr.QStyleOption::operator=(*toolbutton);
3178 fr.rect.adjust(3, 3, -3, -3);
3179 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3180 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3181 toolbutton), 0);
3183 }
3184 QStyleOptionToolButton label = *toolbutton;
3185 label.state = bflags;
3187 label.rect = button.adjusted(fw, fw, -fw, -fw);
3189
3190 if (toolbutton->subControls & SC_ToolButtonMenu) {
3191 tool.rect = menuarea;
3192 tool.state = mflags;
3193 if (mflags & (State_Sunken | State_On | State_Raised))
3196 } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3197 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton);
3198 QRect ir = toolbutton->rect;
3199 QStyleOptionToolButton newBtn = *toolbutton;
3200 newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6);
3201 newBtn.rect = visualRect(toolbutton->direction, button, newBtn.rect);
3203 }
3204 }
3205 break;
3206 case CC_TitleBar:
3207 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
3208 QRect ir;
3209 if (opt->subControls & SC_TitleBarLabel) {
3210 QColor left = tb->palette.highlight().color();
3211 QColor right = tb->palette.base().color();
3212
3213 QBrush fillBrush(left);
3214 if (left != right) {
3215 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
3216 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
3217 QLinearGradient lg(p1, p2);
3218 lg.setColorAt(0, left);
3219 lg.setColorAt(1, right);
3220 fillBrush = lg;
3221 }
3222
3223 p->fillRect(opt->rect, fillBrush);
3224
3226
3227 p->setPen(tb->palette.highlightedText().color());
3228 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(),
3230 }
3231
3232 bool down = false;
3233 QPixmap pm;
3234
3235 QStyleOption tool = *tb;
3236 if (tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3238 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
3239 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool)
3240 pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3241 else
3242 pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3243 tool.rect = ir;
3244 tool.state = down ? State_Sunken : State_Raised;
3246
3247 p->save();
3248 if (down)
3249 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3252 p->restore();
3253 }
3254
3255 if (tb->subControls & SC_TitleBarMaxButton
3256 && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3257 && !(tb->titleBarState & Qt::WindowMaximized)) {
3259
3260 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
3261 pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3262 tool.rect = ir;
3263 tool.state = down ? State_Sunken : State_Raised;
3265
3266 p->save();
3267 if (down)
3268 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3271 p->restore();
3272 }
3273
3274 if (tb->subControls & SC_TitleBarMinButton
3275 && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3276 && !(tb->titleBarState & Qt::WindowMinimized)) {
3278 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
3279 pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3280 tool.rect = ir;
3281 tool.state = down ? State_Sunken : State_Raised;
3283
3284 p->save();
3285 if (down)
3286 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3289 p->restore();
3290 }
3291
3292 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton)
3293 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3294 && (tb->titleBarState & Qt::WindowMinimized))
3295 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3296 && (tb->titleBarState & Qt::WindowMaximized)));
3297
3298 if (drawNormalButton) {
3300 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
3301 pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3302 tool.rect = ir;
3303 tool.state = down ? State_Sunken : State_Raised;
3305
3306 p->save();
3307 if (down)
3308 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3311 p->restore();
3312 }
3313
3314 if (tb->subControls & SC_TitleBarShadeButton
3315 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3316 && !(tb->titleBarState & Qt::WindowMinimized)) {
3318 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
3319 pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3320 tool.rect = ir;
3321 tool.state = down ? State_Sunken : State_Raised;
3323 p->save();
3324 if (down)
3325 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3328 p->restore();
3329 }
3330
3331 if (tb->subControls & SC_TitleBarUnshadeButton
3332 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3333 && tb->titleBarState & Qt::WindowMinimized) {
3335
3336 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
3337 pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3338 tool.rect = ir;
3339 tool.state = down ? State_Sunken : State_Raised;
3341 p->save();
3342 if (down)
3343 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3346 p->restore();
3347 }
3348 if (tb->subControls & SC_TitleBarContextHelpButton
3349 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3351
3352 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
3353 pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool).pixmap(QSize(10, 10), dpr(opt->window));
3354 tool.rect = ir;
3355 tool.state = down ? State_Sunken : State_Raised;
3357 p->save();
3358 if (down)
3359 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb),
3362 p->restore();
3363 }
3364 if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3366 if (!tb->icon.isNull()) {
3367 tb->icon.paint(p, ir);
3368 } else {
3370 pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool).pixmap(QSize(iconSize, iconSize), dpr(opt->window));
3371 tool.rect = ir;
3372 p->save();
3374 p->restore();
3375 }
3376 }
3377 }
3378 break;
3379 case CC_Dial:
3380 if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3381 // OK, this is more a port of things over
3382 p->save();
3383
3384 // avoid dithering
3385 if (p->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
3386 p->setRenderHint(QPainter::Antialiasing);
3387
3388 int width = dial->rect.width();
3389 int height = dial->rect.height();
3390 qreal r = qMin(width, height) / 2;
3391 qreal d_ = r / 6;
3392 qreal dx = dial->rect.x() + d_ + (width - 2 * r) / 2 + 1;
3393 qreal dy = dial->rect.y() + d_ + (height - 2 * r) / 2 + 1;
3394 QRect br = QRect(int(dx), int(dy), int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2));
3395
3396 QPalette pal = opt->palette;
3397 // draw notches
3398 if (dial->subControls & QStyle::SC_DialTickmarks) {
3399 p->setPen(pal.windowText().color());
3400 p->drawLines(QStyleHelper::calcLines(dial));
3401 }
3402
3403 if (dial->state & State_Enabled) {
3405 p->setPen(Qt::NoPen);
3406 p->drawEllipse(br);
3407 p->setBrush(Qt::NoBrush);
3408 }
3409 p->setPen(QPen(pal.dark().color()));
3410 p->drawArc(br, 60 * 16, 180 * 16);
3411 p->setPen(QPen(pal.light().color()));
3412 p->drawArc(br, 240 * 16, 180 * 16);
3413
3414 qreal a;
3415 const StaticPolygonF<3> arrow = calcArrow(dial, a);
3416
3417 p->setPen(Qt::NoPen);
3418 p->setBrush(pal.button());
3419 p->drawPolygon(arrow.cbegin(), arrow.size());
3420
3421 a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]);
3422 p->setBrush(Qt::NoBrush);
3423
3424 if (a <= 0 || a > 200) {
3425 p->setPen(pal.light().color());
3426 p->drawLine(arrow[2], arrow[0]);
3427 p->drawLine(arrow[1], arrow[2]);
3428 p->setPen(pal.dark().color());
3429 p->drawLine(arrow[0], arrow[1]);
3430 } else if (a > 0 && a < 45) {
3431 p->setPen(pal.light().color());
3432 p->drawLine(arrow[2], arrow[0]);
3433 p->setPen(pal.dark().color());
3434 p->drawLine(arrow[1], arrow[2]);
3435 p->drawLine(arrow[0], arrow[1]);
3436 } else if (a >= 45 && a < 135) {
3437 p->setPen(pal.dark().color());
3438 p->drawLine(arrow[2], arrow[0]);
3439 p->drawLine(arrow[1], arrow[2]);
3440 p->setPen(pal.light().color());
3441 p->drawLine(arrow[0], arrow[1]);
3442 } else if (a >= 135 && a < 200) {
3443 p->setPen(pal.dark().color());
3444 p->drawLine(arrow[2], arrow[0]);
3445 p->setPen(pal.light().color());
3446 p->drawLine(arrow[0], arrow[1]);
3447 p->drawLine(arrow[1], arrow[2]);
3448 }
3449
3450 // draw focus rect around the dial
3452 fropt.rect = dial->rect;
3453 fropt.state = dial->state;
3454 fropt.palette = dial->palette;
3455 if (fropt.state & QStyle::State_HasFocus) {
3456 br.adjust(0, 0, 2, 2);
3457 if (dial->subControls & SC_DialTickmarks) {
3458 int r = qMin(width, height) / 2;
3459 br.translate(-r / 6, - r / 6);
3460 br.setWidth(br.width() + r / 3);
3461 br.setHeight(br.height() + r / 3);
3462 }
3463 fropt.rect = br.adjusted(-2, -2, 2, 2);
3465 }
3466 p->restore();
3467 }
3468 break;
3469 case CC_GroupBox:
3470 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
3471 // Draw frame
3474 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
3476 frame.QStyleOption::operator=(*groupBox);
3477 frame.features = groupBox->features;
3478 frame.lineWidth = groupBox->lineWidth;
3479 frame.midLineWidth = groupBox->midLineWidth;
3481 p->save();
3482 QRegion region(groupBox->rect);
3483 if (!groupBox->text.isEmpty()) {
3484 bool ltr = groupBox->direction == Qt::LeftToRight;
3485 QRect finalRect;
3486 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) {
3487 finalRect = checkBoxRect.united(textRect);
3488 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
3489 } else {
3490 finalRect = textRect;
3491 }
3492 region -= finalRect;
3493 }
3494 p->setClipRegion(region);
3496 p->restore();
3497 }
3498
3499 // Draw title
3500 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
3501 QColor textColor = groupBox->textColor;
3502 if (textColor.isValid())
3503 p->setPen(textColor);
3504 int alignment = int(groupBox->textAlignment);
3507
3511
3512 if (groupBox->state & State_HasFocus) {
3514 fropt.QStyleOption::operator=(*groupBox);
3515 fropt.rect = textRect;
3517 }
3518 }
3519
3520 // Draw checkbox
3521 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3523 box.QStyleOption::operator=(*groupBox);
3524 box.rect = checkBoxRect;
3526 }
3527 }
3528 break;
3529 case CC_MdiControls:
3530 {
3531 QStyleOptionButton btnOpt;
3532 btnOpt.QStyleOption::operator=(*opt);
3533 btnOpt.state &= ~State_MouseOver;
3534 int bsx = 0;
3535 int bsy = 0;
3536 const int buttonIconMetric = proxy()->pixelMetric(PM_TitleBarButtonIconSize, &btnOpt);
3537 const QSize buttonIconSize(buttonIconMetric, buttonIconMetric);
3538 if (opt->subControls & QStyle::SC_MdiCloseButton) {
3539 if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) {
3540 btnOpt.state |= State_Sunken;
3541 btnOpt.state &= ~State_Raised;
3544 } else {
3545 btnOpt.state |= State_Raised;
3546 btnOpt.state &= ~State_Sunken;
3547 bsx = 0;
3548 bsy = 0;
3549 }
3552 QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(buttonIconSize, dpr(opt->window));
3553 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3554 }
3555 if (opt->subControls & QStyle::SC_MdiNormalButton) {
3556 if (opt->activeSubControls & QStyle::SC_MdiNormalButton && (opt->state & State_Sunken)) {
3557 btnOpt.state |= State_Sunken;
3558 btnOpt.state &= ~State_Raised;
3561 } else {
3562 btnOpt.state |= State_Raised;
3563 btnOpt.state &= ~State_Sunken;
3564 bsx = 0;
3565 bsy = 0;
3566 }
3569 QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(buttonIconSize, dpr(opt->window));
3570 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3571 }
3572 if (opt->subControls & QStyle::SC_MdiMinButton) {
3573 if (opt->activeSubControls & QStyle::SC_MdiMinButton && (opt->state & State_Sunken)) {
3574 btnOpt.state |= State_Sunken;
3575 btnOpt.state &= ~State_Raised;
3578 } else {
3579 btnOpt.state |= State_Raised;
3580 btnOpt.state &= ~State_Sunken;
3581 bsx = 0;
3582 bsy = 0;
3583 }
3586 QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(buttonIconSize, dpr(opt->window));
3587 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3588 }
3589 }
3590 break;
3591 default:
3592 qWarning("QCommonStyle::drawComplexControl: Control %d not handled", cc);
3593 }
3594}
3595
3600{
3601 SubControl sc = SC_None;
3602 switch (cc) {
3603 case CC_Slider:
3604 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3605 QRect r = proxy()->subControlRect(cc, slider, SC_SliderHandle);
3606 if (r.isValid() && r.contains(pt)) {
3607 sc = SC_SliderHandle;
3608 } else {
3609 r = proxy()->subControlRect(cc, slider, SC_SliderGroove);
3610 if (r.isValid() && r.contains(pt))
3611 sc = SC_SliderGroove;
3612 }
3613 }
3614 break;
3615 case CC_ScrollBar:
3616 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3617 QRect r;
3619 while (ctrl <= SC_ScrollBarGroove) {
3620 r = proxy()->subControlRect(cc, scrollbar, QStyle::SubControl(ctrl));
3621 if (r.isValid() && r.contains(pt)) {
3622 sc = QStyle::SubControl(ctrl);
3623 break;
3624 }
3625 ctrl <<= 1;
3626 }
3627 }
3628 break;
3629 case CC_ToolButton:
3630 if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3631 QRect r;
3632 uint ctrl = SC_ToolButton;
3633 while (ctrl <= SC_ToolButtonMenu) {
3634 r = proxy()->subControlRect(cc, toolbutton, QStyle::SubControl(ctrl));
3635 if (r.isValid() && r.contains(pt)) {
3636 sc = QStyle::SubControl(ctrl);
3637 break;
3638 }
3639 ctrl <<= 1;
3640 }
3641 }
3642 break;
3643 case CC_SpinBox:
3644 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
3645 QRect r;
3646 uint ctrl = SC_SpinBoxUp;
3647 while (ctrl <= SC_SpinBoxEditField) {
3648 r = proxy()->subControlRect(cc, spinbox, QStyle::SubControl(ctrl));
3649 if (r.isValid() && r.contains(pt)) {
3650 sc = QStyle::SubControl(ctrl);
3651 break;
3652 }
3653 ctrl <<= 1;
3654 }
3655 }
3656 break;
3657 case CC_TitleBar:
3658 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
3659 QRect r;
3660 uint ctrl = SC_TitleBarSysMenu;
3661
3662 while (ctrl <= SC_TitleBarLabel) {
3663 r = proxy()->subControlRect(cc, tb, QStyle::SubControl(ctrl));
3664 if (r.isValid() && r.contains(pt)) {
3665 sc = QStyle::SubControl(ctrl);
3666 break;
3667 }
3668 ctrl <<= 1;
3669 }
3670 }
3671 break;
3672 case CC_ComboBox:
3673 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
3674 QRect r;
3675 uint ctrl = SC_ComboBoxArrow; // Start here and go down.
3676 while (ctrl > 0) {
3677 r = proxy()->subControlRect(cc, cb, QStyle::SubControl(ctrl));
3678 if (r.isValid() && r.contains(pt)) {
3679 sc = QStyle::SubControl(ctrl);
3680 break;
3681 }
3682 ctrl >>= 1;
3683 }
3684 }
3685 break;
3686 case CC_GroupBox:
3687 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
3688 QRect r;
3690 while (ctrl <= SC_GroupBoxFrame) {
3692 if (r.isValid() && r.contains(pt)) {
3693 sc = QStyle::SubControl(ctrl);
3694 break;
3695 }
3696 ctrl <<= 1;
3697 }
3698 }
3699 break;
3700 case CC_MdiControls:
3701 {
3702 QRect r;
3703 uint ctrl = SC_MdiMinButton;
3704 while (ctrl <= SC_MdiCloseButton) {
3706 if (r.isValid() && r.contains(pt) && (opt->subControls & ctrl)) {
3707 sc = QStyle::SubControl(ctrl);
3708 return sc;
3709 }
3710 ctrl <<= 1;
3711 }
3712 }
3713 break;
3714 default:
3715 qWarning("QCommonStyle::hitTestComplexControl: Case %d not handled", cc);
3716 }
3717 return sc;
3718}
3719
3724{
3725 QRect ret;
3726 switch (cc) {
3727 case CC_Slider:
3728 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3729 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider);
3730 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider);
3731
3732 switch (sc) {
3733 case SC_SliderHandle: {
3734 int sliderPos = 0;
3735 int len = proxy()->pixelMetric(PM_SliderLength, slider);
3736 bool horizontal = slider->orientation == Qt::Horizontal;
3737 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
3738 slider->sliderPosition,
3739 (horizontal ? slider->rect.width()
3740 : slider->rect.height()) - len,
3741 slider->upsideDown);
3742 if (horizontal)
3743 ret.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
3744 else
3745 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
3746 break; }
3747 case SC_SliderGroove:
3748 if (slider->orientation == Qt::Horizontal)
3749 ret.setRect(slider->rect.x(), slider->rect.y() + tickOffset,
3750 slider->rect.width(), thickness);
3751 else
3752 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y(),
3753 thickness, slider->rect.height());
3754 break;
3755 default:
3756 break;
3757 }
3758 ret = visualRect(slider->direction, slider->rect, ret);
3759 }
3760 break;
3761 case CC_ScrollBar:
3762 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
3763 const QRect scrollBarRect = scrollbar->rect;
3764 int sbextent = 0;
3765 if (!proxy()->styleHint(SH_ScrollBar_Transient, scrollbar))
3766 sbextent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollbar);
3767 int maxlen = ((scrollbar->orientation == Qt::Horizontal) ?
3768 scrollBarRect.width() : scrollBarRect.height()) - (sbextent * 2);
3769 int sliderlen;
3770
3771 // calculate slider length
3772 if (scrollbar->maximum != scrollbar->minimum) {
3773 uint range = scrollbar->maximum - scrollbar->minimum;
3774 sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep);
3775
3776 int slidermin = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollbar);
3777 if (sliderlen < slidermin || range > INT_MAX / 2)
3778 sliderlen = slidermin;
3779 if (sliderlen > maxlen)
3780 sliderlen = maxlen;
3781 } else {
3782 sliderlen = maxlen;
3783 }
3784
3785 int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
3786 scrollbar->maximum,
3787 scrollbar->sliderPosition,
3788 maxlen - sliderlen,
3789 scrollbar->upsideDown);
3790
3791 switch (sc) {
3792 case SC_ScrollBarSubLine: // top/left button
3793 if (scrollbar->orientation == Qt::Horizontal) {
3794 int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent);
3795 ret.setRect(0, 0, buttonWidth, scrollBarRect.height());
3796 } else {
3797 int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent);
3798 ret.setRect(0, 0, scrollBarRect.width(), buttonHeight);
3799 }
3800 break;
3801 case SC_ScrollBarAddLine: // bottom/right button
3802 if (scrollbar->orientation == Qt::Horizontal) {
3803 int buttonWidth = qMin(scrollBarRect.width()/2, sbextent);
3804 ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height());
3805 } else {
3806 int buttonHeight = qMin(scrollBarRect.height()/2, sbextent);
3807 ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight);
3808 }
3809 break;
3810 case SC_ScrollBarSubPage: // between top/left button and slider
3811 if (scrollbar->orientation == Qt::Horizontal)
3812 ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height());
3813 else
3814 ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent);
3815 break;
3816 case SC_ScrollBarAddPage: // between bottom/right button and slider
3817 if (scrollbar->orientation == Qt::Horizontal)
3818 ret.setRect(sliderstart + sliderlen, 0,
3819 maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height());
3820 else
3821 ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(),
3822 maxlen - sliderstart - sliderlen + sbextent);
3823 break;
3824 case SC_ScrollBarGroove:
3825 if (scrollbar->orientation == Qt::Horizontal)
3826 ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2,
3827 scrollBarRect.height());
3828 else
3829 ret.setRect(0, sbextent, scrollBarRect.width(),
3830 scrollBarRect.height() - sbextent * 2);
3831 break;
3832 case SC_ScrollBarSlider:
3833 if (scrollbar->orientation == Qt::Horizontal)
3834 ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height());
3835 else
3836 ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen);
3837 break;
3838 default:
3839 break;
3840 }
3841 ret = visualRect(scrollbar->direction, scrollBarRect, ret);
3842 }
3843 break;
3844 case CC_SpinBox:
3845 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
3846 QSize bs;
3847 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox) : 0;
3848 bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw));
3849 // 1.6 -approximate golden mean
3850 bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4)));
3851 int y = fw + spinbox->rect.y();
3852 int x, lx, rx;
3853 x = spinbox->rect.x() + spinbox->rect.width() - fw - bs.width();
3854 lx = fw;
3855 rx = x - fw;
3856 switch (sc) {
3857 case SC_SpinBoxUp:
3858 if (spinbox->buttonSymbols == QStyleOptionSpinBox::NoButtons)
3859 return QRect();
3860 ret = QRect(x, y, bs.width(), bs.height());
3861 break;
3862 case SC_SpinBoxDown:
3863 if (spinbox->buttonSymbols == QStyleOptionSpinBox::NoButtons)
3864 return QRect();
3865
3866 ret = QRect(x, y + bs.height(), bs.width(), bs.height());
3867 break;
3869 if (spinbox->buttonSymbols == QStyleOptionSpinBox::NoButtons) {
3870 ret = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
3871 } else {
3872 ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
3873 }
3874 break;
3875 case SC_SpinBoxFrame:
3876 ret = spinbox->rect;
3877 break;
3878 default:
3879 break;
3880 }
3881 ret = visualRect(spinbox->direction, spinbox->rect, ret);
3882 }
3883 break;
3884 case CC_ToolButton:
3885 if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
3886 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb);
3887 ret = tb->rect;
3888 switch (sc) {
3889 case SC_ToolButton:
3890 if ((tb->features
3893 ret.adjust(0, 0, -mbi, 0);
3894 break;
3895 case SC_ToolButtonMenu:
3896 if ((tb->features
3899 ret.adjust(ret.width() - mbi, 0, 0, 0);
3900 break;
3901 default:
3902 break;
3903 }
3904 ret = visualRect(tb->direction, tb->rect, ret);
3905 }
3906 break;
3907 case CC_ComboBox:
3908 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
3909 const qreal dpi = QStyleHelper::dpi(opt);
3910 const int x = cb->rect.x(), y = cb->rect.y(), wi = cb->rect.width(), he = cb->rect.height();
3911 const int margin = cb->frame ? qRound(QStyleHelper::dpiScaled(3, dpi)) : 0;
3912 const int bmarg = cb->frame ? qRound(QStyleHelper::dpiScaled(2, dpi)) : 0;
3913 const int xpos = x + wi - bmarg - qRound(QStyleHelper::dpiScaled(16, dpi));
3914
3915
3916 switch (sc) {
3917 case SC_ComboBoxFrame:
3918 ret = cb->rect;
3919 break;
3920 case SC_ComboBoxArrow:
3921 ret.setRect(xpos, y + bmarg, qRound(QStyleHelper::dpiScaled(16, opt)), he - 2*bmarg);
3922 break;
3924 ret.setRect(x + margin, y + margin, wi - 2 * margin - qRound(QStyleHelper::dpiScaled(16, dpi)), he - 2 * margin);
3925 break;
3927 ret = cb->rect;
3928 break;
3929 default:
3930 break;
3931 }
3932 ret = visualRect(cb->direction, cb->rect, ret);
3933 }
3934 break;
3935 case CC_TitleBar:
3936 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
3937 const int controlMargin = 2;
3938 const int controlHeight = tb->rect.height() - controlMargin *2;
3939 const int delta = controlHeight + controlMargin;
3940 int offset = 0;
3941
3942 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
3943 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
3944
3945 switch (sc) {
3946 case SC_TitleBarLabel:
3947 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
3948 ret = tb->rect;
3949 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3950 ret.adjust(delta, 0, -delta, 0);
3951 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3952 ret.adjust(0, 0, -delta, 0);
3953 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3954 ret.adjust(0, 0, -delta, 0);
3955 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
3956 ret.adjust(0, 0, -delta, 0);
3957 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3958 ret.adjust(0, 0, -delta, 0);
3959 }
3960 break;
3962 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
3963 offset += delta;
3964 Q_FALLTHROUGH();
3966 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3967 offset += delta;
3968 else if (sc == SC_TitleBarMinButton)
3969 break;
3970 Q_FALLTHROUGH();
3972 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
3973 offset += delta;
3974 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3975 offset += delta;
3976 else if (sc == SC_TitleBarNormalButton)
3977 break;
3978 Q_FALLTHROUGH();
3980 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
3981 offset += delta;
3982 else if (sc == SC_TitleBarMaxButton)
3983 break;
3984 Q_FALLTHROUGH();
3986 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3987 offset += delta;
3988 else if (sc == SC_TitleBarShadeButton)
3989 break;
3990 Q_FALLTHROUGH();
3992 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
3993 offset += delta;
3994 else if (sc == SC_TitleBarUnshadeButton)
3995 break;
3996 Q_FALLTHROUGH();
3998 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
3999 offset += delta;
4000 else if (sc == SC_TitleBarCloseButton)
4001 break;
4002 ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
4003 controlHeight, controlHeight);
4004 break;
4005 case SC_TitleBarSysMenu:
4006 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
4007 ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
4008 controlHeight, controlHeight);
4009 }
4010 break;
4011 default:
4012 break;
4013 }
4014 ret = visualRect(tb->direction, tb->rect, ret);
4015 }
4016 break;
4017 case CC_GroupBox: {
4018 if (const QStyleOptionGroupBox *groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
4019 switch (sc) {
4020 case SC_GroupBoxFrame:
4021 case SC_GroupBoxContents: {
4022 int topMargin = 0;
4023 int topHeight = 0;
4025 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4026 if (groupBox->text.size() || hasCheckBox) {
4027 int checkBoxHeight = hasCheckBox ? proxy()->pixelMetric(PM_IndicatorHeight, groupBox) : 0;
4028 topHeight = qMax(groupBox->fontMetrics.height(), checkBoxHeight);
4029 if (verticalAlignment & Qt::AlignVCenter)
4030 topMargin = topHeight / 2;
4031 else if (verticalAlignment & Qt::AlignTop)
4032 topMargin = topHeight;
4033 }
4034
4035 QRect frameRect = groupBox->rect;
4036 frameRect.setTop(topMargin);
4037
4038 if (sc == SC_GroupBoxFrame) {
4039 ret = frameRect;
4040 break;
4041 }
4042
4043 int frameWidth = 0;
4044 if ((groupBox->features & QStyleOptionFrame::Flat) == 0)
4046 ret = frameRect.adjusted(frameWidth, frameWidth + topHeight - topMargin,
4047 -frameWidth, -frameWidth);
4048 break;
4049 }
4051 case SC_GroupBoxLabel: {
4053 int th = fontMetrics.height();
4054 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + QLatin1Char(' ')).width();
4055 int marg = (groupBox->features & QStyleOptionFrame::Flat) ? 0 : 8;
4056 ret = groupBox->rect.adjusted(marg, 0, -marg, 0);
4057
4058 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt);
4059 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt);
4060 int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt) - 1;
4061 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4062 int checkBoxWidth = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
4063 int checkBoxHeight = hasCheckBox ? indicatorHeight : 0;
4064
4065 int h = qMax(th, checkBoxHeight);
4066 ret.setHeight(h);
4067
4068 // Adjusted rect for label + indicatorWidth + indicatorSpace
4069 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
4070 QSize(tw + checkBoxWidth, h), ret);
4071
4072 // Adjust totalRect if checkbox is set
4073 if (hasCheckBox) {
4074 bool ltr = groupBox->direction == Qt::LeftToRight;
4075 int left = 0;
4076 // Adjust for check box
4077 if (sc == SC_GroupBoxCheckBox) {
4078 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
4079 int top = totalRect.top() + (h - checkBoxHeight) / 2;
4080 totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
4081 // Adjust for label
4082 } else {
4083 left = ltr ? (totalRect.left() + checkBoxWidth - 2) : totalRect.left();
4084 int top = totalRect.top() + (h - th) / 2;
4085 totalRect.setRect(left, top, totalRect.width() - checkBoxWidth, th);
4086 }
4087 }
4088 ret = totalRect;
4089 break;
4090 }
4091 default:
4092 break;
4093 }
4094 }
4095 break;
4096 }
4097 case CC_MdiControls:
4098 {
4099 int numSubControls = 0;
4100 if (opt->subControls & SC_MdiCloseButton)
4101 ++numSubControls;
4102 if (opt->subControls & SC_MdiMinButton)
4103 ++numSubControls;
4104 if (opt->subControls & SC_MdiNormalButton)
4105 ++numSubControls;
4106 if (numSubControls == 0)
4107 break;
4108
4109 int buttonWidth = opt->rect.width() / numSubControls - 1;
4110 int offset = 0;
4111 switch (sc) {
4112 case SC_MdiCloseButton:
4113 // Only one sub control, no offset needed.
4114 if (numSubControls == 1)
4115 break;
4116 offset += buttonWidth + 2;
4117 Q_FALLTHROUGH();
4118 case SC_MdiNormalButton:
4119 // No offset needed if
4120 // 1) There's only one sub control
4121 // 2) We have a close button and a normal button (offset already added in SC_MdiClose)
4122 if (numSubControls == 1 || (numSubControls == 2 && !(opt->subControls & SC_MdiMinButton)))
4123 break;
4124 if (opt->subControls & SC_MdiNormalButton)
4125 offset += buttonWidth;
4126 break;
4127 default:
4128 break;
4129 }
4130
4131 // Subtract one pixel if we only have one sub control. At this point
4132 // buttonWidth is the actual width + 1 pixel margin, but we don't want the
4133 // margin when there are no other controllers.
4134 if (numSubControls == 1)
4135 --buttonWidth;
4136 ret = QRect(offset, 0, buttonWidth, opt->rect.height());
4137 break; }
4138 default:
4139 qWarning("QCommonStyle::subControlRect: Case %d not handled", cc);
4140 }
4141
4142 return ret;
4143}
4144
4146{
4147 int ret;
4148
4149 switch (m) {
4152 ret = 2;
4153 break;
4154 case PM_MenuBarVMargin:
4155 case PM_MenuBarHMargin:
4156 ret = 0;
4157 break;
4159 ret = int(QStyleHelper::dpiScaled(5, opt));
4160 break;
4162 ret = int(QStyleHelper::dpiScaled(70, opt));
4163 break;
4165 ret = int(QStyleHelper::dpiScaled(30, opt));
4166 break;
4167 case PM_TitleBarHeight: {
4168 if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
4169 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool) {
4170 ret = qMax(opt->fontMetrics.height(), 16);
4171 } else {
4172 ret = qMax(opt->fontMetrics.height(), 18);
4173 }
4174 } else {
4175 ret = int(QStyleHelper::dpiScaled(18., opt));
4176 }
4177
4178 break; }
4180 ret = int(QStyleHelper::dpiScaled(16., opt));
4181 break;
4183 ret = int(QStyleHelper::dpiScaled(16., opt));
4184 break;
4185
4187 ret = int(QStyleHelper::dpiScaled(9., opt));
4188 break;
4189
4190 case PM_ButtonMargin:
4191 ret = int(QStyleHelper::dpiScaled(6., opt));
4192 break;
4193
4195 ret = int(QStyleHelper::dpiScaled(2., opt));
4196 break;
4197
4199 ret = 0;
4200 break;
4201
4203 ret = int(QStyleHelper::dpiScaled(12, opt));
4204 break;
4205
4208
4210 ret = 2;
4211 break;
4212
4215 case PM_MenuPanelWidth:
4219 break;
4221 ret = int(QStyleHelper::dpiScaled(4, opt));
4222 break;
4224 ret = int(QStyleHelper::dpiScaled(196, opt));
4225 break;
4226 case PM_ScrollBarExtent:
4227 ret = int(QStyleHelper::dpiScaled(16, opt));
4228 break;
4231 break;
4232 case PM_SliderThickness:
4233 ret = int(QStyleHelper::dpiScaled(16, opt));
4234 break;
4236 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4237 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height()
4238 : sl->rect.width();
4239 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, sl);
4240 int ticks = sl->tickPosition;
4241
4243 ret = (space - thickness) / 2;
4244 else if (ticks == QStyleOptionSlider::TicksAbove)
4245 ret = space - thickness;
4246 else
4247 ret = 0;
4248 } else {
4249 ret = 0;
4250 }
4251 break;
4253 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
4254 if (sl->orientation == Qt::Horizontal)
4255 ret = sl->rect.width() - proxy()->pixelMetric(PM_SliderLength, sl);
4256 else
4257 ret = sl->rect.height() - proxy()->pixelMetric(PM_SliderLength, sl);
4258 } else {
4259 ret = 0;
4260 }
4261 break;
4263 ret = int(QStyleHelper::dpiScaled(6, opt));
4264 break;
4265
4267 ret = int(QStyleHelper::dpiScaled(8, opt));
4268 break;
4270 ret = 0;
4271 break;
4273 ret = 1;
4274 break;
4277 ret = 2;
4278 break;
4280 ret = 0;
4281 break;
4283 ret = 1;
4284 break;
4285
4287 ret = 0;
4288 break;
4289
4291 ret = int(QStyleHelper::dpiScaled(4, opt));
4292 break;
4293
4295 ret = int(QStyleHelper::dpiScaled(8, opt));
4296 break;
4297
4299 ret = int(QStyleHelper::dpiScaled(6, opt));
4300 break;
4301
4303 ret = int(QStyleHelper::dpiScaled(12, opt));
4304 break;
4305
4307 ret = 3;
4308 break;
4309
4310 case PM_TabBarTabHSpace:
4311 ret = int(QStyleHelper::dpiScaled(24, opt));
4312 break;
4313
4315 ret = 0;
4316 break;
4317
4319 ret = 2;
4320 break;
4321
4322 case PM_TabBarTabVSpace: {
4323 const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt);
4324 if (tb && (tb->shape == QStyleOptionTab::RoundedNorth || tb->shape == QStyleOptionTab::RoundedSouth
4325 || tb->shape == QStyleOptionTab::RoundedWest || tb->shape == QStyleOptionTab::RoundedEast))
4326 ret = 8;
4327 else
4328 if(tb && (tb->shape == QStyleOptionTab::TriangularWest || tb->shape == QStyleOptionTab::TriangularEast))
4329 ret = 3;
4330 else
4331 ret = 2;
4332 break; }
4333
4335 ret = 9;
4336 break;
4337
4338 case PM_IndicatorWidth:
4339 ret = int(QStyleHelper::dpiScaled(13, opt));
4340 break;
4341
4342 case PM_IndicatorHeight:
4343 ret = int(QStyleHelper::dpiScaled(13, opt));
4344 break;
4345
4347 ret = int(QStyleHelper::dpiScaled(12, opt));
4348 break;
4349
4351 ret = int(QStyleHelper::dpiScaled(12, opt));
4352 break;
4353
4355 ret = int(QStyleHelper::dpiScaled(10, opt));
4356 break;
4357
4359 ret = int(QStyleHelper::dpiScaled(10, opt));
4360 break;
4361
4363 case PM_MenuHMargin:
4364 case PM_MenuVMargin:
4365 ret = 0;
4366 break;
4367
4368 case PM_HeaderMargin:
4369 ret = int(QStyleHelper::dpiScaled(4, opt));
4370 break;
4371 case PM_HeaderMarkSize:
4372 ret = int(QStyleHelper::dpiScaled(16, opt));
4373 break;
4375 ret = int(QStyleHelper::dpiScaled(4, opt));
4376 break;
4378 ret = int(QStyleHelper::dpiScaled(100, opt));
4379 break;
4381 ret = int(QStyleHelper::dpiScaled(30, opt));
4382 break;
4384 ret = int(QStyleHelper::dpiScaled(16, opt));
4385 break;
4387 case PM_LayoutTopMargin:
4390 {
4391 bool isWindow = opt ? (opt->state & State_Window) : false;
4393 }
4394 break;
4398 break;
4399
4401 ret = int(QStyleHelper::dpiScaled(11, opt));
4402 break;
4404 ret = int(QStyleHelper::dpiScaled(9, opt));
4405 break;
4407 ret = int(QStyleHelper::dpiScaled(6, opt));
4408 break;
4409
4410 case PM_ToolBarIconSize:
4411 ret = 0;
4413 ret = theme->themeHint(QPlatformTheme::ToolBarIconSize).toInt();
4414 if (ret <= 0)
4415 ret = int(QStyleHelper::dpiScaled(24, opt));
4416 break;
4417
4418 case PM_TabBarIconSize:
4421 break;
4422
4423 case PM_ButtonIconSize:
4424 case PM_SmallIconSize:
4425 ret = int(QStyleHelper::dpiScaled(16, opt));
4426 break;
4429 break;
4430
4431 case PM_LargeIconSize:
4432 ret = int(QStyleHelper::dpiScaled(32, opt));
4433 break;
4434
4436 ret = 1;
4437 break;
4440 ret = int(QStyleHelper::dpiScaled(6, opt));
4441 break;
4442 case PM_SizeGripSize:
4443 ret = int(QStyleHelper::dpiScaled(13, opt));
4444 break;
4446#ifdef Q_OS_MAC
4448 ret = 64; // No DPI scaling, it's handled elsewhere.
4449 } else
4450#endif
4451 {
4452 ret = int(QStyleHelper::dpiScaled(32, opt));
4453 }
4454 break;
4455 case PM_TextCursorWidth:
4457 break;
4459 ret = 1;
4460 break;
4463 ret = int(QStyleHelper::dpiScaled(16, opt));
4464 break;
4467 break;
4469 ret = 0;
4470 break;
4471 case PM_SubMenuOverlap:
4473 break;
4475 ret = int(QStyleHelper::dpiScaled(20, opt));
4476 break;
4477 default:
4478 ret = 0;
4479 break;
4480 }
4481
4482 return ret;
4483}
4484
4486{
4487 QSize sz(!csz.isEmpty() ? csz : QSize(0,0));
4488
4489 switch (ct) {
4490 case CT_PushButton:
4491 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
4492 int w = sz.width(),
4493 h = sz.height(),
4496 w += bm + fw;
4497 h += bm + fw;
4500 w += dbw;
4501 h += dbw;
4502 }
4503 sz = QSize(w, h);
4504 }
4505 break;
4506 case CT_RadioButton:
4507 case CT_CheckBox:
4508 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
4509 bool isRadio = (ct == CT_RadioButton);
4510
4515
4516 int margins = 0;
4517 // we add 4 pixels for label margins
4518 if (!btn->icon.isNull() || !btn->text.isEmpty())
4519 margins = 4 + proxy()->pixelMetric(isRadio ? PM_RadioButtonLabelSpacing
4521 sz += QSize(w + margins, 4);
4522 sz.setHeight(qMax(sz.height(), h));
4523 }
4524 break;
4525 case CT_MenuItem:
4526 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
4527 bool checkable = mi->menuHasCheckableItems;
4528 int maxpmw = mi->maxIconWidth;
4529 int w = sz.width(), h = sz.height();
4530 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
4531 w = 10;
4532 h = 2;
4533 } else {
4534 h = mi->fontMetrics.height() + 8;
4535 if (!mi->icon.isNull()) {
4536 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize);
4537 h = qMax(h, mi->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
4538 }
4539 }
4540 if (mi->text.contains(QLatin1Char('\t')))
4541 w += 12;
4542 if (maxpmw > 0)
4543 w += maxpmw + 6;
4544 if (checkable && maxpmw < 20)
4545 w += 20 - maxpmw;
4546 if (checkable || maxpmw > 0)
4547 w += 2;
4548 w += 12;
4549 sz = QSize(w, h);
4550 }
4551 break;
4552 case CT_ToolButton:
4553 sz = QSize(sz.width() + 6, sz.height() + 5);
4554 break;
4555 case CT_ComboBox:
4556 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
4557 int fw = cmb->frame ? proxy()->pixelMetric(PM_ComboBoxFrameWidth, opt) * 2 : 0;
4558 const int textMargins = 2*(proxy()->pixelMetric(PM_FocusFrameHMargin) + 1);
4559 // QItemDelegate::sizeHint expands the textMargins two times, thus the 2*textMargins...
4560 int other = qMax(23, 2*textMargins + proxy()->pixelMetric(QStyle::PM_ScrollBarExtent, opt));
4561 sz = QSize(sz.width() + fw + other, sz.height() + fw);
4562 }
4563 break;
4564 case CT_HeaderSection:
4565 if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
4566 bool nullIcon = hdr->icon.isNull();
4567 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, hdr);
4568 int iconSize = nullIcon ? 0 : proxy()->pixelMetric(QStyle::PM_SmallIconSize, hdr);
4569 QSize txt = hdr->fontMetrics.size(0, hdr->text);
4570 sz.setHeight(margin + qMax(iconSize, txt.height()) + margin);
4571 sz.setWidth((nullIcon ? 0 : margin) + iconSize
4572 + (hdr->text.isNull() ? 0 : margin) + txt.width() + margin);
4573 if (hdr->sortIndicator != QStyleOptionHeader::None) {
4574 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, hdr);
4575 if (hdr->orientation == Qt::Horizontal)
4576 sz.rwidth() += sz.height() + margin;
4577 else
4578 sz.rheight() += sz.width() + margin;
4579 }
4580 }
4581 break;
4582 case CT_TabWidget:
4583 sz += QSize(4, 4);
4584 break;
4585 case CT_LineEdit:
4586 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4587 const int borderSize = 2 * f->lineWidth;
4588 sz += QSize(borderSize, borderSize);
4589 const int minSize = 10;
4590 if (sz.width() < minSize)
4591 sz.rwidth() = minSize;
4592 if (sz.height() < minSize)
4593 sz.rheight() = minSize;
4594 }
4595 break;
4596 case CT_GroupBox:
4597 if (const QStyleOptionGroupBox *styleOpt = qstyleoption_cast<const QStyleOptionGroupBox *>(opt)) {
4598 if (sz.isEmpty())
4599 sz = QSize(20, 20);
4600 sz += QSize(styleOpt->features.testFlag(QStyleOptionFrame::Flat) ? 0 : 16, 0);
4601 }
4602 break;
4603 case CT_MdiControls:
4604 if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(opt)) {
4605 const int buttonSize = proxy()->pixelMetric(PM_TitleBarButtonSize, styleOpt);
4606 int width = 1;
4607 if (styleOpt->subControls & SC_MdiMinButton)
4608 width += buttonSize + 1;
4609 if (styleOpt->subControls & SC_MdiNormalButton)
4610 width += buttonSize + 1;
4611 if (styleOpt->subControls & SC_MdiCloseButton)
4612 width += buttonSize + 1;
4613 sz = QSize(width, buttonSize);
4614 } else {
4615 const int buttonSize = proxy()->pixelMetric(PM_TitleBarButtonSize, opt);
4616 sz = QSize(1 + 3 * (buttonSize + 1), buttonSize);
4617 }
4618 break;
4619#if QT_CONFIG(quick_itemview)
4620 case CT_ItemViewItem:
4621 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(opt)) {
4622 Q_D(const QCommonStyle);
4623 QRect decorationRect, displayRect, checkRect;
4624 d->viewItemLayout(vopt, &checkRect, &decorationRect, &displayRect, true);
4625 sz = (decorationRect|displayRect|checkRect).size();
4626 if (decorationRect.isValid() && sz.height() == decorationRect.height())
4627 sz.rheight() += 2; // Prevent icons from overlapping.
4628 }
4629 break;
4630#endif // QT_CONFIG(quick_itemview)
4631 case CT_SpinBox:
4632 if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
4633 // Add button + frame widths
4634 if (vopt->subControls == SC_SpinBoxFrame) {
4635 const qreal dpi = QStyleHelper::dpi(opt);
4636 const bool hasButtons = (vopt->buttonSymbols != QStyleOptionSpinBox::NoButtons);
4637 const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
4638 const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt) : 0;
4639 sz += QSize(buttonWidth + 2*fw, 1 + 2*fw);
4640 } else {
4641 const QSize buttonSize = proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp).size();
4642 const int upAndDownTogetherHeight = buttonSize.height() * 2;
4643 sz += QSize(buttonSize.width(), upAndDownTogetherHeight);
4644 }
4645 }
4646 break;
4647 case CT_Slider:
4648 if (const QStyleOptionSlider *option = qstyleoption_cast<const QStyleOptionSlider *>(opt))
4650 break;
4651 case CT_Dial:
4652 sz = QSize(20, 20);
4653 break;
4654 case CT_Frame:
4655 if (const QStyleOptionFrame *option = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
4656 const int ninePatchSplit = 1;
4657 int w = qMax(10, (option->lineWidth * 2) + ninePatchSplit);
4658 sz = QSize(w, w);
4659 }
4660 break;
4661 case CT_ProgressBar:
4662 if (sz.isNull()) {
4663 // Special case: return minimum nine patch image size
4664 sz = QSize(10, 10);
4665 }
4666 break;
4667 case CT_ScrollBar:
4668 case CT_MenuBar:
4669 case CT_Menu:
4670 case CT_MenuBarItem:
4671 case CT_TabBarTab:
4672 // just return the contentsSize for now
4673 Q_FALLTHROUGH();
4674 default:
4675 break;
4676 }
4677 return sz;
4678}
4679
4680QFont QCommonStyle::font(QStyle::ControlElement element, const QStyle::State state) const
4681{
4682 Q_UNUSED(element);
4683 Q_UNUSED(state);
4684 return QGuiApplication::font();
4685}
4686
4688{
4689 // By default, we just divide the image at the center
4690 int w = imageSize.width() / 2;
4691 int h = imageSize.height() / 2;
4692 return QMargins(w, h, w, h);
4693}
4694
4696{
4697 // By default, we just divide the image at the center
4698 int w = imageSize.width() / 2;
4699 int h = imageSize.height() / 2;
4700 return QMargins(w, h, w, h);
4701}
4702
4704{
4705 int ret = 0;
4706
4707 switch (sh) {
4709 ret = false;
4710 break;
4713 break;
4716 break;
4718 ret = true;
4719 break;
4722 break;
4724 ret = opt ? int(opt->palette.color(QPalette::Text).rgba()) : 0;
4725 break;
4726
4730 break;
4731
4734 break;
4735
4738 break;
4739
4741 ret = false;
4742 break;
4743
4745 ret = 256;
4746 break;
4747
4749 ret = true;
4750 break;
4751
4753 ret = false;
4754 break;
4756 ret = 1;
4757 break;
4759 ret = true;
4760 break;
4762 ret = 1000;
4763 break;
4765 ret = false;
4766 break;
4768 ret = false;
4769 break;
4770
4773 break;
4774
4776#if defined(Q_OS_DARWIN)
4777 ret = 0;
4778#else
4779 ret = 1;
4780#endif
4781 break;
4782
4784 if (opt)
4786 else
4787 ret = -1;
4788 break;
4792 const QVariant hint = theme ? theme->themeHint(hintType) : QPlatformTheme::defaultThemeHint(hintType);
4793 ret = hint.toChar().unicode();
4794 break;
4795 }
4798 break;
4800 ret = 1;
4801 break;
4802
4804 ret = 1;
4805 break;
4806
4808 ret = 150;
4809 break;
4810
4812 ret = 500;
4813 break;
4814
4816 ret = 75;
4817 break;
4818
4820 ret = true;
4821 break;
4822
4824 ret = true;
4825 break;
4826
4828 ret = 255;
4829 break;
4830
4833 break;
4834
4836 ret = 0;
4837 break;
4838
4840 ret = 600;
4841 break;
4842
4843 case SH_FocusFrame_Mask:
4844 ret = 1;
4845 break;
4846 case SH_RubberBand_Mask:
4847 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
4848 ret = 0;
4849 if (rbOpt->shape == QStyleOptionRubberBand::Rectangle) {
4850 ret = true;
4851 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) {
4852 mask->region = opt->rect;
4853 int margin = proxy()->pixelMetric(PM_DefaultFrameWidth) * 2;
4854 mask->region -= opt->rect.adjusted(margin, margin, -margin, -margin);
4855 }
4856 }
4857 }
4858 break;
4860 ret = 1;
4861 break;
4862
4865 break;
4866
4869 break;
4870
4873 break;
4874
4876 ret = false;
4877 break;
4878
4880 ret = 0;
4882 ret = theme->themeHint(QPlatformTheme::ItemViewActivateItemOnSingleClick).toBool() ? 1 : 0;
4883 break;
4885 ret = true;
4886 break;
4888 ret = false;
4889 break;
4892 break;
4895 ret = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt();
4896 break;
4899 break;
4902 break;
4904 ret = 0;
4906 ret = theme->themeHint(QPlatformTheme::DialogButtonBoxButtonsHaveIcons).toBool() ? 1 : 0;
4907 break;
4910 break;
4912 ret = true;
4913 break;
4915 ret = true;
4916 break;
4918 ret = false;
4919 break;
4922 break;
4923 case SH_ToolBar_Movable:
4924 ret = true;
4925 break;
4927 ret = true;
4928 if (QStyleHintReturnVariant *vret = qstyleoption_cast<QStyleHintReturnVariant*>(hret)) {
4932 vret->variant = fmt;
4933 }
4934 break;
4935 case SH_WizardStyle:
4936 break;
4938 break;
4940 break;
4943 break;
4946 break;
4948 ret = false;
4949 break;
4951 ret = 0;
4952 break;
4955 break;
4957 ret = 500;
4958 break;
4960 ret = true;
4961 break;
4962 case SH_ToolButtonStyle:
4963 ret = 0;
4965 ret = theme->themeHint(QPlatformTheme::ToolButtonStyle).toInt();
4966 break;
4969 break;
4971 ret = false;
4972 break;
4974 ret = false;
4975 break;
4977 ret = 700;
4978 break;
4980 ret = 2000;
4981 break;
4982 case SH_Widget_Animate:
4983 ret = true;
4984 break;
4986 ret = true;
4987 break;
4988#if QT_CONFIG(quick_itemview)
4990 ret = QStyleOptionViewItem::ScrollPerItem;
4991 break;
4992#endif // QT_CONFIG(quick_itemview)
4994 ret = true;
4995 break;
4997 ret = styleHint(SH_Widget_Animate, opt, hret) ? 200 : 0;
4998 break;
5000 ret = true;
5001 break;
5003 ret = true;
5004 break;
5007 break;
5008 default:
5009 ret = 0;
5010 break;
5011 }
5012
5013 return ret;
5014}
5015
5016#if QT_CONFIG(imageformat_xpm)
5017static QPixmap cachedPixmapFromXPM(const char * const *xpm)
5018{
5020 const QString tag = QString::asprintf("xpm:0x%p", static_cast<const void*>(xpm));
5021 if (!QPixmapCache::find(tag, &result)) {
5022 result = QPixmap(xpm);
5024 }
5025 return result;
5026}
5027
5028static inline QPixmap titleBarMenuCachedPixmapFromXPM() { return cachedPixmapFromXPM(qt_menu_xpm); }
5029#endif
5030
5032{
5033 return QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-16.png");
5034}
5035
5036#if defined(Q_OS_WIN) || QT_CONFIG(imageformat_png)
5037static QIcon clearTextIcon(bool rtl)
5038{
5039 const QString directionalThemeName = rtl
5040 ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl");
5041 if (QIcon::hasThemeIcon(directionalThemeName))
5042 return QIcon::fromTheme(directionalThemeName);
5043 const QString themeName = QStringLiteral("edit-clear");
5046
5047 QIcon icon;
5048#ifndef QT_NO_IMAGEFORMAT_PNG
5049 QPixmap clearText16(clearText16IconPath());
5050 Q_ASSERT(!clearText16.size().isEmpty());
5051 icon.addPixmap(clearText16);
5052 QPixmap clearText32(QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-32.png"));
5053 Q_ASSERT(!clearText32.size().isEmpty());
5054 icon.addPixmap(clearText32);
5055 clearText32.setDevicePixelRatio(2); // The 32x32 pixmap can also be used for 16x16/devicePixelRatio=2
5056 icon.addPixmap(clearText32);
5057#endif // !QT_NO_IMAGEFORMAT_PNG
5058 return icon;
5059}
5060#endif
5061
5063{
5064 const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QGuiApplication::isRightToLeft());
5065#if QT_CONFIG(imageformat_png)
5067
5069 switch (sp) {
5070 case SP_DialogYesButton:
5071 case SP_DialogOkButton:
5072 pixmap = QIcon::fromTheme(QLatin1String("dialog-ok")).pixmap(16);
5073 break;
5075 pixmap = QIcon::fromTheme(QLatin1String("dialog-ok-apply")).pixmap(16);
5076 break;
5078 pixmap = QIcon::fromTheme(QLatin1String("edit-delete")).pixmap(16);
5079 break;
5081 pixmap = QIcon::fromTheme(QLatin1String("dialog-close")).pixmap(16);
5082 break;
5083 case SP_DirHomeIcon:
5084 pixmap = QIcon::fromTheme(QLatin1String("user-home")).pixmap(16);
5085 break;
5087 pixmap = QIcon::fromTheme(QLatin1String("messagebox_info")).pixmap(16);
5088 break;
5090 pixmap = QIcon::fromTheme(QLatin1String("messagebox_warning")).pixmap(16);
5091 break;
5093 pixmap = QIcon::fromTheme(QLatin1String("messagebox_critical")).pixmap(16);
5094 break;
5096 pixmap = QIcon::fromTheme(QLatin1String("help")).pixmap(16);
5097 break;
5099 case SP_DirOpenIcon:
5100 pixmap = QIcon::fromTheme(QLatin1String("folder-open")).pixmap(16);
5101 break;
5102 case SP_FileIcon:
5103 pixmap = QIcon::fromTheme(QLatin1String("text-x-generic"),
5104 QIcon::fromTheme(QLatin1String("empty"))).pixmap(16);
5105 break;
5106 case SP_DirClosedIcon:
5107 case SP_DirIcon:
5108 pixmap = QIcon::fromTheme(QLatin1String("folder")).pixmap(16);
5109 break;
5110 case SP_DriveFDIcon:
5111 pixmap = QIcon::fromTheme(QLatin1String("media-floppy"),
5112 QIcon::fromTheme(QLatin1String("3floppy_unmount"))).pixmap(16);
5113 break;
5114 case SP_ComputerIcon:
5116 QIcon::fromTheme(QLatin1String("system"))).pixmap(16);
5117 break;
5118 case SP_DesktopIcon:
5119 pixmap = QIcon::fromTheme(QLatin1String("user-desktop"),
5120 QIcon::fromTheme(QLatin1String("desktop"))).pixmap(16);
5121 break;
5122 case SP_TrashIcon:
5123 pixmap = QIcon::fromTheme(QLatin1String("user-trash"),
5124 QIcon::fromTheme(QLatin1String("trashcan_empty"))).pixmap(16);
5125 break;
5126 case SP_DriveCDIcon:
5127 case SP_DriveDVDIcon:
5128 pixmap = QIcon::fromTheme(QLatin1String("media-optical"),
5129 QIcon::fromTheme(QLatin1String("cdrom_unmount"))).pixmap(16);
5130 break;
5131 case SP_DriveHDIcon:
5132 pixmap = QIcon::fromTheme(QLatin1String("drive-harddisk"),
5133 QIcon::fromTheme(QLatin1String("hdd_unmount"))).pixmap(16);
5134 break;
5137 QIcon::fromTheme(QLatin1String("up"))).pixmap(16);
5138 break;
5140 pixmap = QIcon::fromTheme(QLatin1String("folder_new")).pixmap(16);
5141 break;
5142 case SP_ArrowUp:
5144 QIcon::fromTheme(QLatin1String("up"))).pixmap(16);
5145 break;
5146 case SP_ArrowDown:
5148 QIcon::fromTheme(QLatin1String("down"))).pixmap(16);
5149 break;
5150 case SP_ArrowRight:
5152 QIcon::fromTheme(QLatin1String("forward"))).pixmap(16);
5153 break;
5154 case SP_ArrowLeft:
5155 pixmap = QIcon::fromTheme(QLatin1String("go-previous"),
5156 QIcon::fromTheme(QLatin1String("back"))).pixmap(16);
5157 break;
5159 pixmap = QIcon::fromTheme(QLatin1String("view_detailed")).pixmap(16);
5160 break;
5162 pixmap = QIcon::fromTheme(QLatin1String("view_icon")).pixmap(16);
5163 break;
5164 case SP_BrowserReload:
5165 pixmap = QIcon::fromTheme(QLatin1String("reload")).pixmap(16);
5166 break;
5167 case SP_BrowserStop:
5168 pixmap = QIcon::fromTheme(QLatin1String("process-stop")).pixmap(16);
5169 break;
5170 case SP_MediaPlay:
5171 pixmap = QIcon::fromTheme(QLatin1String("media-playback-start")).pixmap(16);
5172 break;
5173 case SP_MediaPause:
5174 pixmap = QIcon::fromTheme(QLatin1String("media-playback-pause")).pixmap(16);
5175 break;
5176 case SP_MediaStop:
5177 pixmap = QIcon::fromTheme(QLatin1String("media-playback-stop")).pixmap(16);
5178 break;
5180 pixmap = QIcon::fromTheme(QLatin1String("media-seek-forward")).pixmap(16);
5181 break;
5183 pixmap = QIcon::fromTheme(QLatin1String("media-seek-backward")).pixmap(16);
5184 break;
5186 pixmap = QIcon::fromTheme(QLatin1String("media-skip-forward")).pixmap(16);
5187 break;
5189 pixmap = QIcon::fromTheme(QLatin1String("media-skip-backward")).pixmap(16);
5190 break;
5192 pixmap = QIcon::fromTheme(QLatin1String("edit-clear")).pixmap(24);
5193 break;
5195 pixmap = QIcon::fromTheme(QLatin1String("help-contents")).pixmap(24);
5196 break;
5197 case SP_DialogNoButton:
5199 pixmap = QIcon::fromTheme(QLatin1String("dialog-cancel"),
5200 QIcon::fromTheme(QLatin1String("process-stop"))).pixmap(24);
5201 break;
5203 pixmap = QIcon::fromTheme(QLatin1String("document-save")).pixmap(24);
5204 break;
5205 case SP_FileLinkIcon:
5206 pixmap = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")).pixmap(16);
5207 if (!pixmap.isNull()) {
5208 QPixmap fileIcon = QIcon::fromTheme(QLatin1String("text-x-generic")).pixmap(16);
5209 if (fileIcon.isNull())
5210 fileIcon = QIcon::fromTheme(QLatin1String("empty")).pixmap(16);
5211 if (!fileIcon.isNull()) {
5212 QPainter painter(&fileIcon);
5213 painter.drawPixmap(0, 0, 16, 16, pixmap);
5214 return fileIcon;
5215 }
5216 }
5217 break;
5218 case SP_DirLinkIcon:
5219 pixmap = QIcon::fromTheme(QLatin1String("emblem-symbolic-link")).pixmap(16);
5220 if (!pixmap.isNull()) {
5221 QPixmap dirIcon = QIcon::fromTheme(QLatin1String("folder")).pixmap(16);
5222 if (!dirIcon.isNull()) {
5223 QPainter painter(&dirIcon);
5224 painter.drawPixmap(0, 0, 16, 16, pixmap);
5225 return dirIcon;
5226 }
5227 }
5228 break;
5230 pixmap = clearTextIcon(rtl).pixmap(16);
5231 break;
5232 default:
5233 break;
5234 }
5235 }
5236
5237 if (!pixmap.isNull())
5238 return pixmap;
5239#endif // QT_CONFIG(imageformat_png)
5240 switch (sp) {
5241#ifndef QT_NO_IMAGEFORMAT_XPM
5243 if (rtl) {
5245 im = std::move(im).convertToFormat(QImage::Format_ARGB32).mirrored(true, false);
5246 return QPixmap::fromImage(std::move(im));
5247 }
5248 return cachedPixmapFromXPM(tb_extension_arrow_h_xpm);
5250 return cachedPixmapFromXPM(tb_extension_arrow_v_xpm);
5251 case SP_FileDialogStart:
5252 return cachedPixmapFromXPM(filedialog_start_xpm);
5253 case SP_FileDialogEnd:
5254 return cachedPixmapFromXPM(filedialog_end_xpm);
5255#endif
5256#ifndef QT_NO_IMAGEFORMAT_PNG
5257 case SP_CommandLink:
5258 case SP_ArrowForward:
5259 if (rtl)
5262 case SP_ArrowBack:
5263 if (rtl)
5266 case SP_ArrowLeft:
5267 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/left-16.png"));
5268 case SP_ArrowRight:
5269 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/right-16.png"));
5270 case SP_ArrowUp:
5271 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/up-16.png"));
5272 case SP_ArrowDown:
5273 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/down-16.png"));
5277 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/newdirectory-16.png"));
5279 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewdetailed-16.png"));
5281 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/fileinfo-16.png"));
5283 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/filecontents-16.png"));
5285 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewlist-16.png"));
5286 case SP_FileDialogBack:
5288 case SP_DriveHDIcon:
5289 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/harddrive-16.png"));
5290 case SP_TrashIcon:
5291 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/trash-16.png"));
5292 case SP_DriveFDIcon:
5293 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/floppy-16.png"));
5294 case SP_DriveNetIcon:
5295 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/networkdrive-16.png"));
5296 case SP_DesktopIcon:
5297 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/desktop-16.png"));
5298 case SP_ComputerIcon:
5299 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/computer-16.png"));
5300 case SP_DriveCDIcon:
5301 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/cdr-16.png"));
5302 case SP_DriveDVDIcon:
5303 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/dvd-16.png"));
5304 case SP_DirHomeIcon:
5305 case SP_DirOpenIcon:
5306 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/diropen-16.png"));
5307 case SP_DirIcon:
5308 case SP_DirClosedIcon:
5309 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/dirclosed-16.png"));
5310 case SP_DirLinkIcon:
5311 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/dirlink-16.png"));
5312 case SP_FileIcon:
5313 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
5314 case SP_FileLinkIcon:
5315 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/filelink-16.png"));
5316 case SP_DialogOkButton:
5317 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-ok-16.png"));
5319 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-16.png"));
5321 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-help-16.png"));
5323 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-open-16.png"));
5325 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-save-16.png"));
5327 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-close-16.png"));
5329 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-apply-16.png"));
5331 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-clear-16.png"));
5333 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-delete-16.png"));
5334 case SP_DialogYesButton:
5335 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-yes-16.png"));
5336 case SP_DialogNoButton:
5337 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-no-16.png"));
5338 case SP_BrowserReload:
5339 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/refresh-24.png"));
5340 case SP_BrowserStop:
5341 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/stop-24.png"));
5342 case SP_MediaPlay:
5343 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-play-32.png"));
5344 case SP_MediaPause:
5345 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-pause-32.png"));
5346 case SP_MediaStop:
5347 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-stop-32.png"));
5349 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-forward-32.png"));
5351 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-backward-32.png"));
5353 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-forward-32.png"));
5355 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-backward-32.png"));
5356 case SP_MediaVolume:
5357 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-16.png"));
5359 return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"));
5361 return QPixmap(clearText16IconPath());
5362#endif // QT_NO_IMAGEFORMAT_PNG
5363 default:
5364 break;
5365 }
5366
5367#ifndef QT_NO_IMAGEFORMAT_XPM
5368 switch (sp) {
5370 return titleBarMenuCachedPixmapFromXPM();
5372 return cachedPixmapFromXPM(qt_shade_xpm);
5374 return cachedPixmapFromXPM(qt_unshade_xpm);
5376 return cachedPixmapFromXPM(qt_normalizeup_xpm);
5378 return cachedPixmapFromXPM(qt_minimize_xpm);
5380 return cachedPixmapFromXPM(qt_maximize_xpm);
5382 return cachedPixmapFromXPM(qt_close_xpm);
5384 return cachedPixmapFromXPM(qt_help_xpm);
5386 return cachedPixmapFromXPM(dock_widget_close_xpm);
5388 return cachedPixmapFromXPM(information_xpm);
5390 return cachedPixmapFromXPM(warning_xpm);
5392 return cachedPixmapFromXPM(critical_xpm);
5394 return cachedPixmapFromXPM(question_xpm);
5395 default:
5396 break;
5397 }
5398#endif //QT_NO_IMAGEFORMAT_XPM
5399
5400#if !QT_CONFIG(imageformat_png) && !QT_CONFIG(imageformat_xpm)
5401 Q_UNUSED(rtl);
5402#endif
5403
5404 return QPixmap();
5405}
5406
5407#if QT_CONFIG(imageformat_png)
5408static inline QString iconResourcePrefix() { return QStringLiteral(":/qt-project.org/styles/commonstyle/images/"); }
5409static inline QString iconPngSuffix() { return QStringLiteral(".png"); }
5410
5411static void addIconFiles(const QString &prefix, const int sizes[], size_t count, QIcon &icon)
5412{
5413 for (size_t i = 0; i < count; ++i)
5414 icon.addFile(prefix + QString::number(sizes[i]) + iconPngSuffix());
5415}
5416
5417static const int dockTitleIconSizes[] = {10, 16, 20, 32, 48, 64};
5418static const int titleBarSizes[] = {16, 32, 48};
5419static const int toolBarExtHSizes[] = {8, 16, 32};
5420static const int toolBarExtVSizes[] = {5, 10, 20};
5421#endif // imageformat_png
5422
5427{
5428 QIcon icon;
5429 const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QGuiApplication::isRightToLeft());
5430
5431#ifdef Q_OS_WIN
5432 switch (standardIcon) {
5433 case SP_DriveCDIcon:
5434 case SP_DriveDVDIcon:
5435 case SP_DriveNetIcon:
5436 case SP_DriveHDIcon:
5437 case SP_DriveFDIcon:
5438 case SP_FileIcon:
5439 case SP_FileLinkIcon:
5440 case SP_DesktopIcon:
5441 case SP_ComputerIcon:
5442 case SP_VistaShield:
5449 for (int size = 16 ; size <= 32 ; size += 16) {
5450 QPixmap pixmap = theme->standardPixmap(sp, QSizeF(size, size));
5452 }
5453 }
5454 break;
5455 case SP_DirIcon:
5456 case SP_DirLinkIcon:
5461 for (int size = 16 ; size <= 32 ; size += 16) {
5462 QSizeF pixSize(size, size);
5463 QPixmap pixmap = theme->standardPixmap(spOff, pixSize);
5465 pixmap = theme->standardPixmap(spOn, pixSize);
5467 }
5468 }
5469 break;
5471 icon = clearTextIcon(rtl);
5472 break;
5473 default:
5474 break;
5475 }
5476 if (!icon.isNull())
5477 return icon;
5478
5479#endif
5480
5482 switch (standardIcon) {
5483 case SP_DirHomeIcon:
5484 icon = QIcon::fromTheme(QLatin1String("user-home"));
5485 break;
5487 icon = QIcon::fromTheme(QLatin1String("dialog-information"));
5488 break;
5490 icon = QIcon::fromTheme(QLatin1String("dialog-warning"));
5491 break;
5493 icon = QIcon::fromTheme(QLatin1String("dialog-error"));
5494 break;
5496 icon = QIcon::fromTheme(QLatin1String("dialog-question"));
5497 break;
5499 case SP_DirOpenIcon:
5500 icon = QIcon::fromTheme(QLatin1String("folder-open"));
5501 break;
5503 icon = QIcon::fromTheme(QLatin1String("document-save"));
5504 break;
5506 icon = QIcon::fromTheme(QLatin1String("dialog-ok-apply"));
5507 break;
5508 case SP_DialogYesButton:
5509 case SP_DialogOkButton:
5510 icon = QIcon::fromTheme(QLatin1String("dialog-ok"));
5511 break;
5513 icon = QIcon::fromTheme(QLatin1String("edit-delete"));
5514 break;
5516 icon = QIcon::fromTheme(QLatin1String("edit-clear"));
5517 break;
5519 icon = QIcon::fromTheme(QLatin1String("help-contents"));
5520 break;
5521 case SP_FileIcon:
5522 icon = QIcon::fromTheme(QLatin1String("text-x-generic"));
5523 break;
5524 case SP_DirClosedIcon:
5525 case SP_DirIcon:
5526 icon = QIcon::fromTheme(QLatin1String("folder"));
5527 break;
5528 case SP_DriveFDIcon:
5529 icon = QIcon::fromTheme(QLatin1String("floppy_unmount"));
5530 break;
5531 case SP_ComputerIcon:
5532 icon = QIcon::fromTheme(QLatin1String("computer"),
5533 QIcon::fromTheme(QLatin1String("system")));
5534 break;
5535 case SP_DesktopIcon:
5536 icon = QIcon::fromTheme(QLatin1String("user-desktop"));
5537 break;
5538 case SP_TrashIcon:
5539 icon = QIcon::fromTheme(QLatin1String("user-trash"));
5540 break;
5541 case SP_DriveCDIcon:
5542 case SP_DriveDVDIcon:
5543 icon = QIcon::fromTheme(QLatin1String("media-optical"));
5544 break;
5545 case SP_DriveHDIcon:
5546 icon = QIcon::fromTheme(QLatin1String("drive-harddisk"));
5547 break;
5550 break;
5552 icon = QIcon::fromTheme(QLatin1String("folder-new"));
5553 break;
5554 case SP_ArrowUp:
5556 break;
5557 case SP_ArrowDown:
5558 icon = QIcon::fromTheme(QLatin1String("go-down"));
5559 break;
5560 case SP_ArrowRight:
5561 icon = QIcon::fromTheme(QLatin1String("go-next"));
5562 break;
5563 case SP_ArrowLeft:
5564 icon = QIcon::fromTheme(QLatin1String("go-previous"));
5565 break;
5566 case SP_DialogNoButton:
5568 icon = QIcon::fromTheme(QLatin1String("dialog-cancel"),
5569 QIcon::fromTheme(QLatin1String("process-stop")));
5570 break;
5572 icon = QIcon::fromTheme(QLatin1String("window-close"));
5573 break;
5575 icon = QIcon::fromTheme(QLatin1String("view-list-details"));
5576 break;
5578 icon = QIcon::fromTheme(QLatin1String("view-list-icons"));
5579 break;
5580 case SP_BrowserReload:
5581 icon = QIcon::fromTheme(QLatin1String("view-refresh"));
5582 break;
5583 case SP_BrowserStop:
5584 icon = QIcon::fromTheme(QLatin1String("process-stop"));
5585 break;
5586 case SP_MediaPlay:
5587 icon = QIcon::fromTheme(QLatin1String("media-playback-start"));
5588 break;
5589 case SP_MediaPause:
5590 icon = QIcon::fromTheme(QLatin1String("media-playback-pause"));
5591 break;
5592 case SP_MediaStop:
5593 icon = QIcon::fromTheme(QLatin1String("media-playback-stop"));
5594 break;
5596 icon = QIcon::fromTheme(QLatin1String("media-seek-forward"));
5597 break;
5599 icon = QIcon::fromTheme(QLatin1String("media-seek-backward"));
5600 break;
5602 icon = QIcon::fromTheme(QLatin1String("media-skip-forward"));
5603 break;
5605 icon = QIcon::fromTheme(QLatin1String("media-skip-backward"));
5606 break;
5607 case SP_MediaVolume:
5608 icon = QIcon::fromTheme(QLatin1String("audio-volume-medium"));
5609 break;
5611 icon = QIcon::fromTheme(QLatin1String("audio-volume-muted"));
5612 break;
5613 case SP_ArrowForward:
5614 if (rtl)
5617 case SP_ArrowBack:
5618 if (rtl)
5621 case SP_FileLinkIcon:
5622 {
5623 QIcon linkIcon = QIcon::fromTheme(QLatin1String("emblem-symbolic-link"));
5624 if (!linkIcon.isNull()) {
5626 const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off);
5627 const qreal devicePixelRatio = option ? dpr(option->window) : 1.;
5628 for (int i = 0 ; i < sizes.size() ; ++i) {
5629 int size = sizes[i].width();
5630 QPixmap basePixmap = baseIcon.pixmap(QSize(size, size), devicePixelRatio);
5631 QPixmap linkPixmap = linkIcon.pixmap(QSize(size / 2, size / 2), devicePixelRatio);
5632 QPainter painter(&basePixmap);
5633 painter.drawPixmap(size/2, size/2, linkPixmap);
5634 icon.addPixmap(basePixmap);
5635 }
5636 }
5637 }
5638 break;
5639 case SP_DirLinkIcon:
5640 {
5641 QIcon linkIcon = QIcon::fromTheme(QLatin1String("emblem-symbolic-link"));
5642 if (!linkIcon.isNull()) {
5644 const QList<QSize> sizes = baseIcon.availableSizes(QIcon::Normal, QIcon::Off);
5645 const qreal devicePixelRatio = option ? dpr(option->window) : 1.;
5646 for (int i = 0 ; i < sizes.size() ; ++i) {
5647 int size = sizes[i].width();
5648 QPixmap basePixmap = baseIcon.pixmap(QSize(size, size), devicePixelRatio);
5649 QPixmap linkPixmap = linkIcon.pixmap(QSize(size / 2, size / 2), devicePixelRatio);
5650 QPainter painter(&basePixmap);
5651 painter.drawPixmap(size/2, size/2, linkPixmap);
5652 icon.addPixmap(basePixmap);
5653 }
5654 }
5655 }
5656 break;
5657 default:
5658 break;
5659 }
5660 } // if (QGuiApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty())
5661
5662 if (!icon.isNull())
5663 return icon;
5664
5665#if defined(Q_OS_MAC)
5667 switch (standardIcon) {
5668 case SP_DirIcon: {
5669 // A rather special case
5672 closeIcon.addPixmap(openIcon.pixmap(16, 16), QIcon::Normal, QIcon::On);
5673 closeIcon.addPixmap(openIcon.pixmap(32, 32), QIcon::Normal, QIcon::On);
5674 closeIcon.addPixmap(openIcon.pixmap(64, 64), QIcon::Normal, QIcon::On);
5675 closeIcon.addPixmap(openIcon.pixmap(128, 128), QIcon::Normal, QIcon::On);
5676 return closeIcon;
5677 }
5678
5681 QIcon titleBarIcon;
5683 titleBarIcon.addFile(QLatin1String(":/qt-project.org/styles/macstyle/images/closedock-16.png"));
5684 titleBarIcon.addFile(QLatin1String(":/qt-project.org/styles/macstyle/images/closedock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On);
5685 } else {
5686 titleBarIcon.addFile(QLatin1String(":/qt-project.org/styles/macstyle/images/dockdock-16.png"));
5687 titleBarIcon.addFile(QLatin1String(":/qt-project.org/styles/macstyle/images/dockdock-down-16.png"), QSize(16, 16), QIcon::Normal, QIcon::On);
5688 }
5689 return titleBarIcon;
5690 }
5691
5696 case SP_DesktopIcon:
5697 case SP_TrashIcon:
5698 case SP_ComputerIcon:
5699 case SP_DriveFDIcon:
5700 case SP_DriveHDIcon:
5701 case SP_DriveCDIcon:
5702 case SP_DriveDVDIcon:
5703 case SP_DriveNetIcon:
5704 case SP_DirOpenIcon:
5705 case SP_DirClosedIcon:
5706 case SP_DirLinkIcon:
5707 case SP_FileLinkIcon:
5708 case SP_FileIcon:
5711 QIcon retIcon;
5712 const QList<QSize> sizes = theme->themeHint(QPlatformTheme::IconPixmapSizes).value<QList<QSize> >();
5713 for (const QSize &size : sizes) {
5714 QPixmap mainIcon;
5715 const QString cacheKey = QLatin1String("qt_mac_constructQIconFromIconRef") + QString::number(standardIcon) + QString::number(size.width());
5717 mainIcon = theme->standardPixmap(sp, QSizeF(size));
5718 } else if (QPixmapCache::find(cacheKey, &mainIcon) == false) {
5719 mainIcon = theme->standardPixmap(sp, QSizeF(size));
5720 QPixmapCache::insert(cacheKey, mainIcon);
5721 }
5722
5723 retIcon.addPixmap(mainIcon);
5724 }
5725 if (!retIcon.isNull())
5726 return retIcon;
5727 }
5728
5729 default:
5730 break;
5731 }
5732 } // if (QGuiApplication::desktopSettingsAware())
5733#endif // Q_OS_MAC
5734
5735 switch (standardIcon) {
5736#ifndef QT_NO_IMAGEFORMAT_PNG
5738 addIconFiles(iconResourcePrefix() + QStringLiteral("titlebar-min-"),
5739 titleBarSizes, sizeof(titleBarSizes)/sizeof(titleBarSizes[0]), icon);
5740 break;
5742 addIconFiles(iconResourcePrefix() + QStringLiteral("titlebar-max-"),
5743 titleBarSizes, sizeof(titleBarSizes)/sizeof(titleBarSizes[0]), icon);
5744 break;
5746 addIconFiles(iconResourcePrefix() + QStringLiteral("titlebar-shade-"),
5747 titleBarSizes, sizeof(titleBarSizes)/sizeof(titleBarSizes[0]), icon);
5748
5749 break;
5751 addIconFiles(iconResourcePrefix() + QStringLiteral("titlebar-unshade-"),
5752 titleBarSizes, sizeof(titleBarSizes)/sizeof(titleBarSizes[0]), icon);
5753 break;
5755 addIconFiles(iconResourcePrefix() + QStringLiteral("titlebar-contexthelp-"),
5756 titleBarSizes, sizeof(titleBarSizes)/sizeof(titleBarSizes[0]), icon);
5757 break;
5759 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/newdirectory-16.png"), QSize(16, 16));
5760 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/newdirectory-32.png"), QSize(32, 32));
5761 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/newdirectory-128.png"), QSize(128, 128));
5762 break;
5763 case SP_FileDialogBack:
5768 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewdetailed-16.png"), QSize(16, 16));
5769 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewdetailed-32.png"), QSize(32, 32));
5770 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewdetailed-128.png"), QSize(128, 128));
5771 break;
5773 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/fileinfo-16.png"), QSize(16, 16));
5774 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/fileinfo-32.png"), QSize(32, 32));
5775 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/fileinfo-128.png"), QSize(128, 128));
5776 break;
5778 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filecontents-16.png"), QSize(16, 16));
5779 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filecontents-32.png"), QSize(32, 32));
5780 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filecontents-128.png"), QSize(128, 128));
5781 break;
5783 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewlist-16.png"), QSize(16, 16));
5784 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewlist-32.png"), QSize(32, 32));
5785 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/viewlist-128.png"), QSize(128, 128));
5786 break;
5787 case SP_DialogOkButton:
5788 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-ok-16.png"), QSize(16, 16));
5789 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-ok-32.png"), QSize(32, 32));
5790 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-ok-128.png"), QSize(128, 128));
5791 break;
5793 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-16.png"), QSize(16, 16));
5794 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-32.png"), QSize(32, 32));
5795 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-cancel-128.png"), QSize(128, 128));
5796 break;
5798 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-help-16.png"), QSize(16, 16));
5799 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-help-32.png"), QSize(32, 32));
5800 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-help-128.png"), QSize(128, 128));
5801 break;
5803 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-open-16.png"), QSize(16, 16));
5804 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-open-32.png"), QSize(32, 32));
5805 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-open-128.png"), QSize(128, 128));
5806 break;
5808 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-save-16.png"), QSize(16, 16));
5809 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-save-32.png"), QSize(32, 32));
5810 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-save-128.png"), QSize(128, 128));
5811 break;
5813 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-close-16.png"), QSize(16, 16));
5814 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-close-32.png"), QSize(32, 32));
5815 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-close-128.png"), QSize(128, 128));
5816 break;
5818 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-apply-16.png"), QSize(16, 16));
5819 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-apply-32.png"), QSize(32, 32));
5820 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-apply-128.png"), QSize(128, 128));
5821 break;
5823 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-clear-16.png"), QSize(16, 16));
5824 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-clear-32.png"), QSize(32, 32));
5825 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-clear-128.png"), QSize(128, 128));
5826 break;
5828 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-delete-16.png"), QSize(16, 16));
5829 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-delete-32.png"), QSize(32, 32));
5830 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-delete-128.png"), QSize(128, 128));
5831 break;
5832 case SP_DialogYesButton:
5833 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-yes-16.png"), QSize(16, 16));
5834 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-yes-32.png"), QSize(32, 32));
5835 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-yes-128.png"), QSize(128, 128));
5836 break;
5837 case SP_DialogNoButton:
5838 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-no-16.png"), QSize(16, 16));
5839 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-no-32.png"), QSize(32, 32));
5840 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/standardbutton-no-128.png"), QSize(128, 128));
5841 break;
5842 case SP_ArrowForward:
5843 if (rtl)
5846 case SP_ArrowBack:
5847 if (rtl)
5850 case SP_ArrowLeft:
5851 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/left-16.png"), QSize(16, 16));
5852 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/left-32.png"), QSize(32, 32));
5853 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/left-128.png"), QSize(128, 128));
5854 break;
5855 case SP_ArrowRight:
5856 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/right-16.png"), QSize(16, 16));
5857 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/right-32.png"), QSize(32, 32));
5858 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/right-128.png"), QSize(128, 128));
5859 break;
5860 case SP_ArrowUp:
5861 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/up-16.png"), QSize(16, 16));
5862 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/up-32.png"), QSize(32, 32));
5863 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/up-128.png"), QSize(128, 128));
5864 break;
5865 case SP_ArrowDown:
5866 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/down-16.png"), QSize(16, 16));
5867 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/down-32.png"), QSize(32, 32));
5868 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/down-128.png"), QSize(128, 128));
5869 break;
5870 case SP_DirHomeIcon:
5871 case SP_DirIcon:
5872 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dirclosed-16.png"),
5874 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/diropen-16.png"),
5876 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dirclosed-32.png"),
5877 QSize(32, 32), QIcon::Normal, QIcon::Off);
5878 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/diropen-32.png"),
5879 QSize(32, 32), QIcon::Normal, QIcon::On);
5880 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dirclosed-128.png"),
5881 QSize(128, 128), QIcon::Normal, QIcon::Off);
5882 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/diropen-128.png"),
5883 QSize(128, 128), QIcon::Normal, QIcon::On);
5884 break;
5885 case SP_DriveCDIcon:
5886 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/cdr-16.png"), QSize(16, 16));
5887 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/cdr-32.png"), QSize(32, 32));
5888 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/cdr-128.png"), QSize(128, 128));
5889 break;
5890 case SP_DriveDVDIcon:
5891 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dvd-16.png"), QSize(16, 16));
5892 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dvd-32.png"), QSize(32, 32));
5893 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/dvd-128.png"), QSize(128, 128));
5894 break;
5895 case SP_FileIcon:
5896 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"), QSize(16, 16));
5897 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-32.png"), QSize(32, 32));
5898 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-128.png"), QSize(128, 128));
5899 break;
5900 case SP_FileLinkIcon:
5901 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filelink-16.png"), QSize(16, 16));
5902 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filelink-32.png"), QSize(32, 32));
5903 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/filelink-128.png"), QSize(128, 128));
5904 break;
5905 case SP_TrashIcon:
5906 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/trash-16.png"), QSize(16, 16));
5907 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/trash-32.png"), QSize(32, 32));
5908 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/trash-128.png"), QSize(128, 128));
5909 break;
5910 case SP_BrowserReload:
5911 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/refresh-24.png"), QSize(24, 24));
5912 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/refresh-32.png"), QSize(32, 32));
5913 break;
5914 case SP_BrowserStop:
5915 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/stop-24.png"), QSize(24, 24));
5916 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/stop-32.png"), QSize(32, 32));
5917 break;
5918 case SP_MediaPlay:
5919 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-play-16.png"), QSize(16, 16));
5920 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-play-32.png"), QSize(32, 32));
5921 break;
5922 case SP_MediaPause:
5923 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-pause-16.png"), QSize(16, 16));
5924 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-pause-32.png"), QSize(32, 32));
5925 break;
5926 case SP_MediaStop:
5927 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-stop-16.png"), QSize(16, 16));
5928 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-stop-32.png"), QSize(32, 32));
5929 break;
5931 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-forward-16.png"), QSize(16, 16));
5932 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-forward-32.png"), QSize(32, 32));
5933 break;
5935 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-backward-16.png"), QSize(16, 16));
5936 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-seek-backward-32.png"), QSize(32, 32));
5937 break;
5939 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-forward-16.png"), QSize(16, 16));
5940 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-forward-32.png"), QSize(32, 32));
5941 break;
5943 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-backward-16.png"), QSize(16, 16));
5944 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-skip-backward-32.png"), QSize(32, 32));
5945 break;
5946 case SP_MediaVolume:
5947 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-16.png"), QSize(16, 16));
5948 break;
5950 icon.addFile(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"), QSize(16, 16));
5951 break;
5953 addIconFiles(iconResourcePrefix() + QStringLiteral("closedock-"),
5954 dockTitleIconSizes, sizeof(dockTitleIconSizes)/sizeof(dockTitleIconSizes[0]), icon);
5955 break;
5957# ifndef QT_NO_IMAGEFORMAT_XPM
5958 icon.addPixmap(titleBarMenuCachedPixmapFromXPM());
5959# endif
5960 icon.addFile(QLatin1String(":/qt-project.org/qmessagebox/images/qtlogo-64.png"));
5961 break;
5963 addIconFiles(iconResourcePrefix() + QStringLiteral("normalizedockup-"),
5964 dockTitleIconSizes, sizeof(dockTitleIconSizes)/sizeof(dockTitleIconSizes[0]), icon);
5965 break;
5967 QString prefix = iconResourcePrefix() + QStringLiteral("toolbar-ext-h-");
5968 if (rtl)
5969 prefix += QStringLiteral("rtl-");
5970 addIconFiles(prefix, toolBarExtHSizes, sizeof(toolBarExtHSizes)/sizeof(toolBarExtHSizes[0]), icon);
5971 }
5972 break;
5974 addIconFiles(iconResourcePrefix() + QStringLiteral("toolbar-ext-v-"),
5975 toolBarExtVSizes, sizeof(toolBarExtVSizes)/sizeof(toolBarExtVSizes[0]), icon);
5976 break;
5977#endif // QT_NO_IMAGEFORMAT_PNG
5978 default:
5980 break;
5981 }
5982 return icon;
5983}
5984
5985static inline uint qt_intensity(uint r, uint g, uint b)
5986{
5987 // 30% red, 59% green, 11% blue
5988 return (77 * r + 150 * g + 28 * b) / 255;
5989}
5990
5993 const QStyleOption *opt) const
5994{
5995 switch (iconMode) {
5996 case QIcon::Disabled: {
5998
5999 // Create a colortable based on the background (black -> bg -> white)
6001 int red = bg.red();
6002 int green = bg.green();
6003 int blue = bg.blue();
6004 uchar reds[256], greens[256], blues[256];
6005 for (int i=0; i<128; ++i) {
6006 reds[i] = uchar((red * (i<<1)) >> 8);
6007 greens[i] = uchar((green * (i<<1)) >> 8);
6008 blues[i] = uchar((blue * (i<<1)) >> 8);
6009 }
6010 for (int i=0; i<128; ++i) {
6011 reds[i+128] = uchar(qMin(red + (i << 1), 255));
6012 greens[i+128] = uchar(qMin(green + (i << 1), 255));
6013 blues[i+128] = uchar(qMin(blue + (i << 1), 255));
6014 }
6015
6016 int intensity = qt_intensity(red, green, blue);
6017 const int factor = 191;
6018
6019 // High intensity colors needs dark shifting in the color table, while
6020 // low intensity colors needs light shifting. This is to increase the
6021 // perceived contrast.
6022 if ((red - factor > green && red - factor > blue)
6023 || (green - factor > red && green - factor > blue)
6024 || (blue - factor > red && blue - factor > green))
6025 intensity = qMin(255, intensity + 91);
6026 else if (intensity <= 128)
6027 intensity -= 51;
6028
6029 for (int y=0; y<im.height(); ++y) {
6030 QRgb *scanLine = (QRgb*)im.scanLine(y);
6031 for (int x=0; x<im.width(); ++x) {
6032 QRgb pixel = *scanLine;
6033 // Calculate color table index, taking intensity adjustment
6034 // and a magic offset into account.
6035 uint ci = uint(qGray(pixel)/3 + (130 - intensity / 3));
6036 *scanLine = qRgba(reds[ci], greens[ci], blues[ci], qAlpha(pixel));
6037 ++scanLine;
6038 }
6039 }
6040
6041 return QPixmap::fromImage(std::move(im));
6042 }
6043 case QIcon::Selected: {
6046 color.setAlphaF(0.3f);
6049 painter.fillRect(0, 0, img.width(), img.height(), color);
6050 painter.end();
6051 return QPixmap::fromImage(std::move(img)); }
6052 case QIcon::Active:
6053 return pixmap;
6054 default:
6055 break;
6056 }
6057 return pixmap;
6058}
6059
6060} // namespace QQC2
6061
6063
6064#include "moc_qquickcommonstyle.cpp"
QIcon icon
the icon shown on the button
QSize iconSize
the icon size used for this button.
QString text
the text shown on the button
\inmodule QtGui
Definition qbrush.h:30
const QColor & color() const
Returns the brush color.
Definition qbrush.h:121
\inmodule QtCore
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setAlphaF(float alpha)
Sets the alpha of this color to alpha.
Definition qcolor.cpp:1511
QColor toRgb() const noexcept
Create and returns an RGB QColor based on this color.
Definition qcolor.cpp:2035
QRgb rgba() const noexcept
Returns the RGB value of the color, including its alpha.
Definition qcolor.cpp:1376
int red() const noexcept
Returns the red color component of this color.
Definition qcolor.cpp:1528
int blue() const noexcept
Returns the blue color component of this color.
Definition qcolor.cpp:1583
int green() const noexcept
Returns the green color component of this color.
Definition qcolor.cpp:1555
void getHsv(int *h, int *s, int *v, int *a=nullptr) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
Definition qcolor.cpp:1045
bool isValid() const noexcept
Returns true if the color is valid; otherwise returns false.
Definition qcolor.h:285
@ MouseButtonPress
Definition qcoreevent.h:60
Definition qflags.h:17
\reentrant \inmodule QtGui
int height() const
Returns the height of the font.
QRect boundingRect(QChar) const
Returns the rectangle that is covered by ink if character ch were to be drawn at the origin of the co...
\reentrant
Definition qfont.h:22
void setBold(bool)
If enable is true sets the font's weight to \l{Weight}{QFont::Bold}; otherwise sets the weight to \l{...
Definition qfont.h:373
int midLineWidth
the width of the mid-line
Definition qframe.h:23
int lineWidth
the line width
Definition qframe.h:22
static QPlatformTheme * platformTheme()
static QFont font()
Returns the default application font.
static bool isRightToLeft()
Returns true if the application's layout direction is Qt::RightToLeft; otherwise returns false.
static bool desktopSettingsAware()
Returns true if Qt is set to use the system's standard colors, fonts, etc.; otherwise returns false.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
static bool hasThemeIcon(const QString &name)
Definition qicon.cpp:1401
static QString themeName()
Definition qicon.cpp:1274
void addPixmap(const QPixmap &pixmap, Mode mode=Normal, State state=Off)
Adds pixmap to the icon, as a specialization for mode and state.
Definition qicon.cpp:1060
bool isNull() const
Returns true if the icon is empty; otherwise returns false.
Definition qicon.cpp:1019
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition qicon.h:22
@ Disabled
Definition qicon.h:22
@ Selected
Definition qicon.h:22
@ Normal
Definition qicon.h:22
@ Active
Definition qicon.h:22
void addFile(const QString &fileName, const QSize &size=QSize(), Mode mode=Normal, State state=Off)
Adds an image from the file with the given fileName to the icon, as a specialization for size,...
Definition qicon.cpp:1113
State
This enum describes the state for which a pixmap is intended to be used.
Definition qicon.h:23
@ Off
Definition qicon.h:23
@ On
Definition qicon.h:23
QSize actualSize(const QSize &size, Mode mode=Normal, State state=Off) const
Returns the actual size of the icon for the requested size, mode, and state.
Definition qicon.cpp:926
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Returns a pixmap with the requested size, mode, and state, generating one if necessary.
Definition qicon.cpp:834
static QIcon fromTheme(const QString &name)
Definition qicon.cpp:1344
\inmodule QtGui
Definition qimage.h:37
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition qimage.cpp:1637
int width() const
Returns the width of the image.
int height() const
Returns the height of the image.
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
@ Format_ARGB32
Definition qimage.h:47
QImage mirrored(bool horizontally=false, bool vertically=true) const &
Definition qimage.h:219
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
Definition qimage.h:125
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
\inmodule QtGui
Definition qbrush.h:394
\inmodule QtCore
Definition qmargins.h:24
constexpr int bottom() const noexcept
Returns the bottom margin.
Definition qmargins.h:115
constexpr int left() const noexcept
Returns the left margin.
Definition qmargins.h:106
constexpr int right() const noexcept
Returns the right margin.
Definition qmargins.h:112
constexpr int top() const noexcept
Returns the top margin.
Definition qmargins.h:109
\inmodule QtGui
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device.
@ Antialiasing
Definition qpainter.h:52
bool end()
Ends painting.
@ CompositionMode_SourceAtop
Definition qpainter.h:107
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
The QPalette class contains color groups for each widget state.
Definition qpalette.h:19
const QBrush & button() const
Returns the button brush of the current color group.
Definition qpalette.h:84
const QBrush & text() const
Returns the text foreground brush of the current color group.
Definition qpalette.h:88
const QBrush & toolTipBase() const
Definition qpalette.h:91
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition qpalette.h:83
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition qpalette.h:86
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition qpalette.cpp:748
const QBrush & toolTipText() const
Definition qpalette.h:92
const QBrush & light() const
Returns the light brush of the current color group.
Definition qpalette.h:85
void setCurrentColorGroup(ColorGroup cg)
Set the palette's current color group to cg.
Definition qpalette.h:65
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition qpalette.h:67
const QBrush & mid() const
Returns the mid brush of the current color group.
Definition qpalette.h:87
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette.
Definition qpalette.h:151
ColorGroup
\value Disabled \value Active \value Inactive \value Normal synonym for Active
Definition qpalette.h:49
@ Inactive
Definition qpalette.h:49
@ Disabled
Definition qpalette.h:49
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition qpalette.h:146
const QBrush & window() const
Returns the window (general background) brush of the current color group.
Definition qpalette.h:93
const QBrush & base() const
Returns the base brush of the current color group.
Definition qpalette.h:89
@ HighlightedText
Definition qpalette.h:53
@ AlternateBase
Definition qpalette.h:55
@ ButtonText
Definition qpalette.h:52
@ WindowText
Definition qpalette.h:51
@ Highlight
Definition qpalette.h:53
const QBrush & buttonText() const
Returns the button text foreground brush of the current color group.
Definition qpalette.h:96
const QBrush & highlightedText() const
Returns the highlighted text brush of the current color group.
Definition qpalette.h:99
\inmodule QtGui
Definition qpen.h:28
void setWidth(int width)
Sets the pen width to the given width in pixels with integer precision.
Definition qpen.cpp:592
void setColor(const QColor &color)
Sets the color of this pen's brush to the given color.
Definition qpen.cpp:705
static bool find(const QString &key, QPixmap *pixmap)
Looks for a cached pixmap associated with the given key in the cache.
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
Definition qpixmap.h:27
int height() const
Returns the height of the pixmap.
Definition qpixmap.cpp:480
QSize size() const
Returns the size of the pixmap.
Definition qpixmap.cpp:493
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition qpixmap.cpp:456
int width() const
Returns the width of the pixmap.
Definition qpixmap.cpp:468
qreal devicePixelRatio() const
Returns the device pixel ratio for the pixmap.
Definition qpixmap.cpp:576
static QPixmap fromImage(const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
Converts the given image to a pixmap using the specified flags to control the conversion.
Definition qpixmap.cpp:1437
The QPlatformTheme class allows customizing the UI based on themes.
virtual QVariant themeHint(ThemeHint hint) const
static QVariant defaultThemeHint(ThemeHint hint)
ThemeHint
This enum describes the available theme hints.
@ DialogButtonBoxButtonsHaveIcons
@ ItemViewActivateItemOnSingleClick
\inmodule QtCore\reentrant
Definition qpoint.h:217
\inmodule QtCore\reentrant
Definition qpoint.h:25
The QPolygon class provides a list of points using integer precision.
Definition qpolygon.h:23
Q_GUI_EXPORT void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition qpolygon.cpp:253
QString calculateElidedText(const QString &text, const QTextOption &textOption, const QFont &font, const QRect &textRect, const Qt::Alignment valign, Qt::TextElideMode textElideMode, int flags, bool lastVisibleLineShouldBeElided, QPointF *paintStartPosition) const
QString toolButtonElideText(const QStyleOptionToolButton *toolbutton, const QRect &textRect, int flags) const
virtual void tabLayout(const QStyleOptionTab *opt, QRect *textRect, QRect *pixmapRect) const
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const override
QMargins ninePatchMargins(ControlElement ce, const QStyleOption *opt, const QSize &imageSize) const override
QRect subElementRect(SubElement r, const QStyleOption *opt) const override
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p) const override
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt) const override
\reimp
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const override
\reimp
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *opt=nullptr) const override
int styleHint(StyleHint sh, const QStyleOption *opt=nullptr, QStyleHintReturn *shret=nullptr) const override
QPixmap standardPixmap(StandardPixmap sp, const QStyleOption *opt=nullptr) const override
int pixelMetric(PixelMetric m, const QStyleOption *opt=nullptr) const override
QFont font(ControlElement element, const QStyle::State state) const override
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize) const override
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const override
\reimp
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const override
\reimp
const QStyle * proxy() const
virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt=nullptr) const =0
virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr) const =0
virtual ~QStyle()
Destroys the style object.
@ SC_TitleBarNormalButton
@ SC_TitleBarUnshadeButton
@ SC_ComboBoxListBoxPopup
@ SC_TitleBarContextHelpButton
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment,...
virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
Returns the area within the given rectangle in which to draw the provided text according to the speci...
@ SE_DockWidgetTitleBarText
@ SE_TabBarScrollLeftButton
@ SE_TabWidgetRightCorner
@ SE_ItemViewItemDecoration
@ SE_RadioButtonIndicator
@ SE_ItemViewItemFocusRect
@ SE_TabBarTabRightButton
@ SE_RadioButtonFocusRect
@ SE_RadioButtonClickRect
@ SE_DockWidgetCloseButton
@ SE_TabBarScrollRightButton
@ SE_DockWidgetFloatButton
@ SE_TreeViewDisclosureItem
@ SE_TabWidgetTabContents
@ SE_ItemViewItemCheckIndicator
virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p) const =0
static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment, const QSize &size, const QRect &rectangle)
Returns a new rectangle of the specified size that is aligned to the given rectangle according to the...
virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p) const =0
static int sliderPositionFromValue(int min, int max, int val, int space, bool upsideDown=false)
Converts the given logicalValue to a pixel position.
virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc) const =0
static QRect visualRect(Qt::LayoutDirection direction, const QRect &boundingRect, const QRect &logicalRect)
Returns the given logicalRectangle converted to screen coordinates based on the specified direction.
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option) const =0
@ SH_Splitter_OpaqueResize
@ SH_TitleBar_ModifyNotification
@ SH_DialogButtonBox_ButtonsHaveIcons
@ SH_TabBar_SelectMouseType
@ SH_Menu_SubMenuSloppyCloseTimeout
@ SH_ItemView_EllipsisLocation
@ SH_BlinkCursorWhenTextSelected
@ SH_LineEdit_PasswordMaskDelay
@ SH_ToolBox_SelectedPageTitleBold
@ SH_Slider_AbsoluteSetButtons
@ SH_ItemView_ArrowKeysNavigateIntoChildren
@ SH_FormLayoutWrapPolicy
@ SH_ItemView_MovementWithoutUpdatingSelection
@ SH_Menu_FillScreenWithScroll
@ SH_TitleBar_ShowToolTipsOnButtons
@ SH_GroupBox_TextLabelColor
@ SH_Header_ArrowAlignment
@ SH_FormLayoutLabelAlignment
@ SH_ScrollBar_RollBetweenButtons
@ SH_TabWidget_DefaultTabPosition
@ SH_GroupBox_TextLabelVerticalAlignment
@ SH_MessageBox_TextInteractionFlags
@ SH_ItemView_ShowDecorationSelected
@ SH_ComboBox_LayoutDirection
@ SH_ProgressDialog_TextLabelAlignment
@ SH_RequestSoftwareInputPanel
@ SH_ToolTip_FallAsleepDelay
@ SH_ItemView_ActivateItemOnSingleClick
@ SH_SpinBox_ClickAutoRepeatThreshold
@ SH_ComboBox_PopupFrameStyle
@ SH_FormLayoutFormAlignment
@ SH_TextControl_FocusIndicatorTextCharFormat
@ SH_ScrollBar_ContextMenu
@ SH_Slider_PageSetButtons
@ SH_Menu_SubMenuUniDirectionFailCount
@ SH_ListViewExpand_SelectMouseType
@ SH_FormLayoutFieldGrowthPolicy
@ SH_ToolButton_PopupDelay
@ SH_SpellCheckUnderlineStyle
@ SH_SpinBox_ButtonsInsideFrame
@ SH_MessageBox_UseBorderForButtonSpacing
@ SH_TabBar_CloseButtonPosition
@ SH_Menu_SubMenuSloppySelectOtherActions
@ SH_MessageBox_CenterButtons
@ SH_DockWidget_ButtonsHaveFrame
@ SH_SpinBox_ClickAutoRepeatRate
@ SH_FocusFrame_AboveWidget
@ SH_Widget_Animation_Duration
@ SH_SpinControls_DisableOnBounds
@ SH_Menu_SupportsSections
@ SH_ItemView_DrawDelegateFrame
@ SH_ComboBox_AllowWheelScrolling
@ SH_Menu_SubMenuDontStartSloppyOnLeave
@ SH_TabBar_ChangeCurrentDelay
@ SH_LineEdit_PasswordCharacter
@ SH_Menu_SubMenuResetWhenReenteringParent
@ SH_ToolTipLabel_Opacity
@ SH_Menu_SubMenuUniDirection
@ SH_SpinBox_StepModifier
@ SH_SpinBox_KeyPressAutoRepeatRate
@ SH_Menu_SubMenuPopupDelay
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt=nullptr, QStyleHintReturn *returnData=nullptr) const =0
@ State_KeyboardFocusChange
Definition qquickstyle.h:65
@ PE_IndicatorItemViewItemCheck
@ PE_IndicatorHeaderArrow
@ PE_IndicatorRadioButton
@ PE_PanelButtonCommand
Definition qquickstyle.h:91
@ PE_IndicatorArrowLeft
Definition qquickstyle.h:99
@ PE_PanelScrollAreaCorner
@ PE_IndicatorToolBarHandle
@ PE_FrameStatusBarItem
Definition qquickstyle.h:84
@ PE_IndicatorButtonDropDown
@ PE_IndicatorColumnViewArrow
@ PE_IndicatorMenuCheckMark
@ PE_IndicatorToolBarSeparator
@ PE_IndicatorItemViewItemDrop
@ PE_FrameDefaultButton
Definition qquickstyle.h:78
@ PE_IndicatorProgressChunk
@ PE_IndicatorArrowDown
Definition qquickstyle.h:98
virtual QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=nullptr) const =0
@ PM_TabBarTabShiftHorizontal
@ PM_DialogButtonsButtonWidth
@ PM_LayoutVerticalSpacing
@ PM_RadioButtonLabelSpacing
@ PM_DefaultLayoutSpacing
@ PM_ToolBarSeparatorExtent
@ PM_ButtonDefaultIndicator
@ PM_ScrollView_ScrollBarOverlap
@ PM_TabCloseIndicatorWidth
@ PM_DialogButtonsSeparator
@ PM_TitleBarButtonIconSize
@ PM_DefaultTopLevelMargin
@ PM_ToolBarExtensionExtent
@ PM_HeaderDefaultSectionSizeHorizontal
@ PM_SliderTickmarkOffset
@ PM_MdiSubWindowFrameWidth
@ PM_SliderSpaceAvailable
@ PM_ScrollView_ScrollBarSpacing
@ PM_ProgressBarChunkWidth
@ PM_CheckBoxLabelSpacing
@ PM_TabBarScrollButtonWidth
@ PM_MenuDesktopFrameWidth
@ PM_DockWidgetHandleExtent
@ PM_TabCloseIndicatorHeight
@ PM_DockWidgetTitleBarButtonMargin
@ PM_TabBar_ScrollButtonOverlap
@ PM_DialogButtonsButtonHeight
@ PM_ExclusiveIndicatorHeight
@ PM_LayoutHorizontalSpacing
@ PM_MdiSubWindowMinimizedWidth
@ PM_ExclusiveIndicatorWidth
@ PM_ButtonShiftHorizontal
@ PM_SliderControlThickness
@ PM_DockWidgetFrameWidth
@ PM_DockWidgetSeparatorExtent
@ PM_ToolTipLabelFrameWidth
@ PM_TabBarTabShiftVertical
@ PM_HeaderDefaultSectionSizeVertical
@ PM_DockWidgetTitleMargin
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
@ SP_TitleBarContextHelpButton
@ SP_MessageBoxInformation
@ SP_FileDialogDetailedView
@ SP_FileDialogContentsView
@ SP_ToolBarVerticalExtensionButton
@ SP_TitleBarNormalButton
@ SP_TitleBarUnshadeButton
@ SP_DockWidgetCloseButton
@ SP_ToolBarHorizontalExtensionButton
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
Definition qrect.h:167
constexpr void adjust(int x1, int y1, int x2, int y2) noexcept
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition qrect.h:373
constexpr void getRect(int *x, int *y, int *w, int *h) const
Extracts the position of the rectangle's top-left corner to *x and *y, and its dimensions to *width a...
Definition qrect.h:338
constexpr int height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:239
constexpr bool isValid() const noexcept
Returns true if the rectangle is valid, otherwise returns false.
Definition qrect.h:170
QRect intersected(const QRect &other) const noexcept
Definition qrect.h:415
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:182
constexpr void setRight(int pos) noexcept
Sets the right edge of the rectangle to the given x coordinate.
Definition qrect.h:197
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr QRect adjusted(int x1, int y1, int x2, int y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition qrect.h:370
constexpr int top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:176
constexpr void setLeft(int pos) noexcept
Sets the left edge of the rectangle to the given x coordinate.
Definition qrect.h:191
constexpr int left() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:173
constexpr void setRect(int x, int y, int w, int h) noexcept
Sets the coordinates of the rectangle's top-left corner to ({x}, {y}), and its size to the given widt...
Definition qrect.h:346
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr void setWidth(int w) noexcept
Sets the width of the rectangle to the given width.
Definition qrect.h:381
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr void translate(int dx, int dy) noexcept
Moves the rectangle dx along the x axis and dy along the y axis, relative to the current position.
Definition qrect.h:245
constexpr void setCoords(int x1, int y1, int x2, int y2) noexcept
Sets the coordinates of the rectangle's top-left corner to (x1, y1), and the coordinates of its botto...
Definition qrect.h:362
constexpr QPoint bottomRight() const noexcept
Returns the position of the rectangle's bottom-right corner.
Definition qrect.h:224
constexpr int width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:236
QRect united(const QRect &other) const noexcept
Definition qrect.h:420
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr void setHeight(int h) noexcept
Sets the height of the rectangle to the given height.
Definition qrect.h:384
constexpr QPoint center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:233
constexpr int right() const noexcept
Returns the x-coordinate of the rectangle's right edge.
Definition qrect.h:179
constexpr void setTop(int pos) noexcept
Sets the top edge of the rectangle to the given y coordinate.
Definition qrect.h:194
The QRegion class specifies a clip region for a painter.
Definition qregion.h:27
\inmodule QtCore
Definition qsize.h:208
\inmodule QtCore
Definition qsize.h:25
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr QSize transposed() const noexcept
Definition qsize.h:142
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
Definition qsize.h:139
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString & replace(qsizetype i, qsizetype len, QChar after)
Definition qstring.cpp:3824
void chop(qsizetype n)
Removes n characters from the end of the string.
Definition qstring.cpp:6340
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition qstring.cpp:5506
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:8084
static QString static QString asprintf(const char *format,...) Q_ATTRIBUTE_FORMAT_PRINTF(1
Definition qstring.cpp:7263
ButtonFeatures features
QFontMetrics fontMetrics
QStyle::State state
QPalette palette
Qt::LayoutDirection direction
void setProperty(int propertyId, const QVariant &value)
Sets the property specified by the propertyId to the given value.
\reentrant
Definition qtextlayout.h:70
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
void beginLayout()
Begins the layout process.
QString text() const
Returns the layout's text.
int lineCount() const
Returns the number of lines in this text layout.
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
void setTextOption(const QTextOption &option)
Sets the text option structure that controls the layout process to the given option.
void draw(QPainter *p, const QPointF &pos, const QList< FormatRange > &selections=QList< FormatRange >(), const QRectF &clip=QRectF()) const
Draws the whole layout on the painter p at the position specified by pos.
void endLayout()
Ends the layout process.
QRectF boundingRect() const
The smallest rectangle that contains all the lines in the layout.
\reentrant
qreal height() const
Returns the line's height.
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
\reentrant
Definition qtextoption.h:18
void setTextDirection(Qt::LayoutDirection aDirection)
Sets the direction of the text layout defined by the option to the given direction.
Definition qtextoption.h:57
void setWrapMode(WrapMode wrap)
Sets the option's text wrap mode to the given mode.
Definition qtextoption.h:67
void setAlignment(Qt::Alignment alignment)
Sets the option's text alignment to the specified alignment.
The QTransform class specifies 2D transformations of a coordinate system.
Definition qtransform.h:20
static QTransform fromTranslate(qreal dx, qreal dy)
Creates a matrix which corresponds to a translation of dx along the x axis and dy along the y axis.
\inmodule QtCore
Definition qvariant.h:65
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
QPalette palette
the widget's palette
Definition qwidget.h:132
QFontMetrics fontMetrics() const
Returns the font metrics for the widget's current font.
Definition qwidget.h:847
QRect rect
the internal geometry of the widget excluding any window frame
Definition qwidget.h:116
\inmodule QtGui
Definition qwindow.h:63
QPixmap p2
QPixmap p1
[0]
QString text
qreal spacing
QPushButton * button
[2]
opt iconSize
rect
[4]
QPixmap pix
QStyleOptionButton subopt
[2]
uint alignment
QStyleOptionButton opt
fontMetrics
else opt state
[0]
QRect textRect
const QStyleOptionButton * btn
[3]
struct wl_display * display
Definition linuxdmabuf.h:41
QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size)
int calcBigLineSize(int radius)
QPolygonF calcLines(const QStyleOptionSlider *dial)
qreal dpi(const QStyleOption *option)
qreal dpiScaled(qreal value, qreal dpi)
qreal angle(const QPointF &p1, const QPointF &p2)
static const char *const question_xpm[]
static uint qt_intensity(uint r, uint g, uint b)
static const char *const filedialog_end_xpm[]
static const char *const dock_widget_close_xpm[]
static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbutton, const QRect &rect, QPainter *painter)
void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth, const QBrush *fill)
void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth)
void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, int lineWidth, const QBrush *fill)
static const char *const qt_close_xpm[]
static const char *const qt_help_xpm[]
static const char *const qt_menu_xpm[]
static const char *const qt_unshade_xpm[]
static const char *const qt_normalizeup_xpm[]
static StaticPolygonF< 3 > calcArrow(const QStyleOptionSlider *dial, qreal &a)
static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth, int maxHeight=-1, int *lastVisibleLine=nullptr)
static const char *const information_xpm[]
static const char *const qt_shade_xpm[]
static const char *const qt_maximize_xpm[]
static const char *const qt_minimize_xpm[]
static const char *const critical_xpm[]
static const char *const warning_xpm[]
static QString clearText16IconPath()
static const char *const filedialog_start_xpm[]
static const char *const tb_extension_arrow_h_xpm[]
void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, const QBrush *fill)
static const char *const tb_extension_arrow_v_xpm[]
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Combined button and popup list for selecting options.
@ WindowMinimized
Definition qnamespace.h:253
@ WindowMaximized
Definition qnamespace.h:254
@ BottomLeftCorner
@ TopRightCorner
@ TopLeftCorner
@ BottomRightCorner
@ Unchecked
@ Checked
@ PartiallyChecked
@ AlignRight
Definition qnamespace.h:146
@ AlignVCenter
Definition qnamespace.h:155
@ AlignTop
Definition qnamespace.h:153
@ AlignTrailing
Definition qnamespace.h:147
@ AlignHCenter
Definition qnamespace.h:148
@ AlignCenter
Definition qnamespace.h:163
@ AlignAbsolute
Definition qnamespace.h:150
@ AlignLeft
Definition qnamespace.h:144
@ LeftButton
Definition qnamespace.h:58
@ MiddleButton
Definition qnamespace.h:60
@ LinksAccessibleByMouse
LayoutDirection
@ LeftToRight
@ LayoutDirectionAuto
@ RightToLeft
@ StrongFocus
Definition qnamespace.h:110
@ Horizontal
Definition qnamespace.h:99
@ UpArrow
@ RightArrow
@ LeftArrow
@ DownArrow
@ TextSingleLine
Definition qnamespace.h:170
@ TextDontClip
Definition qnamespace.h:171
@ TextHideMnemonic
Definition qnamespace.h:178
@ TextShowMnemonic
Definition qnamespace.h:173
@ OpaqueMode
Definition qnamespace.h:508
@ white
Definition qnamespace.h:31
@ black
Definition qnamespace.h:30
@ DotLine
@ DashLine
@ NoPen
@ DecorationRole
@ CheckStateRole
@ DisplayRole
@ ControlModifier
@ Dense4Pattern
@ NoBrush
@ WindowContextHelpButtonHint
Definition qnamespace.h:231
@ WindowType_Mask
Definition qnamespace.h:220
@ WindowMaximizeButtonHint
Definition qnamespace.h:229
@ WindowMinimizeButtonHint
Definition qnamespace.h:228
@ WindowShadeButtonHint
Definition qnamespace.h:232
@ Tool
Definition qnamespace.h:212
@ WindowTitleHint
Definition qnamespace.h:226
@ WindowSystemMenuHint
Definition qnamespace.h:227
TextElideMode
Definition qnamespace.h:188
@ ElideMiddle
Definition qnamespace.h:191
@ ElideRight
Definition qnamespace.h:190
@ ElideNone
Definition qnamespace.h:192
@ ToolButtonTextOnly
@ ToolButtonTextUnderIcon
@ ToolButtonIconOnly
Definition brush.cpp:5
Definition image.cpp:4
static jboolean copy(JNIEnv *, jobject)
static QString wrapText(const QString &names, int optionNameMaxWidth, const QString &description)
#define Q_FALLTHROUGH()
#define Q_DECL_CONSTEXPR
#define qApp
AudioChannelLayoutTag tag
static QString header(const QString &name)
#define QFIXED_MAX
Definition qfixed_p.h:127
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:327
static QByteArray cacheKey(Args &&...args)
#define qWarning
Definition qlogging.h:166
return ret
auto qCos(T v)
Definition qmath.h:60
int qCeil(T v)
Definition qmath.h:36
auto qSin(T v)
Definition qmath.h:54
static QT_BEGIN_NAMESPACE const qreal Q_PI
Definition qmath_p.h:24
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
static QString themeName()
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLenum mode
const GLfloat * m
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
GLuint GLfloat GLfloat GLfloat x1
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLdouble GLdouble right
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLenum GLsizei GLsizei GLsizei GLint border
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLfloat GLfloat f
GLsizei range
GLint GLsizei width
GLuint color
[2]
GLint left
GLuint GLsizei const GLchar * label
[43]
GLint GLint bottom
GLuint GLfloat x0
GLbitfield flags
GLuint start
GLenum GLuint GLintptr offset
GLboolean GLboolean g
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLsizei const GLint * box
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
GLint y
GLfloat GLfloat GLfloat GLfloat h
GLfixed GLfixed GLint GLint GLfixed points
GLdouble s
[6]
Definition qopenglext.h:235
GLbyte GLbyte blue
Definition qopenglext.h:385
GLint void * img
Definition qopenglext.h:233
GLuint GLsizei const GLuint const GLintptr const GLsizeiptr * sizes
GLfixed GLfixed x2
GLsizei const GLchar *const * path
GLuint64EXT * result
[6]
GLfloat GLfloat p
[1]
GLuint GLenum option
GLenum GLsizei len
GLbyte green
Definition qopenglext.h:385
static const QRectF boundingRect(const QPointF *points, int pointCount)
static QT_BEGIN_NAMESPACE qreal dpr(const QWindow *w)
static bool isWindow(QObject *object)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
constexpr int qGray(int r, int g, int b)
Definition qrgb.h:36
constexpr QRgb qRgba(int r, int g, int b, int a)
Definition qrgb.h:33
constexpr int qAlpha(QRgb rgb)
Definition qrgb.h:27
Int aligned(Int v, Int byteAlign)
static const struct TessellationWindingOrderTab cw[]
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
static QT_BEGIN_NAMESPACE QVariant hint(QPlatformIntegration::StyleHint h)
QT_BEGIN_NAMESPACE constexpr void qSwap(T &value1, T &value2) noexcept(std::is_nothrow_swappable_v< T >)
Definition qswap.h:20
#define sp
constexpr bool verticalTabs(QTabBar::Shape shape) noexcept
Definition qtabbar_p.h:248
#define tr(X)
#define Q_UNUSED(x)
unsigned char uchar
Definition qtypes.h:32
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
double qreal
Definition qtypes.h:187
QVideoFrameFormat::PixelFormat fmt
const char className[16]
[1]
Definition qwizard.cpp:100
QWidget * panel
Definition settings.cpp:7
obj metaObject() -> className()
p rx()++
QSharedPointer< T > other(t)
[5]
Text files * txt
widget render & pixmap
QPainter painter(this)
[7]
QFrame frame
[0]
QJSEngine engine
[0]
QGraphicsSvgItem * red
\inmodule QtCore \reentrant
Definition qchar.h:18
Q_DECL_CONSTEXPR int size() const
Q_DECL_CONSTEXPR const QPointF & operator[](int idx) const
Q_DECL_CONSTEXPR const QPointF * cbegin() const