mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:56:22 +00:00
UI: OptionsPage: Add group boxes.
This commit is contained in:
parent
0ac0bcd05f
commit
40a94e2835
@ -1,5 +1,8 @@
|
||||
#include "basepage.h"
|
||||
|
||||
#include <QAbstractButton>
|
||||
#include <QDesktopServices>
|
||||
|
||||
#include "../optionscontroller.h"
|
||||
|
||||
BasePage::BasePage(OptionsController *ctrl,
|
||||
@ -50,3 +53,16 @@ void BasePage::setupController()
|
||||
|
||||
connect(ctrl(), &OptionsController::retranslateUi, this, &BasePage::onRetranslateUi);
|
||||
}
|
||||
|
||||
bool BasePage::openUrlExternally(const QUrl &url)
|
||||
{
|
||||
return QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
void BasePage::onLinkClicked()
|
||||
{
|
||||
auto button = qobject_cast<QAbstractButton *>(sender());
|
||||
if (button) {
|
||||
openUrlExternally(QUrl::fromLocalFile(button->windowFilePath()));
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define BASEPAGE_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QUrl>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QCheckBox)
|
||||
QT_FORWARD_DECLARE_CLASS(QComboBox)
|
||||
QT_FORWARD_DECLARE_CLASS(QGroupBox)
|
||||
QT_FORWARD_DECLARE_CLASS(QLabel)
|
||||
QT_FORWARD_DECLARE_CLASS(QLineEdit)
|
||||
QT_FORWARD_DECLARE_CLASS(QPushButton)
|
||||
@ -41,6 +43,9 @@ protected slots:
|
||||
|
||||
virtual void onRetranslateUi() {}
|
||||
|
||||
bool openUrlExternally(const QUrl &url);
|
||||
void onLinkClicked();
|
||||
|
||||
private:
|
||||
void setupController();
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "mainpage.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QIcon>
|
||||
#include <QPushButton>
|
||||
#include <QTabWidget>
|
||||
@ -8,8 +7,6 @@
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../../../fortsettings.h"
|
||||
#include "../../../task/taskinfoupdatechecker.h"
|
||||
#include "../../../task/taskmanager.h"
|
||||
#include "../../controls/controlutil.h"
|
||||
#include "../optionscontroller.h"
|
||||
#include "addressespage.h"
|
||||
@ -18,15 +15,6 @@
|
||||
#include "schedulepage.h"
|
||||
#include "statisticspage.h"
|
||||
|
||||
namespace {
|
||||
|
||||
bool openUrlExternally(const QUrl &url)
|
||||
{
|
||||
return QDesktopServices::openUrl(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MainPage::MainPage(OptionsController *ctrl,
|
||||
QWidget *parent) :
|
||||
BasePage(ctrl, parent)
|
||||
@ -46,21 +34,12 @@ void MainPage::onRetranslateUi()
|
||||
m_btProfile->setText(tr("Profile"));
|
||||
m_btStat->setText(tr("Statistics"));
|
||||
m_btReleases->setText(tr("Releases"));
|
||||
m_btNewVersion->setText(tr("New Version!"));
|
||||
|
||||
m_btOk->setText(tr("OK"));
|
||||
m_btApply->setText(tr("Apply"));
|
||||
m_btCancel->setText(tr("Cancel"));
|
||||
}
|
||||
|
||||
void MainPage::onLinkClicked()
|
||||
{
|
||||
auto button = qobject_cast<QAbstractButton *>(sender());
|
||||
if (button) {
|
||||
openUrlExternally(QUrl::fromLocalFile(button->windowFilePath()));
|
||||
}
|
||||
}
|
||||
|
||||
void MainPage::setupUi()
|
||||
{
|
||||
auto layout = new QVBoxLayout();
|
||||
@ -97,21 +76,16 @@ QLayout *MainPage::setupDialogButtons()
|
||||
m_btProfile = ControlUtil::createLinkButton(":/images/folder_user.png", settings()->profilePath());
|
||||
m_btStat = ControlUtil::createLinkButton(":/images/folder_database.png", settings()->statPath());
|
||||
m_btReleases = ControlUtil::createLinkButton(":/images/server_go.png", settings()->appUpdatesUrl());
|
||||
m_btNewVersion = ControlUtil::createLinkButton(":/images/server_compressed.png");
|
||||
|
||||
connect(m_btLogs, &QAbstractButton::clicked, this, &MainPage::onLinkClicked);
|
||||
connect(m_btProfile, &QAbstractButton::clicked, this, &MainPage::onLinkClicked);
|
||||
connect(m_btStat, &QAbstractButton::clicked, this, &MainPage::onLinkClicked);
|
||||
connect(m_btReleases, &QAbstractButton::clicked, this, &MainPage::onLinkClicked);
|
||||
connect(m_btNewVersion, &QAbstractButton::clicked, this, &MainPage::onLinkClicked);
|
||||
|
||||
setupNewVersionButton();
|
||||
|
||||
buttonsLayout->addWidget(m_btLogs);
|
||||
buttonsLayout->addWidget(m_btProfile);
|
||||
buttonsLayout->addWidget(m_btStat);
|
||||
buttonsLayout->addWidget(m_btReleases);
|
||||
buttonsLayout->addWidget(m_btNewVersion);
|
||||
|
||||
buttonsLayout->addStretch(1);
|
||||
|
||||
@ -132,21 +106,6 @@ QLayout *MainPage::setupDialogButtons()
|
||||
return buttonsLayout;
|
||||
}
|
||||
|
||||
void MainPage::setupNewVersionButton()
|
||||
{
|
||||
const auto refreshNewVersionButton = [&] {
|
||||
auto updateChecker = taskManager()->taskInfoUpdateChecker();
|
||||
m_btNewVersion->setVisible(!updateChecker->version().isEmpty());
|
||||
m_btNewVersion->setWindowFilePath(updateChecker->downloadUrl());
|
||||
m_btNewVersion->setToolTip(updateChecker->plainReleaseText());
|
||||
};
|
||||
|
||||
refreshNewVersionButton();
|
||||
|
||||
connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged,
|
||||
this, refreshNewVersionButton);
|
||||
}
|
||||
|
||||
void MainPage::setupOkApplyButtons()
|
||||
{
|
||||
const auto refreshOkApplyButtons = [&] {
|
||||
|
@ -22,13 +22,9 @@ public:
|
||||
protected slots:
|
||||
void onRetranslateUi() override;
|
||||
|
||||
private slots:
|
||||
void onLinkClicked();
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
QLayout *setupDialogButtons();
|
||||
void setupNewVersionButton();
|
||||
void setupOkApplyButtons();
|
||||
|
||||
private:
|
||||
@ -38,7 +34,6 @@ private:
|
||||
QPushButton *m_btProfile = nullptr;
|
||||
QPushButton *m_btStat = nullptr;
|
||||
QPushButton *m_btReleases = nullptr;
|
||||
QPushButton *m_btNewVersion = nullptr;
|
||||
|
||||
QPushButton *m_btOk = nullptr;
|
||||
QPushButton *m_btApply = nullptr;
|
||||
|
@ -2,16 +2,19 @@
|
||||
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../../../fortmanager.h"
|
||||
#include "../../../fortsettings.h"
|
||||
#include "../../../conf/firewallconf.h"
|
||||
#include "../../../driver/drivermanager.h"
|
||||
#include "../../../fortmanager.h"
|
||||
#include "../../../fortsettings.h"
|
||||
#include "../../../task/taskinfoupdatechecker.h"
|
||||
#include "../../../task/taskmanager.h"
|
||||
#include "../../../translationmanager.h"
|
||||
#include "../../../util/stringutil.h"
|
||||
#include "../../controls/controlutil.h"
|
||||
@ -54,6 +57,12 @@ void OptionsPage::onSaved()
|
||||
|
||||
void OptionsPage::onRetranslateUi()
|
||||
{
|
||||
m_gbStartup->setTitle(tr("Startup"));
|
||||
m_gbTraffic->setTitle(tr("Traffic"));
|
||||
m_gbGlobal->setTitle(tr("Global"));
|
||||
m_gbDriver->setTitle(tr("Driver"));
|
||||
m_gbNewVersion->setTitle(tr("New Version"));
|
||||
|
||||
m_cbStart->setText(tr("Start with Windows"));
|
||||
m_cbProvBoot->setText(tr("Stop traffic when Fort Firewall is not running"));
|
||||
m_cbFilterEnabled->setText(tr("Filter Enabled"));
|
||||
@ -67,21 +76,18 @@ void OptionsPage::onRetranslateUi()
|
||||
|
||||
m_labelLanguage->setText(tr("Language:"));
|
||||
|
||||
m_labelDriver->setText(tr("Driver:"));
|
||||
retranslateDriverMessage();
|
||||
m_btInstallDriver->setText(tr("Install"));
|
||||
m_btRemoveDriver->setText(tr("Remove"));
|
||||
|
||||
m_installDriverButton->setText(tr("Install"));
|
||||
m_removeDriverButton->setText(tr("Remove"));
|
||||
m_btNewVersion->setText(tr("Download"));
|
||||
}
|
||||
|
||||
void OptionsPage::setupUi()
|
||||
{
|
||||
auto rowLayout = new QHBoxLayout();
|
||||
|
||||
// Column #1
|
||||
auto colLayout1 = new QVBoxLayout();
|
||||
colLayout1->setSpacing(10);
|
||||
rowLayout->addLayout(colLayout1);
|
||||
|
||||
m_cbStart = ControlUtil::createCheckBox(settings()->startWithWindows(), [&](bool) {
|
||||
setIniEdited(true);
|
||||
@ -110,13 +116,21 @@ void OptionsPage::setupUi()
|
||||
setIniEdited(true);
|
||||
});
|
||||
|
||||
colLayout1->addWidget(m_cbStart);
|
||||
colLayout1->addWidget(m_cbProvBoot);
|
||||
colLayout1->addWidget(m_cbFilterEnabled);
|
||||
colLayout1->addWidget(m_cbFilterLocals);
|
||||
colLayout1->addWidget(m_cbStopTraffic);
|
||||
colLayout1->addWidget(m_cbStopInetTraffic);
|
||||
colLayout1->addWidget(m_cbHotKeys);
|
||||
m_gbStartup = new QGroupBox();
|
||||
auto startupLayout = new QVBoxLayout();
|
||||
startupLayout->addWidget(m_cbStart);
|
||||
startupLayout->addWidget(m_cbProvBoot);
|
||||
m_gbStartup->setLayout(startupLayout);
|
||||
colLayout1->addWidget(m_gbStartup);
|
||||
|
||||
m_gbTraffic = new QGroupBox();
|
||||
auto trafficLayout = new QVBoxLayout();
|
||||
trafficLayout->addWidget(m_cbFilterEnabled);
|
||||
trafficLayout->addWidget(m_cbFilterLocals);
|
||||
trafficLayout->addWidget(m_cbStopTraffic);
|
||||
trafficLayout->addWidget(m_cbStopInetTraffic);
|
||||
m_gbTraffic->setLayout(trafficLayout);
|
||||
colLayout1->addWidget(m_gbTraffic);
|
||||
|
||||
// Password Row
|
||||
auto passwordLayout = new QHBoxLayout();
|
||||
@ -138,8 +152,6 @@ void OptionsPage::setupUi()
|
||||
passwordLayout->addWidget(m_editPassword);
|
||||
passwordLayout->addStretch(1);
|
||||
|
||||
colLayout1->addLayout(passwordLayout);
|
||||
|
||||
// Language Row
|
||||
auto langLayout = new QHBoxLayout();
|
||||
langLayout->setSpacing(10);
|
||||
@ -152,20 +164,36 @@ void OptionsPage::setupUi()
|
||||
langLayout->addWidget(m_comboLanguage);
|
||||
langLayout->addStretch(1);
|
||||
|
||||
colLayout1->addLayout(langLayout);
|
||||
m_gbGlobal = new QGroupBox();
|
||||
auto globalLayout = new QVBoxLayout();
|
||||
globalLayout->addWidget(m_cbHotKeys);
|
||||
globalLayout->addLayout(passwordLayout);
|
||||
globalLayout->addLayout(langLayout);
|
||||
m_gbGlobal->setLayout(globalLayout);
|
||||
colLayout1->addWidget(m_gbGlobal);
|
||||
|
||||
colLayout1->addStretch(1);
|
||||
|
||||
// Column #2
|
||||
auto colLayout2 = new QVBoxLayout();
|
||||
colLayout2->setSpacing(10);
|
||||
rowLayout->addLayout(colLayout2, 1);
|
||||
|
||||
auto driverFrame = setupDriverFrame();
|
||||
setupDriverBox();
|
||||
|
||||
colLayout2->addWidget(driverFrame, 0, Qt::AlignHCenter);
|
||||
setupNewVersionBox();
|
||||
setupNewVersionUpdate();
|
||||
|
||||
colLayout2->addWidget(m_gbDriver);
|
||||
colLayout2->addWidget(m_gbNewVersion);
|
||||
colLayout2->addStretch(1);
|
||||
|
||||
// Row
|
||||
auto rowLayout = new QHBoxLayout();
|
||||
rowLayout->addLayout(colLayout1);
|
||||
rowLayout->addStretch();
|
||||
rowLayout->addLayout(colLayout2);
|
||||
rowLayout->addStretch();
|
||||
|
||||
this->setLayout(rowLayout);
|
||||
}
|
||||
|
||||
@ -213,35 +241,25 @@ void OptionsPage::setupComboLanguage()
|
||||
connect(translationManager(), &TranslationManager::languageChanged, this, refreshComboLanguage);
|
||||
}
|
||||
|
||||
QFrame *OptionsPage::setupDriverFrame()
|
||||
void OptionsPage::setupDriverBox()
|
||||
{
|
||||
auto frame = new QFrame();
|
||||
frame->setFrameShape(QFrame::Panel);
|
||||
m_gbDriver = new QGroupBox();
|
||||
|
||||
auto colLayout = new QVBoxLayout();
|
||||
colLayout->setMargin(15);
|
||||
colLayout->setSpacing(10);
|
||||
frame->setLayout(colLayout);
|
||||
m_gbDriver->setLayout(colLayout);
|
||||
|
||||
// Label Row
|
||||
auto labelLayout = new QHBoxLayout();
|
||||
labelLayout->setSpacing(4);
|
||||
colLayout->addLayout(labelLayout);
|
||||
|
||||
m_labelDriver = new QLabel();
|
||||
{
|
||||
QFont font;
|
||||
font.setBold(true);
|
||||
m_labelDriver->setFont(font);
|
||||
}
|
||||
|
||||
m_labelDriverMessage = new QLabel();
|
||||
|
||||
setupDriverIcon();
|
||||
|
||||
labelLayout->addStretch(1);
|
||||
labelLayout->addWidget(m_iconDriver, 0, Qt::AlignTop);
|
||||
labelLayout->addWidget(m_labelDriver);
|
||||
labelLayout->addWidget(m_labelDriverMessage);
|
||||
labelLayout->addStretch(1);
|
||||
|
||||
@ -250,23 +268,21 @@ QFrame *OptionsPage::setupDriverFrame()
|
||||
buttonsLayout->setSpacing(10);
|
||||
colLayout->addLayout(buttonsLayout);
|
||||
|
||||
m_installDriverButton = ControlUtil::createButton(QString(), [&] {
|
||||
m_btInstallDriver = ControlUtil::createButton(QString(), [&] {
|
||||
if (fortManager()->showQuestionBox(tr("Install Driver?"))) {
|
||||
fortManager()->installDriver();
|
||||
}
|
||||
});
|
||||
m_removeDriverButton = ControlUtil::createButton(QString(), [&] {
|
||||
m_btRemoveDriver = ControlUtil::createButton(QString(), [&] {
|
||||
if (fortManager()->showQuestionBox(tr("Remove Driver?"))) {
|
||||
fortManager()->removeDriver();
|
||||
}
|
||||
});
|
||||
|
||||
buttonsLayout->addStretch(1);
|
||||
buttonsLayout->addWidget(m_installDriverButton);
|
||||
buttonsLayout->addWidget(m_removeDriverButton);
|
||||
buttonsLayout->addWidget(m_btInstallDriver);
|
||||
buttonsLayout->addWidget(m_btRemoveDriver);
|
||||
buttonsLayout->addStretch(1);
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
void OptionsPage::setupDriverIcon()
|
||||
@ -300,3 +316,41 @@ void OptionsPage::retranslateDriverMessage()
|
||||
|
||||
m_labelDriverMessage->setText(text);
|
||||
}
|
||||
|
||||
void OptionsPage::setupNewVersionBox()
|
||||
{
|
||||
m_gbNewVersion = new QGroupBox();
|
||||
|
||||
auto colLayout = new QVBoxLayout();
|
||||
colLayout->setSpacing(10);
|
||||
m_gbNewVersion->setLayout(colLayout);
|
||||
|
||||
// Label
|
||||
m_labelNewVersion = new QLabel();
|
||||
m_labelNewVersion->setTextFormat(Qt::MarkdownText);
|
||||
m_labelNewVersion->setOpenExternalLinks(true);
|
||||
colLayout->addWidget(m_labelNewVersion, 0, Qt::AlignHCenter);
|
||||
|
||||
// Button
|
||||
m_btNewVersion = ControlUtil::createLinkButton(":/images/server_compressed.png");
|
||||
|
||||
connect(m_btNewVersion, &QAbstractButton::clicked, this, &OptionsPage::onLinkClicked);
|
||||
|
||||
colLayout->addWidget(m_btNewVersion, 0, Qt::AlignHCenter);
|
||||
}
|
||||
|
||||
void OptionsPage::setupNewVersionUpdate()
|
||||
{
|
||||
const auto refreshNewVersion = [&] {
|
||||
auto updateChecker = taskManager()->taskInfoUpdateChecker();
|
||||
m_gbNewVersion->setVisible(!updateChecker->version().isEmpty());
|
||||
m_labelNewVersion->setText(updateChecker->releaseText());
|
||||
m_btNewVersion->setWindowFilePath(updateChecker->downloadUrl());
|
||||
m_btNewVersion->setToolTip(updateChecker->downloadUrl());
|
||||
};
|
||||
|
||||
refreshNewVersion();
|
||||
|
||||
connect(taskManager()->taskInfoUpdateChecker(), &TaskInfoUpdateChecker::versionChanged,
|
||||
this, refreshNewVersion);
|
||||
}
|
||||
|
@ -25,13 +25,20 @@ private:
|
||||
void setupEditPassword();
|
||||
void retranslateEditPassword();
|
||||
void setupComboLanguage();
|
||||
QFrame *setupDriverFrame();
|
||||
void setupDriverBox();
|
||||
void setupDriverIcon();
|
||||
void retranslateDriverMessage();
|
||||
void setupNewVersionBox();
|
||||
void setupNewVersionUpdate();
|
||||
|
||||
private:
|
||||
bool m_iniEdited = false;
|
||||
|
||||
QGroupBox *m_gbStartup = nullptr;
|
||||
QGroupBox *m_gbTraffic = nullptr;
|
||||
QGroupBox *m_gbGlobal = nullptr;
|
||||
QGroupBox *m_gbDriver = nullptr;
|
||||
QGroupBox *m_gbNewVersion = nullptr;
|
||||
QCheckBox *m_cbStart = nullptr;
|
||||
QCheckBox *m_cbProvBoot = nullptr;
|
||||
QCheckBox *m_cbFilterEnabled = nullptr;
|
||||
@ -44,10 +51,11 @@ private:
|
||||
QLabel *m_labelLanguage = nullptr;
|
||||
QComboBox *m_comboLanguage = nullptr;
|
||||
QLabel *m_iconDriver = nullptr;
|
||||
QLabel *m_labelDriver = nullptr;
|
||||
QLabel *m_labelDriverMessage = nullptr;
|
||||
QPushButton *m_installDriverButton = nullptr;
|
||||
QPushButton *m_removeDriverButton = nullptr;
|
||||
QPushButton *m_btInstallDriver = nullptr;
|
||||
QPushButton *m_btRemoveDriver = nullptr;
|
||||
QLabel *m_labelNewVersion = nullptr;
|
||||
QPushButton *m_btNewVersion = nullptr;
|
||||
};
|
||||
|
||||
#endif // OPTIONSPAGE_H
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "taskinfoupdatechecker.h"
|
||||
|
||||
#include <QDataStream>
|
||||
#include <QTextDocument>
|
||||
|
||||
#include "../../common/version.h"
|
||||
#include "../fortmanager.h"
|
||||
@ -14,13 +13,6 @@ TaskInfoUpdateChecker::TaskInfoUpdateChecker(QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
QString TaskInfoUpdateChecker::plainReleaseText() const
|
||||
{
|
||||
QTextDocument doc;
|
||||
doc.setMarkdown(releaseText());
|
||||
return doc.toPlainText();
|
||||
}
|
||||
|
||||
QByteArray TaskInfoUpdateChecker::data() const
|
||||
{
|
||||
QByteArray data;
|
||||
|
@ -16,7 +16,6 @@ public:
|
||||
QString version() const { return m_version; }
|
||||
QString downloadUrl() const { return m_downloadUrl; }
|
||||
QString releaseText() const { return m_releaseText; }
|
||||
QString plainReleaseText() const;
|
||||
|
||||
QByteArray data() const override;
|
||||
void setData(const QByteArray &data) override;
|
||||
|
Loading…
Reference in New Issue
Block a user