Qt 4.8
qstylesheetstyle_p.h
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 #ifndef QSTYLESHEETSTYLE_P_H
43 #define QSTYLESHEETSTYLE_P_H
44 
45 #include "QtGui/qwindowsstyle.h"
46 
47 #ifndef QT_NO_STYLE_STYLESHEET
48 
49 #include "QtGui/qstyleoption.h"
50 #include "QtCore/qhash.h"
51 #include "QtGui/qevent.h"
52 #include "QtCore/qvector.h"
53 #include "QtGui/qapplication.h"
54 #include "private/qcssparser_p.h"
55 #include "QtGui/qbrush.h"
56 
58 
59 //
60 // W A R N I N G
61 // -------------
62 //
63 // This file is not part of the Qt API. It exists purely as an
64 // implementation detail. This header file may change from version to
65 // version without notice, or even be removed.
66 //
67 // We mean it.
68 //
69 
70 class QRenderRule;
74 
76 {
78 
79  Q_OBJECT
80 public:
81  QStyleSheetStyle(QStyle *baseStyle);
83 
85  const QWidget *w = 0) const;
86  void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
87  const QWidget *w = 0) const;
88  void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const;
89  void drawItemText(QPainter *painter, const QRect& rect, int alignment, const QPalette &pal,
90  bool enabled, const QString& text, QPalette::ColorRole textRole = QPalette::NoRole) const;
91  void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
92  const QWidget *w = 0) const;
93  QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
94  const QStyleOption *option) const;
96  const QPoint &pt, const QWidget *w = 0) const;
97  QRect itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pixmap) const;
98  QRect itemTextRect(const QFontMetrics &metrics, const QRect &rect, int alignment, bool enabled,
99  const QString &text) const;
100  int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const;
101  void polish(QWidget *widget);
102  void polish(QApplication *app);
103  void polish(QPalette &pal);
105  const QSize &contentsSize, const QWidget *widget = 0) const;
106  QPalette standardPalette() const;
107  QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option = 0,
108  const QWidget *w = 0 ) const;
110  Qt::Orientation orientation, const QStyleOption *option = 0,
111  const QWidget *widget = 0) const;
112  int styleHint(StyleHint sh, const QStyleOption *opt = 0, const QWidget *w = 0,
113  QStyleHintReturn *shret = 0) const;
114  QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget = 0) const;
116  const QWidget *w = 0) const;
117 
118  // These functions are called from QApplication/QWidget. Be careful.
119  QStyle *baseStyle() const;
120  void repolish(QWidget *widget);
121  void repolish(QApplication *app);
122 
123  void unpolish(QWidget *widget);
124  void unpolish(QApplication *app);
125 
127  void ref() { ++refcount; }
128  void deref() { Q_ASSERT(refcount > 0); if (!--refcount) delete this; }
129 
130  void updateStyleSheetFont(QWidget* w) const;
131  void saveWidgetFont(QWidget* w, const QFont& font) const;
132  void clearWidgetFont(QWidget* w) const;
133 
134  bool styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
135 
136 protected Q_SLOTS:
137  QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0,
138  const QWidget *widget = 0) const;
140  QSizePolicy::ControlType control2,
141  Qt::Orientation orientation,
142  const QStyleOption *option = 0,
143  const QWidget *widget = 0) const;
144 
145 protected:
146  bool event(QEvent *e);
147 
148 private:
149  int refcount;
150 
151  friend class QRenderRule;
152  int nativeFrameWidth(const QWidget *);
153  QRenderRule renderRule(const QWidget *, int, quint64 = 0) const;
154  QRenderRule renderRule(const QWidget *, const QStyleOption *, int = 0) const;
155  QSize defaultSize(const QWidget *, QSize, const QRect&, int) const;
156  QRect positionRect(const QWidget *, const QRenderRule&, const QRenderRule&, int,
157  const QRect&, Qt::LayoutDirection) const;
158  QRect positionRect(const QWidget *w, const QRenderRule &rule2, int pe,
159  const QRect &originRect, Qt::LayoutDirection dir) const;
160 
162 
163  void setPalette(QWidget *);
164  void unsetPalette(QWidget *);
165  void setProperties(QWidget *);
166  void setGeometry(QWidget *);
167  QVector<QCss::StyleRule> styleRules(const QWidget *w) const;
168  bool hasStyleRule(const QWidget *w, int part) const;
169 
170  QHash<QStyle::SubControl, QRect> titleBarLayout(const QWidget *w, const QStyleOptionTitleBar *tb) const;
171 
172  QCss::StyleSheet getDefaultStyleSheet() const;
173 
174  static Qt::Alignment resolveAlignment(Qt::LayoutDirection, Qt::Alignment);
175  static bool isNaturalChild(const QWidget *w);
176  bool initWidget(const QWidget *w) const;
177 public:
178  static int numinstances;
179 
180 private:
183 };
184 
186 {
187  Q_OBJECT
188 public Q_SLOTS:
189  void widgetDestroyed(QObject *);
190  void styleDestroyed(QObject *);
191 public:
196  QHash<const QWidget *, QPalette> customPaletteWidgets; // widgets whose palette we tampered
199 };
200 
201 
203 #endif // QT_NO_STYLE_STYLESHEET
204 #endif // QSTYLESHEETSTYLE_P_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *option, const QWidget *widget=0) const
void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
void polish(QApplication *)
Reimplemented Function
void unpolish(QApplication *)
Reimplemented Function
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
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
QPointer< QWidget > widget
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
QHash< const QWidget *, QPalette > customPaletteWidgets
virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const
Returns the area within the given rectangle in which to draw the specified pixmap according to the de...
Definition: qstyle.cpp:497
static int refcount
Definition: proxyconf.cpp:398
ComplexControl
This enum describes the available complex controls.
Definition: qstyle.h:386
The QStyleOptionTitleBar class is used to describe the parameters for drawing a title bar...
Definition: qstyleoption.h:816
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
QHash< const QWidget *, QHash< int, bool > > hasStyleRuleCache
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
virtual void drawItemText(QPainter *painter, const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole=QPalette::NoRole) const
Draws the given text in the specified rectangle using the provided painter and palette.
Definition: qstyle.cpp:532
QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap, const QStyleOption *opt) const
Reimplemented Function
The QAbstractScrollArea widget provides a scrolling area with on-demand scroll bars.
QHash< const void *, QCss::StyleSheet > styleSheetCache
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
QHash< const QWidget *, QRenderRules > renderRulesCache
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
Returns the spacing that should be used between control1 and control2 in a layout.
Definition: qstyle.cpp:2395
QRect originRect(const QRect &rect, Origin origin) const
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r, int flags, bool enabled, const QString &text) const
Returns the area within the given rectangle in which to draw the provided text according to the speci...
Definition: qstyle.cpp:470
unsigned __int64 quint64
Definition: qglobal.h:943
virtual QPalette standardPalette() const
Returns the style&#39;s standard palette.
Definition: qstyle.cpp:2283
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
LayoutDirection
Definition: qnamespace.h:1580
QHash< int, QHash< quint64, QRenderRule > > QRenderRules
int pixelMetric(PixelMetric pm, const QStyleOption *option=0, const QWidget *widget=0) const
Reimplemented Function
void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p, const QWidget *w=0) const
Reimplemented Function
QWindowsStyle ParentStyle
#define Q_OBJECT
Definition: qobjectdefs.h:157
int styleHint(StyleHint hint, const QStyleOption *opt=0, const QWidget *widget=0, QStyleHintReturn *returnData=0) const
Reimplemented Function
virtual void drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, const QPixmap &pixmap) const
Draws the given pixmap in the specified rectangle, according to the specified alignment, using the provided painter.
Definition: qstyle.cpp:570
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
QSet< const QWidget * > autoFillDisabledWidgets
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *widget=0) const
Reimplemented Function
QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, const QPoint &pt, const QWidget *w=0) const
Reimplemented Function
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
ControlElement
This enum represents a control element.
Definition: qstyle.h:217
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
QRect subElementRect(SubElement r, const QStyleOption *opt, const QWidget *widget=0) const
Reimplemented Function
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
The QWindowsStyle class provides a Microsoft Windows-like look and feel.
Definition: qwindowsstyle.h:57
QHash< const QWidget *, QVector< QCss::StyleRule > > styleRulesCache
Orientation
Definition: qnamespace.h:174
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define enabled
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 ...
Definition: qstyle.cpp:2481
#define text
Definition: qobjectdefs.h:80
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt, SubControl sc, const QWidget *w=0) const
Reimplemented Function
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