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
# 要使用的预处理器指令缩进样式
IndentPPDirectives: BeforeHash
IndentPPDirectives: Leave
# 缩进宽度
IndentWidth: 4

2
.gitignore vendored
View File

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

View File

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

View File

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

View File

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

View File

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