QtBase  v6.3.1
qstyleoption.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include <QtWidgets/private/qtwidgetsglobal_p.h>
41 #include "private/qstylehelper_p.h"
42 #include "qstyleoption.h"
43 #include "qapplication.h"
44 #include <qdebug.h>
45 #include <QtCore/qmath.h>
46 
48 
153  : version(version), type(type), state(QStyle::State_None),
155 {
156 }
157 
158 
163 {
164 }
165 
180 {
181  QWidget *window = widget->window();
183  if (widget->isEnabled())
185  if (widget->hasFocus())
187  if (window->testAttribute(Qt::WA_KeyboardFocusChange))
189  if (widget->underMouse())
191  if (window->isActiveWindow())
193  if (widget->isWindow())
198  break;
201  break;
202  default:
203  ;
204  }
205 #ifdef QT_KEYPAD_NAVIGATION
206  if (widget->hasEditFocus())
207  state |= QStyle::State_HasEditFocus;
208 #endif
209 
211  rect = widget->rect();
212  palette = widget->palette();
214  styleObject = const_cast<QWidget*>(widget);
215 }
216 
224 {
225 }
226 
231 {
232  state = other.state;
233  direction = other.direction;
234  rect = other.rect;
235  fontMetrics = other.fontMetrics;
236  palette = other.palette;
237  styleObject = other.styleObject;
238  return *this;
239 }
240 
381 {
382 }
383 
388  : QStyleOption(version, SO_FocusRect)
389 {
390  state |= QStyle::State_KeyboardFocusChange; // assume we had one, will be corrected in initFrom()
391 }
392 
480 {
481 }
482 
487  : QStyleOption(version, SO_Frame), lineWidth(0), midLineWidth(0),
488  features(None), frameShape(QFrame::NoFrame)
489 {
490 }
491 
692 {
693 }
694 
706  textAlignment(Qt::AlignLeft), lineWidth(0), midLineWidth(0)
707 {
708 }
709 
740 {
741 }
742 
747  : QStyleOption(version, SO_Header),
748  section(0), textAlignment(Qt::AlignLeft), iconAlignment(Qt::AlignLeft),
749  position(QStyleOptionHeader::Beginning),
750  selectedPosition(QStyleOptionHeader::NotAdjacent), sortIndicator(None),
751  orientation(Qt::Horizontal)
752 {
753 }
754 
908 {
909 }
910 
915 : QStyleOptionHeader(version), textElideMode(Qt::ElideNone), isSectionDragTarget(false), unused(0)
916 {}
917 
982 {
983 }
984 
989  : QStyleOption(version, SO_Button), features(None)
990 {
991 }
992 
1062 #if QT_CONFIG(toolbar)
1104 QStyleOptionToolBar::QStyleOptionToolBar()
1105  : QStyleOptionToolBar(Version)
1106 {
1107 }
1108 
1118 QStyleOptionToolBar::QStyleOptionToolBar(int version)
1119 : QStyleOption(version, SO_ToolBar), positionOfLine(OnlyOne), positionWithinLine(OnlyOne),
1120  toolBarArea(Qt::TopToolBarArea), features(None), lineWidth(0), midLineWidth(0)
1121 {
1122 
1123 }
1124 
1247 #endif
1248 
1249 #if QT_CONFIG(tabbar)
1288 QStyleOptionTab::QStyleOptionTab()
1289  : QStyleOptionTab(QStyleOptionTab::Version)
1290 {
1291 }
1292 
1296 QStyleOptionTab::QStyleOptionTab(int version)
1297  : QStyleOption(version, SO_Tab),
1298  shape(QTabBar::RoundedNorth),
1299  row(0),
1300  position(Beginning),
1301  selectedPosition(NotAdjacent), cornerWidgets(QStyleOptionTab::NoCornerWidgets),
1302  documentMode(false),
1303  features(QStyleOptionTab::None)
1304 {
1305 }
1306 
1488 #endif // QT_CONFIG(tabbar)
1489 
1527 {
1528 }
1529 
1534  : QStyleOption(version, SO_ProgressBar),
1535  minimum(0), maximum(0), progress(0), textAlignment(Qt::AlignLeft), textVisible(false),
1536  invertedAppearance(false), bottomToTop(false)
1537 {
1539 }
1540 
1688 {
1689 }
1690 
1695  : QStyleOption(version, SO_MenuItem), menuItemType(Normal),
1696  checkType(NotCheckable), checked(false), menuHasCheckableItems(true), maxIconWidth(0),
1697  reservedShortcutWidth(0)
1698 {
1699 }
1700 
1891  : QStyleOption(version, type), subControls(QStyle::SC_All), activeSubControls(QStyle::SC_None)
1892 {
1893 }
1894 
1954 #if QT_CONFIG(slider)
1982 QStyleOptionSlider::QStyleOptionSlider()
1983  : QStyleOptionSlider(Version)
1984 {
1985 }
1986 
1990 QStyleOptionSlider::QStyleOptionSlider(int version)
1991  : QStyleOptionComplex(version, SO_Slider), orientation(Qt::Horizontal), minimum(0), maximum(0),
1992  tickPosition(QSlider::NoTicks), tickInterval(0), upsideDown(false),
1993  sliderPosition(0), sliderValue(0), singleStep(0), pageStep(0), notchTarget(0.0),
1994  dialWrapping(false), keyboardModifiers{}
1995 {
1996 }
1997 
2149 #endif // QT_CONFIG(slider)
2150 
2151 #if QT_CONFIG(spinbox)
2179 QStyleOptionSpinBox::QStyleOptionSpinBox()
2180  : QStyleOptionSpinBox(Version)
2181 {
2182 }
2183 
2187 QStyleOptionSpinBox::QStyleOptionSpinBox(int version)
2188  : QStyleOptionComplex(version, SO_SpinBox), buttonSymbols(QAbstractSpinBox::UpDownArrows),
2189  stepEnabled(QAbstractSpinBox::StepNone), frame(false)
2190 {
2191 }
2192 
2255 #endif // QT_CONFIG(spinbox)
2256 
2286 {
2287 }
2288 
2293  : QStyleOption(version, SO_DockWidget), closable(false),
2294  movable(false), floatable(false), verticalTitleBar(false)
2295 {
2296 }
2297 
2407 {
2408 }
2409 
2414  : QStyleOptionComplex(version, SO_ToolButton), features(None), arrowType(Qt::DownArrow)
2415  , toolButtonStyle(Qt::ToolButtonIconOnly)
2416 
2417 {
2418 }
2419 
2556 {
2557 }
2558 
2563  : QStyleOptionComplex(version, SO_ComboBox), editable(false), frame(true)
2564 {
2565 }
2566 
2692 {
2693 }
2694 
2699  : QStyleOption(version, SO_ToolBox), position(Beginning), selectedPosition(NotAdjacent)
2700 {
2701 }
2702 
2789 #if QT_CONFIG(rubberband)
2817 QStyleOptionRubberBand::QStyleOptionRubberBand()
2818  : QStyleOptionRubberBand(Version)
2819 {
2820 }
2821 
2825 QStyleOptionRubberBand::QStyleOptionRubberBand(int version)
2826  : QStyleOption(version, SO_RubberBand), shape(QRubberBand::Line), opaque(false)
2827 {
2828 }
2829 
2880 #endif // QT_CONFIG(rubberband)
2881 
2911 {
2912 }
2913 
2955  : QStyleOptionComplex(version, SO_TitleBar), titleBarState(0)
2956 {
2957 }
2958 
2959 
2994 #if QT_CONFIG(itemviews)
3059 QStyleOptionViewItem::QStyleOptionViewItem()
3060  : QStyleOptionViewItem(Version)
3061 {
3062 }
3063 
3067 QStyleOptionViewItem::QStyleOptionViewItem(int version)
3068  : QStyleOption(version, SO_ViewItem),
3069  displayAlignment(Qt::AlignLeft), decorationAlignment(Qt::AlignLeft),
3070  textElideMode(Qt::ElideMiddle), decorationPosition(Left),
3071  showDecorationSelected(false), features(None), widget(nullptr),
3072  checkState(Qt::Unchecked), viewItemPosition(QStyleOptionViewItem::Invalid)
3073 {
3074 }
3075 
3234 #endif // QT_CONFIG(itemviews)
3257 #if QT_CONFIG(tabwidget)
3284 QStyleOptionTabWidgetFrame::QStyleOptionTabWidgetFrame()
3285  : QStyleOptionTabWidgetFrame(Version)
3286 {
3287 }
3288 
3296 QStyleOptionTabWidgetFrame::QStyleOptionTabWidgetFrame(int version)
3297  : QStyleOption(version, SO_TabWidgetFrame), lineWidth(0), midLineWidth(0),
3298  shape(QTabBar::RoundedNorth)
3299 {
3300 }
3301 
3393 #endif // QT_CONFIG(tabwidget)
3394 
3395 #if QT_CONFIG(tabbar)
3396 
3426 QStyleOptionTabBarBase::QStyleOptionTabBarBase()
3427  : QStyleOptionTabBarBase(Version)
3428 {
3429 }
3430 
3432 QStyleOptionTabBarBase::QStyleOptionTabBarBase(int version)
3433  : QStyleOption(version, SO_TabBarBase), shape(QTabBar::RoundedNorth),
3434  documentMode(false)
3435 {
3436 }
3437 
3507 #endif // QT_CONFIG(tabbar)
3508 
3509 #if QT_CONFIG(sizegrip)
3537 {
3538 }
3539 
3551 {
3552 }
3553 
3590 #endif // QT_CONFIG(sizegrip)
3591 
3648 {
3649 }
3650 
3656 {
3657 }
3658 
3673 {
3674  if (worldTransform.type() <= QTransform::TxTranslate)
3675  return 1; // Translation only? The LOD is 1.
3676 
3677  // Two unit vectors.
3678  QLineF v1(0, 0, 1, 0);
3679  QLineF v2(0, 0, 0, 1);
3680  // LOD is the transformed area of a 1x1 rectangle.
3681  return qSqrt(worldTransform.map(v1).length() * worldTransform.map(v2).length());
3682 }
3683 
3784  : version(version), type(type)
3785 {
3786 }
3787 
3793 {
3794 
3795 }
3796 
3815 {
3816 }
3817 
3822 {
3823 }
3824 
3875 {
3876 }
3877 
3882 {
3883 }
3884 
3939 #if !defined(QT_NO_DEBUG_STREAM)
3941 {
3942 #if !defined(QT_NO_DEBUG)
3943  switch (optionType) {
3945  debug << "SO_Default"; break;
3947  debug << "SO_FocusRect"; break;
3949  debug << "SO_Button"; break;
3950  case QStyleOption::SO_Tab:
3951  debug << "SO_Tab"; break;
3953  debug << "SO_MenuItem"; break;
3955  debug << "SO_Frame"; break;
3957  debug << "SO_ProgressBar"; break;
3959  debug << "SO_ToolBox"; break;
3961  debug << "SO_Header"; break;
3963  debug << "SO_DockWidget"; break;
3965  debug << "SO_ViewItem"; break;
3967  debug << "SO_TabWidgetFrame"; break;
3969  debug << "SO_TabBarBase"; break;
3971  debug << "SO_RubberBand"; break;
3973  debug << "SO_Complex"; break;
3975  debug << "SO_Slider"; break;
3977  debug << "SO_SpinBox"; break;
3979  debug << "SO_ToolButton"; break;
3981  debug << "SO_ComboBox"; break;
3983  debug << "SO_TitleBar"; break;
3985  debug << "SO_CustomBase"; break;
3987  debug << "SO_GroupBox"; break;
3989  debug << "SO_ToolBar"; break;
3991  debug << "SO_ComplexCustomBase"; break;
3993  debug << "SO_SizeGrip"; break;
3995  debug << "SO_GraphicsItem"; break;
3996  }
3997 #else
3998  Q_UNUSED(optionType);
3999 #endif
4000  return debug;
4001 }
4002 
4004 {
4005 #if !defined(QT_NO_DEBUG)
4006  debug << "QStyleOption(";
4008  debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight");
4009  debug << ',' << option.state;
4010  debug << ',' << option.rect;
4011  debug << ',' << option.styleObject;
4012  debug << ')';
4013 #else
4014  Q_UNUSED(option);
4015 #endif
4016  return debug;
4017 }
4018 #endif
4019 
The QAbstractSpinBox class provides a spinbox and a line edit to display values.
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
The QFont class specifies a query for a font used for drawing text.
Definition: qfont.h:56
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:53
The QGuiApplication class manages the GUI application's control flow and main settings.
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:215
The QRubberBand class provides a rectangle or line that can indicate a selection or a boundary.
Definition: qrubberband.h:54
The QSlider widget provides a vertical or horizontal slider.
Definition: qslider.h:54
the exposed rectangle, in item coordinates
Definition: qstyleoption.h:724
QStyleHintReturn(int version=QStyleOption::Version, int type=SH_Default)
the type of the style hint container
QStyleHintReturnMask()
the region for style hints that return a QRegion
QStyleHintReturnVariant()
the variant for style hints that return a QVariant
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
@ State_Window
Definition: qstyle.h:120
@ State_MouseOver
Definition: qstyle.h:116
@ State_HasFocus
Definition: qstyle.h:111
@ State_Active
Definition: qstyle.h:119
@ State_Mini
Definition: qstyle.h:132
@ State_Small
Definition: qstyle.h:131
@ State_KeyboardFocusChange
Definition: qstyle.h:126
@ State_Enabled
Definition: qstyle.h:103
@ State_Horizontal
Definition: qstyle.h:110
@ State_None
Definition: qstyle.h:102
where ellipsis should be added for text that is too long to fit into an item
Definition: qstyleoption.h:251
an OR combination of the tool button's features
Definition: qstyleoption.h:608
the type of menu item
Definition: qstyleoption.h:515
QStyleOptionComplex(int version=QStyleOptionComplex::Version, int type=SO_Complex)
The QStyleOptionDockWidget class is used to describe the parameters for drawing a dock widget.
Definition: qstyleoption.h:398
the palette that should be used when painting the control
Definition: qstyleoption.h:111
the background color on which the focus rectangle is being drawn
Definition: qstyleoption.h:127
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem.
Definition: qstyleoption.h:684
static qreal levelOfDetailFromTransform(const QTransform &worldTransform)
a bitwise OR of the features that describe this frame.
Definition: qstyleoption.h:649
QStyleOptionGroupBox()
the line width for drawing the panel
The QStyleOptionHeader class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:204
The QStyleOptionHeaderV2 class is used to describe the parameters for drawing a header.
Definition: qstyleoption.h:233
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:75
@ SO_ComplexCustomBase
Definition: qstyleoption.h:87
QFontMetrics fontMetrics
Definition: qstyleoption.h:98
QStyle::State state
Definition: qstyleoption.h:95
QPalette palette
Definition: qstyleoption.h:99
QStyleOption(int version=QStyleOption::Version, int type=SO_Default)
void initFrom(const QWidget *w)
QObject * styleObject
Definition: qstyleoption.h:100
Qt::LayoutDirection direction
Definition: qstyleoption.h:96
QStyleOption & operator=(const QStyleOption &other)
the minimum value for the progress bar
Definition: qstyleoption.h:369
a bitwise OR of the features that describe this button
Definition: qstyleoption.h:346
the position of the selected tab in relation to this tab
Definition: qstyleoption.h:630
whether or not the combobox is editable or not
Definition: qstyleoption.h:472
the title of the dock window
Definition: qstyleoption.h:579
The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs.
Definition: qtabbar.h:55
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:56
QPoint map(const QPoint &p) const
TransformationType type() const
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
QWidget * window() const
Definition: qwidget.cpp:4319
Qt::LayoutDirection layoutDirection
the layout direction for this widget.
Definition: qwidget.h:204
QPalette palette
the widget's palette
Definition: qwidget.h:166
QFontMetrics fontMetrics() const
Definition: qwidget.h:880
QRect rect
the internal geometry of the widget excluding any window frame
Definition: qwidget.h:150
bool isEnabled() const
Definition: qwidget.h:847
bool hasFocus() const
Definition: qwidget.cpp:6430
bool underMouse() const
Definition: qwidget.h:892
bool isWindow() const
Definition: qwidget.h:844
QOpenGLWidget * widget
[1]
rect
[4]
direction
fontMetrics
palette
else opt state
[0]
int const char * version
Definition: zlib.h:814
#define true
Definition: ftrandom.c:51
QHighDpiScaling::Point position(T, QHighDpiScaling::Point::Kind)
@ OnlyOne
Definition: qprint_p.h:129
WidgetSizePolicy widgetSizePolicy(const QWidget *widget, const QStyleOption *opt)
Definition: qnamespace.h:55
@ BottomRightCorner
Definition: qnamespace.h:1291
@ Unchecked
Definition: qnamespace.h:1496
@ AlignLeft
Definition: qnamespace.h:169
@ WA_KeyboardFocusChange
Definition: qnamespace.h:369
@ TopToolBarArea
Definition: qnamespace.h:1237
@ RightToLeft
Definition: qnamespace.h:1464
@ Horizontal
Definition: qnamespace.h:124
@ DownArrow
Definition: qnamespace.h:1106
@ ElideMiddle
Definition: qnamespace.h:216
@ ElideNone
Definition: qnamespace.h:217
@ ToolButtonIconOnly
Definition: qnamespace.h:1455
#define None
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
auto qSqrt(T v)
Definition: qmath.h:132
@ Invalid
Definition: qmetaobject_p.h:68
GLenum type
Definition: qopengl.h:270
GLint GLfloat GLfloat GLfloat v2
GLint GLfloat GLfloat v1
GLenum GLenum GLsizei void * row
Definition: qopenglext.h:2747
GLuint GLenum option
Definition: qopenglext.h:5929
@ Left
#define v1
QObject * styleObject(const QStyleOption *option)
Q_UNUSED(salary)
[21]
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]
aWidget window() -> setWindowTitle("New Window Title")
[2]
QFrame frame
[0]
Definition: moc.h:48