UI: Programs: Refactor Edit Dialog handling

This commit is contained in:
Nodir Temirkhodjaev 2024-01-31 14:46:56 +03:00
parent 670297afcc
commit 243b31bb0e
7 changed files with 31 additions and 17 deletions

View File

@ -3,6 +3,6 @@
#include "programscontroller.h"
ProgramAlertWindow::ProgramAlertWindow(QWidget *parent) :
ProgramEditDialog(new ProgramsController(this), parent)
ProgramEditDialog(new ProgramsController(this), parent, Qt::Window)
{
}

View File

@ -42,8 +42,8 @@ enum ScheduleTimeType : qint8 {
ScheduleTimeAt,
};
ProgramEditDialog::ProgramEditDialog(ProgramsController *ctrl, QWidget *parent) :
WidgetWindow(parent), m_ctrl(ctrl)
ProgramEditDialog::ProgramEditDialog(ProgramsController *ctrl, QWidget *parent, Qt::WindowFlags f) :
WidgetWindow(parent, (f == Qt::Widget ? Qt::Dialog : f)), m_ctrl(ctrl)
{
setupUi();
setupController();

View File

@ -26,7 +26,8 @@ class ProgramEditDialog : public WidgetWindow
Q_OBJECT
public:
explicit ProgramEditDialog(ProgramsController *ctrl, QWidget *parent = nullptr);
explicit ProgramEditDialog(
ProgramsController *ctrl, QWidget *parent = nullptr, Qt::WindowFlags f = {});
ProgramsController *ctrl() const { return m_ctrl; }
FortManager *fortManager() const;

View File

@ -41,7 +41,6 @@ ProgramsWindow::ProgramsWindow(QWidget *parent) :
m_stateWatcher(new WidgetWindowStateWatcher(this))
{
setupUi();
setupAppEditForm();
setupController();
setupStateWatcher();
}
@ -382,17 +381,10 @@ void ProgramsWindow::setupTableAppsChanged()
connect(m_appListView, &TableView::currentIndexChanged, this, refreshTableAppsChanged);
}
void ProgramsWindow::setupAppEditForm()
{
m_formAppEdit = new ProgramEditDialog(ctrl(), this);
}
bool ProgramsWindow::editProgramByPath(const QString &appPath)
{
if (m_formAppEdit->isVisible()) {
m_formAppEdit->activate();
if (checkAppEditFormOpened())
return false;
}
const auto appRow = appListModel()->appRowByPath(appPath);
@ -450,9 +442,23 @@ void ProgramsWindow::editSelectedPrograms()
void ProgramsWindow::openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList)
{
if (!m_formAppEdit) {
m_formAppEdit = new ProgramEditDialog(ctrl(), this);
}
m_formAppEdit->initialize(appRow, appIdList);
m_formAppEdit->activate();
m_formAppEdit->centerTo(this);
}
bool ProgramsWindow::checkAppEditFormOpened() const
{
if (m_formAppEdit && m_formAppEdit->isVisible()) {
m_formAppEdit->activate();
return true;
}
return false;
}
void ProgramsWindow::updateSelectedApps(bool blocked, bool killProcess)

View File

@ -69,12 +69,12 @@ private:
void setupAppInfoRow();
void setupTableAppsChanged();
void setupAppEditForm();
void addNewProgram();
void addNewWildcard();
void editSelectedPrograms();
void openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList = {});
bool checkAppEditFormOpened() const;
void updateSelectedApps(bool blocked, bool killProcess = false);
void deleteSelectedApps();

View File

@ -2,7 +2,7 @@
#include <QWindowStateChangeEvent>
WidgetWindow::WidgetWindow(QWidget *parent) : QWidget(parent) { }
WidgetWindow::WidgetWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { }
void WidgetWindow::showWindow(bool activate)
{
@ -18,6 +18,11 @@ void WidgetWindow::exposeWindow()
exposeWidget(this);
}
void WidgetWindow::centerTo(QWidget *w)
{
this->move(w->frameGeometry().topLeft() + w->rect().center() - this->rect().center());
}
void WidgetWindow::showWidget(QWidget *w, bool activate)
{
if (w->isMinimized()) {

View File

@ -8,7 +8,7 @@ class WidgetWindow : public QWidget
Q_OBJECT
public:
explicit WidgetWindow(QWidget *parent = nullptr);
explicit WidgetWindow(QWidget *parent = nullptr, Qt::WindowFlags f = {});
virtual quint32 windowCode() const { return 0; }
virtual bool deleteOnClose() const { return true; }
@ -19,6 +19,8 @@ public:
void showWindow(bool activate = true);
void exposeWindow();
void centerTo(QWidget *w);
static void showWidget(QWidget *w, bool activate = true);
static void exposeWidget(QWidget *w);