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

« back to all changes in this revision

Viewing changes to src/gui/styles/qmotifstyle.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 "qmotifstyle.h"
 
30
 
 
31
#if !defined(QT_NO_STYLE_MOTIF) || defined(QT_PLUGIN)
 
32
 
 
33
#include "qmenu.h"
 
34
#include "qapplication.h"
 
35
#include "qpainter.h"
 
36
#include "qdrawutil.h"
 
37
#include "qpixmap.h"
 
38
#include "qpalette.h"
 
39
#include "qwidget.h"
 
40
#include "qpushbutton.h"
 
41
#include "qscrollbar.h"
 
42
#include "qtabbar.h"
 
43
#include "qtabwidget.h"
 
44
#include "qlistview.h"
 
45
#include "qsplitter.h"
 
46
#include "qslider.h"
 
47
#include "qcombobox.h"
 
48
#include "qlineedit.h"
 
49
#include "qprogressbar.h"
 
50
#include "qimage.h"
 
51
#include "qfocusframe.h"
 
52
#include "qdebug.h"
 
53
#include "qpainterpath.h"
 
54
#include <limits.h>
 
55
 
 
56
#ifdef Q_WS_X11
 
57
#include "qx11info_x11.h"
 
58
#endif
 
59
 
 
60
// old constants that might still be useful...
 
61
static const int motifItemFrame         = 2;    // menu item frame width
 
62
static const int motifSepHeight         = 2;    // separator item height
 
63
static const int motifItemHMargin       = 3;    // menu item hor text margin
 
64
static const int motifItemVMargin       = 2;    // menu item ver text margin
 
65
static const int motifArrowHMargin      = 6;    // arrow horizontal margin
 
66
static const int motifTabSpacing        = 12;   // space between text and tab
 
67
static const int motifCheckMarkHMargin  = 2;    // horiz. margins of check mark
 
68
static const int motifCheckMarkSpace    = 12;
 
69
 
 
70
 
 
71
/*!
 
72
  \class QMotifStyle qmotifstyle.h
 
73
  \brief The QMotifStyle class provides Motif look and feel.
 
74
 
 
75
  \ingroup appearance
 
76
 
 
77
  This class implements the Motif look and feel. It closely
 
78
  resembles the original Motif look as defined by the Open Group,
 
79
  but with some minor improvements. The Motif style is Qt's default
 
80
  GUI style on Unix platforms.
 
81
 
 
82
  \img qmotifstyle.png
 
83
  \sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QPlastiqueStyle, QCDEStyle
 
84
*/
 
85
 
 
86
/*!
 
87
    \variable QMotifStyle::focus
 
88
    \internal
 
89
*/
 
90
 
 
91
/*!
 
92
  Constructs a QMotifStyle.
 
93
 
 
94
  If \a useHighlightCols is false (the default), the style will
 
95
  polish the application's color palette to emulate the Motif way of
 
96
  highlighting, which is a simple inversion between the base and the
 
97
  text color.
 
98
*/
 
99
QMotifStyle::QMotifStyle(bool useHighlightCols) : QCommonStyle()
 
100
{
 
101
    focus = 0;
 
102
    highlightCols = useHighlightCols;
 
103
}
 
104
 
 
105
/*!
 
106
  \overload
 
107
 
 
108
  Destroys the style.
 
109
*/
 
110
QMotifStyle::~QMotifStyle()
 
111
{
 
112
    delete focus;
 
113
}
 
114
 
 
115
/*!
 
116
  If \a arg is false, the style will polish the application's color
 
117
  palette to emulate the Motif way of highlighting, which is a
 
118
  simple inversion between the base and the text color.
 
119
 
 
120
  The effect will show up the next time an application palette is
 
121
  set via QApplication::setPalette(). The current color palette of
 
122
  the application remains unchanged.
 
123
 
 
124
  \sa QStyle::polish()
 
125
*/
 
126
void QMotifStyle::setUseHighlightColors(bool arg)
 
127
{
 
128
    highlightCols = arg;
 
129
}
 
130
 
 
131
/*!
 
132
  Returns true if the style treats the highlight colors of the
 
133
  palette in a Motif-like manner, which is a simple inversion
 
134
  between the base and the text color; otherwise returns false. The
 
135
  default is false.
 
136
*/
 
137
bool QMotifStyle::useHighlightColors() const
 
138
{
 
139
    return highlightCols;
 
140
}
 
141
 
 
142
/*! \reimp */
 
143
 
 
144
void QMotifStyle::polish(QPalette& pal)
 
145
{
 
146
    if (pal.brush(QPalette::Active, QPalette::Light) == pal.brush(QPalette::Active, QPalette::Base)) {
 
147
        QColor nlight = pal.color(QPalette::Active, QPalette::Light).dark(108);
 
148
        pal.setColor(QPalette::Active, QPalette::Light, nlight) ;
 
149
        pal.setColor(QPalette::Disabled, QPalette::Light, nlight) ;
 
150
        pal.setColor(QPalette::Inactive, QPalette::Light, nlight) ;
 
151
    }
 
152
 
 
153
    if (highlightCols)
 
154
        return;
 
155
 
 
156
    // force the ugly motif way of highlighting *sigh*
 
157
    pal.setColor(QPalette::Active, QPalette::Highlight,
 
158
                 pal.color(QPalette::Active, QPalette::Text));
 
159
    pal.setColor(QPalette::Active, QPalette::HighlightedText,
 
160
                 pal.color(QPalette::Active, QPalette::Base));
 
161
    pal.setColor(QPalette::Disabled, QPalette::Highlight,
 
162
                 pal.color(QPalette::Disabled, QPalette::Text));
 
163
    pal.setColor(QPalette::Disabled, QPalette::HighlightedText,
 
164
                 pal.color(QPalette::Disabled, QPalette::Base));
 
165
    pal.setColor(QPalette::Inactive, QPalette::Highlight,
 
166
                 pal.color(QPalette::Active, QPalette::Text));
 
167
    pal.setColor(QPalette::Inactive, QPalette::HighlightedText,
 
168
                 pal.color(QPalette::Active, QPalette::Base));
 
169
}
 
170
 
 
171
/*!
 
172
  \reimp
 
173
  \internal
 
174
  Keep QStyle::polish() visible.
 
175
*/
 
176
void QMotifStyle::polish(QWidget* w)
 
177
{
 
178
    QStyle::polish(w);
 
179
}
 
180
 
 
181
/*!
 
182
  \reimp
 
183
  \internal
 
184
  Keep QStyle::polish() visible.
 
185
*/
 
186
void QMotifStyle::polish(QApplication* a)
 
187
{
 
188
    QStyle::polish(a);
 
189
}
 
190
 
 
191
static void rot(QPolygon& a, int n)
 
192
{
 
193
    QPolygon r(a.size());
 
194
    for (int i = 0; i < (int)a.size(); i++) {
 
195
        switch (n) {
 
196
        case 1: r.setPoint(i,-a[i].y(),a[i].x()); break;
 
197
        case 2: r.setPoint(i,-a[i].x(),-a[i].y()); break;
 
198
        case 3: r.setPoint(i,a[i].y(),-a[i].x()); break;
 
199
        }
 
200
    }
 
201
    a = r;
 
202
}
 
203
 
 
204
 
 
205
/*!
 
206
  \reimp
 
207
*/
 
208
void QMotifStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
 
209
                                const QWidget *w) const
 
210
{
 
211
    switch(pe) {
 
212
    case PE_Q3CheckListExclusiveIndicator:
 
213
        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
214
            if (lv->items.isEmpty())
 
215
                return;
 
216
 
 
217
            if (lv->state & State_Enabled)
 
218
                p->setPen(QPen(opt->palette.text().color()));
 
219
            else
 
220
                p->setPen(QPen(lv->palette.color(QPalette::Disabled, QPalette::Text)));
 
221
            QPolygon a;
 
222
 
 
223
            int cx = opt->rect.width()/2 - 1;
 
224
            int cy = opt->rect.height()/2;
 
225
            int e = opt->rect.width()/2 - 1;
 
226
            for (int i = 0; i < 3; i++) { //penWidth 2 doesn't quite work
 
227
                a.setPoints(4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e);
 
228
                p->drawPolygon(a);
 
229
                e--;
 
230
            }
 
231
            if (opt->state & State_On) {
 
232
                if (lv->state & State_Enabled)
 
233
                    p->setPen(QPen(opt->palette.text().color()));
 
234
                else
 
235
                    p->setPen(QPen(lv->palette.color(QPalette::Disabled,
 
236
                                                     QPalette::Text)));
 
237
                QBrush saveBrush = p->brush();
 
238
                p->setBrush(opt->palette.text());
 
239
                e = e - 2;
 
240
                a.setPoints(4, cx-e, cy, cx, cy-e, cx+e, cy, cx, cy+e);
 
241
                p->drawPolygon(a);
 
242
                p->setBrush(saveBrush);
 
243
            }
 
244
        }
 
245
        break;
 
246
 
 
247
    case PE_FrameTabWidget:
 
248
    case PE_FrameWindow:
 
249
        qDrawShadePanel(p, opt->rect, opt->palette, QStyle::State_None, pixelMetric(PM_DefaultFrameWidth));
 
250
        break;
 
251
    case PE_FrameFocusRect:
 
252
        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
 
253
            if ((fropt->state & State_HasFocus) && focus && focus->isVisible())
 
254
                break;
 
255
            QCommonStyle::drawPrimitive(pe, opt, p, w);
 
256
        }
 
257
        break;
 
258
 
 
259
    case PE_IndicatorToolBarHandle: {
 
260
        p->save();
 
261
        p->translate(opt->rect.x(), opt->rect.y());
 
262
 
 
263
        QColor dark(opt->palette.dark().color());
 
264
        QColor light(opt->palette.light().color());
 
265
        int i;
 
266
        if (opt->state & State_Horizontal) {
 
267
            int h = opt->rect.height();
 
268
            if (h > 6) {
 
269
                if (opt->state & State_On)
 
270
                    p->fillRect(1, 1, 8, h - 2, opt->palette.highlight());
 
271
                QPolygon a(2 * ((h-6)/3));
 
272
                int y = 3 + (h%3)/2;
 
273
                p->setPen(dark);
 
274
                p->drawLine(8, 1, 8, h-2);
 
275
                for(i=0; 2*i < a.size(); i ++) {
 
276
                    a.setPoint(2*i, 5, y+1+3*i);
 
277
                    a.setPoint(2*i+1, 2, y+2+3*i);
 
278
                }
 
279
                p->drawPoints(a);
 
280
                p->setPen(light);
 
281
                p->drawLine(9, 1, 9, h-2);
 
282
                for(i=0; 2*i < a.size(); i++) {
 
283
                    a.setPoint(2*i, 4, y+3*i);
 
284
                    a.setPoint(2*i+1, 1, y+1+3*i);
 
285
                }
 
286
                p->drawPoints(a);
 
287
                // if (drawBorder) {
 
288
                // p->setPen(QPen(Qt::darkGray));
 
289
                // p->drawLine(0, opt->rect.height() - 1,
 
290
                // tbExtent, opt->rect.height() - 1);
 
291
                // }
 
292
            }
 
293
        } else {
 
294
            int w = opt->rect.width();
 
295
            if (w > 6) {
 
296
                if (opt->state & State_On)
 
297
                    p->fillRect(1, 1, w - 2, 9, opt->palette.highlight());
 
298
                QPolygon a(2 * ((w-6)/3));
 
299
 
 
300
                int x = 3 + (w%3)/2;
 
301
                p->setPen(dark);
 
302
                p->drawLine(1, 8, w-2, 8);
 
303
                for(i=0; 2*i < a.size(); i ++) {
 
304
                    a.setPoint(2*i, x+1+3*i, 6);
 
305
                    a.setPoint(2*i+1, x+2+3*i, 3);
 
306
                }
 
307
                p->drawPoints(a);
 
308
                p->setPen(light);
 
309
                p->drawLine(1, 9, w-2, 9);
 
310
                for(i=0; 2*i < a.size(); i++) {
 
311
                    a.setPoint(2*i, x+3*i, 5);
 
312
                    a.setPoint(2*i+1, x+1+3*i, 2);
 
313
                }
 
314
                p->drawPoints(a);
 
315
                // if (drawBorder) {
 
316
                // p->setPen(QPen(Qt::darkGray));
 
317
                // p->drawLine(opt->rect.width() - 1, 0,
 
318
                // opt->rect.width() - 1, tbExtent);
 
319
                // }
 
320
            }
 
321
        }
 
322
        p->restore();
 
323
        break; }
 
324
 
 
325
    case PE_PanelButtonCommand:
 
326
    case PE_PanelButtonBevel:
 
327
    case PE_PanelButtonTool: {
 
328
        QBrush fill;
 
329
        if (opt->state & State_Sunken)
 
330
            fill = opt->palette.brush(QPalette::Mid);
 
331
        else if ((opt->state & State_On) && (opt->state & State_Enabled))
 
332
            fill = QBrush(opt->palette.mid().color(), Qt::Dense4Pattern);
 
333
        else
 
334
            fill = opt->palette.brush(QPalette::Button);
 
335
        qDrawShadePanel(p, opt->rect, opt->palette, bool(opt->state & (State_Sunken | State_On)),
 
336
                        pixelMetric(PM_DefaultFrameWidth), &fill);
 
337
        break; }
 
338
 
 
339
    case PE_IndicatorCheckBox: {
 
340
        bool on = opt->state & State_On;
 
341
        bool down = opt->state & State_Sunken;
 
342
        bool showUp = !(down ^ on);
 
343
        QBrush fill = opt->palette.brush((showUp || opt->state & State_NoChange) ?QPalette::Button : QPalette::Mid);
 
344
        if (opt->state & State_NoChange) {
 
345
            qDrawPlainRect(p, opt->rect, opt->palette.text().color(),
 
346
                           1, &fill);
 
347
            p->drawLine(opt->rect.x() + opt->rect.width() - 1, opt->rect.y(),
 
348
                        opt->rect.x(), opt->rect.y() + opt->rect.height() - 1);
 
349
        } else {
 
350
            qDrawShadePanel(p, opt->rect, opt->palette, !showUp,
 
351
                            pixelMetric(PM_DefaultFrameWidth), &fill);
 
352
        }
 
353
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
354
            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
355
        break; }
 
