~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/styles/qcommonstyle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the style module of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qcommonstyle.h"
 
30
 
 
31
#ifndef QT_NO_STYLE
 
32
 
 
33
#include <qapplication.h>
 
34
#include <qbitmap.h>
 
35
#include <qcache.h>
 
36
#include <qdockwidget.h>
 
37
#include <qdrawutil.h>
 
38
#include <qgroupbox.h>
 
39
#include <qmenu.h>
 
40
#include <qpainter.h>
 
41
#include <qpaintengine.h>
 
42
#include <qpainterpath.h>
 
43
#include <qslider.h>
 
44
#include <qstyleoption.h>
 
45
#include <qtabbar.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>
 
51
 
 
52
#include <QtCore/qdebug.h>
 
53
 
 
54
#include <limits.h>
 
55
 
 
56
/*!
 
57
    \class QCommonStyle
 
58
    \brief The QCommonStyle class encapsulates the common Look and Feel of a GUI.
 
59
 
 
60
    \ingroup appearance
 
61
 
 
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
 
64
    Qt.
 
65
 
 
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.
 
71
*/
 
72
 
 
73
/*!
 
74
    Constructs a QCommonStyle.
 
75
*/
 
76
QCommonStyle::QCommonStyle()
 
77
    : QStyle()
 
78
{ }
 
79
 
 
80
/*!
 
81
    \overload
 
82
 
 
83
    Destroys the style
 
84
*/
 
85
QCommonStyle::~QCommonStyle()
 
86
{ }
 
87
 
 
88
 
 
89
/*!
 
90
    \reimp
 
91
*/
 
92
void QCommonStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
 
93
                                 const QWidget *widget) const
 
94
{
 
95
    switch (pe) {
 
96
    case PE_FrameButtonBevel:
 
97
    case PE_FrameButtonTool:
 
98
        qDrawShadeRect(p, opt->rect, opt->palette,
 
99
                       opt->state & (State_Sunken | State_On), 1, 0);
 
100
        break;
 
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));
 
108
        break;
 
109
    case PE_IndicatorViewItemCheck:
 
110
        drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
 
111
        break;
 
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());
 
118
        } else {
 
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));
 
122
        }
 
123
        break;
 
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());
 
131
            p->drawEllipse(ir);
 
132
        }
 
133
        break; }
 
134
    case PE_FrameFocusRect:
 
135
        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
 
136
            QColor bg = fropt->backgroundColor;
 
137
            QPen oldPen = p->pen();
 
138
            if (bg.isValid()) {
 
139
                int h, s, v;
 
140
                bg.getHsv(&h, &s, &v);
 
141
                if (v >= 128)
 
142
                    p->setPen(Qt::black);
 
143
                else
 
144
                    p->setPen(Qt::white);
 
145
            } else {
 
146
                p->setPen(opt->palette.foreground().color());
 
147
            }
 
148
            QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
 
149
            p->drawRect(focusRect.adjusted(0, 0, -1, -1)); //draw pen inclusive
 
150
            p->setPen(oldPen);
 
151
        }
 
152
        break;
 
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;
 
158
 
 
159
        QVector<QLineF> a;
 
160
        a.reserve(markH);
 
161
 
 
162
        int i, xx, yy;
 
163
        xx = posX;
 
164
        yy = 3 + posY;
 
165
        for (i = 0; i < markW/2; ++i) {
 
166
            a << QLineF(xx, yy, xx, yy + 2);
 
167
            ++xx;
 
168
            ++yy;
 
169
        }
 
170
        yy -= 2;
 
171
        for (; i < markH; ++i) {
 
172
            a << QLineF(xx, yy, xx, yy + 2);
 
173
            ++xx;
 
174
            --yy;
 
175
        }
 
176
        if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
 
177
            int pnt;
 
178
            p->setPen(opt->palette.highlightedText().color());
 
179
            QPoint offset(1, 1);
 
180
            for (pnt = 0; pnt < a.size(); ++pnt)
 
181
                a[pnt].translate(offset.x(), offset.y());
 
182
            p->drawLines(a);
 
183
            for (pnt = 0; pnt < a.size(); ++pnt)
 
184
                a[pnt].translate(offset.x(), offset.y());
 
185
        }
 
186
        p->setPen(opt->palette.text().color());
 
187
        p->drawLines(a);
 
188
        break; }
 
189
    case PE_Frame:
 
190
    case PE_FrameMenu:
 
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,
 
194
                                frame->lineWidth);
 
195
            } else {
 
196
                qDrawPlainRect(p, frame->rect, frame->palette.foreground().color(), frame->lineWidth);
 
197
            }
 
198
        }
 
199
        break;
 
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));
 
205
        break;
 
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));
 
209
        break;
 
210
    case PE_Q3CheckListController:
 
211
        p->drawPixmap(opt->rect.topLeft(), QPixmap(check_list_controller_xpm));
 
212
        break;
 
213
    case PE_Q3CheckListExclusiveIndicator:
 
214
        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
215
            if (lv->items.isEmpty())
 
216
                return;
 
217
            int x = lv->rect.x(),
 
218
                y = lv->rect.y();
 
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,
 
228
                11,4, 10,3, 10,2 };
 
229
            // static const int pts5[] = {                // inner fill
 
230
            //    4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
 
231
            //QPolygon a;
 
232
 
 
233
            if (lv->state & State_Enabled)
 
234
                p->setPen(lv->palette.text().color());
 
235
            else
 
236
                p->setPen(QPen(lv->viewportPalette.color(QPalette::Disabled, QPalette::Text)));
 
237
            QPolygon a(INTARRLEN(pts1), pts1);
 
238
            a.translate(x, y);
 
239
            //p->setPen(pal.dark());
 
240
            p->drawPolyline(a);
 
241
            a.setPoints(INTARRLEN(pts2), pts2);
 
242
            a.translate(x, y);
 
243
            p->drawPolyline(a);
 
244
            a.setPoints(INTARRLEN(pts3), pts3);
 
245
            a.translate(x, y);
 
246
            //                p->setPen(black);
 
247
            p->drawPolyline(a);
 
248
            a.setPoints(INTARRLEN(pts4), pts4);
 
249
            a.translate(x, y);
 
250
            //                        p->setPen(blue);
 
251
            p->drawPolyline(a);
 
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);
 
263
            }
 
264
#undef INTARRLEN
 
265
        }
 
266
        break;
 
267
    case PE_Q3CheckListIndicator:
 
268
        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
269
            if(lv->items.isEmpty())
 
270
                break;
 
271
            QStyleOptionQ3ListViewItem item = lv->items.at(0);
 
272
            int x = lv->rect.x(),
 
273
                y = lv->rect.y(),
 
274
                w = lv->rect.width(),
 
275
                h = lv->rect.width(),
 
276
             marg = lv->itemMargin;
 
277
 
 
278
            if (lv->state & State_Enabled)
 
279
                p->setPen(QPen(lv->palette.text().color(), 2));
 
280
            else
 
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));
 
288
            }
 
289
 
 
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
            /////////////////////
 
294
                ++x;
 
295
                ++y;
 
296
                if (lv->state & State_On || lv->state & State_NoChange) {
 
297
                    QLineF lines[7];
 
298
                    int i,
 
299
                        xx = x + 1 + marg,
 
300
                        yy = y + 5;
 
301
                    for (i = 0; i < 3; ++i) {
 
302
                        lines[i] = QLineF(xx, yy, xx, yy + 2);
 
303
                        ++xx;
 
304
                        ++yy;
 
305
                    }
 
306
                    yy -= 2;
 
307
                    for (i = 3; i < 7; ++i) {
 
308
                        lines[i] = QLineF(xx, yy, xx, yy + 2);
 
309
                        ++xx;
 
310
                        --yy;
 
311
                    }
 
312
                    p->drawLines(lines, 7);
 
313
                }
 
314
        }
 
315
        break;
 
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;
 
322
        int bef_h = mid_h;
 
323
        int bef_v = mid_v;
 
324
        int aft_h = mid_h;
 
325
        int aft_v = mid_v;
 
326
        if (opt->state & State_Children) {
 
327
            int delta = decoration_size / 2;
 
328
            bef_h -= delta;
 
329
            bef_v -= delta;
 
330
            aft_h += delta;
 
331
            aft_v += delta;
 
332
            p->drawPixmap(bef_h, bef_v, opt->state & State_Open ? open : closed);
 
333
        }
 
334
        if (opt->state & State_Item) {
 
335
            if (opt->direction == Qt::RightToLeft)
 
336
                p->drawLine(opt->rect.left(), mid_v, bef_h, mid_v);
 
337
            else
 
338
                p->drawLine(aft_h, mid_v, opt->rect.right(), mid_v);
 
339
        }
 
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);
 
344
        break; }
 
345
    case PE_Q3Separator:
 
346
        qDrawShadeLine(p, opt->rect.left(), opt->rect.top(), opt->rect.right(), opt->rect.bottom(),
 
347
                       opt->palette, opt->state & State_Sunken, 1, 0);
 
348
        break;
 
349
    case PE_FrameStatusBar:
 
350
        qDrawShadeRect(p, opt->rect, opt->palette, true, 1, 0, 0);
 
351
        break;
 
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) {
 
356
                QPolygon pa(3);
 
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());
 
364
                p->drawPolyline(pa);
 
365
            } else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
 
366
                QPolygon pa(3);
 
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());
 
371
                p->drawPolyline(pa);
 
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());
 
375
            }
 
376
            p->setPen(oldPen);
 
377
        }
 
378
        break;
 
379
    case PE_FrameTabBarBase:
 
380
        if (const QStyleOptionTabBarBase *tbb
 
381
                = qstyleoption_cast<const QStyleOptionTabBarBase *>(opt)) {
 
382
            QRegion region(tbb->rect);
 
383
            region -= tbb->selectedTabRect;
 
384
            p->save();
 
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());
 
391
                break;
 
392
            case QTabBar::RoundedWest:
 
393
            case QTabBar::TriangularWest:
 
394
                p->setPen(tbb->palette.light().color());
 
395
                p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
 
396
                break;
 
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);
 
405
                break;
 
406
            case QTabBar::RoundedEast:
 
407
            case QTabBar::TriangularEast:
 
408
                p->setPen(tbb->palette.dark().color());
 
409
                p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
 
410
                break;
 
411
            }
 
412
            p->restore();
 
413
        }
 
414
        break;
 
415
    case PE_FrameTabWidget:
 
416
    case PE_FrameWindow:
 
