2
2
3
3
#include < QFileOpenEvent>
4
4
#include < QDebug>
5
+ #include < QDir>
6
+ #include < QStyle>
7
+ #include < QFileSystemWatcher>
8
+ #include < QTimer>
9
+ #include < core/vnotex.h>
5
10
6
11
using namespace vnotex ;
7
12
@@ -10,6 +15,53 @@ Application::Application(int &p_argc, char **p_argv)
10
15
{
11
16
}
12
17
18
+ void Application::watchThemeFolder (const QString &p_themeFolderPath)
19
+ {
20
+ if (p_themeFolderPath.isEmpty ()) {
21
+ return ;
22
+ }
23
+
24
+ // Initialize watchers only when needed
25
+ if (!m_styleWatcher) {
26
+ m_styleWatcher = new QFileSystemWatcher (this );
27
+ }
28
+ if (!m_reloadTimer) {
29
+ m_reloadTimer = new QTimer (this );
30
+ m_reloadTimer->setSingleShot (true );
31
+ m_reloadTimer->setInterval (500 ); // 500ms debounce delay
32
+ connect (m_reloadTimer, &QTimer::timeout,
33
+ this , &Application::reloadThemeResources);
34
+
35
+ // Connect file watcher to timer
36
+ connect (m_styleWatcher, &QFileSystemWatcher::directoryChanged,
37
+ m_reloadTimer, qOverload<>(&QTimer::start));
38
+ connect (m_styleWatcher, &QFileSystemWatcher::fileChanged,
39
+ m_reloadTimer, qOverload<>(&QTimer::start));
40
+ }
41
+
42
+ // Watch the theme folder and its files
43
+ m_styleWatcher->addPath (p_themeFolderPath);
44
+
45
+ // Also watch individual files in the theme folder
46
+ QDir themeDir (p_themeFolderPath);
47
+ QStringList files = themeDir.entryList (QDir::Files);
48
+ for (const QString &file : files) {
49
+ m_styleWatcher->addPath (themeDir.filePath (file));
50
+ }
51
+ }
52
+
53
+ void Application::reloadThemeResources ()
54
+ {
55
+ VNoteX::getInst ().getThemeMgr ().refreshCurrentTheme ();
56
+
57
+ auto stylesheet = VNoteX::getInst ().getThemeMgr ().fetchQtStyleSheet ();
58
+ if (!stylesheet.isEmpty ()) {
59
+ setStyleSheet (stylesheet);
60
+ style ()->unpolish (this );
61
+ style ()->polish (this );
62
+ }
63
+ }
64
+
13
65
bool Application::event (QEvent *p_event)
14
66
{
15
67
// On macOS, we need this to open file from Finder.
0 commit comments