diff --git a/src/ui/form/opt/pages/addressespage.cpp b/src/ui/form/opt/pages/addressespage.cpp index 98640de1..be47c944 100644 --- a/src/ui/form/opt/pages/addressespage.cpp +++ b/src/ui/form/opt/pages/addressespage.cpp @@ -71,32 +71,15 @@ void AddressesPage::setupUi() setupAddressesUseAllEnabled(); - setupAddressGroup(); - // Splitter setupSplitter(); layout->addWidget(m_splitter, 1); + setupAddressGroup(); + this->setLayout(layout); } -void AddressesPage::setupSplitter() -{ - m_splitter = new TextArea2Splitter(ctrl()); - - m_splitter->setSettingsPropName("optWindowAddrSplit"); - - Q_ASSERT(!m_splitter->handle()); - - m_splitter->addWidget(m_includeAddresses); - m_splitter->addWidget(m_excludeAddresses); - - Q_ASSERT(m_splitter->handle()); - - m_splitter->handle()->setTextArea1(m_includeAddresses->editIpText()); - m_splitter->handle()->setTextArea2(m_excludeAddresses->editIpText()); -} - void AddressesPage::setupIncludeAddresses() { m_includeAddresses = new AddressesColumn(); @@ -173,6 +156,23 @@ void AddressesPage::retranslateAddressesPlaceholderText() m_excludeAddresses->editIpText()->setPlaceholderText(placeholderText); } +void AddressesPage::setupSplitter() +{ + m_splitter = new TextArea2Splitter(ctrl()); + + m_splitter->setSettingsPropName("optWindowAddrSplit"); + + Q_ASSERT(!m_splitter->handle()); + + m_splitter->addWidget(m_includeAddresses); + m_splitter->addWidget(m_excludeAddresses); + + Q_ASSERT(m_splitter->handle()); + + m_splitter->handle()->setTextArea1(m_includeAddresses->editIpText()); + m_splitter->handle()->setTextArea2(m_excludeAddresses->editIpText()); +} + void AddressesPage::refreshGroup() { m_includeAddresses->cbUseAll()->setChecked(addressGroup()->includeAll()); diff --git a/src/ui/form/opt/pages/addressespage.h b/src/ui/form/opt/pages/addressespage.h index 6c41cc2e..364e02d6 100644 --- a/src/ui/form/opt/pages/addressespage.h +++ b/src/ui/form/opt/pages/addressespage.h @@ -25,11 +25,11 @@ protected slots: private: void setupUi(); - void setupSplitter(); void setupIncludeAddresses(); void setupExcludeAddresses(); void setupAddressesUseAllEnabled(); void retranslateAddressesPlaceholderText(); + void setupSplitter(); void refreshGroup(); void setupAddressGroup(); diff --git a/src/ui/form/opt/pages/applicationspage.cpp b/src/ui/form/opt/pages/applicationspage.cpp index e58156e6..a28d2b2c 100644 --- a/src/ui/form/opt/pages/applicationspage.cpp +++ b/src/ui/form/opt/pages/applicationspage.cpp @@ -2,8 +2,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -17,7 +19,10 @@ #include "../../controls/checktimeperiod.h" #include "../../controls/controlutil.h" #include "../../controls/tabbar.h" +#include "../controls/textarea2splitter.h" +#include "../controls/textarea2splitterhandle.h" #include "../optionscontroller.h" +#include "apps/appscolumn.h" namespace { @@ -61,6 +66,16 @@ void ApplicationsPage::onRetranslateUi() m_cbGroupEnabled->setText(tr("Enabled")); m_ctpGroupPeriod->checkBox()->setText(tr("time period:")); + + m_blockApps->labelTitle()->setText(tr("Block")); + m_allowApps->labelTitle()->setText(tr("Allow")); + + m_splitter->handle()->btMoveAllFrom1To2()->setToolTip(tr("Move All Lines to 'Allow'")); + m_splitter->handle()->btMoveAllFrom2To1()->setToolTip(tr("Move All Lines to 'Block'")); + m_splitter->handle()->btMoveSelectedFrom1To2()->setToolTip(tr("Move Selected Lines to 'Allow'")); + m_splitter->handle()->btMoveSelectedFrom2To1()->setToolTip(tr("Move Selected Lines to 'Block'")); + + retranslateAppsPlaceholderText(); } void ApplicationsPage::setupUi() @@ -79,9 +94,15 @@ void ApplicationsPage::setupUi() auto groupHeader = setupGroupHeader(); layout->addLayout(groupHeader); - setupAppGroup(); + // App Columns + setupBlockApps(); + setupAllowApps(); - layout->addStretch(); + // Splitter + setupSplitter(); + layout->addWidget(m_splitter, 1); + + setupAppGroup(); this->setLayout(layout); } @@ -423,6 +444,67 @@ void ApplicationsPage::setupGroupPeriodEnabled() connect(m_cbGroupEnabled, &QCheckBox::toggled, this, refreshPeriodEnabled); } +void ApplicationsPage::setupBlockApps() +{ + m_blockApps = new AppsColumn(); + + connect(m_blockApps->editText(), &QPlainTextEdit::textChanged, [&] { + const auto text = m_blockApps->editText()->toPlainText(); + + if (appGroup()->blockText() == text) + return; + + appGroup()->setBlockText(text); + + ctrl()->setConfEdited(true); + }); +} + +void ApplicationsPage::setupAllowApps() +{ + m_allowApps = new AppsColumn(); + + connect(m_allowApps->editText(), &QPlainTextEdit::textChanged, [&] { + const auto text = m_allowApps->editText()->toPlainText(); + + if (appGroup()->allowText() == text) + return; + + appGroup()->setAllowText(text); + + ctrl()->setConfEdited(true); + }); +} + +void ApplicationsPage::retranslateAppsPlaceholderText() +{ + const auto placeholderText = tr("# Examples:") + '\n' + + QLatin1String( + "System\n" + "C:\\Program Files (x86)\\Microsoft\\Skype for Desktop\\Skype.exe\n") + + '\n' + tr("# All programs in the sub-path:") + + QLatin1String("\nC:\\Git\\**"); + + m_allowApps->editText()->setPlaceholderText(placeholderText); +} + +void ApplicationsPage::setupSplitter() +{ + m_splitter = new TextArea2Splitter(ctrl()); + + m_splitter->setSettingsPropName("optWindowAppsSplit"); + + Q_ASSERT(!m_splitter->handle()); + + m_splitter->addWidget(m_blockApps); + m_splitter->addWidget(m_allowApps); + + Q_ASSERT(m_splitter->handle()); + + m_splitter->handle()->setTextArea1(m_blockApps->editText()); + m_splitter->handle()->setTextArea2(m_allowApps->editText()); +} + void ApplicationsPage::refreshGroup() { m_cscLimitIn->checkBox()->setChecked(appGroup()->limitInEnabled()); @@ -440,6 +522,9 @@ void ApplicationsPage::refreshGroup() appGroup()->periodFrom())); m_ctpGroupPeriod->timeEdit2()->setTime(CheckTimePeriod::toTime( appGroup()->periodTo())); + + m_blockApps->editText()->setPlainText(appGroup()->blockText()); + m_allowApps->editText()->setPlainText(appGroup()->allowText()); } void ApplicationsPage::setupAppGroup() diff --git a/src/ui/form/opt/pages/applicationspage.h b/src/ui/form/opt/pages/applicationspage.h index ea259f5c..2720f72a 100644 --- a/src/ui/form/opt/pages/applicationspage.h +++ b/src/ui/form/opt/pages/applicationspage.h @@ -4,9 +4,11 @@ #include "basepage.h" QT_FORWARD_DECLARE_CLASS(AppGroup) -QT_FORWARD_DECLARE_CLASS(TabBar) +QT_FORWARD_DECLARE_CLASS(AppsColumn) QT_FORWARD_DECLARE_CLASS(CheckSpinCombo) QT_FORWARD_DECLARE_CLASS(CheckTimePeriod) +QT_FORWARD_DECLARE_CLASS(TabBar) +QT_FORWARD_DECLARE_CLASS(TextArea2Splitter) class ApplicationsPage : public BasePage { @@ -44,6 +46,10 @@ private: void setupGroupEnabled(); void setupGroupPeriod(); void setupGroupPeriodEnabled(); + void setupBlockApps(); + void setupAllowApps(); + void retranslateAppsPlaceholderText(); + void setupSplitter(); void refreshGroup(); void setupAppGroup(); @@ -68,6 +74,9 @@ private: QCheckBox *m_cbFragmentPacket = nullptr; QCheckBox *m_cbGroupEnabled = nullptr; CheckTimePeriod *m_ctpGroupPeriod = nullptr; + AppsColumn *m_blockApps = nullptr; + AppsColumn *m_allowApps = nullptr; + TextArea2Splitter *m_splitter = nullptr; }; #endif // APPLICATIONSPAGE_H diff --git a/src/ui/form/opt/pages/apps/appscolumn.cpp b/src/ui/form/opt/pages/apps/appscolumn.cpp index 37f4ca5d..e13618aa 100644 --- a/src/ui/form/opt/pages/apps/appscolumn.cpp +++ b/src/ui/form/opt/pages/apps/appscolumn.cpp @@ -1,6 +1,37 @@ #include "appscolumn.h" +#include +#include +#include + AppsColumn::AppsColumn(QWidget *parent) : QWidget(parent) { + setupUi(); +} + +void AppsColumn::setupUi() +{ + auto layout = new QVBoxLayout(); + layout->setMargin(0); + + // Header + auto headerLayout = new QHBoxLayout(); + layout->addLayout(headerLayout); + + m_labelTitle = new QLabel(); + { + QFont font; + font.setWeight(QFont::DemiBold); + m_labelTitle->setFont(font); + } + + headerLayout->addWidget(m_labelTitle); + headerLayout->addStretch(1); + + // Text Area + m_editText = new QPlainTextEdit(); + layout->addWidget(m_editText); + + this->setLayout(layout); } diff --git a/src/ui/form/opt/pages/apps/appscolumn.h b/src/ui/form/opt/pages/apps/appscolumn.h index 81705a89..f542e75c 100644 --- a/src/ui/form/opt/pages/apps/appscolumn.h +++ b/src/ui/form/opt/pages/apps/appscolumn.h @@ -3,6 +3,9 @@ #include +QT_FORWARD_DECLARE_CLASS(QLabel) +QT_FORWARD_DECLARE_CLASS(QPlainTextEdit) + class AppsColumn : public QWidget { Q_OBJECT @@ -10,6 +13,15 @@ class AppsColumn : public QWidget public: explicit AppsColumn(QWidget *parent = nullptr); + QLabel *labelTitle() const { return m_labelTitle; } + QPlainTextEdit *editText() const { return m_editText; } + +private: + void setupUi(); + +private: + QLabel *m_labelTitle = nullptr; + QPlainTextEdit *m_editText = nullptr; }; #endif // APPSCOLUMN_H