417
        qDrawWinPanel(p, opt->rect, opt->palette, false, 0);
 
418
        break;
 
419
    case PE_FrameLineEdit:
 
420
        drawPrimitive(PE_Frame, opt, p, widget);
 
421
        break;
 
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,
 
429
                               lwidth, mlwidth);
 
430
            else
 
431
                qDrawPlainRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
 
432
                               frame->rect.height(), frame->palette.foreground().color(), lwidth);
 
433
        }
 
434
        break;
 
435
    case PE_FrameDockWidget:
 
436
        if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
 
437
            int lw = frame->lineWidth;
 
438
            if (lw <= 0)
 
439
                lw = pixelMetric(PM_DockWidgetFrameWidth);
 
440
 
 
441
            qDrawShadePanel(p, frame->rect, frame->palette, false, lw);
 
442
        }
 
443
        break;
 
444
 
 
445
    case PE_IndicatorToolBarHandle:
 
446
        p->save();
 
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)
 
451
                x -= 2;
 
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);
 
457
            }
 
458
        } else {
 
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);
 
465
            }
 
466
        }
 
467
        p->restore();
 
468
        break;
 
469
    case PE_IndicatorToolBarSeparator:
 
470
        {
 
471
            QPoint p1, p2;
 
472
            if (opt->state & State_Horizontal) {
 
473
                p1 = QPoint(opt->rect.width()/2, 0);
 
474
                p2 = QPoint(p1.x(), opt->rect.height());
 
475
            } else {
 
476
                p1 = QPoint(0, opt->rect.height()/2);
 
477
                p2 = QPoint(opt->rect.width(), p1.y());
 
478
            }
 
479
            qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
 
480
            break;
 
481
        }
 
482
    case PE_IndicatorSpinPlus:
 
483
    case PE_IndicatorSpinMinus: {
 
484
        QRect r = opt->rect;
 
485
        int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
 
486
        QRect br = r.adjusted(fw, fw, -fw, -fw);
 
487
 
 
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,
 
491
                    br.width(), step,
 
492
                    opt->palette.buttonText());
 
493
        if (pe == PE_IndicatorSpinPlus)
 
494
            p->fillRect(br.x() + br.width() / 2 - step / 2 + offset, br.y() + offset,
 
495
                        step, br.height(),
 
496
                        opt->palette.buttonText());
 
497
 
 
498
        break; }
 
499
    case PE_IndicatorSpinUp:
 
500
    case PE_IndicatorSpinDown: {
 
501
        QRect r = opt->rect;
 
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();
 
505
        int sw = w-4;
 
506
        if (sw < 3)
 
507
            break;
 
508
        else if (!(sw & 1))
 
509
            sw--;
 
510
        sw -= (sw / 7) * 2;        // Empty border
 
511
        int sh = sw/2 + 2;      // Must have empty row at foot of arrow
 
512
 
 
513
        int sx = x + w / 2 - sw / 2;
 
514
        int sy = y + h / 2 - sh / 2;
 
515
 
 
516
        if (pe == PE_IndicatorSpinUp && fw)
 
517
            --sy;
 
518
 
 
519
        QPolygon a;
 
520
        if (pe == PE_IndicatorSpinDown)
 
521
            a.setPoints(3, 0, 1,  sw-1, 1,  sh-2, sh-1);
 
522
        else
 
523
            a.setPoints(3, 0, sh-1,  sw-1, sh-1,  sh-2, 1);
 
524
        int bsx = 0;
 
525
        int bsy = 0;
 
526
        if (opt->state & State_Sunken) {
 
527
            bsx = pixelMetric(PM_ButtonShiftHorizontal);
 
528
            bsy = pixelMetric(PM_ButtonShiftVertical);
 
529
        }
 
530
        p->save();
 
531
        p->translate(sx + bsx, sy + bsy);
 
532
        p->setPen(opt->palette.buttonText().color());
 
533
        p->setBrush(opt->palette.buttonText());
 
534
        p->drawPolygon(a);
 
535
        p->restore();
 
536
        break; }
 
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));
 
543
        p->setPen(oldPen);
 
544
        p->setBrush(oldBrush);
 
545
        break;
 
546
    }
 
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;
 
551
            QPainterPath path;
 
552
 
 
553
            rect.setTop(rect.top() + ((tab->state & State_Selected) ? 1 : 3));
 
554
            rect.setBottom(rect.bottom() - ((tab->state & State_Selected) ? 0 : 2));
 
555
 
 
556
            path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
 
557
            int count = 4;
 
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));
 
560
 
 
561
            p->setPen(QPen(tab->palette.light(), .8));
 
562
            p->setBrush(tab->palette.background());
 
563
            p->setRenderHint(QPainter::Antialiasing);
 
564
            p->drawPath(path);
 
565
        }
 
566
        break;
 
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);
 
572
            }
 
573
        }
 
574
        break;
 
575
    default:
 
576
        break;
 
577
    }
 
578
}
 
579
 
 
580
/*!
 
581
  \reimp
 
582
*/
 
583
void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
 
584
                               QPainter *p, const QWidget *widget) const
 
585
{
 
586
    switch (element) {
 
587
    case CE_PushButton:
 
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);
 
598
            }
 
599
        }
 
600
        break;
 
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;
 
612
                tmpBtn.rect = br;
 
613
                drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
 
614
            }
 
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);
 
621
            }
 
622
        }
 
623
        break;
 
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
 
633
                                                              : QIcon::Disabled;
 
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)
 
638
                    state = QIcon::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
 
643
 
 
644
                QPoint point;
 
645
                if (btn->text.isEmpty()) {
 
646
                    point = QPoint(ir.x() + ir.width() / 2 - pixw / 2,
 
647
                                   ir.y() + ir.height() / 2 - pixh / 2);
 
648
                } else {
 
649
                    point = QPoint(ir.x() + 2, ir.y() + ir.height() / 2 - pixh / 2);
 
650
                }
 
651
                if (btn->direction == Qt::RightToLeft)
 
652
                    point.rx() += pixw;
 
653
 
 
654
                if ((btn->state & (State_On | State_Sunken)) && btn->direction == Qt::RightToLeft)
 
655
                    point.rx() -= pixelMetric(PM_ButtonShiftHorizontal, opt, widget) * 2;
 
656
 
 
657
                p->drawPixmap(visualPos(btn->direction, btn->rect, point), pixmap);
 
658
 
 
659
                if (btn->direction == Qt::RightToLeft)
 
660
                    ir.translate(-4, 0);
 
661
                else
 
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())
 
666
                    tf |= Qt::AlignLeft;
 
667
            } else {
 
668
                tf |= Qt::AlignHCenter;
 
669
            }
 
670
            drawItemText(p, ir, tf, btn->palette, (btn->state & State_Enabled),
 
671
                         btn->text, QPalette::ButtonText);
 
672
        }
 
673
        break;
 
674
    case CE_RadioButton:
 
675
    case CE_CheckBox:
 
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,
 
682
                          &subopt, p, widget);
 
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);
 
692
            }
 
693
        }
 
694
        break;
 
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);
 
699
 
 
700
            if (!styleHint(SH_UnderlineShortcut, btn, widget))
 
701
                alignment |= Qt::TextHideMnemonic;
 
702
            QPixmap pix;
 
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);
 
709
                else
 
710
                    textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
 
711
            }
 
712
            if (!btn->text.isEmpty()){
 
713
                drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
 
714
                             btn->palette, btn->state & State_Enabled, btn->text);
 
715
            }
 
716
        }
 
717
        break;
 
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);
 
724
        break; }
 
725
    case CE_MenuTearoff:
 
726
        if (opt->state & State_Selected)
 
727
            p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
 
728
        else
 
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);
 
737
        break;
 
738
    case CE_MenuBarItem:
 
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);
 
745
            if (!pix.isNull())
 
746
                drawItemPixmap(p,mbi->rect, alignment, pix);
 
747
            else
 
748
                drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
 
749
                             mbi->text, QPalette::ButtonText);
 
750
        }
 
751
        break;
 
752
    case CE_MenuBarEmptyArea:
 
753
        if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))
 
754
            p->eraseRect(opt->rect);
 
755
        break;
 
756
    case CE_ProgressBar:
 
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);
 
767
            }
 
768
        }
 
769
        break;
 
770
    case CE_ProgressBarGroove:
 
771
        qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
 
772
                        &opt->palette.brush(QPalette::Background));
 
773
        break;
 
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);
 
782
        }
 
783
        break;
 
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;
 
792
            int fw = 2;
 
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);
 
797
                if (x > w)
 
798
                    x = 2 * w - x;
 
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);
 
802
            } else {
 
803
                const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
 
804
                int u;
 
805
                if (unit_width > 1)
 
806
                    u = (pb->rect.width() + unit_width / 3) / unit_width;
 
807
                else
 
808
                    u = w / unit_width;
 
809
                int p_v = pb->progress;
 
810
                int t_s = pb->maximum ? pb->maximum : 1;
 
811
 
 
812
                if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
 
813
                    // scale down to something usable.
 
814
                    p_v /= u;
 
815
                    t_s /= u;
 
816
                }
 
817
 
 
818
                // nu < tnu, if last chunk is only a partial chunk
 
819
                int tnu, nu;
 
820
                tnu = nu = p_v * u / t_s;
 
821
 
 
822
                if (nu * unit_width > w)
 
823
                    --nu;
 
824
 
 
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.
 
829
                int x = 0;
 
830
                int x0 = reverse ? pb->rect.right() - ((unit_width > 1) ? unit_width : fw)
 
831
                                 : pb->rect.x() + 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;
 
841
                }
 
842
 
 
843
                // Draw the last partial chunk to fill up the
 
844
                // progressbar entirely
 
845
                if (nu < tnu) {
 
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);
 
850
                }
 
851
            }
 
852
        }
 
853
        break;
 
854
    case CE_HeaderLabel:
 
855
        if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
 
856
            QRect rect = header->rect;
 
857
            if (!header->icon.isNull()) {
 
858
                QPixmap pixmap
 
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);
 
865
                else
 
866
                    rect.setRight(rect.right() - pixw - 2);
 
867
            }
 
868
            drawItemText(p, rect, header->textAlignment, header->palette,
 
869
                         (header->state & State_Enabled), header->text, QPalette::ButtonText);
 
870
        }
 
871
        break;
 
872
 
 
873
    case CE_ToolButtonLabel:
 
