From f9aa4aacae56e3a82bce492196ff1802f3ecaf02 Mon Sep 17 00:00:00 2001
From: Yuhang Zhao <zhaoyuhang@rankyee.com>
Date: 周二, 19 12月 2023 13:05:53 +0800
Subject: [PATCH] add a convenient API

---
 src/quick/quickwindowagent.h       |    6 ++++++
 examples/mainwindow/main.cpp       |    2 --
 src/widgets/widgetwindowagent.h    |    6 ++++++
 examples/mainwindow/mainwindow.cpp |    5 +----
 4 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/examples/mainwindow/main.cpp b/examples/mainwindow/main.cpp
index d8dffe9..9e86f81 100644
--- a/examples/mainwindow/main.cpp
+++ b/examples/mainwindow/main.cpp
@@ -1,6 +1,4 @@
 #include <QtWidgets/QApplication>
-#include <QtGui/QFont>
-#include <QtCore/QDebug>
 
 #include "mainwindow.h"
 
diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp
index 96736de..79724d4 100644
--- a/examples/mainwindow/mainwindow.cpp
+++ b/examples/mainwindow/mainwindow.cpp
@@ -107,10 +107,7 @@
 
 void MainWindow::installWindowAgent() {
     // 1. Setup window agent
-    auto agent = new QWK::WidgetWindowAgent(this);
-    if (!agent->setup(this)) {
-        qFatal("QWK failed to initialize.");
-    }
+    QWK::WidgetWindowAgent *agent = QWK::QWK_Initialize(this);
 
     // 2. Construct your title bar
     auto menuBar = []() {
diff --git a/src/quick/quickwindowagent.h b/src/quick/quickwindowagent.h
index 4d6160b..23b6521 100644
--- a/src/quick/quickwindowagent.h
+++ b/src/quick/quickwindowagent.h
@@ -38,6 +38,12 @@
         QuickWindowAgent(QuickWindowAgentPrivate &d, QObject *parent = nullptr);
     };
 
+    inline QuickWindowAgent *QWK_Initialize(QQuickWindow *window) {
+        auto agent = new QuickWindowAgent(window);
+        agent->setup(window);
+        return agent;
+    }
+
 }
 
 #endif // QUICKWINDOWAGENT_H
\ No newline at end of file
diff --git a/src/widgets/widgetwindowagent.h b/src/widgets/widgetwindowagent.h
index ea20025..94af904 100644
--- a/src/widgets/widgetwindowagent.h
+++ b/src/widgets/widgetwindowagent.h
@@ -42,6 +42,12 @@
         WidgetWindowAgent(WidgetWindowAgentPrivate &d, QObject *parent = nullptr);
     };
 
+    inline WidgetWindowAgent *QWK_Initialize(QWidget *w) {
+        auto agent = new WidgetWindowAgent(w);
+        agent->setup(w);
+        return agent;
+    }
+
 }
 
 #endif // WIDGETWINDOWAGENT_H
\ No newline at end of file

--
Gitblit v1.9.1