summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles/qstyle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/styles/qstyle.cpp')
-rw-r--r--src/widgets/styles/qstyle.cpp122
1 files changed, 37 insertions, 85 deletions
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index 04c110a662..60b2f51e95 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtWidgets module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qstyle.h"
#include "qapplication.h"
@@ -285,9 +249,6 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C
widget is a QSpinBox just because the enum value is called
PE_IndicatorSpinUp or PE_IndicatorSpinDown.
- The documentation for the \l{widgets/styles}{Styles} example
- covers this topic in more detail.
-
\warning Qt style sheets are currently not supported for custom QStyle
subclasses. We plan to address this in some future release.
@@ -388,7 +349,7 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C
The drawing of item view headers is also done by the style, giving
control over size of header items and row and column sizes.
- \sa QStyleOption, QStylePainter, {Styles Example},
+ \sa QStyleOption, QStylePainter,
{Styles and Style Aware Widgets}, QStyledItemDelegate, {Styling}
*/
@@ -412,6 +373,9 @@ QStyle::QStyle(QStylePrivate &dd)
{
Q_D(QStyle);
d->proxyStyle = this;
+ Q_STATIC_ASSERT_X(int(StandardPixmap::NStandardPixmap) ==
+ int(QPlatformTheme::StandardPixmap::NStandardPixmap),
+ "StandardPixmap in QPlatformTheme and QStyle out of sync");
}
/*!
@@ -1504,24 +1468,19 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value PM_SubMenuOverlap The horizontal overlap between a submenu and its parent.
- \value PM_TreeViewIndentation The indentation of items in a tree view.
- This enum value has been introduced in Qt 5.4.
+ \value [since 5.4] PM_TreeViewIndentation The indentation of items in a tree view.
\value PM_HeaderDefaultSectionSizeHorizontal The default size of sections
in a horizontal header. This enum value has been introduced in Qt 5.5.
\value PM_HeaderDefaultSectionSizeVertical The default size of sections
in a vertical header. This enum value has been introduced in Qt 5.5.
- \value PM_TitleBarButtonIconSize The size of button icons on a title bar.
- This enum value has been introduced in Qt 5.8.
- \value PM_TitleBarButtonSize The size of buttons on a title bar.
- This enum value has been introduced in Qt 5.8.
+ \value [since 5.8] PM_TitleBarButtonIconSize The size of button icons on a title bar.
+ \value [since 5.8] PM_TitleBarButtonSize The size of buttons on a title bar.
- \value PM_LineEditIconSize The default size for icons in a line edit.
- This enum value has been introduced in Qt 6.2.
+ \value [since 6.2] PM_LineEditIconSize The default size for icons in a line edit.
- \value PM_LineEditIconMargin The margin around icons in a line edit.
- This enum value has been introduced in Qt 6.3.
+ \value [since 6.3] PM_LineEditIconMargin The margin around icons in a line edit.
\value PM_CustomBase Base value for custom pixel metrics. Custom
values must be greater than this value.
@@ -1535,8 +1494,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
Returns the value of the given pixel \a metric.
The specified \a option and \a widget can be used for calculating
- the metric. In general, the \a widget argument is not used. The \a
- option can be cast to the appropriate type using the
+ the metric. The \a option can be cast to the appropriate type using the
qstyleoption_cast() function. Note that the \a option may be zero
even for PixelMetrics that can make use of it. See the table below
for the appropriate \a option casts:
@@ -1725,7 +1683,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
the line edit receives focus, as done on Windows.
\value SH_Menu_KeyboardSearch Typing causes a menu to be search
- for relevant items, otherwise only mnemnonic is considered.
+ for relevant items, otherwise only mnemonic is considered.
\value SH_Menu_AllowActiveAndDisabled Allows disabled menu
items to be active.
@@ -1853,9 +1811,8 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
spinbox mouse clicks.
\value SH_SpinBox_ClickAutoRepeatThreshold Auto-repeat threshold for
spinbox mouse clicks.
- \value SH_SpinBox_SelectOnStep Whether changing the value using
- the buttons or up/down keys automatically selects the text. This enum
- value has been introduced in Qt 6.3.
+ \value [since 6.3] SH_SpinBox_SelectOnStep Whether changing the value using
+ the buttons or up/down keys automatically selects the text.
\value SH_ToolTipLabel_Opacity An integer indicating the opacity for
the tip label, 0 is completely transparent, 255 is completely
@@ -2024,7 +1981,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SH_Table_AlwaysDrawLeftTopGridLines
Determines if the far left and top grid lines are drawn in a table or
not when the header is hidden. Defaults to false.
- This enum value has been introduced in Qt 6.2.
+ This enum value has been introduced in Qt 6.3.
\sa styleHint()
*/
@@ -2117,23 +2074,16 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
\value SP_MediaSeekBackward Icon indicating that media should seek backward.
\value SP_MediaVolume Icon indicating a volume control.
\value SP_MediaVolumeMuted Icon indicating a muted volume control.
- \value SP_LineEditClearButton Icon for a standard clear button in a QLineEdit. This enum value was added in Qt 5.2.
- \value SP_DialogYesToAllButton Icon for a standard YesToAll button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_DialogNoToAllButton Icon for a standard NoToAll button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_DialogSaveAllButton Icon for a standard SaveAll button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_DialogAbortButton Icon for a standard Abort button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_DialogRetryButton Icon for a standard Retry button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_DialogIgnoreButton Icon for a standard Ignore button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_RestoreDefaultsButton Icon for a standard RestoreDefaults button in a QDialogButtonBox.
- This enum value was added in Qt 5.14.
- \value SP_TabCloseButton Icon for the close button in the tab of a QTabBar.
- This enum value was added in Qt 6.3.
+ \value [since 5.2] SP_LineEditClearButton Icon for a standard clear button in a QLineEdit.
+ \value [since 5.14] SP_DialogYesToAllButton Icon for a standard YesToAll button in a QDialogButtonBox.
+ \value [since 5.14] SP_DialogNoToAllButton Icon for a standard NoToAll button in a QDialogButtonBox.
+ \value [since 5.14] SP_DialogSaveAllButton Icon for a standard SaveAll button in a QDialogButtonBox.
+ \value [since 5.14] SP_DialogAbortButton Icon for a standard Abort button in a QDialogButtonBox.
+ \value [since 5.14] SP_DialogRetryButton Icon for a standard Retry button in a QDialogButtonBox.
+ \value [since 5.14] SP_DialogIgnoreButton Icon for a standard Ignore button in a QDialogButtonBox.
+ \value [since 5.14] SP_RestoreDefaultsButton Icon for a standard RestoreDefaults button in a QDialogButtonBox.
+ \value [since 6.3] SP_TabCloseButton Icon for the close button in the tab of a QTabBar.
+ \omitvalue NStandardPixmap
\value SP_CustomBase Base value for custom standard pixmaps;
custom values must be greater than this value.
@@ -2271,13 +2221,15 @@ Qt::Alignment QStyle::visualAlignment(Qt::LayoutDirection direction, Qt::Alignme
int QStyle::sliderPositionFromValue(int min, int max, int logicalValue, int span, bool upsideDown)
{
- if (span <= 0 || logicalValue < min || max <= min)
+ if (span <= 0 || max <= min)
return 0;
+ if (logicalValue < min)
+ return upsideDown ? span : 0;
if (logicalValue > max)
- return upsideDown ? span : min;
+ return upsideDown ? 0 : span;
- uint range = max - min;
- uint p = upsideDown ? max - logicalValue : logicalValue - min;
+ const uint range = qint64(max) - min;
+ const uint p = upsideDown ? qint64(max) - logicalValue : qint64(logicalValue) - min;
if (range > (uint)INT_MAX/4096) {
double dpos = (double(p))/(double(range)/span);
@@ -2319,15 +2271,15 @@ int QStyle::sliderValueFromPosition(int min, int max, int pos, int span, bool up
if (pos >= span)
return upsideDown ? min : max;
- uint range = max - min;
+ const qint64 range = qint64(max) - min;
if ((uint)span > range) {
- int tmp = (2 * pos * range + span) / (2 * span);
+ const int tmp = (2 * range * pos + span) / (qint64(2) * span);
return upsideDown ? max - tmp : tmp + min;
} else {
- uint div = range / span;
- uint mod = range % span;
- int tmp = pos * div + (2 * pos * mod + span) / (2 * span);
+ const qint64 div = range / span;
+ const qint64 mod = range % span;
+ const int tmp = pos * div + (2 * mod * pos + span) / (qint64(2) * span);
return upsideDown ? max - tmp : tmp + min;
}
// equiv. to min + (pos*range)/span + 0.5