Qt 4.8
qcdestyle.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qcdestyle.h"
43 
44 #if !defined(QT_NO_STYLE_CDE) || defined(QT_PLUGIN)
45 
46 #include "qmenu.h"
47 #include "qapplication.h"
48 #include "qpainter.h"
49 #include "qdrawutil.h"
50 #include "qpixmap.h"
51 #include "qpalette.h"
52 #include "qwidget.h"
53 #include "qpushbutton.h"
54 #include "qscrollbar.h"
55 #include "qtabbar.h"
56 #include "qtabwidget.h"
57 #include "qlistview.h"
58 #include "qsplitter.h"
59 #include "qslider.h"
60 #include "qcombobox.h"
61 #include "qlineedit.h"
62 #include "qprogressbar.h"
63 #include "qimage.h"
64 #include "qfocusframe.h"
65 #include "qpainterpath.h"
66 #include "qdebug.h"
67 #include <limits.h>
68 
70 
104 QCDEStyle::QCDEStyle(bool useHighlightCols)
105  : QMotifStyle(useHighlightCols)
106 {
107 }
108 
113 {
114 }
115 
116 
120  const QWidget *widget) const
121 /*
122 int QCDEStyle::pixelMetric(PixelMetric metric, const QStyleOption *option,
123  const QWidget *widget) const
124  */
125 {
126  int ret = 0;
127 
128  switch(metric) {
133  case PM_MenuPanelWidth:
135  case PM_MenuBarVMargin:
136  case PM_MenuBarHMargin:
138  ret = 1;
139  break;
140  case PM_ScrollBarExtent:
141  ret = 13;
142  break;
143  default:
144  ret = QMotifStyle::pixelMetric(metric, option, widget);
145  break;
146  }
147  return ret;
148 }
149 
154  const QWidget *widget) const
155 {
156 
157  switch(element) {
158  case CE_MenuBarItem: {
159  if (opt->state & State_Selected) // active item
160  qDrawShadePanel(p, opt->rect, opt->palette, true, 1,
162  else // other item
163  p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
164  QCommonStyle::drawControl(element, opt, p, widget);
165  break; }
166  case CE_RubberBand: {
167  p->save();
168  p->setClipping(false);
169  QPainterPath path;
170  path.addRect(opt->rect);
171  path.addRect(opt->rect.adjusted(2, 2, -2, -2));
173  p->restore();
174  break; }
175  default:
176  QMotifStyle::drawControl(element, opt, p, widget);
177  break;
178  }
179 }
180 
185  const QWidget *widget) const
186 {
187  switch(pe) {
188  case PE_IndicatorCheckBox: {
189  bool down = opt->state & State_Sunken;
190  bool on = opt->state & State_On;
191  bool showUp = !(down ^ on);
192  QBrush fill = (showUp || (opt->state & State_NoChange)) ? opt->palette.brush(QPalette::Button) : opt->palette.brush(QPalette::Mid);
194 
195  if (on || (opt->state & State_NoChange)) {
196  QRect r = opt->rect;
197  QPolygon a(7 * 2);
198  int i, xx, yy;
199  xx = r.x() + 3;
200  yy = r.y() + 5;
201  if (opt->rect.width() <= 9) {
202  // When called from CE_MenuItem in QMotifStyle
203  xx -= 2;
204  yy -= 2;
205  }
206 
207  for (i = 0; i < 3; i++) {
208  a.setPoint(2 * i, xx, yy);
209  a.setPoint(2 * i + 1, xx, yy + 2);
210  xx++; yy++;
211  }
212  yy -= 2;
213  for (i = 3; i < 7; i++) {
214  a.setPoint(2 * i, xx, yy);
215  a.setPoint(2 * i + 1, xx, yy + 2);
216  xx++; yy--;
217  }
218  if (opt->state & State_NoChange)
219  p->setPen(opt->palette.dark().color());
220  else
221  p->setPen(opt->palette.foreground().color());
222  p->drawPolyline(a);
223  }
226  } break;
228  {
229  QRect r = opt->rect;
230 #define INTARRLEN(x) sizeof(x)/(sizeof(int)*2)
231  static const int pts1[] = { // up left lines
232  1,9, 1,8, 0,7, 0,4, 1,3, 1,2, 2,1, 3,1, 4,0, 7,0, 8,1, 9,1 };
233  static const int pts4[] = { // bottom right lines
234  2,10, 3,10, 4,11, 7,11, 8,10, 9,10, 10,9, 10,8, 11,7,
235  11,4, 10,3, 10,2 };
236  static const int pts5[] = { // inner fill
237  4,2, 7,2, 9,4, 9,7, 7,9, 4,9, 2,7, 2,4 };
238  bool down = opt->state & State_Sunken;
239  bool on = opt->state & State_On;
240  QPolygon a(INTARRLEN(pts1), pts1);
241 
242  //center when rect is larger than indicator size
243  int xOffset = 0;
244  int yOffset = 0;
245  int indicatorWidth = pixelMetric(PM_ExclusiveIndicatorWidth);
246  int indicatorHeight = pixelMetric(PM_ExclusiveIndicatorWidth);
247  if (r.width() > indicatorWidth)
248  xOffset += (r.width() - indicatorWidth)/2;
249  if (r.height() > indicatorHeight)
250  yOffset += (r.height() - indicatorHeight)/2;
251  p->translate(xOffset, yOffset);
252 
253  a.translate(r.x(), r.y());
254  QPen oldPen = p->pen();
255  QBrush oldBrush = p->brush();
256  p->setPen((down || on) ? opt->palette.dark().color() : opt->palette.light().color());
257  p->drawPolyline(a);
258  a.setPoints(INTARRLEN(pts4), pts4);
259  a.translate(r.x(), r.y());
260  p->setPen((down || on) ? opt->palette.light().color() : opt->palette.dark().color());
261  p->drawPolyline(a);
262  a.setPoints(INTARRLEN(pts5), pts5);
263  a.translate(r.x(), r.y());
264  QColor fillColor = on ? opt->palette.dark().color() : opt->palette.background().color();
265  p->setPen(fillColor);
266  p->setBrush(on ? opt->palette.brush(QPalette::Dark) :
268  p->drawPolygon(a);
271  p->setPen(oldPen);
272  p->setBrush(oldBrush);
273 
274  p->translate(-xOffset, -yOffset);
275 
276  } break;
277  default:
278  QMotifStyle::drawPrimitive(pe, opt, p, widget);
279  }
280 }
281 
284 {
285  QColor background(0xb6, 0xb6, 0xcf);
286  QColor light = background.lighter();
287  QColor mid = background.darker(150);
288  QColor dark = background.darker();
289  QPalette palette(Qt::black, background, light, dark, mid, Qt::black, Qt::white);
293  palette.setBrush(QPalette::Disabled, QPalette::Base, background);
294  return palette;
295 }
296 
301  const QWidget *widget) const
302 {
303  return QMotifStyle::standardIconImplementation(standardIcon, opt, widget);
304 }
305 
307 
308 #endif
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
#define INTARRLEN(x)
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
QPointer< QWidget > widget
int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
Returns the value of the given pixel metric.
Definition: qcdestyle.cpp:119
const QBrush & dark() const
Returns the dark brush of the current color group.
Definition: qpalette.h:127
const QBrush & background() const
Returns the current background brush.
Definition: qpainter.cpp:2482
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
Definition: qcdestyle.cpp:184
const QBrush & background() const
Use window() instead.
Definition: qpalette.h:134
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
const QBrush & foreground() const
Use windowText() instead.
Definition: qpalette.h:123
long ASN1_INTEGER_get ASN1_INTEGER * a
The QPolygon class provides a vector of points using integer precision.
Definition: qpolygon.h:60
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
virtual ~QCDEStyle()
Destroys the style.
Definition: qcdestyle.cpp:112
QColor darker(int f=200) const
Returns a darker (or lighter) color, but does not change this object.
Definition: qcolor.h:301
void translate(int dx, int dy)
Translates all points in the polygon by ({dx}, {dy}).
Definition: qpolygon.cpp:238
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
const QBrush & light() const
Returns the light brush of the current color group.
Definition: qpalette.h:126
void fillPath(const QPainterPath &path, const QBrush &brush)
Fills the given path using the given brush.
Definition: qpainter.cpp:3456
QCDEStyle(bool useHighlightCols=false)
Constructs a QCDEStyle.
Definition: qcdestyle.cpp:104
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
QPalette standardPalette() const
Returns the style&#39;s standard palette.
Definition: qcdestyle.cpp:283
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
void drawPolygon(const QPointF *points, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)
Draws the polygon defined by the first pointCount points in the array points using the current pen an...
Definition: qpainter.cpp:5205
void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, const QPalette &pal, bool sunken, int lineWidth, const QBrush *fill)
Definition: qdrawutil.cpp:303
The QMotifStyle class provides Motif look and feel.
Definition: qmotifstyle.h:60
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
Definition: qcdestyle.cpp:153
void setClipping(bool enable)
Enables clipping if enable is true, or disables clipping if enable is false.
Definition: qpainter.cpp:2517
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
void setPoint(int index, int x, int y)
Sets the point at the given index to the point specified by ({x}, {y}).
Definition: qpolygon.h:120
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
ControlElement
This enum represents a control element.
Definition: qstyle.h:217
void setPoints(int nPoints, const int *points)
Resizes the polygon to nPoints and populates it with the given points.
Definition: qpolygon.cpp:350
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
QColor lighter(int f=150) const
Returns a lighter (or darker) color, but does not change this object.
Definition: qcolor.h:298
int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
void drawPolyline(const QPointF *points, int pointCount)
Draws the polyline defined by the first pointCount points in points using the current pen...
Definition: qpainter.cpp:5055
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt=0, const QWidget *widget=0) const
Definition: qcdestyle.cpp:300
int styleHint(StyleHint hint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const
Reimplemented Function
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt=0, const QWidget *widget=0) const
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60