chore: 调整格式化配置

This commit is contained in:
sleepwithoutbz
2025-09-16 17:07:56 +08:00
parent e172afa4cc
commit 16c1e759ff
6 changed files with 236 additions and 217 deletions

View File

@@ -19,7 +19,7 @@ AccessModifierOffset: -4
IndentCaseLabels: false IndentCaseLabels: false
# 要使用的预处理器指令缩进样式 # 要使用的预处理器指令缩进样式
IndentPPDirectives: BeforeHash IndentPPDirectives: Leave
# 缩进宽度 # 缩进宽度
IndentWidth: 4 IndentWidth: 4

2
.gitignore vendored
View File

@@ -1,4 +1,6 @@
build/ build/
Debug/
Release/
.cache/ .cache/
.vs/ .vs/
.vscode/ .vscode/

View File

@@ -2,7 +2,7 @@
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
project(systray LANGUAGES CXX) project(tido LANGUAGES CXX)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
@@ -10,41 +10,42 @@ qt_standard_project_setup()
# 导出src下的cpp文件 # 导出src下的cpp文件
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp) file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS src/*.cpp)
qt_add_executable(systray ${SRC_FILES}) qt_add_executable(tido ${SRC_FILES})
set_target_properties(systray PROPERTIES set_target_properties(tido PROPERTIES
WIN32_EXECUTABLE TRUE # 控制是否显示终端为TRUE则不显示
WIN32_EXECUTABLE FALSE
MACOSX_BUNDLE TRUE MACOSX_BUNDLE TRUE
) )
target_link_libraries(systray PRIVATE target_link_libraries(tido PRIVATE
Qt6::Core Qt6::Core
Qt6::Gui Qt6::Gui
Qt6::Widgets Qt6::Widgets
) )
# Resources: # Resources:
set(systray_resource_files set(tido_resource_files
"images/bad.png" "images/bad.png"
"images/heart.png" "images/heart.png"
"images/trash.png" "images/trash.png"
) )
qt_add_resources(systray "systray" qt_add_resources(tido "tido"
PREFIX PREFIX
"/" "/"
FILES FILES
${systray_resource_files} ${tido_resource_files}
) )
install(TARGETS systray install(TARGETS tido
BUNDLE DESTINATION . BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
) )
qt_generate_deploy_app_script( qt_generate_deploy_app_script(
TARGET systray TARGET tido
OUTPUT_SCRIPT deploy_script OUTPUT_SCRIPT deploy_script
NO_UNSUPPORTED_PLATFORM_ERROR NO_UNSUPPORTED_PLATFORM_ERROR
) )

View File

@@ -2,15 +2,15 @@
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
#include "window.h" #include "window.h"
#include <QMessageBox> #include <QMessageBox>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);
if (!QSystemTrayIcon::isSystemTrayAvailable()) { if (!QSystemTrayIcon::isSystemTrayAvailable()) {
auto choice = auto choice = QMessageBox::critical(
QMessageBox::critical(nullptr, QObject::tr("Systray"), nullptr, QObject::tr("Systray"),
QObject::tr("I couldn't detect any system tray on this system."), QObject::tr("I couldn't detect any system tray on this system."),
QMessageBox::Close | QMessageBox::Ignore); QMessageBox::Close | QMessageBox::Ignore);
if (choice == QMessageBox::Close) if (choice == QMessageBox::Close)
@@ -27,8 +27,8 @@ int main(int argc, char *argv[]) {
#else #else
#include <QDebug> #include <QDebug>
#include <QLabel> #include <QLabel>
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QApplication app(argc, argv); QApplication app(argc, argv);

View File

@@ -2,20 +2,20 @@
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
#include <QAction> #include <QAction>
#include <QCheckBox> #include <QCheckBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox> #include <QComboBox>
#include <QCoreApplication> #include <QCoreApplication>
#include <QGroupBox> #include <QGroupBox>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
#include <QPushButton> #include <QPushButton>
#include <QSpinBox> #include <QSpinBox>
#include <QTextEdit> #include <QTextEdit>
#include <QVBoxLayout> #include <QVBoxLayout>
//! [0] //! [0]
Window::Window() { Window::Window() {
@@ -27,10 +27,14 @@ Window::Window() {
createActions(); createActions();
createTrayIcon(); createTrayIcon();
connect(showMessageButton, &QAbstractButton::clicked, this, &Window::showMessage); connect(showMessageButton, &QAbstractButton::clicked, this,
connect(showIconCheckBox, &QAbstractButton::toggled, trayIcon, &QSystemTrayIcon::setVisible); &Window::showMessage);
connect(iconComboBox, &QComboBox::currentIndexChanged, this, &Window::setIcon); connect(showIconCheckBox, &QAbstractButton::toggled, trayIcon,
connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked); &QSystemTrayIcon::setVisible);
connect(iconComboBox, &QComboBox::currentIndexChanged, this,
&Window::setIcon);
connect(trayIcon, &QSystemTrayIcon::messageClicked, this,
&Window::messageClicked);
connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated); connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -41,7 +45,7 @@ Window::Window() {
iconComboBox->setCurrentIndex(1); iconComboBox->setCurrentIndex(1);
trayIcon->show(); trayIcon->show();
setWindowTitle(tr("Systray")); setWindowTitle(tr("Tido"));
resize(400, 300); resize(400, 300);
} }
//! [0] //! [0]
@@ -60,12 +64,21 @@ void Window::closeEvent(QCloseEvent *event) {
if (!event->spontaneous() || !isVisible()) if (!event->spontaneous() || !isVisible())
return; return;
if (trayIcon->isVisible()) { if (trayIcon->isVisible()) {
QMessageBox::information(this, tr("Systray"), QMessageBox::StandardButtons reply =
QMessageBox::question(this, tr("关闭Tido"),
tr("The program will keep running in the " tr("The program will keep running in the "
"system tray. To terminate the program, " "system tray. To terminate the program, "
"choose <b>Quit</b> in the context menu " "choose <b>Quit</b> in the context menu "
"of the system tray entry.")); "of the system tray entry."),
QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
qDebug() << "Button `Yes` was clicked";
hide(); hide();
} else if (reply == QMessageBox::No) {
qDebug() << "Button `No` was clicked";
} else {
qDebug() << "No button was clicked";
}
event->ignore(); event->ignore();
} }
} }
@@ -86,7 +99,8 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) { switch (reason) {
case QSystemTrayIcon::Trigger: case QSystemTrayIcon::Trigger:
case QSystemTrayIcon::DoubleClick: case QSystemTrayIcon::DoubleClick:
iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) % iconComboBox->count()); iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) %
iconComboBox->count());
break; break;
case QSystemTrayIcon::MiddleClick: case QSystemTrayIcon::MiddleClick:
showMessage(); showMessage();
@@ -99,8 +113,10 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) {
//! [5] //! [5]
void Window::showMessage() { void Window::showMessage() {
showIconCheckBox->setChecked(true); showIconCheckBox->setChecked(true);
int selectedIcon = typeComboBox->itemData(typeComboBox->currentIndex()).toInt(); int selectedIcon =
QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon(selectedIcon); typeComboBox->itemData(typeComboBox->currentIndex()).toInt();
QSystemTrayIcon::MessageIcon msgIcon =
QSystemTrayIcon::MessageIcon(selectedIcon);
if (selectedIcon == -1) { // custom icon if (selectedIcon == -1) { // custom icon
QIcon icon(iconComboBox->itemIcon(iconComboBox->currentIndex())); QIcon icon(iconComboBox->itemIcon(iconComboBox->currentIndex()));
@@ -115,14 +131,14 @@ void Window::showMessage() {
//! [6] //! [6]
void Window::messageClicked() { void Window::messageClicked() {
QMessageBox::information(nullptr, tr("Systray"), QMessageBox::information(nullptr, tr("tido"),
tr("Sorry, I already gave what help I could.\n" tr("Sorry, I already gave what help I could.\n"
"Maybe you should try asking a human?")); "Maybe you should try asking a human?"));
} }
//! [6] //! [6]
void Window::createIconGroupBox() { void Window::createIconGroupBox() {
iconGroupBox = new QGroupBox(tr("Tray Icon")); iconGroupBox = new QGroupBox(tr("托盘图标"));
iconLabel = new QLabel("Icon:"); iconLabel = new QLabel("Icon:");
@@ -143,7 +159,7 @@ void Window::createIconGroupBox() {
} }
void Window::createMessageGroupBox() { void Window::createMessageGroupBox() {
messageGroupBox = new QGroupBox(tr("Balloon Message")); messageGroupBox = new QGroupBox(tr("气泡消息"));
typeLabel = new QLabel(tr("Type:")); typeLabel = new QLabel(tr("Type:"));
@@ -151,10 +167,10 @@ void Window::createMessageGroupBox() {
typeComboBox->addItem(tr("None"), QSystemTrayIcon::NoIcon); typeComboBox->addItem(tr("None"), QSystemTrayIcon::NoIcon);
typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxInformation), typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxInformation),
tr("Information"), QSystemTrayIcon::Information); tr("Information"), QSystemTrayIcon::Information);
typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxWarning), tr("Warning"), typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxWarning),
QSystemTrayIcon::Warning); tr("Warning"), QSystemTrayIcon::Warning);
typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxCritical), tr("Critical"), typeComboBox->addItem(style()->standardIcon(QStyle::SP_MessageBoxCritical),
QSystemTrayIcon::Critical); tr("Critical"), QSystemTrayIcon::Critical);
typeComboBox->addItem(QIcon(), tr("Custom icon"), -1); typeComboBox->addItem(QIcon(), tr("Custom icon"), -1);
typeComboBox->setCurrentIndex(1); typeComboBox->setCurrentIndex(1);

View File

@@ -4,7 +4,7 @@
#ifndef QT_NO_SYSTEMTRAYICON #ifndef QT_NO_SYSTEMTRAYICON
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QAction; class QAction;