874
        if (const QStyleOptionToolButton *toolbutton
 
875
                = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
 
876
            QRect rect = toolbutton->rect;
 
877
            int shiftX = 0;
 
878
            int shiftY = 0;
 
879
            if (toolbutton->state & (State_Sunken | State_On)) {
 
880
                shiftX = pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
 
881
                shiftY = pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
 
882
            }
 
883
            if (toolbutton->features & QStyleOptionToolButton::Arrow) {
 
884
                PrimitiveElement pe;
 
885
                switch (toolbutton->arrowType) {
 
886
                case Qt::LeftArrow:
 
887
                    pe = PE_IndicatorArrowLeft;
 
888
                    break;
 
889
                case Qt::RightArrow:
 
890
                    pe = PE_IndicatorArrowRight;
 
891
                    break;
 
892
                case Qt::UpArrow:
 
893
                    pe = PE_IndicatorArrowUp;
 
894
                    break;
 
895
                case Qt::DownArrow:
 
896
                    pe = PE_IndicatorArrowDown;
 
897
                    break;
 
898
                default:
 
899
                    return;
 
900
                }
 
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);
 
907
            } else {
 
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);
 
917
                } else {
 
918
                    QPixmap pm;
 
919
                    QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
 
920
                    QIcon::Mode mode;
 
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;
 
925
                    else
 
926
                        mode = QIcon::Normal;
 
927
                    pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), mode, state);
 
928
 
 
929
                    if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
 
930
                        p->setFont(toolbutton->font);
 
931
                        QRect pr = rect,
 
932
                        tr = rect;
 
933
                        int alignment = Qt::TextShowMnemonic;
 
934
                        if (!styleHint(SH_UnderlineShortcut, opt, widget))
 
935
                            alignment |= Qt::TextHideMnemonic;
 
936
 
 
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;
 
944
                        } else {
 
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;
 
950
                        }
 
951
                        tr.translate(shiftX, shiftY);
 
952
                        drawItemText(p, tr, alignment, toolbutton->palette,
 
953
                                     toolbutton->state & State_Enabled, toolbutton->text,
 
954
                                     QPalette::ButtonText);
 
955
                    } else {
 
956
                        rect.translate(shiftX, shiftY);
 
957
                        drawItemPixmap(p, rect, Qt::AlignCenter, pm);
 
958
                    }
 
959
                }
 
960
            }
 
961
        }
 
962
        break;
 
963
    case CE_ToolBoxTab:
 
964
        if (const QStyleOptionToolBox *tb = qstyleoption_cast<const QStyleOptionToolBox *>(opt)) {
 
965
            int d = 20 + tb->rect.height() - 3;
 
966
            QPolygon a(7);
 
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);
 
974
 
 
975
            p->setPen(tb->palette.mid().color().dark(150));
 
976
            p->drawPolygon(a);
 
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);
 
983
        }
 
984
        break;
 
985
    case CE_TabBarTab:
 
986
        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
 
987
            drawControl(CE_TabBarTabShape, tab, p, widget);
 
988
            drawControl(CE_TabBarTabLabel, tab, p, widget);
 
989
        }
 
990
        break;
 
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());
 
997
            else
 
998
                p->setBrush(tab->palette.background());
 
999
            p->setPen(tab->palette.foreground().color());
 
1000
            int y;
 
1001
            int x;
 
1002
            QPolygon a(10);
 
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;
 
1009
                x = y / 3;
 
1010
                a.setPoint(2, x++, y - 1);
 
1011
                ++x;
 
1012
                a.setPoint(3, x++, y++);
 
1013
                a.setPoint(4, x, y);
 
1014
 
 
1015
                int i;
 
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());
 
1022
 
 
1023
                a.translate(tab->rect.left(), tab->rect.top());
 
1024
                p->drawPolygon(a);
 
1025
                break; }
 
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;
 
1031
                y = x / 3;
 
1032
                a.setPoint(2, x - 1, y++);
 
1033
                ++y;
 
1034
                a.setPoint(3, x++, y++);
 
1035
                a.setPoint(4, x, y);
 
1036
                int i;
 
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());
 
1044
                p->drawPolygon(a);
 
1045
                break; }
 
1046
            default:
 
1047
                break;
 
1048
            }
 
1049
            p->setPen(oldPen);
 
1050
            p->setBrush(oldBrush);
 
1051
        }
 
1052
        break;
 
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;
 
1061
            if (verticalTabs) {
 
1062
                p->save();
 
1063
                int newX, newY, newRot;
 
1064
                if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
 
1065
                    newX = tr.width();
 
1066
                    newY = tr.y();
 
1067
                    newRot = 90;
 
1068
                } else {
 
1069
                    newX = 0;
 
1070
                    newY = tr.y() + tr.height();
 
1071
                    newRot = -90;
 
1072
                }
 
1073
                tr.setRect(0, 0, tr.height(), tr.width());
 
1074
                QMatrix m;
 
1075
                m.translate(newX, newY);
 
1076
                m.rotate(newRot);
 
1077
                p->setMatrix(m, true);
 
1078
            }
 
1079
            if (selected) {
 
1080
                tr.setBottom(tr.bottom() - pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab,
 
1081
                                                       widget));
 
1082
                tr.setRight(tr.right() - pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab,
 
1083
                                                     widget));
 
1084
            }
 
1085
 
 
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);
 
1093
            }
 
1094
            drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::Foreground);
 
1095
 
 
1096
            if (verticalTabs)
 
1097
                p->restore();
 
1098
 
 
1099
            if (tab->state & State_HasFocus && !tab->text.isEmpty()) {
 
1100
                const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth);
 
1101
 
 
1102
                int x1, x2;
 
1103
                x1 = tab->rect.left();
 
1104
                x2 = tab->rect.right() - 1;
 
1105
 
 
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);
 
1111
            }
 
1112
        }
 
1113
        break;
 
1114
    case CE_SizeGrip: {
 
1115
        p->save();
 
1116
        int x, y, w, h;
 
1117
        opt->rect.getRect(&x, &y, &w, &h);
 
1118
 
 
1119
        int sw = qMin(h, w);
 
1120
        if (h > w)
 
1121
            p->translate(0, h - w);
 
1122
        else
 
1123
            p->translate(w - h, 0);
 
1124
 
 
1125
        int sx = x;
 
1126
        int sy = y;
 
1127
        int s = sw / 3;
 
1128
 
 
1129
        if (opt->direction == Qt::RightToLeft) {
 
1130
            sx = x + sw;
 
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);
 
1138
                sx -= s;
 
1139
                sy += s;
 
1140
            }
 
1141
        } else {
 
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);
 
1149
                sx += s;
 
1150
                sy += s;
 
1151
            }
 
1152
        }
 
1153
        p->restore();
 
1154
        break; }
 
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();
 
1165
 
 
1166
            p->save();
 
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));
 
1177
            p->restore();
 
1178
        }
 
1179
        break; }
 
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));
 
1185
                p->drawRect(r);
 
1186
            }
 
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);
 
1193
            }
 
1194
        }
 
1195
        break;
 
1196
    case CE_Header:
 
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);
 
1205
            }
 
1206
        }
 
1207
        break;
 
1208
    case CE_FocusFrame:
 
1209
        p->fillRect(opt->rect, opt->palette.foreground());
 
1210
        break;
 
1211
    case CE_HeaderSection:
 
1212
        qDrawShadePanel(p, opt->rect, opt->palette,
 
1213
                        opt->state & State_Sunken, 1,
 
1214
                        &opt->palette.brush(QPalette::Button));
 
1215
        break;
 
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);
 
1228
            }
 
1229
 
 
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),
 
1234
                            cb->currentText);
 
1235
            }
 
1236
        }
 
1237
        break;
 
1238
    default:
 
1239
        break;
 
1240
    }
 
1241
}
 
1242
 
 
1243
 
 
1244
/*!
 
1245
  \reimp
 
1246
*/
 
1247
QRect QCommonStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const
 
1248
{
 
1249
    QRect r;
 
1250
    switch (sr) {
 
1251
    case SE_PushButtonContents:
 
1252
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
1253
            int dx1, dx2;
 
1254
            dx1 = pixelMetric(PM_DefaultFrameWidth, btn, widget);
 
1255
            if (btn->features & QStyleOptionButton::AutoDefaultButton)
 
1256
                dx1 += pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
 
1257
            dx2 = dx1 * 2;
 
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);
 
1261
        }
 
1262
        break;
 
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);
 
1268
                dbw2 = dbw1 * 2;
 
1269
            }
 
1270
 
 
1271
            int dfw1 = pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1,
 
1272
                dfw2 = dfw1 * 2;
 
1273
 
 
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);
 
1277
        }
 
1278
        break;
 
1279
    case SE_ViewItemCheckIndicator:
 
1280
        r = subElementRect(SE_CheckBoxIndicator, opt, widget);
 
1281
        break;
 
1282
    case SE_CheckBoxIndicator:
 
1283
        {
 
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);
 
1288
        }
 
1289
        break;
 
1290
 
 
1291
    case SE_CheckBoxContents:
 
1292
        {
 
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);
 
1299
        }
 
1300
        break;
 
1301
 
 
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);
 
1307
                break;
 
1308
            }
 
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));
 
1312
 
 
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);
 
1318
            }
 
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);
 
1325
            }
 
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);
 
1330
        }
 
1331
        break;
 
1332
 
 
1333
    case SE_RadioButtonIndicator:
 
1334
        {
 
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);
 
1339
        }
 
1340
        break;
 
1341
 
 
1342
    case SE_RadioButtonContents:
 
1343
        {
 
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);
 
1349
            break;
 
1350
        }
 
1351
 
 
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);
 
1357
                break;
 
1358
            }
 
1359
            QRect cr = visualRect(btn->direction, btn->rect,
 
1360
                                  subElementRect(SE_RadioButtonContents, opt, widget));
 
1361
 
 
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);
 
1366
            }
 
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);
 
1372
            }
 
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);
 
1377
        }
 
1378
        break;
 
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);
 
1385
            else
 
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);
 
1389
        }
 
1390
        break;
 
1391
    case SE_ProgressBarGroove:
 
1392
    case SE_ProgressBarContents:
 
1393
    case SE_ProgressBarLabel:
 
1394
        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
 
1395
            int textw = 0;
 
1396
            if (pb->textVisible)
 
1397
                textw = qMax(pb->fontMetrics.width(pb->text), pb->fontMetrics.width("100%")) + 6;
 
1398
 
 
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());
 
1403
                else
 
