1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the style module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qcdestyle.h"
31
#if !defined(QT_NO_STYLE_CDE) || defined(QT_PLUGIN)
34
#include "qapplication.h"
36
#include "qdrawutil.h"
40
#include "qpushbutton.h"
41
#include "qscrollbar.h"
43
#include "qtabwidget.h"
44
#include "qlistview.h"
45
#include "qsplitter.h"
47
#include "qcombobox.h"
48
#include "qlineedit.h"
49
#include "qprogressbar.h"
51
#include "qfocusframe.h"
52
#include "qpainterpath.h"
59
\brief The QCDEStyle class provides a CDE look and feel.
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
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.
76
\sa QWindowsXPStyle, QMacStyle, QWindowsStyle, QPlastiqueStyle, QMotifStyle
80
Constructs a QCDEStyle.
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
87
QCDEStyle::QCDEStyle(bool useHighlightCols)
88
: QMotifStyle(useHighlightCols)
95
QCDEStyle::~QCDEStyle()
102
int QCDEStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
103
const QWidget *widget) const
105
int QCDEStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
106
const QWidget *widget) const
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:
123
case PM_ScrollBarExtent:
127
ret = QMotifStyle::pixelMetric(metric, option, widget);
136
void QCDEStyle::drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
137
const QWidget *widget) const
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));
146
p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
147
QCommonStyle::drawControl(element, opt, p, widget);
149
case CE_RubberBand: {
151
path.addRect(opt->rect);
152
path.addRect(opt->rect.adjusted(2, 2, -2, -2));
153
p->fillPath(path, opt->palette.dark());
156
QMotifStyle::drawControl(element, opt, p, widget);
166
void QCDEStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
167
const QWidget *widget) const
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));
177
if (!(opt->state & State_Off)) {
183
for (i = 0; i < 3; i++) {
184
a.setPoint(2 * i, xx, yy);
185
a.setPoint(2 * i + 1, xx, 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);
194
if (opt->state & State_NoChange)
195
p->setPen(opt->palette.dark().color());
197
p->setPen(opt->palette.foreground().color());
200
if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
201
p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
203
case PE_IndicatorRadioButton:
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,
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());
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());
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));
233
if (!(opt->state & State_Enabled) && styleHint(SH_DitherDisabledText))
234
p->fillRect(opt->rect, QBrush(p->background().color(), Qt::Dense5Pattern));
236
p->setBrush(oldBrush);
240
QMotifStyle::drawPrimitive(pe, opt, p, widget);
245
QPalette QCDEStyle::standardPalette() const
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);