2022-07-19 14:15:00 +08:00
|
|
|
|
//
|
|
|
|
|
|
// Created by Krad on 2022/7/19.
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
#include "DialogManager.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
#include <QWidget>
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include <QThread>
|
2022-07-19 14:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
#include "event/EventCenter.h"
|
|
|
|
|
|
#include "dialogs/GUIMessageDialog.h"
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include "dialogs/ChangePasswordFormDialog.h"
|
|
|
|
|
|
#include "dialogs/AccountFormDialog.h"
|
2022-07-19 14:15:00 +08:00
|
|
|
|
#include "appvals/AppGlobalValues.h"
|
2022-07-20 16:45:33 +08:00
|
|
|
|
#include "windows/LoginDialog.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DialogManager::DialogManager()
|
|
|
|
|
|
: QObject()
|
|
|
|
|
|
, mFunctionDialog(nullptr)
|
|
|
|
|
|
, mMessageDialog(nullptr)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-07-19 14:15:00 +08:00
|
|
|
|
|
|
|
|
|
|
void DialogManager::init() {
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationStart,this,&DialogManager::invokeOperationStart);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationProgress,this,&DialogManager::invokeOperationProgress);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationPending,this,&DialogManager::invokeOperationPending);
|
|
|
|
|
|
connect(EventCenter::Default(), &EventCenter::InvokeOperationEnd,this,&DialogManager::invokeOperationEnd);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QWidget *DialogManager::getTopWidget() {
|
|
|
|
|
|
if (!topWidgetStore.isEmpty()) return topWidgetStore.top();
|
|
|
|
|
|
return QApplication::activeWindow();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
void DialogManager::requestLogin()
|
|
|
|
|
|
{
|
|
|
|
|
|
//Login 直接最顶层模态
|
|
|
|
|
|
if (!mFunctionDialog){
|
|
|
|
|
|
mFunctionDialog = new LoginDialog;
|
|
|
|
|
|
}
|
|
|
|
|
|
mFunctionDialog->exec();
|
|
|
|
|
|
while (QDialog::Accepted != mFunctionDialog->result())
|
|
|
|
|
|
{
|
|
|
|
|
|
mFunctionDialog->exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestAddAccount(QSqlTableModel* model) {
|
|
|
|
|
|
AccountFormDialog dialog(getTopWidget(), New);
|
|
|
|
|
|
topWidgetStore.push(&dialog);
|
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
dialog.setReferenceModel(model);
|
|
|
|
|
|
int ret = dialog.exec();
|
|
|
|
|
|
topWidgetStore.pop();
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestEditSelfAccount() {
|
|
|
|
|
|
AccountFormDialog dialog(getTopWidget(), Self);
|
|
|
|
|
|
topWidgetStore.push(&dialog);
|
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
int ret = dialog.exec();
|
|
|
|
|
|
topWidgetStore.pop();
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int DialogManager::requestEditAdminAccount(const QMap<QString, QVariant>& values) {
|
|
|
|
|
|
AccountFormDialog dialog(getTopWidget(), Admin);
|
|
|
|
|
|
topWidgetStore.push(&dialog);
|
|
|
|
|
|
dialog.setAccountInformation(values);
|
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
int ret = dialog.exec();
|
|
|
|
|
|
topWidgetStore.pop();
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::requestChangePassword() {
|
|
|
|
|
|
ChangePasswordFormDialog dialog(getTopWidget());
|
|
|
|
|
|
topWidgetStore.push(&dialog);
|
|
|
|
|
|
dialog.setGeometry(getTopWidget()->geometry());
|
|
|
|
|
|
dialog.setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
dialog.exec();
|
|
|
|
|
|
topWidgetStore.pop();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//考虑以后使用另外的dialog显示错误
|
2022-07-19 14:15:00 +08:00
|
|
|
|
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
|
|
|
|
|
if (!this->getTopWidget()->isVisible()) return;
|
2022-07-20 16:45:33 +08:00
|
|
|
|
clearMessageDialog();
|
2022-07-19 14:15:00 +08:00
|
|
|
|
//new dialog
|
|
|
|
|
|
auto dialog = new GUIMessageDialog(this->getTopWidget());
|
2022-07-20 16:45:33 +08:00
|
|
|
|
if (msg) {
|
|
|
|
|
|
QString *str = (QString *) msg;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
dialog->showMessage(*str);
|
2022-07-20 16:45:33 +08:00
|
|
|
|
} else {
|
2022-07-19 14:15:00 +08:00
|
|
|
|
dialog->showMessage("Something went error!");
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog->stopLoading();
|
|
|
|
|
|
dialog->showExitButton();
|
2022-07-20 16:45:33 +08:00
|
|
|
|
topWidgetStore.push(dialog);
|
|
|
|
|
|
dialog->setWindowModality(Qt::NonModal);
|
|
|
|
|
|
dialog->exec();
|
|
|
|
|
|
auto lastDialog = topWidgetStore.pop();
|
|
|
|
|
|
lastDialog->deleteLater();
|
2022-07-19 14:15:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-20 16:45:33 +08:00
|
|
|
|
// 扫描过程 dialog 只能为最底层,并且会被error dialog 清除!
|
2022-07-19 14:15:00 +08:00
|
|
|
|
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//没有目标parent 撤销操作
|
|
|
|
|
|
if (!QApplication::activeWindow()) return;
|
|
|
|
|
|
//只能在最底层窗口上模态
|
|
|
|
|
|
if (!topWidgetStore.isEmpty()) return;
|
|
|
|
|
|
clearMessageDialog();
|
2022-07-19 14:15:00 +08:00
|
|
|
|
mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
|
|
|
|
|
if (msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
QString* str = (QString*)msg;
|
|
|
|
|
|
mMessageDialog->showMessage(*str);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->hideMessage();
|
|
|
|
|
|
}
|
|
|
|
|
|
mMessageDialog->hideExitButton();
|
|
|
|
|
|
mMessageDialog->startLoading();
|
|
|
|
|
|
AppGlobalValues::setInProcessing(true);
|
|
|
|
|
|
if (mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->open();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
|
|
|
|
|
if (!mMessageDialog) return;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (msg)
|
|
|
|
|
|
{
|
|
|
|
|
|
QVariant* var = (QVariant*)msg;
|
|
|
|
|
|
if (mMessageDialog->Pending())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->stopPending();
|
|
|
|
|
|
}
|
|
|
|
|
|
mMessageDialog->showMessage(var->toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->hideMessage();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (!mMessageDialog) return;
|
|
|
|
|
|
if (!mMessageDialog->Pending())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->startPending();
|
|
|
|
|
|
QVariant* var = (QVariant*)msg;
|
|
|
|
|
|
mMessageDialog->showMessage(var->toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
2022-07-20 16:45:33 +08:00
|
|
|
|
//窗口不存在,撤销操作
|
|
|
|
|
|
if (!mMessageDialog) return;
|
2022-07-19 14:15:00 +08:00
|
|
|
|
if (!mMessageDialog->isHidden())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (msg && ((QVariant*)msg)->toBool())
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->stopLoading();
|
|
|
|
|
|
mMessageDialog->showMessage("Scan completed!");
|
|
|
|
|
|
mMessageDialog->showExitButton();
|
|
|
|
|
|
mMessageDialog->setWindowModality(Qt::WindowModal);
|
|
|
|
|
|
mMessageDialog->exec();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
mMessageDialog->accept();
|
|
|
|
|
|
}
|
|
|
|
|
|
delete mMessageDialog;
|
|
|
|
|
|
mMessageDialog = nullptr;
|
|
|
|
|
|
AppGlobalValues::setInProcessing(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-07-20 16:45:33 +08:00
|
|
|
|
|
|
|
|
|
|
void DialogManager::clearMessageDialog() {
|
|
|
|
|
|
if (mMessageDialog){
|
|
|
|
|
|
if (!mMessageDialog->isHidden()) mMessageDialog->hide();
|
|
|
|
|
|
delete mMessageDialog;
|
|
|
|
|
|
mMessageDialog = nullptr;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DialogManager::~DialogManager() {
|
|
|
|
|
|
clearMessageDialog();
|
|
|
|
|
|
}
|