mirror of
https://github.com/tnodir/fort
synced 2024-11-15 11:35:07 +00:00
UI: Programs: Refactor Edit Dialog handling
This commit is contained in:
parent
670297afcc
commit
243b31bb0e
@ -3,6 +3,6 @@
|
|||||||
#include "programscontroller.h"
|
#include "programscontroller.h"
|
||||||
|
|
||||||
ProgramAlertWindow::ProgramAlertWindow(QWidget *parent) :
|
ProgramAlertWindow::ProgramAlertWindow(QWidget *parent) :
|
||||||
ProgramEditDialog(new ProgramsController(this), parent)
|
ProgramEditDialog(new ProgramsController(this), parent, Qt::Window)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ enum ScheduleTimeType : qint8 {
|
|||||||
ScheduleTimeAt,
|
ScheduleTimeAt,
|
||||||
};
|
};
|
||||||
|
|
||||||
ProgramEditDialog::ProgramEditDialog(ProgramsController *ctrl, QWidget *parent) :
|
ProgramEditDialog::ProgramEditDialog(ProgramsController *ctrl, QWidget *parent, Qt::WindowFlags f) :
|
||||||
WidgetWindow(parent), m_ctrl(ctrl)
|
WidgetWindow(parent, (f == Qt::Widget ? Qt::Dialog : f)), m_ctrl(ctrl)
|
||||||
{
|
{
|
||||||
setupUi();
|
setupUi();
|
||||||
setupController();
|
setupController();
|
||||||
|
@ -26,7 +26,8 @@ class ProgramEditDialog : public WidgetWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ProgramEditDialog(ProgramsController *ctrl, QWidget *parent = nullptr);
|
explicit ProgramEditDialog(
|
||||||
|
ProgramsController *ctrl, QWidget *parent = nullptr, Qt::WindowFlags f = {});
|
||||||
|
|
||||||
ProgramsController *ctrl() const { return m_ctrl; }
|
ProgramsController *ctrl() const { return m_ctrl; }
|
||||||
FortManager *fortManager() const;
|
FortManager *fortManager() const;
|
||||||
|
@ -41,7 +41,6 @@ ProgramsWindow::ProgramsWindow(QWidget *parent) :
|
|||||||
m_stateWatcher(new WidgetWindowStateWatcher(this))
|
m_stateWatcher(new WidgetWindowStateWatcher(this))
|
||||||
{
|
{
|
||||||
setupUi();
|
setupUi();
|
||||||
setupAppEditForm();
|
|
||||||
setupController();
|
setupController();
|
||||||
setupStateWatcher();
|
setupStateWatcher();
|
||||||
}
|
}
|
||||||
@ -382,17 +381,10 @@ void ProgramsWindow::setupTableAppsChanged()
|
|||||||
connect(m_appListView, &TableView::currentIndexChanged, this, refreshTableAppsChanged);
|
connect(m_appListView, &TableView::currentIndexChanged, this, refreshTableAppsChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramsWindow::setupAppEditForm()
|
|
||||||
{
|
|
||||||
m_formAppEdit = new ProgramEditDialog(ctrl(), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgramsWindow::editProgramByPath(const QString &appPath)
|
bool ProgramsWindow::editProgramByPath(const QString &appPath)
|
||||||
{
|
{
|
||||||
if (m_formAppEdit->isVisible()) {
|
if (checkAppEditFormOpened())
|
||||||
m_formAppEdit->activate();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
const auto appRow = appListModel()->appRowByPath(appPath);
|
const auto appRow = appListModel()->appRowByPath(appPath);
|
||||||
|
|
||||||
@ -450,9 +442,23 @@ void ProgramsWindow::editSelectedPrograms()
|
|||||||
|
|
||||||
void ProgramsWindow::openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList)
|
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->initialize(appRow, appIdList);
|
||||||
|
|
||||||
m_formAppEdit->activate();
|
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)
|
void ProgramsWindow::updateSelectedApps(bool blocked, bool killProcess)
|
||||||
|
@ -69,12 +69,12 @@ private:
|
|||||||
void setupAppInfoRow();
|
void setupAppInfoRow();
|
||||||
void setupTableAppsChanged();
|
void setupTableAppsChanged();
|
||||||
|
|
||||||
void setupAppEditForm();
|
|
||||||
|
|
||||||
void addNewProgram();
|
void addNewProgram();
|
||||||
void addNewWildcard();
|
void addNewWildcard();
|
||||||
void editSelectedPrograms();
|
void editSelectedPrograms();
|
||||||
|
|
||||||
void openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList = {});
|
void openAppEditForm(const AppRow &appRow, const QVector<qint64> &appIdList = {});
|
||||||
|
bool checkAppEditFormOpened() const;
|
||||||
|
|
||||||
void updateSelectedApps(bool blocked, bool killProcess = false);
|
void updateSelectedApps(bool blocked, bool killProcess = false);
|
||||||
void deleteSelectedApps();
|
void deleteSelectedApps();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <QWindowStateChangeEvent>
|
#include <QWindowStateChangeEvent>
|
||||||
|
|
||||||
WidgetWindow::WidgetWindow(QWidget *parent) : QWidget(parent) { }
|
WidgetWindow::WidgetWindow(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { }
|
||||||
|
|
||||||
void WidgetWindow::showWindow(bool activate)
|
void WidgetWindow::showWindow(bool activate)
|
||||||
{
|
{
|
||||||
@ -18,6 +18,11 @@ void WidgetWindow::exposeWindow()
|
|||||||
exposeWidget(this);
|
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)
|
void WidgetWindow::showWidget(QWidget *w, bool activate)
|
||||||
{
|
{
|
||||||
if (w->isMinimized()) {
|
if (w->isMinimized()) {
|
||||||
|
@ -8,7 +8,7 @@ class WidgetWindow : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WidgetWindow(QWidget *parent = nullptr);
|
explicit WidgetWindow(QWidget *parent = nullptr, Qt::WindowFlags f = {});
|
||||||
|
|
||||||
virtual quint32 windowCode() const { return 0; }
|
virtual quint32 windowCode() const { return 0; }
|
||||||
virtual bool deleteOnClose() const { return true; }
|
virtual bool deleteOnClose() const { return true; }
|
||||||
@ -19,6 +19,8 @@ public:
|
|||||||
void showWindow(bool activate = true);
|
void showWindow(bool activate = true);
|
||||||
void exposeWindow();
|
void exposeWindow();
|
||||||
|
|
||||||
|
void centerTo(QWidget *w);
|
||||||
|
|
||||||
static void showWidget(QWidget *w, bool activate = true);
|
static void showWidget(QWidget *w, bool activate = true);
|
||||||
static void exposeWidget(QWidget *w);
|
static void exposeWidget(QWidget *w);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user