diff options
Diffstat (limited to 'src/widgets/styles/qwindowsstyle.cpp')
-rw-r--r-- | src/widgets/styles/qwindowsstyle.cpp | 389 |
1 files changed, 145 insertions, 244 deletions
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 12ca5201c1..bae182b467 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.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 "qwindowsstyle_p.h" #include "qwindowsstyle_p_p.h" @@ -78,12 +42,15 @@ #endif #include <private/qmath_p.h> #include <qmath.h> +#include <QtGui/qpainterpath.h> #include <QtGui/qscreen.h> #include <QtGui/qwindow.h> #include <qpa/qplatformtheme.h> #include <qpa/qplatformscreen.h> #include <private/qguiapplication_p.h> #include <private/qhighdpiscaling_p.h> +#include <qpa/qplatformintegration.h> +#include <private/qwidget_p.h> #include <private/qstylehelper_p.h> #if QT_CONFIG(animation) @@ -119,15 +86,7 @@ enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; \internal */ -QWindowsStylePrivate::QWindowsStylePrivate() - : alt_down(false), menuBarTimer(0) -{ -} - -qreal QWindowsStylePrivate::appDevicePixelRatio() -{ - return qApp->devicePixelRatio(); -} +QWindowsStylePrivate::QWindowsStylePrivate() = default; // Returns \c true if the toplevel parent of \a widget has seen the Alt-key bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const @@ -153,19 +112,20 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) widget = widget->window(); // Alt has been pressed - find all widgets that care - QList<QWidget *> l = widget->findChildren<QWidget *>(); + const QList<QWidget *> children = widget->findChildren<QWidget *>(); auto ignorable = [](QWidget *w) { return w->isWindow() || !w->isVisible() - || w->style()->styleHint(SH_UnderlineShortcut, 0, w); + || w->style()->styleHint(SH_UnderlineShortcut, nullptr, w); }; - l.erase(std::remove_if(l.begin(), l.end(), ignorable), l.end()); // Update states before repainting d->seenAlt.append(widget); d->alt_down = true; // Repaint all relevant widgets - for (int pos = 0; pos < l.size(); ++pos) - l.at(pos)->update(); + for (QWidget *w : children) { + if (!ignorable(w)) + w->update(); + } } break; case QEvent::KeyRelease: @@ -175,9 +135,9 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) // Update state and repaint the menu bars. d->alt_down = false; #if QT_CONFIG(menubar) - QList<QMenuBar *> l = widget->findChildren<QMenuBar *>(); - for (int i = 0; i < l.size(); ++i) - l.at(i)->update(); + const QList<QMenuBar *> menuBars = widget->findChildren<QMenuBar *>(); + for (QWidget *w : menuBars) + w->update(); #endif } break; @@ -241,17 +201,18 @@ void QWindowsStyle::polish(QApplication *app) QCommonStyle::polish(app); QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func()); // We only need the overhead when shortcuts are sometimes hidden - if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app) + if (!proxy()->styleHint(SH_UnderlineShortcut, nullptr) && app) app->installEventFilter(this); - d->activeCaptionColor = app->palette().highlight().color(); - d->activeGradientCaptionColor = app->palette().highlight() .color(); - d->inactiveCaptionColor = app->palette().dark().color(); - d->inactiveGradientCaptionColor = app->palette().dark().color(); - d->inactiveCaptionText = app->palette().background().color(); + const auto &palette = QGuiApplication::palette(); + d->activeGradientCaptionColor = palette.highlight().color(); + d->activeCaptionColor = d->activeGradientCaptionColor; + d->inactiveGradientCaptionColor = palette.dark().color(); + d->inactiveCaptionColor = d->inactiveGradientCaptionColor; + d->inactiveCaptionText = palette.window().color(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //fetch native title bar colors - if(app->desktopSettingsAware()){ +#if defined(Q_OS_WIN) //fetch native title bar colors + if (app->desktopSettingsAware()){ DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION); DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION); DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION); @@ -295,34 +256,39 @@ void QWindowsStyle::polish(QPalette &pal) int QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *, const QWidget *widget) { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) + // The pixel metrics are in device indepentent pixels; + // hardcode DPI to 1x 96 DPI. + const int dpi = 96; + switch (pm) { case QStyle::PM_DockWidgetFrameWidth: - return GetSystemMetrics(SM_CXFRAME); - - case QStyle::PM_TitleBarHeight: - if (widget && (widget->windowType() == Qt::Tool)) { - // MS always use one less than they say - return GetSystemMetrics(SM_CYSMCAPTION) - 1; - } - return GetSystemMetrics(SM_CYCAPTION) - 1; + return GetSystemMetricsForDpi(SM_CXFRAME, dpi); + + case QStyle::PM_TitleBarHeight: { + const int resizeBorderThickness = + GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi) + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi); + if (widget && (widget->windowType() == Qt::Tool)) + return GetSystemMetricsForDpi(SM_CYSMCAPTION, dpi) + resizeBorderThickness; + return GetSystemMetricsForDpi(SM_CYCAPTION, dpi) + resizeBorderThickness; + } case QStyle::PM_ScrollBarExtent: { NONCLIENTMETRICS ncm; - ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT); - if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) + ncm.cbSize = sizeof(NONCLIENTMETRICS); + if (SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi)) return qMax(ncm.iScrollHeight, ncm.iScrollWidth); } break; case QStyle::PM_MdiSubWindowFrameWidth: - return GetSystemMetrics(SM_CYFRAME); + return GetSystemMetricsForDpi(SM_CYFRAME, dpi); default: break; } -#else // Q_OS_WIN && !Q_OS_WINRT +#else // Q_OS_WIN Q_UNUSED(pm); Q_UNUSED(widget); #endif @@ -341,7 +307,6 @@ int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm) case QStyle::PM_MenuVMargin: case QStyle::PM_ToolBarItemMargin: return 1; - break; case QStyle::PM_DockWidgetSeparatorExtent: return 4; #if QT_CONFIG(tabbar) @@ -380,45 +345,20 @@ int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm) return QWindowsStylePrivate::InvalidMetric; } -static QWindow *windowOf(const QWidget *w) +static QScreen *screenOf(const QWidget *w) { - QWindow *result = nullptr; if (w) { - result = w->windowHandle(); - if (!result) { - if (const QWidget *np = w->nativeParentWidget()) - result = np->windowHandle(); - } + if (auto screen = qt_widget_private(const_cast<QWidget *>(w))->associatedScreen()) + return screen; } - return result; -} - -static QScreen *screenOf(const QWidget *w) -{ - if (const QWindow *window = windowOf(w)) - return window->screen(); return QGuiApplication::primaryScreen(); } // Calculate the overall scale factor to obtain Qt Device Independent -// Pixels from a native Windows size. Divide by devicePixelRatio -// and account for secondary screens with differing logical DPI. +// Pixels from a native Windows size. qreal QWindowsStylePrivate::nativeMetricScaleFactor(const QWidget *widget) { - if (!QHighDpiScaling::isActive()) - return 1; - qreal result = qreal(1) / QWindowsStylePrivate::devicePixelRatio(widget); - if (QGuiApplicationPrivate::screen_list.size() > 1) { - const QScreen *primaryScreen = QGuiApplication::primaryScreen(); - const QScreen *screen = screenOf(widget); - if (screen != primaryScreen) { - const qreal primaryLogicalDpi = primaryScreen->handle()->logicalDpi().first; - const qreal logicalDpi = screen->handle()->logicalDpi().first; - if (!qFuzzyCompare(primaryLogicalDpi, logicalDpi)) - result *= logicalDpi / primaryLogicalDpi; - } - } - return result; + return qreal(1) / QHighDpiScaling::factor(screenOf(widget)); } /*! @@ -428,17 +368,17 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW { int ret = QWindowsStylePrivate::pixelMetricFromSystemDp(pm, opt, widget); if (ret != QWindowsStylePrivate::InvalidMetric) - return qRound(qreal(ret) * QWindowsStylePrivate::nativeMetricScaleFactor(widget)); + return ret; ret = QWindowsStylePrivate::fixedPixelMetric(pm); if (ret != QWindowsStylePrivate::InvalidMetric) - return int(QStyleHelper::dpiScaled(ret)); + return int(QStyleHelper::dpiScaled(ret, opt)); ret = 0; switch (pm) { case PM_MaximumDragDistance: - ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance); + ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance, opt, widget); if (ret == -1) ret = 60; break; @@ -478,7 +418,7 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW break; case PM_SplitterWidth: - ret = qMax(int(QStyleHelper::dpiScaled(4)), QApplication::globalStrut().width()); + ret = QStyleHelper::dpiScaled(4, opt); break; default: @@ -495,46 +435,6 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt, const QWidget *widget) const { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) - QPixmap desktopIcon; - switch(standardPixmap) { - case SP_DriveCDIcon: - case SP_DriveDVDIcon: - case SP_DriveNetIcon: - case SP_DriveHDIcon: - case SP_DriveFDIcon: - case SP_FileIcon: - case SP_FileLinkIcon: - case SP_DirLinkIcon: - case SP_DirClosedIcon: - case SP_DesktopIcon: - case SP_ComputerIcon: - case SP_DirOpenIcon: - case SP_FileDialogNewFolder: - case SP_DirHomeIcon: - case SP_TrashIcon: - case SP_VistaShield: - if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { - QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap); - desktopIcon = theme->standardPixmap(sp, QSizeF(16, 16)); - } - break; - case SP_MessageBoxInformation: - case SP_MessageBoxWarning: - case SP_MessageBoxCritical: - case SP_MessageBoxQuestion: - if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { - QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap); - desktopIcon = theme->standardPixmap(sp, QSizeF()); - } - break; - default: - break; - } - if (!desktopIcon.isNull()) { - return desktopIcon; - } -#endif // Q_OS_WIN && !Q_OS_WINRT return QCommonStyle::standardPixmap(standardPixmap, opt, widget); } @@ -545,7 +445,14 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid int ret = 0; switch (hint) { - case SH_EtchDisabledText: + case SH_EtchDisabledText: { + const QPalette pal = opt ? opt->palette + : widget ? widget->palette() + : QPalette(); + ret = pal.window().color().lightness() > pal.text().color().lightness() + ? 1 : 0; + break; + } case SH_Slider_SnapToValue: case SH_PrintDialog_RightAlignButtons: case SH_FontDialog_SelectAssociatedText: @@ -554,7 +461,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid case SH_MenuBar_MouseTracking: case SH_Menu_MouseTracking: case SH_ComboBox_ListMouseTracking: - case SH_ScrollBar_StopMouseOverSlider: + case SH_Slider_StopMouseOverSlider: case SH_MainWindow_SpaceBelowMenuBar: ret = 1; @@ -572,7 +479,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid ret = 0; break; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Option not used on WinRT -> common style +#if defined(Q_OS_WIN) case SH_UnderlineShortcut: { ret = 1; @@ -600,23 +507,23 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid ret = 1; } } -#ifndef QT_NO_ACCESSIBILITY +#if QT_CONFIG(accessibility) if (!ret && opt && opt->type == QStyleOption::SO_MenuItem && QStyleHelper::isInstanceOf(opt->styleObject, QAccessible::MenuItem) && opt->styleObject->property("_q_showUnderlined").toBool()) ret = 1; -#endif // QT_NO_ACCESSIBILITY +#endif // QT_CONFIG(accessibility) break; } -#endif // Q_OS_WIN && !Q_OS_WINRT +#endif // Q_OS_WIN case SH_Menu_SubMenuSloppyCloseTimeout: case SH_Menu_SubMenuPopupDelay: { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) DWORD delay; if (SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0)) ret = delay; else -#endif // Q_OS_WIN && !Q_OS_WINRT +#endif // Q_OS_WIN ret = 400; break; } @@ -626,7 +533,7 @@ int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWid ret = 0; if (rbOpt->shape == QRubberBand::Rectangle) { ret = true; - if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) { + if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) { mask->region = opt->rect; int size = 1; if (widget && widget->isWindow()) @@ -669,7 +576,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QRect rect = opt->rect; const int margin = 2; QPen oldPen = p->pen(); - if(opt->state & State_Horizontal){ + if (opt->state & State_Horizontal){ const int offset = rect.width()/2; p->setPen(QPen(opt->palette.dark().color())); p->drawLine(rect.bottomLeft().x() + offset, @@ -707,17 +614,17 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, x -= 2; if (opt->rect.height() > 4) { qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); } } else { if (opt->rect.width() > 4) { int y = opt->rect.height() / 2 - 4; qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3, - opt->palette, false, 1, 0); + opt->palette, false, 1, nullptr); } } p->restore(); @@ -754,7 +661,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, if (opt->state & (State_Raised | State_Sunken | State_On)) { if (opt->state & State_AutoRaise) { - if(opt->state & (State_Enabled | State_Sunken | State_On)){ + if (opt->state & (State_Enabled | State_Sunken | State_On)){ if (panel) qDrawShadePanel(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), 1, &fill); @@ -768,7 +675,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } } else { qDrawWinButton(p, opt->rect, opt->palette, - opt->state & (State_Sunken | State_On), panel ? &fill : 0); + opt->state & (State_Sunken | State_On), panel ? &fill : nullptr); } } else { p->fillRect(opt->rect, fill); @@ -802,8 +709,11 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPen oldPen = p->pen(); p->setPen(QPen(opt->palette.shadow().color(), 0)); QRectF rect = opt->rect; - rect.adjust(QStyleHelper::dpiScaled(0.5), QStyleHelper::dpiScaled(0.5), - QStyleHelper::dpiScaled(-1.5), QStyleHelper::dpiScaled(-1.5)); + const qreal dpi = QStyleHelper::dpi(opt); + const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi); + const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5, dpi); + rect.adjust(topLevelAdjustment, topLevelAdjustment, + bottomRightAdjustment, bottomRightAdjustment); p->drawRect(rect); p->setPen(oldPen); break; @@ -817,7 +727,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, else if (opt->state & State_Enabled) fill = opt->palette.base(); else - fill = opt->palette.background(); + fill = opt->palette.window(); p->save(); doRestore = true; qDrawWinPanel(p, opt->rect, opt->palette, true, &fill); @@ -827,13 +737,13 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, p->setPen(opt->palette.text().color()); } Q_FALLTHROUGH(); - case PE_IndicatorViewItemCheck: + case PE_IndicatorItemViewItemCheck: if (!doRestore) { p->save(); doRestore = true; } #if QT_CONFIG(itemviews) - if (pe == PE_IndicatorViewItemCheck) { + if (pe == PE_IndicatorItemViewItemCheck) { const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt); p->setPen(itemViewOpt && itemViewOpt->showDecorationSelected @@ -846,10 +756,10 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } #endif // QT_CONFIG(itemviews) if (!(opt->state & State_Off)) { - QPointF points[6]; + std::array<QPointF, 6> points; qreal scaleh = opt->rect.width() / 12.0; qreal scalev = opt->rect.height() / 12.0; - points[0] = { opt->rect.x() + 3.5 * scaleh, opt->rect.y() + 5.5 * scalev }; + points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev }; points[1] = { points[0].x(), points[0].y() + 2 * scalev }; points[2] = { points[1].x() + 2 * scaleh, points[1].y() + 2 * scalev }; points[3] = { points[2].x() + 4 * scaleh, points[2].y() - 4 * scalev }; @@ -857,7 +767,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev }; p->setPen(QPen(opt->palette.text().color(), 0)); p->setBrush(opt->palette.text().color()); - p->drawPolygon(points, 6); + p->drawPolygon(points.data(), static_cast<int>(points.size())); } if (doRestore) p->restore(); @@ -951,14 +861,14 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, if (frame->lineWidth == 2 || pe == PE_Frame) { QPalette popupPal = frame->palette; if (pe == PE_FrameMenu) { - popupPal.setColor(QPalette::Light, frame->palette.background().color()); + popupPal.setColor(QPalette::Light, frame->palette.window().color()); popupPal.setColor(QPalette::Midlight, frame->palette.light().color()); } if (pe == PE_Frame && (frame->state & State_Raised)) qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken); else if (pe == PE_Frame && (frame->state & State_Sunken)) { - popupPal.setColor(QPalette::Midlight, frame->palette.background().color()); + popupPal.setColor(QPalette::Midlight, frame->palette.window().color()); qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken); } else @@ -968,7 +878,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, } } else { QPalette popupPal = opt->palette; - popupPal.setColor(QPalette::Light, opt->palette.background().color()); + popupPal.setColor(QPalette::Light, opt->palette.window().color()); popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); } @@ -986,7 +896,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, if (opt->state & (State_Raised | State_On | State_Sunken)) { qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On), - panel ? &fill : 0); + panel ? &fill : nullptr); } else { if (panel) p->fillRect(opt->rect, fill); @@ -996,7 +906,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, break; } case PE_FrameWindow: { QPalette popupPal = opt->palette; - popupPal.setColor(QPalette::Light, opt->palette.background().color()); + popupPal.setColor(QPalette::Light, opt->palette.window().color()); popupPal.setColor(QPalette::Midlight, opt->palette.light().color()); qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken); break; } @@ -1011,14 +921,14 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, #endif // QT_CONFIG(dockwidget) case PE_FrameStatusBarItem: - qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0); + qDrawShadePanel(p, opt->rect, opt->palette, true, 1, nullptr); break; case PE_IndicatorProgressChunk: { bool vertical = false, inverted = false; if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) { - vertical = pb->orientation == Qt::Vertical; + vertical = !(pb->state & QStyle::State_Horizontal); inverted = pb->invertedAppearance; } @@ -1049,7 +959,7 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, break; case PE_FrameTabWidget: { - qDrawWinButton(p, opt->rect, opt->palette, false, 0); + qDrawWinButton(p, opt->rect, opt->palette, false, nullptr); break; } default: @@ -1103,7 +1013,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) { int x, y, w, h; menuitem->rect.getRect(&x, &y, &w, &h); - int tab = menuitem->tabWidth; + int tab = menuitem->reservedShortcutWidth; bool dis = !(menuitem->state & State_Enabled); bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable ? menuitem->checked : false; @@ -1150,9 +1060,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On); else pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode); - const int pixw = pixmap.width() / pixmap.devicePixelRatio(); - const int pixh = pixmap.height() / pixmap.devicePixelRatio(); - QRect pmr(0, 0, pixw, pixh); + QRect pmr(QPoint(0, 0), pixmap.deviceIndependentSize().toSize()); pmr.moveCenter(vCheckRect.center()); p->setPen(menuitem->palette.text().color()); p->drawPixmap(pmr.topLeft(), pixmap); @@ -1162,7 +1070,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai if (!dis) newMi.state |= State_Enabled; if (act) - newMi.state |= State_On; + newMi.state |= State_On | State_Selected; newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame, menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame, checkcol - 2 * QWindowsStylePrivate::windowsItemFrame, @@ -1182,10 +1090,10 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin, w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin); QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect); - QStringRef s(&menuitem->text); + QStringView s(menuitem->text); if (!s.isEmpty()) { // draw text p->save(); - int t = s.indexOf(QLatin1Char('\t')); + qsizetype t = s.indexOf(u'\t'); int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget)) text_flags |= Qt::TextHideMnemonic; @@ -1315,12 +1223,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai x2 -= onlyOne || lastTab ? borderThinkness : 0; } - p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background()); + p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window()); // Delete border if (selected) { - p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background()); - p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background()); + p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window()); + p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window()); } // Left if (firstTab || selected || onlyOne || !previousSelected) { @@ -1351,12 +1259,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai x2 -= lastTab ? borderThinkness : 0; } - p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); + p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window()); // Delete border if (selected) { - p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background()); - p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background()); + p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window()); + p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window()); } // Left if (firstTab || selected || onlyOne || !previousSelected) { @@ -1389,12 +1297,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai y2 -= lastTab ? borderThinkness : 0; } - p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background()); + p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window()); // Delete border if (selected) { - p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background()); - p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background()); + p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window()); + p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window()); } // Top if (firstTab || selected || onlyOne || !previousSelected) { @@ -1427,12 +1335,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai y2 -= lastTab ? borderThinkness : 0; } - p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background()); + p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window()); // Delete border if (selected) { - p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background()); - p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background()); + p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window()); + p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window()); } // Top if (firstTab || selected || onlyOne || !previousSelected) { @@ -1526,7 +1434,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai br = QBrush(paletteBrush.textureImage()); } else br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern); - p->setBackground(opt->palette.background().color()); + p->setBackground(opt->palette.window().color()); p->setBrush(br); } p->drawRect(opt->rect); @@ -1591,6 +1499,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::Beginning: case QStyleOptionToolBar::OnlyOne: paintBottomBorder = false; + break; default: break; } @@ -1606,14 +1515,12 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::OnlyOne: paintRightBorder = false; paintLeftBorder = false; + break; default: break; } - if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end - bool tmp = paintLeftBorder; - paintRightBorder=paintLeftBorder; - paintLeftBorder=tmp; - } + if (opt->direction == Qt::RightToLeft) //reverse layout changes the order of Beginning/end + std::swap(paintLeftBorder, paintRightBorder); break; case Qt::RightToolBarArea : switch (toolbar->positionOfLine){ @@ -1682,10 +1589,10 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai if (!rect.isValid()) return; - const bool vertical = pb->orientation == Qt::Vertical; + const bool vertical = !(pb->state & QStyle::State_Horizontal); const bool inverted = pb->invertedAppearance; - QMatrix m; + QTransform m; if (vertical) { rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height m.rotate(90); @@ -1693,7 +1600,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai } QPalette pal2 = pb->palette; // Correct the highlight color if it is the same as the background - if (pal2.highlight() == pal2.background()) + if (pal2.highlight() == pal2.window()) pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active, QPalette::Highlight)); bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical); @@ -1724,7 +1631,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai int myHeight = pbBits.rect.height(); int chunksToDraw = chunksInRow; - if(step > chunkCount - 5)chunksToDraw = (chunkCount - step); + if (step > chunkCount - 5)chunksToDraw = (chunkCount - step); p->save(); p->setClipRect(m.mapRect(QRectF(rect)).toRect()); @@ -1738,7 +1645,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai x += reverse ? -unit_width : unit_width; } //Draw wrap-around chunks - if( step > chunkCount-5){ + if ( step > chunkCount-5){ x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ; x = 0; int chunksToDraw = step - (chunkCount - chunksInRow); @@ -1825,7 +1732,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai titleRect.height(), titleRect.width()); } proxy()->drawItemText(p, titleRect, - Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette, + Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, palette, dwOpt->state & State_Enabled, dwOpt->title, floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText); p->setFont(oldFont); @@ -1843,7 +1750,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai p->setBackground(cb->palette.highlight()); } else { p->setPen(cb->palette.text().color()); - p->setBackground(cb->palette.background()); + p->setBackground(cb->palette.window()); } } QCommonStyle::drawControl(ce, opt, p, widget); @@ -1988,51 +1895,46 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp QSliderDirection dir; if (orient == Qt::Horizontal) - if (tickAbove) - dir = SlUp; - else - dir = SlDown; + dir = tickAbove ? SlUp : SlDown; else - if (tickAbove) - dir = SlLeft; - else - dir = SlRight; - - QPolygon a; + dir = tickAbove ? SlLeft : SlRight; + std::array<QPoint, 5> points; int d = 0; switch (dir) { case SlUp: - y1 = y1 + wi/2; + y1 = y1 + wi / 2; d = (wi + 1) / 2 - 1; - a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d); + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2), + QPoint(x2, y1), QPoint(x1 + d, y1 - d)}; break; case SlDown: - y2 = y2 - wi/2; + y2 = y2 - wi / 2; d = (wi + 1) / 2 - 1; - a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1); + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d), + QPoint(x2, y2), QPoint(x2, y1)}; break; case SlLeft: d = (he + 1) / 2 - 1; - x1 = x1 + he/2; - a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1); + x1 = x1 + he / 2; + points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2), + QPoint(x2, y2), QPoint(x2, y1)}; break; case SlRight: d = (he + 1) / 2 - 1; - x2 = x2 - he/2; - a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1); + x2 = x2 - he / 2; + points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2), + QPoint(x2 + d, y1 + d), QPoint(x2, y1)}; break; } QBrush oldBrush = p->brush(); - bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting); p->setPen(Qt::NoPen); p->setBrush(handleBrush); - p->setRenderHint(QPainter::Qt4CompatiblePainting); Qt::BGMode oldMode = p->backgroundMode(); p->setBackgroundMode(Qt::OpaqueMode); p->drawRect(x1, y1, x2-x1+1, y2-y1+1); - p->drawPolygon(a); + p->drawPolygon(points.data(), static_cast<int>(points.size())); p->setBrush(oldBrush); p->setBackgroundMode(oldMode); @@ -2111,7 +2013,6 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp p->drawLine(x2, y2-1, x2+d, y2-1-d); break; } - p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting); } } break; @@ -2129,7 +2030,7 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp #if QT_CONFIG(combobox) case CC_ComboBox: if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) { - QBrush editBrush = cmb->palette.brush(QPalette::Base); + QBrush editBrush = cmb->palette.brush(QPalette::Button); if ((cmb->subControls & SC_ComboBoxFrame)) { if (cmb->frame) { QPalette shadePal = opt->palette; @@ -2185,7 +2086,7 @@ void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComp } else { p->setPen(cmb->palette.text().color()); - p->setBackground(cmb->palette.background()); + p->setBackground(cmb->palette.window()); } if (cmb->state & State_HasFocus && !cmb->editable) { @@ -2310,15 +2211,15 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, int defwidth = 0; if (btn->features & QStyleOptionButton::AutoDefaultButton) defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); - int minwidth = int(QStyleHelper::dpiScaled(75.)); - int minheight = int(QStyleHelper::dpiScaled(23.)); + const qreal dpi = QStyleHelper::dpi(opt); + int minwidth = int(QStyleHelper::dpiScaled(75, dpi)); + int minheight = int(QStyleHelper::dpiScaled(23, dpi)); -#ifndef QT_QWS_SMALL_PUSHBUTTON if (w < minwidth + defwidth && !btn->text.isEmpty()) w = minwidth + defwidth; if (h < minheight + defwidth) h = minheight + defwidth; -#endif + sz = QSize(w, h); } break; @@ -2344,7 +2245,7 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, } int maxpmw = mi->maxIconWidth; int tabSpacing = 20; - if (mi->text.contains(QLatin1Char('\t'))) + if (mi->text.contains(u'\t')) w += tabSpacing; else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu) w += 2 * QWindowsStylePrivate::windowsArrowHMargin; |