From ae0776cae958d84184286f549be062d1947b52f6 Mon Sep 17 00:00:00 2001 From: Qv2ray-dev <59914293+Qv2ray-dev@users.noreply.github.com> Date: Sat, 21 Mar 2020 15:13:52 +0800 Subject: [PATCH] fix: fixing MainWindow size issue. --- makespec/BUILDVERSION | 2 +- src/base/models/QvStartupConfig.hpp | 6 +-- src/common/CommandArgs.cpp | 20 ++++----- src/common/CommandArgs.hpp | 2 +- src/main.cpp | 67 +++++++++++++---------------- src/ui/w_ImportConfig.cpp | 3 +- src/ui/w_MainWindow.cpp | 20 +++++---- src/ui/w_MainWindow.ui | 36 +++++++++++++--- src/ui/w_PreferencesWindow.cpp | 15 +++++-- src/ui/w_SubscriptionManager.cpp | 39 +++++++++-------- src/ui/w_SubscriptionManager.hpp | 6 +-- 11 files changed, 124 insertions(+), 92 deletions(-) diff --git a/makespec/BUILDVERSION b/makespec/BUILDVERSION index 032c2466..b9fda0c2 100644 --- a/makespec/BUILDVERSION +++ b/makespec/BUILDVERSION @@ -1 +1 @@ -4955 +4956 diff --git a/src/base/models/QvStartupConfig.hpp b/src/base/models/QvStartupConfig.hpp index 4003dfb1..cb908816 100644 --- a/src/base/models/QvStartupConfig.hpp +++ b/src/base/models/QvStartupConfig.hpp @@ -14,10 +14,10 @@ namespace Qv2ray bool debugLog; /// Enable Network toolbar plugin. bool enableToolbarPlguin; - /// Endable HiDPI support. - bool hiDPI; - /// Force endable HiDPI support. + /// Force Enable HiDPI support. bool forceHiDPI; + /// Disable Qt scale factors support. + bool noScaleFactors; }; } // namespace base inline base::QvStartupOptions StartupOption = base::QvStartupOptions(); diff --git a/src/common/CommandArgs.cpp b/src/common/CommandArgs.cpp index 64fa8d1a..90e7ea47 100644 --- a/src/common/CommandArgs.cpp +++ b/src/common/CommandArgs.cpp @@ -8,8 +8,8 @@ namespace Qv2ray::common : QObject(), noAPIOption("noAPI", tr("Disable gRPC API subsystems.")), // runAsRootOption("I-just-wanna-run-with-root", tr("Explicitly run Qv2ray as root.")), // debugOption("debug", tr("Enable Debug Output")), // - hiDpiOption("hiDPI", tr("Enable HiDPI support for Qt")), // - forceHiDpiOption("force-hiDPI", tr("Force enable HiDPI support for Qt")), // + noScaleFactorOption("noScaleFactor", tr("Disable manually set QT_SCALE_FACTOR")), // + forceHiDpiOption("forceHiDPI", tr("Force enable HiDPI support for Qt")), // withToolbarOption("withToolbarPlugin", tr("Enable Qv2ray network toolbar plugin")), // // helpOption("FAKE"), versionOption("FAKE") @@ -20,8 +20,8 @@ namespace Qv2ray::common parser.addOption(noAPIOption); parser.addOption(runAsRootOption); parser.addOption(debugOption); - parser.addOption(hiDpiOption); parser.addOption(forceHiDpiOption); + parser.addOption(noScaleFactorOption); parser.addOption(withToolbarOption); helpOption = parser.addHelpOption(); versionOption = parser.addVersionOption(); @@ -59,18 +59,18 @@ namespace Qv2ray::common StartupOption.debugLog = true; } - if (parser.isSet(hiDpiOption)) - { - DEBUG(MODULE_INIT, "hiDPI is set.") - StartupOption.hiDPI = true; - } - if (parser.isSet(forceHiDpiOption)) { - DEBUG(MODULE_INIT, "forceHiDPI is set.") + DEBUG(MODULE_INIT, "forceHiDpiOption is set.") StartupOption.forceHiDPI = true; } + if (parser.isSet(noScaleFactorOption)) + { + DEBUG(MODULE_INIT, "noScaleFactorOption is set.") + StartupOption.noScaleFactors = true; + } + if (parser.isSet(withToolbarOption)) { DEBUG(MODULE_INIT, "withToolbarOption is set.") diff --git a/src/common/CommandArgs.hpp b/src/common/CommandArgs.hpp index f2f2c21b..05cd050c 100644 --- a/src/common/CommandArgs.hpp +++ b/src/common/CommandArgs.hpp @@ -27,7 +27,7 @@ namespace Qv2ray::common QCommandLineOption noAPIOption; QCommandLineOption runAsRootOption; QCommandLineOption debugOption; - QCommandLineOption hiDpiOption; + QCommandLineOption noScaleFactorOption; QCommandLineOption forceHiDpiOption; QCommandLineOption withToolbarOption; QCommandLineOption helpOption; diff --git a/src/main.cpp b/src/main.cpp index 2ab58ad2..3193b4b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -227,17 +227,18 @@ int main(int argc, char *argv[]) SingleApplication::setApplicationName("qv2ray_debug"); SingleApplication::setApplicationDisplayName("Qv2ray - " + QObject::tr("Debug version")); #endif - if ((!qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO") && // - !qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") && // - !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") && // - !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) || // + if (!(qEnvironmentVariableIsSet("QT_DEVICE_PIXEL_RATIO") || qEnvironmentVariableIsSet("QT_AUTO_SCREEN_SCALE_FACTOR") || // + qEnvironmentVariableIsSet("QT_SCALE_FACTOR") || !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) || // StartupOption.forceHiDPI) { - if (StartupOption.forceHiDPI || StartupOption.hiDPI) - { - DEBUG(MODULE_INIT, "High DPI scaling is enabled.") - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - } + LOG(MODULE_INIT, "High DPI scaling is enabled.") + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + } + else if (StartupOption.noScaleFactors) + { + LOG(MODULE_INIT, "Force set QT_SCALE_FACTOR to 0.") + LOG(MODULE_UI, "Original QT_SCALE_FACTOR was: " + qEnvironmentVariable("QT_SCALE_FACTOR")) + qputenv("QT_SCALE_FACTOR", "1"); } SingleApplication _qApp(argc, argv, false, SingleApplication::User | SingleApplication::ExcludeAppPath | SingleApplication::ExcludeAppVersion); @@ -251,42 +252,36 @@ int main(int argc, char *argv[]) bool _result_ = Qv2rayTranslator->InstallTranslation(_lang); LOG(MODULE_UI, "Installing a tranlator from OS: " + _lang + " -- " + (_result_ ? "OK" : "Failed")) // - LOG("LICENCE", NEWLINE - "This program comes with ABSOLUTELY NO WARRANTY." NEWLINE "This is free software, and you are welcome to redistribute it" NEWLINE - "under certain conditions." NEWLINE NEWLINE "Copyright (c) 2019-2020 Qv2ray Development Group." NEWLINE NEWLINE NEWLINE - "Libraries that have been used in Qv2ray are listed below (Sorted by date added):" NEWLINE - "Copyright (c) 2020 dridk (@dridk): X2Struct (Apache)" NEWLINE "Copyright (c) 2011 SCHUTZ Sacha (@dridk): QJsonModel (MIT)" NEWLINE - "Copyright (c) 2020 Nikolaos Ftylitakis (@ftylitak): QZXing (Apache2)" NEWLINE - "Copyright (c) 2016 Singein (@Singein): ScreenShot (MIT)" NEWLINE - "Copyright (c) 2016 Nikhil Marathe (@nikhilm): QHttpServer (MIT)" NEWLINE - "Copyright (c) 2020 Itay Grudev (@itay-grudev): SingleApplication (MIT)" NEWLINE - "Copyright (c) 2020 paceholder (@paceholder): nodeeditor (QNodeEditor modified by lhy0403) (BSD-3-Clause)" NEWLINE - "Copyright (c) 2019 TheWanderingCoel (@TheWanderingCoel): ShadowClash (launchatlogin) (GPLv3)" NEWLINE - "Copyright (c) 2020 Ram Pani (@DuckSoft): QvRPCBridge (WTFPL)" NEWLINE - "Copyright (c) 2019 ShadowSocks (@shadowsocks): libQtShadowsocks (LGPLv3)" NEWLINE - "Copyright (c) 2015-2020 qBittorrent (Anton Lashkov) (@qBittorrent): speedplotview (GPLv2)" NEWLINE NEWLINE) + LOG("LICENCE", NEWLINE // + "This program comes with ABSOLUTELY NO WARRANTY." NEWLINE // + "This is free software, and you are welcome to redistribute it" NEWLINE // + "under certain conditions." NEWLINE // + NEWLINE // + "Copyright (c) 2019-2020 Qv2ray Development Group." NEWLINE // + NEWLINE // + "Libraries that have been used in Qv2ray are listed below (Sorted by date added):" NEWLINE // + "Copyright (c) 2020 dridk (@dridk): X2Struct (Apache)" NEWLINE // + "Copyright (c) 2011 SCHUTZ Sacha (@dridk): QJsonModel (MIT)" NEWLINE // + "Copyright (c) 2020 Nikolaos Ftylitakis (@ftylitak): QZXing (Apache2)" NEWLINE // + "Copyright (c) 2016 Singein (@Singein): ScreenShot (MIT)" NEWLINE // + "Copyright (c) 2016 Nikhil Marathe (@nikhilm): QHttpServer (MIT)" NEWLINE // + "Copyright (c) 2020 Itay Grudev (@itay-grudev): SingleApplication (MIT)" NEWLINE // + "Copyright (c) 2020 paceholder (@paceholder): nodeeditor (QNodeEditor modified by lhy0403) (BSD-3-Clause)" NEWLINE // + "Copyright (c) 2019 TheWanderingCoel (@TheWanderingCoel): ShadowClash (launchatlogin) (GPLv3)" NEWLINE // + "Copyright (c) 2020 Ram Pani (@DuckSoft): QvRPCBridge (WTFPL)" NEWLINE // + "Copyright (c) 2019 ShadowSocks (@shadowsocks): libQtShadowsocks (LGPLv3)" NEWLINE // + "Copyright (c) 2015-2020 qBittorrent (Anton Lashkov) (@qBittorrent): speedplotview (GPLv2)" NEWLINE NEWLINE) // // LOG(MODULE_INIT, "Qv2ray Start Time: " + QSTRN(QTime::currentTime().msecsSinceStartOfDay())) // #ifdef QT_DEBUG - cout << "WARNING: ============================== This is a debug build, many features are not stable enough. ==============================" - << endl; + cout << "WARNING: ========================= This is a debug build, many features are not stable enough. =========================" << endl; #endif // - // Load the language translation list. - // auto translationDir = Qv - - // auto translationDir = QvTranslator::deduceTranslationDir(); - // if (!translationDir) - // { - // LOG(MODULE_INIT, "FAILED to find any translations. THIS IS A BUILD ERROR.") - // QvMessageBoxWarn(nullptr, QObject::tr("Cannot load languages"), - // QObject::tr("Qv2ray will continue running, but you cannot change the UI language.")); - // } - // Qv2ray Initialize, find possible config paths and verify them. if (!initialiseQv2ray()) { + LOG(MODULE_INIT, "Failed to initialise Qv2ray, exiting.") return -1; } diff --git a/src/ui/w_ImportConfig.cpp b/src/ui/w_ImportConfig.cpp index a2ddd5de..a71396a4 100644 --- a/src/ui/w_ImportConfig.cpp +++ b/src/ui/w_ImportConfig.cpp @@ -24,7 +24,6 @@ ImportConfigWindow::ImportConfigWindow(QWidget *parent) : QDialog(parent) setupUi(this); // nameTxt->setText(tr("My Connection Imported at: ") + QDateTime::currentDateTime().toString("MM-dd hh:mm")); QvMessageBusConnect(ImportConfigWindow); - adjustSize(); RESTORE_RUNTIME_CONFIG(screenShotHideQv2ray, hideQv2rayCB->setChecked) } @@ -255,7 +254,7 @@ void ImportConfigWindow::on_cancelImportBtn_clicked() void ImportConfigWindow::on_subscriptionButton_clicked() { hide(); - SubscribeEditor w; + SubscriptionEditor w; w.exec(); auto importToComplex = !keepImportedInboundCheckBox->isEnabled(); connections.clear(); diff --git a/src/ui/w_MainWindow.cpp b/src/ui/w_MainWindow.cpp index ad971c14..3221830c 100644 --- a/src/ui/w_MainWindow.cpp +++ b/src/ui/w_MainWindow.cpp @@ -311,7 +311,7 @@ void MainWindow::timerEvent(QTimerEvent *event) auto log = readLastLog().trimmed(); if (!log.isEmpty()) { - FastAppendTextDocument(NEWLINE + log, qvLogDocument); + FastAppendTextDocument(NEWLINE + log, qvLogDocument); /*end*/ // qvLogDocument->setPlainText(qvLogDocument->toPlainText() + NEWLINE + log); } } @@ -378,11 +378,15 @@ void MainWindow::VersionUpdate(QByteArray &data) { LOG(MODULE_UPDATE, "New version detected.") auto link = root["html_url"].toString(""); - auto result = - QvMessageBoxAsk(this, tr("Update"), - tr("Found a new version: ") + root["tag_name"].toString("") + "\r\n" + root["name"].toString("") + - "\r\n------------\r\n" + root["body"].toString("") + "\r\n------------\r\n" + tr("Download Link: ") + link, - QMessageBox::Ignore); + auto result = QvMessageBoxAsk(this, tr("Update"), + tr("Found a new version: ") + // + root["tag_name"].toString("") + NEWLINE + // + root["name"].toString("") + // + NEWLINE "------------" NEWLINE + // + root["body"].toString("") + // + NEWLINE "------------" NEWLINE + // + tr("Download Link: ") + link, + QMessageBox::Ignore); if (result == QMessageBox::Yes) { @@ -392,7 +396,7 @@ void MainWindow::VersionUpdate(QByteArray &data) { // Set and save ingored version. GlobalConfig.ignoredVersion = newVersion.toString(); - // SaveGlobalConfig(GlobalConfig); + SaveGlobalSettings(); } } } @@ -566,7 +570,7 @@ void MainWindow::on_action_RCM_EditAsComplex_triggered() void MainWindow::on_subsButton_clicked() { - SubscribeEditor().exec(); + SubscriptionEditor().exec(); } void MainWindow::on_connectionListWidget_itemDoubleClicked(QTreeWidgetItem *item, int column) diff --git a/src/ui/w_MainWindow.ui b/src/ui/w_MainWindow.ui index e0495011..b7b32c92 100644 --- a/src/ui/w_MainWindow.ui +++ b/src/ui/w_MainWindow.ui @@ -2,22 +2,27 @@ MainWindow + + + 0 + 0 + 860 + 650 + + - 780 - 530 + 790 + 600 Qv2ray - - - - + 5 @@ -35,6 +40,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + @@ -43,6 +61,12 @@ QSizePolicy::Maximum + + + 0 + 0 + + diff --git a/src/ui/w_PreferencesWindow.cpp b/src/ui/w_PreferencesWindow.cpp index 3d86bb72..c42c41bf 100644 --- a/src/ui/w_PreferencesWindow.cpp +++ b/src/ui/w_PreferencesWindow.cpp @@ -175,11 +175,17 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), Current auto autoStartConnId = ConnectionId(CurrentConfig.autoStartId); auto autoStartGroupId = GetConnectionGroupId(autoStartConnId); - for (auto group : ConnectionManager->AllGroups()) { autoStartSubsCombo->addItem(GetDisplayName(group)); } + for (auto group : ConnectionManager->AllGroups()) + { + autoStartSubsCombo->addItem(GetDisplayName(group)); + } autoStartSubsCombo->setCurrentText(GetDisplayName(autoStartGroupId)); - for (auto conn : ConnectionManager->Connections(autoStartGroupId)) { autoStartConnCombo->addItem(GetDisplayName(conn)); } + for (auto conn : ConnectionManager->Connections(autoStartGroupId)) + { + autoStartConnCombo->addItem(GetDisplayName(conn)); + } autoStartConnCombo->setCurrentText(GetDisplayName(autoStartConnId)); @@ -1032,7 +1038,10 @@ void PreferencesWindow::on_autoStartSubsCombo_currentIndexChanged(const QString auto list = ConnectionManager->Connections(groupId); autoStartConnCombo->clear(); - for (auto id : list) { autoStartConnCombo->addItem(GetDisplayName(id)); } + for (auto id : list) + { + autoStartConnCombo->addItem(GetDisplayName(id)); + } } } diff --git a/src/ui/w_SubscriptionManager.cpp b/src/ui/w_SubscriptionManager.cpp index 85c53fd2..ac3c7ae8 100644 --- a/src/ui/w_SubscriptionManager.cpp +++ b/src/ui/w_SubscriptionManager.cpp @@ -4,27 +4,28 @@ #include "core/handler/ConfigHandler.hpp" #include "core/settings/SettingsBackend.hpp" -SubscribeEditor::SubscribeEditor(QWidget *parent) : QDialog(parent) +SubscriptionEditor::SubscriptionEditor(QWidget *parent) : QDialog(parent) { setupUi(this); - QvMessageBusConnect(SubscribeEditor); + QvMessageBusConnect(SubscriptionEditor); UpdateColorScheme(); - adjustSize(); for (auto subs : ConnectionManager->Subscriptions()) - { subscriptionList->addTopLevelItem(new QTreeWidgetItem(QStringList{ GetDisplayName(subs), subs.toString() })); } + { + subscriptionList->addTopLevelItem(new QTreeWidgetItem(QStringList{ GetDisplayName(subs), subs.toString() })); + } if (subscriptionList->topLevelItemCount() > 0) { subscriptionList->setCurrentItem(subscriptionList->topLevelItem(0)); } } -void SubscribeEditor::UpdateColorScheme() +void SubscriptionEditor::UpdateColorScheme() { addSubsButton->setIcon(QICON_R("add.png")); removeSubsButton->setIcon(QICON_R("delete.png")); } -QvMessageBusSlotImpl(SubscribeEditor) +QvMessageBusSlotImpl(SubscriptionEditor) { switch (msg) { @@ -32,16 +33,16 @@ QvMessageBusSlotImpl(SubscribeEditor) } } -tuple SubscribeEditor::GetSelectedConfig() +tuple SubscriptionEditor::GetSelectedConfig() { return { GetDisplayName(currentConnectionId), ConnectionManager->GetConnectionRoot(currentConnectionId) }; } -SubscribeEditor::~SubscribeEditor() +SubscriptionEditor::~SubscriptionEditor() { } -void SubscribeEditor::on_addSubsButton_clicked() +void SubscriptionEditor::on_addSubsButton_clicked() { auto const key = QSTRN(QTime::currentTime().msecsSinceStartOfDay()); auto id = ConnectionManager->CreateGroup(key, true); @@ -49,7 +50,7 @@ void SubscribeEditor::on_addSubsButton_clicked() subscriptionList->addTopLevelItem(new QTreeWidgetItem(QStringList{ key, id.toString() })); } -void SubscribeEditor::on_updateButton_clicked() +void SubscriptionEditor::on_updateButton_clicked() { if (QvMessageBoxAsk(this, tr("Reload Subscription"), tr("Would you like to reload the subscription?")) == QMessageBox::Yes) { @@ -60,7 +61,7 @@ void SubscribeEditor::on_updateButton_clicked() } } -void SubscribeEditor::on_removeSubsButton_clicked() +void SubscriptionEditor::on_removeSubsButton_clicked() { if (QvMessageBoxAsk(this, tr("Deleting a subscription"), tr("All connections will be moved to default group, do you want to continue?")) == QMessageBox::Yes) @@ -81,17 +82,17 @@ void SubscribeEditor::on_removeSubsButton_clicked() } } -void SubscribeEditor::on_buttonBox_accepted() +void SubscriptionEditor::on_buttonBox_accepted() { // Nothing? } -void SubscribeEditor::on_subscriptionList_itemSelectionChanged() +void SubscriptionEditor::on_subscriptionList_itemSelectionChanged() { groupBox_2->setEnabled(subscriptionList->selectedItems().count() > 0); } -void SubscribeEditor::on_subscriptionList_itemClicked(QTreeWidgetItem *item, int column) +void SubscriptionEditor::on_subscriptionList_itemClicked(QTreeWidgetItem *item, int column) { Q_UNUSED(column) @@ -118,31 +119,31 @@ void SubscribeEditor::on_subscriptionList_itemClicked(QTreeWidgetItem *item, int } } -void SubscribeEditor::on_subscriptionList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) +void SubscriptionEditor::on_subscriptionList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { Q_UNUSED(previous) on_subscriptionList_itemClicked(current, 0); } -void SubscribeEditor::on_subNameTxt_textEdited(const QString &arg1) +void SubscriptionEditor::on_subNameTxt_textEdited(const QString &arg1) { subscriptionList->selectedItems().first()->setText(0, arg1); ConnectionManager->RenameGroup(currentSubId, arg1.trimmed()); } -void SubscribeEditor::on_subAddrTxt_textEdited(const QString &arg1) +void SubscriptionEditor::on_subAddrTxt_textEdited(const QString &arg1) { auto newUpdateInterval = updateIntervalSB->value(); ConnectionManager->SetSubscriptionData(currentSubId, arg1, newUpdateInterval); } -void SubscribeEditor::on_updateIntervalSB_valueChanged(double arg1) +void SubscriptionEditor::on_updateIntervalSB_valueChanged(double arg1) { auto newAddress = subAddrTxt->text().trimmed(); ConnectionManager->SetSubscriptionData(currentSubId, newAddress, arg1); } -void SubscribeEditor::on_connectionsList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) +void SubscriptionEditor::on_connectionsList_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous) { Q_UNUSED(previous) if (current != nullptr) diff --git a/src/ui/w_SubscriptionManager.hpp b/src/ui/w_SubscriptionManager.hpp index cf1b6c43..01134023 100644 --- a/src/ui/w_SubscriptionManager.hpp +++ b/src/ui/w_SubscriptionManager.hpp @@ -7,15 +7,15 @@ #include -class SubscribeEditor +class SubscriptionEditor : public QDialog , private Ui::w_SubscribeEditor { Q_OBJECT public: - explicit SubscribeEditor(QWidget *parent = nullptr); - ~SubscribeEditor(); + explicit SubscriptionEditor(QWidget *parent = nullptr); + ~SubscriptionEditor(); tuple GetSelectedConfig(); private: