From f8e08308f5b8821246f7c65194259db8f1ade446 Mon Sep 17 00:00:00 2001 From: parhelia512 <0011d3@gmail.com> Date: Fri, 25 Apr 2025 00:52:52 -0400 Subject: [PATCH] Add support for all versions of Qt6 (#387) --- cmake/QHotkey.cmake | 2 +- include/global/NekoGui_Utils.hpp | 9 +++++++++ include/sys/windows/eventHandler.h | 2 +- src/ui/mainwindow.cpp | 8 ++++++-- src/ui/setting/dialog_basic_settings.cpp | 2 +- src/ui/setting/dialog_manage_routes.cpp | 8 ++++---- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cmake/QHotkey.cmake b/cmake/QHotkey.cmake index 10a67e5..4ec9ed1 100644 --- a/cmake/QHotkey.cmake +++ b/cmake/QHotkey.cmake @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_AUTOMOC ON) -find_package(Qt6 6.8.0 COMPONENTS Core Gui REQUIRED) +find_package(Qt6 COMPONENTS Core Gui REQUIRED) # General settings set(CPACK_PACKAGE_VENDOR "Skycoder42") diff --git a/include/global/NekoGui_Utils.hpp b/include/global/NekoGui_Utils.hpp index 010bab6..5a4cc49 100644 --- a/include/global/NekoGui_Utils.hpp +++ b/include/global/NekoGui_Utils.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include // @@ -181,3 +183,10 @@ inline void connectOnce(EMITTER *emitter, SIGNAL signal, RECEIVER *receiver, Rec } void setTimeout(const std::function &callback, QObject *obj, int timeout = 0); + +inline bool isDarkMode() { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + return qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark; +#endif + return qApp->style()->standardPalette().window().color().lightness() < qApp->style()->standardPalette().windowText().color().lightness(); +} diff --git a/include/sys/windows/eventHandler.h b/include/sys/windows/eventHandler.h index b54d20e..20ad500 100644 --- a/include/sys/windows/eventHandler.h +++ b/include/sys/windows/eventHandler.h @@ -2,7 +2,7 @@ #include #include - +#include class PowerOffTaskkillFilter : public QAbstractNativeEventFilter { diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 66eb7cd..7c09b51 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -45,7 +45,9 @@ #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) #include +#endif #include #include #include <3rdparty/QHotkey/qhotkey.h> @@ -79,16 +81,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // setup log ui->splitter->restoreState(DecodeB64IfValid(NekoGui::dataStore->splitter_state)); - new SyntaxHighlighter(qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark || NekoGui::dataStore->theme.toLower() == "qdarkstyle", qvLogDocument); + new SyntaxHighlighter(isDarkMode() || NekoGui::dataStore->theme.toLower() == "qdarkstyle", qvLogDocument); qvLogDocument->setUndoRedoEnabled(false); ui->masterLogBrowser->setUndoRedoEnabled(false); ui->masterLogBrowser->setDocument(qvLogDocument); ui->masterLogBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) connect(qApp->styleHints(), &QStyleHints::colorSchemeChanged, this, [=](const Qt::ColorScheme& scheme) { new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument); themeManager->ApplyTheme(NekoGui::dataStore->theme, true); }); +#endif connect(themeManager, &ThemeManager::themeChanged, this, [=](const QString& theme){ if (theme.toLower().contains("vista")) { // light themes @@ -98,7 +102,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi new SyntaxHighlighter(true, qvLogDocument); } else { // bi-mode themes, follow system preference - new SyntaxHighlighter(qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark, qvLogDocument); + new SyntaxHighlighter(isDarkMode(), qvLogDocument); } }); connect(ui->masterLogBrowser->verticalScrollBar(), &QSlider::valueChanged, this, [=](int value) { diff --git a/src/ui/setting/dialog_basic_settings.cpp b/src/ui/setting/dialog_basic_settings.cpp index 8735dd2..f96d5ae 100644 --- a/src/ui/setting/dialog_basic_settings.cpp +++ b/src/ui/setting/dialog_basic_settings.cpp @@ -138,7 +138,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) ui->ntp_server->setText(NekoGui::dataStore->ntp_server_address); ui->ntp_port->setText(Int2String(NekoGui::dataStore->ntp_server_port)); ui->ntp_interval->setCurrentText(NekoGui::dataStore->ntp_interval); - connect(ui->ntp_enable, &QCheckBox::checkStateChanged, this, [=](const bool &state) { + connect(ui->ntp_enable, &QCheckBox::stateChanged, this, [=](const bool &state) { ui->ntp_server->setEnabled(state); ui->ntp_port->setEnabled(state); ui->ntp_interval->setEnabled(state); diff --git a/src/ui/setting/dialog_manage_routes.cpp b/src/ui/setting/dialog_manage_routes.cpp index 19eb691..e22f6a8 100644 --- a/src/ui/setting/dialog_manage_routes.cpp +++ b/src/ui/setting/dialog_manage_routes.cpp @@ -87,12 +87,12 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne ui->remote_dns_strategy->addItems(qsValue); ui->enable_fakeip->setChecked(NekoGui::dataStore->fake_dns); // - connect(ui->use_dns_object, &QCheckBox::checkStateChanged, this, [=](int state) { + connect(ui->use_dns_object, &QCheckBox::stateChanged, this, [=](int state) { auto useDNSObject = state == Qt::Checked; ui->simple_dns_box->setDisabled(useDNSObject); ui->dns_object->setDisabled(!useDNSObject); }); - ui->use_dns_object->checkStateChanged(Qt::Unchecked); // uncheck to uncheck + ui->use_dns_object->stateChanged(Qt::Unchecked); // uncheck to uncheck connect(ui->dns_document, &QPushButton::clicked, this, [=] { MessageBoxInfo("DNS", dnsHelpDocumentUrl); }); @@ -166,10 +166,10 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne ui->redirect_listenport->setValidator(QRegExpValidator_Number); ui->redirect_listenport->setText(Int2String(NekoGui::dataStore->redirect_listen_port)); - connect(ui->dnshijack_enable, &QCheckBox::checkStateChanged, this, [=](bool state) { + connect(ui->dnshijack_enable, &QCheckBox::stateChanged, this, [=](bool state) { set_dns_hijack_enability(state); }); - connect(ui->redirect_enable, &QCheckBox::checkStateChanged, this, [=](bool state) { + connect(ui->redirect_enable, &QCheckBox::stateChanged, this, [=](bool state) { ui->redirect_listenaddr->setEnabled(state); ui->redirect_listenport->setEnabled(state); });