Qt 4.8
qstyle.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 QSTYLE_H
43 #define QSTYLE_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtCore/qrect.h>
47 #include <QtCore/qsize.h>
48 #include <QtGui/qicon.h>
49 #include <QtGui/qpixmap.h>
50 #include <QtGui/qpalette.h>
51 #include <QtGui/qsizepolicy.h>
52 
54 
56 
57 QT_MODULE(Gui)
58 
59 class QAction;
60 class QDebug;
61 class QTab;
62 class QFontMetrics;
63 class QStyleHintReturn;
64 class QStyleOption;
66 class QStylePrivate;
67 
68 class Q_GUI_EXPORT QStyle : public QObject
69 {
70  Q_OBJECT
72 
73 protected:
74  QStyle(QStylePrivate &dd);
75 
76 public:
77  QStyle();
78  virtual ~QStyle();
79 
80  virtual void polish(QWidget *);
81  virtual void unpolish(QWidget *);
82 
83  virtual void polish(QApplication *);
84  virtual void unpolish(QApplication *);
85 
86  virtual void polish(QPalette &);
87 
88  virtual QRect itemTextRect(const QFontMetrics &fm, const QRect &r,
89  int flags, bool enabled,
90  const QString &text) const;
91 
92  virtual QRect itemPixmapRect(const QRect &r, int flags, const QPixmap &pixmap) const;
93 
94  virtual void drawItemText(QPainter *painter, const QRect &rect,
95  int flags, const QPalette &pal, bool enabled,
96  const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) const;
97 
98  virtual void drawItemPixmap(QPainter *painter, const QRect &rect,
99  int alignment, const QPixmap &pixmap) const;
100 
101  virtual QPalette standardPalette() const;
102 
103  enum StateFlag {
104  State_None = 0x00000000,
105 #ifdef QT3_SUPPORT
106  State_Default = State_None,
107 #endif
108  State_Enabled = 0x00000001,
109  State_Raised = 0x00000002,
110  State_Sunken = 0x00000004,
111  State_Off = 0x00000008,
112  State_NoChange = 0x00000010,
113  State_On = 0x00000020,
114  State_DownArrow = 0x00000040,
115  State_Horizontal = 0x00000080,
116  State_HasFocus = 0x00000100,
117  State_Top = 0x00000200,
118  State_Bottom = 0x00000400,
119  State_FocusAtBorder = 0x00000800,
120  State_AutoRaise = 0x00001000,
121  State_MouseOver = 0x00002000,
122  State_UpArrow = 0x00004000,
123  State_Selected = 0x00008000,
124  State_Active = 0x00010000,
125  State_Window = 0x00020000,
126  State_Open = 0x00040000,
127  State_Children = 0x00080000,
128  State_Item = 0x00100000,
129  State_Sibling = 0x00200000,
130  State_Editing = 0x00400000,
131  State_KeyboardFocusChange = 0x00800000,
132 #ifdef QT_KEYPAD_NAVIGATION
133  State_HasEditFocus = 0x01000000,
134 #endif
135  State_ReadOnly = 0x02000000,
136  State_Small = 0x04000000,
137  State_Mini = 0x08000000
138  };
140 
141 #ifdef QT3_SUPPORT
142  typedef State SFlags;
143 #endif
144 
151 
159  PE_FrameStatusBar, // obsolete
160  PE_FrameStatusBarItem = PE_FrameStatusBar,
166 
173 
181  PE_IndicatorItemViewItemCheck = PE_IndicatorViewItemCheck,
197 
199 
202 
204  PE_PanelItemViewRow, // ### Qt 5: remove
205 
207 
210 
211  // do not add any values below/greater this
212  PE_CustomBase = 0xf000000
213  };
214 
215  virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
216  const QWidget *w = 0) const = 0;
221 
224 
227 
231 
236 
243 
246 
248 
252 
259 
267 
270 
275 
277 
279 
281 
282  // do not add any values below/greater than this
283  CE_CustomBase = 0xf0000000
284  };
285 
286  virtual void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p,
287  const QWidget *w = 0) const = 0;
288 
289  enum SubElement {
292 
297 
302 
304 
306 
308 
312 
313  // ### Qt 5: These values are unused; eliminate them
323 
325 
328 
334 
336  SE_ItemViewItemCheckIndicator = SE_ViewItemCheckIndicator,
337 
339 
341 
344 
349 
361 
365 
369 
373 
375 
377 
378  // do not add any values below/greater than this
379  SE_CustomBase = 0xf0000000
380  };
381 
382  virtual QRect subElementRect(SubElement subElement, const QStyleOption *option,
383  const QWidget *widget = 0) const = 0;
384 
385 
397 
398  // do not add any values below/greater than this
399  CC_CustomBase = 0xf0000000
400  };
401 
402  enum SubControl {
403  SC_None = 0x00000000,
404 
405  SC_ScrollBarAddLine = 0x00000001,
406  SC_ScrollBarSubLine = 0x00000002,
407  SC_ScrollBarAddPage = 0x00000004,
408  SC_ScrollBarSubPage = 0x00000008,
409  SC_ScrollBarFirst = 0x00000010,
410  SC_ScrollBarLast = 0x00000020,
411  SC_ScrollBarSlider = 0x00000040,
412  SC_ScrollBarGroove = 0x00000080,
413 
414  SC_SpinBoxUp = 0x00000001,
415  SC_SpinBoxDown = 0x00000002,
416  SC_SpinBoxFrame = 0x00000004,
417  SC_SpinBoxEditField = 0x00000008,
418 
419  SC_ComboBoxFrame = 0x00000001,
420  SC_ComboBoxEditField = 0x00000002,
421  SC_ComboBoxArrow = 0x00000004,
422  SC_ComboBoxListBoxPopup = 0x00000008,
423 
424  SC_SliderGroove = 0x00000001,
425  SC_SliderHandle = 0x00000002,
426  SC_SliderTickmarks = 0x00000004,
427 
428  SC_ToolButton = 0x00000001,
429  SC_ToolButtonMenu = 0x00000002,
430 
431  SC_TitleBarSysMenu = 0x00000001,
432  SC_TitleBarMinButton = 0x00000002,
433  SC_TitleBarMaxButton = 0x00000004,
434  SC_TitleBarCloseButton = 0x00000008,
435  SC_TitleBarNormalButton = 0x00000010,
436  SC_TitleBarShadeButton = 0x00000020,
437  SC_TitleBarUnshadeButton = 0x00000040,
438  SC_TitleBarContextHelpButton = 0x00000080,
439  SC_TitleBarLabel = 0x00000100,
440 
441  SC_Q3ListView = 0x00000001,
442  SC_Q3ListViewBranch = 0x00000002,
443  SC_Q3ListViewExpand = 0x00000004,
444 
445  SC_DialGroove = 0x00000001,
446  SC_DialHandle = 0x00000002,
447  SC_DialTickmarks = 0x00000004,
448 
449  SC_GroupBoxCheckBox = 0x00000001,
450  SC_GroupBoxLabel = 0x00000002,
451  SC_GroupBoxContents = 0x00000004,
452  SC_GroupBoxFrame = 0x00000008,
453 
454  SC_MdiMinButton = 0x00000001,
455  SC_MdiNormalButton = 0x00000002,
456  SC_MdiCloseButton = 0x00000004,
457 
458  SC_CustomBase = 0xf0000000,
459  SC_All = 0xffffffff
460  };
462 
463 #ifdef QT3_SUPPORT
464  typedef SubControls SCFlags;
465 #endif
466 
467  virtual void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *p,
468  const QWidget *widget = 0) const = 0;
469  virtual SubControl hitTestComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
470  const QPoint &pt, const QWidget *widget = 0) const = 0;
471  virtual QRect subControlRect(ComplexControl cc, const QStyleOptionComplex *opt,
472  SubControl sc, const QWidget *widget = 0) const = 0;
473 
474  enum PixelMetric {
480 
484 
486 
489 
490  PM_SliderThickness, // total slider thickness
491  PM_SliderControlThickness, // thickness of the business part
492  PM_SliderLength, // total length of slider
494  PM_SliderSpaceAvailable, // available space for slider to move
495 
499 
505 
507 
510 
517 
522 
529 
533 
535  PM_MDIFrameWidth = PM_MdiSubWindowFrameWidth, //obsolete
537  PM_MDIMinimizedWidth = PM_MdiSubWindowMinimizedWidth, //obsolete
538 
545 
552 
554 
558 
564 
567 
575 
577 
586 
588 
591 
594 
595  // do not add any values below/greater than this
596  PM_CustomBase = 0xf0000000
597  };
598 
599  virtual int pixelMetric(PixelMetric metric, const QStyleOption *option = 0,
600  const QWidget *widget = 0) const = 0;
601 
628  // do not add any values below/greater than this
629  CT_CustomBase = 0xf0000000
630  };
631 
632  virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt,
633  const QSize &contentsSize, const QWidget *w = 0) const = 0;
634 
637  RSIP_OnMouseClick
638  };
639 
640  enum StyleHint {
669  SH_ScrollBar_StopMouseOverSlider = SH_Slider_StopMouseOverSlider, // obsolete
740  // Add new style hint values here
741 
742 #ifdef QT3_SUPPORT
743  SH_GUIStyle = 0x00000100,
744  SH_ScrollBar_BackgroundMode,
745  // Add other compat values here
746 
747  SH_UnderlineAccelerator = SH_UnderlineShortcut,
748 #endif
749  SH_CustomBase = 0xf0000000
750  };
751 
752  virtual int styleHint(StyleHint stylehint, const QStyleOption *opt = 0,
753  const QWidget *widget = 0, QStyleHintReturn* returnData = 0) const = 0;
754 
825  // do not add any values below/greater than this
826  SP_CustomBase = 0xf0000000
827  };
828 
829  virtual QPixmap standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt = 0,
830  const QWidget *widget = 0) const = 0;
831 
832  QIcon standardIcon(StandardPixmap standardIcon, const QStyleOption *option = 0,
833  const QWidget *widget = 0) const;
834 
835  virtual QPixmap generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
836  const QStyleOption *opt) const = 0;
837 
839  const QRect &logicalRect);
840  static QPoint visualPos(Qt::LayoutDirection direction, const QRect &boundingRect,
841  const QPoint &logicalPos);
842  static int sliderPositionFromValue(int min, int max, int val, int space,
843  bool upsideDown = false);
844  static int sliderValueFromPosition(int min, int max, int pos, int space,
845  bool upsideDown = false);
846  static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment);
847  static QRect alignedRect(Qt::LayoutDirection direction, Qt::Alignment alignment,
848  const QSize &size, const QRect &rectangle);
849 
850  int layoutSpacing(QSizePolicy::ControlType control1,
851  QSizePolicy::ControlType control2, Qt::Orientation orientation,
852  const QStyleOption *option = 0, const QWidget *widget = 0) const;
853  int combinedLayoutSpacing(QSizePolicy::ControlTypes controls1,
854  QSizePolicy::ControlTypes controls2, Qt::Orientation orientation,
855  QStyleOption *option = 0, QWidget *widget = 0) const;
856 
857  const QStyle * proxy() const;
858 
859 protected Q_SLOTS:
860  QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0,
861  const QWidget *widget = 0) const;
862  int layoutSpacingImplementation(QSizePolicy::ControlType control1,
863  QSizePolicy::ControlType control2,
864  Qt::Orientation orientation,
865  const QStyleOption *option = 0,
866  const QWidget *widget = 0) const;
867 
868 private:
870  friend class QWidget;
875  void setProxy(QStyle *style);
876 };
877 
880 
881 #if !defined(QT_NO_DEBUG_STREAM)
883 #endif
884 
886 
888 
889 #endif // QSTYLE_H
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
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
#define QT_MODULE(x)
Definition: qglobal.h:2783
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
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
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
RequestSoftwareInputPanel
This enum describes under what circumstances a software input panel will be requested by input capabl...
Definition: qstyle.h:635
StandardPixmap
This enum describes the available standard pixmaps.
Definition: qstyle.h:755
static const QRectF boundingRect(const QPointF *points, int pointCount)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
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
const char * styleHint(const QFontDef &request)
The State element defines configurations of objects and properties.
#define Q_OBJECT
Definition: qobjectdefs.h:157
PrimitiveElement
This enum describes the various primitive elements.
Definition: qstyle.h:145
State
Definition: qaudio.h:59
static const QStyle::SubControl SubControls[]
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
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
The QStyleOptionComplex class is used to hold parameters that are common to all complex controls...
Definition: qstyleoption.h:687
#define class
Orientation
Definition: qnamespace.h:174
#define QT_END_HEADER
Definition: qglobal.h:137
StateFlag
This enum describes flags that are used when drawing primitive elements.
Definition: qstyle.h:103
#define enabled
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
Q_GUI_EXPORT QDebug operator<<(QDebug debug, QStyle::State state)
Definition: qstyle.cpp:2495
#define text
Definition: qobjectdefs.h:80
SubElement
This enum represents a sub-area of a widget.
Definition: qstyle.h:289
Qt::LayoutDirection direction
static void visualRect(QRectF *geom, Qt::LayoutDirection dir, const QRectF &contentsRect)
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