356
 
 
357
    case PE_IndicatorRadioButton: {
 
358
#define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)
 
359
        int inner_pts[] = { // used for filling diamond
 
360
            2,opt->rect.height()/2,
 
361
            opt->rect.width()/2,2,
 
362
            opt->rect.width()-3,opt->rect.height()/2,
 
363
            opt->rect.width()/2,opt->rect.height()-3
 
364
        };
 
365
        int top_pts[] = { // top (^) of diamond
 
366
            0,opt->rect.height()/2,
 
367
            opt->rect.width()/2,0,
 
368
            opt->rect.width()-2,opt->rect.height()/2-1,
 
369
            opt->rect.width()-3,opt->rect.height()/2-1,
 
370
            opt->rect.width()/2,1,
 
371
            1,opt->rect.height()/2,
 
372
            2,opt->rect.height()/2,
 
373
            opt->rect.width()/2,2,
 
374
            opt->rect.width()-4,opt->rect.height()/2-1
 
375
        };
 
376
        int bottom_pts[] = { // bottom (v) of diamond
 
377
            1,opt->rect.height()/2+1,
 
378
            opt->rect.width()/2,opt->rect.height()-1,
 
379
            opt->rect.width()-1,opt->rect.height()/2,
 
380
            opt->rect.width()-2,opt->rect.height()/2,
 
381
            opt->rect.width()/2,opt->rect.height()-2,
 
382
            2,opt->rect.height()/2+1,
 
383
            3,opt->rect.height()/2+1,
 
384
            opt->rect.width()/2,opt->rect.height()-3,
 
385
            opt->rect.width()-3,opt->rect.height()/2
 
386
        };
 
387
        bool on = opt->state & State_On;
 
388
        bool down = opt->state & State_Sunken;
 
389
        bool showUp = !(down ^ on);
 
390
        QPen oldPen = p->pen();
 
391
        QBrush oldBrush = p->brush();
 
392
        QPolygon a(INTARRLEN(inner_pts), inner_pts);
 
393
        p->setPen(Qt::NoPen);
 
394
        p->setBrush(opt->palette.brush(showUp ? QPalette::Button : QPalette::Mid));
 
395
        a.translate(opt->rect.x(), opt->rect.y());
 
396
        p->drawPolygon(a);
 
397
        p->setPen(showUp ? opt->palette.light().color() : opt->palette.dark().color());
 
398
        p->setBrush(Qt::NoBrush);
 
399
        a.setPoints(INTARRLEN(top_pts), top_pts);
 
400
        a.translate(opt->rect.x(), opt->rect.y());
 
401
        p->drawPolyline(a);
 
402
        p->setPen(showUp ? opt->palette.dark().color() : opt->palette.light().color());
 
403
        a.setPoints(INTARRLEN(bottom_pts), bottom_pts);
 
404
        a.translate(opt->rect.x(), opt->rect.y());
 
405
        p->drawPolyline(a);
 
406
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
407
            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
408
        p->setPen(oldPen);
 
409
        p->setBrush(oldBrush);
 
410
        break; }
 
411
 
 
412
    case PE_IndicatorSpinUp:
 
413
    case PE_IndicatorSpinPlus:
 
414
    case PE_IndicatorSpinDown:
 
415
    case PE_IndicatorSpinMinus:
 
416
    case PE_IndicatorArrowUp:
 
417
    case PE_IndicatorArrowDown:
 
418
    case PE_IndicatorArrowRight:
 
419
    case PE_IndicatorArrowLeft: {
 
420
        QRect rect = opt->rect;
 
421
        QPolygon bFill;
 
422
        QPolygon bTop;
 
423
        QPolygon bBot;
 
424
        QPolygon bLeft;
 
425
        if (pe == PE_IndicatorSpinPlus || pe == PE_IndicatorSpinUp)
 
426
            pe = PE_IndicatorArrowUp;
 
427
        else if (pe == PE_IndicatorSpinMinus || pe == PE_IndicatorSpinDown)
 
428
            pe = PE_IndicatorArrowDown;
 
429
        bool vertical = pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowDown;
 
430
        bool horizontal = !vertical;
 
431
        int dim = rect.width() < rect.height() ? rect.width() : rect.height();
 
432
        int colspec = 0x0000;
 
433
 
 
434
        if (!(opt->state & State_Enabled))
 
435
            dim -= 2;
 
436
        if(dim < 2)
 
437
           break;
 
438
 
 
439
        // adjust size and center (to fix rotation below)
 
440
        if (rect.width() > dim) {
 
441
            rect.setX(rect.x() + ((rect.width() - dim) / 2));
 
442
            rect.setWidth(dim);
 
443
        }
 
444
        if (rect.height() > dim) {
 
445
            rect.setY(rect.y() + ((rect.height() - dim) / 2));
 
446
            rect.setHeight(dim);
 
447
        }
 
448
 
 
449
        if (dim > 3) {
 
450
            if (pixelMetric(PM_DefaultFrameWidth) < 2) { // thin style
 
451
                bFill.resize( dim & 1 ? 3 : 4 );
 
452
                bTop.resize( 2 );
 
453
                bBot.resize( 2 );
 
454
                bLeft.resize( 2 );
 
455
                bLeft.putPoints( 0, 2, 0, 0, 0, dim-1 );
 
456
                bTop.putPoints( 0, 2, 1, 0, dim-1, dim/2 );
 
457
                bBot.putPoints( 0, 2, 1, dim-1, dim-1, dim/2 );
 
458
 
 
459
                if ( dim > 6 ) {                        // dim>6: must fill interior
 
460
                    bFill.putPoints( 0, 2, 0, dim-1, 0, 0 );
 
461
                    if ( dim & 1 )                      // if size is an odd number
 
462
                        bFill.setPoint( 2, dim - 1, dim / 2 );
 
463
                    else
 
464
                        bFill.putPoints( 2, 2, dim-1, dim/2-1, dim-1, dim/2 );
 
465
                }
 
466
            } else {
 
467
                if (dim > 6)
 
468
                    bFill.resize(dim & 1 ? 3 : 4);
 
469
                bTop.resize((dim/2)*2);
 
470
                bBot.resize(dim & 1 ? dim + 1 : dim);
 
471
                bLeft.resize(dim > 4 ? 4 : 2);
 
472
                bLeft.putPoints(0, 2, 0,0, 0,dim-1);
 
473
                if (dim > 4)
 
474
                    bLeft.putPoints(2, 2, 1,2, 1,dim-3);
 
475
                bTop.putPoints(0, 4, 1,0, 1,1, 2,1, 3,1);
 
476
                bBot.putPoints(0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2);
 
477
 
 
478
                for(int i=0; i<dim/2-2 ; i++) {
 
479
                    bTop.putPoints(i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i);
 
480
                    bBot.putPoints(i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i);
 
481
                }
 
482
                if (dim & 1)                          // odd number size: extra line
 
483
                    bBot.putPoints(dim-1, 2, dim-3,dim/2, dim-1,dim/2);
 
484
                if (dim > 6) {                        // dim>6: must fill interior
 
485
                    bFill.putPoints(0, 2, 1,dim-3, 1,2);
 
486
                    if (dim & 1)                      // if size is an odd number
 
487
                        bFill.setPoint(2, dim - 3, dim / 2);
 
488
                    else
 
489
                        bFill.putPoints(2, 2, dim-4,dim/2-1, dim-4,dim/2);
 
490
                }
 
491
            }
 
492
        } else {
 
493
            if (dim == 3) {                       // 3x3 arrow pattern
 
494
                bLeft.setPoints(4, 0,0, 0,2, 1,1, 1,1);
 
495
                bTop .setPoints(2, 1,0, 1,0);
 
496
                bBot .setPoints(2, 1,2, 2,1);
 
497
            }
 
498
            else {                                  // 2x2 arrow pattern
 
499
                bLeft.setPoints(2, 0,0, 0,1);
 
500
                bTop .setPoints(2, 1,0, 1,0);
 
501
                bBot .setPoints(2, 1,1, 1,1);
 
502
            }
 
503
        }
 
504
 
 
505
        // We use rot() and translate() as it is more efficient that
 
506
        // matrix transformations on the painter, and because it still
 
507
        // works with QT_NO_TRANSFORMATIONS defined.
 
508
 
 
509
        if (pe == PE_IndicatorArrowUp || pe == PE_IndicatorArrowLeft) {
 
510
            if (vertical) {
 
511
                rot(bFill,3);
 
512
                rot(bLeft,3);
 
513
                rot(bTop,3);
 
514
                rot(bBot,3);
 
515
                bFill.translate(0, rect.height() - 1);
 
516
                bLeft.translate(0, rect.height() - 1);
 
517
                bTop.translate(0, rect.height() - 1);
 
518
                bBot.translate(0, rect.height() - 1);
 
519
            } else {
 
520
                rot(bFill,2);
 
521
                rot(bLeft,2);
 
522
                rot(bTop,2);
 
523
                rot(bBot,2);
 
524
                bFill.translate(rect.width() - 1, rect.height() - 1);
 
525
                bLeft.translate(rect.width() - 1, rect.height() - 1);
 
526
                bTop.translate(rect.width() - 1, rect.height() - 1);
 
527
                bBot.translate(rect.width() - 1, rect.height() - 1);
 
528
            }
 
529
            if (opt->state & State_Sunken)
 
530
                colspec = horizontal ? 0x2334 : 0x2343;
 
531
            else
 
532
                colspec = horizontal ? 0x1443 : 0x1434;
 
533
        } else {
 
534
            if (vertical) {
 
535
                rot(bFill,1);
 
536
                rot(bLeft,1);
 
537
                rot(bTop,1);
 
538
                rot(bBot,1);
 
539
                bFill.translate(rect.width() - 1, 0);
 
540
                bLeft.translate(rect.width() - 1, 0);
 
541
                bTop.translate(rect.width() - 1, 0);
 
542
                bBot.translate(rect.width() - 1, 0);
 
543
            }
 
544
            if (opt->state & State_Sunken)
 
545
                colspec = horizontal ? 0x2443 : 0x2434;
 
546
            else
 
547
                colspec = horizontal ? 0x1334 : 0x1343;
 
548
        }
 
549
        bFill.translate(rect.x(), rect.y());
 
550
        bLeft.translate(rect.x(), rect.y());
 
551
        bTop.translate(rect.x(), rect.y());
 
552
        bBot.translate(rect.x(), rect.y());
 
553
 
 
554
        const QColor *cols[5];
 
555
        if (opt->state & State_Enabled) {
 
556
            cols[0] = 0;
 
557
            cols[1] = &opt->palette.button().color();
 
558
            cols[2] = &opt->palette.mid().color();
 
559
            cols[3] = &opt->palette.light().color();
 
560
            cols[4] = &opt->palette.dark().color();
 
561
        } else {
 
562
            cols[0] = 0;
 
563
            cols[1] = &opt->palette.mid().color();
 
564
            cols[2] = &opt->palette.mid().color();
 
565
            cols[3] = &opt->palette.mid().color();
 
566
            cols[4] = &opt->palette.mid().color();
 
567
        }
 
568
 
 
569
#define CMID *cols[(colspec>>12) & 0xf]
 
570
#define CLEFT *cols[(colspec>>8) & 0xf]
 
571
#define CTOP *cols[(colspec>>4) & 0xf]
 
572
#define CBOT *cols[colspec & 0xf]
 
573
 
 
574
        QPen savePen = p->pen();
 
575
        QBrush saveBrush = p->brush();
 
576
        QPen pen(Qt::NoPen);
 
577
        QBrush brush = opt->palette.brush((opt->state & State_Enabled) ?
 
578
                                          QPalette::Button : QPalette::Mid);
 
579
        p->setPen(pen);
 
580
        p->setBrush(brush);
 
581
        p->drawPolygon(bFill);
 
582
        p->setBrush(Qt::NoBrush);
 
583
 
 
584
        p->setPen(CLEFT);
 
585
        p->drawPolyline(bLeft);
 
586
        p->setPen(CTOP);
 
587
        p->drawPolyline(bTop);
 
588
        p->setPen(CBOT);
 
589
        p->drawPolyline(bBot);
 
590
 
 
591
        p->setBrush(saveBrush);
 
592
        p->setPen(savePen);
 
593
#undef CMID
 
594
#undef CLEFT
 
595
#undef CTOP
 
596
#undef CBOT
 
597
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
598
            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
599
        break; }
 
600
 
 
601
    case PE_IndicatorDockWidgetResizeHandle: {
 
602
        const int motifOffset = 10;
 
603
        int sw = pixelMetric(PM_SplitterWidth);
 
604
        if (opt->state & State_Horizontal) {
 
605
            int yPos = opt->rect.y() + opt->rect.height() / 2;
 
606
            int kPos = opt->rect.width() - motifOffset - sw;
 
607
            int kSize = sw - 2;
 
608
 
 
609
            qDrawShadeLine(p, 0, yPos, kPos, yPos, opt->palette);
 
610
            qDrawShadePanel(p, kPos, yPos - sw / 2 + 1, kSize, kSize,
 
611
                            opt->palette, false, 1, &opt->palette.brush(QPalette::Button));
 
612
            qDrawShadeLine(p, kPos + kSize - 1, yPos, opt->rect.width(), yPos, opt->palette);
 
613
        } else {
 
614
            int xPos = opt->rect.x() + opt->rect.width() / 2;
 
615
            int kPos = motifOffset;
 
616
            int kSize = sw - 2;
 
617
 
 
618
            qDrawShadeLine(p, xPos, kPos + kSize - 1, xPos, opt->rect.height(), opt->palette);
 
619
            qDrawShadePanel(p, xPos - sw / 2 + 1, kPos, kSize, kSize, opt->palette,
 
620
                            false, 1, &opt->palette.brush(QPalette::Button));
 
621
            qDrawShadeLine(p, xPos, 0, xPos, kPos, opt->palette);
 
622
        }
 
623
        break; }
 