1404
                    r.setCoords(pb->rect.right() - textw, pb->rect.top(),
 
1405
                                pb->rect.right(), pb->rect.bottom());
 
1406
            } else {
 
1407
                r = pb->rect;
 
1408
            }
 
1409
            r = visualRect(pb->direction, pb->rect, r);
 
1410
        }
 
1411
        break;
 
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());
 
1416
            else {
 
1417
                if (dw->state & State_Horizontal)
 
1418
                    r.setRect(0, 15, dw->rect.width(), dw->rect.height() - 15);
 
1419
                else
 
1420
                    r.setRect(0, 1, dw->rect.width() - 15, dw->rect.height() - 1);
 
1421
            }
 
1422
            r = visualRect(opt->direction, opt->rect, r);
 
1423
        }
 
1424
        break;
 
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);
 
1430
        }
 
1431
        break;
 
1432
    case SE_ToolBoxTabContents:
 
1433
        r = opt->rect;
 
1434
        r.adjust(0, 0, -30, 0);
 
1435
        break;
 
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);
 
1440
 
 
1441
        r = visualRect(opt->direction, opt->rect, r);
 
1442
        break; }
 
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);
 
1451
        else
 
1452
            r.setRect(x + 5, y, h / 2, h - margin * 2);
 
1453
        r = visualRect(opt->direction, opt->rect, r);
 
1454
        break; }
 
1455
 
 
1456
    case SE_RadioButtonClickRect:
 
1457
        r = subElementRect(SE_RadioButtonFocusRect, opt, widget);
 
1458
        r |= subElementRect(SE_RadioButtonIndicator, opt, widget);
 
1459
        break;
 
1460
    case SE_CheckBoxClickRect:
 
1461
        r = subElementRect(SE_CheckBoxFocusRect, opt, widget);
 
1462
        r |= subElementRect(SE_CheckBoxIndicator, opt, widget);
 
1463
        break;
 
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)) {
 
1472
                default:
 
1473
                case Qt::AlignLeft:
 
1474
                    r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
 
1475
                    break;
 
1476
                case Qt::AlignCenter:
 
1477
                    r.moveTopLeft(QPoint(twf->rect.center().x() - twf->tabBarSize.width() / 2, 0));
 
1478
                    break;
 
1479
                case Qt::AlignRight:
 
1480
                    r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
 
1481
                                         - twf->rightCornerWidgetSize.width(), 0));
 
1482
                    break;
 
1483
                }
 
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);
 
1488
                break;
 
1489
            case QTabBar::RoundedSouth:
 
1490
            case QTabBar::TriangularSouth:
 
1491
                switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
 
1492
                default:
 
1493
                case Qt::AlignLeft:
 
1494
                    r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
 
1495
                                         twf->rect.height() - twf->tabBarSize.height()));
 
1496
                    break;
 
1497
                case Qt::AlignCenter:
 
1498
                    r.moveTopLeft(QPoint(twf->rect.center().x() - twf->tabBarSize.width() / 2,
 
1499
                                         twf->rect.height() - twf->tabBarSize.height()));
 
1500
                    break;
 
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()));
 
1505
                    break;
 
1506
                }
 
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);
 
1511
                break;
 
1512
            case QTabBar::RoundedEast:
 
1513
            case QTabBar::TriangularEast:
 
1514
                switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
 
1515
                default:
 
1516
                case Qt::AlignLeft:
 
1517
                    r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
 
1518
                                         twf->leftCornerWidgetSize.height()));
 
1519
                    break;
 
1520
                case Qt::AlignCenter:
 
1521
                    r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
 
1522
                                         twf->rect.center().y() - twf->tabBarSize.height() / 2));
 
1523
                    break;
 
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()));
 
1528
                    break;
 
1529
                }
 
1530
                r.setHeight(qMin(r.height(), twf->rect.height()
 
1531
                                            - twf->leftCornerWidgetSize.height()
 
1532
                                            - twf->rightCornerWidgetSize.height()));
 
1533
                break;
 
1534
            case QTabBar::RoundedWest:
 
1535
            case QTabBar::TriangularWest:
 
1536
                switch (styleHint(SH_TabBar_Alignment, twf, widget)) {
 
1537
                default:
 
1538
                case Qt::AlignLeft:
 
1539
                    r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
 
1540
                    break;
 
1541
                case Qt::AlignCenter:
 
1542
                    r.moveTopLeft(QPoint(0, twf->rect.center().y() - twf->tabBarSize.height() / 2));
 
1543
                    break;
 
1544
                case Qt::AlignRight:
 
1545
                    r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
 
1546
                                         - twf->rightCornerWidgetSize.height()));
 
1547
                    break;
 
1548
                }
 
1549
                r.setHeight(qMin(r.height(), twf->rect.height())
 
1550
                                             - twf->leftCornerWidgetSize.height()
 
1551
                                             - twf->rightCornerWidgetSize.height());
 
1552
                break;
 
1553
            }
 
1554
        }
 
1555
        break;
 
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));
 
1566
                break;
 
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));
 
1570
                break;
 
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()));
 
1574
                break;
 
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()));
 
1578
                break;
 
1579
            }
 
1580
            if (sr == SE_TabWidgetTabContents)
 
1581
               r.adjust(2, 2, -2, -2);
 
1582
        }
 
1583
        break;
 
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);
 
1592
                break;
 
1593
            case QTabBar::RoundedSouth:
 
1594
            case QTabBar::TriangularSouth:
 
1595
                r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
 
1596
               break;
 
1597
            default:
 
1598
               break;
 
1599
            }
 
1600
           r = visualRect(twf->direction, twf->rect, r);
 
1601
        }
 
1602
        break;
 
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);
 
1612
               break;
 
1613
           case QTabBar::RoundedSouth:
 
1614
           case QTabBar::TriangularSouth:
 
1615
                r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
 
1616
                                 paneRect.height()), twf->rightCornerWidgetSize);
 
1617
               break;
 
1618
           default:
 
1619
               break;
 
1620
           }
 
1621
           r = visualRect(twf->direction, twf->rect, r);
 
1622
        }
 
1623
        break;
 
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());
 
1632
                break;
 
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);
 
1638
                break;
 
1639
            default:
 
1640
                break;
 
1641
            }
 
1642
            r = visualRect(opt->direction, opt->rect, r);
 
1643
        }
 
1644
        break;
 
1645
    default:
 
1646
        break;
 
1647
    }
 
1648
    return r;
 
1649
}
 
1650
 
 
1651
static qreal angle(const QPoint &p1, const QPoint &p2)
 
1652
{
 
1653
    static const double rad_factor = 180.0 / Q_PI;
 
1654
    qreal _angle = 0.0;
 
1655
 
 
1656
    if (p1.x() == p2.x()) {
 
1657
        if (p1.y() < p2.y())
 
1658
            _angle = 270.0;
 
1659
        else
 
1660
            _angle = 90.0;
 
1661
    } else  {
 
1662
        double x1, x2, y1, y2;
 
1663
 
 
1664
        if (p1.x() <= p2.x()) {
 
1665
            x1 = p1.x(); y1 = p1.y();
 
1666
            x2 = p2.x(); y2 = p2.y();
 
1667
        } else {
 
1668
            x2 = p1.x(); y2 = p1.y();
 
1669
            x1 = p2.x(); y1 = p2.y();
 
1670
        }
 
1671
 
 
1672
        double m = -(y2 - y1) / (x2 - x1);
 
1673
        _angle = atan(m) *  rad_factor;
 
1674
 
 
1675
        if (p1.x() < p2.x())
 
1676
            _angle = 180.0 - _angle;
 
1677
        else
 
1678
            _angle = -_angle;
 
1679
    }
 
1680
    return _angle;
 
1681
}
 
1682
 
 
1683
static int calcBigLineSize(int radius)
 
1684
{
 
1685
    int bigLineSize = radius / 6;
 
1686
    if (bigLineSize < 4)
 
1687
        bigLineSize = 4;
 
1688
    if (bigLineSize > radius / 2)
 
1689
        bigLineSize = radius / 2;
 
1690
    return bigLineSize;
 
1691
}
 
1692
 
 
1693
static QPolygon calcArrow(const QStyleOptionSlider *dial, qreal &a)
 
1694
{
 
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)
 
1699
        a = Q_PI / 2;
 
1700
    else if (dial->dialWrapping)
 
1701
        a = Q_PI * 3 / 2 - (dial->sliderValue - dial->minimum) * 2 * Q_PI
 
1702
            / (dial->maximum - dial->minimum);
 
1703
    else
 
1704
        a = (Q_PI * 8 - (dial->sliderValue - dial->minimum) * 10 * Q_PI
 
1705
            / (dial->maximum - dial->minimum)) / 6;
 
1706
 
 
1707
    int xc = width / 2;
 
1708
    int yc = height / 2;
 
1709
 
 
1710
    int len = r - calcBigLineSize(r) - 5;
 
1711
    if (len < 5)
 
1712
        len = 5;
 
1713
    int back = len / 2;
 
1714
    if (back < 1)
 
1715
        back = 1;
 
1716
 
 
1717
    QPolygon arrow(3);
 
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)));
 
1724
    return arrow;
 
1725
}
 
1726
 
 
1727
static QPolygon calcLines(const QStyleOptionSlider *dial, const QWidget *)
 
1728
{
 
1729
    QPolygon poly;
 
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));
 
1734
 
 
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));
 
1750
        } else {
 
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));
 
1754
        }
 
1755
    }
 
1756
    return poly;
 
1757
}
 
1758
 
 
1759
/*!
 
1760
  \reimp
 
1761
*/
 
1762
void QCommonStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
 
1763
                                      QPainter *p, const QWidget *widget) const
 
1764
{
 
1765
    switch (cc) {
 
1766
    case CC_Slider:
 
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,
 
1778
                                                        available)
 
1779
                        - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
 
1780
                                                          0, available) < 3)
 
1781
                        interval = slider->pageStep;
 
1782
                }
 
1783
                if (!interval)
 
1784
                    interval = 1;
 
1785
                int fudge = len / 2;
 
1786
                int pos;
 
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);
 
1798
                    } else {
 
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);
 
1804
                    }
 
1805
                    v += interval;
 
1806
                }
 
1807
            }
 
1808
        }
 
1809
        break;
 
1810
    case CC_ScrollBar:
 
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;
 
1817
 
 
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);
 
1825
                }
 
1826
            }
 
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);
 
1835
                }
 
1836
            }
 
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);
 
1845
                }
 
1846
            }
 
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);
 
1855
                }
 
