diff --git a/res/neko.css b/res/neko.css deleted file mode 100644 index 512e281..0000000 --- a/res/neko.css +++ /dev/null @@ -1,3 +0,0 @@ -QMessageBox { - messagebox-text-interaction-flags: 5; -} diff --git a/res/neko.qrc b/res/neko.qrc index 6e1c3f2..4881eee 100644 --- a/res/neko.qrc +++ b/res/neko.qrc @@ -17,7 +17,6 @@ public/nekobox.png public/nekoray.png - neko.css vpn/vpn-run-root.sh vpn/sing-box-vpn.json dashboard-notice.html diff --git a/ui/ThemeManager.cpp b/ui/ThemeManager.cpp index 0817018..1765717 100644 --- a/ui/ThemeManager.cpp +++ b/ui/ThemeManager.cpp @@ -9,27 +9,22 @@ ThemeManager *themeManager = new ThemeManager; extern QString ReadFileText(const QString &path); -void ThemeManager::ApplyTheme(const QString &theme) { - auto internal = [=] { +void ThemeManager::ApplyTheme(const QString &theme, bool force) { + if (this->system_style_name.isEmpty()) { + this->system_style_name = qApp->style()->name(); + } - if (this->system_style_name.isEmpty()) { - this->system_style_name = qApp->style()->name(); - } + if (this->current_theme == theme && !force) { + return; + } - if (this->current_theme == theme) { - return; - } + if (theme.toLower() == "system") { + qApp->setStyle(system_style_name); + } else { + qApp->setStyle(theme); + } - if (theme.toLower() == "system") { - qApp->setStyle(system_style_name); - } else { - qApp->setStyle(theme); - } + current_theme = theme; - current_theme = theme; - }; - internal(); - - auto nekoray_css = ReadFileText(":/neko/neko.css"); - qApp->setStyleSheet(qApp->styleSheet().append("\n").append(nekoray_css)); + emit themeChanged(theme); } diff --git a/ui/ThemeManager.hpp b/ui/ThemeManager.hpp index 1514f23..f2ad0eb 100644 --- a/ui/ThemeManager.hpp +++ b/ui/ThemeManager.hpp @@ -1,11 +1,16 @@ #pragma once -class ThemeManager { +#include + +class ThemeManager : public QObject { + Q_OBJECT public: QString system_style_name = ""; QString current_theme = "0"; // int: 0:system 1+:builtin string: QStyleFactory - void ApplyTheme(const QString &theme); + void ApplyTheme(const QString &theme, bool force = false); +signals: + void themeChanged(QString themeName); }; extern ThemeManager *themeManager; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 2a1a8b4..043d54c 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -46,6 +46,7 @@ #include #include #include +#include void UI_InitMainWindow() { mainwindow = new MainWindow; @@ -118,17 +119,23 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // Setup log UI ui->splitter->restoreState(DecodeB64IfValid(NekoGui::dataStore->splitter_state)); - new SyntaxHighlighter(false, qvLogDocument); + new SyntaxHighlighter(qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark, qvLogDocument); qvLogDocument->setUndoRedoEnabled(false); ui->masterLogBrowser->setUndoRedoEnabled(false); ui->masterLogBrowser->setDocument(qvLogDocument); ui->masterLogBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); - { - auto font = ui->masterLogBrowser->font(); - font.setPointSize(9); - ui->masterLogBrowser->setFont(font); - qvLogDocument->setDefaultFont(font); - } + + connect(qApp->styleHints(), &QStyleHints::colorSchemeChanged, this, [=](const Qt::ColorScheme& scheme) { + new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument); + themeManager->ApplyTheme(NekoGui::dataStore->theme, true); + }); + connect(themeManager, &ThemeManager::themeChanged, this, [=](const QString& theme){ + if (theme.toLower().contains("vista")) { + new SyntaxHighlighter(false, qvLogDocument); + } else { + new SyntaxHighlighter(qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark, qvLogDocument); + } + }); connect(ui->masterLogBrowser->verticalScrollBar(), &QSlider::valueChanged, this, [=](int value) { if (ui->masterLogBrowser->verticalScrollBar()->maximum() == value) qvLogAutoScoll = true;