624
 
 
625
    case PE_IndicatorMenuCheckMark: {
 
626
        const int markW = 6;
 
627
        const int markH = 6;
 
628
        int posX = opt->rect.x() + (opt->rect.width()  - markW) / 2 - 1;
 
629
        int posY = opt->rect.y() + (opt->rect.height() - markH) / 2;
 
630
        int dfw = pixelMetric(PM_DefaultFrameWidth);
 
631
 
 
632
        if (dfw < 2) {
 
633
            // Could do with some optimizing/caching...
 
634
            QPolygon a(7*2);
 
635
            int i, xx, yy;
 
636
            xx = posX;
 
637
            yy = 3 + posY;
 
638
            for (i=0; i<3; i++) {
 
639
                a.setPoint(2*i,   xx, yy);
 
640
                a.setPoint(2*i+1, xx, yy+2);
 
641
                xx++; yy++;
 
642
            }
 
643
            yy -= 2;
 
644
            for (i=3; i<7; i++) {
 
645
                a.setPoint(2*i,   xx, yy);
 
646
                a.setPoint(2*i+1, xx, yy+2);
 
647
                xx++; yy--;
 
648
            }
 
649
            if (! (opt->state & State_Enabled) && ! (opt->state & State_On)) {
 
650
                int pnt;
 
651
                p->setPen(opt->palette.highlightedText().color());
 
652
                QPoint offset(1,1);
 
653
                for (pnt = 0; pnt < (int)a.size(); pnt++)
 
654
                    a[pnt] += offset;
 
655
                p->drawPolyline(a);
 
656
                for (pnt = 0; pnt < (int)a.size(); pnt++)
 
657
                    a[pnt] -= offset;
 
658
            }
 
659
            p->setPen(opt->palette.text().color());
 
660
            p->drawPolyline(a);
 
661
 
 
662
            qDrawShadePanel(p, posX-2, posY-2, markW+4, markH+6, opt->palette, true, dfw);
 
663
        } else
 
664
            qDrawShadePanel(p, posX, posY, markW, markH, opt->palette, true, dfw,
 
665
                            &opt->palette.brush(QPalette::Mid));
 
666
 
 
667
        break; }
 
668
 
 
669
    case PE_IndicatorProgressChunk:
 
670
        p->fillRect(opt->rect.x(), opt->rect.y() + 2, opt->rect.width(),
 
671
                    opt->rect.height() - 4, opt->palette.brush(QPalette::Highlight));
 
672
        break;
 
673
 
 
674
    default:
 
675
        QCommonStyle::drawPrimitive(pe, opt, p, w);
 
676
        break;
 
677
    }
 
678
}
 
679
 
 
680
 
 
681
/*!
 
682
  \reimp
 
683
*/
 
684
void QMotifStyle::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
 
685
                              const QWidget *widget) const
 
686
{
 
687
    switch(element) {
 
688
    case CE_Splitter: {
 
689
        QStyleOption handleOpt = *opt;
 
690
        if (handleOpt.state & State_Horizontal)
 
691
            handleOpt.state &= ~State_Horizontal;
 
692
        else
 
693
            handleOpt.state |= State_Horizontal;
 
694
        drawPrimitive(PE_IndicatorDockWidgetResizeHandle, &handleOpt, p, widget);
 
695
        break; }
 
696
 
 
697
    case CE_ScrollBarSubLine:
 
698
    case CE_ScrollBarAddLine:{
 
699
        PrimitiveElement pe;
 
700
        if (element == CE_ScrollBarAddLine)
 
701
            pe = (opt->state & State_Horizontal) ? (opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft) : PE_IndicatorArrowDown;
 
702
        else
 
703
            pe = (opt->state & State_Horizontal) ? (opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight) : PE_IndicatorArrowUp;
 
704
        QStyleOption arrowOpt = *opt;
 
705
        arrowOpt.state |= State_Enabled;
 
706
        drawPrimitive(pe, &arrowOpt, p, widget);
 
707
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText)) {
 
708
            int fw = pixelMetric(PM_DefaultFrameWidth);
 
709
            p->fillRect(opt->rect.adjusted(fw, fw, -fw, -fw), QBrush(p->background().color(), Qt::Dense5Pattern));
 
710
        }
 
711
    }break;
 
712
 
 
713
    case CE_ScrollBarSubPage:
 
714
    case CE_ScrollBarAddPage:
 
715
        p->fillRect(opt->rect, opt->palette.brush((opt->state & State_Enabled) ? QPalette::Mid : QPalette::Background));
 
716
        break;
 
717
 
 
718
    case CE_ScrollBarSlider: {
 
719
        QStyleOption bevelOpt = *opt;
 
720
        bevelOpt.state |= State_Raised;
 
721
        bevelOpt.state &= ~(State_Sunken | State_On);
 
722
        p->save();
 
723
        p->setBrushOrigin(bevelOpt.rect.topLeft());
 
724
        drawPrimitive(PE_PanelButtonBevel, &bevelOpt, p, widget);
 
725
        p->restore();
 
726
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
727
            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
728
        break; }
 
729
 
 
730
    case CE_RadioButton:
 
731
    case CE_CheckBox:
 
732
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
733
            bool isRadio = (element == CE_RadioButton);
 
734
            QStyleOptionButton subopt = *btn;
 
735
            subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
 
736
                                         : SE_CheckBoxIndicator, btn, widget);
 
737
            drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
 
738
                          &subopt, p, widget);
 
739
            subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
 
740
                                         : SE_CheckBoxContents, btn, widget);
 
741
            drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);
 
742
            if ((btn->state & State_HasFocus) && (!focus || !focus->isVisible())) {
 
743
                QStyleOptionFocusRect fropt;
 
744
                fropt.QStyleOption::operator=(*btn);
 
745
                fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
 
746
                                            : SE_CheckBoxFocusRect, btn, widget);
 
747
                drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
 
748
            }
 
749
        }
 
750
        break;
 
751
    case CE_PushButton:
 
752
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
753
            drawControl(CE_PushButtonBevel, btn, p, widget);
 
754
            QStyleOptionButton subopt = *btn;
 
755
            subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
 
756
            drawControl(CE_PushButtonLabel, &subopt, p, widget);
 
757
            if ((btn->state & State_HasFocus) && (!focus || !focus->isVisible())) {
 
758
                QStyleOptionFocusRect fropt;
 
759
                fropt.QStyleOption::operator=(*btn);
 
760
                fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);
 
761
                drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
 
762
            }
 
763
        }
 
764
        break;
 
765
    case CE_PushButtonBevel:
 
766
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
767
            int diw, x1, y1, x2, y2;
 
768
            p->setPen(opt->palette.foreground().color());
 
769
            p->setBrush(QBrush(opt->palette.button().color(), Qt::NoBrush));
 
770
            diw = pixelMetric(PM_ButtonDefaultIndicator);
 
771
            opt->rect.getCoords(&x1, &y1, &x2, &y2);
 
772
            if (btn->features & (QStyleOptionButton::AutoDefaultButton|QStyleOptionButton::DefaultButton)) {
 
773
                x1 += diw;
 
774
                y1 += diw;
 
775
                x2 -= diw;
 
776
                y2 -= diw;
 
777
            }
 
778
            if (btn->features & QStyleOptionButton::DefaultButton) {
 
779
                if (diw == 0) {
 
780
                    QPolygon a;
 
781
                    a.setPoints(9,
 
782
                                x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
 
783
                                x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1);
 
784
                    p->setPen(opt->palette.shadow().color());
 
785
                    p->drawPolygon(a);
 
786
                    x1 += 2;
 
787
                    y1 += 2;
 
788
                    x2 -= 2;
 
789
                    y2 -= 2;
 
790
                } else {
 
791
                    qDrawShadePanel(p, opt->rect.adjusted(1, 1, -1, -1), opt->palette, true);
 
792
                }
 
793
            }
 
794
            if (!(btn->features & QStyleOptionButton::Flat) ||
 
795
                (btn->state & (State_Sunken | State_On))) {
 
796
                QStyleOptionButton newOpt = *btn;
 
797
                newOpt.rect = QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
 
798
                p->setBrushOrigin(p->brushOrigin());
 
799
                drawPrimitive(PE_PanelButtonCommand, &newOpt, p, widget);
 
800
            }
 
801
            break;
 
802
        }
 
803
 
 
804
    case CE_TabBarTabShape:
 
805
        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
 
806
            const int default_frame = pixelMetric(PM_DefaultFrameWidth, tab, widget);
 
807
            const int frame_offset =  (default_frame > 1) ? 1 : 0;
 
808
 
 
809
            if (tab->shape == QTabBar::RoundedNorth || tab->shape == QTabBar::RoundedEast ||
 
810
                tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::RoundedWest) {
 
811
                p->save();
 
812
                QRect tabRect = opt->rect;
 
813
                QColor tabLight = opt->palette.light().color();
 
814
                QColor tabDark = opt->palette.dark().color();
 
815
                if(tab->shape == QTabBar::RoundedWest) {
 
816
                    tabDark = opt->palette.light().color();
 
817
                    tabLight = opt->palette.dark().color();
 
818
                    tabRect = QRect(0, 0, tabRect.height(), tabRect.width());
 
819
                    p->translate(opt->rect.left(), opt->rect.bottom());
 
820
                    p->rotate(-90);
 
821
                } else if(tab->shape == QTabBar::RoundedSouth) {
 
822
                    tabDark = opt->palette.light().color();
 
823
                    tabLight = opt->palette.dark().color();
 
824
                    tabRect = QRect(0, 0, tabRect.width(), tabRect.height());
 
825
                    p->translate(opt->rect.right(), opt->rect.bottom());
 
826
                    p->rotate(180);
 
827
                } else if(tab->shape == QTabBar::RoundedEast) {
 
828
                    tabRect = QRect(0, 0, tabRect.height(), tabRect.width());
 
829
                    p->translate(opt->rect.right(), opt->rect.top());
 
830
                    p->rotate(90);
 
831
                }
 
832
 
 
833
                if (default_frame > 1) {
 
834
                    p->setPen(tabLight);
 
835
                    p->drawLine(tabRect.left(), tabRect.bottom(),
 
836
                                tabRect.right(), tabRect.bottom());
 
837
                    p->setPen(tabLight);
 
838
                    p->drawLine(tabRect.left(), tabRect.bottom()-1,
 
839
                                tabRect.right(), tabRect.bottom()-1);
 
840
                    if (tabRect.left() == 0)
 
841
                        p->drawPoint(tabRect.bottomLeft());
 
842
                } else {
 
843
                    p->setPen(tabLight);
 
844
                    p->drawLine(tabRect.left(), tabRect.bottom(),
 
845
                                tabRect.right(), tabRect.bottom());
 
846
                }
 
847
 
 
848
                if (opt->state & State_Selected) {
 
849
                    p->fillRect(QRect(tabRect.left()+1, tabRect.bottom()-frame_offset,
 
850
                                      tabRect.width()-3, 2),
 
851
                                tab->palette.brush(QPalette::Active, QPalette::Background));
 
852
                    p->setPen(tab->palette.background().color());
 
853
                    p->drawLine(tabRect.left()+1, tabRect.bottom(),
 
854
                                tabRect.left()+1, tabRect.top()+2);
 
855
                    p->setPen(tabLight);
 
856
                } else {
 
857
                    p->setPen(tabLight);
 
858
                }
 
859
                p->drawLine(tabRect.left(), tabRect.bottom()-1,
 
860
                            tabRect.left(), tabRect.top() + 2);
 
861
                p->drawPoint(tabRect.left()+1, tabRect.top() + 1);
 
862
                p->drawLine(tabRect.left()+2, tabRect.top(),
 
863
                            tabRect.right() - 2, tabRect.top());
 
864
                p->drawPoint(tabRect.left(), tabRect.bottom());
 
865
 
 
866
                if (default_frame > 1) {
 
867
                    p->drawLine(tabRect.left()+1, tabRect.bottom(),
 
868
                                tabRect.left()+1, tabRect.top() + 2);
 
869
                    p->drawLine(tabRect.left()+2, tabRect.top()+1,
 
870
                                tabRect.right() - 2, tabRect.top()+1);
 
871
                }
 
872
 
 
873
                p->setPen(tabDark);
 
874
                p->drawLine(tabRect.right() - 1, tabRect.top() + 2,
 
875
                            tabRect.right() - 1, tabRect.bottom() - 1 +
 
876
                            ((opt->state & State_Selected) ? frame_offset : -frame_offset));
 
877
                if (default_frame > 1) {
 
878
                    p->drawPoint(tabRect.right() - 1, tabRect.top() + 1);
 
879
                    p->drawLine(tabRect.right(), tabRect.top() + 2, tabRect.right(),
 
880
                                tabRect.bottom() -
 
881
                                ((opt->state & State_Selected) ?
 
882
                                 ((tab->position == QStyleOptionTab::End) ? 0:1):1+frame_offset));
 
883
                    p->drawPoint(tabRect.right() - 1, tabRect.top() + 1);
 
884
                }
 
885
                p->restore();
 
886
            } else {
 
887
                QCommonStyle::drawControl(element, opt, p, widget);
 
888
            }
 
889
            break; }
 
890
    case CE_ProgressBarGroove:
 
891
        qDrawShadePanel(p, opt->rect, opt->palette, true, 2);
 
892
        break;
 
893
 
 
894
    case CE_ProgressBarLabel:
 
895
        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
 
