diff options
Diffstat (limited to 'src/plugins/styles')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 87 | ||||
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac_p_p.h | 2 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsvistastyle.cpp | 11 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h | 2 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsxpstyle.cpp | 277 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h | 4 | ||||
-rw-r--r-- | src/plugins/styles/windowsvista/windowsvista.pro | 4 |
7 files changed, 194 insertions, 193 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 71eb88008e..d5ad1a8ca0 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -236,6 +236,18 @@ static QLinearGradient titlebarGradientInactive() } #if QT_CONFIG(tabwidget) +/* + Since macOS 10.14 AppKit is using transparency more extensively, especially for the + dark theme. Inactive buttons, for example, are semi-transparent. And we use them to + draw tab widget's tab bar. The combination of NSBox (also a part of tab widget) + and these transparent buttons gives us an undesired side-effect: an outline of + NSBox is visible through transparent buttons. To avoid this, we have this hack below: + we clip the area where the line would be visible through the buttons. The area we + want to clip away can be described as an intersection of the option's rect and + the tab widget's tab bar rect. But some adjustments are required, since those rects + are anyway adjusted during the rendering and they are not exactly what you'll see on + the screen. Thus this switch-statement inside. +*/ static void clipTabBarFrame(const QStyleOption *option, const QMacStyle *style, CGContextRef ctx) { Q_ASSERT(option); @@ -246,7 +258,19 @@ static void clipTabBarFrame(const QStyleOption *option, const QMacStyle *style, QTabWidget *tabWidget = qobject_cast<QTabWidget *>(option->styleObject); Q_ASSERT(tabWidget); - const QRect tabBarRect = style->subElementRect(QStyle::SE_TabWidgetTabBar, option, tabWidget).adjusted(2, 2, -3, -2); + QRect tabBarRect = style->subElementRect(QStyle::SE_TabWidgetTabBar, option, tabWidget).adjusted(2, 0, -3, 0); + switch (tabWidget->tabPosition()) { + case QTabWidget::South: + tabBarRect.setY(tabBarRect.y() + tabBarRect.height() / 2); + break; + case QTabWidget::North: + case QTabWidget::West: + tabBarRect = tabBarRect.adjusted(0, 2, 0, -2); + break; + case QTabWidget::East: + tabBarRect = tabBarRect.adjusted(tabBarRect.width() / 2, 2, tabBarRect.width() / 2, -2); + } + const QRegion clipPath = QRegion(option->rect) - tabBarRect; QVarLengthArray<CGRect, 3> cgRects; for (const QRect &qtRect : clipPath) @@ -1388,14 +1412,22 @@ void QMacStylePrivate::tabLayout(const QStyleOptionTab *opt, const QWidget *widg // High-dpi icons do not need adjustment; make sure tabIconSize is not larger than iconSize tabIconSize = QSize(qMin(tabIconSize.width(), iconSize.width()), qMin(tabIconSize.height(), iconSize.height())); - *iconRect = QRect(tr.left(), tr.center().y() - tabIconSize.height() / 2, - tabIconSize.width(), tabIconSize.height()); + const int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2 - hpadding; + + if (opt->documentMode) { + // documents show the icon as part of the the text + const int textWidth = + opt->fontMetrics.boundingRect(tr, Qt::AlignCenter | Qt::TextShowMnemonic, opt->text).width(); + *iconRect = QRect(tr.center().x() - textWidth / 2 - stylePadding - tabIconSize.width(), + tr.center().y() - tabIconSize.height() / 2, + tabIconSize.width(), tabIconSize.height()); + } else { + *iconRect = QRect(tr.left() + stylePadding, tr.center().y() - tabIconSize.height() / 2, + tabIconSize.width(), tabIconSize.height()); + } if (!verticalTabs) *iconRect = proxyStyle->visualRect(opt->direction, opt->rect, *iconRect); - int stylePadding = proxyStyle->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2; - stylePadding -= hpadding; - tr.setLeft(tr.left() + stylePadding + tabIconSize.width() + 4); tr.setRight(tr.right() - stylePadding - tabIconSize.width() - 4); } @@ -2553,7 +2585,7 @@ QPalette QMacStyle::standardPalette() const auto platformTheme = QGuiApplicationPrivate::platformTheme(); auto styleNames = platformTheme->themeHint(QPlatformTheme::StyleNames); if (styleNames.toStringList().contains("macintosh")) - return *platformTheme->palette(); + return QPalette(); // Inherit everything from theme else return QStyle::standardPalette(); } @@ -2873,7 +2905,7 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w ret = false; break; case SH_Table_GridLineColor: - ret = int(qt_mac_toQColor(NSColor.gridColor).rgb()); + ret = int(qt_mac_toQColor(NSColor.gridColor).rgba()); break; default: ret = QCommonStyle::styleHint(sh, opt, w, hret); @@ -3064,13 +3096,18 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai bool needTranslation = false; if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSMojave && !qt_mac_applicationIsInDarkMode()) { - // Another surprise from AppKit (SDK 10.14) - -displayRectIgnoringOpacity: - // is different from drawRect: for some Apple-known reason box is smaller - // in height than we need, resulting in tab buttons sitting too high/not - // centered. Attempts to play with insets etc did not work - the same wrong - // height. Simple translation is not working (too much space "at bottom"), - // so we make it bigger and translate (otherwise it's clipped at bottom btw). - adjustedRect.adjust(0, 0, 0, 3); + // In Aqua theme we have to use the 'default' NSBox (as opposite + // to the 'custom' QDarkNSBox we use in dark theme). Since -drawRect: + // does nothing in default NSBox, we call -displayRectIgnoringOpaticty:. + // Unfortunately, the resulting box is smaller then the actual rect we + // wanted. This can be seen, e.g. because tabs (buttons) are misaligned + // vertically and even worse, if QTabWidget has autoFillBackground + // set, this background overpaints NSBox making it to disappear. + // We trick our NSBox to render in a larger rectangle, so that + // the actuall result (which is again smaller than requested), + // more or less is what we really want. We'll have to adjust CTM + // and translate accordingly. + adjustedRect.adjust(0, 0, 6, 6); needTranslation = true; } d->drawNSViewInRect(box, adjustedRect, p, ^(CGContextRef ctx, const CGRect &rect) { @@ -3085,7 +3122,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai [box drawRect:rect]; } else { if (needTranslation) - CGContextTranslateCTM(ctx, 0.0, 4.0); + CGContextTranslateCTM(ctx, -3.0, 5.0); [box displayRectIgnoringOpacity:box.bounds inContext:NSGraphicsContext.currentContext]; } }); @@ -4594,6 +4631,7 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, case SE_ToolBoxTabContents: rect = QCommonStyle::subElementRect(sr, opt, widget); break; + case SE_PushButtonBevel: case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) { // Comment from the old HITheme days: @@ -4607,9 +4645,20 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, const auto ct = cocoaControlType(btn, widget); const auto cs = d->effectiveAquaSizeConstrain(btn, widget); const auto cw = QMacStylePrivate::CocoaControl(ct, cs); - const auto frameRect = cw.adjustedControlFrame(btn->rect); - const auto titleMargins = cw.titleMargins(); - rect = (frameRect - titleMargins).toRect(); + auto frameRect = cw.adjustedControlFrame(btn->rect); + if (sr == SE_PushButtonContents) { + frameRect -= cw.titleMargins(); + } else { + auto *pb = static_cast<NSButton *>(d->cocoaControl(cw)); + if (cw.type != QMacStylePrivate::Button_SquareButton) { + frameRect = QRectF::fromCGRect([pb alignmentRectForFrame:pb.frame]); + if (cw.type == QMacStylePrivate::Button_PushButton) + frameRect -= pushButtonShadowMargins[cw.size]; + else if (cw.type == QMacStylePrivate::Button_PullDown) + frameRect -= pullDownButtonShadowMargins[cw.size]; + } + } + rect = frameRect.toRect(); } break; case SE_HeaderLabel: { diff --git a/src/plugins/styles/mac/qmacstyle_mac_p_p.h b/src/plugins/styles/mac/qmacstyle_mac_p_p.h index d6af18f01f..274936bd79 100644 --- a/src/plugins/styles/mac/qmacstyle_mac_p_p.h +++ b/src/plugins/styles/mac/qmacstyle_mac_p_p.h @@ -284,7 +284,7 @@ public: CocoaControlType windowButtonCocoaControl(QStyle::SubControl sc) const; #if QT_CONFIG(tabbar) - void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const; + void tabLayout(const QStyleOptionTab *opt, const QWidget *widget, QRect *textRect, QRect *iconRect) const override; static Direction tabDirection(QTabBar::Shape shape); static bool verticalTabs(QMacStylePrivate::Direction tabDirection); #endif diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index f9d26c49ae..30b3786a80 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -1365,6 +1365,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsStyle::drawControl(element, ©Opt, painter, widget); } break; +#if QT_CONFIG(dockwidget) case CE_DockWidgetTitle: if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(option)) { const QDockWidget *dockWidget = qobject_cast<const QDockWidget *>(widget); @@ -1431,6 +1432,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption } } break; +#endif // QT_CONFIG(dockwidget) #if QT_CONFIG(itemviews) case CE_ItemViewItem: { @@ -2110,7 +2112,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co break; case SH_Table_GridLineColor: if (option) - ret = int(option->palette.color(QPalette::Base).darker(118).rgb()); + ret = int(option->palette.color(QPalette::Base).darker(118).rgba()); else ret = -1; break; @@ -2311,11 +2313,13 @@ void QWindowsVistaStyle::polish(QWidget *widget) #endif // QT_CONFIG(lineedit) if (qobject_cast<QGroupBox*>(widget)) widget->setAttribute(Qt::WA_Hover); +#if QT_CONFIG(commandlinkbutton) else if (qobject_cast<QCommandLinkButton*>(widget)) { QFont buttonFont = widget->font(); buttonFont.setFamily(QLatin1String("Segoe UI")); widget->setFont(buttonFont); } +#endif // QT_CONFIG(commandlinkbutton) else if (widget->inherits("QTipLabel")){ //note that since tooltips are not reused //we do not have to care about unpolishing @@ -2392,12 +2396,15 @@ void QWindowsVistaStyle::unpolish(QWidget *widget) #endif // QT_CONFIG(inputdialog) else if (QTreeView *tree = qobject_cast<QTreeView *> (widget)) { tree->viewport()->setAttribute(Qt::WA_Hover, false); - } else if (qobject_cast<QCommandLinkButton*>(widget)) { + } +#if QT_CONFIG(commandlinkbutton) + else if (qobject_cast<QCommandLinkButton*>(widget)) { QFont font = QApplication::font("QCommandLinkButton"); QFont widgetFont = widget->font(); widgetFont.setFamily(font.family()); //Only family set by polish widget->setFont(widgetFont); } +#endif // QT_CONFIG(commandlinkbutton) } diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index 8fef9f9927..c1d764a60e 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -106,7 +106,9 @@ #include <qtableview.h> #endif #include <qdatetime.h> +#if QT_CONFIG(commandlinkbutton) #include <qcommandlinkbutton.h> +#endif QT_BEGIN_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index ba590b3eca..e43746e79f 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -225,9 +225,11 @@ static HRGN qt_hrgn_from_qregion(const QRegion ®ion) */ bool QWindowsXPStylePrivate::useXP(bool update) { - if (!update) - return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); + if (update) { + use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()) + && !QWindowsStylePrivate::isDarkMode(); + } + return use_xp; } /* \internal @@ -663,7 +665,7 @@ static inline bool isFullyOpaque(const XPThemeData &themeData) \note drawBackgroundThruNativeBuffer() can return false for large sizes due to buffer()/CreateDIBSection() failing. */ -bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) +bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData, qreal correctionFactor) { if (themeData.rect.isEmpty()) return true; @@ -708,9 +710,9 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) } const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr; - const bool result = dc + const bool result = dc && qFuzzyCompare(correctionFactor, qreal(1)) ? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio) - : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio); + : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio, correctionFactor); painter->restore(); return result; } @@ -784,9 +786,14 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa other pixmaps etc), or when special transformations are needed (e.g. flips (horizonal mirroring only, vertical are handled by the theme engine). + + \a correctionFactor is an additional factor used to scale up controls + that are too small on High DPI screens, as has been observed for + WP_MDICLOSEBUTTON, WP_MDIRESTOREBUTTON, WP_MDIMINBUTTON (QTBUG-75927). */ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeData, - qreal additionalDevicePixelRatio) + qreal additionalDevicePixelRatio, + qreal correctionFactor) { QPainter *painter = themeData.painter; QRectF rectF = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio); @@ -795,7 +802,11 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa rectF = QRectF(0, 0, rectF.height(), rectF.width()); } rectF.moveTo(0, 0); + + const bool hasCorrectionFactor = !qFuzzyCompare(correctionFactor, qreal(1)); QRect rect = rectF.toRect(); + QRect drawRect = hasCorrectionFactor + ? QRectF(rectF.topLeft() / correctionFactor, rectF.size() / correctionFactor).toRect() : rect; int partId = themeData.partId; int stateId = themeData.stateId; int w = rect.width(); @@ -824,6 +835,10 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa pixmapCacheKey.append(QLatin1Char('h')); pixmapCacheKey.append(QString::number(additionalDevicePixelRatio)); pixmapCacheKey.append(QLatin1Char('d')); + if (hasCorrectionFactor) { + pixmapCacheKey.append(QLatin1Char('c')); + pixmapCacheKey.append(QString::number(correctionFactor)); + } QPixmap cachedPixmap; ThemeMapKey key(themeData); @@ -882,7 +897,7 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa // and DTGB_OMITCONTENT bool addBorderContentClipping = false; QRegion extraClip; - QRect area = rect; + QRect area = drawRect; if (themeData.noBorder || themeData.noContent) { extraClip = area; // We are running on a system where the uxtheme.dll does not have @@ -913,19 +928,19 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa QImage img; if (!haveCachedPixmap) { // If the pixmap is not cached, generate it! ------------------------- - if (!buffer(w, h)) // Ensure a buffer of at least (w, h) in size + if (!buffer(drawRect.width(), drawRect.height())) // Ensure a buffer of at least (w, h) in size return false; HDC dc = bufferHDC(); // Clear the buffer if (alphaType != NoAlpha) { // Consider have separate "memset" function for small chunks for more speedup - memset(bufferPixels, 0x00, bufferW * h * 4); + memset(bufferPixels, 0x00, bufferW * drawRect.height() * 4); } // Difference between area and rect - int dx = area.x() - rect.x(); - int dy = area.y() - rect.y(); + int dx = area.x() - drawRect.x(); + int dy = area.y() - drawRect.y(); // Adjust so painting rect starts from Origo rect.moveTo(0,0); @@ -955,7 +970,7 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa if (!hasAlpha && partIsTransparent) potentialInvalidAlpha = true; #if defined(DEBUG_XP_STYLE) && 1 - dumpNativeDIB(w, h); + dumpNativeDIB(drawRect.width(), drawRect.height()); #endif } @@ -983,6 +998,8 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa printf("Image format is: %s\n", alphaType == RealAlpha ? "Real Alpha" : alphaType == MaskAlpha ? "Masked Alpha" : "No Alpha"); #endif img = QImage(bufferPixels, bufferW, bufferH, format); + if (hasCorrectionFactor) + img = img.scaled(w, h, Qt::KeepAspectRatio, Qt::SmoothTransformation); img.setDevicePixelRatio(additionalDevicePixelRatio); } @@ -1023,7 +1040,7 @@ bool QWindowsXPStylePrivate::drawBackgroundThruNativeBuffer(XPThemeData &themeDa imgCopy = cachedPixmap.toImage(); if (themeData.rotate) { - QMatrix rotMatrix; + QTransform rotMatrix; rotMatrix.rotate(themeData.rotate); imgCopy = imgCopy.transformed(rotMatrix); } @@ -2461,6 +2478,61 @@ QRect QWindowsXPStylePrivate::scrollBarGripperBounds(QStyle::State flags, const return sufficientSpace ? QRect(theme->rect.topLeft() + QPoint(hSpace, vSpace) / 2, size) : QRect(); } +#if QT_CONFIG(mdiarea) +// Helper for drawing MDI buttons into the corner widget of QMenuBar in case a +// QMdiSubWindow is maximized. +static void populateMdiButtonTheme(const QStyle *proxy, const QWidget *widget, + const QStyleOptionComplex *option, + QStyle::SubControl subControl, int part, + XPThemeData *theme) +{ + theme->partId = part; + theme->rect = proxy->subControlRect(QStyle::CC_MdiControls, option, subControl, widget); + if (!option->state.testFlag(QStyle::State_Enabled)) + theme->stateId = CBS_INACTIVE; + else if (option->state.testFlag(QStyle::State_Sunken) && option->activeSubControls.testFlag(subControl)) + theme->stateId = CBS_PUSHED; + else if (option->state.testFlag(QStyle::State_MouseOver) && option->activeSubControls.testFlag(subControl)) + theme->stateId = CBS_HOT; + else + theme->stateId = CBS_NORMAL; +} + +// Calculate an small (max 2), empirical correction factor for scaling up +// WP_MDICLOSEBUTTON, WP_MDIRESTOREBUTTON, WP_MDIMINBUTTON, which are too +// small on High DPI screens (QTBUG-75927). +qreal mdiButtonCorrectionFactor(XPThemeData &theme, const QPaintDevice *pd = nullptr) +{ + const auto dpr = pd ? pd->devicePixelRatioF() : qApp->devicePixelRatio(); + const QSizeF nativeSize = QSizeF(theme.size()) / dpr; + const QSizeF requestedSize(theme.rect.size()); + const auto rawFactor = qMin(requestedSize.width() / nativeSize.width(), + requestedSize.height() / nativeSize.height()); + const auto factor = rawFactor >= qreal(2) ? qreal(2) : qreal(1); + return factor; +} +#endif // QT_CONFIG(mdiarea) + +static void populateTitleBarButtonTheme(const QStyle *proxy, const QWidget *widget, + const QStyleOptionComplex *option, + QStyle::SubControl subControl, + bool isTitleBarActive, int part, + XPThemeData *theme) +{ + theme->rect = proxy->subControlRect(QStyle::CC_TitleBar, option, subControl, widget); + theme->partId = part; + if (widget && !widget->isEnabled()) + theme->stateId = RBS_DISABLED; + else if (option->activeSubControls == subControl && option->state.testFlag(QStyle::State_Sunken)) + theme->stateId = RBS_PUSHED; + else if (option->activeSubControls == subControl && option->state.testFlag(QStyle::State_MouseOver)) + theme->stateId = RBS_HOT; + else if (!isTitleBarActive) + theme->stateId = RBS_INACTIVE; + else + theme->stateId = RBS_NORMAL; +} + /*! \reimp */ @@ -3022,56 +3094,17 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo if (sub & SC_TitleBarMinButton && tb->titleBarFlags & Qt::WindowMinimizeButtonHint && !(tb->titleBarState & Qt::WindowMinimized)) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarMinButton, widget); - partId = WP_MINBUTTON; - if (widget && !widget->isEnabled()) - stateId = MINBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarMinButton && (option->state & State_Sunken)) - stateId = MINBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarMinButton && (option->state & State_MouseOver)) - stateId = MINBS_HOT; - else if (!isActive) - stateId = MINBS_INACTIVE; - else - stateId = MINBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMinButton, isActive, WP_MINBUTTON, &theme); d->drawBackground(theme); } if (sub & SC_TitleBarMaxButton && tb->titleBarFlags & Qt::WindowMaximizeButtonHint && !(tb->titleBarState & Qt::WindowMaximized)) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarMaxButton, widget); - partId = WP_MAXBUTTON; - if (widget && !widget->isEnabled()) - stateId = MAXBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarMaxButton && (option->state & State_Sunken)) - stateId = MAXBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarMaxButton && (option->state & State_MouseOver)) - stateId = MAXBS_HOT; - else if (!isActive) - stateId = MAXBS_INACTIVE; - else - stateId = MAXBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarMaxButton, isActive, WP_MAXBUTTON, &theme); d->drawBackground(theme); } if (sub & SC_TitleBarContextHelpButton && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarContextHelpButton, widget); - partId = WP_HELPBUTTON; - if (widget && !widget->isEnabled()) - stateId = MINBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarContextHelpButton && (option->state & State_Sunken)) - stateId = MINBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarContextHelpButton && (option->state & State_MouseOver)) - stateId = MINBS_HOT; - else if (!isActive) - stateId = MINBS_INACTIVE; - else - stateId = MINBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarContextHelpButton, isActive, WP_HELPBUTTON, &theme); d->drawBackground(theme); } bool drawNormalButton = (sub & SC_TitleBarNormalButton) @@ -3080,74 +3113,21 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint) && (tb->titleBarState & Qt::WindowMaximized))); if (drawNormalButton) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarNormalButton, widget); - partId = WP_RESTOREBUTTON; - if (widget && !widget->isEnabled()) - stateId = RBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarNormalButton && (option->state & State_Sunken)) - stateId = RBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarNormalButton && (option->state & State_MouseOver)) - stateId = RBS_HOT; - else if (!isActive) - stateId = RBS_INACTIVE; - else - stateId = RBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarNormalButton, isActive, WP_RESTOREBUTTON, &theme); d->drawBackground(theme); } if (sub & SC_TitleBarShadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint && !(tb->titleBarState & Qt::WindowMinimized)) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarShadeButton, widget); - partId = WP_MINBUTTON; - if (widget && !widget->isEnabled()) - stateId = MINBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarShadeButton && (option->state & State_Sunken)) - stateId = MINBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarShadeButton && (option->state & State_MouseOver)) - stateId = MINBS_HOT; - else if (!isActive) - stateId = MINBS_INACTIVE; - else - stateId = MINBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarShadeButton, isActive, WP_MINBUTTON, &theme); d->drawBackground(theme); } if (sub & SC_TitleBarUnshadeButton && tb->titleBarFlags & Qt::WindowShadeButtonHint && tb->titleBarState & Qt::WindowMinimized) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarUnshadeButton, widget); - partId = WP_RESTOREBUTTON; - if (widget && !widget->isEnabled()) - stateId = RBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarUnshadeButton && (option->state & State_Sunken)) - stateId = RBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarUnshadeButton && (option->state & State_MouseOver)) - stateId = RBS_HOT; - else if (!isActive) - stateId = RBS_INACTIVE; - else - stateId = RBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarUnshadeButton, isActive, WP_RESTOREBUTTON, &theme); d->drawBackground(theme); } if (sub & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) { - theme.rect = proxy()->subControlRect(CC_TitleBar, option, SC_TitleBarCloseButton, widget); - //partId = titlebar->testWFlags(Qt::WA_WState_Tool) ? WP_SMALLCLOSEBUTTON : WP_CLOSEBUTTON; - partId = WP_CLOSEBUTTON; - if (widget && !widget->isEnabled()) - stateId = CBS_DISABLED; - else if (option->activeSubControls == SC_TitleBarCloseButton && (option->state & State_Sunken)) - stateId = CBS_PUSHED; - else if (option->activeSubControls == SC_TitleBarCloseButton && (option->state & State_MouseOver)) - stateId = CBS_HOT; - else if (!isActive) - stateId = CBS_INACTIVE; - else - stateId = CBS_NORMAL; - theme.partId = partId; - theme.stateId = stateId; + populateTitleBarButtonTheme(proxy(), widget, option, SC_TitleBarCloseButton, isActive, WP_CLOSEBUTTON, &theme); d->drawBackground(theme); } } @@ -3157,56 +3137,21 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo #if QT_CONFIG(mdiarea) case CC_MdiControls: { - QRect buttonRect; XPThemeData theme(widget, p, QWindowsXPStylePrivate::WindowTheme, WP_MDICLOSEBUTTON, CBS_NORMAL); + if (Q_UNLIKELY(!theme.isValid())) + return; - if (option->subControls & SC_MdiCloseButton) { - buttonRect = proxy()->subControlRect(CC_MdiControls, option, SC_MdiCloseButton, widget); - if (theme.isValid()) { - theme.partId = WP_MDICLOSEBUTTON; - theme.rect = buttonRect; - if (!(flags & State_Enabled)) - theme.stateId = CBS_INACTIVE; - else if (flags & State_Sunken && (option->activeSubControls & SC_MdiCloseButton)) - theme.stateId = CBS_PUSHED; - else if (flags & State_MouseOver && (option->activeSubControls & SC_MdiCloseButton)) - theme.stateId = CBS_HOT; - else - theme.stateId = CBS_NORMAL; - d->drawBackground(theme); - } + if (option->subControls.testFlag(SC_MdiCloseButton)) { + populateMdiButtonTheme(proxy(), widget, option, SC_MdiCloseButton, WP_MDICLOSEBUTTON, &theme); + d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget)); } - if (option->subControls & SC_MdiNormalButton) { - buttonRect = proxy()->subControlRect(CC_MdiControls, option, SC_MdiNormalButton, widget); - if (theme.isValid()) { - theme.partId = WP_MDIRESTOREBUTTON; - theme.rect = buttonRect; - if (!(flags & State_Enabled)) - theme.stateId = CBS_INACTIVE; - else if (flags & State_Sunken && (option->activeSubControls & SC_MdiNormalButton)) - theme.stateId = CBS_PUSHED; - else if (flags & State_MouseOver && (option->activeSubControls & SC_MdiNormalButton)) - theme.stateId = CBS_HOT; - else - theme.stateId = CBS_NORMAL; - d->drawBackground(theme); - } + if (option->subControls.testFlag(SC_MdiNormalButton)) { + populateMdiButtonTheme(proxy(), widget, option, SC_MdiNormalButton, WP_MDIRESTOREBUTTON, &theme); + d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget)); } - if (option->subControls & QStyle::SC_MdiMinButton) { - buttonRect = proxy()->subControlRect(CC_MdiControls, option, SC_MdiMinButton, widget); - if (theme.isValid()) { - theme.partId = WP_MDIMINBUTTON; - theme.rect = buttonRect; - if (!(flags & State_Enabled)) - theme.stateId = CBS_INACTIVE; - else if (flags & State_Sunken && (option->activeSubControls & SC_MdiMinButton)) - theme.stateId = CBS_PUSHED; - else if (flags & State_MouseOver && (option->activeSubControls & SC_MdiMinButton)) - theme.stateId = CBS_HOT; - else - theme.stateId = CBS_NORMAL; - d->drawBackground(theme); - } + if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) { + populateMdiButtonTheme(proxy(), widget, option, SC_MdiMinButton, WP_MDIMINBUTTON, &theme); + d->drawBackground(theme, mdiButtonCorrectionFactor(theme, widget)); } } break; @@ -3668,19 +3613,20 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt sz = QWindowsStyle::sizeFromContents(ct, option, sz, widget); break; - case CT_MdiControls: + case CT_MdiControls: { + sz.setHeight(int(QStyleHelper::dpiScaled(19, option))); + int width = 54; if (const QStyleOptionComplex *styleOpt = qstyleoption_cast<const QStyleOptionComplex *>(option)) { - int width = 0; + width = 0; if (styleOpt->subControls & SC_MdiMinButton) width += 17 + 1; if (styleOpt->subControls & SC_MdiNormalButton) width += 17 + 1; if (styleOpt->subControls & SC_MdiCloseButton) width += 17 + 1; - sz = QSize(width, 19); - } else { - sz = QSize(54, 19); } + sz.setWidth(int(QStyleHelper::dpiScaled(width, option))); + } break; default: @@ -3774,8 +3720,7 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const /*! \reimp */ QPalette QWindowsXPStyle::standardPalette() const { - return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal - ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette(); + return QWindowsXPStylePrivate::useXP() ? QPalette() : QWindowsStyle::standardPalette(); } /*! diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h index ad7754e3d4..06b37a6e5c 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h @@ -241,8 +241,8 @@ public: bool isTransparent(XPThemeData &themeData); QRegion region(XPThemeData &themeData); - bool drawBackground(XPThemeData &themeData); - bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio); + bool drawBackground(XPThemeData &themeData, qreal correctionFactor = 1); + bool drawBackgroundThruNativeBuffer(XPThemeData &themeData, qreal aditionalDevicePixelRatio, qreal correctionFactor); bool drawBackgroundDirectly(HDC dc, XPThemeData &themeData, qreal aditionalDevicePixelRatio); bool hasAlphaChannel(const QRect &rect); diff --git a/src/plugins/styles/windowsvista/windowsvista.pro b/src/plugins/styles/windowsvista/windowsvista.pro index c08db7f533..483914c13d 100644 --- a/src/plugins/styles/windowsvista/windowsvista.pro +++ b/src/plugins/styles/windowsvista/windowsvista.pro @@ -11,9 +11,7 @@ HEADERS += qwindowsxpstyle_p.h qwindowsxpstyle_p_p.h SOURCES += qwindowsxpstyle.cpp QMAKE_USE_PRIVATE += user32 gdi32 - -# DEFINES/LIBS needed for qwizard_win.cpp and the styles -include(../../../widgets/kernel/win.pri) +LIBS_PRIVATE *= -luxtheme DISTFILES += windowsvistastyle.json |