From 16d8c5065e34f269296649a7e3c394363b122be0 Mon Sep 17 00:00:00 2001 From: sleepwithoutbz Date: Tue, 23 Sep 2025 12:08:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=89=98=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 12 ++++++++++++ assets/icon.png | Bin 0 -> 1834 bytes src/clipboard.h | 1 - src/window.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++---- src/window.h | 21 +++++++++++++++++++-- 5 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 assets/icon.png diff --git a/CMakeLists.txt b/CMakeLists.txt index f97e312..e9d0cd4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,18 @@ target_link_libraries(cbh PRIVATE sqlite_orm::sqlite_orm ) +# 添加资源文件 +set(cbh_resource_files + "assets/icon.png" +) + +qt_add_resources(cbh "cbh" + PREFIX + "/" + FILES + ${cbh_resource_files} +) + # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5d466b1b89417c407d0ee35153d6195971c2bd58 GIT binary patch literal 1834 zcmZvdc{Ce{7RK$`D56q|Dy0*98~akJJw_xMB`S(oD|XE(MTc05s3ppDw6UvY?5$D6 zAht>^vDDZat-Vsz5~GMxlXv>hJLkP~zWaT@bMHO(-}~4OWi1Sl25@n43ETW^Y0t@> z|I`^?j-O4FD&~ZV9Rh8|Nnv4OAP~s${{{{V2?>dah;ZPCpF4Ms13xx7qaTp5sqzcw z1SrfN<-j#BAGZxG^5}$&+C6z`de1cT9%Mg4(2$EuAlb&!3?0e%@?m3qLjIh)Kpi(#Y3%N&IS?|v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`b^{Zk?fee+E{`+J3r{zyp#QFED4)2Kct^HjtK9>VUQf_ zUmX&I%q2t>;-?Eh88MsI)u-Xea;D;V`_x|}+b=c@NX!36Cv3rot-3gCSjQL6$KtZF LLRr?EdnEh|XvAl= literal 0 HcmV?d00001 diff --git a/src/clipboard.h b/src/clipboard.h index 7e2891a..35fd5bf 100644 --- a/src/clipboard.h +++ b/src/clipboard.h @@ -3,7 +3,6 @@ #include "sqlite_orm/sqlite_orm.h" #include #include -#include #include using sqlite_orm::datetime; diff --git a/src/window.cpp b/src/window.cpp index 41f98c9..5af0b0d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,6 +1,5 @@ #include "window.h" -#include #include #include #include @@ -30,14 +29,56 @@ MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) { initWindow(); } MainWindow::~MainWindow() {} void MainWindow::initWindow() { - qDebug() << "Window: Init the window."; + // 调整窗口 setNavigationBarDisplayMode(ElaNavigationType::NavigationDisplayMode::Minimal); resize(480, 640); setIsFixedSize(true); + + // 调整托盘 + createActions(); + createTrayIcon(); + + // 设置图标 + setIcon(); + trayIcon->show(); + + // 设置窗口页面内容 // TODO: Set the subtitle of user info card setUserInfoCardSubTitle("Nothing!"); - _tablePage = new CBTable(this); - addPageNode("剪贴板历史", _tablePage, ElaIconType::TableTree); + addPageNode("剪贴板历史", _tablePage, ElaIconType::TableTree); +} + +void MainWindow::createActions() { + minimizeAction = new QAction(tr("Mi&nimize"), this); + connect(minimizeAction, &QAction::triggered, this, &QWidget::hide); + + maximizeAction = new QAction(tr("Ma&ximize"), this); + connect(maximizeAction, &QAction::triggered, this, &QWidget::showMaximized); + + restoreAction = new QAction(tr("&Restore"), this); + connect(restoreAction, &QAction::triggered, this, &QWidget::showNormal); + + quitAction = new QAction(tr("&Quit"), this); + connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); +} + +void MainWindow::createTrayIcon() { + trayMenu = new QMenu(this); + trayMenu->addAction(minimizeAction); + trayMenu->addAction(maximizeAction); + trayMenu->addAction(restoreAction); + trayMenu->addSeparator(); + trayMenu->addAction(quitAction); + + trayIcon = new QSystemTrayIcon(this); + trayIcon->setContextMenu(trayMenu); +} + +// TODO: 添加正式图标 +void MainWindow::setIcon() { + QIcon icon(":/assets/icon.png"); + setWindowIcon(icon); + trayIcon->setIcon(icon); } diff --git a/src/window.h b/src/window.h index eabb91b..4ba6628 100644 --- a/src/window.h +++ b/src/window.h @@ -3,17 +3,34 @@ #include "ElaWindow.h" #include "UI/CBTable.h" #include +#include class MainWindow : public ElaWindow { Q_OBJECT -/* F */ + /* F */ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); private: void initWindow(); - CBTable* _tablePage{nullptr}; + void createActions(); + void createTrayIcon(); + void setIcon(); + + CBTable *_tablePage{nullptr}; + + // 图标 + QIcon *icon; + + // 系统托盘选项 + QAction *minimizeAction; + QAction *maximizeAction; + QAction *restoreAction; + QAction *quitAction; + // 系统托盘与菜单 + QSystemTrayIcon *trayIcon; + QMenu *trayMenu; protected: };