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

« back to all changes in this revision

Viewing changes to src/gui/styles/qcdestyle.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 "qcdestyle.h"
 
30
 
 
31
#if !defined(QT_NO_STYLE_CDE) || 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 "qpainterpath.h"
 
53
#include "qdebug.h"
 
54
#include <limits.h>
 
55
 
 
56
 
 
57
/*!
 
58
    \class QCDEStyle
 
59
    \brief The QCDEStyle class provides a CDE look and feel.
 
60
 
 
61
    \ingroup appearance
 
62
 
 
63
    This style provides a slightly improved Motif look similar to some
 
64
    versions of the Common Desktop Environment (CDE). The main
 
65
    differences are thinner frames and more modern radio buttons and
 
66
    checkboxes. Together with a dark background and a bright
 
67
    text/foreground color, the style looks quite attractive (at least
 
68
    for Motif fans).
 
69
 
 
70
    Note that most of the functions provided by QCDEStyle are
 
71
    reimplementations of QStyle functions; see QStyle for their
 
72
    documentation. QCDEStyle provides overloads for drawControl() and
 
73
    drawPrimitive() which are documented here.
 
74
 
 
75
    \img qcdestyle.png
 
76
    \sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QPlastiqueStyle, QMotifStyle
 
77
*/
 
78
 
 
79
/*!
 
80
    Constructs a QCDEStyle.
 
81
 
 
82
    If \a useHighlightCols is false (the default), then the style will
 
83
    polish the application's color palette to emulate the Motif way of
 
84
    highlighting, which is a simple inversion between the base and the
 
85
    text color.
 
86
*/
 
87
QCDEStyle::QCDEStyle(bool useHighlightCols)
 
88
    : QMotifStyle(useHighlightCols)
 
89
{
 
90
}
 
91
 
 
92
/*!
 
93
    Destroys the style.
 
94
*/
 
95
QCDEStyle::~QCDEStyle()
 
96
{
 
97
}
 
98
 
 
99
 
 
100
/*!\reimp
 
101
*/
 
102
int QCDEStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
 
103
                           const QWidget *widget) const
 
104
/*
 
105
int QCDEStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
 
106
                           const QWidget *widget) const
 
107
                           */
 
108
{
 
109
    int ret;
 
110
 
 
111
    switch(metric) {
 
112
    case PM_MenuBarPanelWidth:
 
113
    case PM_DefaultFrameWidth:
 
114
    case PM_FocusFrameVMargin:
 
115
    case PM_FocusFrameHMargin:
 
116
    case PM_MenuPanelWidth:
 
117
    case PM_SpinBoxFrameWidth:
 
118
    case PM_MenuBarVMargin:
 
119
    case PM_MenuBarHMargin:
 
120
    case PM_DockWidgetFrameWidth:
 
121
        ret = 1;
 
122
        break;
 
123
    case PM_ScrollBarExtent:
 
124
        ret = 13;
 
125
        break;
 
126
    default:
 
127
        ret = QMotifStyle::pixelMetric(metric, option, widget);
 
128
        break;
 
129
    }
 
130
    return ret;
 
131
}
 
132
 
 
133
/*!
 
134
    \reimp
 
135
*/
 
136
void QCDEStyle::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
 
137
                             const QWidget *widget) const
 
138
{
 
139
 
 
140
    switch(element) {
 
141
    case CE_MenuBarItem: {
 
142
        if (opt->state & State_Selected)  // active item
 
143
            qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
 
144
                            &opt->palette.brush(QPalette::Button));
 
145
        else  // other item
 
146
            p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
 
147
        QCommonStyle::drawControl(element, opt, p, widget);
 
148
        break; }
 
149
    case CE_RubberBand: {
 
150
        QPainterPath path;
 
151
        path.addRect(opt->rect);
 
152
        path.addRect(opt->rect.adjusted(2, 2, -2, -2));
 
153
        p->fillPath(path, opt->palette.dark());
 
154
        break; }
 
155
    default:
 
156
        QMotifStyle::drawControl(element, opt, p, widget);
 
157
    break;
 
158
    }
 
159
 
 
160
 
 
161
}
 
162
 
 
163
/*!
 
164
    \reimp
 
165
*/
 
166
void QCDEStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
 
167
                        const QWidget *widget) const
 