896
            const int unit_width = pixelMetric(PM_ProgressBarChunkWidth, opt, widget);
 
897
            int u = opt->rect.width() / unit_width;
 
898
            int p_v = pb->progress;
 
899
            int t_s = qMax(0, pb->maximum - pb->minimum);
 
900
            if (u > 0 && pb->progress >= INT_MAX / u && t_s >= u) {
 
901
                // scale down to something usable.
 
902
                p_v /= u;
 
903
                t_s /= u;
 
904
            }
 
905
            if (pb->textVisible && t_s) {
 
906
                int nu = (u * p_v + t_s/2) / t_s;
 
907
                int x = unit_width * nu;
 
908
                QRect left(opt->rect.x(), opt->rect.y(), x, opt->rect.height());
 
909
                QRect right(opt->rect.x() + x, opt->rect.y(), opt->rect.width() - x, opt->rect.height());
 
910
                const QRect &highlighted = visualRect(pb->direction, pb->rect, left);
 
911
                const QRect &background = visualRect(pb->direction, pb->rect, right);
 
912
                p->setPen(opt->palette.highlightedText().color());
 
913
                p->setClipRect(highlighted);
 
914
                p->drawText(opt->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->text);
 
915
 
 
916
                if (pb->progress != pb->maximum) {
 
917
                    p->setClipRect(background);
 
918
                    p->setPen(opt->palette.highlight().color());
 
919
                    p->drawText(opt->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->text);
 
920
                }
 
921
            }
 
922
            break;
 
923
        }
 
924
 
 
925
    case CE_MenuTearoff: {
 
926
        if(opt->state & State_Selected) {
 
927
            if(pixelMetric(PM_MenuPanelWidth, opt, widget) > 1)
 
928
                qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(),
 
929
                                opt->rect.height(), opt->palette, false, motifItemFrame,
 
930
                                &opt->palette.brush(QPalette::Button));
 
931
            else
 
932
                qDrawShadePanel(p, opt->rect.x()+1, opt->rect.y()+1, opt->rect.width()-2,
 
933
                                opt->rect.height()-2, opt->palette, true, 1, &opt->palette.brush(QPalette::Button));
 
934
        } else {
 
935
            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
 
936
        }
 
937
        p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
 
938
        p->drawLine(opt->rect.x()+2, opt->rect.y()+opt->rect.height()/2-1, opt->rect.x()+opt->rect.width()-4,
 
939
                    opt->rect.y()+opt->rect.height()/2-1);
 
940
        p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
 
941
        p->drawLine(opt->rect.x()+2, opt->rect.y()+opt->rect.height()/2, opt->rect.x()+opt->rect.width()-4,
 
942
                    opt->rect.y()+opt->rect.height()/2);
 
943
        break; }
 
944
 
 
945
    case CE_MenuItem:
 
946
        if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
 
947
            int maxpmw = menuitem->maxIconWidth;
 
948
            if(menuitem->menuHasCheckableItems)
 
949
                maxpmw = qMax(maxpmw, motifCheckMarkSpace);
 
950
 
 
951
            int x, y, w, h;
 
952
            opt->rect.getRect(&x, &y, &w, &h);
 
953
 
 
954
            if(menuitem->menuItemType == QStyleOptionMenuItem::Separator) {  // draw separator
 
955
                p->setPen(opt->palette.dark().color());
 
956
                p->drawLine(x, y, x+w, y);
 
957
                p->setPen(opt->palette.light().color());
 
958
                p->drawLine(x, y+1, x+w, y+1);
 
959
                return;
 
960
            }
 
961
 
 
962
            int pw = motifItemFrame;
 
963
            if((opt->state & State_Selected) && (opt->state & State_Enabled)) {  // active item frame
 
964
                if(pixelMetric(PM_MenuPanelWidth, opt) > 1)
 
965
                    qDrawShadePanel(p, x, y, w, h, opt->palette, false, pw,
 
966
                                    &opt->palette.brush(QPalette::Button));
 
967
                else
 
968
                    qDrawShadePanel(p, x+1, y+1, w-2, h-2, opt->palette, true, 1,
 
969
                                    &opt->palette.brush(QPalette::Button));
 
970
            } else  {                               // incognito frame
 
971
                p->fillRect(x, y, w, h, opt->palette.brush(QPalette::Button));
 
972
            }
 
973
 
 
974
            QRect vrect = visualRect(opt->direction, opt->rect,
 
975
                                     QRect(x+motifItemFrame, y+motifItemFrame, maxpmw,
 
976
                                           h-2*motifItemFrame));
 
977
            int xvis = vrect.x();
 
978
            if (menuitem->checked) {
 
979
                if(!menuitem->icon.isNull())
 
980
                    qDrawShadePanel(p, xvis, y+motifItemFrame, maxpmw, h-2*motifItemFrame,
 
981
                                    opt->palette, true, 1, &opt->palette.brush(QPalette::Midlight));
 
982
            } else if (!(opt->state & State_Selected)) {
 
983
                p->fillRect(xvis, y+motifItemFrame, maxpmw, h-2*motifItemFrame,
 
984
                            opt->palette.brush(QPalette::Button));
 
985
            }
 
986
 
 
987
            if(!menuitem->icon.isNull()) {              // draw icon
 
988
                QIcon::Mode mode = QIcon::Normal; // no disabled icons in Motif
 
989
                if ((opt->state & State_Selected) && !!(opt->state & State_Enabled))
 
990
                    mode = QIcon::Active;
 
991
                QPixmap pixmap;
 
992
                if (menuitem->checkType != QStyleOptionMenuItem::NotCheckable && menuitem->checked)
 
993
                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
 
994
                else
 
995
                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
 
996
 
 
997
                int pixw = pixmap.width();
 
998
                int pixh = pixmap.height();
 
999
                QRect pmr(0, 0, pixw, pixh);
 
1000
                pmr.moveCenter(vrect.center());
 
1001
                p->setPen(opt->palette.text().color());
 
1002
                p->drawPixmap(pmr.topLeft(), pixmap);
 
1003
 
 
1004
            } else  if (menuitem->checkType != QStyleOptionMenuItem::NotCheckable) {  // just "checking"...
 
1005
                int mw = maxpmw;
 
1006
                int mh = h - 2*motifItemFrame;
 
1007
                if (menuitem->checked) {
 
1008
                    QStyleOptionMenuItem newMenuItem = *menuitem;
 
1009
                    newMenuItem.state = State_None;
 
1010
                    if ((opt->state & State_Enabled))
 
1011
                        newMenuItem.state |= State_Enabled;
 
1012
                    if ((opt->state & State_Selected))
 
1013
                        newMenuItem.state |= State_On;
 
1014
                    newMenuItem.rect = QRect(xvis, y+motifItemFrame, mw, mh);
 
1015
                    drawPrimitive(PE_IndicatorMenuCheckMark, &newMenuItem, p, widget);
 
1016
                }
 
1017
            }
 
1018
 
 
1019
            p->setPen(opt->palette.buttonText().color());
 
1020
 
 
1021
            QColor discol;
 
1022
            if (!(opt->state & State_Enabled)) {
 
1023
                discol = opt->palette.text().color();
 
1024
                p->setPen(discol);
 
1025
            }
 
1026
 
 
1027
            int xm = motifItemFrame + maxpmw + motifItemHMargin;
 
1028
 
 
1029
            vrect = visualRect(opt->direction, opt->rect,
 
1030
                               QRect(x+xm, y+motifItemVMargin, w-xm-menuitem->tabWidth,
 
1031
                                     h-2*motifItemVMargin));
 
1032
            xvis = vrect.x();
 
1033
 
 
1034
            QString s = menuitem->text;
 
1035
            if (!s.isNull()) {                        // draw text
 
1036
                int t = s.indexOf('\t');
 
1037
                int m = motifItemVMargin;
 
1038
                int text_flags = Qt::AlignVCenter|Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
 
1039
                text_flags |= Qt::AlignLeft;
 
1040
                if (t >= 0) {                         // draw tab text
 
1041
                    QRect vr = visualRect(opt->direction, opt->rect,
 
1042
                                          QRect(x+w-menuitem->tabWidth-motifItemHMargin-motifItemFrame,
 
1043
                                                y+motifItemVMargin, menuitem->tabWidth,
 
1044
                                                h-2*motifItemVMargin));
 
1045
                    int xv = vr.x();
 
1046
                    QRect tr(xv, y+m, menuitem->tabWidth, h-2*m);
 
1047
                    p->drawText(tr, text_flags, s.mid(t+1));
 
1048
                    if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
1049
                        p->fillRect(tr, QBrush(p->background().color(), Qt::Dense5Pattern));
 
1050
                    s = s.left(t);
 
1051
                }
 
1052
                QRect tr(xvis, y+m, w - xm - menuitem->tabWidth + 1, h-2*m);
 
1053
                p->drawText(tr, text_flags, s.left(t));
 
1054
                if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
1055
                    p->fillRect(tr, QBrush(p->background().color(), Qt::Dense5Pattern));
 
1056
            }
 
1057
            if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {           // draw sub menu arrow
 
1058
                int dim = (h-2*motifItemFrame) / 2;
 
1059
                QStyle::PrimitiveElement arrow = (QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight);
 
1060
                QStyleOption arrowOpt = *opt;
 
1061
                arrowOpt.rect = visualRect(opt->direction, opt->rect,
 
1062
                                           QRect(x+w - motifArrowHMargin - motifItemFrame - dim,
 
1063
                                                 y+h/2-dim/2, dim, dim));
 
1064
                if ((opt->state & State_Selected))
 
1065
                    arrowOpt.state = (State_Sunken | ((opt->state & State_Enabled) ? State_Enabled : State_None));
 
1066
                else
 
1067
                    arrowOpt.state = ((opt->state & State_Enabled) ? State_Enabled : State_None);
 
1068
                drawPrimitive(arrow, &arrowOpt, p, widget);
 
1069
            }
 
1070
            break; }
 
1071
 
 
1072
    case CE_MenuBarItem:
 
1073
        if (opt->state & State_Selected)  // active item
 
1074
            qDrawShadePanel(p, opt->rect, opt->palette, false, motifItemFrame,
 
1075
                            &opt->palette.brush(QPalette::Button));
 
1076
        else  // other item
 
1077
            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
 
1078
        QCommonStyle::drawControl(element, opt, p, widget);
 
1079
        break;
 
1080
 
 
1081
    case CE_HeaderSection:
 
1082
        p->save();
 
1083
        p->setBrushOrigin(opt->rect.topLeft());
 
1084
        qDrawShadePanel(p, opt->rect, opt->palette, bool(opt->state & (State_Sunken|State_On)),
 
1085
                        pixelMetric(PM_DefaultFrameWidth),
 
1086
                        &opt->palette.brush((opt->state & State_Sunken) ? QPalette::Mid : QPalette::Button));
 
1087
        p->restore();
 
1088
        break;
 
1089
    case CE_RubberBand: {
 
1090
        p->save();
 
1091
        p->setClipping(false);
 
1092
        QPainterPath path;
 
1093
        path.addRect(opt->rect);
 
1094
        path.addRect(opt->rect.adjusted(4, 4, -4, -4));
 
1095
 
 
1096
        p->fillPath(path, opt->palette.base());
 
1097
        p->fillPath(path, QBrush(opt->palette.foreground().color(), Qt::Dense4Pattern));
 
1098
        p->restore();
 
1099
        }
 
1100
        break;
 
1101
    default:
 
1102
        QCommonStyle::drawControl(element, opt, p, widget);
 
1103
        break; }
 
1104
}
 
1105
 
 
1106
static int get_combo_extra_width(int h, int w, int *return_awh=0)
 
1107
{
 
1108
    int awh,
 
1109
        tmp;
 
1110
    if (h < 8) {
 
1111
        awh = 6;
 
1112
    } else if (h < 14) {
 
1113
        awh = h - 2;
 
1114
    } else {
 
1115
        awh = h/2;
 
1116
    }
 
1117
    tmp = (awh * 3) / 2;
 
1118
    if (tmp > w / 2) {
 
1119
        awh = w / 2 - 3;
 
1120
        tmp = w / 2 + 3;
 
1121
    }
 
1122
 
 
1123
    if (return_awh)
 
1124
        *return_awh = awh;
 
1125
 
 
1126
    return tmp;
 
1127
}
 
1128
 
 
1129
static void get_combo_parameters(const QRect &r,
 
1130
                                 int &ew, int &awh, int &ax,
 
1131
                                 int &ay, int &sh, int &dh,
 
1132
                                 int &sy)
 
1133
{
 
1134
    ew = get_combo_extra_width(r.height(), r.width(), &awh);
 
1135
 
 
1136
    sh = (awh+3)/4;
 
1137
    if (sh < 3)
 
1138
        sh = 3;
 
1139
    dh = sh/2 + 1;
 
1140
 
 
1141
    ay = r.y() + (r.height()-awh-sh-dh)/2;
 
1142
    if (ay < 0) {
 
1143
        //panic mode
 
1144
        ay = 0;
 
1145
        sy = r.height();
 
1146
    } else {
 
1147
        sy = ay+awh+dh;
 
1148
    }
 
1149
    ax = r.x() + r.width() - ew;
 
1150
    ax  += (ew-awh)/2;
 
1151
}
 
1152
 
 
1153
/*!
 
1154
  \reimp
 
1155
*/
 
1156
void QMotifStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
 
1157
                                     const QWidget *widget) const
 
