1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the style module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qcommonstyle.h"
33
#include <qapplication.h>
36
#include <qdockwidget.h>
37
#include <qdrawutil.h>
38
#include <qgroupbox.h>
41
#include <qpaintengine.h>
42
#include <qpainterpath.h>
44
#include <qstyleoption.h>
46
#include <qtoolbutton.h>
47
#include <qrubberband.h>
48
#include <private/qcommonstylepixmaps_p.h>
49
#include <private/qdialogbuttons_p.h>
50
#include <private/qmath_p.h>
52
#include <QtCore/qdebug.h>
58
\brief The QCommonStyle class encapsulates the common Look and Feel of a GUI.
62
This abstract class implements some of the widget's look and feel
63
that is common to all GUI styles provided and shipped as part of
66
All the functions are full documented in \l{QStyle}, although the
67
extra functions that QCommonStyle provides, e.g.
68
drawComplexControl(), drawControl(), drawPrimitive(),
69
hitTestComplexControl(), subControlRect(), sizeFromContents(), and
70
subElementRect() are documented here.
74
Constructs a QCommonStyle.
76
QCommonStyle::QCommonStyle()
85
QCommonStyle::~QCommonStyle()
92
void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
93
const QWidget *widget) const
96
case PE_FrameButtonBevel:
97
case PE_FrameButtonTool:
98
qDrawShadeRect(p, opt->rect, opt->palette,
99
opt->state & (State_Sunken | State_On), 1, 0);
101
case PE_PanelButtonCommand:
102
case PE_PanelButtonBevel:
103
case PE_PanelButtonTool:
104
case PE_IndicatorButtonDropDown:
105
qDrawShadePanel(p, opt->rect, opt->palette,
106
opt->state & (State_Sunken | State_On), 1,
107
&opt->palette.brush(QPalette::Button));
109
case PE_IndicatorViewItemCheck:
110
drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
112
case PE_IndicatorCheckBox:
113
if (opt->state & State_NoChange) {
114
p->setPen(opt->palette.foreground().color());
115
p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
116
p->drawRect(opt->rect);
117
p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
119
qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(),
120
opt->palette, opt->state & (State_Sunken | State_On), 1,
121
&opt->palette.brush(QPalette::Button));
124
case PE_IndicatorRadioButton: {
125
QRect ir = opt->rect;
126
p->setPen(opt->palette.dark().color());
127
p->drawArc(opt->rect, 0, 5760);
128
if (opt->state & (State_Sunken | State_On)) {
129
ir.adjust(2, 2, -2, -2);
130
p->setBrush(opt->palette.foreground());
134
case PE_FrameFocusRect:
135
if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
136
QColor bg = fropt->backgroundColor;
137
QPen oldPen = p->pen();
140
bg.getHsv(&h, &s, &v);
142
p->setPen(Qt::black);
144
p->setPen(Qt::white);
146
p->setPen(opt->palette.foreground().color());
148
QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
149
p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
153
case PE_IndicatorMenuCheckMark: {
154
const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();
155
const int markH = markW;
156
int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;
157
int posY = opt->rect.y() + (opt->rect.height() - markH)/2;
165
for (i = 0; i < markW/2; ++i) {
166
a << QLineF(xx, yy, xx, yy + 2);
171
for (; i < markH; ++i) {
172
a << QLineF(xx, yy, xx, yy + 2);
176
if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
178
p->setPen(opt->palette.highlightedText().color());
180
for (pnt = 0; pnt < a.size(); ++pnt)
181
a[pnt].translate(offset.x(), offset.y());
183
for (pnt = 0; pnt < a.size(); ++pnt)
184
a[pnt].translate(offset.x(), offset.y());
186
p->setPen(opt->palette.text().color());
191
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
192
if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {
193
qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,
196
qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth);
200
case PE_PanelMenuBar:
201
case PE_PanelToolBar:
202
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt))
203
qDrawShadePanel(p, frame->rect, frame->palette, false, frame->lineWidth,
204
&frame->palette.brush(QPalette::Button));
206
case PE_IndicatorProgressChunk:
207
p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,
208
opt->palette.brush(QPalette::Highlight));
210
case PE_Q3CheckListController:
211
p->drawPixmap(opt->rect.topLeft(), QPixmap(check_list_controller_xpm));
213
case PE_Q3CheckListExclusiveIndicator:
214
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
215
if (lv->items.isEmpty())
217
int x = lv->rect.x(),
219
#define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)
220
static const int pts1[] = { // dark lines
221
1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
222
static const int pts2[] = { // black lines
223
2,8, 1,7, 1,4, 2,3, 2,2, 3,2, 4,1, 7,1, 8,2, 9,2 };
224
static const int pts3[] = { // background lines
225
2,9, 3,9, 4,10, 7,10, 8,9, 9,9, 9,8, 10,7, 10,4, 9,3 };
226
static const int pts4[] = { // white lines
227
2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
229
// static const int pts5[] = { // inner fill
230
// 4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
233
if (lv->state & State_Enabled)
234
p->setPen(lv->palette.text().color());
236
p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text)));
237
QPolygon a(INTARRLEN(pts1), pts1);
239
//p->setPen(pal.dark());
241
a.setPoints(INTARRLEN(pts2), pts2);
244
a.setPoints(INTARRLEN(pts3), pts3);
248
a.setPoints(INTARRLEN(pts4), pts4);
252
// a.setPoints(INTARRLEN(pts5), pts5);
253
// a.translate(x, y);
254
// QColor fillColor = isDown() ? g.background() : g.base();
255
// p->setPen(fillColor);
256
// p->setBrush(fillColor);
257
// p->drawPolygon(a);
258
if (opt->state & State_On) {
259
p->setPen(Qt::NoPen);
260
p->setBrush(opt->palette.text());
261
p->drawRect(x + 5, y + 4, 2, 4);
262
p->drawRect(x + 4, y + 5, 4, 2);
267
case PE_Q3CheckListIndicator:
268
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
269
if(lv->items.isEmpty())
271
QStyleOptionQ3ListViewItem item = lv->items.at(0);
272
int x = lv->rect.x(),
274
w = lv->rect.width(),
275
h = lv->rect.width(),
276
marg = lv->itemMargin;
278
if (lv->state & State_Enabled)
279
p->setPen(QPen(lv->palette.text().color(), 2));
281
p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text), 2));
282
if (opt->state & State_Selected && !lv->rootIsDecorated
283
&& !(item.features & QStyleOptionQ3ListViewItem::ParentControl)) {
284
p->fillRect(0, 0, x + marg + w + 4, item.height,
285
lv->palette.brush(QPalette::Highlight));
286
if (item.state & State_Enabled)
287
p->setPen(QPen(lv->palette.highlightedText().color(), 2));
290
if (lv->state & State_NoChange)
291
p->setBrush(lv->palette.brush(QPalette::Button));
292
p->drawRect(x + marg, y + 2, w - 4, h - 4);
293
/////////////////////
296
if (lv->state & State_On || lv->state & State_NoChange) {
301
for (i = 0; i < 3; ++i) {
302
lines[i] = QLineF(xx, yy, xx, yy + 2);
307
for (i = 3; i < 7; ++i) {
308
lines[i] = QLineF(xx, yy, xx, yy + 2);
312
p->drawLines(lines, 7);
316
case PE_IndicatorBranch: {
317
static QPixmap open(tree_branch_open_xpm);
318
static QPixmap closed(tree_branch_closed_xpm);
319
static const int decoration_size = 9;
320
int mid_h = opt->rect.x() + opt->rect.width() / 2;
321
int mid_v = opt->rect.y() + opt->rect.height() / 2;
326
if (opt->state & State_Children) {
327
int delta = decoration_size / 2;
332
p->drawPixmap(bef_h, bef_v, opt->state & State_Open ? open : closed);
334
if (opt->state & State_Item) {
335
if (opt->direction == Qt::RightToLeft)
336
p->drawLine(opt->rect.left(), mid_v, bef_h, mid_v);
338
p->drawLine(aft_h, mid_v, opt->rect.right(), mid_v);
340
if (opt->state & State_Sibling)
341
p->drawLine(mid_h, aft_v, mid_h, opt->rect.bottom());
342
if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
343
p->drawLine(mid_h, opt->rect.y(), mid_h, bef_v);
346
qDrawShadeLine(p, opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.bottom(),
347
opt->palette, opt->state & State_Sunken, 1, 0);
349
case PE_FrameStatusBar:
350
qDrawShadeRect(p, opt->rect, opt->palette, true, 1, 0, 0);
352
case PE_IndicatorHeaderArrow:
353
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
354
QPen oldPen = p->pen();
355
if (header->sortIndicator & QStyleOptionHeader::SortUp) {
357
p->setPen(opt->palette.light().color());
358
p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(),
359
opt->rect.x() + opt->rect.width() / 2, opt->rect.height());
360
p->setPen(opt->palette.dark().color());
361
pa.setPoint(0, opt->rect.x() + opt->rect.width() / 2, opt->rect.height());
362
pa.setPoint(1, opt->rect.x(), opt->rect.y());
363
pa.setPoint(2, opt->rect.x() + opt->rect.width(), opt->rect.y());
365
} else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
367
p->setPen(opt->palette.light().color());
368
pa.setPoint(0, opt->rect.x(), opt->rect.height());
369
pa.setPoint(1, opt->rect.x() + opt->rect.width(), opt->rect.height());
370
pa.setPoint(2, opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
372
p->setPen(opt->palette.dark().color());
373
p->drawLine(opt->rect.x(), opt->rect.height(),
374
opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
379
case PE_FrameTabBarBase:
380
if (const QStyleOptionTabBarBase *tbb
381
= qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
382
QRegion region(tbb->rect);
383
region -= tbb->selectedTabRect;
385
p->setClipRegion(region);
386
switch (tbb->shape) {
387
case QTabBar::RoundedNorth:
388
case QTabBar::TriangularNorth:
389
p->setPen(tbb->palette.light().color());
390
p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
392
case QTabBar::RoundedWest:
393
case QTabBar::TriangularWest:
394
p->setPen(tbb->palette.light().color());
395
p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
397
case QTabBar::RoundedSouth:
398
case QTabBar::TriangularSouth:
399
p->setPen(tbb->palette.shadow().color());
400
p->drawLine(tbb->rect.left(), tbb->rect.bottom(),
401
tbb->rect.right(), tbb->rect.bottom());
402
p->setPen(tbb->palette.dark().color());
403
p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1,
404
tbb->rect.right() - 1, tbb->rect.bottom() - 1);
406
case QTabBar::RoundedEast:
407
case QTabBar::TriangularEast:
408
p->setPen(tbb->palette.dark().color());
409
p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
415
case PE_FrameTabWidget:
417
qDrawWinPanel(p, opt->rect, opt->palette, false, 0);
419
case PE_FrameLineEdit:
420
drawPrimitive(PE_Frame, opt, p, widget);
422
case PE_FrameGroupBox:
423
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
424
int lwidth = frame->lineWidth,
425
mlwidth = frame->midLineWidth;
426
if (opt->state & (State_Sunken | State_Raised))
427
qDrawShadeRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
428
frame->rect.height(), frame->palette, frame->state & State_Sunken,
431
qDrawPlainRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
432
frame->rect.height(), frame->palette.foreground().color(), lwidth);
435
case PE_FrameDockWidget:
436
if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
437
int lw = frame->lineWidth;
439
lw = pixelMetric(PM_DockWidgetFrameWidth);
441
qDrawShadePanel(p, frame->rect, frame->palette, false, lw);
445
case PE_IndicatorToolBarHandle:
447
p->translate(opt->rect.x(), opt->rect.y());
448
if (opt->state & State_Horizontal) {
449
int x = opt->rect.width() / 3;
450
if (QApplication::layoutDirection() == Qt::RightToLeft)
452
if (opt->rect.height() > 4) {
453
qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
454
opt->palette, false, 1, 0);
455
qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4,
456
opt->palette, false, 1, 0);
459
if (opt->rect.width() > 4) {
460
int y = opt->rect.height() / 3;
461
qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
462
opt->palette, false, 1, 0);
463
qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3,
464
opt->palette, false, 1, 0);
469
case PE_IndicatorToolBarSeparator:
472
if (opt->state & State_Horizontal) {
473
p1 = QPoint(opt->rect.width()/2, 0);
474
p2 = QPoint(p1.x(), opt->rect.height());
476
p1 = QPoint(0, opt->rect.height()/2);
477
p2 = QPoint(opt->rect.width(), p1.y());
479
qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
482
case PE_IndicatorSpinPlus:
483
case PE_IndicatorSpinMinus: {
485
int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
486
QRect br = r.adjusted(fw, fw, -fw, -fw);
488
int offset = (opt->state & State_Sunken) ? 1 : 0;
489
int step = (br.width() + 4) / 5;
490
p->fillRect(br.x() + offset, br.y() + offset +br.height() / 2 - step / 2,
492
opt->palette.buttonText());
493
if (pe == PE_IndicatorSpinPlus)
494
p->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset,
496
opt->palette.buttonText());
499
case PE_IndicatorSpinUp:
500
case PE_IndicatorSpinDown: {
502
int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
503
// QRect br = r.adjusted(fw, fw, -fw, -fw);
504
int x = r.x(), y = r.y(), w = r.width(), h = r.height();
510
sw -= (sw / 7) * 2; // Empty border
511
int sh = sw/2 + 2; // Must have empty row at foot of arrow
513
int sx = x + w / 2 - sw / 2;
514
int sy = y + h / 2 - sh / 2;
516
if (pe == PE_IndicatorSpinUp && fw)
520
if (pe == PE_IndicatorSpinDown)
521
a.setPoints(3, 0, 1, sw-1, 1, sh-2, sh-1);
523
a.setPoints(3, 0, sh-1, sw-1, sh-1, sh-2, 1);
526
if (opt->state & State_Sunken) {
527
bsx = pixelMetric(PM_ButtonShiftHorizontal);
528
bsy = pixelMetric(PM_ButtonShiftVertical);
531
p->translate(sx + bsx, sy + bsy);
532
p->setPen(opt->palette.buttonText().color());
533
p->setBrush(opt->palette.buttonText());
537
case PE_PanelTipLabel: {
538
QBrush oldBrush = p->brush();
539
QPen oldPen = p->pen();
540
p->setPen(opt->palette.foreground().color());
541
p->setBrush(opt->palette.background());
542
p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
544
p->setBrush(oldBrush);
547
case PE_IndicatorTabTear:
548
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
549
bool rtl = tab->direction == Qt::RightToLeft;
550
QRect rect = tab->rect;
553
rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));
554
rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));
556
path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
558
for(int jags = 1; jags <= count; ++jags, rtl = !rtl)
559
path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
561
p->setPen(QPen(tab->palette.light(), .8));
562
p->setBrush(tab->palette.background());
563
p->setRenderHint(QPainter::Antialiasing);
567
case PE_PanelLineEdit:
568
if (const QStyleOptionFrame *panel = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
569
if (!(panel->state & State_Enabled)) {
570
QBrush bg = panel->palette.brush(QPalette::Base);
571
p->fillRect(panel->rect, bg);
583
void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
584
QPainter *p, const QWidget *widget) const
588
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
589
drawControl(CE_PushButtonBevel, btn, p, widget);
590
QStyleOptionButton subopt = *btn;
591
subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
592
drawControl(CE_PushButtonLabel, &subopt, p, widget);
593
if (btn->state & State_HasFocus) {
594
QStyleOptionFocusRect fropt;
595
fropt.QStyleOption::operator=(*btn);
596
fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);
597
drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
601
case CE_PushButtonBevel:
602
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
603
QRect br = btn->rect;
604
int dbi = pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
605
if (btn->features & QStyleOptionButton::DefaultButton)
606
drawPrimitive(PE_FrameDefaultButton, opt, p, widget);
607
if (btn->features & QStyleOptionButton::AutoDefaultButton)
608
br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
609
if (!(btn->features & QStyleOptionButton::Flat)
610
|| btn->state & (State_Sunken | State_On)) {
611
QStyleOptionButton tmpBtn = *btn;
613
drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
615
if (btn->features & QStyleOptionButton::HasMenu) {
616
int mbi = pixelMetric(PM_MenuButtonIndicator, btn, widget);
617
QRect ir = btn->rect;
618
QStyleOptionButton newBtn = *btn;
619
newBtn.rect = QRect(ir.right() - mbi, ir.height() - 20, mbi, ir.height() - 4);
620
drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
624
case CE_PushButtonLabel:
625
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
626
QRect ir = btn->rect;
627
uint tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
628
if (btn->state & (State_On | State_Sunken))
629
ir.translate(pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
630
pixelMetric(PM_ButtonShiftVertical, opt, widget));
631
if (!btn->icon.isNull()) {
632
QIcon::Mode mode = btn->state & State_Enabled ? QIcon::Normal
634
if (mode == QIcon::Normal && btn->state & State_HasFocus)
635
mode = QIcon::Active;
636
QIcon::State state = QIcon::Off;
637
if (btn->state & State_On)
639
QPixmap pixmap = btn->icon.pixmap(btn->iconSize, mode, state);
640
int pixw = pixmap.width();
641
int pixh = pixmap.height();
642
//Center the icon if there is no text
645
if (btn->text.isEmpty()) {
646
point = QPoint(ir.x() + ir.width() / 2 - pixw / 2,
647
ir.y() + ir.height() / 2 - pixh / 2);
649
point = QPoint(ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2);
651
if (btn->direction == Qt::RightToLeft)
654
if ((btn->state & (State_On | State_Sunken)) && btn->direction == Qt::RightToLeft)
655
point.rx() -= pixelMetric(PM_ButtonShiftHorizontal, opt, widget) * 2;
657
p->drawPixmap(visualPos(btn->direction, btn->rect, point), pixmap);
659
if (btn->direction == Qt::RightToLeft)
662
ir.translate(pixw + 4, 0);
663
ir.setWidth(ir.width() - (pixw + 4));
664
// left-align text if there is
665
if (!btn->text.isEmpty())
668
tf |= Qt::AlignHCenter;
670
drawItemText(p, ir, tf, btn->palette, (btn->state & State_Enabled),
671
btn->text, QPalette::ButtonText);
676
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
677
bool isRadio = (element == CE_RadioButton);
678
QStyleOptionButton subopt = *btn;
679
subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
680
: SE_CheckBoxIndicator, btn, widget);
681
drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
683
subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
684
: SE_CheckBoxContents, btn, widget);
685
drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);
686
if (btn->state & State_HasFocus) {
687
QStyleOptionFocusRect fropt;
688
fropt.QStyleOption::operator=(*btn);
689
fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
690
: SE_CheckBoxFocusRect, btn, widget);
691
drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
695
case CE_RadioButtonLabel:
696
case CE_CheckBoxLabel:
697
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
698
uint alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
700
if (!styleHint(SH_UnderlineShortcut, btn, widget))
701
alignment |= Qt::TextHideMnemonic;
703
QRect textRect = btn->rect;
704
if (!btn->icon.isNull()) {
705
pix = btn->icon.pixmap(btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
706
drawItemPixmap(p, btn->rect, alignment, pix);
707
if (btn->direction == Qt::RightToLeft)
708
textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
710
textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
712
if (!btn->text.isEmpty()){
713
drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
714
btn->palette, btn->state & State_Enabled, btn->text);
718
case CE_MenuScroller: {
719
p->fillRect(opt->rect, opt->palette.background());
720
QStyleOption arrowOpt = *opt;
721
arrowOpt.state |= State_Enabled;
722
drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp),
723
&arrowOpt, p, widget);
726
if (opt->state & State_Selected)
727
p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
729
p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
730
p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
731
p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,
732
opt->rect.x() + opt->rect.width() - 4,
733
opt->rect.y() + opt->rect.height() / 2 - 1);
734
p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
735
p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,
736
opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);
739
if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
740
uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
741
| Qt::TextSingleLine;
742
if (!styleHint(SH_UnderlineShortcut, mbi, widget))
743
alignment |= Qt::TextHideMnemonic;
744
QPixmap pix = mbi->icon.pixmap(pixelMetric(PM_SmallIconSize), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
746
drawItemPixmap(p,mbi->rect, alignment, pix);
748
drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
749
mbi->text, QPalette::ButtonText);
752
case CE_MenuBarEmptyArea:
753
if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))
754
p->eraseRect(opt->rect);
757
if (const QStyleOptionProgressBar *pb
758
= qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
759
QStyleOptionProgressBar subopt = *pb;
760
subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);
761
drawControl(CE_ProgressBarGroove, &subopt, p, widget);
762
subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);
763
drawControl(CE_ProgressBarContents, &subopt, p, widget);
764
if (pb->textVisible) {
765
subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);
766
drawControl(CE_ProgressBarLabel, &subopt, p, widget);
770
case CE_ProgressBarGroove:
771
qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
772
&opt->palette.brush(QPalette::Background));
774
case CE_ProgressBarLabel:
775
if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
776
QPalette::ColorRole textRole = QPalette::NoRole;
777
if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible
778
&& pb->progress * 2 >= pb->maximum)
779
textRole = QPalette::HighlightedText;
780
drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,
781
pb->state & State_Enabled, pb->text, textRole);
784
case CE_ProgressBarContents:
785
if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
786
QPalette pal2 = pb->palette;
787
// Correct the highlight color if it is the same as the background
788
if (pal2.highlight() == pal2.background())
789
pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
790
QPalette::Highlight));
791
bool reverse = pb->direction == Qt::RightToLeft;
793
int w = pb->rect.width() - 2 * fw;
794
if (pb->minimum == 0 && pb->maximum == 0) {
795
// draw busy indicator
796
int x = pb->progress % (w * 2);
799
x = reverse ? pb->rect.right() - x : x + pb->rect.x();
800
p->setPen(QPen(pal2.highlight().color(), 4));
801
p->drawLine(x, pb->rect.y() + 1, x, pb->rect.height() - fw);
803
const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
806
u = (pb->rect.width() + unit_width / 3) / unit_width;
809
int p_v = pb->progress;
810
int t_s = pb->maximum ? pb->maximum : 1;
812
if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
813
// scale down to something usable.
818
// nu < tnu, if last chunk is only a partial chunk
820
tnu = nu = p_v * u / t_s;
822
if (nu * unit_width > w)
825
// Draw nu units out of a possible u of unit_width
826
// width, each a rectangle bordered by background
827
// color, all in a sunken panel with a percentage text
828
// display at the end.
830
int x0 = reverse ? pb->rect.right() - ((unit_width > 1) ? unit_width : fw)
832
QStyleOptionProgressBar pbBits = *pb;
833
pbBits.palette = pal2;
834
int myY = pbBits.rect.y();
835
int myHeight = pbBits.rect.height();
836
pbBits.state = State_None;
837
for (int i = 0; i < nu; ++i) {
838
pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
839
drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
840
x += reverse ? -unit_width : unit_width;
843
// Draw the last partial chunk to fill up the
844
// progressbar entirely
846
int pixels_left = w - (nu * unit_width);
847
int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
848
pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
849
drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
855
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
856
QRect rect = header->rect;
857
if (!header->icon.isNull()) {
859
= header->icon.pixmap(pixelMetric(PM_SmallIconSize), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
860
int pixw = pixmap.width();
861
// "pixh - 1" because of tricky integer division
862
drawItemPixmap(p, rect, header->iconAlignment, pixmap);
863
if (header->direction == Qt::LeftToRight)
864
rect.setLeft(rect.left() + pixw + 2);
866
rect.setRight(rect.right() - pixw - 2);
868
drawItemText(p, rect, header->textAlignment, header->palette,
869
(header->state & State_Enabled), header->text, QPalette::ButtonText);
873
case CE_ToolButtonLabel:
874
if (const QStyleOptionToolButton *toolbutton
875
= qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
876
QRect rect = toolbutton->rect;
879
if (toolbutton->state & (State_Sunken | State_On)) {
880
shiftX = pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
881
shiftY = pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
883
if (toolbutton->features & QStyleOptionToolButton::Arrow) {
885
switch (toolbutton->arrowType) {
887
pe = PE_IndicatorArrowLeft;
890
pe = PE_IndicatorArrowRight;
893
pe = PE_IndicatorArrowUp;
896
pe = PE_IndicatorArrowDown;
901
rect.translate(shiftX, shiftY);
902
QStyleOption arrowOpt(0);
903
arrowOpt.rect = rect;
904
arrowOpt.palette = toolbutton->palette;
905
arrowOpt.state = toolbutton->state;
906
drawPrimitive(pe, &arrowOpt, p, widget);
908
if (toolbutton->icon.isNull() && !toolbutton->text.isEmpty()
909
|| toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
910
int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
911
if (!styleHint(SH_UnderlineShortcut, opt, widget))
912
alignment |= Qt::TextHideMnemonic;
913
rect.translate(shiftX, shiftY);
914
drawItemText(p, rect, alignment, toolbutton->palette,
915
opt->state & State_Enabled, toolbutton->text,
916
QPalette::ButtonText);
919
QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
921
if (!(toolbutton->state & State_Enabled))
922
mode = QIcon::Disabled;
923
else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
924
mode = QIcon::Active;
926
mode = QIcon::Normal;
927
pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), mode, state);
929
if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
930
p->setFont(toolbutton->font);
933
int alignment = Qt::TextShowMnemonic;
934
if (!styleHint(SH_UnderlineShortcut, opt, widget))
935
alignment |= Qt::TextHideMnemonic;
937
if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
938
int fh = p->fontMetrics().height();
939
pr.adjust(0, 3, 0, -fh - 3);
940
tr.adjust(0, pr.bottom(), 0, -3);
941
pr.translate(shiftX, shiftY);
942
drawItemPixmap(p, pr, Qt::AlignCenter, pm);
943
alignment |= Qt::AlignCenter;
945
pr.setWidth(pm.width() + 8);
946
tr.adjust(pr.right(), 0, 0, 0);
947
pr.translate(shiftX, shiftY);
948
drawItemPixmap(p, pr, Qt::AlignCenter, pm);
949
alignment |= Qt::AlignLeft | Qt::AlignVCenter;
951
tr.translate(shiftX, shiftY);
952
drawItemText(p, tr, alignment, toolbutton->palette,
953
toolbutton->state & State_Enabled, toolbutton->text,
954
QPalette::ButtonText);
956
rect.translate(shiftX, shiftY);
957
drawItemPixmap(p, rect, Qt::AlignCenter, pm);
964
if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
965
int d = 20 + tb->rect.height() - 3;
967
a.setPoint(0, -1, tb->rect.height() + 1);
968
a.setPoint(1, -1, 1);
969
a.setPoint(2, tb->rect.width() - d, 1);
970
a.setPoint(3, tb->rect.width() - 20, tb->rect.height() - 2);
971
a.setPoint(4, tb->rect.width() - 1, tb->rect.height() - 2);
972
a.setPoint(5, tb->rect.width() - 1, tb->rect.height() + 1);
973
a.setPoint(6, -1, tb->rect.height() + 1);
975
p->setPen(tb->palette.mid().color().dark(150));
977
p->setPen(tb->palette.light().color());
978
p->drawLine(0, 2, tb->rect.width() - d, 2);
979
p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);
980
p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,
981
tb->rect.width(), tb->rect.height() - 1);
982
p->setBrush(Qt::NoBrush);
986
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
987
drawControl(CE_TabBarTabShape, tab, p, widget);
988
drawControl(CE_TabBarTabLabel, tab, p, widget);
991
case CE_TabBarTabShape:
992
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
993
QBrush oldBrush = p->brush();
994
QPen oldPen = p->pen();
995
if (tab->state & State_Selected)
996
p->setBrush(tab->palette.base());
998
p->setBrush(tab->palette.background());
999
p->setPen(tab->palette.foreground().color());
1003
switch (tab->shape) {
1004
case QTabBar::TriangularNorth:
1005
case QTabBar::TriangularSouth: {
1006
a.setPoint(0, 0, -1);
1007
a.setPoint(1, 0, 0);
1008
y = tab->rect.height() - 2;
1010
a.setPoint(2, x++, y - 1);
1012
a.setPoint(3, x++, y++);
1013
a.setPoint(4, x, y);
1016
int right = tab->rect.width() - 1;
1017
for (i = 0; i < 5; ++i)
1018
a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());
1019
if (tab->shape == QTabBar::TriangularNorth)
1020
for (i = 0; i < 10; ++i)
1021
a.setPoint(i, a.point(i).x(), tab->rect.height() - 1 - a.point(i).y());
1023
a.translate(tab->rect.left(), tab->rect.top());
1026
case QTabBar::TriangularEast:
1027
case QTabBar::TriangularWest: {
1028
a.setPoint(0, -1, 0);
1029
a.setPoint(1, 0, 0);
1030
x = tab->rect.width() - 2;
1032
a.setPoint(2, x - 1, y++);
1034
a.setPoint(3, x++, y++);
1035
a.setPoint(4, x, y);
1037
int bottom = tab->rect.height() - 1;
1038
for (i = 0; i < 5; ++i)
1039
a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());
1040
if (tab->shape == QTabBar::TriangularWest)
1041
for (i = 0; i < 10; ++i)
1042
a.setPoint(i, tab->rect.width() - 1 - a.point(i).x(), a.point(i).y());
1043
a.translate(tab->rect.left(), tab->rect.top());
1050
p->setBrush(oldBrush);
1053
case CE_TabBarTabLabel:
1054
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1055
QRect tr = tab->rect;
1056
bool verticalTabs = tab->shape == QTabBar::RoundedEast
1057
|| tab->shape == QTabBar::RoundedWest
1058
|| tab->shape == QTabBar::TriangularEast
1059
|| tab->shape == QTabBar::TriangularWest;
1060
bool selected = tab->state & State_Selected;
1063
int newX, newY, newRot;
1064
if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
1070
newY = tr.y() + tr.height();
1073
tr.setRect(0, 0, tr.height(), tr.width());
1075
m.translate(newX, newY);
1077
p->setMatrix(m, true);
1080
tr.setBottom(tr.bottom() - pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab,
1082
tr.setRight(tr.right() - pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab,
1086
int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1087
if (!styleHint(SH_UnderlineShortcut, opt, widget))
1088
alignment |= Qt::TextHideMnemonic;
1089
if (!tab->icon.isNull()) {
1090
QPixmap tabIcon = tab->icon.pixmap(pixelMetric(PM_SmallIconSize), (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1091
p->drawPixmap(tr.left() + 6, tr.center().y() - tabIcon.height() / 2, tabIcon);
1092
tr.setLeft(tr.left() + tabIcon.width() + 4);
1094
drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::Foreground);
1099
if (tab->state & State_HasFocus && !tab->text.isEmpty()) {
1100
const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth);
1103
x1 = tab->rect.left();
1104
x2 = tab->rect.right() - 1;
1106
QStyleOptionFocusRect fropt;
1107
fropt.QStyleOption::operator=(*tab);
1108
fropt.rect.setRect(x1 + 1 + OFFSET, tab->rect.y() + OFFSET,
1109
x2 - x1 - 2*OFFSET, tab->rect.height() - 2*OFFSET);
1110
drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1117
opt->rect.getRect(&x, &y, &w, &h);
1119
int sw = qMin(h, w);
1121
p->translate(0, h - w);
1123
p->translate(w - h, 0);
1129
if (opt->direction == Qt::RightToLeft) {
1131
for (int i = 0; i < 4; ++i) {
1132
p->setPen(QPen(opt->palette.light().color(), 1));
1133
p->drawLine(x, sy - 1 , sx + 1, sw);
1134
p->setPen(QPen(opt->palette.dark().color(), 1));
1135
p->drawLine(x, sy, sx, sw);
1136
p->setPen(QPen(opt->palette.dark().color(), 1));
1137
p->drawLine(x, sy + 1, sx - 1, sw);
1142
for (int i = 0; i < 4; ++i) {
1143
p->setPen(QPen(opt->palette.light().color(), 1));
1144
p->drawLine(sx - 1, sw, sw, sy - 1);
1145
p->setPen(QPen(opt->palette.dark().color(), 1));
1146
p->drawLine(sx, sw, sw, sy);
1147
p->setPen(QPen(opt->palette.dark().color(), 1));
1148
p->drawLine(sx + 1, sw, sw, sy + 1);
1155
case CE_RubberBand: {
1156
if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
1157
QPixmap tiledPixmap(16, 16);
1158
QPainter pixmapPainter(&tiledPixmap);
1159
pixmapPainter.setPen(Qt::NoPen);
1160
pixmapPainter.setBrush(Qt::Dense4Pattern);
1161
pixmapPainter.setBackground(QBrush(opt->palette.base()));
1162
pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1163
pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1164
pixmapPainter.end();
1167
QRect r = opt->rect;
1168
QStyleHintReturnMask mask;
1169
if (styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1170
p->setClipRegion(mask.region);
1171
p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1172
p->setPen(opt->palette.color(QPalette::Active, QPalette::Foreground));
1173
p->setBrush(Qt::NoBrush);
1174
p->drawRect(r.adjusted(0, 0, -1, -1));
1175
if (rbOpt->shape == QRubberBand::Rectangle)
1176
p->drawRect(r.adjusted(3, 3, -4, -4));
1180
case CE_DockWidgetTitle:
1181
if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
1182
QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
1183
if (dwOpt->movable) {
1184
p->setPen(dwOpt->palette.color(QPalette::Dark));
1187
if (!dwOpt->title.isEmpty()) {
1188
const int indent = p->fontMetrics().descent();
1189
drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
1190
Qt::AlignLeft | Qt::AlignVCenter, dwOpt->palette,
1191
dwOpt->state & State_Enabled, dwOpt->title,
1192
QPalette::Foreground);
1197
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
1198
drawControl(CE_HeaderSection, header, p, widget);
1199
QStyleOptionHeader subopt = *header;
1200
subopt.rect = subElementRect(SE_HeaderLabel, header, widget);
1201
drawControl(CE_HeaderLabel, &subopt, p, widget);
1202
if (header->sortIndicator != QStyleOptionHeader::None) {
1203
subopt.rect = subElementRect(SE_HeaderArrow, opt, widget);
1204
drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget);
1209
p->fillRect(opt->rect, opt->palette.foreground());
1211
case CE_HeaderSection:
1212
qDrawShadePanel(p, opt->rect, opt->palette,
1213
opt->state & State_Sunken, 1,
1214
&opt->palette.brush(QPalette::Button));
1216
case CE_ComboBoxLabel:
1217
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1218
QRect editRect = subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
1219
if (!cb->currentIcon.isNull()) {
1220
QRect comboRect(editRect);
1221
QRect iconRect(editRect);
1222
iconRect.setWidth(cb->iconSize.width() + 4);
1223
editRect.setWidth(editRect.width() - iconRect.width());
1224
iconRect = alignedRect(cb->direction, Qt::AlignLeft, iconRect.size(), comboRect);
1225
editRect = alignedRect(cb->direction, Qt::AlignRight, editRect.size(), comboRect);
1226
p->setClipRect(iconRect);
1227
cb->currentIcon.paint(p, iconRect);
1230
if (!cb->currentText.isEmpty() && !cb->editable) {
1231
p->setClipRect(editRect);
1232
p->drawText(editRect.adjusted(1, 0, -1, 0),
1233
visualAlignment(cb->direction, Qt::AlignLeft | Qt::AlignVCenter),
1247
QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const
1251
case SE_PushButtonContents:
1252
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1254
dx1 = pixelMetric(PM_DefaultFrameWidth, btn, widget);
1255
if (btn->features & QStyleOptionButton::AutoDefaultButton)
1256
dx1 += pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1258
r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2,
1259
opt->rect.height() - dx2);
1260
r = visualRect(opt->direction, opt->rect, r);
1263
case SE_PushButtonFocusRect:
1264
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1265
int dbw1 = 0, dbw2 = 0;
1266
if (btn->features & QStyleOptionButton::AutoDefaultButton){
1267
dbw1 = pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1271
int dfw1 = pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1,
1274
r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1,
1275
btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2);
1276
r = visualRect(opt->direction, opt->rect, r);
1279
case SE_ViewItemCheckIndicator:
1280
r = subElementRect(SE_CheckBoxIndicator, opt, widget);
1282
case SE_CheckBoxIndicator:
1284
int h = pixelMetric(PM_IndicatorHeight, opt, widget);
1285
r.setRect(0, (opt->rect.height() - h) / 2,
1286
pixelMetric(PM_IndicatorWidth, opt, widget), h);
1287
r = visualRect(opt->direction, opt->rect, r);
1291
case SE_CheckBoxContents:
1293
// Deal with the logical first, then convert it back to screen coords.
1294
QRect ir = visualRect(opt->direction, opt->rect,
1295
subElementRect(SE_CheckBoxIndicator, opt, widget));
1296
r.setRect(ir.right() + 6, opt->rect.y(), opt->rect.width() - ir.width() - 6,
1297
opt->rect.height());
1298
r = visualRect(opt->direction, opt->rect, r);
1302
case SE_CheckBoxFocusRect:
1303
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1304
if (btn->icon.isNull() && btn->text.isEmpty()) {
1305
r = subElementRect(SE_CheckBoxIndicator, opt, widget);
1306
r.adjust(1, 1, -1, -1);
1309
// As above, deal with the logical first, then convert it back to screen coords.
1310
QRect cr = visualRect(btn->direction, btn->rect,
1311
subElementRect(SE_CheckBoxContents, btn, widget));
1313
QRect iconRect, textRect;
1314
if (!btn->text.isEmpty()) {
1315
textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft
1316
| Qt::AlignVCenter | Qt::TextShowMnemonic,
1317
btn->state & State_Enabled, btn->text);
1319
if (!btn->icon.isNull()) {
1320
iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
1321
| Qt::TextShowMnemonic,
1322
btn->icon.pixmap(btn->iconSize, QIcon::Normal));
1323
if (!textRect.isEmpty())
1324
textRect.translate(iconRect.right() + 4, 0);
1326
r = iconRect | textRect;
1327
r.adjust(-3, -2, 3, 2);
1328
r = r.intersect(btn->rect);
1329
r = visualRect(btn->direction, btn->rect, r);
1333
case SE_RadioButtonIndicator:
1335
int h = pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
1336
r.setRect(0, (opt->rect.height() - h) / 2,
1337
pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), h);
1338
r = visualRect(opt->direction, opt->rect, r);
1342
case SE_RadioButtonContents:
1344
QRect ir = visualRect(opt->direction, opt->rect,
1345
subElementRect(SE_RadioButtonIndicator, opt, widget));
1346
r.setRect(ir.right() + 6, opt->rect.y(),
1347
opt->rect.width() - ir.width() - 6, opt->rect.height());
1348
r = visualRect(opt->direction, opt->rect, r);
1352
case SE_RadioButtonFocusRect:
1353
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1354
if (btn->icon.isNull() && btn->text.isEmpty()) {
1355
r = subElementRect(SE_RadioButtonIndicator, opt, widget);
1356
r.adjust(1, 1, -1, -1);
1359
QRect cr = visualRect(btn->direction, btn->rect,
1360
subElementRect(SE_RadioButtonContents, opt, widget));
1362
QRect iconRect, textRect;
1363
if (!btn->text.isEmpty()){
1364
textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
1365
| Qt::TextShowMnemonic, btn->state & State_Enabled, btn->text);
1367
if(!btn->icon.isNull()) {
1368
iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic,
1369
btn->icon.pixmap(btn->iconSize, QIcon::Normal));
1370
if (!textRect.isEmpty())
1371
textRect.translate(iconRect.right() + 4, 0);
1373
r = iconRect | textRect;
1374
r.adjust(-3, -2, 3, 2);
1375
r = r.intersect(btn->rect);
1376
r = visualRect(btn->direction, btn->rect, r);
1379
case SE_SliderFocusRect:
1380
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1381
int tickOffset = pixelMetric(PM_SliderTickmarkOffset, slider, widget);
1382
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1383
if (slider->orientation == Qt::Horizontal)
1384
r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2);
1386
r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height());
1387
r = r.intersect(slider->rect);
1388
r = visualRect(opt->direction, opt->rect, r);
1391
case SE_ProgressBarGroove:
1392
case SE_ProgressBarContents:
1393
case SE_ProgressBarLabel:
1394
if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1396
if (pb->textVisible)
1397
textw = qMax(pb->fontMetrics.width(pb->text), pb->fontMetrics.width("100%")) + 6;
1399
if ((pb->textAlignment & Qt::AlignCenter) == 0) {
1400
if (sr != SE_ProgressBarLabel)
1401
r.setCoords(pb->rect.left(), pb->rect.top(),
1402
pb->rect.right() - textw, pb->rect.bottom());
1404
r.setCoords(pb->rect.right() - textw, pb->rect.top(),
1405
pb->rect.right(), pb->rect.bottom());
1409
r = visualRect(pb->direction, pb->rect, r);
1412
case SE_Q3DockWindowHandleRect:
1413
if (const QStyleOptionQ3DockWindow *dw = qstyleoption_cast<const QStyleOptionQ3DockWindow *>(opt)) {
1414
if (!dw->docked || !dw->closeEnabled)
1415
r.setRect(0, 0, dw->rect.width(), dw->rect.height());
1417
if (dw->state & State_Horizontal)
1418
r.setRect(0, 15, dw->rect.width(), dw->rect.height() - 15);
1420
r.setRect(0, 1, dw->rect.width() - 15, dw->rect.height() - 1);
1422
r = visualRect(opt->direction, opt->rect, r);
1425
case SE_ComboBoxFocusRect:
1426
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1427
int margin = cb->frame ? 3 : 0;
1428
r.setRect(margin, margin, opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin);
1429
r = visualRect(opt->direction, opt->rect, r);
1432
case SE_ToolBoxTabContents:
1434
r.adjust(0, 0, -30, 0);
1436
case SE_HeaderLabel: {
1437
int margin = pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
1438
r.setRect(opt->rect.x() + margin, opt->rect.y() + margin,
1439
opt->rect.width() - margin * 2, opt->rect.height() - margin * 2);
1441
r = visualRect(opt->direction, opt->rect, r);
1443
case SE_HeaderArrow: {
1444
int h = opt->rect.height();
1445
int w = opt->rect.width();
1446
int x = opt->rect.x();
1447
int y = opt->rect.y();
1448
int margin = pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
1449
if (opt->state & State_Horizontal)
1450
r.setRect(x + w - margin * 2 - (h / 2), y + 5, h / 2, h - margin * 2);
1452
r.setRect(x + 5, y, h / 2, h - margin * 2);
1453
r = visualRect(opt->direction, opt->rect, r);
1456
case SE_RadioButtonClickRect:
1457
r = subElementRect(SE_RadioButtonFocusRect, opt, widget);
1458
r |= subElementRect(SE_RadioButtonIndicator, opt, widget);
1460
case SE_CheckBoxClickRect:
1461
r = subElementRect(SE_CheckBoxFocusRect, opt, widget);
1462
r |= subElementRect(SE_CheckBoxIndicator, opt, widget);
1464
case SE_TabWidgetTabBar:
1465
if (const QStyleOptionTabWidgetFrame *twf
1466
= qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
1467
r.setSize(twf->tabBarSize);
1468
switch (twf->shape) {
1469
case QTabBar::RoundedNorth:
1470
case QTabBar::TriangularNorth:
1471
switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
1474
r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
1476
case Qt::AlignCenter:
1477
r.moveTopLeft(QPoint(twf->rect.center().x() - twf->tabBarSize.width() / 2, 0));
1479
case Qt::AlignRight:
1480
r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
1481
- twf->rightCornerWidgetSize.width(), 0));
1484
r.setWidth(qMin(r.width(), twf->rect.width()
1485
- twf->leftCornerWidgetSize.width()
1486
- twf->rightCornerWidgetSize.width()));
1487
r = visualRect(twf->direction, twf->rect, r);
1489
case QTabBar::RoundedSouth:
1490
case QTabBar::TriangularSouth:
1491
switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
1494
r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
1495
twf->rect.height() - twf->tabBarSize.height()));
1497
case Qt::AlignCenter:
1498
r.moveTopLeft(QPoint(twf->rect.center().x() - twf->tabBarSize.width() / 2,
1499
twf->rect.height() - twf->tabBarSize.height()));
1501
case Qt::AlignRight:
1502
r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
1503
- twf->rightCornerWidgetSize.width(),
1504
twf->rect.height() - twf->tabBarSize.height()));
1507
r.setWidth(qMin(r.width(), twf->rect.width()
1508
- twf->leftCornerWidgetSize.width()
1509
- twf->rightCornerWidgetSize.width()));
1510
r = visualRect(twf->direction, twf->rect, r);
1512
case QTabBar::RoundedEast:
1513
case QTabBar::TriangularEast:
1514
switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
1517
r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
1518
twf->leftCornerWidgetSize.height()));
1520
case Qt::AlignCenter:
1521
r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
1522
twf->rect.center().y() - twf->tabBarSize.height() / 2));
1524
case Qt::AlignRight:
1525
r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
1526
twf->rect.height() - twf->tabBarSize.height()
1527
- twf->rightCornerWidgetSize.height()));
1530
r.setHeight(qMin(r.height(), twf->rect.height()
1531
- twf->leftCornerWidgetSize.height()
1532
- twf->rightCornerWidgetSize.height()));
1534
case QTabBar::RoundedWest:
1535
case QTabBar::TriangularWest:
1536
switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
1539
r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
1541
case Qt::AlignCenter:
1542
r.moveTopLeft(QPoint(0, twf->rect.center().y() - twf->tabBarSize.height() / 2));
1544
case Qt::AlignRight:
1545
r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
1546
- twf->rightCornerWidgetSize.height()));
1549
r.setHeight(qMin(r.height(), twf->rect.height())
1550
- twf->leftCornerWidgetSize.height()
1551
- twf->rightCornerWidgetSize.height());
1556
case SE_TabWidgetTabPane:
1557
case SE_TabWidgetTabContents:
1558
if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
1559
QStyleOptionTab tabopt;
1560
tabopt.shape = twf->shape;
1561
int overlap = pixelMetric(PM_TabBarBaseOverlap, &tabopt, widget);
1562
switch (twf->shape) {
1563
case QTabBar::RoundedNorth:
1564
case QTabBar::TriangularNorth:
1565
r = QRect(QPoint(0,twf->tabBarSize.height() - overlap), QSize(twf->rect.width(), twf->rect.height() - twf->tabBarSize.height() + overlap));
1567
case QTabBar::RoundedSouth:
1568
case QTabBar::TriangularSouth:
1569
r = QRect(QPoint(0,0), QSize(twf->rect.width(), twf->rect.height() - twf->tabBarSize.height() + overlap));
1571
case QTabBar::RoundedEast:
1572
case QTabBar::TriangularEast:
1573
r = QRect(QPoint(0, 0), QSize(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.height()));
1575
case QTabBar::RoundedWest:
1576
case QTabBar::TriangularWest:
1577
r = QRect(QPoint(twf->tabBarSize.width() - overlap, 0), QSize(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.height()));
1580
if (sr == SE_TabWidgetTabContents)
1581
r.adjust(2, 2, -2, -2);
1584
case SE_TabWidgetLeftCorner:
1585
if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
1586
QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
1587
switch (twf->shape) {
1588
case QTabBar::RoundedNorth:
1589
case QTabBar::TriangularNorth:
1590
r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()),
1591
twf->leftCornerWidgetSize);
1593
case QTabBar::RoundedSouth:
1594
case QTabBar::TriangularSouth:
1595
r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
1600
r = visualRect(twf->direction, twf->rect, r);
1603
case SE_TabWidgetRightCorner:
1604
if (const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(opt)) {
1605
QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
1606
switch (twf->shape) {
1607
case QTabBar::RoundedNorth:
1608
case QTabBar::TriangularNorth:
1609
r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
1610
paneRect.y() - twf->leftCornerWidgetSize.height()),
1611
twf->rightCornerWidgetSize);
1613
case QTabBar::RoundedSouth:
1614
case QTabBar::TriangularSouth:
1615
r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
1616
paneRect.height()), twf->rightCornerWidgetSize);
1621
r = visualRect(twf->direction, twf->rect, r);
1624
case SE_TabBarTearIndicator:
1625
if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1626
switch (tab->shape) {
1627
case QTabBar::RoundedNorth:
1628
case QTabBar::TriangularNorth:
1629
case QTabBar::RoundedSouth:
1630
case QTabBar::TriangularSouth:
1631
r.setRect(tab->rect.left(), tab->rect.top(), 4, opt->rect.height());
1633
case QTabBar::RoundedWest:
1634
case QTabBar::TriangularWest:
1635
case QTabBar::RoundedEast:
1636
case QTabBar::TriangularEast:
1637
r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 4);
1642
r = visualRect(opt->direction, opt->rect, r);
1651
static qreal angle(const QPoint &p1, const QPoint &p2)
1653
static const double rad_factor = 180.0 / Q_PI;
1656
if (p1.x() == p2.x()) {
1657
if (p1.y() < p2.y())
1662
double x1, x2, y1, y2;
1664
if (p1.x() <= p2.x()) {
1665
x1 = p1.x(); y1 = p1.y();
1666
x2 = p2.x(); y2 = p2.y();
1668
x2 = p1.x(); y2 = p1.y();
1669
x1 = p2.x(); y1 = p2.y();
1672
double m = -(y2 - y1) / (x2 - x1);
1673
_angle = atan(m) * rad_factor;
1675
if (p1.x() < p2.x())
1676
_angle = 180.0 - _angle;
1683
static int calcBigLineSize(int radius)
1685
int bigLineSize = radius / 6;
1686
if (bigLineSize < 4)
1688
if (bigLineSize > radius / 2)
1689
bigLineSize = radius / 2;
1693
static QPolygon calcArrow(const QStyleOptionSlider *dial, qreal &a)
1695
int width = dial->rect.width();
1696
int height = dial->rect.height();
1697
int r = qMin(width, height) / 2;
1698
if (dial->maximum == dial->minimum)
1700
else if (dial->dialWrapping)
1701
a = Q_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * Q_PI
1702
/ (dial->maximum - dial->minimum);
1704
a = (Q_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * Q_PI
1705
/ (dial->maximum - dial->minimum)) / 6;
1708
int yc = height / 2;
1710
int len = r - calcBigLineSize(r) - 5;
1718
arrow[0] = QPoint(int(0.5 + xc + len * qCos(a)),
1719
int(0.5 + yc - len * qSin(a)));
1720
arrow[1] = QPoint(int(0.5 + xc + back * qCos(a + Q_PI * 5 / 6)),
1721
int(0.5 + yc - back * qSin(a + Q_PI * 5 / 6)));
1722
arrow[2] = QPoint(int(0.5 + xc + back * qCos(a - Q_PI * 5 / 6)),
1723
int(0.5 + yc - back * qSin(a - Q_PI * 5 / 6)));
1727
static QPolygon calcLines(const QStyleOptionSlider *dial, const QWidget *)
1730
int width = dial->rect.width();
1731
int height = dial->rect.height();
1732
qreal r = qMin(width, height) / 2.0;
1733
int bigLineSize = calcBigLineSize(int(r));
1735
qreal xc = width / 2.0;
1736
qreal yc = height / 2.0;
1737
int ns = dial->tickInterval;
1738
int notches = (dial->maximum + ns - 1 - dial->minimum) / ns;
1739
poly.resize(2 + 2 * notches);
1740
int smallLineSize = bigLineSize / 2;
1741
for (int i = 0; i <= notches; ++i) {
1742
qreal angle = dial->dialWrapping ? Q_PI * 3 / 2 - i * 2 * Q_PI / notches
1743
: (Q_PI * 8 - i * 10 * Q_PI / notches) / 6;
1744
qreal s = qSin(angle);
1745
qreal c = qCos(angle);
1746
if (i == 0 || (((ns * i) % dial->pageStep) == 0)) {
1747
poly[2 * i] = QPoint(int(xc + (r - bigLineSize) * c),
1748
int(yc - (r - bigLineSize) * s));
1749
poly[2 * i + 1] = QPoint(int(xc + r * c), int(yc - r * s));
1751
poly[2 * i] = QPoint(int(xc + (r - 1 - smallLineSize) * c),
1752
int(yc - (r - 1 - smallLineSize) * s));
1753
poly[2 * i + 1] = QPoint(int(xc + (r - 1) * c), int(yc -(r - 1) * s));
1762
void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
1763
QPainter *p, const QWidget *widget) const
1767
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1768
if (slider->subControls == SC_SliderTickmarks) {
1769
int tickOffset = pixelMetric(PM_SliderTickmarkOffset, slider, widget);
1770
int ticks = slider->tickPosition;
1771
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
1772
int len = pixelMetric(PM_SliderLength, slider, widget);
1773
int available = pixelMetric(PM_SliderSpaceAvailable, slider, widget);
1774
int interval = slider->tickInterval;
1775
if (interval <= 0) {
1776
interval = slider->singleStep;
1777
if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
1779
- QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
1781
interval = slider->pageStep;
1785
int fudge = len / 2;
1787
p->setPen(slider->palette.foreground().color());
1788
int v = slider->minimum;
1789
while (v <= slider->maximum + 1) {
1790
pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum + 1,
1791
v, available) + fudge;
1792
if (slider->orientation == Qt::Horizontal) {
1793
if (ticks & QSlider::TicksAbove)
1794
p->drawLine(pos, 0, pos, tickOffset - 2);
1795
if (ticks & QSlider::TicksBelow)
1796
p->drawLine(pos, tickOffset + thickness + 1, pos,
1797
tickOffset + thickness + 1 + available - 2);
1799
if (ticks & QSlider::TicksAbove)
1800
p->drawLine(0, pos, tickOffset - 2, pos);
1801
if (ticks & QSlider::TicksBelow)
1802
p->drawLine(tickOffset + thickness + 1, pos,
1803
tickOffset + thickness + 1 + available - 2, pos);
1811
if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1812
// Make a copy here and reset it for each primitive.
1813
QStyleOptionSlider newScrollbar = *scrollbar;
1814
State saveFlags = scrollbar->state;
1815
if (scrollbar->minimum == scrollbar->maximum)
1816
saveFlags |= State_Enabled;
1818
if (scrollbar->subControls & SC_ScrollBarSubLine) {
1819
newScrollbar.state = saveFlags;
1820
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine, widget);
1821
if (newScrollbar.rect.isValid()) {
1822
if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
1823
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1824
drawControl(CE_ScrollBarSubLine, &newScrollbar, p, widget);
1827
if (scrollbar->subControls & SC_ScrollBarAddLine) {
1828
newScrollbar.rect = scrollbar->rect;
1829
newScrollbar.state = saveFlags;
1830
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine, widget);
1831
if (newScrollbar.rect.isValid()) {
1832
if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
1833
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1834
drawControl(CE_ScrollBarAddLine, &newScrollbar, p, widget);
1837
if (scrollbar->subControls & SC_ScrollBarSubPage) {
1838
newScrollbar.rect = scrollbar->rect;
1839
newScrollbar.state = saveFlags;
1840
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage, widget);
1841
if (newScrollbar.rect.isValid()) {
1842
if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage))
1843
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1844
drawControl(CE_ScrollBarSubPage, &newScrollbar, p, widget);
1847
if (scrollbar->subControls & SC_ScrollBarAddPage) {
1848
newScrollbar.rect = scrollbar->rect;
1849
newScrollbar.state = saveFlags;
1850
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage, widget);
1851
if (newScrollbar.rect.isValid()) {
1852
if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage))
1853
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1854
drawControl(CE_ScrollBarAddPage, &newScrollbar, p, widget);
1857
if (scrollbar->subControls & SC_ScrollBarFirst) {
1858
newScrollbar.rect = scrollbar->rect;
1859
newScrollbar.state = saveFlags;
1860
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarFirst, widget);
1861
if (newScrollbar.rect.isValid()) {
1862
if (!(scrollbar->activeSubControls & SC_ScrollBarFirst))
1863
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1864
drawControl(CE_ScrollBarFirst, &newScrollbar, p, widget);
1867
if (scrollbar->subControls & SC_ScrollBarLast) {
1868
newScrollbar.rect = scrollbar->rect;
1869
newScrollbar.state = saveFlags;
1870
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarLast, widget);
1871
if (newScrollbar.rect.isValid()) {
1872
if (!(scrollbar->activeSubControls & SC_ScrollBarLast))
1873
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1874
drawControl(CE_ScrollBarLast, &newScrollbar, p, widget);
1877
if (scrollbar->subControls & SC_ScrollBarSlider) {
1878
newScrollbar.rect = scrollbar->rect;
1879
newScrollbar.state = saveFlags;
1880
newScrollbar.rect = subControlRect(cc, &newScrollbar, SC_ScrollBarSlider, widget);
1881
if (newScrollbar.rect.isValid()) {
1882
if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
1883
newScrollbar.state &= ~(State_Sunken | State_MouseOver);
1884
drawControl(CE_ScrollBarSlider, &newScrollbar, p, widget);
1886
if (scrollbar->state & State_HasFocus) {
1887
QStyleOptionFocusRect fropt;
1888
fropt.QStyleOption::operator=(newScrollbar);
1889
fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2,
1890
newScrollbar.rect.width() - 5,
1891
newScrollbar.rect.height() - 5);
1892
drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1899
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
1900
if (lv->subControls & SC_Q3ListView)
1901
p->fillRect(lv->rect, lv->viewportPalette.brush(lv->viewportBGRole));
1905
if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
1906
QStyleOptionSpinBox copy = *sb;
1907
PrimitiveElement pe;
1909
if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
1910
QRect r = subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
1911
qDrawWinPanel(p, r, sb->palette, true);
1914
if (sb->subControls & SC_SpinBoxUp) {
1915
copy.subControls = SC_SpinBoxUp;
1916
QPalette pal2 = sb->palette;
1917
if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
1918
pal2.setCurrentColorGroup(QPalette::Disabled);
1919
copy.state &= ~State_Enabled;
1922
copy.palette = pal2;
1924
if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
1925
copy.state |= State_On;
1926
copy.state |= State_Sunken;
1928
copy.state |= State_Raised;
1929
copy.state &= ~State_Sunken;
1931
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
1932
: PE_IndicatorSpinUp);
1934
copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
1935
drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
1936
copy.rect.adjust(3, 0, -4, 0);
1937
drawPrimitive(pe, ©, p, widget);
1940
if (sb->subControls & SC_SpinBoxDown) {
1941
copy.subControls = SC_SpinBoxDown;
1942
copy.state = sb->state;
1943
QPalette pal2 = sb->palette;
1944
if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
1945
pal2.setCurrentColorGroup(QPalette::Disabled);
1946
copy.state &= ~State_Enabled;
1948
copy.palette = pal2;
1950
if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
1951
copy.state |= State_On;
1952
copy.state |= State_Sunken;
1954
copy.state |= State_Raised;
1955
copy.state &= ~State_Sunken;
1957
pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
1958
: PE_IndicatorSpinDown);
1960
copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
1961
drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
1962
copy.rect.adjust(3, 0, -4, 0);
1963
drawPrimitive(pe, ©, p, widget);
1968
if (const QStyleOptionToolButton *toolbutton
1969
= qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
1970
QRect button, menuarea;
1971
button = subControlRect(cc, toolbutton, SC_ToolButton, widget);
1972
menuarea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
1974
State bflags = toolbutton->state;
1976
if (bflags & State_AutoRaise) {
1977
if (!(bflags & State_MouseOver)) {
1978
bflags &= ~State_Raised;
1981
State mflags = bflags;
1983
if (toolbutton->activeSubControls & SC_ToolButton)
1984
bflags |= State_Sunken;
1985
if (toolbutton->activeSubControls & SC_ToolButtonMenu)
1986
mflags |= State_Sunken;
1988
QStyleOption tool(0);
1989
tool.palette = toolbutton->palette;
1990
if (toolbutton->subControls & SC_ToolButton) {
1991
if (bflags & (State_Sunken | State_On | State_Raised)) {
1993
tool.state = bflags;
1994
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
1998
if (toolbutton->subControls & SC_ToolButtonMenu) {
1999
tool.rect = menuarea;
2000
tool.state = mflags;
2001
if (mflags & (State_Sunken | State_On | State_Raised))
2002
drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
2003
drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
2006
if (toolbutton->state & State_HasFocus) {
2007
QStyleOptionFocusRect fr;
2008
fr.QStyleOption::operator=(*toolbutton);
2009
fr.rect.adjust(3, 3, -3, -3);
2010
if (toolbutton->features & QStyleOptionToolButton::Menu)
2011
fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator,
2012
toolbutton, widget), 0);
2013
drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
2015
QStyleOptionToolButton label = *toolbutton;
2016
int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
2017
label.rect = button.adjusted(fw, fw, -fw, -fw);
2018
drawControl(CE_ToolButtonLabel, &label, p, widget);
2022
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
2024
if (opt->subControls & SC_TitleBarLabel) {
2025
QColor left = tb->palette.highlight().color();
2026
QColor right = tb->palette.base().color();
2028
QBrush fillBrush(left);
2029
if (left != right) {
2030
QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
2031
QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
2032
QLinearGradient lg(p1, p2);
2033
lg.setColorAt(0, left);
2034
lg.setColorAt(1, right);
2038
p->fillRect(opt->rect, fillBrush);
2040
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
2042
p->setPen(tb->palette.highlightedText().color());
2043
p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(),
2044
Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
2050
QStyleOption tool(0);
2051
tool.palette = tb->palette;
2052
if (tb->subControls & SC_TitleBarCloseButton) {
2053
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget);
2054
down = tb->activeSubControls & SC_TitleBarCloseButton;
2055
if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool
2056
#ifndef QT_NO_MAINWINDOW
2057
|| qobject_cast<const QDockWidget *>(widget)
2060
pm = standardPixmap(SP_DockWidgetCloseButton, &tool, widget);
2062
pm = standardPixmap(SP_TitleBarCloseButton, &tool, widget);
2064
tool.state = down ? State_Sunken : State_Raised;
2065
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2069
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2070
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2071
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2075
if (tb->subControls & SC_TitleBarMaxButton
2076
&& tb->titleBarFlags & Qt::WindowMaximizeButtonHint) {
2077
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
2079
down = tb->activeSubControls & SC_TitleBarMaxButton;
2080
pm = standardPixmap(SP_TitleBarMaxButton, &tool, widget);
2082
tool.state = down ? State_Sunken : State_Raised;
2083
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2087
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2088
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2089
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2093
if ((tb->subControls & SC_TitleBarNormalButton
2094
|| tb->subControls & SC_TitleBarMinButton)
2095
&& tb->titleBarFlags & Qt::WindowMinimizeButtonHint) {
2096
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget);
2098
QStyle::SubControl ctrl = (tb->subControls & SC_TitleBarNormalButton ?
2099
SC_TitleBarNormalButton :
2100
SC_TitleBarMinButton);
2101
QStyle::StandardPixmap spixmap = (tb->subControls & SC_TitleBarNormalButton ?
2102
SP_TitleBarNormalButton :
2103
SP_TitleBarMinButton);
2104
down = tb->activeSubControls & ctrl;
2105
pm = standardPixmap(spixmap, &tool, widget);
2107
tool.state = down ? State_Sunken : State_Raised;
2108
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2112
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2113
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2114
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2118
if (tb->subControls & SC_TitleBarShadeButton) {
2119
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
2121
down = tb->activeSubControls & SC_TitleBarShadeButton;
2122
pm = standardPixmap(SP_TitleBarShadeButton, &tool, widget);
2124
tool.state = down ? State_Sunken : State_Raised;
2125
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2128
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2129
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2130
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2134
if (tb->subControls & SC_TitleBarUnshadeButton) {
2135
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
2137
down = tb->activeSubControls & SC_TitleBarUnshadeButton;
2138
pm = standardPixmap(SP_TitleBarUnshadeButton, &tool, widget);
2140
tool.state = down ? State_Sunken : State_Raised;
2141
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2144
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2145
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2146
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2149
if (tb->subControls & SC_TitleBarContextHelpButton
2150
&& tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
2151
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
2153
down = tb->activeSubControls & SC_TitleBarContextHelpButton;
2154
pm = standardPixmap(SP_TitleBarContextHelpButton, &tool, widget);
2156
tool.state = down ? State_Sunken : State_Raised;
2157
drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
2160
p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
2161
pixelMetric(PM_ButtonShiftVertical, tb, widget));
2162
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2165
if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
2166
ir = subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget);
2167
if (!tb->icon.isNull()) {
2168
tb->icon.paint(p, ir);
2170
pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
2173
drawItemPixmap(p, ir, Qt::AlignCenter, pm);
2180
if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2181
// OK, this is more a port of things over
2185
if (p->device()->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
2186
p->setRenderHint(QPainter::Antialiasing);
2188
int width = dial->rect.width();
2189
int height = dial->rect.height();
2190
qreal r = qMin(width, height) / 2.0;
2192
qreal dx = d_ + (width - 2 * r) / 2.0 + 1;
2193
qreal dy = d_ + (height - 2 * r) / 2.0 + 1;
2194
QRect br = QRect(int(dx), int(dy), int(r * 2 - 2 * d_ - 2), int(r * 2 - 2 * d_ - 2));
2196
QPalette pal = opt->palette;
2198
if (dial->subControls & QStyle::SC_DialTickmarks) {
2199
p->setPen(pal.foreground().color());
2200
p->drawLines(calcLines(dial, widget)); // ### calcLines could be cached...
2203
if (dial->state & State_Enabled) {
2204
p->setBrush(pal.brush(QPalette::ColorRole(styleHint(SH_Dial_BackgroundRole,
2206
p->setPen(Qt::NoPen);
2208
p->setBrush(Qt::NoBrush);
2210
p->setPen(QPen(pal.dark().color()));
2211
p->drawArc(br, 60 * 16, 180 * 16);
2212
p->setPen(QPen(pal.light().color()));
2213
p->drawArc(br, 240 * 16, 180 * 16);
2216
QPolygon arrow(calcArrow(dial, a));
2218
p->setPen(Qt::NoPen);
2219
p->setBrush(pal.button());
2220
p->drawPolygon(arrow);
2222
a = angle(QPoint(width / 2, height / 2), arrow[0]);
2223
p->setBrush(Qt::NoBrush);
2225
if (a <= 0 || a > 200) {
2226
p->setPen(pal.light().color());
2227
p->drawLine(arrow[2], arrow[0]);
2228
p->drawLine(arrow[1], arrow[2]);
2229
p->setPen(pal.dark().color());
2230
p->drawLine(arrow[0], arrow[1]);
2231
} else if (a > 0 && a < 45) {
2232
p->setPen(pal.light().color());
2233
p->drawLine(arrow[2], arrow[0]);
2234
p->setPen(pal.dark().color());
2235
p->drawLine(arrow[1], arrow[2]);
2236
p->drawLine(arrow[0], arrow[1]);
2237
} else if (a >= 45 && a < 135) {
2238
p->setPen(pal.dark().color());
2239
p->drawLine(arrow[2], arrow[0]);
2240
p->drawLine(arrow[1], arrow[2]);
2241
p->setPen(pal.light().color());
2242
p->drawLine(arrow[0], arrow[1]);
2243
} else if (a >= 135 && a < 200) {
2244
p->setPen(pal.dark().color());
2245
p->drawLine(arrow[2], arrow[0]);
2246
p->setPen(pal.light().color());
2247
p->drawLine(arrow[0], arrow[1]);
2248
p->drawLine(arrow[1], arrow[2]);
2251
// draw focus rect around the dial
2252
QStyleOptionFocusRect fropt;
2253
fropt.rect = dial->rect;
2254
fropt.state = dial->state;
2255
fropt.palette = dial->palette;
2256
if (fropt.state & QStyle::State_HasFocus) {
2257
br.adjust(0, 0, 2, 2);
2258
if (dial->subControls & SC_DialTickmarks) {
2259
int r = qMin(width, height) / 2;
2260
br.translate(-r / 6, - r / 6);
2261
br.setWidth(br.width() + r / 3);
2262
br.setHeight(br.height() + r / 3);
2264
fropt.rect = br.adjusted(-2, -2, 2, 2);
2265
drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
2271
qWarning("drawComplexControl control not handled %d", cc);
2278
QStyle::SubControl QCommonStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
2279
const QPoint &pt, const QWidget *widget) const
2281
SubControl sc = SC_None;
2284
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2285
QRect r = subControlRect(cc, slider, SC_SliderHandle, widget);
2286
if (r.isValid() && r.contains(pt)) {
2287
sc = SC_SliderHandle;
2289
r = subControlRect(cc, slider, SC_SliderGroove ,widget);
2290
if (r.isValid() && r.contains(pt))
2291
sc = SC_SliderGroove;
2296
if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2298
uint ctrl = SC_ScrollBarAddLine;
2299
while (ctrl <= SC_ScrollBarGroove) {
2300
r = subControlRect(cc, scrollbar, QStyle::SubControl(ctrl), widget);
2301
if (r.isValid() && r.contains(pt)) {
2302
sc = QStyle::SubControl(ctrl);
2310
if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
2311
if (pt.x() >= 0 && pt.x() < lv->treeStepSize)
2312
sc = SC_Q3ListViewExpand;
2316
if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2318
uint ctrl = SC_SpinBoxUp;
2319
while (ctrl <= SC_SpinBoxEditField) {
2320
r = subControlRect(cc, spinbox, QStyle::SubControl(ctrl), widget);
2321
if (r.isValid() && r.contains(pt)) {
2322
sc = QStyle::SubControl(ctrl);
2331
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
2333
uint ctrl = SC_TitleBarSysMenu;
2335
while (ctrl <= SC_TitleBarLabel) {
2336
r = subControlRect(cc, tb, QStyle::SubControl(ctrl), widget);
2337
if (r.isValid() && r.contains(pt)) {
2338
sc = QStyle::SubControl(ctrl);
2346
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2348
uint ctrl = SC_ComboBoxArrow; // Start here and go down.
2350
r = subControlRect(cc, cb, QStyle::SubControl(ctrl), widget);
2351
if (r.isValid() && r.contains(pt)) {
2352
sc = QStyle::SubControl(ctrl);
2360
qWarning("QCommonStyle::hitTestComplexControl case not handled %d", cc);
2368
QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
2369
SubControl sc, const QWidget *widget) const
2374
if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2375
int tickOffset = pixelMetric(PM_SliderTickmarkOffset, slider, widget);
2376
int thickness = pixelMetric(PM_SliderControlThickness, slider, widget);
2379
case SC_SliderHandle: {
2381
int len = pixelMetric(PM_SliderLength, slider, widget);
2382
bool horizontal = slider->orientation == Qt::Horizontal;
2383
sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
2384
slider->sliderPosition,
2385
(horizontal ? slider->rect.width()
2386
: slider->rect.height()) - len,
2387
slider->upsideDown);
2389
ret.setRect(sliderPos, tickOffset, len, thickness);
2391
ret.setRect(tickOffset, sliderPos, thickness, len);
2393
case SC_SliderGroove:
2394
if (slider->orientation == Qt::Horizontal)
2395
ret.setRect(0, tickOffset, slider->rect.width(), thickness);
2397
ret.setRect(tickOffset, 0, thickness, slider->rect.height());
2402
ret = visualRect(slider->direction, slider->rect, ret);
2406
if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2407
int sbextent = pixelMetric(PM_ScrollBarExtent, scrollbar, widget);
2408
int maxlen = ((scrollbar->orientation == Qt::Horizontal) ?
2409
scrollbar->rect.width() : scrollbar->rect.height()) - (sbextent * 2);
2412
// calculate slider length
2413
if (scrollbar->maximum != scrollbar->minimum) {
2414
uint range = scrollbar->maximum - scrollbar->minimum;
2415
sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep);
2417
int slidermin = pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget);
2418
if (sliderlen < slidermin || range > INT_MAX / 2)
2419
sliderlen = slidermin;
2420
if (sliderlen > maxlen)
2426
int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
2428
scrollbar->sliderPosition,
2430
scrollbar->upsideDown);
2432
case SC_ScrollBarSubLine: // top/left button
2433
if (scrollbar->orientation == Qt::Horizontal) {
2434
int buttonWidth = qMin(scrollbar->rect.width() / 2, sbextent);
2435
ret.setRect(0, 0, buttonWidth, sbextent);
2437
int buttonHeight = qMin(scrollbar->rect.height() / 2, sbextent);
2438
ret.setRect(0, 0, sbextent, buttonHeight);
2441
case SC_ScrollBarAddLine: // bottom/right button
2442
if (scrollbar->orientation == Qt::Horizontal) {
2443
int buttonWidth = qMin(scrollbar->rect.width()/2, sbextent);
2444
ret.setRect(scrollbar->rect.width() - buttonWidth, 0, buttonWidth, sbextent);
2446
int buttonHeight = qMin(scrollbar->rect.height()/2, sbextent);
2447
ret.setRect(0, scrollbar->rect.height() - buttonHeight, sbextent, buttonHeight);
2450
case SC_ScrollBarSubPage: // between top/left button and slider
2451
if (scrollbar->orientation == Qt::Horizontal)
2452
ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
2454
ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
2456
case SC_ScrollBarAddPage: // between bottom/right button and slider
2457
if (scrollbar->orientation == Qt::Horizontal)
2458
ret.setRect(sliderstart + sliderlen, 0,
2459
maxlen - sliderstart - sliderlen + sbextent, sbextent);
2461
ret.setRect(0, sliderstart + sliderlen, sbextent,
2462
maxlen - sliderstart - sliderlen + sbextent);
2464
case SC_ScrollBarGroove:
2465
if (scrollbar->orientation == Qt::Horizontal)
2466
ret.setRect(sbextent, 0, scrollbar->rect.width() - sbextent * 2,
2467
scrollbar->rect.height());
2469
ret.setRect(0, sbextent, scrollbar->rect.width(),
2470
scrollbar->rect.height() - sbextent * 2);
2472
case SC_ScrollBarSlider:
2473
if (scrollbar->orientation == Qt::Horizontal)
2474
ret.setRect(sliderstart, 0, sliderlen, sbextent);
2476
ret.setRect(0, sliderstart, sbextent, sliderlen);
2481
ret = visualRect(scrollbar->direction, scrollbar->rect, ret);
2485
if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2487
int fw = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
2488
bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw));
2489
// 1.6 -approximate golden mean
2490
bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4)));
2491
bs = bs.expandedTo(QApplication::globalStrut());
2494
x = spinbox->rect.width() - y - bs.width();
2499
ret = QRect(x, y, bs.width(), bs.height());
2501
case SC_SpinBoxDown:
2502
ret = QRect(x, y + bs.height(), bs.width(), bs.height());
2504
case SC_SpinBoxEditField:
2505
ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
2507
case SC_SpinBoxFrame:
2508
ret = spinbox->rect;
2512
ret = visualRect(spinbox->direction, spinbox->rect, ret);
2516
if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
2517
int mbi = pixelMetric(PM_MenuButtonIndicator, tb, widget);
2522
& (QStyleOptionToolButton::Menu | QStyleOptionToolButton::PopupDelay))
2523
== QStyleOptionToolButton::Menu)
2524
ret.adjust(0, 0, -mbi, 0);
2526
case SC_ToolButtonMenu:
2528
& (QStyleOptionToolButton::Menu | QStyleOptionToolButton::PopupDelay))
2529
== QStyleOptionToolButton::Menu)
2530
ret.adjust(ret.width() - mbi, 0, 0, 0);
2535
ret = visualRect(tb->direction, tb->rect, ret);
2539
if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2542
wi = cb->rect.width(),
2543
he = cb->rect.height();
2545
int margin = cb->frame ? 3 : 0;
2546
int bmarg = cb->frame ? 2 : 0;
2547
xpos += wi - bmarg - 16;
2551
case SC_ComboBoxFrame:
2554
case SC_ComboBoxArrow:
2555
ret.setRect(xpos, y + bmarg, 16, he - 2*bmarg);
2557
case SC_ComboBoxEditField:
2558
ret.setRect(x + margin, y + margin, wi - 2 * margin - 16, he - 2 * margin);
2560
case SC_ComboBoxListBoxPopup:
2561
ret = cb->popupRect;
2566
ret = visualRect(cb->direction, cb->rect, ret);
2570
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
2571
const int controlMargin = 2;
2572
const int controlHeight = tb->rect.height() - controlMargin *2;
2573
const int delta = controlHeight + controlMargin;
2576
bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
2579
case SC_TitleBarLabel:
2580
if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
2582
if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
2583
ret.adjust(delta, 0, -delta, 0);
2584
if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
2585
ret.adjust(0, 0, -delta, 0);
2586
if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
2587
ret.adjust(0, 0, -delta, 0);
2588
if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
2589
ret.adjust(0, 0, -delta, 0);
2590
if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
2591
ret.adjust(0, 0, -delta, 0);
2594
case SC_TitleBarContextHelpButton:
2595
if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
2597
case SC_TitleBarMinButton:
2598
if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
2600
else if (sc == SC_TitleBarMinButton)
2602
case SC_TitleBarNormalButton:
2603
if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
2605
else if (sc == SC_TitleBarNormalButton)
2607
case SC_TitleBarMaxButton:
2608
if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
2610
else if (sc == SC_TitleBarMaxButton)
2612
case SC_TitleBarShadeButton:
2613
if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
2615
else if (sc == SC_TitleBarShadeButton)
2617
case SC_TitleBarUnshadeButton:
2618
if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
2620
else if (sc == SC_TitleBarUnshadeButton)
2622
case SC_TitleBarCloseButton:
2623
if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
2625
else if (sc == SC_TitleBarCloseButton)
2627
ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
2628
controlHeight, controlHeight);
2630
case SC_TitleBarSysMenu:
2631
if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
2632
ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
2633
controlHeight, controlHeight);
2639
ret = visualRect(tb->direction, tb->rect, ret);
2643
qWarning("QCommonStyle::subControlRect case not handled %d", cc);
2649
int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const
2654
case PM_FocusFrameVMargin:
2655
case PM_FocusFrameHMargin:
2658
case PM_MenuBarVMargin:
2659
case PM_MenuBarHMargin:
2662
case PM_DialogButtonsSeparator:
2665
case PM_DialogButtonsButtonWidth:
2668
case PM_DialogButtonsButtonHeight:
2671
case PM_CheckListControllerSize:
2672
case PM_CheckListButtonSize:
2675
case PM_TitleBarHeight: {
2676
if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
2677
if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool) {
2678
ret = qMax(widget ? widget->fontMetrics().lineSpacing() : 0, 16);
2679
#ifndef QT_NO_MAINWINDOW
2680
} else if (qobject_cast<const QDockWidget*>(widget)) {
2681
ret = qMax(widget->fontMetrics().lineSpacing(), 13);
2684
ret = qMax(widget ? widget->fontMetrics().lineSpacing() : 0, 18);
2691
case PM_ScrollBarSliderMin:
2695
case PM_ButtonMargin:
2699
case PM_ButtonDefaultIndicator:
2703
case PM_MenuButtonIndicator:
2707
ret = qMax(12, (opt->rect.height() - 4) / 3);
2710
case PM_ButtonShiftHorizontal:
2711
case PM_ButtonShiftVertical:
2713
case PM_DefaultFrameWidth:
2717
case PM_ComboBoxFrameWidth:
2718
case PM_SpinBoxFrameWidth:
2719
case PM_MenuPanelWidth:
2720
case PM_TabBarBaseOverlap:
2721
case PM_TabBarBaseHeight:
2722
ret = pixelMetric(PM_DefaultFrameWidth, opt, widget);
2725
case PM_MDIFrameWidth:
2729
case PM_MDIMinimizedWidth:
2733
#ifndef QT_NO_SCROLLBAR
2734
case PM_ScrollBarExtent:
2735
if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2736
int s = sb->orientation == Qt::Horizontal ?
2737
QApplication::globalStrut().height()
2738
: QApplication::globalStrut().width();
2745
case PM_MaximumDragDistance:
2749
#ifndef QT_NO_SLIDER
2750
case PM_SliderThickness:
2754
case PM_SliderTickmarkOffset:
2755
if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2756
int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height()
2758
int thickness = pixelMetric(PM_SliderControlThickness, sl, widget);
2759
int ticks = sl->tickPosition;
2761
if (ticks == QSlider::TicksBothSides)
2762
ret = (space - thickness) / 2;
2763
else if (ticks == QSlider::TicksAbove)
2764
ret = space - thickness;
2772
case PM_SliderSpaceAvailable:
2773
if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2774
if (sl->orientation == Qt::Horizontal)
2775
ret = sl->rect.width() - pixelMetric(PM_SliderLength, sl, widget);
2777
ret = sl->rect.height() - pixelMetric(PM_SliderLength, sl, widget);
2782
#endif // QT_NO_SLIDER
2784
case PM_DockWidgetSeparatorExtent:
2788
case PM_DockWidgetHandleExtent:
2792
case PM_DockWidgetFrameWidth:
2796
case PM_SpinBoxSliderHeight:
2797
case PM_MenuBarPanelWidth:
2801
case PM_MenuBarItemSpacing:
2805
case PM_ToolBarFrameWidth:
2809
case PM_ToolBarItemMargin:
2813
case PM_ToolBarItemSpacing:
2817
case PM_ToolBarHandleExtent:
2821
case PM_ToolBarSeparatorExtent:
2825
case PM_ToolBarExtensionExtent:
2829
case PM_TabBarTabOverlap:
2833
case PM_TabBarTabHSpace:
2837
case PM_TabBarTabShiftHorizontal:
2839
case PM_TabBarTabShiftVertical:
2843
#ifndef QT_NO_TABBAR
2844
case PM_TabBarTabVSpace: {
2845
const QStyleOptionTab *tb = qstyleoption_cast<const QStyleOptionTab *>(opt);
2846
if (tb && (tb->shape == QTabBar::RoundedNorth || tb->shape == QTabBar::RoundedSouth
2847
|| tb->shape == QTabBar::RoundedWest || tb->shape == QTabBar::RoundedEast))
2854
case PM_ProgressBarChunkWidth:
2858
case PM_IndicatorWidth:
2862
case PM_IndicatorHeight:
2866
case PM_ExclusiveIndicatorWidth:
2870
case PM_ExclusiveIndicatorHeight:
2874
case PM_MenuTearoffHeight:
2878
case PM_MenuScrollerHeight:
2882
case PM_MenuDesktopFrameWidth:
2883
case PM_MenuHMargin:
2884
case PM_MenuVMargin:
2888
case PM_HeaderMargin:
2891
case PM_HeaderMarkSize:
2894
case PM_HeaderGripMargin:
2897
case PM_TabBarScrollButtonWidth:
2901
case PM_DefaultTopLevelMargin:
2904
case PM_DefaultChildMargin:
2907
case PM_DefaultLayoutSpacing:
2911
case PM_ToolBarIconSize:
2912
ret = pixelMetric(PM_SmallIconSize);
2915
case PM_ListViewIconSize:
2916
ret = pixelMetric(PM_SmallIconSize);
2918
case PM_IconViewIconSize:
2919
ret = pixelMetric(PM_LargeIconSize);
2922
case PM_SmallIconSize:
2925
case PM_LargeIconSize:
2929
case PM_ToolTipLabelFrameWidth:
2943
QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2944
const QSize &csz, const QWidget *widget) const
2949
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2950
int w = csz.width(),
2952
bm = pixelMetric(PM_ButtonMargin, btn, widget),
2953
fw = pixelMetric(PM_DefaultFrameWidth, btn, widget) * 2;
2956
if (btn->features & QStyleOptionButton::AutoDefaultButton){
2957
int dbw = pixelMetric(PM_ButtonDefaultIndicator, btn, widget) * 2;
2964
case CT_RadioButton:
2966
if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2967
bool isRadio = (ct == CT_RadioButton);
2968
QRect irect = visualRect(btn->direction, btn->rect,
2969
subElementRect(isRadio ? SE_RadioButtonIndicator
2970
: SE_CheckBoxIndicator, btn, widget));
2971
int h = pixelMetric(isRadio ? PM_ExclusiveIndicatorHeight
2972
: PM_IndicatorHeight, btn, widget);
2973
int margins = (!btn->icon.isNull() && btn->text.isEmpty()) ? 0 : 10;
2974
sz += QSize(irect.right() + margins, 4);
2975
sz.setHeight(qMax(sz.height(), h));
2979
if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2980
bool checkable = mi->menuHasCheckableItems;
2981
int maxpmw = mi->maxIconWidth;
2982
int w = sz.width(), h = sz.height();
2983
if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2987
h = qMax(h, mi->fontMetrics.height() + 8);
2988
if (!mi->icon.isNull())
2989
h = qMax(h, mi->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal).height() + 4);
2991
if (mi->text.contains('\t'))
2995
if (checkable && maxpmw < 20)
2997
if (checkable || maxpmw > 0)
3004
sz = QSize(sz.width() + 6, sz.height() + 5);
3007
if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
3008
int fw = cmb->frame ? pixelMetric(PM_ComboBoxFrameWidth, opt, widget) * 2 : 0;
3009
sz = QSize(sz.width() + fw + 21, sz.height() + fw);
3012
case CT_HeaderSection:
3013
if (const QStyleOptionHeader *hdr = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
3014
int margin = pixelMetric(QStyle::PM_HeaderMargin);
3015
QSize icn = hdr->icon.isNull() ? QSize(0,0) : QSize(22,22);
3016
QSize txt = hdr->fontMetrics.size(0, hdr->text);
3017
sz.setHeight(margin + qMax(icn.height(), txt.height()) + margin);
3018
sz.setWidth(margin + icn.width() + margin + txt.width() + margin);
3027
case CT_MenuBarItem:
3031
case CT_ProgressBar:
3033
// just return the contentsSize for now
3034
// fall through intended
3043
int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget,
3044
QStyleHintReturn *hret) const
3049
#ifndef QT_NO_DIALOGBUTTONS
3050
case SH_DialogButtons_DefaultButton:
3051
ret = QDialogButtons::Accept;
3054
case SH_GroupBox_TextLabelVerticalAlignment:
3055
ret = Qt::AlignVCenter;
3058
case SH_GroupBox_TextLabelColor:
3062
case SH_Q3ListViewExpand_SelectMouseType:
3063
case SH_TabBar_SelectMouseType:
3064
ret = QEvent::MouseButtonPress;
3069
ret = Qt::WindowsStyle;
3073
case SH_TabBar_Alignment:
3074
case SH_Header_ArrowAlignment:
3075
ret = Qt::AlignLeft;
3078
case SH_TitleBar_AutoRaise:
3082
case SH_Menu_SubMenuPopupDelay:
3086
case SH_ProgressDialog_TextLabelAlignment:
3087
ret = Qt::AlignCenter;
3090
case SH_BlinkCursorWhenTextSelected:
3094
case SH_Table_GridLineColor:
3096
ret = opt->palette.color(QPalette::Mid).rgb();
3101
case SH_LineEdit_PasswordCharacter:
3105
case SH_ToolBox_SelectedPageTitleBold:
3109
case SH_UnderlineShortcut:
3113
case SH_SpinBox_ClickAutoRepeatRate:
3117
case SH_SpinBox_KeyPressAutoRepeatRate:
3121
case SH_Menu_FillScreenWithScroll:
3125
case SH_ToolTipLabel_Opacity:
3129
case SH_Button_FocusPolicy:
3130
ret = Qt::StrongFocus;
3133
case SH_MenuBar_DismissOnSecondClick:
3137
case SH_MessageBox_UseBorderForButtonSpacing:
3141
case SH_ToolButton_PopupDelay:
3145
case SH_FocusFrame_Mask:
3148
if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) {
3149
mask->region = widget->rect();
3150
int vmargin = pixelMetric(QStyle::PM_FocusFrameVMargin),
3151
hmargin = pixelMetric(QStyle::PM_FocusFrameHMargin);
3152
mask->region -= QRect(widget->rect().adjusted(hmargin, vmargin, -hmargin, -vmargin));
3157
case SH_RubberBand_Mask:
3158
if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
3160
if (rbOpt->shape == QRubberBand::Rectangle) {
3162
if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(hret)) {
3163
mask->region = opt->rect;
3164
int margin = pixelMetric(PM_DefaultFrameWidth) * 2;
3165
mask->region -= opt->rect.adjusted(margin, margin, -margin, -margin);
3171
case SH_SpinControls_DisableOnBounds:
3175
case SH_Dial_BackgroundRole:
3176
ret = QPalette::Background;
3179
case SH_ComboBox_LayoutDirection:
3180
ret = opt->direction;
3183
case SH_ItemView_EllipsisLocation:
3184
ret = Qt::AlignTrailing;
3187
case SH_ItemView_ShowDecorationSelected:
3191
case SH_ItemView_ActivateItemOnSingleClick:
3195
case SH_TitleBar_ModifyNotification:
3208
QPixmap QCommonStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *,
3209
const QWidget *) const
3211
#ifndef QT_NO_IMAGEIO_XPM
3212
switch (standardPixmap) {
3213
case SP_ToolBarHorizontalExtensionButton:
3214
if (QApplication::layoutDirection() == Qt::RightToLeft) {
3215
QImage im(tb_extension_arrow_h_xpm);
3216
im = im.mirrored(true, false);
3217
return QPixmap::fromImage(im);
3219
return QPixmap(tb_extension_arrow_h_xpm);
3220
case SP_ToolBarVerticalExtensionButton:
3221
return QPixmap(tb_extension_arrow_v_xpm);
3222
case SP_FileDialogStart:
3223
return QPixmap(filedialog_start_xpm);
3224
case SP_FileDialogEnd:
3225
return QPixmap(filedialog_end_xpm);
3226
case SP_FileDialogToParent:
3227
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/parentdir-16.png"));
3228
case SP_FileDialogNewFolder:
3229
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/newdirectory-16.png"));
3230
case SP_FileDialogDetailedView:
3231
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/viewdetailed-16.png"));
3232
case SP_FileDialogInfoView:
3233
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/fileinfo-16.png"));
3234
case SP_FileDialogContentsView:
3235
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/filecontents-16.png"));
3236
case SP_FileDialogListView:
3237
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/viewlist-16.png"));
3238
case SP_FileDialogBack:
3239
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/back-16.png"));
3240
case SP_DriveHDIcon:
3241
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/harddrive-16.png"));
3243
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/trash-16.png"));
3244
case SP_DriveFDIcon:
3245
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/floppy-16.png"));
3246
case SP_DriveNetIcon:
3247
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/networkdrive-16.png"));
3248
case SP_DesktopIcon:
3249
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/desktop-16.png"));
3250
case SP_ComputerIcon:
3251
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/computer-16.png"));
3252
case SP_DriveCDIcon:
3253
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/cdr-16.png"));
3254
case SP_DriveDVDIcon:
3255
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dvd-16.png"));
3256
case SP_DirOpenIcon:
3257
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/diropen-16.png"));
3258
case SP_DirClosedIcon:
3259
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dirclosed-16.png"));
3260
case SP_DirLinkIcon:
3261
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/dirlink-16.png"));
3263
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/file-16.png"));
3264
case SP_FileLinkIcon:
3265
return QPixmap(QLatin1String(":/trolltech/styles/commonstyle/images/filelink-16.png"));
3269
#endif // QT_NO_IMAGEIO_XPM
3273
static inline uint qt_intensity(uint r, uint g, uint b)
3275
// 30% red, 59% green, 11% blue
3276
return (77 * r + 150 * g + 28 * b) / 255;
3280
QPixmap QCommonStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
3281
const QStyleOption *opt) const
3284
case QIcon::Disabled: {
3285
QImage im = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
3287
// Create a colortable based on the background (black -> bg -> white)
3288
QColor bg = opt->palette.color(QPalette::Disabled, QPalette::Background);
3290
int green = bg.green();
3291
int blue = bg.blue();
3292
uchar reds[256], greens[256], blues[256];
3293
for (int i=0; i<128; ++i) {
3294
reds[i] = uchar((red * (i<<1)) >> 8);
3295
greens[i] = uchar((green * (i<<1)) >> 8);
3296
blues[i] = uchar((blue * (i<<1)) >> 8);
3298
for (int i=0; i<128; ++i) {
3299
reds[i+128] = uchar(qMin(red + (i << 1), 255));
3300
greens[i+128] = uchar(qMin(green + (i << 1), 255));
3301
blues[i+128] = uchar(qMin(blue + (i << 1), 255));
3304
int intensity = qt_intensity(red, green, blue);
3305
const int factor = 191;
3307
// High intensity colors needs dark shifting in the color table, while
3308
// low intensity colors needs light shifting. This is to increase the
3309
// percieved contrast.
3310
if ((red - factor > green && red - factor > blue)
3311
|| (green - factor > red && green - factor > blue)
3312
|| (blue - factor > red && blue - factor > green))
3313
intensity = qMin(255, intensity + 91);
3314
else if (intensity <= 128)
3317
for (int y=0; y<im.height(); ++y) {
3318
QRgb *scanLine = (QRgb*)im.scanLine(y);
3319
for (int x=0; x<im.width(); ++x) {
3320
QRgb pixel = *scanLine;
3321
// Calculate color table index, taking intensity adjustment
3322
// and a magic offset into account.
3323
uint ci = uint(qGray(pixel)/3 + (130 - intensity / 3));
3324
*scanLine = qRgba(reds[ci], greens[ci], blues[ci], qAlpha(pixel));
3329
return QPixmap::fromImage(im);
3339
#endif // QT_NO_STYLE