feat: Improve log visibility and improve themes

This commit is contained in:
unknown 2024-07-08 18:24:31 +03:30
parent fa5998f89f
commit cbfcc88f83
No known key found for this signature in database
GPG Key ID: C2CA486E4F771093
5 changed files with 35 additions and 32 deletions

View File

@ -1,3 +0,0 @@
QMessageBox {
messagebox-text-interaction-flags: 5;
}

View File

@ -17,7 +17,6 @@
<qresource prefix="/neko">
<file alias="nekobox.png">public/nekobox.png</file>
<file alias="nekoray.png">public/nekoray.png</file>
<file>neko.css</file>
<file>vpn/vpn-run-root.sh</file>
<file>vpn/sing-box-vpn.json</file>
<file>dashboard-notice.html</file>

View File

@ -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);
}

View File

@ -1,11 +1,16 @@
#pragma once
class ThemeManager {
#include <QObject>
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;

View File

@ -46,6 +46,7 @@
#include <QMessageBox>
#include <QDir>
#include <QFileInfo>
#include <QStyleHints>
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;