fix: fixing MainWindow size issue.

This commit is contained in:
Qv2ray-dev 2020-03-21 15:13:52 +08:00
parent 750c96c5b1
commit ae0776cae9
11 changed files with 124 additions and 92 deletions

View File

@ -1 +1 @@
4955
4956

View File

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

View File

@ -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.")

View File

@ -27,7 +27,7 @@ namespace Qv2ray::common
QCommandLineOption noAPIOption;
QCommandLineOption runAsRootOption;
QCommandLineOption debugOption;
QCommandLineOption hiDpiOption;
QCommandLineOption noScaleFactorOption;
QCommandLineOption forceHiDpiOption;
QCommandLineOption withToolbarOption;
QCommandLineOption helpOption;

View File

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

View File

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

View File

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

View File

@ -2,22 +2,27 @@
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>860</width>
<height>650</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>780</width>
<height>530</height>
<width>790</width>
<height>600</height>
</size>
</property>
<property name="windowTitle">
<string>Qv2ray</string>
</property>
<property name="toolTip">
<string/>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1,0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0">
<property name="spacing">
<number>5</number>
</property>
@ -35,6 +40,19 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -43,6 +61,12 @@
<property name="sizeType">
<enum>QSizePolicy::Maximum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>

View File

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

View File

@ -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<QString, CONFIGROOT> SubscribeEditor::GetSelectedConfig()
tuple<QString, CONFIGROOT> 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)

View File

@ -7,15 +7,15 @@
#include <QDialog>
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<QString, CONFIGROOT> GetSelectedConfig();
private: