Qt 4.8
qproxystyle.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 <qstyle.h>
43 #include <private/qproxystyle_p.h>
44 #include <private/qapplication_p.h>
45 #include "qproxystyle.h"
46 #include "qstylefactory.h"
47 #include <private/qstyle_p.h>
48 
49 #if !defined(QT_NO_STYLE_PROXY) || defined(QT_PLUGIN)
50 
52 
82 {
83  Q_Q(const QProxyStyle);
84 
85  if (baseStyle)
86  return;
87 
90  if (baseStyle) {
91  // If baseStyle is an instance of the same proxyStyle
92  // we destroy it and fall back to the desktop style
94  q->metaObject()->className()) == 0) {
95  delete baseStyle;
96  baseStyle = 0;
97  }
98  }
99  }
100 
101  if (!baseStyle) // Use application desktop style
103 
104  if (!baseStyle) // Fallback to windows style
106 
107  baseStyle->setProxy(const_cast<QProxyStyle*>(q));
108  baseStyle->setParent(const_cast<QProxyStyle*>(q)); // Take ownership
109 }
110 
121 {
122  Q_D(QProxyStyle);
123  if (style) {
124  style->setProxy(this);
125  style->setParent(this); // Take ownership
126  d->baseStyle = style;
127  }
128 }
129 
134 {
135 }
136 
145 {
146  Q_D (const QProxyStyle);
147  d->ensureBaseStyle();
148  return d->baseStyle;
149 }
150 
160 {
161  Q_D (QProxyStyle);
162 
163  if (d->baseStyle && d->baseStyle->parent() == this)
164  d->baseStyle->deleteLater();
165 
166  d->baseStyle = style;
167 
168  if (d->baseStyle) {
169  d->baseStyle->setProxy(this);
170  d->baseStyle->setParent(this);
171  }
172 }
173 
176 void QProxyStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
177 {
178  Q_D (const QProxyStyle);
179  d->ensureBaseStyle();
180  d->baseStyle->drawPrimitive(element, option, painter, widget);
181 }
182 
186 void QProxyStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
187 {
188  Q_D (const QProxyStyle);
189  d->ensureBaseStyle();
190  d->baseStyle->drawControl(element, option, painter, widget);
191 }
192 
195 void QProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
196 {
197  Q_D (const QProxyStyle);
198  d->ensureBaseStyle();
199  d->baseStyle->drawComplexControl(control, option, painter, widget);
200 }
201 
204 void QProxyStyle::drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled,
205  const QString &text, QPalette::ColorRole textRole) const
206 {
207  Q_D (const QProxyStyle);
208  d->ensureBaseStyle();
209  d->baseStyle->drawItemText(painter, rect, flags, pal, enabled, text, textRole);
210 }
211 
214 void QProxyStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
215 {
216  Q_D (const QProxyStyle);
217  d->ensureBaseStyle();
218  d->baseStyle->drawItemPixmap(painter, rect, alignment, pixmap);
219 }
220 
224 {
225  Q_D (const QProxyStyle);
226  d->ensureBaseStyle();
227  return d->baseStyle->sizeFromContents(type, option, size, widget);
228 }
229 
233 {
234  Q_D (const QProxyStyle);
235  d->ensureBaseStyle();
236  return d->baseStyle->subElementRect(element, option, widget);
237 }
238 
242 {
243  Q_D (const QProxyStyle);
244  d->ensureBaseStyle();
245  return d->baseStyle->subControlRect(cc, option, sc, widget);
246 }
247 
250 QRect QProxyStyle::itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
251 {
252  Q_D (const QProxyStyle);
253  d->ensureBaseStyle();
254  return d->baseStyle->itemTextRect(fm, r, flags, enabled, text);
255 }
256 
259 QRect QProxyStyle::itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
260 {
261  Q_D (const QProxyStyle);
262  d->ensureBaseStyle();
263  return d->baseStyle->itemPixmapRect(r, flags, pixmap);
264 }
265 
269 {
270  Q_D (const QProxyStyle);
271  d->ensureBaseStyle();
272  return d->baseStyle->hitTestComplexControl(control, option, pos, widget);
273 }
274 
277 int QProxyStyle::styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *returnData) const
278 {
279  Q_D (const QProxyStyle);
280  d->ensureBaseStyle();
281  return d->baseStyle->styleHint(hint, option, widget, returnData);
282 }
283 
286 int QProxyStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
287 {
288  Q_D (const QProxyStyle);
289  d->ensureBaseStyle();
290  return d->baseStyle->pixelMetric(metric, option, widget);
291 }
292 
296 {
297  Q_D (const QProxyStyle);
298  d->ensureBaseStyle();
299  return d->baseStyle->standardPixmap(standardPixmap, opt, widget);
300 }
301 
304 QPixmap QProxyStyle::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
305 {
306  Q_D (const QProxyStyle);
307  d->ensureBaseStyle();
308  return d->baseStyle->generatedIconPixmap(iconMode, pixmap, opt);
309 }
310 
314 {
315  Q_D (const QProxyStyle);
316  d->ensureBaseStyle();
317  return d->baseStyle->standardPalette();
318 }
319 
323 {
324  Q_D (QProxyStyle);
325  d->ensureBaseStyle();
326  d->baseStyle->polish(widget);
327 }
328 
332 {
333  Q_D (QProxyStyle);
334  d->ensureBaseStyle();
335  d->baseStyle->polish(pal);
336 }
337 
341 {
342  Q_D (QProxyStyle);
343  d->ensureBaseStyle();
344  d->baseStyle->polish(app);
345 }
346 
350 {
351  Q_D (QProxyStyle);
352  d->ensureBaseStyle();
353  d->baseStyle->unpolish(widget);
354 }
355 
359 {
360  Q_D (QProxyStyle);
361  d->ensureBaseStyle();
362  d->baseStyle->unpolish(app);
363 }
364 
368 {
369  Q_D (QProxyStyle);
370  d->ensureBaseStyle();
371  return d->baseStyle->event(e);
372 }
373 
390  const QStyleOption *option,
391  const QWidget *widget) const
392 {
393  Q_D (const QProxyStyle);
394  d->ensureBaseStyle();
395  return d->baseStyle->standardIcon(standardIcon, option, widget);
396 }
397 
411  QSizePolicy::ControlType control2,
412  Qt::Orientation orientation,
413  const QStyleOption *option,
414  const QWidget *widget) const
415 {
416  Q_D (const QProxyStyle);
417  d->ensureBaseStyle();
418  return d->baseStyle->layoutSpacing(control1, control2, orientation, option, widget);
419 }
420 
422 
423 #endif // QT_NO_STYLE_PROXY
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
double d
Definition: qnumeric_p.h:62
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
int type
Definition: qmetatype.cpp:239
SubControl
This enum describes the available sub controls.
Definition: qstyle.h:402
StyleHint
This enum describes the available style hints.
Definition: qstyle.h:640
The QStyleHintReturn class provides style hints that return more than basic data types.
Definition: qstyleoption.h:907
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
QPointer< QWidget > widget
QSize sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const
Reimplemented Function
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
bool event(QEvent *e)
Reimplemented Function
int layoutSpacingImplementation(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
This slot is called by layoutSpacing() to determine the spacing that should be used between control1 ...
void drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget=0) const
Reimplemented Function
ComplexControl
This enum describes the available complex controls.
Definition: qstyle.h:386
The QProxyStyle class is a convenience class that simplifies dynamically overriding QStyle elements...
Definition: qproxystyle.h:56
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static QStyle * create(const QString &)
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
QRect subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
Reimplemented Function
int styleHint(StyleHint hint, const QStyleOption *option=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const
Reimplemented Function
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const
Reimplemented Function
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget) const
Returns an icon for the given standardIcon.
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_D(Class)
Definition: qglobal.h:2482
void polish(QWidget *widget)
Reimplemented Function
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
void setParent(QObject *)
Makes the object a child of parent.
Definition: qobject.cpp:1950
#define Q_Q(Class)
Definition: qglobal.h:2483
void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget=0) const
Reimplemented Function
QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option=0, const QWidget *widget=0) const
Returns an icon for the given standardIcon.
Definition: qstyle.cpp:2327
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
Reimplemented Function
static bool isEmpty(const char *str)
void ensureBaseStyle() const
Definition: qproxystyle.cpp:81
void setBaseStyle(QStyle *style)
Sets the base style that should be proxied.
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
ContentsType
This enum describes the available contents types.
Definition: qstyle.h:602
Mode
This enum type describes the mode for which a pixmap is intended to be used.
Definition: qicon.h:63
QPalette standardPalette() const
Reimplemented Function
void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Reimplemented Function
QStyle * baseStyle() const
Returns the proxy base style object.
QProxyStyle(QStyle *baseStyle=0)
Constructs a QProxyStyle object for overriding behavior in style or in the current application style ...
QPointer< QStyle > baseStyle
Definition: qproxystyle_p.h:72
QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
Reimplemented Function
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
~QProxyStyle()
Destroys the QProxyStyle object.
The QCommonStyle class encapsulates the common Look and Feel of a GUI.
Definition: qcommonstyle.h:54
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
static QString desktopStyleKey()
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Reimplemented Function
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
static QString styleOverride
ControlElement
This enum represents a control element.
Definition: qstyle.h:217
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *widget) const
Reimplemented Function
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
int qstrcmp(const QByteArray &str1, const char *str2)
Definition: qbytearray.cpp:336
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
void unpolish(QWidget *widget)
Reimplemented Function
void setProxy(QStyle *style)
Definition: qstyle.cpp:2557
QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Reimplemented Function
Orientation
Definition: qnamespace.h:174
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define enabled
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.
SubControl hitTestComplexControl(ComplexControl control, const QStyleOptionComplex *option, const QPoint &pos, const QWidget *widget=0) const
Reimplemented Function
#define text
Definition: qobjectdefs.h:80
SubElement
This enum represents a sub-area of a widget.
Definition: qstyle.h:289
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