From 44c08f3cc456155b960ca5a115df93109d2202ce Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周三, 13 12月 2023 23:22:25 +0800
Subject: [PATCH] Remove event observer

---
 examples/mainwindow/mainwindow.cpp |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp
index 7246fdd..c18fe5d 100644
--- a/examples/mainwindow/mainwindow.cpp
+++ b/examples/mainwindow/mainwindow.cpp
@@ -32,8 +32,7 @@
 void MainWindow::installWindowAgent() {
     auto agent = new QWK::WidgetWindowAgent(this);
     if (!agent->setup(this)) {
-        qDebug() << "Frameless handle failed to initialize.";
-        return;
+        qFatal("Frameless handle failed to initialize.");
     }
 
     auto titleLabel = new QLabel();
@@ -54,17 +53,19 @@
         return menuBar;
     }();
 
-    static const auto buttonStyleSheet = QLatin1String{ "QPushButton{color:black;};QPushButton:hover{background-color:black;color:white;}" };
-
     auto iconButton = new QPushButton("I");
-    iconButton->setStyleSheet(buttonStyleSheet);
+    iconButton->setAttribute(Qt::WA_Hover);
+    iconButton->setMouseTracking(true);
     auto minButton = new QPushButton("鈥�");
-    minButton->setStyleSheet(buttonStyleSheet);
+    minButton->setAttribute(Qt::WA_Hover);
+    minButton->setMouseTracking(true);
     auto maxButton = new QPushButton("馃棖");
-    maxButton->setStyleSheet(buttonStyleSheet);
     maxButton->setCheckable(true);
+    maxButton->setAttribute(Qt::WA_Hover);
+    maxButton->setMouseTracking(true);
     auto closeButton = new QPushButton("鉁�");
-    closeButton->setStyleSheet(buttonStyleSheet);
+    closeButton->setAttribute(Qt::WA_Hover);
+    closeButton->setMouseTracking(true);
 
     auto windowBar = new QWK::WindowBar();
     windowBar->setIconButton(iconButton);
@@ -76,10 +77,10 @@
     windowBar->setHostWidget(this);
 
     agent->setTitleBar(windowBar);
-    agent->setSystemButton(QWK::CoreWindowAgent::WindowIcon, iconButton);
-    agent->setSystemButton(QWK::CoreWindowAgent::Minimize, minButton);
-    agent->setSystemButton(QWK::CoreWindowAgent::Maximize, maxButton);
-    agent->setSystemButton(QWK::CoreWindowAgent::Close, closeButton);
+    agent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton);
+    agent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton);
+    agent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton);
+    agent->setSystemButton(QWK::WindowAgentBase::Close, closeButton);
     agent->setHitTestVisible(menuBar, true);
 
     connect(windowBar, &QWK::WindowBar::minimizeRequested, this, &QWidget::showMinimized);
@@ -94,9 +95,17 @@
 
     auto clockWidget = new ClockWidget();
     clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    connect(clockWidget, &QAbstractButton::clicked, this, [this]() {
+        if (!isMaximized()) {
+            showMaximized();
+        } else {
+            showNormal();
+        }
+    });
 
     setMenuWidget(windowBar);
     setCentralWidget(clockWidget);
     setWindowTitle("Example MainWindow");
-    resize(1024, 768);
+    // setContentsMargins({0, 1, 0, 0});
+    resize(640, 480);
 }

--
Gitblit v1.9.1