1158
{
 
1159
    switch (cc) {
 
1160
    case CC_ToolButton:
 
1161
        if (const QStyleOptionToolButton *toolbutton
 
1162
            = qstyleoption_cast<const QStyleOptionToolButton *>(opt)) {
 
1163
            QRect button, menuarea;
 
1164
            button = subControlRect(cc, toolbutton, SC_ToolButton, widget);
 
1165
            menuarea = subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
 
1166
 
 
1167
            State bflags = toolbutton->state;
 
1168
 
 
1169
            if (bflags & State_AutoRaise) {
 
1170
                if (!(bflags & State_MouseOver)) {
 
1171
                    bflags &= ~State_Raised;
 
1172
                }
 
1173
            }
 
1174
            State mflags = bflags;
 
1175
 
 
1176
            if (toolbutton->activeSubControls & SC_ToolButton)
 
1177
                bflags |= State_Sunken;
 
1178
            if (toolbutton->activeSubControls & SC_ToolButtonMenu)
 
1179
                mflags |= State_Sunken;
 
1180
 
 
1181
            QStyleOption tool(0);
 
1182
            tool.palette = toolbutton->palette;
 
1183
            if (toolbutton->subControls & SC_ToolButton) {
 
1184
                if (bflags & (State_Sunken | State_On | State_Raised)) {
 
1185
                    tool.rect = button;
 
1186
                    tool.state = bflags;
 
1187
                    drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
 
1188
                }
 
1189
            }
 
1190
 
 
1191
            if (toolbutton->subControls & SC_ToolButtonMenu) {
 
1192
                tool.rect = menuarea;
 
1193
                tool.state = mflags;
 
1194
                if (mflags & (State_Sunken | State_On | State_Raised))
 
1195
                    drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
 
1196
                drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
 
1197
            }
 
1198
 
 
1199
            if ((toolbutton->state & State_HasFocus) && (!focus || !focus->isVisible())) {
 
1200
                QStyleOptionFocusRect fr;
 
1201
                fr.QStyleOption::operator=(*toolbutton);
 
1202
                fr.rect = toolbutton->rect.adjusted(3, 3, -3, -3);
 
1203
                drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
 
1204
            }
 
1205
            QStyleOptionToolButton label = *toolbutton;
 
1206
            int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
 
1207
            label.rect = button.adjusted(fw, fw, -fw, -fw);
 
1208
            drawControl(CE_ToolButtonLabel, &label, p, widget);
 
1209
        }
 
1210
        break;
 
1211
    case CC_SpinBox:
 
1212
        if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
 
1213
            QStyleOptionSpinBox copy = *spinbox;
 
1214
            PrimitiveElement pe;
 
1215
 
 
1216
            if (spinbox->frame && (spinbox->subControls & SC_SpinBoxFrame)) {
 
1217
                QRect r = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxFrame, widget);
 
1218
                qDrawShadePanel(p, r, opt->palette, false, pixelMetric(PM_SpinBoxFrameWidth));
 
1219
 
 
1220
                int fw = pixelMetric(QStyle::PM_DefaultFrameWidth);
 
1221
                r = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxEditField, widget).adjusted(-fw,-fw,fw,fw);
 
1222
                QStyleOptionFrame lineOpt;
 
1223
                lineOpt.QStyleOption::operator=(*opt);
 
1224
                lineOpt.rect = r;
 
1225
                lineOpt.lineWidth = fw;
 
1226
                lineOpt.midLineWidth = 0;
 
1227
                lineOpt.state |= QStyle::State_Sunken;
 
1228
                drawPrimitive(QStyle::PE_FrameLineEdit, &lineOpt, p, widget);
 
1229
            }
 
1230
 
 
1231
            if (spinbox->subControls & SC_SpinBoxUp) {
 
1232
                copy.subControls = SC_SpinBoxUp;
 
1233
                QPalette pal2 = spinbox->palette;
 
1234
                if (!(spinbox->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
 
1235
                    pal2.setCurrentColorGroup(QPalette::Disabled);
 
1236
                    copy.state &= ~State_Enabled;
 
1237
                }
 
1238
 
 
1239
                copy.palette = pal2;
 
1240
 
 
1241
                if (spinbox->activeSubControls == SC_SpinBoxUp && (spinbox->state & State_Sunken)) {
 
1242
                    copy.state |= State_On;
 
1243
                    copy.state |= State_Sunken;
 
1244
                } else {
 
1245
                    copy.state |= State_Raised;
 
1246
                    copy.state &= ~State_Sunken;
 
1247
                }
 
1248
                pe = (spinbox->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
 
1249
                      : PE_IndicatorSpinUp);
 
1250
 
 
1251
                copy.rect = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxUp, widget);
 
1252
                drawPrimitive(pe, &copy, p, widget);
 
1253
            }
 
1254
 
 
1255
            if (spinbox->subControls & SC_SpinBoxDown) {
 
1256
                copy.subControls = SC_SpinBoxDown;
 
1257
                copy.state = spinbox->state;
 
1258
                QPalette pal2 = spinbox->palette;
 
1259
                if (!(spinbox->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
 
1260
                    pal2.setCurrentColorGroup(QPalette::Disabled);
 
1261
                    copy.state &= ~State_Enabled;
 
1262
                }
 
1263
                copy.palette = pal2;
 
1264
 
 
1265
                if (spinbox->activeSubControls == SC_SpinBoxDown && (spinbox->state & State_Sunken)) {
 
1266
                    copy.state |= State_On;
 
1267
                    copy.state |= State_Sunken;
 
1268
                } else {
 
1269
                    copy.state |= State_Raised;
 
1270
                    copy.state &= ~State_Sunken;
 
1271
                }
 
1272
                pe = (spinbox->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
 
1273
                      : PE_IndicatorSpinDown);
 
1274
 
 
1275
                copy.rect = subControlRect(CC_SpinBox, spinbox, SC_SpinBoxDown, widget);
 
1276
                drawPrimitive(pe, &copy, p, widget);
 
1277
            }
 
1278
        }
 
1279
        break;
 
1280
 
 
1281
    case CC_Slider:
 
1282
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1283
            QRect groove = subControlRect(CC_Slider, opt, SC_SliderGroove, widget),
 
1284
                  handle = subControlRect(CC_Slider, opt, SC_SliderHandle, widget);
 
1285
 
 
1286
            if ((opt->subControls & SC_SliderGroove) && groove.isValid()) {
 
1287
                qDrawShadePanel(p, groove, opt->palette, true, pixelMetric(PM_DefaultFrameWidth),
 
1288
                                &opt->palette.brush((opt->state & State_Enabled) ? QPalette::Mid : QPalette::Background));
 
1289
                if ((opt->state & State_HasFocus) && (!focus || !focus->isVisible())) {
 
1290
                    QStyleOption focusOpt = *opt;
 
1291
                    focusOpt.rect = subElementRect(SE_SliderFocusRect, opt, widget);
 
1292
                    drawPrimitive(PE_FrameFocusRect, &focusOpt, p, widget);
 
1293
                }
 
1294
            }
 
1295
 
 
1296
            if ((opt->subControls & SC_SliderHandle) && handle.isValid()) {
 
1297
                QStyleOption bevelOpt = *opt;
 
1298
                bevelOpt.state = (opt->state | State_Raised) & ~State_Sunken;
 
1299
                bevelOpt.rect = handle;
 
1300
                p->save();
 
1301
                p->setBrushOrigin(bevelOpt.rect.topLeft());
 
1302
                drawPrimitive(PE_PanelButtonBevel, &bevelOpt, p, widget);
 
1303
                p->restore();
 
1304
 
 
1305
                if (slider->orientation == Qt::Horizontal) {
 
1306
                    int mid = handle.x() + handle.width() / 2;
 
1307
                    qDrawShadeLine(p, mid, handle.y(), mid, handle.y() + handle.height() - 2,
 
1308
                                   opt->palette, true, 1);
 
1309
                } else {
 
1310
                    int mid = handle.y() + handle.height() / 2;
 
1311
                    qDrawShadeLine(p, handle.x(), mid, handle.x() + handle.width() - 2, mid, opt->palette,
 
1312
                                   true, 1);
 
1313
                }
 
1314
                if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
1315
                    p->fillRect(handle, QBrush(p->background().color(), Qt::Dense5Pattern));
 
1316
            }
 
1317
 
 
1318
            if (opt->subControls & SC_SliderTickmarks) {
 
1319
                QStyleOptionComplex tickOpt = *opt;
 
1320
                tickOpt.subControls = SC_SliderTickmarks;
 
1321
                QCommonStyle::drawComplexControl(cc, &tickOpt, p, widget);
 
1322
            }
 
1323
        }
 
1324
        break;
 
1325
 
 
1326
    case CC_ComboBox:
 
1327
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
 
1328
            if (opt->subControls & SC_ComboBoxArrow) {
 
1329
                int awh, ax, ay, sh, sy, dh, ew;
 
1330
                int fw = cb->frame ? pixelMetric(PM_ComboBoxFrameWidth, opt, widget) : 0;
 
1331
 
 
1332
                if (cb->frame) {
 
1333
                    QStyleOptionButton btn;
 
1334
                    btn.QStyleOption::operator=(*cb);
 
1335
                    btn.state |= QStyle::State_Raised;
 
1336
                    drawPrimitive(PE_PanelButtonCommand, &btn, p, widget);
 
1337
                } else {
 
1338
                    p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
 
1339
                }
 
1340
 
 
1341
                QRect tr = opt->rect;
 
1342
                tr.adjust(fw, fw, -fw, -fw);
 
1343
                get_combo_parameters(tr, ew, awh, ax, ay, sh, dh, sy);
 
1344
 
 
1345
                QRect ar = QStyle::visualRect(opt->direction, opt->rect, QRect(ax,ay,awh,awh));
 
1346
 
 
1347
                QStyleOption arrowOpt = *opt;
 
1348
                arrowOpt.rect = ar;
 
1349
                arrowOpt.state |= State_Enabled;
 
1350
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
 
1351
 
 
1352
 
 
1353
                // draws the shaded line under the arrow
 
1354
                p->setPen(opt->palette.light().color());
 
1355
                p->drawLine(ar.x(), sy, ar.x()+awh-1, sy);
 
1356
                p->drawLine(ar.x(), sy, ar.x(), sy+sh-1);
 
1357
                p->setPen(opt->palette.dark().color());
 
1358
                p->drawLine(ar.x()+1, sy+sh-1, ar.x()+awh-1, sy+sh-1);
 
1359
                p->drawLine(ar.x()+awh-1, sy+1, ar.x()+awh-1, sy+sh-1);
 
1360
 
 
1361
                if ((cb->state & State_HasFocus) && (!focus || !focus->isVisible())) {
 
1362
                    QStyleOptionFocusRect focus;
 
1363
                    focus.QStyleOption::operator=(*opt);
 
1364
                    focus.rect = subElementRect(SE_ComboBoxFocusRect, opt, widget);
 
1365
                    focus.backgroundColor = opt->palette.button().color();
 
1366
                    drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
 
1367
                }
 
1368
            }
 
1369
 
 
1370
            if (opt->subControls & SC_ComboBoxEditField) {
 
1371
                if (cb->editable) {
 
1372
                    QRect er = subControlRect(CC_ComboBox, opt, SC_ComboBoxEditField, widget);
 
1373
                    er.adjust(-1, -1, 1, 1);
 
1374
                    qDrawShadePanel(p, er, opt->palette, true, 1,
 
1375
                                    &opt->palette.brush(QPalette::Base));
 
1376
                }
 
1377
            }
 
1378
            p->setPen(opt->palette.buttonText().color());
 
1379
        }
 
1380
        break;
 
1381
 
 
1382
    case CC_ScrollBar: {
 
1383
        if (opt->subControls & SC_ScrollBarGroove)
 
1384
            qDrawShadePanel(p, opt->rect, opt->palette, true,
 
1385
                            pixelMetric(PM_DefaultFrameWidth, opt, widget),
 
1386
                            &opt->palette.brush((opt->state & State_Enabled) ? QPalette::Mid : QPalette::Background));
 
1387
 
 
1388
        QCommonStyle::drawComplexControl(cc, opt, p, widget);
 
1389
        break; }
 
1390
 
 
1391
 
 
1392
    case CC_Q3ListView:
 
