diff --git a/src/ui/FortFirewallUI.pro b/src/ui/FortFirewallUI.pro index 16031a69..46620ce4 100644 --- a/src/ui/FortFirewallUI.pro +++ b/src/ui/FortFirewallUI.pro @@ -41,6 +41,7 @@ SOURCES += \ form/controls/tableview.cpp \ form/controls/textarea2splitter.cpp \ form/controls/textarea2splitterhandle.cpp \ + form/dialog/dialogutil.cpp \ form/dialog/passworddialog.cpp \ form/graph/axistickerspeed.cpp \ form/graph/graphplot.cpp \ @@ -192,6 +193,7 @@ HEADERS += \ form/controls/tableview.h \ form/controls/textarea2splitter.h \ form/controls/textarea2splitterhandle.h \ + form/dialog/dialogutil.h \ form/dialog/passworddialog.h \ form/graph/axistickerspeed.h \ form/graph/graphplot.h \ diff --git a/src/ui/form/controls/controlutil.cpp b/src/ui/form/controls/controlutil.cpp index e3524a38..f3082b8b 100644 --- a/src/ui/form/controls/controlutil.cpp +++ b/src/ui/form/controls/controlutil.cpp @@ -2,9 +2,7 @@ #include #include -#include #include -#include #include #include #include @@ -206,26 +204,3 @@ QFont ControlUtil::fontDemiBold() font.setWeight(QFont::DemiBold); return font; } - -QString ControlUtil::getOpenFileName(const QString &title, const QString &filter) -{ - return QFileDialog::getOpenFileName( - nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); -} - -QStringList ControlUtil::getOpenFileNames(const QString &title, const QString &filter) -{ - return QFileDialog::getOpenFileNames( - nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); -} - -QString ControlUtil::getSaveFileName(const QString &title, const QString &filter) -{ - return QFileDialog::getSaveFileName( - nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); -} - -QColor ControlUtil::getColor(const QColor &initial, const QString &title) -{ - return QColorDialog::getColor(initial, nullptr, title); -} diff --git a/src/ui/form/controls/controlutil.h b/src/ui/form/controls/controlutil.h index e07685a9..e9220948 100644 --- a/src/ui/form/controls/controlutil.h +++ b/src/ui/form/controls/controlutil.h @@ -1,7 +1,6 @@ #ifndef CONTROLUTIL_H #define CONTROLUTIL_H -#include #include #include @@ -50,15 +49,6 @@ public: static QWidget *wrapToScrollArea(QWidget *content, bool isBgTransparent = true); static QFont fontDemiBold(); - - static QString getOpenFileName( - const QString &title = QString(), const QString &filter = QString()); - static QStringList getOpenFileNames( - const QString &title = QString(), const QString &filter = QString()); - static QString getSaveFileName( - const QString &title = QString(), const QString &filter = QString()); - - static QColor getColor(const QColor &initial = Qt::white, const QString &title = QString()); }; #endif // CONTROLUTIL_H diff --git a/src/ui/form/controls/labelcolor.cpp b/src/ui/form/controls/labelcolor.cpp index 3b9788f0..80c56785 100644 --- a/src/ui/form/controls/labelcolor.cpp +++ b/src/ui/form/controls/labelcolor.cpp @@ -4,6 +4,7 @@ #include #include +#include "../dialog/dialogutil.h" #include "controlutil.h" LabelColor::LabelColor(QWidget *parent) : QWidget(parent) @@ -22,7 +23,7 @@ void LabelColor::setColor(const QColor &v) void LabelColor::selectColor() { const auto title = tr("Select color for %1").arg(label()->text()); - const auto selectedColor = ControlUtil::getColor(color(), title); + const auto selectedColor = DialogUtil::getColor(color(), title); if (selectedColor.isValid()) { setColor(selectedColor); } diff --git a/src/ui/form/dialog/dialogutil.cpp b/src/ui/form/dialog/dialogutil.cpp new file mode 100644 index 00000000..cf207e12 --- /dev/null +++ b/src/ui/form/dialog/dialogutil.cpp @@ -0,0 +1,27 @@ +#include "dialogutil.h" + +#include +#include + +QString DialogUtil::getOpenFileName(const QString &title, const QString &filter) +{ + return QFileDialog::getOpenFileName( + nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); +} + +QStringList DialogUtil::getOpenFileNames(const QString &title, const QString &filter) +{ + return QFileDialog::getOpenFileNames( + nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); +} + +QString DialogUtil::getSaveFileName(const QString &title, const QString &filter) +{ + return QFileDialog::getSaveFileName( + nullptr, title, QString(), filter, nullptr, QFileDialog::ReadOnly); +} + +QColor DialogUtil::getColor(const QColor &initial, const QString &title) +{ + return QColorDialog::getColor(initial, nullptr, title); +} diff --git a/src/ui/form/dialog/dialogutil.h b/src/ui/form/dialog/dialogutil.h new file mode 100644 index 00000000..e0358464 --- /dev/null +++ b/src/ui/form/dialog/dialogutil.h @@ -0,0 +1,20 @@ +#ifndef DIALOGUTIL_H +#define DIALOGUTIL_H + +#include +#include + +class DialogUtil +{ +public: + static QString getOpenFileName( + const QString &title = QString(), const QString &filter = QString()); + static QStringList getOpenFileNames( + const QString &title = QString(), const QString &filter = QString()); + static QString getSaveFileName( + const QString &title = QString(), const QString &filter = QString()); + + static QColor getColor(const QColor &initial = Qt::white, const QString &title = QString()); +}; + +#endif // DIALOGUTIL_H diff --git a/src/ui/form/opt/pages/applicationspage.cpp b/src/ui/form/opt/pages/applicationspage.cpp index 8191fe67..6de577ae 100644 --- a/src/ui/form/opt/pages/applicationspage.cpp +++ b/src/ui/form/opt/pages/applicationspage.cpp @@ -25,6 +25,7 @@ #include "../../controls/tabbar.h" #include "../../controls/textarea2splitter.h" #include "../../controls/textarea2splitterhandle.h" +#include "../../dialog/dialogutil.h" #include "../optionscontroller.h" #include "apps/appscolumn.h" @@ -532,7 +533,7 @@ void ApplicationsPage::setupSplitter() void ApplicationsPage::setupSplitterButtons() { m_btSelectFile = ControlUtil::createSplitterButton(":/icons/folder-open.png", [&] { - const auto filePaths = ControlUtil::getOpenFileNames( + const auto filePaths = DialogUtil::getOpenFileNames( m_btSelectFile->text(), tr("Programs (*.exe);;All files (*.*)")); if (!filePaths.isEmpty()) { diff --git a/src/ui/form/prog/programeditdialog.cpp b/src/ui/form/prog/programeditdialog.cpp index 4c9dfa90..31466968 100644 --- a/src/ui/form/prog/programeditdialog.cpp +++ b/src/ui/form/prog/programeditdialog.cpp @@ -19,6 +19,7 @@ #include "../../util/ioc/ioccontainer.h" #include "../controls/checkspincombo.h" #include "../controls/controlutil.h" +#include "../dialog/dialogutil.h" #include "programscontroller.h" namespace { @@ -236,7 +237,7 @@ QLayout *ProgramEditDialog::setupAppPathLayout() m_editPath->setMaxLength(1024); m_btSelectFile = ControlUtil::createFlatButton(":/icons/folder-open.png", [&] { - const auto filePath = ControlUtil::getOpenFileName( + const auto filePath = DialogUtil::getOpenFileName( m_labelEditPath->text(), tr("Programs (*.exe);;All files (*.*)")); if (!filePath.isEmpty()) { diff --git a/src/ui/form/zone/zoneswindow.cpp b/src/ui/form/zone/zoneswindow.cpp index f1a512d7..95d45385 100644 --- a/src/ui/form/zone/zoneswindow.cpp +++ b/src/ui/form/zone/zoneswindow.cpp @@ -26,6 +26,7 @@ #include "../../util/window/widgetwindowstatewatcher.h" #include "../controls/controlutil.h" #include "../controls/tableview.h" +#include "../dialog/dialogutil.h" #include "zonescontroller.h" namespace { @@ -297,7 +298,7 @@ QLayout *ZonesWindow::setupHeader() // Save As Text m_btSaveAsText = ControlUtil::createButton(":/icons/floppy.png", [&] { - const auto filePath = ControlUtil::getSaveFileName( + const auto filePath = DialogUtil::getSaveFileName( m_btSaveAsText->text(), tr("Text files (*.txt);;All files (*.*)")); if (!filePath.isEmpty()) {