From 72522517688d68a25a543a1da2497a4b8f6b424b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 12 Sep 2019 09:43:21 +0200 Subject: Brush up the Windows styles - use range-based for loops where possible - use nullptr - use member initialization - remove a lot of C-style casts - use override - fix some signedness warnings - add some missing break statements Task-number: QTBUG-76493 Change-Id: Ica6ed65ec29e958406e54d816b8a679ed81bd177 Reviewed-by: Oliver Wolff --- src/plugins/styles/windowsvista/main.cpp | 4 +- .../styles/windowsvista/qwindowsvistastyle.cpp | 110 +++++++------- .../styles/windowsvista/qwindowsvistastyle_p_p.h | 2 +- .../styles/windowsvista/qwindowsxpstyle.cpp | 158 ++++++++++----------- .../styles/windowsvista/qwindowsxpstyle_p_p.h | 61 ++++---- src/widgets/styles/qwindowsstyle.cpp | 28 ++-- src/widgets/styles/qwindowsstyle_p_p.h | 4 +- 7 files changed, 180 insertions(+), 187 deletions(-) diff --git a/src/plugins/styles/windowsvista/main.cpp b/src/plugins/styles/windowsvista/main.cpp index d5048e45b7..5e7bcf5e6e 100644 --- a/src/plugins/styles/windowsvista/main.cpp +++ b/src/plugins/styles/windowsvista/main.cpp @@ -48,7 +48,7 @@ class QWindowsVistaStylePlugin : public QStylePlugin Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QStyleFactoryInterface" FILE "windowsvistastyle.json") public: - QStyle *create(const QString &key); + QStyle *create(const QString &key) override; }; QStyle *QWindowsVistaStylePlugin::create(const QString &key) @@ -56,7 +56,7 @@ QStyle *QWindowsVistaStylePlugin::create(const QString &key) if (key.compare(QLatin1String("windowsvista"), Qt::CaseInsensitive) == 0) return new QWindowsVistaStyle(); - return 0; + return nullptr; } QT_END_NAMESPACE diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp index feb2bc824b..e213d65946 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle.cpp @@ -44,7 +44,6 @@ #include #include #include -#include #include QT_BEGIN_NAMESPACE @@ -91,7 +90,7 @@ bool QWindowsVistaStylePrivate::useVista() Checks and returns the style object */ inline QObject *styleObject(const QStyleOption *option) { - return option ? option->styleObject : 0; + return option ? option->styleObject : nullptr; } /* \internal @@ -116,7 +115,7 @@ static inline QImage createAnimationBuffer(const QStyleOption *option, const QWi Used by animations to clone a styleoption and shift its offset */ QStyleOption *clonedAnimationStyleOption(const QStyleOption*option) { - QStyleOption *styleOption = 0; + QStyleOption *styleOption = nullptr; if (const QStyleOptionSlider *slider = qstyleoption_cast(option)) styleOption = new QStyleOptionSlider(*slider); else if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast(option)) @@ -297,7 +296,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = oldState && @@ -315,7 +314,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (doTransition) { QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); @@ -340,7 +339,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt // The end state of the transition is simply the result we would have painted // if the style was not animated. - styleOption->styleObject = 0; + styleOption->styleObject = nullptr; styleOption->state = option->state; proxy()->drawPrimitive(element, styleOption, &endPainter, widget); @@ -355,7 +354,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt //translate state flags to UXTHEME states : if (element == PE_FrameLineEdit) { - theme = OpenThemeData(0, L"Edit"); + theme = OpenThemeData(nullptr, L"Edit"); partId = EP_EDITBORDER_NOSCROLL; if (oldState & State_MouseOver) @@ -373,7 +372,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt toState = ETS_NORMAL; } else { - theme = OpenThemeData(0, L"Button"); + theme = OpenThemeData(nullptr, L"Button"); if (element == PE_IndicatorRadioButton) partId = BP_RADIOBUTTON; else if (element == PE_IndicatorCheckBox) @@ -389,7 +388,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt if (theme && SUCCEEDED(GetThemeTransitionDuration(theme, partId, fromState, toState, TMT_TRANSITIONDURATIONS, &duration))) { - t->setDuration(duration); + t->setDuration(int(duration)); } t->setStartTime(QTime::currentTime()); @@ -534,7 +533,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt else if (state & State_MouseOver) stateId = EBS_HOT; - XPThemeData theme(0, painter, QWindowsXPStylePrivate::EditTheme, + XPThemeData theme(nullptr, painter, QWindowsXPStylePrivate::EditTheme, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(element, option, painter, widget); @@ -581,27 +580,26 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else { - int stateId = ETS_NORMAL; - if (!(state & State_Enabled)) - stateId = ETS_DISABLED; - else if (state & State_ReadOnly) - stateId = ETS_READONLY; - else if (state & State_MouseOver) - stateId = ETS_HOT; - else if (state & State_HasFocus) - stateId = ETS_SELECTED; - XPThemeData theme(widget, painter, - QWindowsXPStylePrivate::EditTheme, - EP_EDITBORDER_NOSCROLL, stateId, option->rect); - theme.noContent = true; - painter->save(); - QRegion clipRegion = option->rect; - clipRegion -= option->rect.adjusted(2, 2, -2, -2); - painter->setClipRegion(clipRegion); - d->drawBackground(theme); - painter->restore(); } + int stateId = ETS_NORMAL; + if (!(state & State_Enabled)) + stateId = ETS_DISABLED; + else if (state & State_ReadOnly) + stateId = ETS_READONLY; + else if (state & State_MouseOver) + stateId = ETS_HOT; + else if (state & State_HasFocus) + stateId = ETS_SELECTED; + XPThemeData theme(widget, painter, + QWindowsXPStylePrivate::EditTheme, + EP_EDITBORDER_NOSCROLL, stateId, option->rect); + theme.noContent = true; + painter->save(); + QRegion clipRegion = option->rect; + clipRegion -= option->rect.adjusted(2, 2, -2, -2); + painter->setClipRegion(clipRegion); + d->drawBackground(theme); + painter->restore(); } break; @@ -724,7 +722,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt d->drawBackground(theme); } else { QWindowsXPStyle::drawPrimitive(PE_PanelItemViewItem, option, painter, widget); - break;; + break; } QPixmapCache::insert(key, pixmap); } @@ -770,7 +768,7 @@ void QWindowsVistaStyle::drawPrimitive(PrimitiveElement element, const QStyleOpt case PE_Widget: { #if QT_CONFIG(dialogbuttonbox) - const QDialogButtonBox *buttonBox = 0; + const QDialogButtonBox *buttonBox = nullptr; if (qobject_cast (widget)) buttonBox = widget->findChild(QLatin1String("qt_msgbox_buttonbox")); @@ -844,7 +842,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int oldState = styleObject->property("_q_stylestate").toInt(); oldRect = styleObject->property("_q_stylerect").toRect(); newRect = option->rect; - styleObject->setProperty("_q_stylestate", (int)option->state); + styleObject->setProperty("_q_stylestate", int(option->state)); styleObject->setProperty("_q_stylerect", option->rect); bool wasDefault = false; @@ -870,7 +868,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QWindowsVistaTransition *t = new QWindowsVistaTransition(styleObject); QWindowsVistaAnimation *anim = qobject_cast(d->animation(styleObject)); QStyleOption *styleOption = clonedAnimationStyleOption(option); - styleOption->state = (QStyle::State)oldState; + styleOption->state = QStyle::State(oldState); QImage startImage = createAnimationBuffer(option, widget); QPainter startPainter(&startImage); @@ -892,12 +890,12 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption DWORD duration = 0; - const HTHEME theme = OpenThemeData(0, L"Button"); + const HTHEME theme = OpenThemeData(nullptr, L"Button"); int fromState = buttonStateId(oldState, BP_PUSHBUTTON); int toState = buttonStateId(option->state, BP_PUSHBUTTON); if (GetThemeTransitionDuration(theme, BP_PUSHBUTTON, fromState, toState, TMT_TRANSITIONDURATIONS, &duration) == S_OK) - t->setDuration(duration); + t->setDuration(int(duration)); else t->setDuration(0); t->setStartTime(QTime::currentTime()); @@ -983,7 +981,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ToolBarTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_DROPDOWNBUTTON); if (theme.isValid()) { const QSizeF size = theme.size() * QStyleHelper::dpiScaled(1, option); @@ -992,7 +990,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption mbih = qRound(size.height()); } } - QRect ir = subElementRect(SE_PushButtonContents, option, 0); + QRect ir = subElementRect(SE_PushButtonContents, option, nullptr); QStyleOptionButton newBtn = *btn; newBtn.rect = QStyle::visualRect(option->direction, option->rect, QRect(ir.right() - mbiw - 2, @@ -1137,7 +1135,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption QPalette::ColorRole textRole = disabled ? QPalette::Text : QPalette::ButtonText; QPixmap pix = mbi->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, option, widget), QIcon::Normal); - uint alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; + int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget)) alignment |= Qt::TextHideMnemonic; @@ -1177,7 +1175,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int checkcol = qRound(qreal(25) * factor); const int gutterWidth = qRound(qreal(3) * factor); { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::MenuTheme, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; themeSize.partId = MENU_POPUPCHECK; @@ -1394,7 +1392,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption int mw = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, dwOpt, widget); int fw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, dwOpt, widget); const QDockWidget *dw = qobject_cast(widget); - bool isFloating = dw != 0 && dw->isFloating(); + bool isFloating = dw && dw->isFloating(); QRect r = option->rect.adjusted(0, 2, -1, -3); QRect titleRect = r; @@ -1411,7 +1409,7 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -1517,8 +1515,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle int oldActiveControls = styleObject->property("_q_stylecontrols").toInt(); QRect oldRect = styleObject->property("_q_stylerect").toRect(); - styleObject->setProperty("_q_stylestate", (int)option->state); - styleObject->setProperty("_q_stylecontrols", (int)option->activeSubControls); + styleObject->setProperty("_q_stylestate", int(option->state)); + styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls)); styleObject->setProperty("_q_stylerect", option->rect); bool doTransition = ((state & State_Sunken) != (oldState & State_Sunken) || @@ -1562,8 +1560,8 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // Draw transition source if (!anim) { - styleOption->state = (QStyle::State)oldState; - styleOption->activeSubControls = (QStyle::SubControl)oldActiveControls; + styleOption->state = QStyle::State(oldState); + styleOption->activeSubControls = QStyle::SubControl(oldActiveControls); proxy()->drawComplexControl(control, styleOption, &startPainter, widget); } else { anim->paint(&startPainter, option); @@ -1814,7 +1812,7 @@ void QWindowsVistaStyle::drawComplexControl(ComplexControl control, const QStyle // That however breaks with QtQuickControls where this results in transparent // spinbox background, so if there's no "widget" passed (QtQuickControls case), // let ftheme.noContent be false, which fixes the spinbox rendering in QQC - ftheme.noContent = (widget != NULL); + ftheme.noContent = (widget != nullptr); d->drawBackground(ftheme); } if (sub & SC_SpinBoxUp) { @@ -1871,7 +1869,7 @@ QSize QWindowsVistaStyle::sizeFromContents(ContentsType type, const QStyleOption sz = QWindowsXPStyle::sizeFromContents(type, option, size, widget); int minimumHeight; { - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::MenuTheme, MENU_POPUPCHECKBACKGROUND, MBI_HOT); XPThemeData themeSize = theme; @@ -1939,7 +1937,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption case SE_PushButtonContents: if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; - const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"Button"); + const HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"Button"); if (theme) { int stateId = PBS_NORMAL; if (!(option->state & State_Enabled)) @@ -1954,7 +1952,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1972,7 +1970,7 @@ QRect QWindowsVistaStyle::subElementRect(SubElement element, const QStyleOption int y = option->rect.y(); int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, option, widget); - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::HeaderTheme, HP_HEADERSORTARROW, HSAS_SORTEDDOWN, option->rect); @@ -2045,7 +2043,7 @@ static bool buttonVisible(const QStyle::SubControl sc, const QStyleOptionTitleBa bool isMinimized = tb->titleBarState & Qt::WindowMinimized; bool isMaximized = tb->titleBarState & Qt::WindowMaximized; - const uint flags = tb->titleBarFlags; + const auto flags = tb->titleBarFlags; bool retVal = false; switch (sc) { case QStyle::SC_TitleBarContextHelpButton: @@ -2103,7 +2101,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co if (option) { if (QStyleHintReturnMask *mask = qstyleoption_cast(returnData)) { ret = true; - XPThemeData themeData(widget, 0, + XPThemeData themeData(widget, nullptr, QWindowsXPStylePrivate::ToolTipTheme, TTP_STANDARD, TTSS_NORMAL, option->rect); mask->region = d->region(themeData); @@ -2112,7 +2110,7 @@ int QWindowsVistaStyle::styleHint(StyleHint hint, const QStyleOption *option, co break; case SH_Table_GridLineColor: if (option) - ret = option->palette.color(QPalette::Base).darker(118).rgb(); + ret = int(option->palette.color(QPalette::Base).darker(118).rgb()); else ret = -1; break; @@ -2323,7 +2321,7 @@ void QWindowsVistaStyle::polish(QWidget *widget) //we do not have to care about unpolishing widget->setContentsMargins(3, 0, 4, 0); COLORREF bgRef; - HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : 0, L"TOOLTIP"); + HTHEME theme = OpenThemeData(widget ? QWindowsVistaStylePrivate::winId(widget) : nullptr, L"TOOLTIP"); if (theme && SUCCEEDED(GetThemeColor(theme, TTP_STANDARD, TTSS_NORMAL, TMT_TEXTCOLOR, &bgRef))) { QColor textColor = QColor::fromRgb(bgRef); QPalette pal; @@ -2463,7 +2461,7 @@ QIcon QWindowsVistaStyle::standardIcon(StandardPixmap standardIcon, switch(standardIcon) { case SP_CommandLink: { - XPThemeData theme(0, 0, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_COMMANDLINKGLYPH, CMDLGS_NORMAL); if (theme.isValid()) { diff --git a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h index d66b17e9f8..8fef9f9927 100644 --- a/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsvistastyle_p_p.h @@ -162,7 +162,7 @@ class QWindowsVistaAnimation : public QBlendStyleAnimation public: QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { } - virtual bool isUpdateNeeded() const; + bool isUpdateNeeded() const override; void paint(QPainter *painter, const QStyleOption *option); }; diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp index e2c5bdc924..bf80138b32 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle.cpp @@ -117,7 +117,7 @@ static inline QBackingStore *backingStoreForWidget(const QWidget *widget) if (const QWidget *topLevel = widget->nativeParentWidget()) if (QBackingStore *topLevelBackingStore = topLevel->backingStore()) return topLevelBackingStore; - return 0; + return nullptr; } static inline HDC hdcForWidgetBackingStore(const QWidget *widget) @@ -127,7 +127,7 @@ static inline HDC hdcForWidgetBackingStore(const QWidget *widget) if (nativeInterface) return static_cast(nativeInterface->nativeResourceForBackingStore(QByteArrayLiteral("getDC"), backingStore)); } - return 0; + return nullptr; } // Theme data helper ------------------------------------------------------------------------------ @@ -148,7 +148,7 @@ bool XPThemeData::isValid() HTHEME XPThemeData::handle() { if (!QWindowsXPStylePrivate::useXP()) - return 0; + return nullptr; if (!htheme) htheme = QWindowsXPStylePrivate::createTheme(theme, QWindowsXPStylePrivate::winId(widget)); @@ -175,10 +175,10 @@ RECT XPThemeData::toRECT(const QRect &qr) HRGN XPThemeData::mask(QWidget *widget) { if (!IsThemeBackgroundPartiallyTransparent(handle(), partId, stateId)) - return 0; + return nullptr; HRGN hrgn; - HDC dc = 0; + HDC dc = nullptr; if (widget) dc = hdcForWidgetBackingStore(widget); RECT nativeRect = toRECT(rect); @@ -188,7 +188,7 @@ HRGN XPThemeData::mask(QWidget *widget) // QWindowsXPStylePrivate ------------------------------------------------------------------------- // Static initializations -HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = 0; +HWND QWindowsXPStylePrivate::m_vistaTreeViewHelper = nullptr; HTHEME QWindowsXPStylePrivate::m_themes[NThemes]; bool QWindowsXPStylePrivate::use_xp = false; QBasicAtomicInt QWindowsXPStylePrivate::ref = Q_BASIC_ATOMIC_INITIALIZER(-1); // -1 based refcounting @@ -227,7 +227,7 @@ bool QWindowsXPStylePrivate::useXP(bool update) { if (!update) return use_xp; - return use_xp = IsThemeActive() && (IsAppThemed() || !QApplication::instance()); + return use_xp = IsThemeActive() && (IsAppThemed() || !QCoreApplication::instance()); } /* \internal @@ -241,7 +241,7 @@ void QWindowsXPStylePrivate::init(bool force) ref.ref(); useXP(true); - std::fill(m_themes, m_themes + NThemes, HTHEME(0)); + std::fill(m_themes, m_themes + NThemes, nullptr); } /* \internal @@ -253,12 +253,12 @@ void QWindowsXPStylePrivate::cleanup(bool force) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } if(bufferDC) DeleteDC(bufferDC); - bufferDC = 0; + bufferDC = nullptr; if (ref.deref() && !force) return; @@ -282,7 +282,7 @@ void QWindowsXPStylePrivate::cleanup(bool force) static inline HWND createTreeViewHelperWindow() { if (QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface()) { - void *hwnd = 0; + void *hwnd = nullptr; void *wndProc = reinterpret_cast(DefWindowProc); if (QMetaObject::invokeMethod(ni, "createMessageWindow", Qt::DirectConnection, Q_RETURN_ARG(void*, hwnd), @@ -292,7 +292,7 @@ static inline HWND createTreeViewHelperWindow() return reinterpret_cast(hwnd); } } - return 0; + return nullptr; } bool QWindowsXPStylePrivate::initVistaTreeViewTheming() @@ -305,7 +305,7 @@ bool QWindowsXPStylePrivate::initVistaTreeViewTheming() qWarning("Unable to create the treeview helper window."); return false; } - if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", NULL))) { + if (FAILED(SetWindowTheme(m_vistaTreeViewHelper, L"explorer", nullptr))) { qErrnoWarning("SetWindowTheme() failed."); cleanupVistaTreeViewTheming(); return false; @@ -317,7 +317,7 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() { if (m_vistaTreeViewHelper) { DestroyWindow(m_vistaTreeViewHelper); - m_vistaTreeViewHelper = 0; + m_vistaTreeViewHelper = nullptr; } } @@ -328,11 +328,12 @@ void QWindowsXPStylePrivate::cleanupVistaTreeViewTheming() */ void QWindowsXPStylePrivate::cleanupHandleMap() { - for (int i = 0; i < NThemes; ++i) - if (m_themes[i]) { - CloseThemeData(m_themes[i]); - m_themes[i] = 0; + for (auto &theme : m_themes) { + if (theme) { + CloseThemeData(theme); + theme = nullptr; } + } QWindowsXPStylePrivate::cleanupVistaTreeViewTheming(); } @@ -340,7 +341,7 @@ HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) { if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) { qWarning("Invalid parameters #%d, %p", theme, hwnd); - return 0; + return nullptr; } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; @@ -427,16 +428,16 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) if (bufferDC && nullBitmap) SelectObject(bufferDC, nullBitmap); DeleteObject(bufferBitmap); - bufferBitmap = 0; + bufferBitmap = nullptr; } w = qMax(bufferW, w); h = qMax(bufferH, h); if (!bufferDC) { - HDC displayDC = GetDC(0); + HDC displayDC = GetDC(nullptr); bufferDC = CreateCompatibleDC(displayDC); - ReleaseDC(0, displayDC); + ReleaseDC(nullptr, displayDC); } // Define the header @@ -450,22 +451,22 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) bmi.bmiHeader.biCompression = BI_RGB; // Create the pixmap - bufferPixels = 0; - bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, (void **) &bufferPixels, 0, 0); + bufferPixels = nullptr; + bufferBitmap = CreateDIBSection(bufferDC, &bmi, DIB_RGB_COLORS, reinterpret_cast(&bufferPixels), nullptr, 0); GdiFlush(); - nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); + nullBitmap = static_cast(SelectObject(bufferDC, bufferBitmap)); if (Q_UNLIKELY(!bufferBitmap)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } if (Q_UNLIKELY(!bufferPixels)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); bufferW = 0; bufferH = 0; - return 0; + return nullptr; } bufferW = w; bufferH = h; @@ -493,7 +494,7 @@ bool QWindowsXPStylePrivate::isTransparent(XPThemeData &themeData) */ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) { - HRGN hRgn = 0; + HRGN hRgn = nullptr; const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(themeData.widget); RECT rect = themeData.toRECT(QRect(themeData.rect.topLeft() / factor, themeData.rect.size() / factor)); if (!SUCCEEDED(GetThemeBackgroundRegion(themeData.handle(), bufferHDC(), themeData.partId, @@ -502,12 +503,12 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) } HRGN dest = CreateRectRgn(0, 0, 0, 0); - const bool success = CombineRgn(dest, hRgn, 0, RGN_COPY) != ERROR; + const bool success = CombineRgn(dest, hRgn, nullptr, RGN_COPY) != ERROR; QRegion region; if (success) { - int numBytes = GetRegionData(dest, 0, 0); + const auto numBytes = GetRegionData(dest, 0, nullptr); if (numBytes == 0) return QRegion(); @@ -551,7 +552,7 @@ bool QWindowsXPStylePrivate::hasAlphaChannel(const QRect &rect) int firstAlpha = -1; for (int y = startY; y < h/2; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { int alpha = (*buffer) >> 24; if (firstAlpha == -1) @@ -580,7 +581,7 @@ bool QWindowsXPStylePrivate::fixAlphaChannel(const QRect &rect) bool hasFixedAlphaValue = false; for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { uint pixel = *buffer; int alpha = qAlpha(pixel); @@ -612,7 +613,7 @@ bool QWindowsXPStylePrivate::swapAlphaChannel(const QRect &rect, bool allPixels) // Flip the alphas, so that 255-alpha pixels are 0, and 0-alpha are 255. for (int y = startY; y < h; ++y) { - DWORD *buffer = (DWORD*)bufferPixels + (y * bufferW); + auto buffer = reinterpret_cast(bufferPixels) + (y * bufferW); for (int x = startX; x < w; ++x, ++buffer) { if (allPixels) { *buffer |= 0xFF000000; @@ -668,7 +669,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) return true; QPainter *painter = themeData.painter; - Q_ASSERT_X(painter != 0, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); + Q_ASSERT_X(painter != nullptr, "QWindowsXPStylePrivate::drawBackground()", "Trying to draw a theme part without a painter"); if (!painter || !painter->isActive()) return false; @@ -706,7 +707,7 @@ bool QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) } } - const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : HDC(0); + const HDC dc = canDrawDirectly ? hdcForWidgetBackingStore(themeData.widget) : nullptr; const bool result = dc ? drawBackgroundDirectly(dc, themeData, aditionalDevicePixelRatio) : drawBackgroundThruNativeBuffer(themeData, aditionalDevicePixelRatio); @@ -740,7 +741,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa { QPainter *painter = themeData.painter; - const auto deviceTransform = painter->deviceTransform(); + const auto &deviceTransform = painter->deviceTransform(); const QPointF redirectionDelta(deviceTransform.dx(), deviceTransform.dy()); const QRect area = scaleRect(QRectF(themeData.rect), additionalDevicePixelRatio).translated(redirectionDelta).toRect(); @@ -771,7 +772,7 @@ bool QWindowsXPStylePrivate::drawBackgroundDirectly(HDC dc, XPThemeData &themeDa | (themeData.mirrorHorizontally ? DTBG_MIRRORDC : 0); const HRESULT result = DrawThemeBackgroundEx(themeData.handle(), dc, themeData.partId, themeData.stateId, &(drawRECT), &drawOptions); - SelectClipRgn(dc, 0); + SelectClipRgn(dc, nullptr); DeleteObject(hrgn); return SUCCEEDED(result); } @@ -1099,9 +1100,7 @@ QWindowsXPStyle::QWindowsXPStyle() /*! Destroys the style. */ -QWindowsXPStyle::~QWindowsXPStyle() -{ -} +QWindowsXPStyle::~QWindowsXPStyle() = default; /*! \reimp */ void QWindowsXPStyle::unpolish(QApplication *app) @@ -1157,7 +1156,7 @@ void QWindowsXPStyle::polish(QWidget *widget) if (!d->hasInitColors) { // Get text color for group box labels COLORREF cref; - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, 0, 0); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, 0, 0); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_NORMAL, TMT_TEXTCOLOR, &cref); d->groupBoxTextColor = qRgb(GetRValue(cref), GetGValue(cref), GetBValue(cref)); GetThemeColor(theme.handle(), BP_GROUPBOX, GBS_DISABLED, TMT_TEXTCOLOR, &cref); @@ -1270,7 +1269,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, if (const QStyleOptionButton *btn = qstyleoption_cast(option)) { MARGINS borderSize; if (widget) { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme); HTHEME theme = buttontheme.handle(); if (theme) { int stateId; @@ -1288,7 +1287,7 @@ QRect QWindowsXPStyle::subElementRect(SubElement sr, const QStyleOption *option, int border = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget); rect = option->rect.adjusted(border, border, -border, -border); - if (SUCCEEDED(GetThemeMargins(theme, NULL, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, NULL, &borderSize))) { + if (SUCCEEDED(GetThemeMargins(theme, nullptr, BP_PUSHBUTTON, stateId, TMT_CONTENTMARGINS, nullptr, &borderSize))) { rect.adjust(borderSize.cxLeftWidth, borderSize.cyTopHeight, -borderSize.cxRightWidth, -borderSize.cyBottomHeight); rect = visualRect(option->direction, option->rect, rect); @@ -1468,7 +1467,7 @@ case PE_Frame: return; themeNumber = QWindowsXPStylePrivate::ListViewTheme; partId = LVP_LISTGROUP; - XPThemeData theme(widget, 0, themeNumber, partId, 0); + XPThemeData theme(widget, nullptr, themeNumber, partId); if (!(flags & State_Enabled)) stateId = ETS_DISABLED; @@ -1496,9 +1495,9 @@ case PE_Frame: p->drawRect(QRectF(option->rect).adjusted(0, 0, -topLevelAdjustment, -topLevelAdjustment)); p->setPen(oldPen); return; - } else if (fillType == BT_NONE) { - return; } + if (fillType == BT_NONE) + return; } break; } @@ -1514,7 +1513,8 @@ case PE_Frame: p->drawRect(option->rect.adjusted(0, 0, -1, -1)); p->setPen(oldPen); return; - } else if (qstyleoption_cast(option)) { + } + if (qstyleoption_cast(option)) { themeNumber = QWindowsXPStylePrivate::EditTheme; partId = EP_EDITTEXT; noContent = true; @@ -1538,7 +1538,7 @@ case PE_Frame: if (QWindowsXPStylePrivate::isLineEditBaseColorSet(option, widget)) { p->fillRect(panel->rect, panel->palette.brush(QPalette::Base)); } else { - XPThemeData theme(0, p, themeNumber, partId, stateId, rect); + XPThemeData theme(nullptr, p, themeNumber, partId, stateId, rect); if (!theme.isValid()) { QWindowsStyle::drawPrimitive(pe, option, p, widget); return; @@ -1587,9 +1587,9 @@ case PE_Frame: wchar_t themeFileName[maxlength]; wchar_t themeColor[maxlength]; // Due to a a scaling issue with the XP Silver theme, tab gradients are not used with it - if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, NULL, 0) == S_OK) { - wchar_t *offset = 0; - if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != NULL) { + if (GetCurrentThemeName(themeFileName, maxlength, themeColor, maxlength, nullptr, 0) == S_OK) { + wchar_t *offset = nullptr; + if ((offset = wcsrchr(themeFileName, QChar(QLatin1Char('\\')).unicode())) != nullptr) { offset++; if (!lstrcmp(offset, L"Luna.msstyles") && !lstrcmp(offset, L"Metallic")) { useGradient = false; @@ -1820,7 +1820,7 @@ case PE_Frame: bef_v -= delta; aft_h += delta; aft_v += delta; - XPThemeData theme(0, p, QWindowsXPStylePrivate::XpTreeViewTheme); + XPThemeData theme(nullptr, p, QWindowsXPStylePrivate::XpTreeViewTheme); theme.rect = QRect(bef_h, bef_v, decoration_size, decoration_size); theme.partId = TVP_GLYPH; theme.stateId = flags & QStyle::State_Open ? GLPS_OPENED : GLPS_CLOSED; @@ -1912,7 +1912,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op { themeNumber = QWindowsXPStylePrivate::StatusTheme; partId = SP_GRIPPER; - XPThemeData theme(0, p, themeNumber, partId, 0); + XPThemeData theme(nullptr, p, themeNumber, partId); QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); size.rheight()--; if (const QStyleOptionSizeGrip *sg = qstyleoption_cast(option)) { @@ -1980,7 +1980,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (btn->features & QStyleOptionButton::HasMenu) { int mbiw = 0, mbih = 0; - XPThemeData theme(widget, 0, + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::ToolBarTheme, TP_SPLITBUTTONDROPDOWN); if (theme.isValid()) { @@ -2309,7 +2309,7 @@ void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *op if (isFloating) { titleRect.adjust(0, -fw, 0, 0); - if (widget != 0 && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) + if (widget != nullptr && widget->windowIcon().cacheKey() != QApplication::windowIcon().cacheKey()) titleRect.adjust(titleRect.height() + mw, 0, 0, 0); } else { titleRect.adjust(mw, 0, 0, 0); @@ -2775,7 +2775,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo break; v = nextInterval; } - if (lines.size() > 0) { + if (!lines.isEmpty()) { p->save(); p->translate(slrect.topLeft()); p->drawLines(lines.constData(), lines.size()); @@ -2923,7 +2923,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo p->save(); p->setClipRect(menuarea); tool.rect = option->rect; - proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, 0); + proxy()->drawPrimitive(PE_PanelButtonBevel, &tool, p, nullptr); p->restore(); } // Draw arrow @@ -3223,7 +3223,7 @@ void QWindowsXPStyle::drawComplexControl(ComplexControl cc, const QStyleOptionCo } } -static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = 0) +static inline Qt::Orientation progressBarOrientation(const QStyleOption *option = nullptr) { if (const QStyleOptionProgressBar *pb = qstyleoption_cast(option)) return pb->orientation; @@ -3234,27 +3234,27 @@ int QWindowsXPStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, cons { switch (pm) { case QStyle::PM_IndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).width(); case QStyle::PM_IndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_CHECKBOX, CBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ExclusiveIndicatorWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).width(); case QStyle::PM_ExclusiveIndicatorHeight: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL).height(); case QStyle::PM_ProgressBarChunkWidth: return progressBarOrientation(option) == Qt::Horizontal - ? XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() - : XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); + ? XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNK).width() + : XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::ProgressTheme, PP_CHUNKVERT).height(); case QStyle::PM_SliderThickness: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::TrackBarTheme, TKP_THUMB).height(); case QStyle::PM_TitleBarHeight: return widget && (widget->windowType() == Qt::Tool) ? GetSystemMetrics(SM_CYSMCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME) : GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXSIZEFRAME); case QStyle::PM_MdiSubWindowFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_FRAMELEFT, FS_ACTIVE).width(); case QStyle::PM_DockWidgetFrameWidth: - return XPThemeData::themeSize(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); + return XPThemeData::themeSize(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLFRAMERIGHT, FS_ACTIVE).width(); default: break; } @@ -3620,7 +3620,7 @@ QSize QWindowsXPStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt case CT_LineEdit: case CT_ComboBox: { - XPThemeData buttontheme(widget, 0, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); + XPThemeData buttontheme(widget, nullptr, QWindowsXPStylePrivate::ButtonTheme, BP_PUSHBUTTON, PBS_NORMAL); if (buttontheme.isValid()) { const qreal factor = QWindowsXPStylePrivate::nativeMetricScaleFactor(widget); const QMarginsF borderSize = buttontheme.margins() * factor; @@ -3741,11 +3741,11 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const titleBarRect.setHeight(tbHeight); XPThemeData themeData; if (titlebar->titleBarState & Qt::WindowMinimized) { - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MINCAPTION, CS_ACTIVE, titleBarRect); } else - themeData = XPThemeData(widget, 0, + themeData = XPThemeData(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_CAPTION, CS_ACTIVE, titleBarRect); mask->region = d->region(themeData) + @@ -3774,10 +3774,8 @@ int QWindowsXPStyle::styleHint(StyleHint hint, const QStyleOption *option, const /*! \reimp */ QPalette QWindowsXPStyle::standardPalette() const { - if (QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal) - return *QApplicationPrivate::sys_pal; - else - return QWindowsStyle::standardPalette(); + return QWindowsXPStylePrivate::useXP() && QApplicationPrivate::sys_pal + ? *QApplicationPrivate::sys_pal : QWindowsStyle::standardPalette(); } /*! @@ -3795,7 +3793,7 @@ QPixmap QWindowsXPStyle::standardPixmap(StandardPixmap standardPixmap, const QSt if (qstyleoption_cast(option)) { if (widget && widget->isWindow()) { - XPThemeData theme(widget, 0, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); + XPThemeData theme(widget, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); return QIcon(QWindowsStyle::standardPixmap(standardPixmap, option, widget)).pixmap(size); @@ -3826,9 +3824,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_MAXBUTTON, MAXBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3862,7 +3860,7 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockClose.isNull()) { - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); if (theme.isValid()) { const QSize size = (theme.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); @@ -3896,9 +3894,9 @@ QIcon QWindowsXPStyle::standardIcon(StandardPixmap standardIcon, if (qstyleoption_cast(option)) { if (d->dockFloat.isNull()) { - XPThemeData themeSize(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData themeSize(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_SMALLCLOSEBUTTON, CBS_NORMAL); - XPThemeData theme(0, 0, QWindowsXPStylePrivate::WindowTheme, + XPThemeData theme(nullptr, nullptr, QWindowsXPStylePrivate::WindowTheme, WP_RESTOREBUTTON, RBS_NORMAL); if (theme.isValid()) { const QSize size = (themeSize.size() * QWindowsStylePrivate::nativeMetricScaleFactor(widget)).toSize(); diff --git a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h index 60f9d7e9b7..ad7754e3d4 100644 --- a/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h +++ b/src/plugins/styles/windowsvista/qwindowsxpstyle_p_p.h @@ -100,11 +100,11 @@ class QDebug; class XPThemeData { public: - explicit XPThemeData(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + explicit XPThemeData(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, const QRect &r = QRect()) - : widget(w), painter(p), theme(themeIn), htheme(0), partId(part), stateId(state), + : widget(w), painter(p), theme(themeIn), partId(part), stateId(state), mirrorHorizontally(false), mirrorVertically(false), noBorder(false), - noContent(false), rotate(0), rect(r) + noContent(false), rect(r) {} HRGN mask(QWidget *widget); @@ -117,17 +117,17 @@ public: QMarginsF margins(const QRect &rect, int propId = TMT_CONTENTMARGINS); QMarginsF margins(int propId = TMT_CONTENTMARGINS); - static QSizeF themeSize(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, int part = 0, int state = 0); - static QMarginsF themeMargins(const QRect &rect, const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QSizeF themeSize(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0); + static QMarginsF themeMargins(const QRect &rect, const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); - static QMarginsF themeMargins(const QWidget *w = 0, QPainter *p = 0, int themeIn = -1, + static QMarginsF themeMargins(const QWidget *w = nullptr, QPainter *p = nullptr, int themeIn = -1, int part = 0, int state = 0, int propId = TMT_CONTENTMARGINS); const QWidget *widget; QPainter *painter; int theme; - HTHEME htheme; + HTHEME htheme = nullptr; int partId; int stateId; @@ -135,18 +135,18 @@ public: uint mirrorVertically : 1; uint noBorder : 1; uint noContent : 1; - uint rotate; + uint rotate = 0; QRect rect; }; struct ThemeMapKey { - int theme; - int partId; - int stateId; - bool noBorder; - bool noContent; + int theme = 0; + int partId = -1; + int stateId = -1; + bool noBorder = false; + bool noContent = false; - ThemeMapKey() : partId(-1), stateId(-1) {} + ThemeMapKey() = default; ThemeMapKey(const XPThemeData &data) : theme(data.theme), partId(data.partId), stateId(data.stateId), noBorder(data.noBorder), noContent(data.noContent) {} @@ -171,7 +171,7 @@ enum AlphaChannelType { }; struct ThemeMapData { - AlphaChannelType alphaType; // Which type of alpha on part & state + AlphaChannelType alphaType = UnknownAlpha; // Which type of alpha on part & state bool dataValid : 1; // Only used to detect if hash value is ok bool partIsTransparent : 1; @@ -217,15 +217,13 @@ public: }; QWindowsXPStylePrivate() - : QWindowsStylePrivate(), hasInitColors(false), bufferDC(0), bufferBitmap(0), nullBitmap(0), - bufferPixels(0), bufferW(0), bufferH(0) { init(); } ~QWindowsXPStylePrivate() { cleanup(); } - static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); - static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = 0, const QWidget *widget = 0); + static int pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); + static int fixedPixelMetric(QStyle::PixelMetric pm, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); static HWND winId(const QWidget *widget); @@ -251,10 +249,10 @@ public: bool fixAlphaChannel(const QRect &rect); bool swapAlphaChannel(const QRect &rect, bool allPixels = false); - QRgb groupBoxTextColor; - QRgb groupBoxTextColorDisabled; - QRgb sliderTickColor; - bool hasInitColors; + QRgb groupBoxTextColor = 0; + QRgb groupBoxTextColorDisabled = 0; + QRgb sliderTickColor = 0; + bool hasInitColors = false; static HTHEME createTheme(int theme, HWND hwnd); static QString themeName(int theme); @@ -277,11 +275,12 @@ private: static bool use_xp; QHash alphaCache; - HDC bufferDC; - HBITMAP bufferBitmap; - HBITMAP nullBitmap; - uchar *bufferPixels; - int bufferW, bufferH; + HDC bufferDC = nullptr; + HBITMAP bufferBitmap = nullptr; + HBITMAP nullBitmap = nullptr; + uchar *bufferPixels = nullptr; + int bufferW = 0; + int bufferH = 0; static HWND m_vistaTreeViewHelper; static HTHEME m_themes[NThemes]; @@ -292,7 +291,7 @@ inline QSizeF XPThemeData::size() QSizeF result(0, 0); if (isValid()) { SIZE size; - if (SUCCEEDED(GetThemePartSize(handle(), 0, partId, stateId, 0, TS_TRUE, &size))) + if (SUCCEEDED(GetThemePartSize(handle(), nullptr, partId, stateId, nullptr, TS_TRUE, &size))) result = QSize(size.cx, size.cy); } return result; @@ -304,7 +303,7 @@ inline QMarginsF XPThemeData::margins(const QRect &qRect, int propId) if (isValid()) { MARGINS margins; RECT rect = XPThemeData::toRECT(qRect); - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, &rect, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, &rect, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; @@ -315,7 +314,7 @@ inline QMarginsF XPThemeData::margins(int propId) QMarginsF result(0, 0, 0 ,0); if (isValid()) { MARGINS margins; - if (SUCCEEDED(GetThemeMargins(handle(), 0, partId, stateId, propId, NULL, &margins))) + if (SUCCEEDED(GetThemeMargins(handle(), nullptr, partId, stateId, propId, nullptr, &margins))) result = QMargins(margins.cxLeftWidth, margins.cyTopHeight, margins.cxRightWidth, margins.cyBottomHeight); } return result; diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index 72c803cb99..7d4e1fe9e7 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -120,10 +120,7 @@ enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight }; \internal */ -QWindowsStylePrivate::QWindowsStylePrivate() - : alt_down(false), menuBarTimer(0) -{ -} +QWindowsStylePrivate::QWindowsStylePrivate() = default; qreal QWindowsStylePrivate::appDevicePixelRatio() { @@ -157,7 +154,7 @@ bool QWindowsStyle::eventFilter(QObject *o, QEvent *e) QList l = widget->findChildren(); 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 @@ -242,7 +239,7 @@ void QWindowsStyle::polish(QApplication *app) QCommonStyle::polish(app); QWindowsStylePrivate *d = const_cast(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); const auto &palette = QGuiApplication::palette(); @@ -343,7 +340,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) @@ -698,17 +694,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(); @@ -759,7 +755,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); @@ -980,7 +976,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); @@ -1005,7 +1001,7 @@ 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: @@ -1043,7 +1039,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: @@ -1585,6 +1581,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::Beginning: case QStyleOptionToolBar::OnlyOne: paintBottomBorder = false; + break; default: break; } @@ -1600,6 +1597,7 @@ void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPai case QStyleOptionToolBar::OnlyOne: paintRightBorder = false; paintLeftBorder = false; + break; default: break; } diff --git a/src/widgets/styles/qwindowsstyle_p_p.h b/src/widgets/styles/qwindowsstyle_p_p.h index e6ea809f11..4f6ffcefc2 100644 --- a/src/widgets/styles/qwindowsstyle_p_p.h +++ b/src/widgets/styles/qwindowsstyle_p_p.h @@ -77,9 +77,9 @@ public: bool hasSeenAlt(const QWidget *widget) const; bool altDown() const { return alt_down; } - bool alt_down; + bool alt_down = false; QList seenAlt; - int menuBarTimer; + int menuBarTimer = 0; QColor inactiveCaptionText; QColor activeCaptionColor; -- cgit v1.2.3