From 99c31340244b8ce35b897d44277fc6d41ead9563 Mon Sep 17 00:00:00 2001 From: Hugo Hromic Date: Sun, 21 Apr 2024 13:17:29 +0100 Subject: [PATCH 1/2] Fix dangling reference warnings in GCC 13 * The code is essentially the same but the compiler is happier. --- lib/src/widgets/Switch.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/src/widgets/Switch.cpp b/lib/src/widgets/Switch.cpp index af9b609..1c7bfa5 100644 --- a/lib/src/widgets/Switch.cpp +++ b/lib/src/widgets/Switch.cpp @@ -248,9 +248,10 @@ void Switch::setupAnimation() { const QColor& Switch::getBgColor() const { const auto* style = this->style(); const auto* qlementineStyle = qobject_cast(style); + const auto palette = style->standardPalette(); const auto& bgColor = qlementineStyle ? qlementineStyle->switchGrooveColor( getMouseState(isDown(), _isMouseOver, isEnabled()), getCheckState(isChecked())) - : style->standardPalette().color( + : palette.color( isEnabled() ? QPalette::ColorGroup::Normal : QPalette::ColorGroup::Disabled, QPalette::ColorRole::Button); return bgColor; @@ -259,11 +260,12 @@ const QColor& Switch::getBgColor() const { const QColor& Switch::getBorderColor() const { const auto* style = this->style(); const auto* qlementineStyle = qobject_cast(style); + const auto palette = style->standardPalette(); const auto& borderColor = qlementineStyle ? qlementineStyle->switchGrooveBorderColor( getMouseState(isDown(), _isMouseOver, isEnabled()), getFocusState(hasFocus()), getCheckState(isChecked())) - : style->standardPalette().color( + : palette.color( isEnabled() ? QPalette::ColorGroup::Normal : QPalette::ColorGroup::Disabled, QPalette::ColorRole::ButtonText); return borderColor; } @@ -271,9 +273,10 @@ const QColor& Switch::getBorderColor() const { const QColor& Switch::getFgColor() const { const auto* style = this->style(); const auto* qlementineStyle = qobject_cast(style); + const auto palette = style->standardPalette(); const auto& fgColor = qlementineStyle ? qlementineStyle->switchHandleColor( getMouseState(isDown(), _isMouseOver, isEnabled()), getCheckState(isChecked())) - : style->standardPalette().color( + : palette.color( isEnabled() ? QPalette::ColorGroup::Normal : QPalette::ColorGroup::Disabled, QPalette::ColorRole::ButtonText); return fgColor; @@ -282,10 +285,11 @@ const QColor& Switch::getFgColor() const { const QColor& Switch::getTextColor() const { const auto* style = this->style(); const auto* qlementineStyle = qobject_cast(style); + const auto palette = style->standardPalette(); const auto& textColor = qlementineStyle ? qlementineStyle->labelForegroundColor(getMouseState(isDown(), _isMouseOver, isEnabled()), this) - : style->standardPalette().color( + : palette.color( isEnabled() ? QPalette::ColorGroup::Normal : QPalette::ColorGroup::Disabled, QPalette::ColorRole::Text); return textColor; } From 1da94016f7cbcb68a51cbc03e2b4fe83df3b7bc2 Mon Sep 17 00:00:00 2001 From: Hugo Hromic Date: Sun, 21 Apr 2024 15:55:14 +0100 Subject: [PATCH 2/2] Use correct preprocessor macro for Windows code paths * The `WIN32` _macro_ is not defined by any compiler but only some build systems. - Not to be confused with the `WIN32` _variable_ in CMake. * The standardized macro to use is `_WIN32` which is defined by most Windows compilers. - Reference: * This fixes Qlementine when using MinGW and other non-MSVC compilers. --- lib/src/csd/FramelessWindow.cpp | 12 +++---- lib/src/csd/FramelessWindowBehavior.cpp | 34 ++++++++++---------- lib/src/resources/ResourceInitialization.cpp | 2 +- lib/src/style/QlementineStyle.cpp | 8 ++--- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/src/csd/FramelessWindow.cpp b/lib/src/csd/FramelessWindow.cpp index ffec1d5..f2f9569 100644 --- a/lib/src/csd/FramelessWindow.cpp +++ b/lib/src/csd/FramelessWindow.cpp @@ -40,7 +40,7 @@ struct FramelessWindow::Impl { QVBoxLayout* rootLayout{ nullptr }; QMenuBar* menuBar{ nullptr }; QWidget* contentWidget{ nullptr }; -#ifdef WIN32 +#ifdef _WIN32 WindowsTitleBar* titleBar{ nullptr }; QPointer behavior{ nullptr }; #endif @@ -53,7 +53,7 @@ struct FramelessWindow::Impl { rootLayout->setSpacing(0); rootLayout->setContentsMargins(0, 0, 0, 0); -#ifdef WIN32 +#ifdef _WIN32 // Title bar: stuck the top. titleBar = new WindowsTitleBar(&owner); rootLayout->addWidget(titleBar, 0, Qt::AlignTop); @@ -77,7 +77,7 @@ struct FramelessWindow::Impl { rootLayout->setMenuBar(menuBar); #endif } -#ifdef WIN32 +#ifdef _WIN32 void createBehavior() { if (behavior) return; @@ -106,7 +106,7 @@ FramelessWindow::FramelessWindow(QWidget* parent) // Get rid of system's native window frame. setWindowFlag(Qt::WindowType::Window, true); setWindowFlag(Qt::WindowType::WindowContextHelpButtonHint, false); -#ifdef WIN32 +#ifdef _WIN32 setWindowFlag(Qt::FramelessWindowHint, true); #endif setFocusPolicy(Qt::NoFocus); @@ -125,7 +125,7 @@ QWidget* FramelessWindow::contentWidget() const { void FramelessWindow::setContentWidget(QWidget* content) { if (content != _impl->contentWidget) { -#ifdef WIN32 +#ifdef _WIN32 const auto index = 1; #else const auto index = 0; @@ -161,7 +161,7 @@ void FramelessWindow::paintEvent(QPaintEvent* e) { } bool FramelessWindow::event(QEvent* e) { -#ifdef WIN32 +#ifdef _WIN32 const auto type = e->type(); switch (type) { case QEvent::Type::PaletteChange: diff --git a/lib/src/csd/FramelessWindowBehavior.cpp b/lib/src/csd/FramelessWindowBehavior.cpp index 3a1bf40..16016f9 100644 --- a/lib/src/csd/FramelessWindowBehavior.cpp +++ b/lib/src/csd/FramelessWindowBehavior.cpp @@ -28,12 +28,12 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 # include # include # include # include -#endif // WIN32 +#endif // _WIN32 #include #include @@ -127,7 +127,7 @@ void FramelessWindowBehavior::setSystemMenuAreaWidth(int width) { } void FramelessWindowBehavior::showSystemMenu(const QPoint& position) { -#ifdef WIN32 +#ifdef _WIN32 const auto hWnd = reinterpret_cast(_parentWindowHandle->winId()); const auto menu = ::GetSystemMenu(hWnd, FALSE); @@ -142,7 +142,7 @@ void FramelessWindowBehavior::showSystemMenu(const QPoint& position) { } #else Q_UNUSED(position); -#endif // WIN32 +#endif // _WIN32 } bool FramelessWindowBehavior::eventFilter(QObject* obj, QEvent* evt) { @@ -161,7 +161,7 @@ bool FramelessWindowBehavior::eventFilter(QObject* obj, QEvent* evt) { } bool FramelessWindowBehavior::nativeEventFilter(const QByteArray& eventType, void* message, long* result) { -#ifdef WIN32 +#ifdef _WIN32 if (eventType != QByteArrayLiteral("windows_generic_MSG")) return false; @@ -369,7 +369,7 @@ void FramelessWindowBehavior::updateNativeWindowProperties() { } int FramelessWindowBehavior::hitTest(const QPoint& mousePos) const { -#ifdef WIN32 +#ifdef _WIN32 enum RegionMask { Client = 0x0000, Top = 0x0001, @@ -431,13 +431,13 @@ int FramelessWindowBehavior::hitTest(const QPoint& mousePos) const { return hitTestNativeTitleBar(localPos) ? HTCAPTION : HTCLIENT; #else Q_UNUSED(mousePos); -#endif // WIN32 +#endif // _WIN32 return false; } bool FramelessWindowBehavior::hitTestNativeTitleBar(const QPoint& mousePos) const { -#ifdef WIN32 +#ifdef _WIN32 const int scaledTitleBarHeight = _titleBarHeight * _scaleFactor; if (!_parentWindowWidget) @@ -478,12 +478,12 @@ bool FramelessWindowBehavior::hitTestNativeTitleBar(const QPoint& mousePos) cons } #else Q_UNUSED(mousePos); -#endif // WIN32 +#endif // _WIN32 return true; } QRect FramelessWindowBehavior::availableGeometry() const { -#ifdef WIN32 +#ifdef _WIN32 MONITORINFO monitorInfo{ 0, RECT(), RECT(), 0 }; monitorInfo.cbSize = sizeof(MONITORINFO); @@ -496,13 +496,13 @@ QRect FramelessWindowBehavior::availableGeometry() const { return QRect(monitorInfo.rcWork.left, monitorInfo.rcWork.top, monitorInfo.rcWork.right - monitorInfo.rcWork.left, monitorInfo.rcWork.bottom - monitorInfo.rcWork.top); -#endif // WIN32 +#endif // _WIN32 return QRect(); } QRect FramelessWindowBehavior::systemMenuArea() const { -#ifdef WIN32 +#ifdef _WIN32 QRect rect{ 0, 0, _systemMenuAreaWidth, _titleBarHeight }; if (isMaximized(_parentWindowHandle)) { @@ -512,13 +512,13 @@ QRect FramelessWindowBehavior::systemMenuArea() const { } return rect; -#endif // WIN32 +#endif // _WIN32 return QRect(); } void FramelessWindowBehavior::updateNativeWindowProperties(QWindow* const window) { -#ifdef WIN32 +#ifdef _WIN32 if (!window) return; @@ -561,11 +561,11 @@ void FramelessWindowBehavior::updateNativeWindowProperties(QWindow* const window } #else Q_UNUSED(window); -#endif // WIN32 +#endif // _WIN32 } bool FramelessWindowBehavior::isMaximized(const QWindow* const window) { -#ifdef WIN32 +#ifdef _WIN32 if (!window) return false; @@ -581,6 +581,6 @@ bool FramelessWindowBehavior::isMaximized(const QWindow* const window) { #else Q_UNUSED(window); return false; -#endif // WIN32 +#endif // _WIN32 } } // namespace oclero::qlementine diff --git a/lib/src/resources/ResourceInitialization.cpp b/lib/src/resources/ResourceInitialization.cpp index 8077680..70e3bdc 100644 --- a/lib/src/resources/ResourceInitialization.cpp +++ b/lib/src/resources/ResourceInitialization.cpp @@ -29,7 +29,7 @@ void qlementineResourceInitialization() { // Loads the QRC content. Q_INIT_RESOURCE(qlementine); Q_INIT_RESOURCE(qlementine_font_roboto); -#if defined(WIN32) +#if defined(_WIN32) Q_INIT_RESOURCE(qlementine_font_inter_windows); #else Q_INIT_RESOURCE(qlementine_font_inter); diff --git a/lib/src/style/QlementineStyle.cpp b/lib/src/style/QlementineStyle.cpp index 86e36b3..dcd1ef2 100644 --- a/lib/src/style/QlementineStyle.cpp +++ b/lib/src/style/QlementineStyle.cpp @@ -96,7 +96,7 @@ struct QlementineStyleImpl { /// Registers all the theme fonts to Qt's font database. void installFonts() { -#if defined(WIN32) +#if defined(_WIN32) const auto regularFontPath = QString(":/qlementine/resources/fonts/inter/%1.ttf"); #else const auto regularFontPath = QString(":/qlementine/resources/fonts/inter/%1.otf"); @@ -722,11 +722,11 @@ void QlementineStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption* opt const auto& borderColor = toolTipBorderColor(); // More investigation is needed to make rounded tooltips on Windows. // Currently we only support this feature on MacOS. -#ifdef WIN32 +#ifdef _WIN32 constexpr auto radius = 0; #else const auto radius = _impl->theme.borderRadius; -#endif // WIN32 +#endif // _WIN32 const auto borderW = _impl->theme.borderWidth; p->setRenderHint(QPainter::Antialiasing, true); @@ -4752,7 +4752,7 @@ void QlementineStyle::polish(QWidget* w) { // Currently we only support tooltips with rounded corners on MacOS. // More investigation is need to make it work on Windows. -#ifndef WIN32 +#ifndef _WIN32 if (w->inherits("QTipLabel")) { // TODO: turn this into addAlphaChannel w->setBackgroundRole(QPalette::NoRole);