From 3e942c3dc8955be577079fbc028ce216e1c594b2 Mon Sep 17 00:00:00 2001 From: SineStriker <55847490+SineStriker@users.noreply.github.com> Date: 周二, 11 2月 2025 19:07:53 +0800 Subject: [PATCH] Fix numerous bugs (#162) --- examples/mainwindow/mainwindow.cpp | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 36 insertions(+), 18 deletions(-) diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index 7492b43..a8d2c61 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -188,24 +188,26 @@ winStyleGroup->addAction(acrylicAction); winStyleGroup->addAction(micaAction); winStyleGroup->addAction(micaAltAction); - connect(winStyleGroup, &QActionGroup::triggered, this, [this, winStyleGroup](QAction *action) { - // Unset all custom style attributes first, otherwise the style will not display correctly - for (const QAction* _act : winStyleGroup->actions()) { - const QString data = _act->data().toString(); - if (data.isEmpty() || data == QStringLiteral("none")) { - continue; - } - windowAgent->setWindowAttribute(data, false); - } - const QString data = action->data().toString(); - if (data == QStringLiteral("none")) { - setProperty("custom-style", false); - } else if (!data.isEmpty()) { - windowAgent->setWindowAttribute(data, true); - setProperty("custom-style", true); - } - style()->polish(this); - }); + connect(winStyleGroup, &QActionGroup::triggered, this, + [this, winStyleGroup](QAction *action) { + // Unset all custom style attributes first, otherwise the style will not display + // correctly + for (const QAction *_act : winStyleGroup->actions()) { + const QString data = _act->data().toString(); + if (data.isEmpty() || data == QStringLiteral("none")) { + continue; + } + windowAgent->setWindowAttribute(data, false); + } + const QString data = action->data().toString(); + if (data == QStringLiteral("none")) { + setProperty("custom-style", false); + } else if (!data.isEmpty()) { + windowAgent->setWindowAttribute(data, true); + setProperty("custom-style", true); + } + style()->polish(this); + }); #elif defined(Q_OS_MAC) auto darkBlurAction = new QAction(tr("Dark blur"), menuBar); @@ -283,6 +285,12 @@ iconButton->setObjectName(QStringLiteral("icon-button")); iconButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + auto pinButton = new QWK::WindowButton(); + pinButton->setCheckable(true); + pinButton->setObjectName(QStringLiteral("pin-button")); + pinButton->setProperty("system-button", true); + pinButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + auto minButton = new QWK::WindowButton(); minButton->setObjectName(QStringLiteral("min-button")); minButton->setProperty("system-button", true); @@ -303,6 +311,7 @@ auto windowBar = new QWK::WindowBar(); #ifndef Q_OS_MAC windowBar->setIconButton(iconButton); + windowBar->setPinButton(pinButton); windowBar->setMinButton(minButton); windowBar->setMaxButton(maxButton); windowBar->setCloseButton(closeButton); @@ -313,6 +322,7 @@ windowAgent->setTitleBar(windowBar); #ifndef Q_OS_MAC + windowAgent->setHitTestVisible(pinButton, true); windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton); windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); @@ -331,6 +341,14 @@ #ifndef Q_OS_MAC + connect(windowBar, &QWK::WindowBar::pinRequested, this, [this, pinButton](bool pin){ + if (isHidden() || isMinimized() || isMaximized() || isFullScreen()) { + return; + } + setWindowFlag(Qt::WindowStaysOnTopHint, pin); + show(); + pinButton->setChecked(pin); + }); connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized); connect(windowBar, &QWK::WindowBar::maximizeRequested, this, [this, maxButton](bool max) { if (max) { -- Gitblit v1.9.1