1393
        if (opt->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand)) {
 
1394
            int i;
 
1395
            if (opt->subControls & SC_Q3ListView)
 
1396
                QCommonStyle::drawComplexControl(cc, opt, p, widget);
 
1397
            if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
1398
                QStyleOptionQ3ListViewItem item = lv->items.at(0);
 
1399
                int y = opt->rect.y();
 
1400
                int c;
 
1401
                QPolygon dotlines;
 
1402
                if ((opt->activeSubControls & SC_All) && (opt->subControls & SC_Q3ListViewExpand)) {
 
1403
                    c = 2;
 
1404
                    dotlines.resize(2);
 
1405
                    dotlines[0] = QPoint(opt->rect.right(), opt->rect.top());
 
1406
                    dotlines[1] = QPoint(opt->rect.right(), opt->rect.bottom());
 
1407
                } else {
 
1408
                    int linetop = 0, linebot = 0;
 
1409
                    // each branch needs at most two lines, ie. four end points
 
1410
                    dotlines.resize(item.childCount * 4);
 
1411
                    c = 0;
 
1412
 
 
1413
                    // skip the stuff above the exposed rectangle
 
1414
                    for (i = 1; i < lv->items.size(); ++i) {
 
1415
                        QStyleOptionQ3ListViewItem child = lv->items.at(i);
 
1416
                        if (child.height + y > 0)
 
1417
                            break;
 
1418
                        y += child.totalHeight;
 
1419
                    }
 
1420
 
 
1421
                    int bx = opt->rect.width() / 2;
 
1422
 
 
1423
                    // paint stuff in the magical area
 
1424
                    while (i < lv->items.size() && y < lv->rect.height()) {
 
1425
                        QStyleOptionQ3ListViewItem child = lv->items.at(i);
 
1426
                        if (child.features & QStyleOptionQ3ListViewItem::Visible) {
 
1427
                            int lh;
 
1428
                            if (!(item.features & QStyleOptionQ3ListViewItem::MultiLine))
 
1429
                                lh = child.height;
 
1430
                            else
 
1431
                                lh = p->fontMetrics().height() + 2 * lv->itemMargin;
 
1432
                            lh = qMax(lh, QApplication::globalStrut().height());
 
1433
                            if (lh % 2 > 0)
 
1434
                                lh++;
 
1435
                            linebot = y + lh/2;
 
1436
                            if ((child.features & QStyleOptionQ3ListViewItem::Expandable || child.childCount > 0) &&
 
1437
                                child.height > 0) {
 
1438
                                // needs a box
 
1439
                                p->setPen(opt->palette.text().color());
 
1440
                                p->drawRect(bx-4, linebot-4, 9, 9);
 
1441
                                QPolygon a;
 
1442
                                if ((child.state & State_Open))
 
1443
                                    a.setPoints(3, bx-2, linebot-2,
 
1444
                                                bx, linebot+2,
 
1445
                                                bx+2, linebot-2); //Qt::RightArrow
 
1446
                                else
 
1447
                                    a.setPoints(3, bx-2, linebot-2,
 
1448
                                                bx+2, linebot,
 
1449
                                                bx-2, linebot+2); //Qt::DownArrow
 
1450
                                p->setBrush(opt->palette.text());
 
1451
                                p->drawPolygon(a);
 
1452
                                p->setBrush(Qt::NoBrush);
 
1453
                                // dotlinery
 
1454
                                dotlines[c++] = QPoint(bx, linetop);
 
1455
                                dotlines[c++] = QPoint(bx, linebot - 5);
 
1456
                                dotlines[c++] = QPoint(bx + 5, linebot);
 
1457
                                dotlines[c++] = QPoint(opt->rect.width(), linebot);
 
1458
                                linetop = linebot + 5;
 
1459
                            } else {
 
1460
                                // just dotlinery
 
1461
                                dotlines[c++] = QPoint(bx+1, linebot);
 
1462
                                dotlines[c++] = QPoint(opt->rect.width(), linebot);
 
1463
                            }
 
1464
                            y += child.totalHeight;
 
1465
                        }
 
1466
                        ++i;
 
1467
                    }
 
1468
 
 
1469
                    // Expand line height to edge of rectangle if there's any
 
1470
                    // visible child below
 
1471
                    while (i < lv->items.size() && lv->items.at(i).height <= 0)
 
1472
                        ++i;
 
1473
                    if (i < lv->items.size())
 
1474
                        linebot = opt->rect.height();
 
1475
 
 
1476
                    if (linetop < linebot) {
 
1477
                        dotlines[c++] = QPoint(bx, linetop);
 
1478
                        dotlines[c++] = QPoint(bx, linebot);
 
1479
                    }
 
1480
                }
 
1481
 
 
1482
                int line; // index into dotlines
 
1483
                p->setPen(opt->palette.text().color());
 
1484
                if (opt->subControls & SC_Q3ListViewBranch) for(line = 0; line < c; line += 2) {
 
1485
                    p->drawLine(dotlines[line].x(), dotlines[line].y(),
 
1486
                                dotlines[line+1].x(), dotlines[line+1].y());
 
1487
                }
 
1488
            }
 
1489
            break; }
 
1490
 
 
1491
    default:
 
1492
        QCommonStyle::drawComplexControl(cc, opt, p, widget);
 
1493
        break;
 
1494
    }
 
1495
}
 
1496
 
 
1497
 
 
1498
/*! \reimp */
 
1499
int QMotifStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt,
 
1500
                             const QWidget *widget) const
 
1501
{
 
1502
    int ret = 0;
 
1503
 
 
1504
    switch(pm) {
 
1505
    case PM_ButtonDefaultIndicator:
 
1506
        ret = 5;
 
1507
        break;
 
1508
 
 
1509
    case PM_ToolBarFrameWidth:
 
1510
        ret = pixelMetric(PM_DefaultFrameWidth);
 
1511
        break;
 
1512
 
 
1513
    case PM_ToolBarItemMargin:
 
1514
        ret = 1;
 
1515
        break;
 
1516
 
 
1517
    case PM_ButtonShiftHorizontal:
 
1518
    case PM_ButtonShiftVertical:
 
1519
        ret = 0;
 
1520
        break;
 
1521
 
 
1522
    case PM_SplitterWidth:
 
1523
        ret = qMax(10, QApplication::globalStrut().width());
 
1524
        break;
 
1525
 
 
1526
    case PM_SliderLength:
 
1527
        ret = 30;
 
1528
        break;
 
1529
 
 
1530
    case PM_SliderThickness:
 
1531
        ret = 16 + 4 * pixelMetric(PM_DefaultFrameWidth);
 
1532
        break;
 
1533
 
 
1534
    case PM_SliderControlThickness:
 
1535
        if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1536
            int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
 
1537
            int ticks = sl->tickPosition;
 
1538
            int n = 0;
 
1539
            if (ticks & QSlider::TicksAbove)
 
1540
                n++;
 
1541
            if (ticks & QSlider::TicksBelow)
 
1542
                n++;
 
1543
            if (!n) {
 
1544
                ret = space;
 
1545
                break;
 
1546
            }
 
1547
 
 
1548
            int thick = 6;        // Magic constant to get 5 + 16 + 5
 
1549
 
 
1550
            space -= thick;
 
1551
            //### the two sides may be unequal in size
 
1552
            if (space > 0)
 
1553
                thick += (space * 2) / (n + 2);
 
1554
            ret = thick;
 
1555
        }
 
1556
        break;
 
1557
 
 
1558
    case PM_SliderSpaceAvailable:
 
1559
        if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1560
            if (sl->orientation == Qt::Horizontal)
 
1561
                ret = sl->rect.width() - pixelMetric(PM_SliderLength, opt, widget) - 6;
 
1562
            else
 
1563
                ret = sl->rect.height() - pixelMetric(PM_SliderLength, opt, widget) - 6;
 
1564
        }
 
1565
        break;
 
1566
 
 
1567
    case PM_DockWidgetFrameWidth:
 
1568
        ret = 2;
 
1569
        break;
 
1570
 
 
1571
    case PM_DockWidgetHandleExtent:
 
1572
        ret = 9;
 
1573
        break;
 
1574
 
 
1575
    case PM_ProgressBarChunkWidth:
 
1576
        ret = 1;
 
1577
        break;
 
1578
 
 
1579
    case PM_ExclusiveIndicatorWidth:
 
1580
    case PM_ExclusiveIndicatorHeight:
 
1581
        ret = 13;
 
1582
        break;
 
1583
 
 
1584
    case PM_MenuBarHMargin:
 
1585
        ret = 2; // really ugly, but Motif
 
1586
        break;
 
1587
 
 
1588
    default:
 
1589
        ret =  QCommonStyle::pixelMetric(pm, opt, widget);
 
1590
        break;
 
1591
    }
 
1592
    return ret;
 
1593
}
 
1594
 
 
1595
 
 
1596
/*!
 
1597
  \reimp
 
1598
*/
 
1599
QRect
 
1600
QMotifStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
 
1601
                            SubControl sc, const QWidget *widget) const
 
1602
{
 
1603
    switch (cc) {
 
1604
    case CC_SpinBox:
 
1605
        if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
 
1606
            int fw = spinbox->frame ? pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
 
1607
            QSize bs;
 
1608
            bs.setHeight(opt->rect.height()/2 - fw);
 
1609
            bs.setWidth(qMin(bs.height() * 8 / 5, opt->rect.width() / 4)); // 1.6 -approximate golden mean
 
1610
            bs = bs.expandedTo(QApplication::globalStrut());
 
1611
            int y = fw;
 
1612
            int x, lx, rx;
 
1613
            x = opt->rect.width() - y - bs.width();
 
1614
            lx = fw;
 
1615
            rx = x - fw * 2;
 
1616
            const int margin = spinbox->frame ? 4 : 0;
 
1617
            switch (sc) {
 
1618
            case SC_SpinBoxUp:
 
1619
                return visualRect(spinbox->direction, spinbox->rect,
 
1620
                                  QRect(x, y, bs.width(), bs.height() - 1));
 
1621
            case SC_SpinBoxDown:
 
1622
                return visualRect(spinbox->direction, spinbox->rect,
 
1623
                                  QRect(x, y + bs.height() + 1, bs.width(), bs.height() - 1));
 
1624
            case SC_SpinBoxEditField:
 
1625
                return visualRect(spinbox->direction, spinbox->rect,
 
1626
                                  QRect(lx + margin, fw + margin, rx - margin,
 
1627
                                        spinbox->rect.height() - 2*fw - 2 * margin));
 
1628
            case SC_SpinBoxFrame:
 
1629
                return visualRect(spinbox->direction, spinbox->rect, spinbox->rect);
 
1630
            default:
 
1631
                break;
 
1632
            }
 
1633
            break; }
 
1634
 
 
1635
    case CC_Slider:
 
1636
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1637
            if (sc == SC_SliderHandle) {
 
1638
                int tickOffset = pixelMetric(PM_SliderTickmarkOffset, opt, widget);
 
1639
                int thickness = pixelMetric(PM_SliderControlThickness, opt, widget);
 
1640
                bool horizontal = slider->orientation == Qt::Horizontal;
 
1641
                int len = pixelMetric(PM_SliderLength, opt, widget);
 
1642
                int motifBorder = pixelMetric(PM_DefaultFrameWidth);
 
1643
                int sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum, slider->sliderPosition,
 
1644
                                                        horizontal ? slider->rect.width() - len - 2 * motifBorder
 
1645
                                                        : slider->rect.height() - len - 2 * motifBorder,
 
1646
                                                        slider->upsideDown);
 
1647
                if (horizontal)
 
1648
                    return visualRect(slider->direction, slider->rect,
 
1649
                                      QRect(sliderPos + motifBorder, tickOffset + motifBorder, len,
 
1650
                                            thickness - 2 * motifBorder));
 
1651
                return visualRect(slider->direction, slider->rect,
 
1652
                                  QRect(tickOffset + motifBorder, sliderPos + motifBorder,
 
1653
                                        thickness - 2 * motifBorder, len));
 
1654
            }
 
1655
        }
 
1656
        break;
 
1657
 
 
1658
    case CC_ScrollBar:
 
1659
        if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1660
            int dfw = pixelMetric(PM_DefaultFrameWidth);
 
1661
            QRect rect =  visualRect(scrollbar->direction, scrollbar->rect,
 
1662
                                     QCommonStyle::subControlRect(cc, scrollbar, sc, widget));
 
1663
            if (sc == SC_ScrollBarSlider) {
 
1664
                if (scrollbar->orientation == Qt::Horizontal)
 
1665
                    rect.adjust(-dfw, dfw, dfw, -dfw);
 
1666
                else
 
1667
                    rect.adjust(dfw, -dfw, -dfw, dfw);
 
1668
            } else if (sc != SC_ScrollBarGroove)
 
1669
                if (scrollbar->orientation == Qt::Horizontal)
 
1670
                    rect.adjust(0, dfw, 0, -dfw);
 
1671
                else
 
1672
                    rect.adjust(dfw, 0, -dfw, 0);
 
1673
            return visualRect(scrollbar->direction, scrollbar->rect, rect);
 
1674
        }
 
1675
        break;
 
1676
 
 
1677
    case CC_ComboBox:
 
1678
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
 
1679
            switch (sc) {
 
1680
            case SC_ComboBoxArrow: {
 
1681
                int ew, awh, sh, dh, ax, ay, sy;
 
1682
                int fw = cb->frame ? pixelMetric(PM_ComboBoxFrameWidth, opt, widget) : 0;
 
1683
                QRect cr = opt->rect;
 
1684
                cr.adjust(fw, fw, -fw, -fw);
 
1685
                get_combo_parameters(cr, ew, awh, ax, ay, sh, dh, sy);
 
1686
                return visualRect(cb->direction, cb->rect, QRect(QPoint(ax, ay), cr.bottomRight()));
 
1687
            }
 
1688
 
 
1689
            case SC_ComboBoxEditField: {
 
1690
                int fw = cb->frame ? pixelMetric(PM_ComboBoxFrameWidth, opt, widget) : 0;
 
1691
                QRect rect = opt->rect;
 
1692
                rect.adjust(fw, fw, -fw, -fw);
 
1693
                int ew = get_combo_extra_width(rect.height(), rect.width());
 
1694
                rect.adjust(1, 1, -1-ew, -1);
 
1695
                return visualRect(cb->direction, cb->rect, rect);
 
1696
            }
 
1697
 
 
1698
            default:
 
1699
                break;
 
1700
            }
 
1701
        }
 
1702
        break;
 
1703
    default:
 
1704
        break;
 
1705
    }
 
1706
    return QCommonStyle::subControlRect(cc, opt, sc, widget);
 
1707
}
 
1708
 
 
1709
/*!
 
1710
  \reimp
 
1711
*/
 
1712
QSize
 
1713
QMotifStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
 
1714
                              const QSize &contentsSize, const QWidget *widget) const
 
1715
{
 
1716
    QSize sz(contentsSize);
 
1717
 
 
1718
    switch(ct) {
 
1719
    case CT_Splitter:
 
1720
        sz = QSize(10, 10);
 
1721
        break;
 
1722
 
 
1723
    case CT_RadioButton:
 
1724
    case CT_CheckBox:
 
1725
        sz = QCommonStyle::sizeFromContents(ct, opt, contentsSize, widget);
 
1726
        sz.rwidth() += motifItemFrame;
 
1727
        break;
 
1728
 
 
1729
    case CT_PushButton:
 
1730
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
1731
            sz = QCommonStyle::sizeFromContents(ct, opt, contentsSize, widget);
 
1732
            if (!btn->text.isEmpty() && (btn->features & (QStyleOptionButton::AutoDefaultButton|QStyleOptionButton::DefaultButton)))
 
1733
                sz.setWidth(qMax(75, sz.width()));
 
1734
            sz += QSize(0, 1); // magical extra pixel
 
1735
        }
 
1736
        break;
 
1737
 
 
1738
    case CT_MenuBarItem: {
 
1739
        if(!sz.isEmpty())
 
1740
            sz += QSize(5*motifItemHMargin+1, 2*motifItemVMargin + motifItemFrame);
 
1741
        break; }
 
1742
 
 
1743
    case CT_MenuItem:
 
1744
        if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
 
1745
            sz = QCommonStyle::sizeFromContents(ct, opt, sz, widget);
 
1746
            int w = sz.width(), h = sz.height();
 
1747
 
 
1748
            if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
 
1749
                w = 10;
 
1750
                h = motifSepHeight;
 
1751
            }
 
