QtBase  v6.3.1
doc_src_styles.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 documentation of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:BSD$
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 ** BSD License Usage
18 ** Alternatively, you may use this file under the terms of the BSD license
19 ** as follows:
20 **
21 ** "Redistribution and use in source and binary forms, with or without
22 ** modification, are permitted provided that the following conditions are
23 ** met:
24 ** * Redistributions of source code must retain the above copyright
25 ** notice, this list of conditions and the following disclaimer.
26 ** * Redistributions in binary form must reproduce the above copyright
27 ** notice, this list of conditions and the following disclaimer in
28 ** the documentation and/or other materials provided with the
29 ** distribution.
30 ** * Neither the name of The Qt Company Ltd nor the names of its
31 ** contributors may be used to endorse or promote products derived
32 ** from this software without specific prior written permission.
33 **
34 **
35 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
46 **
47 ** $QT_END_LICENSE$
48 **
49 ****************************************************************************/
50 
53  if (down)
55  if (tristate && noChange)
57  else
58  opt.state |= checked ? QStyle::State_On :
60  if (q->testAttribute(Qt::WA_Hover) && q->underMouse()) {
61  if (hovering)
63  else
64  opt.state &= ~QStyle::State_MouseOver;
65  }
68  opt.iconSize = q->iconSize();
70 
71 
74  if (widget->isEnabled())
76  if (widget->hasFocus())
80  if (widget->underMouse())
84 #ifdef QT_KEYPAD_NAVIGATION
85  if (widget->hasEditFocus())
86  state |= QStyle::State_HasEditFocus;
87 #endif
88 
94 
95 
98  QStyleOptionButton opt = d->getStyleOption();
99  p.drawControl(QStyle::CE_CheckBox, opt);
101 
102 
105  subopt.rect = subElementRect(SE_CheckBoxIndicator, btn, widget);
106  drawPrimitive(PE_IndicatorCheckBox, &subopt, p, widget);
107  subopt.rect = subElementRect(SE_CheckBoxContents, btn, widget);
108  drawControl(CE_CheckBoxLabel, &subopt, p, widget);
109 
110  if (btn->state & State_HasFocus) {
111  QStyleOptionFocusRect fropt;
112  fropt.QStyleOption::operator=(*btn);
113  fropt.rect = subElementRect(SE_CheckBoxFocusRect, btn, widget);
114  drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
115  }
117 
118 
120  const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt);
122 
123  if (!styleHint(SH_UnderlineShortcut, btn, widget))
127  if (!btn->icon.isNull()) {
128  pix = btn->icon.pixmap(btn->iconSize, btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
129  drawItemPixmap(p, btn->rect, alignment, pix);
130  if (btn->direction == Qt::RightToLeft)
132  else
134  }
135  if (!btn->text.isEmpty()){
136  drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
137  btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);
138  }
bool isNull() const
Definition: qicon.cpp:1002
@ Disabled
Definition: qicon.h:58
@ Normal
Definition: qicon.h:58
QPixmap pixmap(const QSize &size, Mode mode=Normal, State state=Off) const
Definition: qicon.cpp:817
@ WindowText
Definition: qpalette.h:86
The QPixmap class is an off-screen image representation that can be used as a paint device.
Definition: qpixmap.h:63
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
constexpr void setRight(int pos) noexcept
Definition: qrect.h:224
constexpr void setLeft(int pos) noexcept
Definition: qrect.h:218
constexpr int left() const noexcept
Definition: qrect.h:200
constexpr int right() const noexcept
Definition: qrect.h:206
constexpr int width() const noexcept
Definition: qsize.h:157
bool isEmpty() const
Definition: qstring.h:1216
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition: qstyle.h:65
@ State_MouseOver
Definition: qstyle.h:116
@ State_Sunken
Definition: qstyle.h:105
@ State_HasFocus
Definition: qstyle.h:111
@ State_Active
Definition: qstyle.h:119
@ State_Off
Definition: qstyle.h:106
@ State_NoChange
Definition: qstyle.h:107
@ State_KeyboardFocusChange
Definition: qstyle.h:126
@ State_Enabled
Definition: qstyle.h:103
@ State_On
Definition: qstyle.h:108
@ State_None
Definition: qstyle.h:102
@ CE_CheckBox
Definition: qstyle.h:211
where ellipsis should be added for text that is too long to fit into an item
Definition: qstyleoption.h:251
the palette that should be used when painting the control
Definition: qstyleoption.h:111
QStyle::State state
Definition: qstyleoption.h:95
QPalette palette
Definition: qstyleoption.h:99
void initFrom(const QWidget *w)
Qt::LayoutDirection direction
Definition: qstyleoption.h:96
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
Definition: qstylepainter.h:52
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 isActiveWindow
whether this widget's window is the active window
Definition: qwidget.h:173
bool testAttribute(Qt::WidgetAttribute) const
Definition: qwidget.h:943
QOpenGLWidget * widget
[1]
opt icon
drawPrimitive(PE_IndicatorCheckBox, &subopt, p, widget)
rect
[4]
QPixmap pix
QStyleOptionButton subopt
[2]
uint alignment
opt text
QStylePainter p(this)
[1]
direction
QStyleOptionButton opt
fontMetrics
p drawControl(QStyle::CE_CheckBox, opt)
palette
else opt state
[0]
QRect textRect
const QStyleOptionButton * btn
[3]
@ AlignVCenter
Definition: qnamespace.h:180
@ AlignLeft
Definition: qnamespace.h:169
@ WA_Hover
Definition: qnamespace.h:365
@ WA_KeyboardFocusChange
Definition: qnamespace.h:369
@ RightToLeft
Definition: qnamespace.h:1464
@ TextHideMnemonic
Definition: qnamespace.h:203
@ TextShowMnemonic
Definition: qnamespace.h:198
unsigned int uint
Definition: qglobal.h:334
GLdouble GLdouble GLdouble GLdouble q
Definition: qopenglext.h:259
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698