1856
            }
 
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);
 
1865
                }
 
1866
            }
 
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);
 
1875
                }
 
1876
            }
 
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);
 
1885
 
 
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);
 
1893
                    }
 
1894
                }
 
1895
            }
 
1896
        }
 
1897
        break;
 
1898
    case CC_Q3ListView:
 
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));
 
1902
        }
 
1903
        break;
 
1904
    case CC_SpinBox:
 
1905
        if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
 
1906
            QStyleOptionSpinBox copy = *sb;
 
1907
            PrimitiveElement pe;
 
1908
 
 
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);
 
1912
            }
 
1913
 
 
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;
 
1920
                }
 
1921
 
 
1922
                copy.palette = pal2;
 
1923
 
 
1924
                if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
 
1925
                    copy.state |= State_On;
 
1926
                    copy.state |= State_Sunken;
 
1927
                } else {
 
1928
                    copy.state |= State_Raised;
 
1929
                    copy.state &= ~State_Sunken;
 
1930
                }
 
1931
                pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
 
1932
                                                                       : PE_IndicatorSpinUp);
 
1933
 
 
1934
                copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
 
1935
                drawPrimitive(PE_PanelButtonBevel, &copy, p, widget);
 
1936
                copy.rect.adjust(3, 0, -4, 0);
 
1937
                drawPrimitive(pe, &copy, p, widget);
 
1938
            }
 
1939
 
 
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;
 
1947
                }
 
1948
                copy.palette = pal2;
 
1949
 
 
1950
                if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
 
1951
                    copy.state |= State_On;
 
1952
                    copy.state |= State_Sunken;
 
1953
                } else {
 
1954
                    copy.state |= State_Raised;
 
1955
                    copy.state &= ~State_Sunken;
 
1956
                }
 
1957
                pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
 
1958
                                                                       : PE_IndicatorSpinDown);
 
1959
 
 
1960
                copy.rect = subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
 
1961
                drawPrimitive(PE_PanelButtonBevel, &copy, p, widget);
 
1962
                copy.rect.adjust(3, 0, -4, 0);
 
1963
                drawPrimitive(pe, &copy, p, widget);
 
1964
            }
 
1965
        }
 
1966
        break;
 
1967
    case CC_ToolButton:
 
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);
 
1973
 
 
1974
            State bflags = toolbutton->state;
 
1975
 
 
1976
            if (bflags & State_AutoRaise) {
 
1977
                if (!(bflags & State_MouseOver)) {
 
1978
                    bflags &= ~State_Raised;
 
1979
                }
 
1980
            }
 
1981
            State mflags = bflags;
 
1982
 
 
1983
            if (toolbutton->activeSubControls & SC_ToolButton)
 
1984
                bflags |= State_Sunken;
 
1985
            if (toolbutton->activeSubControls & SC_ToolButtonMenu)
 
1986
                mflags |= State_Sunken;
 
1987
 
 
1988
            QStyleOption tool(0);
 
1989
            tool.palette = toolbutton->palette;
 
1990
            if (toolbutton->subControls & SC_ToolButton) {
 
1991
                if (bflags & (State_Sunken | State_On | State_Raised)) {
 
1992
                    tool.rect = button;
 
1993
                    tool.state = bflags;
 
1994
                    drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
1995
                }
 
1996
            }
 
1997
 
 
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);
 
2004
            }
 
2005
 
 
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);
 
2014
            }
 
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);
 
2019
        }
 
2020
        break;
 
2021
    case CC_TitleBar:
 
2022
        if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
 
2023
            QRect ir;
 
2024
            if (opt->subControls & SC_TitleBarLabel) {
 
2025
                QColor left = tb->palette.highlight().color();
 
2026
                QColor right = tb->palette.base().color();
 
2027
 
 
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);
 
2035
                    fillBrush = lg;
 
2036
                }
 
2037
 
 
2038
                p->fillRect(opt->rect, fillBrush);
 
2039
 
 
2040
                ir = subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
 
2041
 
 
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);
 
2045
            }
 
2046
 
 
2047
            bool down = false;
 
2048
            QPixmap pm;
 
2049
 
 
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)
 
2058
#endif
 
2059
                   )
 
2060
                    pm = standardPixmap(SP_DockWidgetCloseButton, &tool, widget);
 
2061
                else
 
2062
                    pm = standardPixmap(SP_TitleBarCloseButton, &tool, widget);
 
2063
                tool.rect = ir;
 
2064
                tool.state = down ? State_Sunken : State_Raised;
 
2065
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2066
 
 
2067
                p->save();
 
2068
                if (down)
 
2069
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2070
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2071
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2072
                p->restore();
 
2073
            }
 
2074
 
 
2075
            if (tb->subControls & SC_TitleBarMaxButton
 
2076
                && tb->titleBarFlags & Qt::WindowMaximizeButtonHint) {
 
2077
                ir = subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
 
2078
 
 
2079
                down = tb->activeSubControls & SC_TitleBarMaxButton;
 
2080
                pm = standardPixmap(SP_TitleBarMaxButton, &tool, widget);
 
2081
                tool.rect = ir;
 
2082
                tool.state = down ? State_Sunken : State_Raised;
 
2083
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2084
 
 
2085
                p->save();
 
2086
                if (down)
 
2087
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2088
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2089
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2090
                p->restore();
 
2091
            }
 
2092
 
 
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);
 
2097
 
 
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);
 
2106
                tool.rect = ir;
 
2107
                tool.state = down ? State_Sunken : State_Raised;
 
2108
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2109
 
 
2110
                p->save();
 
2111
                if (down)
 
2112
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2113
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2114
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2115
                p->restore();
 
2116
            }
 
2117
 
 
2118
            if (tb->subControls & SC_TitleBarShadeButton) {
 
2119
                ir = subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
 
2120
 
 
2121
                down = tb->activeSubControls & SC_TitleBarShadeButton;
 
2122
                pm = standardPixmap(SP_TitleBarShadeButton, &tool, widget);
 
2123
                tool.rect = ir;
 
2124
                tool.state = down ? State_Sunken : State_Raised;
 
2125
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2126
                p->save();
 
2127
                if (down)
 
2128
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2129
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2130
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2131
                p->restore();
 
2132
            }
 
2133
 
 
2134
            if (tb->subControls & SC_TitleBarUnshadeButton) {
 
2135
                ir = subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
 
2136
 
 
2137
                down = tb->activeSubControls & SC_TitleBarUnshadeButton;
 
2138
                pm = standardPixmap(SP_TitleBarUnshadeButton, &tool, widget);
 
2139
                tool.rect = ir;
 
2140
                tool.state = down ? State_Sunken : State_Raised;
 
2141
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2142
                p->save();
 
2143
                if (down)
 
2144
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2145
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2146
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2147
                p->restore();
 
2148
            }
 
2149
            if (tb->subControls & SC_TitleBarContextHelpButton
 
2150
                && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
 
2151
                ir = subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
 
2152
 
 
2153
                down = tb->activeSubControls & SC_TitleBarContextHelpButton;
 
2154
                pm = standardPixmap(SP_TitleBarContextHelpButton, &tool, widget);
 
2155
                tool.rect = ir;
 
2156
                tool.state = down ? State_Sunken : State_Raised;
 
2157
                drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
2158
                p->save();
 
2159
                if (down)
 
2160
                    p->translate(pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
 
2161
                                 pixelMetric(PM_ButtonShiftVertical, tb, widget));
 
2162
                drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2163
                p->restore();
 
2164
            }
 
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);
 
2169
                } else {
 
2170
                    pm = standardPixmap(SP_TitleBarMenuButton, &tool, widget);
 
2171
                    tool.rect = ir;
 
2172
                    p->save();
 
2173
                    drawItemPixmap(p, ir, Qt::AlignCenter, pm);
 
2174
                    p->restore();
 
2175
                }
 
2176
            }
 
2177
        }
 
2178
        break;
 
2179
    case CC_Dial:
 
2180
        if (const QStyleOptionSlider *dial = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
2181
            // OK, this is more a port of things over
 
2182
            p->save();
 
2183
 
 
2184
            // avoid dithering
 
2185
            if (p->device()->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
 
2186
                p->setRenderHint(QPainter::Antialiasing);
 
2187
 
 
2188
            int width = dial->rect.width();
 
2189
            int height = dial->rect.height();
 
2190
            qreal r = qMin(width, height) / 2.0;
 
2191
            qreal d_ = r / 6.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));
 
2195
 
 
2196
            QPalette pal = opt->palette;
 
2197
            // draw notches
 
2198
            if (dial->subControls & QStyle::SC_DialTickmarks) {
 
2199
                p->setPen(pal.foreground().color());
 
2200
                p->drawLines(calcLines(dial, widget)); // ### calcLines could be cached...
 
2201
            }
 
2202
 
 
2203
            if (dial->state & State_Enabled) {
 
2204
                p->setBrush(pal.brush(QPalette::ColorRole(styleHint(SH_Dial_BackgroundRole,
 
2205
                                                                    dial, widget))));
 
2206
                p->setPen(Qt::NoPen);
 
2207
                p->drawEllipse(br);
 
2208
                p->setBrush(Qt::NoBrush);
 
2209
            }
 
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);
 
2214
 
 
2215
            qreal a;
 
2216
            QPolygon arrow(calcArrow(dial, a));
 
2217
 
 
2218
            p->setPen(Qt::NoPen);
 
2219
            p->setBrush(pal.button());
 
2220
            p->drawPolygon(arrow);
 
2221
 
 
2222
            a = angle(QPoint(width / 2, height / 2), arrow[0]);
 
2223
            p->setBrush(Qt::NoBrush);
 
2224
 
 
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]);
 
2249
            }
 
2250
 
 
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);
 
2263
                }
 
2264
                fropt.rect = br.adjusted(-2, -2, 2, 2);
 
2265
                drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
 
2266
            }
 
2267
            p->restore();
 
2268
        }
 
2269
        break;
 
2270
    default:
 
2271
        qWarning("drawComplexControl control not handled %d", cc);
 
2272
    }
 
2273
}
 
2274
 
 
2275
/*!
 
2276
    \reimp
 
2277
*/
 
2278
QStyle::SubControl QCommonStyle::hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
 
2279
                                                 const QPoint &pt, const QWidget *widget) const
 
