From df53287060966d78ffccac78342fb5d0a028f835 Mon Sep 17 00:00:00 2001
From: sola.lu <sola.lu.greentest.com.cn>
Date: 周二, 10 6月 2025 19:03:07 +0800
Subject: [PATCH] 1.添加翻译,about,手册,login这几个按钮到标题栏。

---
 examples/mainwindow/mainwindow.cpp |   59 +++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 41 insertions(+), 18 deletions(-)

diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp
index 7492b43..fb3d5eb 100644
--- a/examples/mainwindow/mainwindow.cpp
+++ b/examples/mainwindow/mainwindow.cpp
@@ -188,26 +188,33 @@
         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)
+        // Set whether to use system buttons (close/minimize/zoom)
+        // - true:  Hide system buttons (use custom UI controls)
+        // - false: Show native system buttons (default behavior)
+        windowAgent->setWindowAttribute(QStringLiteral("no-system-buttons"), false);
+
         auto darkBlurAction = new QAction(tr("Dark blur"), menuBar);
         darkBlurAction->setCheckable(true);
         connect(darkBlurAction, &QAction::toggled, this, [this](bool checked) {
@@ -283,6 +290,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 +316,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 +327,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 +346,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