Add support for all versions of Qt6 (#387)

This commit is contained in:
parhelia512 2025-04-25 00:52:52 -04:00 committed by GitHub
parent 987cc04d4e
commit f8e08308f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 9 deletions

View File

@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.10)
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
find_package(Qt6 6.8.0 COMPONENTS Core Gui REQUIRED) find_package(Qt6 COMPONENTS Core Gui REQUIRED)
# General settings # General settings
set(CPACK_PACKAGE_VENDOR "Skycoder42") set(CPACK_PACKAGE_VENDOR "Skycoder42")

View File

@ -5,6 +5,8 @@
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QApplication>
#include <QStyle>
// //
@ -181,3 +183,10 @@ inline void connectOnce(EMITTER *emitter, SIGNAL signal, RECEIVER *receiver, Rec
} }
void setTimeout(const std::function<void()> &callback, QObject *obj, int timeout = 0); void setTimeout(const std::function<void()> &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();
}

View File

@ -2,7 +2,7 @@
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <QByteArray> #include <QByteArray>
#include <functional>
class PowerOffTaskkillFilter : public QAbstractNativeEventFilter class PowerOffTaskkillFilter : public QAbstractNativeEventFilter
{ {

View File

@ -45,7 +45,9 @@
#include <QMessageBox> #include <QMessageBox>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
#include <QStyleHints> #include <QStyleHints>
#endif
#include <QToolTip> #include <QToolTip>
#include <random> #include <random>
#include <3rdparty/QHotkey/qhotkey.h> #include <3rdparty/QHotkey/qhotkey.h>
@ -79,16 +81,18 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// setup log // setup log
ui->splitter->restoreState(DecodeB64IfValid(NekoGui::dataStore->splitter_state)); 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); qvLogDocument->setUndoRedoEnabled(false);
ui->masterLogBrowser->setUndoRedoEnabled(false); ui->masterLogBrowser->setUndoRedoEnabled(false);
ui->masterLogBrowser->setDocument(qvLogDocument); ui->masterLogBrowser->setDocument(qvLogDocument);
ui->masterLogBrowser->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); 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) { connect(qApp->styleHints(), &QStyleHints::colorSchemeChanged, this, [=](const Qt::ColorScheme& scheme) {
new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument); new SyntaxHighlighter(scheme == Qt::ColorScheme::Dark, qvLogDocument);
themeManager->ApplyTheme(NekoGui::dataStore->theme, true); themeManager->ApplyTheme(NekoGui::dataStore->theme, true);
}); });
#endif
connect(themeManager, &ThemeManager::themeChanged, this, [=](const QString& theme){ connect(themeManager, &ThemeManager::themeChanged, this, [=](const QString& theme){
if (theme.toLower().contains("vista")) { if (theme.toLower().contains("vista")) {
// light themes // light themes
@ -98,7 +102,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
new SyntaxHighlighter(true, qvLogDocument); new SyntaxHighlighter(true, qvLogDocument);
} else { } else {
// bi-mode themes, follow system preference // 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) { connect(ui->masterLogBrowser->verticalScrollBar(), &QSlider::valueChanged, this, [=](int value) {

View File

@ -138,7 +138,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->ntp_server->setText(NekoGui::dataStore->ntp_server_address); ui->ntp_server->setText(NekoGui::dataStore->ntp_server_address);
ui->ntp_port->setText(Int2String(NekoGui::dataStore->ntp_server_port)); ui->ntp_port->setText(Int2String(NekoGui::dataStore->ntp_server_port));
ui->ntp_interval->setCurrentText(NekoGui::dataStore->ntp_interval); 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_server->setEnabled(state);
ui->ntp_port->setEnabled(state); ui->ntp_port->setEnabled(state);
ui->ntp_interval->setEnabled(state); ui->ntp_interval->setEnabled(state);

View File

@ -87,12 +87,12 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->remote_dns_strategy->addItems(qsValue); ui->remote_dns_strategy->addItems(qsValue);
ui->enable_fakeip->setChecked(NekoGui::dataStore->fake_dns); 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; auto useDNSObject = state == Qt::Checked;
ui->simple_dns_box->setDisabled(useDNSObject); ui->simple_dns_box->setDisabled(useDNSObject);
ui->dns_object->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, [=] { connect(ui->dns_document, &QPushButton::clicked, this, [=] {
MessageBoxInfo("DNS", dnsHelpDocumentUrl); MessageBoxInfo("DNS", dnsHelpDocumentUrl);
}); });
@ -166,10 +166,10 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
ui->redirect_listenport->setValidator(QRegExpValidator_Number); ui->redirect_listenport->setValidator(QRegExpValidator_Number);
ui->redirect_listenport->setText(Int2String(NekoGui::dataStore->redirect_listen_port)); 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); 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_listenaddr->setEnabled(state);
ui->redirect_listenport->setEnabled(state); ui->redirect_listenport->setEnabled(state);
}); });