Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fixes for GCC 13 and MinGW compilers #52

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/src/csd/FramelessWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct FramelessWindow::Impl {
QVBoxLayout* rootLayout{ nullptr };
QMenuBar* menuBar{ nullptr };
QWidget* contentWidget{ nullptr };
#ifdef WIN32
#ifdef _WIN32
WindowsTitleBar* titleBar{ nullptr };
QPointer<FramelessWindowBehavior> behavior{ nullptr };
#endif
Expand All @@ -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);
Expand All @@ -77,7 +77,7 @@ struct FramelessWindow::Impl {
rootLayout->setMenuBar(menuBar);
#endif
}
#ifdef WIN32
#ifdef _WIN32
void createBehavior() {
if (behavior)
return;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand Down
34 changes: 17 additions & 17 deletions lib/src/csd/FramelessWindowBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#include <QScreen>
#include <QWindow>

#ifdef WIN32
#ifdef _WIN32
# include <QtWin>
# include <windows.h>
# include <windowsx.h>
# include <winuser.h>
#endif // WIN32
#endif // _WIN32

#include <array>
#include <algorithm>
Expand Down Expand Up @@ -127,7 +127,7 @@ void FramelessWindowBehavior::setSystemMenuAreaWidth(int width) {
}

void FramelessWindowBehavior::showSystemMenu(const QPoint& position) {
#ifdef WIN32
#ifdef _WIN32
const auto hWnd = reinterpret_cast<HWND>(_parentWindowHandle->winId());

const auto menu = ::GetSystemMenu(hWnd, FALSE);
Expand All @@ -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) {
Expand All @@ -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;

Expand Down Expand Up @@ -369,7 +369,7 @@ void FramelessWindowBehavior::updateNativeWindowProperties() {
}

int FramelessWindowBehavior::hitTest(const QPoint& mousePos) const {
#ifdef WIN32
#ifdef _WIN32
enum RegionMask {
Client = 0x0000,
Top = 0x0001,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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)) {
Expand All @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -581,6 +581,6 @@ bool FramelessWindowBehavior::isMaximized(const QWindow* const window) {
#else
Q_UNUSED(window);
return false;
#endif // WIN32
#endif // _WIN32
}
} // namespace oclero::qlementine
2 changes: 1 addition & 1 deletion lib/src/resources/ResourceInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/src/style/QlementineStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 8 additions & 4 deletions lib/src/widgets/Switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ void Switch::setupAnimation() {
const QColor& Switch::getBgColor() const {
const auto* style = this->style();
const auto* qlementineStyle = qobject_cast<const QlementineStyle*>(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;
Expand All @@ -259,21 +260,23 @@ const QColor& Switch::getBgColor() const {
const QColor& Switch::getBorderColor() const {
const auto* style = this->style();
const auto* qlementineStyle = qobject_cast<const QlementineStyle*>(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;
}

const QColor& Switch::getFgColor() const {
const auto* style = this->style();
const auto* qlementineStyle = qobject_cast<const QlementineStyle*>(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;
Expand All @@ -282,10 +285,11 @@ const QColor& Switch::getFgColor() const {
const QColor& Switch::getTextColor() const {
const auto* style = this->style();
const auto* qlementineStyle = qobject_cast<const QlementineStyle*>(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;
}
Expand Down