2280
{
 
2281
    SubControl sc = SC_None;
 
2282
    switch (cc) {
 
2283
    case CC_Slider:
 
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;
 
2288
            } else {
 
2289
                r = subControlRect(cc, slider, SC_SliderGroove ,widget);
 
2290
                if (r.isValid() && r.contains(pt))
 
2291
                    sc = SC_SliderGroove;
 
2292
            }
 
2293
        }
 
2294
        break;
 
2295
    case CC_ScrollBar:
 
2296
        if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
2297
            QRect r;
 
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);
 
2303
                    break;
 
2304
                }
 
2305
                ctrl <<= 1;
 
2306
            }
 
2307
        }
 
2308
        break;
 
2309
    case CC_Q3ListView:
 
2310
        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
2311
            if (pt.x() >= 0 && pt.x() < lv->treeStepSize)
 
2312
                sc = SC_Q3ListViewExpand;
 
2313
        }
 
2314
        break;
 
2315
    case CC_SpinBox:
 
2316
        if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
 
2317
            QRect r;
 
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);
 
2323
                    break;
 
2324
                }
 
2325
                ctrl <<= 1;
 
2326
            }
 
2327
        }
 
2328
        break;
 
2329
 
 
2330
    case CC_TitleBar:
 
2331
        if (const QStyleOptionTitleBar *tb = qstyleoption_cast<const QStyleOptionTitleBar *>(opt)) {
 
2332
            QRect r;
 
2333
            uint ctrl = SC_TitleBarSysMenu;
 
2334
 
 
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);
 
2339
                    break;
 
2340
                }
 
2341
                ctrl <<= 1;
 
2342
            }
 
2343
        }
 
2344
        break;
 
2345
    case CC_ComboBox:
 
2346
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
 
2347
            QRect r;
 
2348
            uint ctrl = SC_ComboBoxArrow;  // Start here and go down.
 
2349
            while (ctrl > 0) {
 
2350
                r = subControlRect(cc, cb, QStyle::SubControl(ctrl), widget);
 
2351
                if (r.isValid() && r.contains(pt)) {
 
2352
                    sc = QStyle::SubControl(ctrl);
 
2353
                    break;
 
2354
                }
 
2355
                ctrl >>= 1;
 
2356
            }
 
2357
        }
 
2358
        break;
 
2359
    default:
 
2360
        qWarning("QCommonStyle::hitTestComplexControl case not handled %d", cc);
 
2361
    }
 
2362
    return sc;
 
2363
}
 
2364
 
 
2365
/*!
 
2366
    \reimp
 
2367
*/
 
2368
QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
 
2369
                                   SubControl sc, const QWidget *widget) const
 
2370
{
 
2371
    QRect ret;
 
2372
    switch (cc) {
 
2373
    case CC_Slider:
 
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);
 
2377
 
 
2378
            switch (sc) {
 
2379
            case SC_SliderHandle: {
 
2380
                int sliderPos = 0;
 
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);
 
2388
                if (horizontal)
 
2389
                    ret.setRect(sliderPos, tickOffset, len, thickness);
 
2390
                else
 
2391
                    ret.setRect(tickOffset, sliderPos, thickness, len);
 
2392
                break; }
 
2393
            case SC_SliderGroove:
 
2394
                if (slider->orientation == Qt::Horizontal)
 
2395
                    ret.setRect(0, tickOffset, slider->rect.width(), thickness);
 
2396
                else
 
2397
                    ret.setRect(tickOffset, 0, thickness, slider->rect.height());
 
2398
                break;
 
2399
            default:
 
2400
                break;
 
2401
            }
 
2402
            ret = visualRect(slider->direction, slider->rect, ret);
 
2403
        }
 
2404
        break;
 
2405
    case CC_ScrollBar:
 
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);
 
2410
            int sliderlen;
 
2411
 
 
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);
 
2416
 
 
2417
                int slidermin = pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget);
 
2418
                if (sliderlen < slidermin || range > INT_MAX / 2)
 
2419
                    sliderlen = slidermin;
 
2420
                if (sliderlen > maxlen)
 
2421
                    sliderlen = maxlen;
 
2422
            } else {
 
2423
                sliderlen = maxlen;
 
2424
            }
 
2425
 
 
2426
            int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
 
2427
                                                                 scrollbar->maximum,
 
2428
                                                                 scrollbar->sliderPosition,
 
2429
                                                                 maxlen - sliderlen,
 
2430
                                                                 scrollbar->upsideDown);
 
2431
            switch (sc) {
 
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);
 
2436
                } else {
 
2437
                    int buttonHeight = qMin(scrollbar->rect.height() / 2, sbextent);
 
2438
                    ret.setRect(0, 0, sbextent, buttonHeight);
 
2439
                }
 
2440
                break;
 
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);
 
2445
                } else {
 
2446
                    int buttonHeight = qMin(scrollbar->rect.height()/2, sbextent);
 
2447
                    ret.setRect(0, scrollbar->rect.height() - buttonHeight, sbextent, buttonHeight);
 
2448
                }
 
2449
                break;
 
2450
            case SC_ScrollBarSubPage:            // between top/left button and slider
 
2451
                if (scrollbar->orientation == Qt::Horizontal)
 
2452
                    ret.setRect(sbextent, 0, sliderstart - sbextent, sbextent);
 
2453
                else
 
2454
                    ret.setRect(0, sbextent, sbextent, sliderstart - sbextent);
 
2455
                break;
 
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);
 
2460
                else
 
2461
                    ret.setRect(0, sliderstart + sliderlen, sbextent,
 
2462
                                maxlen - sliderstart - sliderlen + sbextent);
 
2463
                break;
 
2464
            case SC_ScrollBarGroove:
 
2465
                if (scrollbar->orientation == Qt::Horizontal)
 
2466
                    ret.setRect(sbextent, 0, scrollbar->rect.width() - sbextent * 2,
 
2467
                                scrollbar->rect.height());
 
2468
                else
 
2469
                    ret.setRect(0, sbextent, scrollbar->rect.width(),
 
2470
                                scrollbar->rect.height() - sbextent * 2);
 
2471
                break;
 
2472
            case SC_ScrollBarSlider:
 
2473
                if (scrollbar->orientation == Qt::Horizontal)
 
2474
                    ret.setRect(sliderstart, 0, sliderlen, sbextent);
 
2475
                else
 
2476
                    ret.setRect(0, sliderstart, sbextent, sliderlen);
 
2477
                break;
 
2478
            default:
 
2479
                break;
 
2480
            }
 
2481
            ret = visualRect(scrollbar->direction, scrollbar->rect, ret);
 
2482
        }
 
2483
        break;
 
2484
    case CC_SpinBox:
 
2485
        if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
 
2486
            QSize bs;
 
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());
 
2492
            int y = fw;
 
2493
            int x, lx, rx;
 
2494
            x = spinbox->rect.width() - y - bs.width();
 
2495
            lx = fw;
 
2496
            rx = x - fw;
 
2497
            switch (sc) {
 
2498
            case SC_SpinBoxUp:
 
2499
                ret = QRect(x, y, bs.width(), bs.height());
 
2500
                break;
 
2501
            case SC_SpinBoxDown:
 
2502
                ret = QRect(x, y + bs.height(), bs.width(), bs.height());
 
2503
                break;
 
2504
            case SC_SpinBoxEditField:
 
2505
                ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
 
2506
                break;
 
2507
            case SC_SpinBoxFrame:
 
2508
                ret = spinbox->rect;
 
2509
            default:
 
2510
                break;
 
2511
            }
 
2512
            ret = visualRect(spinbox->direction, spinbox->rect, ret);
 
2513
        }
 
2514
        break;
 
2515
    case CC_ToolButton:
 
2516
        if (const QStyleOptionToolButton *tb = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
 
2517
            int mbi = pixelMetric(PM_MenuButtonIndicator, tb, widget);
 
2518
            ret = tb->rect;
 
2519
            switch (sc) {
 
2520
            case SC_ToolButton:
 
2521
                if ((tb->features
 
2522
                     & (QStyleOptionToolButton::Menu | QStyleOptionToolButton::PopupDelay))
 
2523
                    == QStyleOptionToolButton::Menu)
 
2524
                    ret.adjust(0, 0, -mbi, 0);
 
2525
                break;
 
2526
            case SC_ToolButtonMenu:
 
2527
                if ((tb->features
 
2528
                     & (QStyleOptionToolButton::Menu | QStyleOptionToolButton::PopupDelay))
 
2529
                    == QStyleOptionToolButton::Menu)
 
2530
                    ret.adjust(ret.width() - mbi, 0, 0, 0);
 
2531
                break;
 
2532
            default:
 
2533
                break;
 
2534
            }
 
2535
            ret = visualRect(tb->direction, tb->rect, ret);
 
2536
        }
 
2537
        break;
 
2538
    case CC_ComboBox:
 
2539
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
 
2540
            int x = 0,
 
2541
                y = 0,
 
2542
                wi = cb->rect.width(),
 
2543
                he = cb->rect.height();
 
2544
            int xpos = x;
 
2545
            int margin = cb->frame ? 3 : 0;
 
2546
            int bmarg = cb->frame ? 2 : 0;
 
2547
            xpos += wi - bmarg - 16;
 
2548
 
 
2549
 
 
2550
            switch (sc) {
 
2551
            case SC_ComboBoxFrame:
 
2552
                ret = cb->rect;
 
2553
                break;
 
2554
            case SC_ComboBoxArrow:
 
2555
                ret.setRect(xpos, y + bmarg, 16, he - 2*bmarg);
 
2556
                break;
 
2557
            case SC_ComboBoxEditField:
 
2558
                ret.setRect(x + margin, y + margin, wi - 2 * margin - 16, he - 2 * margin);
 
2559
                break;
 
2560
            case SC_ComboBoxListBoxPopup:
 
2561
                ret = cb->popupRect;
 
2562
                break;
 
2563
            default:
 
2564
                break;
 
2565
            }
 
2566
            ret = visualRect(cb->direction, cb->rect, ret);
 
2567
        }
 
2568
        break;
 
2569
    case CC_TitleBar:
 
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;
 
2574
            int offset = 0;
 
2575
 
 
2576
            bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
 
2577
 
 
2578
            switch (sc) {
 
2579
            case SC_TitleBarLabel:
 
2580
                if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
 
2581
                    ret = tb->rect;
 
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);
 
2592
                }
 
2593
                break;
 
2594
            case SC_TitleBarContextHelpButton:
 
2595
                if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
 
2596
                    offset += delta;
 
2597
            case SC_TitleBarMinButton:
 
2598
                if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
 
2599
                    offset += delta;
 
2600
                else if (sc == SC_TitleBarMinButton)
 
