mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:38:16 +00:00
UI: Programs: Refactor Edit Dialog handling
This commit is contained in:
parent
670297afcc
commit
243b31bb0e
@ -3,6 +3,6 @@
|
||||
#include "programscontroller.h"
|
||||
|
||||
ProgramAlertWindow::ProgramAlertWindow(QWidget *parent) :
|
||||
ProgramEditDialog(new ProgramsController(this), parent)
|
||||
ProgramEditDialog(new ProgramsController(this), parent, Qt::Window)
|
||||
{
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
@ -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()) {
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user