1752
 
 
1753
            // a little bit of border can never harm
 
1754
            w += 2*motifItemHMargin + 2*motifItemFrame;
 
1755
 
 
1756
            if (!mi->text.isNull() && mi->text.indexOf('\t') >= 0)
 
1757
                // string contains tab
 
1758
                w += motifTabSpacing;
 
1759
            else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
 
1760
                // submenu indicator needs some room if we don't have a tab column
 
1761
                w += motifArrowHMargin + 4*motifItemFrame;
 
1762
 
 
1763
            int checkColumn = mi->maxIconWidth;
 
1764
            if (mi->menuHasCheckableItems)
 
1765
                checkColumn = qMax(checkColumn, motifCheckMarkSpace);
 
1766
            if (checkColumn > 0)
 
1767
                w += checkColumn + motifCheckMarkHMargin;
 
1768
 
 
1769
            sz = QSize(w, h);
 
1770
        }
 
1771
        break;
 
1772
 
 
1773
 
 
1774
    default:
 
1775
        sz = QCommonStyle::sizeFromContents(ct, opt, contentsSize, widget);
 
1776
        break;
 
1777
    }
 
1778
 
 
1779
    return sz;
 
1780
}
 
1781
 
 
1782
/*!
 
1783
  \reimp
 
1784
*/
 
1785
QRect
 
1786
QMotifStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *widget) const
 
1787
{
 
1788
    QRect rect;
 
1789
 
 
1790
    switch (sr) {
 
1791
    case SE_SliderFocusRect:
 
1792
        rect = QCommonStyle::subElementRect(sr, opt, widget);
 
1793
        rect.adjust(2, 2, -2, -2);
 
1794
        break;
 
1795
 
 
1796
    case SE_CheckBoxIndicator:
 
1797
    case SE_RadioButtonIndicator:
 
1798
        {
 
1799
            rect = visualRect(opt->direction, opt->rect,
 
1800
                              QCommonStyle::subElementRect(sr, opt, widget));
 
1801
            rect.adjust(motifItemFrame,0, motifItemFrame,0);
 
1802
            rect = visualRect(opt->direction, opt->rect, rect);
 
1803
        }
 
1804
        break;
 
1805
 
 
1806
    case SE_ComboBoxFocusRect:
 
1807
    {
 
1808
        int awh, ax, ay, sh, sy, dh, ew;
 
1809
        int fw = pixelMetric(PM_DefaultFrameWidth, opt, widget);
 
1810
        QRect tr = opt->rect;
 
1811
 
 
1812
        tr.adjust(fw, fw, -fw, -fw);
 
1813
        get_combo_parameters(tr, ew, awh, ax, ay, sh, dh, sy);
 
1814
        rect.setRect(ax-2, ay-2, awh+4, awh+sh+dh+4);
 
1815
        break;
 
1816
    }
 
1817
 
 
1818
    case SE_Q3DockWindowHandleRect:
 
1819
        if (const QStyleOptionQ3DockWindow *dw = qstyleoption_cast<const QStyleOptionQ3DockWindow *>(opt)) {
 
1820
            if (!dw->docked || !dw->closeEnabled)
 
1821
                rect.setRect(0, 0, opt->rect.width(), opt->rect.height());
 
1822
            else {
 
1823
                if (dw->state == State_Horizontal)
 
1824
                    rect.setRect(2, 15, opt->rect.width()-2, opt->rect.height() - 15);
 
1825
                else
 
1826
                    rect.setRect(0, 2, opt->rect.width() - 15, opt->rect.height() - 2);
 
1827
            }
 
1828
            rect = visualRect(dw->direction, dw->rect, rect);
 
1829
        }
 
1830
        break;
 
1831
 
 
1832
    case SE_ProgressBarLabel:
 
1833
    case SE_ProgressBarGroove:
 
1834
    case SE_ProgressBarContents:
 
1835
        if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
 
1836
            int textw = 0;
 
1837
            if (pb->textVisible)
 
1838
                textw = pb->fontMetrics.width("100%") + 6;
 
1839
 
 
1840
            if (pb->textAlignment == Qt::AlignLeft || pb->textAlignment == Qt::AlignCenter) {
 
1841
                rect = opt->rect;
 
1842
            } else {
 
1843
                if(sr == SE_ProgressBarLabel)
 
1844
                    rect.setCoords(opt->rect.right() - textw, opt->rect.top(),
 
1845
                                   opt->rect.right(), opt->rect.bottom());
 
1846
                else
 
1847
                    rect.setCoords(opt->rect.left(), opt->rect.top(),
 
1848
                                   opt->rect.right() - textw, opt->rect.bottom());
 
1849
            }
 
1850
            rect = visualRect(pb->direction, pb->rect, rect);
 
1851
        }
 
1852
        break;
 
1853
    case SE_CheckBoxContents:
 
1854
    case SE_RadioButtonContents: {
 
1855
        QRect ir = visualRect(opt->direction, opt->rect,
 
1856
                              subElementRect(sr == SE_CheckBoxContents ? SE_CheckBoxIndicator
 
1857
                                                                       : SE_RadioButtonIndicator,
 
1858
                                             opt, widget));
 
1859
        rect.setRect(ir.right() + 10, opt->rect.y(),
 
1860
                     opt->rect.width() - ir.width() - 10, opt->rect.height());
 
1861
        rect = visualRect(opt->direction, opt->rect, rect);
 
1862
        break; }
 
1863
    case SE_CheckBoxClickRect:
 
1864
    case SE_RadioButtonClickRect:
 
1865
        rect = visualRect(opt->direction, opt->rect, opt->rect);
 
1866
        break;
 
1867
 
 
1868
    default:
 
1869
        rect = QCommonStyle::subElementRect(sr, opt, widget);
 
1870
    }
 
1871
    return rect;
 
1872
}
 
1873
 
 
1874
#ifndef QT_NO_IMAGEIO_XPM
 
1875
static const char * const qt_menu_xpm[] = {
 
1876
"16 16 11 1",
 
1877
"  c #000000",
 
1878
", c #336600",
 
1879
". c #99CC00",
 
1880
"X c #666600",
 
1881
"o c #999933",
 
1882
"+ c #333300",
 
1883
"@ c #669900",
 
1884
"# c #999900",
 
1885
"$ c #336633",
 
1886
"% c #666633",
 
1887
"& c #99CC33",
 
1888
"................",
 
1889
"................",
 
1890
".....#,++X#.....",
 
1891
"....X      X....",
 
1892
"...X  Xo#%  X&..",
 
1893
"..#  o..&@o  o..",
 
1894
".., X..#+ @X X..",
 
1895
"..+ o.o+ +o# +..",
 
1896
"..+ #o+  +## +..",
 
1897
".., %@ ++ +, X..",
 
1898
"..#  o@oo+   #..",
 
1899
"...X  X##$   o..",
 
1900
"....X        X..",
 
1901
"....&oX++X#oX...",
 
1902
"................",
 
1903
"................"};
 
1904
 
 
1905
 
 
1906
static const char * const qt_close_xpm[] = {
 
1907
    "12 12 2 1",
 
1908
    "       s None  c None",
 
1909
    ".      c black",
 
1910
    "            ",
 
1911
    "            ",
 
1912
    "   .    .   ",
 
1913
    "  ...  ...  ",
 
1914
    "   ......   ",
 
1915
    "    ....    ",
 
1916
    "    ....    ",
 
1917
    "   ......   ",
 
1918
    "  ...  ...  ",
 
1919
    "   .    .   ",
 
1920
    "            ",
 
1921
    "            "};
 
1922
 
 
1923
static const char * const qt_maximize_xpm[] = {
 
1924
    "12 12 2 1",
 
1925
    "       s None  c None",
 
1926
    ".      c black",
 
1927
    "            ",
 
1928
    "            ",
 
1929
    "            ",
 
1930
    "     .      ",
 
1931
    "    ...     ",
 
1932
    "   .....    ",
 
1933
    "  .......   ",
 
1934
    " .........  ",
 
1935
    "            ",
 
1936
    "            ",
 
1937
    "            ",
 
1938
    "            "};
 
1939
 
 
1940
static const char * const qt_minimize_xpm[] = {
 
1941
    "12 12 2 1",
 
1942
    "       s None  c None",
 
1943
    ".      c black",
 
1944
    "            ",
 
1945
    "            ",
 
1946
    "            ",
 
1947
    "            ",
 
1948
    " .........  ",
 
1949
    "  .......   ",
 
1950
    "   .....    ",
 
1951
    "    ...     ",
 
1952
    "     .      ",
 
1953
    "            ",
 
1954
    "            ",
 
1955
    "            "};
 
1956
 
 
1957
#if 0 // ### not used???
 
1958
static const char * const qt_normalize_xpm[] = {
 
1959
    "12 12 2 1",
 
1960
    "       s None  c None",
 
1961
    ".      c black",
 
1962
    "            ",
 
1963
    "            ",
 
1964
    "  .         ",
 
1965
    "  ..        ",
 
1966
    "  ...       ",
 
1967
    "  ....      ",
 
1968
    "  .....     ",
 
1969
    "  ......    ",
 
1970
    "  .......   ",
 
1971
    "            ",
 
1972
    "            ",
 
1973
    "            "};
 
1974
#endif
 
1975
 
 
1976
static const char * const qt_normalizeup_xpm[] = {
 
1977
    "12 12 2 1",
 
1978
    "       s None  c None",
 
1979
    ".      c black",
 
1980
    "            ",
 
1981
    "            ",
 
1982
    "            ",
 
1983
    "  .......   ",
 
1984
    "   ......   ",
 
1985
    "    .....   ",
 
1986
    "     ....   ",
 
1987
    "      ...   ",
 
1988
    "       ..   ",
 
1989
    "        .   ",
 
1990
    "            ",
 
1991
    "            "};
 
1992
 
 
1993
static const char * const qt_shade_xpm[] = {
 
1994
    "12 12 2 1", "# c #000000",
 
1995
    ". c None",
 
1996
    "............",
 
1997
    "............",
 
1998
    ".#########..",
 
1999
    ".#########..",
 
2000
    "............",
 
2001
    "............",
 
2002
    "............",
 
2003
    "............",
 
2004
    "............",
 
2005
    "............",
 
2006
    "............",
 
2007
    "............"};
 
2008
 
 
2009
 
 
2010
static const char * const qt_unshade_xpm[] = {
 
2011
    "12 12 2 1",
 
2012
    "# c #000000",
 
2013
    ". c None",
 
2014
    "............",
 
2015
    "............",
 
2016
    ".#########..",
 
2017
    ".#########..",
 
2018
    ".#.......#..",
 
2019
    ".#.......#..",
 
2020
    ".#.......#..",
 
2021
    ".#.......#..",
 
2022
    ".#.......#..",
 
2023
    ".#########..",
 
2024
    "............",
 
2025
    "............"};
 
2026
 
 
2027
 
 
2028
static const char * dock_window_close_xpm[] = {
 
2029
    "8 8 2 1",
 
2030
    "# c #000000",
 
2031
    ". c None",
 
2032
    "##....##",
 
2033
    ".##..##.",
 
2034
    "..####..",
 
2035
    "...##...",
 
2036
    "..####..",
 
2037
    ".##..##.",
 
2038
    "##....##",
 
2039
    "........"};
 
2040
 
 
2041
// Message box icons, from page 210 of the Windows style guide.
 
2042
 
 
2043
// Hand-drawn to resemble Microsoft's icons, but in the Mac/Netscape palette.
 
2044
// Thanks to TrueColor displays, it is slightly more efficient to have
 
2045
// them duplicated.
 
2046
/* XPM */
 
2047
static const char * const information_xpm[]={
 
2048
    "32 32 5 1",
 
2049
    ". c None",
 
2050
    "c c #000000",
 
2051
    "* c #999999",
 
2052
    "a c #ffffff",
 
2053
    "b c #0000ff",
 
2054
    "...........********.............",
 
2055
    "........***aaaaaaaa***..........",
 
2056
    "......**aaaaaaaaaaaaaa**........",
 
2057
    ".....*aaaaaaaaaaaaaaaaaa*.......",
 
2058
    "....*aaaaaaaabbbbaaaaaaaac......",
 
2059
    "...*aaaaaaaabbbbbbaaaaaaaac.....",
 
2060
    "..*aaaaaaaaabbbbbbaaaaaaaaac....",
 
2061
    ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
 
2062
    ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
 
2063
    "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
 
2064
    "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
 
2065
    "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
2066
    "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
2067
    "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
2068
    "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
2069
    "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
2070
    ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
 
2071
    ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
 
2072
    "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
 
2073
    "...caaaaaaabbbbbbbbbaaaaaac****.",
 
2074
    "....caaaaaaaaaaaaaaaaaaaac****..",
 
2075
    ".....caaaaaaaaaaaaaaaaaac****...",
 
2076
    "......ccaaaaaaaaaaaaaacc****....",
 
2077
    ".......*cccaaaaaaaaccc*****.....",
 
2078
    "........***cccaaaac*******......",
 
2079
    "..........****caaac*****........",
 
2080
    ".............*caaac**...........",
 
2081
    "...............caac**...........",
 
2082
    "................cac**...........",
 
2083
    ".................cc**...........",
 
2084
    "..................***...........",
 
2085
    "...................**..........."};
 