2601
                    break;
 
2602
            case SC_TitleBarNormalButton:
 
2603
                if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
 
2604
                    offset += delta;
 
2605
                else if (sc == SC_TitleBarNormalButton)
 
2606
                    break;
 
2607
            case SC_TitleBarMaxButton:
 
2608
                if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
 
2609
                    offset += delta;
 
2610
                else if (sc == SC_TitleBarMaxButton)
 
2611
                    break;
 
2612
            case SC_TitleBarShadeButton:
 
2613
                if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
 
2614
                    offset += delta;
 
2615
                else if (sc == SC_TitleBarShadeButton)
 
2616
                    break;
 
2617
            case SC_TitleBarUnshadeButton:
 
2618
                if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
 
2619
                    offset += delta;
 
2620
                else if (sc == SC_TitleBarUnshadeButton)
 
2621
                    break;
 
2622
            case SC_TitleBarCloseButton:
 
2623
                if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
 
2624
                    offset += delta;
 
2625
                else if (sc == SC_TitleBarCloseButton)
 
2626
                    break;
 
2627
                ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
 
2628
                            controlHeight, controlHeight);
 
2629
                break;
 
2630
            case SC_TitleBarSysMenu:
 
2631
                if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
 
2632
                    ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
 
2633
                                controlHeight, controlHeight);
 
2634
                }
 
2635
                break;
 
2636
            default:
 
2637
                break;
 
2638
            }
 
2639
            ret = visualRect(tb->direction, tb->rect, ret);
 
2640
        }
 
2641
        break;
 
2642
    default:
 
2643
        qWarning("QCommonStyle::subControlRect case not handled %d", cc);
 
2644
    }
 
2645
    return ret;
 
2646
}
 
2647
 
 
2648
/*! \reimp */
 
2649
int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWidget *widget) const
 
2650
{
 
2651
    int ret;
 
2652
 
 
2653
    switch (m) {
 
2654
    case PM_FocusFrameVMargin:
 
2655
    case PM_FocusFrameHMargin:
 
2656
        ret = 2;
 
2657
        break;
 
2658
    case PM_MenuBarVMargin:
 
2659
    case PM_MenuBarHMargin:
 
2660
        ret = 0;
 
2661
        break;
 
2662
    case PM_DialogButtonsSeparator:
 
2663
        ret = 5;
 
2664
        break;
 
2665
    case PM_DialogButtonsButtonWidth:
 
2666
        ret = 70;
 
2667
        break;
 
2668
    case PM_DialogButtonsButtonHeight:
 
2669
        ret = 30;
 
2670
        break;
 
2671
    case PM_CheckListControllerSize:
 
2672
    case PM_CheckListButtonSize:
 
2673
        ret = 16;
 
2674
        break;
 
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);
 
2682
#endif
 
2683
            } else {
 
2684
                ret = qMax(widget ? widget->fontMetrics().lineSpacing() : 0, 18);
 
2685
            }
 
2686
        } else {
 
2687
            ret = 18;
 
2688
        }
 
2689
 
 
2690
        break; }
 
2691
    case PM_ScrollBarSliderMin:
 
2692
        ret = 9;
 
2693
        break;
 
2694
 
 
2695
    case PM_ButtonMargin:
 
2696
        ret = 6;
 
2697
        break;
 
2698
 
 
2699
    case PM_ButtonDefaultIndicator:
 
2700
        ret = 0;
 
2701
        break;
 
2702
 
 
2703
    case PM_MenuButtonIndicator:
 
2704
        if (!opt)
 
2705
            ret = 12;
 
2706
        else
 
2707
            ret = qMax(12, (opt->rect.height() - 4) / 3);
 
2708
        break;
 
2709
 
 
2710
    case PM_ButtonShiftHorizontal:
 
2711
    case PM_ButtonShiftVertical:
 
2712
 
 
2713
    case PM_DefaultFrameWidth:
 
2714
        ret = 2;
 
2715
        break;
 
2716
 
 
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);
 
2723
        break;
 
2724
 
 
2725
    case PM_MDIFrameWidth:
 
2726
        ret = 4;
 
2727
        break;
 
2728
 
 
2729
    case PM_MDIMinimizedWidth:
 
2730
        ret = 196;
 
2731
        break;
 
2732
 
 
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();
 
2739
            ret = qMax(16, s);
 
2740
        } else {
 
2741
            ret = 16;
 
2742
        }
 
2743
        break;
 
2744
#endif
 
2745
    case PM_MaximumDragDistance:
 
2746
        ret = -1;
 
2747
        break;
 
2748
 
 
2749
#ifndef QT_NO_SLIDER
 
2750
    case PM_SliderThickness:
 
2751
        ret = 16;
 
2752
        break;
 
2753
 
 
2754
    case PM_SliderTickmarkOffset:
 
2755
        if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
2756
            int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height()
 
2757
                                                            : sl->rect.width();
 
2758
            int thickness = pixelMetric(PM_SliderControlThickness, sl, widget);
 
2759
            int ticks = sl->tickPosition;
 
2760
 
 
2761
            if (ticks == QSlider::TicksBothSides)
 
2762
                ret = (space - thickness) / 2;
 
2763
            else if (ticks == QSlider::TicksAbove)
 
2764
                ret = space - thickness;
 
2765
            else
 
2766
                ret = 0;
 
2767
        } else {
 
2768
            ret = 0;
 
2769
        }
 
2770
        break;
 
2771
 
 
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);
 
2776
            else
 
2777
                ret = sl->rect.height() - pixelMetric(PM_SliderLength, sl, widget);
 
2778
            break;
 
2779
        } else {
 
2780
            ret = 0;
 
2781
        }
 
2782
#endif // QT_NO_SLIDER
 
2783
 
 
2784
    case PM_DockWidgetSeparatorExtent:
 
2785
        ret = 6;
 
2786
        break;
 
2787
 
 
2788
    case PM_DockWidgetHandleExtent:
 
2789
        ret = 8;
 
2790
        break;
 
2791
 
 
2792
    case PM_DockWidgetFrameWidth:
 
2793
        ret = 1;
 
2794
        break;
 
2795
 
 
2796
    case PM_SpinBoxSliderHeight:
 
2797
    case PM_MenuBarPanelWidth:
 
2798
        ret = 2;
 
2799
        break;
 
2800
 
 
2801
    case PM_MenuBarItemSpacing:
 
2802
        ret = 0;
 
2803
        break;
 
2804
 
 
2805
    case PM_ToolBarFrameWidth:
 
2806
        ret = 1;
 
2807
        break;
 
2808
 
 
2809
    case PM_ToolBarItemMargin:
 
2810
        ret = 0;
 
2811
        break;
 
2812
 
 
2813
    case PM_ToolBarItemSpacing:
 
2814
        ret = 4;
 
2815
        break;
 
2816
 
 
2817
    case PM_ToolBarHandleExtent:
 
2818
        ret = 8;
 
2819
        break;
 
2820
 
 
2821
    case PM_ToolBarSeparatorExtent:
 
2822
        ret = 6;
 
2823
        break;
 
2824
 
 
2825
    case PM_ToolBarExtensionExtent:
 
2826
        ret = 12;
 
2827
        break;
 
2828
 
 
2829
    case PM_TabBarTabOverlap:
 
2830
        ret = 3;
 
2831
        break;
 
2832
 
 
2833
    case PM_TabBarTabHSpace:
 
2834
        ret = 24;
 
2835
        break;
 
2836
 
 
2837
    case PM_TabBarTabShiftHorizontal:
 
2838
        ret = 0;
 
2839
    case PM_TabBarTabShiftVertical:
 
2840
        ret = 2;
 
2841
        break;
 
2842
 
 
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))
 
2848
            ret = 8;
 
2849
        else
 
2850
            ret = 0;
 
2851
        break; }
 
2852
#endif
 
2853
 
 
2854
    case PM_ProgressBarChunkWidth:
 
2855
        ret = 9;
 
2856
        break;
 
2857
 
 
2858
    case PM_IndicatorWidth:
 
2859
        ret = 13;
 
2860
        break;
 
2861
 
 
2862
    case PM_IndicatorHeight:
 
2863
        ret = 13;
 
2864
        break;
 
2865
 
 
2866
    case PM_ExclusiveIndicatorWidth:
 
2867
        ret = 12;
 
2868
        break;
 
2869
 
 
2870
    case PM_ExclusiveIndicatorHeight:
 
2871
        ret = 12;
 
2872
        break;
 
2873
 
 
2874
    case PM_MenuTearoffHeight:
 
2875
        ret = 6;
 
2876
        break;
 
2877
 
 
2878
    case PM_MenuScrollerHeight:
 
2879
        ret = 10;
 
2880
        break;
 
2881
 
 
2882
    case PM_MenuDesktopFrameWidth:
 
2883
    case PM_MenuHMargin:
 
2884
    case PM_MenuVMargin:
 
2885
        ret = 0;
 
2886
        break;
 
2887
 
 
2888
    case PM_HeaderMargin:
 
2889
        ret = 4;
 
2890
        break;
 
2891
    case PM_HeaderMarkSize:
 
2892
        ret = 32;
 
2893
        break;
 
2894
    case PM_HeaderGripMargin:
 
2895
        ret = 4;
 
2896
        break;
 
2897
    case PM_TabBarScrollButtonWidth:
 
2898
        ret = 16;
 
2899
        break;
 
2900
 
 
2901
    case PM_DefaultTopLevelMargin:
 
2902
        ret = 11;
 
2903
        break;
 
2904
    case PM_DefaultChildMargin:
 
2905
        ret = 9;
 
2906
        break;
 
2907
    case PM_DefaultLayoutSpacing:
 
2908
        ret = 6;
 
2909
        break;
 
2910
 
 
2911
    case PM_ToolBarIconSize:
 
2912
        ret = pixelMetric(PM_SmallIconSize);
 
2913
        break;
 
2914
 
 
2915
    case PM_ListViewIconSize:
 
2916
        ret = pixelMetric(PM_SmallIconSize);
 
2917
        break;
 
2918
    case PM_IconViewIconSize:
 
2919
        ret = pixelMetric(PM_LargeIconSize);
 
2920
        break;
 
2921
 
 
2922
    case PM_SmallIconSize:
 
2923
        ret = 16;
 
2924
        break;
 
2925
    case PM_LargeIconSize:
 
2926
        ret = 32;
 
2927
        break;
 
2928
 
 
2929
    case PM_ToolTipLabelFrameWidth:
 
