diff options
Diffstat (limited to 'src/widgets/styles/qstyle.cpp')
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 180 |
1 files changed, 88 insertions, 92 deletions
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index a4fe0365f9..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" @@ -91,7 +55,7 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C look of the different platforms supported by Qt (QWindowsStyle, QMacStyle, etc.). These styles are built into the Qt GUI module, other styles can be made available using Qt's - plugin mechansim. + plugin mechanism. Most functions for drawing style elements take four arguments: @@ -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. @@ -372,7 +333,7 @@ static int unpackControlTypes(QSizePolicy::ControlTypes controls, QSizePolicy::C We include a small example where we customize the drawing of item backgrounds. - \snippet customviewstyle.cpp 0 + \snippet customviewstyle/customviewstyle.cpp 0 The primitive element PE_PanelItemViewItem is responsible for painting the background of items, and is called from @@ -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"); } /*! @@ -422,6 +386,30 @@ QStyle::~QStyle() } /*! + Returns the name of the style. + + This value can be used to create a style with QStyleFactory::create(). + + \sa QStyleFactory::create() + \since 6.1 +*/ +QString QStyle::name() const +{ + Q_D(const QStyle); + return d->name; +} + +/*! + \internal + Set the style name +*/ +void QStyle::setName(const QString &name) +{ + Q_D(QStyle); + d->name = name; +} + +/*! Initializes the appearance of the given \a widget. This function is called for every widget at some point after it @@ -549,8 +537,9 @@ QRect QStyle::itemPixmapRect(const QRect &rect, int alignment, const QPixmap &pi int x, y, w, h; rect.getRect(&x, &y, &w, &h); - const int pixmapWidth = pixmap.width()/pixmap.devicePixelRatio(); - const int pixmapHeight = pixmap.height()/pixmap.devicePixelRatio(); + QSizeF pixmapSize = pixmap.deviceIndependentSize(); + const int pixmapWidth = pixmapSize.width(); + const int pixmapHeight = pixmapSize.height(); if ((alignment & Qt::AlignVCenter) == Qt::AlignVCenter) y += h/2 - pixmapHeight/2; @@ -627,7 +616,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, QRect aligned = alignedRect(QGuiApplication::layoutDirection(), QFlag(alignment), pixmap.size() / scale, rect); QRect inter = aligned.intersected(rect); - painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), inter.width() * scale, inter.height() *scale); + painter->drawPixmap(inter.x(), inter.y(), pixmap, inter.x() - aligned.x(), inter.y() - aligned.y(), qRound(inter.width() * scale), qRound(inter.height() *scale)); } /*! @@ -637,8 +626,6 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, primitive element is a common GUI element, such as a checkbox indicator or button bevel. - \omitvalue PE_IndicatorViewItemCheck - \value PE_PanelButtonCommand Button used to initiate an action, for example, a QPushButton. @@ -696,7 +683,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value PE_IndicatorToolBarSeparator The separator in a toolbar. \value PE_PanelToolBar The panel for a toolbar. \value PE_PanelTipLabel The panel for a tip label. - \value PE_FrameTabBarBase The frame that is drawn for a tab bar, ususally drawn for a tab bar that isn't part of a tab widget. + \value PE_FrameTabBarBase The frame that is drawn for a tab bar, usually drawn for a tab bar that isn't part of a tab widget. \value PE_IndicatorTabTear Deprecated. Use \l{PE_IndicatorTabTearLeft} instead. \value PE_IndicatorTabTearLeft An indicator that a tab is partially scrolled out on the left side of the visible tab bar when there are many tabs. \value PE_IndicatorTabTearRight An indicator that a tab is partially scrolled out on the right side of the visible tab bar when there are many tabs. @@ -1481,18 +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 [since 6.2] PM_LineEditIconSize The default size for icons in a line edit. + + \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. @@ -1506,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: @@ -1696,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. @@ -1774,7 +1761,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, cause a list view expansion to be selected. \value SH_TabBar_PreferNoArrows Whether a tab bar should suggest a size - to prevent scoll arrows. + to prevent scroll arrows. \value SH_ComboBox_Popup Allows popups as a combobox drop-down menu. @@ -1816,9 +1803,6 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, \value SH_UnderlineShortcut Whether shortcuts are underlined. - \value SH_SpellCheckUnderlineStyle Obsolete. Use SpellCheckUnderlineStyle - hint in QPlatformTheme instead. - \value SH_SpinBox_AnimateButton Animate a click when up or down is pressed in a spin box. \value SH_SpinBox_KeyPressAutoRepeatRate Auto-repeat interval for @@ -1827,6 +1811,9 @@ 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 [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 opaque. @@ -1986,6 +1973,16 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, disables this feature. This enum value has been introduced in Qt 5.12. + \value SH_TabBar_AllowWheelScrolling + Determines if the mouse wheel can be used to cycle through the tabs + of a QTabBar. + This enum value has been introduced in Qt 6.1. + + \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.3. + \sa styleHint() */ @@ -2077,21 +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 [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. @@ -2118,7 +2110,7 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, /*! \fn QPixmap QStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *option, const QWidget *widget) const - \obsolete + \deprecated Returns a pixmap for the given \a standardPixmap. A standard pixmap is a pixmap that can follow some existing GUI @@ -2229,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); @@ -2277,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 @@ -2322,8 +2316,8 @@ QPalette QStyle::standardPalette() const /*! \since 4.1 - \fn QIcon QStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option = 0, - const QWidget *widget = 0) const = 0; + \fn QIcon QStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option = nullptr, + const QWidget *widget = nullptr) const = 0; Returns an icon for the given \a standardIcon. @@ -2406,17 +2400,19 @@ int QStyle::combinedLayoutSpacing(QSizePolicy::ControlTypes controls1, const QStyle * QStyle::proxy() const { Q_D(const QStyle); - return d->proxyStyle; + return d->proxyStyle == this ? this : d->proxyStyle->proxy(); } /* \internal This function sets the base style that style calls will be - redirected to. Note that ownership is not transferred. + redirected to. Note that ownership is not transferred. \a style + must be a valid pointer (not nullptr). */ void QStyle::setProxy(QStyle *style) { Q_D(QStyle); + Q_ASSERT(style); d->proxyStyle = style; } |