feat: 添加系统托盘
This commit is contained in:
@@ -45,6 +45,18 @@ target_link_libraries(cbh PRIVATE
|
|||||||
sqlite_orm::sqlite_orm
|
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.
|
# 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
|
# If you are developing for iOS or macOS you should consider setting an
|
||||||
# explicit, fixed bundle identifier manually though.
|
# explicit, fixed bundle identifier manually though.
|
||||||
|
|||||||
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -3,7 +3,6 @@
|
|||||||
#include "sqlite_orm/sqlite_orm.h"
|
#include "sqlite_orm/sqlite_orm.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDebug>
|
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
|
||||||
using sqlite_orm::datetime;
|
using sqlite_orm::datetime;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
@@ -30,14 +29,56 @@ MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) { initWindow(); }
|
|||||||
MainWindow::~MainWindow() {}
|
MainWindow::~MainWindow() {}
|
||||||
|
|
||||||
void MainWindow::initWindow() {
|
void MainWindow::initWindow() {
|
||||||
qDebug() << "Window: Init the window.";
|
// 调整窗口
|
||||||
setNavigationBarDisplayMode(ElaNavigationType::NavigationDisplayMode::Minimal);
|
setNavigationBarDisplayMode(ElaNavigationType::NavigationDisplayMode::Minimal);
|
||||||
resize(480, 640);
|
resize(480, 640);
|
||||||
setIsFixedSize(true);
|
setIsFixedSize(true);
|
||||||
|
|
||||||
|
// 调整托盘
|
||||||
|
createActions();
|
||||||
|
createTrayIcon();
|
||||||
|
|
||||||
|
// 设置图标
|
||||||
|
setIcon();
|
||||||
|
trayIcon->show();
|
||||||
|
|
||||||
|
// 设置窗口页面内容
|
||||||
// TODO: Set the subtitle of user info card
|
// TODO: Set the subtitle of user info card
|
||||||
setUserInfoCardSubTitle("Nothing!");
|
setUserInfoCardSubTitle("Nothing!");
|
||||||
|
|
||||||
_tablePage = new CBTable(this);
|
_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);
|
||||||
|
}
|
||||||
|
|||||||
17
src/window.h
17
src/window.h
@@ -3,6 +3,7 @@
|
|||||||
#include "ElaWindow.h"
|
#include "ElaWindow.h"
|
||||||
#include "UI/CBTable.h"
|
#include "UI/CBTable.h"
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include <QSystemTrayIcon>
|
||||||
|
|
||||||
class MainWindow : public ElaWindow {
|
class MainWindow : public ElaWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -13,7 +14,23 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void initWindow();
|
void initWindow();
|
||||||
|
void createActions();
|
||||||
|
void createTrayIcon();
|
||||||
|
void setIcon();
|
||||||
|
|
||||||
CBTable *_tablePage{nullptr};
|
CBTable *_tablePage{nullptr};
|
||||||
|
|
||||||
|
// 图标
|
||||||
|
QIcon *icon;
|
||||||
|
|
||||||
|
// 系统托盘选项
|
||||||
|
QAction *minimizeAction;
|
||||||
|
QAction *maximizeAction;
|
||||||
|
QAction *restoreAction;
|
||||||
|
QAction *quitAction;
|
||||||
|
// 系统托盘与菜单
|
||||||
|
QSystemTrayIcon *trayIcon;
|
||||||
|
QMenu *trayMenu;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user