2930
        ret = 1;
 
2931
        break;
 
2932
    default:
 
2933
        ret = 0;
 
2934
        break;
 
2935
    }
 
2936
 
 
2937
    return ret;
 
2938
}
 
2939
 
 
2940
/*!
 
2941
    \reimp
 
2942
*/
 
2943
QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
 
2944
                                     const QSize &csz, const QWidget *widget) const
 
2945
{
 
2946
    QSize sz(csz);
 
2947
    switch (ct) {
 
2948
    case CT_PushButton:
 
2949
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
2950
            int w = csz.width(),
 
2951
                h = csz.height(),
 
2952
                bm = pixelMetric(PM_ButtonMargin, btn, widget),
 
2953
            fw = pixelMetric(PM_DefaultFrameWidth, btn, widget) * 2;
 
2954
            w += bm + fw;
 
2955
            h += bm + fw;
 
2956
            if (btn->features & QStyleOptionButton::AutoDefaultButton){
 
2957
                int dbw = pixelMetric(PM_ButtonDefaultIndicator, btn, widget) * 2;
 
2958
                w += dbw;
 
2959
                h += dbw;
 
2960
            }
 
2961
            sz = QSize(w, h);
 
2962
        }
 
2963
        break;
 
2964
    case CT_RadioButton:
 
2965
    case CT_CheckBox:
 
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));
 
2976
        }
 
2977
        break;
 
2978
    case CT_MenuItem:
 
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) {
 
2984
                w = 10;
 
2985
                h = 2;
 
2986
            } else {
 
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);
 
2990
            }
 
2991
            if (mi->text.contains('\t'))
 
2992
                w += 12;
 
2993
            if (maxpmw > 0)
 
2994
                w += maxpmw + 6;
 
2995
            if (checkable && maxpmw < 20)
 
2996
                w += 20 - maxpmw;
 
2997
            if (checkable || maxpmw > 0)
 
2998
                w += 2;
 
2999
            w += 12;
 
3000
            sz = QSize(w, h);
 
3001
        }
 
3002
        break;
 
3003
    case CT_ToolButton:
 
3004
        sz = QSize(sz.width() + 6, sz.height() + 5);
 
3005
        break;
 
3006
    case CT_ComboBox:
 
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);
 
3010
        }
 
3011
        break;
 
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);
 
3019
        }
 
3020
        break;
 
3021
    case CT_TabWidget:
 
3022
        sz += QSize(4, 4);
 
3023
        break;
 
3024
    case CT_ScrollBar:
 
3025
    case CT_MenuBar:
 
3026
    case CT_Menu:
 
3027
    case CT_MenuBarItem:
 
3028
    case CT_LineEdit:
 
3029
    case CT_Q3Header:
 
3030
    case CT_Slider:
 
3031
    case CT_ProgressBar:
 
3032
    case CT_TabBarTab:
 
3033
        // just return the contentsSize for now
 
3034
        // fall through intended
 
3035
    default:
 
3036
        break;
 
3037
    }
 
3038
    return sz;
 
3039
}
 
3040
 
 
3041
 
 
3042
/*! \reimp */
 
3043
int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *widget,
 
3044
                            QStyleHintReturn *hret) const
 
3045
{
 
3046
    int ret = 0;
 
3047
 
 
3048
    switch (sh) {
 
3049
#ifndef QT_NO_DIALOGBUTTONS
 
3050
    case SH_DialogButtons_DefaultButton:
 
3051
        ret = QDialogButtons::Accept;
 
3052
        break;
 
3053
#endif
 
3054
    case SH_GroupBox_TextLabelVerticalAlignment:
 
3055
        ret = Qt::AlignVCenter;
 
3056
        break;
 
3057
 
 
3058
    case SH_GroupBox_TextLabelColor:
 
3059
        ret = 0;
 
3060
        break;
 
3061
 
 
3062
    case SH_Q3ListViewExpand_SelectMouseType:
 
3063
    case SH_TabBar_SelectMouseType:
 
3064
        ret = QEvent::MouseButtonPress;
 
3065
        break;
 
3066
 
 
3067
#ifdef QT3_SUPPORT
 
3068
    case SH_GUIStyle:
 
3069
        ret = Qt::WindowsStyle;
 
3070
        break;
 
3071
#endif
 
3072
 
 
3073
    case SH_TabBar_Alignment:
 
3074
    case SH_Header_ArrowAlignment:
 
3075
        ret = Qt::AlignLeft;
 
3076
        break;
 
3077
 
 
3078
    case SH_TitleBar_AutoRaise:
 
3079
        ret = false;
 
3080
        break;
 
3081
 
 
3082
    case SH_Menu_SubMenuPopupDelay:
 
3083
        ret = 256;
 
3084
        break;
 
3085
 
 
3086
    case SH_ProgressDialog_TextLabelAlignment:
 
3087
        ret = Qt::AlignCenter;
 
3088
        break;
 
3089
 
 
3090
    case SH_BlinkCursorWhenTextSelected:
 
3091
        ret = 1;
 
3092
        break;
 
3093
 
 
3094
    case SH_Table_GridLineColor:
 
3095
        if (opt)
 
3096
            ret = opt->palette.color(QPalette::Mid).rgb();
 
3097
        else
 
3098
            ret = -1;
 
3099
        break;
 
3100
 
 
3101
    case SH_LineEdit_PasswordCharacter:
 
3102
        ret = '*';
 
3103
        break;
 
3104
 
 
3105
    case SH_ToolBox_SelectedPageTitleBold:
 
3106
        ret = 1;
 
3107
        break;
 
3108
 
 
3109
    case SH_UnderlineShortcut:
 
3110
        ret = 1;
 
3111
        break;
 
3112
 
 
3113
    case SH_SpinBox_ClickAutoRepeatRate:
 
3114
        ret = 150;
 
3115
        break;
 
3116
 
 
3117
    case SH_SpinBox_KeyPressAutoRepeatRate:
 
3118
        ret = 75;
 
3119
        break;
 
3120
 
 
3121
    case SH_Menu_FillScreenWithScroll:
 
3122
        ret = true;
 
3123
        break;
 
3124
 
 
3125
    case SH_ToolTipLabel_Opacity:
 
3126
        ret = 255;
 
3127
        break;
 
3128
 
 
3129
    case SH_Button_FocusPolicy:
 
3130
        ret = Qt::StrongFocus;
 
3131
        break;
 
3132
 
 
3133
    case SH_MenuBar_DismissOnSecondClick:
 
3134
        ret = 1;
 
3135
        break;
 
3136
 
 
3137
    case SH_MessageBox_UseBorderForButtonSpacing:
 
3138
        ret = 0;
 
3139
        break;
 
3140
 
 
3141
    case SH_ToolButton_PopupDelay:
 
3142
        ret = 600;
 
3143
        break;
 
3144
 
 
3145
    case SH_FocusFrame_Mask:
 
3146
        ret = 1;
 
3147
        if (widget) {
 
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));
 
3153
            }
 
3154
        }
 
3155
        break;
 
3156
 
 
3157
    case SH_RubberBand_Mask:
 
3158
        if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
 
3159
            ret = 0;
 
3160
            if (rbOpt->shape == QRubberBand::Rectangle) {
 
3161
                ret = true;
 
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);
 
3166
                }
 
3167
            }
 
3168
        }
 
3169
        break;
 
3170
 
 
3171
    case SH_SpinControls_DisableOnBounds:
 
3172
        ret = 1;
 
3173
        break;
 
3174
 
 
3175
    case SH_Dial_BackgroundRole:
 
3176
        ret = QPalette::Background;
 
3177
        break;
 
3178
 
 
3179
    case SH_ComboBox_LayoutDirection:
 
3180
        ret = opt->direction;
 
3181
        break;
 
3182
 
 
3183
    case SH_ItemView_EllipsisLocation:
 
3184
        ret = Qt::AlignTrailing;
 
3185
        break;
 
3186
 
 
3187
    case SH_ItemView_ShowDecorationSelected:
 
3188
        ret = false;
 
3189
        break;
 
3190
 
 
3191
    case SH_ItemView_ActivateItemOnSingleClick:
 
3192
        ret = false;
 
3193
        break;
 
3194
 
 
3195
    case SH_TitleBar_ModifyNotification:
 
3196
        ret = true;
 
3197
        break;
 
3198
 
 
3199
    default:
 
3200
        ret = 0;
 
3201
        break;
 
3202
    }
 
3203
 
 
3204
    return ret;
 
3205
}
 
3206
 
 
3207
/*! \reimp */
 
3208
QPixmap QCommonStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *,
 
3209
                                     const QWidget *) const
 
3210
{
 
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);
 
3218
        }
 
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"));
 
3242
    case SP_TrashIcon:
 
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"));
 
3262
    case SP_FileIcon:
 
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"));
 
3266
    default:
 
3267
        break;
 
3268
    }
 
3269
#endif // QT_NO_IMAGEIO_XPM
 
3270
    return QPixmap();
 
3271
}
 
3272
 
 
3273
static inline uint qt_intensity(uint r, uint g, uint b)
 
3274
{
 
3275
    // 30% red, 59% green, 11% blue
 
3276
    return (77 * r + 150 * g + 28 * b) / 255;
 
3277
}
 
3278
 
 
3279
/*! \reimp */
 
3280
QPixmap QCommonStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
 
3281
                                          const QStyleOption *opt) const
 
3282
{
 
3283
    switch (iconMode) {
 
3284
    case QIcon::Disabled: {
 
3285
        QImage im = pixmap.toImage().convertToFormat(QImage::Format_ARGB32);
 
3286
 
 
3287
        // Create a colortable based on the background (black -> bg -> white)
 
3288
        QColor bg = opt->palette.color(QPalette::Disabled, QPalette::Background);
 
3289
        int red = bg.red();
 
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);
 
3297
        }
 
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));
 
3302
        }
 
3303
 
 
3304
        int intensity = qt_intensity(red, green, blue);
 
3305
        const int factor = 191;
 
3306
 
 
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)
 
3315
            intensity -= 51;
 
3316
 
 
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));
 
3325
                ++scanLine;
 
3326
            }
 
3327
        }
 
3328
 
 
3329
        return QPixmap::fromImage(im);
 
3330
    }
 
3331
    case QIcon::Active:
 
3332
        return pixmap;
 
3333
    default:
 
3334
        break;
 
3335
    }
 
3336
    return pixmap;
 
3337
}
 
3338
 
 
3339
#endif // QT_NO_STYLE