58 Star 461 Fork 110

GVPVNoteX/vnote

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
application.cpp 2.22 KB
一键复制 编辑 原始数据 按行查看 历史
tamlok 提交于 2026-02-24 21:28 +08:00 . refine DockWidgetHelper and NotebookExplorer2
#include "application.h"
#include <QDebug>
#include <QDir>
#include <QFileOpenEvent>
#include <QFileSystemWatcher>
#include <QStyle>
#include <QTimer>
#include <gui/services/themeservice.h>
using namespace vnotex;
Application::Application(int &p_argc, char **p_argv) : QApplication(p_argc, p_argv) {}
void Application::setThemeService(ThemeService *p_themeService) {
m_themeService = p_themeService;
}
void Application::watchThemeFolder(const QString &p_themeFolderPath) {
if (p_themeFolderPath.isEmpty()) {
return;
}
// Initialize watchers only when needed
if (!m_styleWatcher) {
m_styleWatcher = new QFileSystemWatcher(this);
}
if (!m_reloadTimer) {
m_reloadTimer = new QTimer(this);
m_reloadTimer->setSingleShot(true);
m_reloadTimer->setInterval(500); // 500ms debounce delay
connect(m_reloadTimer, &QTimer::timeout, this, &Application::reloadThemeResources);
// Connect file watcher to timer
connect(m_styleWatcher, &QFileSystemWatcher::directoryChanged, m_reloadTimer,
qOverload<>(&QTimer::start));
connect(m_styleWatcher, &QFileSystemWatcher::fileChanged, m_reloadTimer,
qOverload<>(&QTimer::start));
}
// Watch the theme folder and its files
m_styleWatcher->addPath(p_themeFolderPath);
// Also watch individual files in the theme folder
QDir themeDir(p_themeFolderPath);
QStringList files = themeDir.entryList(QDir::Files);
for (const QString &file : files) {
m_styleWatcher->addPath(themeDir.filePath(file));
}
}
void Application::reloadThemeResources() {
if (!m_themeService) {
qWarning() << "ThemeService not set, cannot reload theme resources";
return;
}
m_themeService->refreshCurrentTheme();
auto stylesheet = m_themeService->fetchQtStyleSheet();
if (!stylesheet.isEmpty()) {
setStyleSheet(stylesheet);
style()->unpolish(this);
style()->polish(this);
}
}
bool Application::event(QEvent *p_event) {
// On macOS, we need this to open file from Finder.
if (p_event->type() == QEvent::FileOpen) {
QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(p_event);
qDebug() << "request to open file" << openEvent->file();
emit openFileRequested(openEvent->file());
}
return QApplication::event(p_event);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/vnotex/vnote.git
git@gitee.com:vnotex/vnote.git
vnotex
vnote
vnote
master

搜索帮助