168
{
 
169
    switch(pe) {
 
170
    case PE_IndicatorCheckBox: {
 
171
        bool down = opt->state & State_Sunken;
 
172
        bool on = opt->state & State_On;
 
173
        bool showUp = !(down ^ on);
 
174
        QBrush fill = showUp || opt->state & State_NoChange ? opt->palette.brush(QPalette::Button) : opt->palette.brush(QPalette::Mid);
 
175
        qDrawShadePanel(p, opt->rect, opt->palette, !showUp, pixelMetric(PM_DefaultFrameWidth), &opt->palette.brush(QPalette::Button));
 
176
 
 
177
        if (!(opt->state & State_Off)) {
 
178
            QRect r = opt->rect;
 
179
            QPolygon a(7 * 2);
 
180
            int i, xx, yy;
 
181
            xx = r.x() + 3;
 
182
            yy = r.y() + 5;
 
183
            for (i = 0; i < 3; i++) {
 
184
                a.setPoint(2 * i, xx, yy);
 
185
                a.setPoint(2 * i + 1, xx, yy + 2);
 
186
                xx++; yy++;
 
187
            }
 
188
            yy -= 2;
 
189
            for (i = 3; i < 7; i++) {
 
190
                a.setPoint(2 * i, xx, yy);
 
191
                a.setPoint(2 * i + 1, xx, yy + 2);
 
192
                xx++; yy--;
 
193
            }
 
194
            if (opt->state & State_NoChange)
 
195
                p->setPen(opt->palette.dark().color());
 
196
            else
 
197
                p->setPen(opt->palette.foreground().color());
 
198
            p->drawPolyline(a);
 
199
        }
 
200
        if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
201
            p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
202
    } break;
 
203
    case PE_IndicatorRadioButton:
 
204
        {
 
205
            QRect r = opt->rect;
 
206
#define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)
 
207
            static const int pts1[] = {              // up left  lines
 
208
                1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
 
209
            static const int pts4[] = {              // bottom right  lines
 
210
                2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
 
211
                11,4, 10,3, 10,2 };
 
212
            static const int pts5[] = {              // inner fill
 
213
                4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
 
214
            bool down = opt->state & State_Sunken;
 
215
            bool on = opt->state & State_On;
 
216
            QPolygon a(INTARRLEN(pts1), pts1);
 
217
            a.translate(r.x(), r.y());
 
218
            QPen oldPen = p->pen();
 
219
            QBrush oldBrush = p->brush();
 
220
            p->setPen((down || on) ? opt->palette.dark().color() : opt->palette.light().color());
 
221
            p->drawPolyline(a);
 
222
            a.setPoints(INTARRLEN(pts4), pts4);
 
223
            a.translate(r.x(), r.y());
 
224
            p->setPen((down || on) ? opt->palette.light().color() : opt->palette.dark().color());
 
225
            p->drawPolyline(a);
 
226
            a.setPoints(INTARRLEN(pts5), pts5);
 
227
            a.translate(r.x(), r.y());
 
228
            QColor fillColor = on ? opt->palette.dark().color() : opt->palette.background().color();
 
229
            p->setPen(fillColor);
 
230
            p->setBrush(on ? opt->palette.brush(QPalette::Dark) :
 
231
                         opt->palette.brush(QPalette::Background));
 
232
            p->drawPolygon(a);
 
233
            if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
 
234
                p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
 
235
            p->setPen(oldPen);
 
236
            p->setBrush(oldBrush);
 
237
        } break;
 
238
 
 
239
    default:
 
240
        QMotifStyle::drawPrimitive(pe, opt, p, widget);
 
241
    }
 
242
}
 
243
 
 
244
/*!\reimp*/
 
245
QPalette QCDEStyle::standardPalette() const
 
246
{
 
247
    QColor background = QColor(0xb6, 0xb6, 0xcf);
 
248
    QColor light = background.light();
 
249
    QColor mid = background.dark(150);
 
250
    QColor dark = background.dark();
 
251
    QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
 
252
    palette.setBrush(QPalette::Disabled, QPalette::Foreground, dark);
 
253
    palette.setBrush(QPalette::Disabled, QPalette::Text, dark);
 
254
    palette.setBrush(QPalette::Disabled, QPalette::ButtonText, dark);
 
255
    palette.setBrush(QPalette::Disabled, QPalette::Base, background);
 
256
    return palette;
 
257
}
 
258
 
 
259
#endif