2086
/* XPM */
 
2087
static const char* const warning_xpm[]={
 
2088
    "32 32 4 1",
 
2089
    ". c None",
 
2090
    "a c #ffff00",
 
2091
    "* c #000000",
 
2092
    "b c #999999",
 
2093
    ".............***................",
 
2094
    "............*aaa*...............",
 
2095
    "...........*aaaaa*b.............",
 
2096
    "...........*aaaaa*bb............",
 
2097
    "..........*aaaaaaa*bb...........",
 
2098
    "..........*aaaaaaa*bb...........",
 
2099
    ".........*aaaaaaaaa*bb..........",
 
2100
    ".........*aaaaaaaaa*bb..........",
 
2101
    "........*aaaaaaaaaaa*bb.........",
 
2102
    "........*aaaa***aaaa*bb.........",
 
2103
    ".......*aaaa*****aaaa*bb........",
 
2104
    ".......*aaaa*****aaaa*bb........",
 
2105
    "......*aaaaa*****aaaaa*bb.......",
 
2106
    "......*aaaaa*****aaaaa*bb.......",
 
2107
    ".....*aaaaaa*****aaaaaa*bb......",
 
2108
    ".....*aaaaaa*****aaaaaa*bb......",
 
2109
    "....*aaaaaaaa***aaaaaaaa*bb.....",
 
2110
    "....*aaaaaaaa***aaaaaaaa*bb.....",
 
2111
    "...*aaaaaaaaa***aaaaaaaaa*bb....",
 
2112
    "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
 
2113
    "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
 
2114
    "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
 
2115
    ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
 
2116
    ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
 
2117
    "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
 
2118
    "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
 
2119
    "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
 
2120
    "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
 
2121
    ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
 
2122
    "..*************************bbbbb",
 
2123
    "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
 
2124
    ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
 
2125
/* XPM */
 
2126
static const char* const critical_xpm[]={
 
2127
    "32 32 4 1",
 
2128
    ". c None",
 
2129
    "a c #999999",
 
2130
    "* c #ff0000",
 
2131
    "b c #ffffff",
 
2132
    "...........********.............",
 
2133
    ".........************...........",
 
2134
    ".......****************.........",
 
2135
    "......******************........",
 
2136
    ".....********************a......",
 
2137
    "....**********************a.....",
 
2138
    "...************************a....",
 
2139
    "..*******b**********b*******a...",
 
2140
    "..******bbb********bbb******a...",
 
2141
    ".******bbbbb******bbbbb******a..",
 
2142
    ".*******bbbbb****bbbbb*******a..",
 
2143
    "*********bbbbb**bbbbb*********a.",
 
2144
    "**********bbbbbbbbbb**********a.",
 
2145
    "***********bbbbbbbb***********aa",
 
2146
    "************bbbbbb************aa",
 
2147
    "************bbbbbb************aa",
 
2148
    "***********bbbbbbbb***********aa",
 
2149
    "**********bbbbbbbbbb**********aa",
 
2150
    "*********bbbbb**bbbbb*********aa",
 
2151
    ".*******bbbbb****bbbbb*******aa.",
 
2152
    ".******bbbbb******bbbbb******aa.",
 
2153
    "..******bbb********bbb******aaa.",
 
2154
    "..*******b**********b*******aa..",
 
2155
    "...************************aaa..",
 
2156
    "....**********************aaa...",
 
2157
    "....a********************aaa....",
 
2158
    ".....a******************aaa.....",
 
2159
    "......a****************aaa......",
 
2160
    ".......aa************aaaa.......",
 
2161
    ".........aa********aaaaa........",
 
2162
    "...........aaaaaaaaaaa..........",
 
2163
    ".............aaaaaaa............"};
 
2164
/* XPM */
 
2165
static const char *const question_xpm[] = {
 
2166
    "32 32 5 1",
 
2167
    ". c None",
 
2168
    "c c #000000",
 
2169
    "* c #999999",
 
2170
    "a c #ffffff",
 
2171
    "b c #0000ff",
 
2172
    "...........********.............",
 
2173
    "........***aaaaaaaa***..........",
 
2174
    "......**aaaaaaaaaaaaaa**........",
 
2175
    ".....*aaaaaaaaaaaaaaaaaa*.......",
 
2176
    "....*aaaaaaaaaaaaaaaaaaaac......",
 
2177
    "...*aaaaaaaabbbbbbaaaaaaaac.....",
 
2178
    "..*aaaaaaaabaaabbbbaaaaaaaac....",
 
2179
    ".*aaaaaaaabbaaaabbbbaaaaaaaac...",
 
2180
    ".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
 
2181
    "*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
 
2182
    "*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
 
2183
    "*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
 
2184
    "*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
 
2185
    "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
 
2186
    "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
 
2187
    "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
 
2188
    ".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
 
2189
    ".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
 
2190
    "..*aaaaaaaaaabbbbaaaaaaaaaac***.",
 
2191
    "...caaaaaaaaaabbaaaaaaaaaac****.",
 
2192
    "....caaaaaaaaaaaaaaaaaaaac****..",
 
2193
    ".....caaaaaaaaaaaaaaaaaac****...",
 
2194
    "......ccaaaaaaaaaaaaaacc****....",
 
2195
    ".......*cccaaaaaaaaccc*****.....",
 
2196
    "........***cccaaaac*******......",
 
2197
    "..........****caaac*****........",
 
2198
    ".............*caaac**...........",
 
2199
    "...............caac**...........",
 
2200
    "................cac**...........",
 
2201
    ".................cc**...........",
 
2202
    "..................***...........",
 
2203
    "...................**...........",
 
2204
};
 
2205
#endif
 
2206
 
 
2207
/*!
 
2208
  \reimp
 
2209
*/
 
2210
QPixmap
 
2211
QMotifStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
 
2212
                            const QWidget *widget) const
 
2213
{
 
2214
#ifndef QT_NO_IMAGEIO_XPM
 
2215
    switch (standardPixmap) {
 
2216
    case SP_TitleBarMenuButton:
 
2217
        return QPixmap((const char **)qt_menu_xpm);
 
2218
    case SP_TitleBarShadeButton:
 
2219
        return QPixmap((const char **)qt_shade_xpm);
 
2220
    case SP_TitleBarUnshadeButton:
 
2221
        return QPixmap((const char **)qt_unshade_xpm);
 
2222
    case SP_TitleBarNormalButton:
 
2223
        return QPixmap((const char **)qt_normalizeup_xpm);
 
2224
    case SP_TitleBarMinButton:
 
2225
        return QPixmap((const char **)qt_minimize_xpm);
 
2226
    case SP_TitleBarMaxButton:
 
2227
        return QPixmap((const char **)qt_maximize_xpm);
 
2228
    case SP_TitleBarCloseButton:
 
2229
        return QPixmap((const char **)qt_close_xpm);
 
2230
    case SP_DockWidgetCloseButton:
 
2231
        return QPixmap((const char **)dock_window_close_xpm);
 
2232
 
 
2233
    case SP_MessageBoxInformation:
 
2234
    case SP_MessageBoxWarning:
 
2235
    case SP_MessageBoxCritical:
 
2236
    case SP_MessageBoxQuestion:
 
2237
    {
 
2238
        const char * const * xpm_data;
 
2239
        switch (standardPixmap) {
 
2240
        case SP_MessageBoxInformation:
 
2241
            xpm_data = information_xpm;
 
2242
            break;
 
2243
        case SP_MessageBoxWarning:
 
2244
            xpm_data = warning_xpm;
 
2245
            break;
 
2246
        case SP_MessageBoxCritical:
 
2247
            xpm_data = critical_xpm;
 
2248
            break;
 
2249
        case SP_MessageBoxQuestion:
 
2250
            xpm_data = question_xpm;
 
2251
            break;
 
2252
        default:
 
2253
            xpm_data = 0;
 
2254
            break;
 
2255
        }
 
2256
        QPixmap pm;
 
2257
        if (xpm_data) {
 
2258
            QImage image((const char **) xpm_data);
 
2259
            // All that color looks ugly in Motif
 
2260
            const QPalette &pal = QApplication::palette();
 
2261
            switch (standardPixmap) {
 
2262
            case SP_MessageBoxInformation:
 
2263
            case SP_MessageBoxQuestion:
 
2264
                image.setColor(2, 0xff000000 |
 
2265
                               pal.color(QPalette::Active, QPalette::Dark).rgb());
 
2266
                image.setColor(3, 0xff000000 |
 
2267
                               pal.color(QPalette::Active, QPalette::Base).rgb());
 
2268
                image.setColor(4, 0xff000000 |
 
2269
                               pal.color(QPalette::Active, QPalette::Text).rgb());
 
2270
                break;
 
2271
            case SP_MessageBoxWarning:
 
2272
                image.setColor(1, 0xff000000 |
 
2273
                               pal.color(QPalette::Active, QPalette::Base).rgb());
 
2274
                image.setColor(2, 0xff000000 |
 
2275
                               pal.color(QPalette::Active, QPalette::Text).rgb());
 
2276
                image.setColor(3, 0xff000000 |
 
2277
                               pal.color(QPalette::Active, QPalette::Dark).rgb());
 
2278
                break;
 
2279
            case SP_MessageBoxCritical:
 
2280
                image.setColor(1, 0xff000000 |
 
2281
                               pal.color(QPalette::Active, QPalette::Dark).rgb());
 
2282
                image.setColor(2, 0xff000000 |
 
2283
                               pal.color(QPalette::Active, QPalette::Text).rgb());
 
2284
                image.setColor(3, 0xff000000 |
 
2285
                               pal.color(QPalette::Active, QPalette::Base).rgb());
 
2286
                break;
 
2287
            default:
 
2288
                break;
 
2289
            }
 
2290
            image = pm.toImage();
 
2291
        }
 
2292
        return pm;
 
2293
    }
 
2294
 
 
2295
    default:
 
2296
        break;
 
2297
    }
 
2298
#endif
 
2299
 
 
2300
    return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
 
2301
}
 
2302
 
 
2303
/*! \reimp */
 
2304
bool QMotifStyle::event(QEvent *e)
 
2305
{
 
2306
    if(e->type() == QEvent::FocusIn) {
 
2307
        if (QWidget *focusWidget = QApplication::focusWidget()) {
 
2308
            if(!focus)
 
2309
                focus = new QFocusFrame(focusWidget);
 
2310
            focus->setWidget(focusWidget);
 
2311
        } else {
 
2312
            if(focus)
 
2313
                focus->setWidget(0);
 
2314
        }
 
2315
    } else if(e->type() == QEvent::FocusOut) {
 
2316
        if(focus)
 
2317
            focus->setWidget(0);
 
2318
    }
 
2319
    return false;
 
2320
}
 
2321
 
 
2322
 
 
2323
/*! \reimp */
 
2324
int
 
2325
QMotifStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
 
2326
                           QStyleHintReturn *returnData) const
 
2327
{
 
2328
    int ret;
 
2329
 
 
2330
    switch (hint) {
 
2331
#ifdef QT3_SUPPORT
 
2332
    case SH_GUIStyle:
 
2333
        ret = Qt::MotifStyle;
 
2334
        break;
 
2335
#endif
 
2336
    case SH_DrawMenuBarSeparator:
 
2337
        ret = true;
 
2338
        break;
 
2339
 
 
2340
    case SH_ScrollBar_MiddleClickAbsolutePosition:
 
2341
    case SH_Slider_SloppyKeyEvents:
 
2342
    case SH_ProgressDialog_CenterCancelButton:
 
2343
    case SH_Menu_SpaceActivatesItem:
 
2344
    case SH_ScrollView_FrameOnlyAroundContents:
 
2345
    case SH_DitherDisabledText:
 
2346
        ret = 1;
 
2347
        break;
 
2348
 
 
2349
    case SH_Menu_SubMenuPopupDelay:
 
2350
        ret = 96;
 
2351
        break;
 
2352
 
 
2353
    case SH_ProgressDialog_TextLabelAlignment:
 
2354
        ret = Qt::AlignLeft | Qt::AlignVCenter;
 
2355
        break;
 
2356
 
 
2357
    case SH_ItemView_ChangeHighlightOnFocus:
 
2358
        ret = 0;
 
2359
        break;
 
2360
 
 
2361
    case SH_MenuBar_DismissOnSecondClick:
 
2362
        ret = 0;
 
2363
        break;
 
2364
 
 
2365
    case SH_MessageBox_UseBorderForButtonSpacing:
 
2366
        ret = 1;
 
2367
        break;
 
2368
 
 
2369
    case SH_Dial_BackgroundRole:
 
2370
        ret = QPalette::Mid;
 
2371
        break;
 
2372
 
 
2373
    default:
 
2374
        ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
 
2375
        break;
 
2376
    }
 
2377
 
 
2378
    return ret;
 
2379
}
 
2380
 
 
2381
/*! \reimp */
 
2382
QPalette QMotifStyle::standardPalette() const
 
2383
{
 
2384
#ifdef Q_WS_X11
 
2385
    QColor background(0xcf, 0xcf, 0xcf);
 
2386
    if (QX11Info::appDepth() <= 8)
 
2387
        background = QColor(0xc0, 0xc0, 0xc0);
 
2388
#else
 
2389
    QColor background = QColor(0xcf, 0xcf, 0xcf);
 
2390
#endif
 
2391
 
 
2392
    QColor light = background.light();
 
2393
    QColor mid = QColor(0xa6, 0xa6, 0xa6);
 
2394
    QColor dark = QColor(0x79, 0x7d, 0x79);
 
2395
    QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
 
2396
    palette.setBrush(QPalette::Disabled, QPalette::Foreground, dark);
 
2397
    palette.setBrush(QPalette::Disabled, QPalette::Text, dark);
 
2398
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
 
2399
    palette.setBrush(QPalette::Disabled, QPalette::Base, background);
 
2400
    return palette;
 
2401
}
 
2402
 
 
2403
#endif