UI: ControlUtil: Extract dialog functions to DialogUtil.

This commit is contained in:
Nodir Temirkhodjaev 2021-08-07 12:13:49 +03:00
parent 96beea0f08
commit 8e5c236293
9 changed files with 57 additions and 39 deletions

View File

@ -41,6 +41,7 @@ SOURCES += \
form/controls/tableview.cpp \ form/controls/tableview.cpp \
form/controls/textarea2splitter.cpp \ form/controls/textarea2splitter.cpp \
form/controls/textarea2splitterhandle.cpp \ form/controls/textarea2splitterhandle.cpp \
form/dialog/dialogutil.cpp \
form/dialog/passworddialog.cpp \ form/dialog/passworddialog.cpp \
form/graph/axistickerspeed.cpp \ form/graph/axistickerspeed.cpp \
form/graph/graphplot.cpp \ form/graph/graphplot.cpp \
@ -192,6 +193,7 @@ HEADERS += \
form/controls/tableview.h \ form/controls/tableview.h \
form/controls/textarea2splitter.h \ form/controls/textarea2splitter.h \
form/controls/textarea2splitterhandle.h \ form/controls/textarea2splitterhandle.h \
form/dialog/dialogutil.h \
form/dialog/passworddialog.h \ form/dialog/passworddialog.h \
form/graph/axistickerspeed.h \ form/graph/axistickerspeed.h \
form/graph/graphplot.h \ form/graph/graphplot.h \

View File

@ -2,9 +2,7 @@
#include <QBoxLayout> #include <QBoxLayout>
#include <QCheckBox> #include <QCheckBox>
#include <QColorDialog>
#include <QComboBox> #include <QComboBox>
#include <QFileDialog>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QMenu> #include <QMenu>
@ -206,26 +204,3 @@ QFont ControlUtil::fontDemiBold()
font.setWeight(QFont::DemiBold); font.setWeight(QFont::DemiBold);
return font; 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);
}

View File

@ -1,7 +1,6 @@
#ifndef CONTROLUTIL_H #ifndef CONTROLUTIL_H
#define CONTROLUTIL_H #define CONTROLUTIL_H
#include <QColor>
#include <QObject> #include <QObject>
#include <functional> #include <functional>
@ -50,15 +49,6 @@ public:
static QWidget *wrapToScrollArea(QWidget *content, bool isBgTransparent = true); static QWidget *wrapToScrollArea(QWidget *content, bool isBgTransparent = true);
static QFont fontDemiBold(); 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 #endif // CONTROLUTIL_H

View File

@ -4,6 +4,7 @@
#include <QLabel> #include <QLabel>
#include <QPushButton> #include <QPushButton>
#include "../dialog/dialogutil.h"
#include "controlutil.h" #include "controlutil.h"
LabelColor::LabelColor(QWidget *parent) : QWidget(parent) LabelColor::LabelColor(QWidget *parent) : QWidget(parent)
@ -22,7 +23,7 @@ void LabelColor::setColor(const QColor &v)
void LabelColor::selectColor() void LabelColor::selectColor()
{ {
const auto title = tr("Select color for %1").arg(label()->text()); 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()) { if (selectedColor.isValid()) {
setColor(selectedColor); setColor(selectedColor);
} }

View File

@ -0,0 +1,27 @@
#include "dialogutil.h"
#include <QColorDialog>
#include <QFileDialog>
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);
}

View File

@ -0,0 +1,20 @@
#ifndef DIALOGUTIL_H
#define DIALOGUTIL_H
#include <QColor>
#include <QObject>
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

View File

@ -25,6 +25,7 @@
#include "../../controls/tabbar.h" #include "../../controls/tabbar.h"
#include "../../controls/textarea2splitter.h" #include "../../controls/textarea2splitter.h"
#include "../../controls/textarea2splitterhandle.h" #include "../../controls/textarea2splitterhandle.h"
#include "../../dialog/dialogutil.h"
#include "../optionscontroller.h" #include "../optionscontroller.h"
#include "apps/appscolumn.h" #include "apps/appscolumn.h"
@ -532,7 +533,7 @@ void ApplicationsPage::setupSplitter()
void ApplicationsPage::setupSplitterButtons() void ApplicationsPage::setupSplitterButtons()
{ {
m_btSelectFile = ControlUtil::createSplitterButton(":/icons/folder-open.png", [&] { 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 (*.*)")); m_btSelectFile->text(), tr("Programs (*.exe);;All files (*.*)"));
if (!filePaths.isEmpty()) { if (!filePaths.isEmpty()) {

View File

@ -19,6 +19,7 @@
#include "../../util/ioc/ioccontainer.h" #include "../../util/ioc/ioccontainer.h"
#include "../controls/checkspincombo.h" #include "../controls/checkspincombo.h"
#include "../controls/controlutil.h" #include "../controls/controlutil.h"
#include "../dialog/dialogutil.h"
#include "programscontroller.h" #include "programscontroller.h"
namespace { namespace {
@ -236,7 +237,7 @@ QLayout *ProgramEditDialog::setupAppPathLayout()
m_editPath->setMaxLength(1024); m_editPath->setMaxLength(1024);
m_btSelectFile = ControlUtil::createFlatButton(":/icons/folder-open.png", [&] { 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 (*.*)")); m_labelEditPath->text(), tr("Programs (*.exe);;All files (*.*)"));
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {

View File

@ -26,6 +26,7 @@
#include "../../util/window/widgetwindowstatewatcher.h" #include "../../util/window/widgetwindowstatewatcher.h"
#include "../controls/controlutil.h" #include "../controls/controlutil.h"
#include "../controls/tableview.h" #include "../controls/tableview.h"
#include "../dialog/dialogutil.h"
#include "zonescontroller.h" #include "zonescontroller.h"
namespace { namespace {
@ -297,7 +298,7 @@ QLayout *ZonesWindow::setupHeader()
// Save As Text // Save As Text
m_btSaveAsText = ControlUtil::createButton(":/icons/floppy.png", [&] { 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 (*.*)")); m_btSaveAsText->text(), tr("Text files (*.txt);;All files (*.*)"));
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {