Add DialogManager
This commit is contained in:
130
src/dialogs/DialogManager.cpp
Normal file
130
src/dialogs/DialogManager.cpp
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
//
|
||||||
|
// Created by Krad on 2022/7/19.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "DialogManager.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
#include "event/EventCenter.h"
|
||||||
|
#include "dialogs/GUIMessageDialog.h"
|
||||||
|
#include "appvals/AppGlobalValues.h"
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
||||||
|
if (!this->getTopWidget()->isVisible()) return;
|
||||||
|
//new dialog
|
||||||
|
auto dialog = new GUIMessageDialog(this->getTopWidget());
|
||||||
|
if (msg)
|
||||||
|
{
|
||||||
|
QString* str = (QString*)msg;
|
||||||
|
dialog->showMessage(*str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dialog->showMessage("Something went error!");
|
||||||
|
}
|
||||||
|
dialog->stopLoading();
|
||||||
|
dialog->showExitButton();
|
||||||
|
if (dialog->isHidden())
|
||||||
|
{
|
||||||
|
topWidgetStore.push(dialog);
|
||||||
|
dialog->setWindowModality(Qt::NonModal);
|
||||||
|
dialog->exec();
|
||||||
|
topWidgetStore.pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
||||||
|
if (mMessageDialog)
|
||||||
|
{
|
||||||
|
mMessageDialog->hide();
|
||||||
|
delete mMessageDialog;
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
if (!mMessageDialog) mMessageDialog = new GUIMessageDialog(this->getTopWidget());
|
||||||
|
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) {
|
||||||
|
if (!mMessageDialog) return;
|
||||||
|
if (!mMessageDialog->Pending())
|
||||||
|
{
|
||||||
|
mMessageDialog->startPending();
|
||||||
|
QVariant* var = (QVariant*)msg;
|
||||||
|
mMessageDialog->showMessage(var->toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
||||||
|
if (!mMessageDialog)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/dialogs/DialogManager.h
Normal file
39
src/dialogs/DialogManager.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
//
|
||||||
|
// Created by Krad on 2022/7/19.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef GUI_DIALOGMANAGER_H
|
||||||
|
#define GUI_DIALOGMANAGER_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStack>
|
||||||
|
|
||||||
|
class QWidget;
|
||||||
|
class QDialog;
|
||||||
|
class GUIMessageDialog;
|
||||||
|
|
||||||
|
class DialogManager:public QObject {
|
||||||
|
public:
|
||||||
|
static DialogManager *Default() {
|
||||||
|
static DialogManager manager;
|
||||||
|
return &manager;
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogManager() = default;
|
||||||
|
|
||||||
|
~DialogManager() override = default;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
QWidget* getTopWidget();
|
||||||
|
void raiseDeviceError(QObject* parent, QObject* msg);
|
||||||
|
void invokeOperationStart(QObject* parent, QObject* msg);
|
||||||
|
void invokeOperationProgress(QObject* parent, QObject* msg);
|
||||||
|
void invokeOperationPending(QObject* parent, QObject* msg);
|
||||||
|
void invokeOperationEnd(QObject* parent, QObject* msg);
|
||||||
|
private:
|
||||||
|
QDialog* mDialog = nullptr;
|
||||||
|
GUIMessageDialog* mMessageDialog = nullptr;
|
||||||
|
QStack<QDialog*> topWidgetStore;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //GUI_DIALOGMANAGER_H
|
||||||
17
src/main.cpp
17
src/main.cpp
@@ -11,6 +11,7 @@
|
|||||||
#include "log/UserOperationLog.h"
|
#include "log/UserOperationLog.h"
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
#include <src/device/DeviceManager.h>
|
#include <src/device/DeviceManager.h>
|
||||||
|
#include "dialogs/DialogManager.h"
|
||||||
#include "json/jsonobject.h"
|
#include "json/jsonobject.h"
|
||||||
#include "src/utilities/Locker.h"
|
#include "src/utilities/Locker.h"
|
||||||
#include "src/utilities/LanguageSwitcher.h"
|
#include "src/utilities/LanguageSwitcher.h"
|
||||||
@@ -60,6 +61,14 @@ int main(int argc, char* argv[])
|
|||||||
QFont font(fontName);
|
QFont font(fontName);
|
||||||
QApplication::setFont(font);
|
QApplication::setFont(font);
|
||||||
|
|
||||||
|
QFile file(":/stylesheet/Dark2.css");
|
||||||
|
file.open(QFile::ReadOnly);
|
||||||
|
if (file.isOpen())
|
||||||
|
{
|
||||||
|
a.setStyleSheet(QLatin1String(file.readAll()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
SQLHelper::Open();
|
SQLHelper::Open();
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
UserOperationLog::Default()->init();
|
UserOperationLog::Default()->init();
|
||||||
@@ -93,10 +102,11 @@ int main(int argc, char* argv[])
|
|||||||
Timer.start(1000);
|
Timer.start(1000);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
|
|
||||||
DeviceManager::Default()->initDevice();
|
|
||||||
w.requestLogin();
|
w.requestLogin();
|
||||||
|
|
||||||
|
DialogManager::Default()->init();
|
||||||
|
DeviceManager::Default()->initDevice();
|
||||||
|
|
||||||
ret = a.exec();
|
ret = a.exec();
|
||||||
thread.terminate();
|
thread.terminate();
|
||||||
|
|
||||||
@@ -104,8 +114,9 @@ int main(int argc, char* argv[])
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
w.showFullScreen();
|
w.showFullScreen();
|
||||||
DeviceManager::Default()->initDevice();
|
|
||||||
w.requestLogin();
|
w.requestLogin();
|
||||||
|
DialogManager::Default()->init();
|
||||||
|
DeviceManager::Default()->initDevice();
|
||||||
ret = a.exec();
|
ret = a.exec();
|
||||||
}
|
}
|
||||||
DeviceManager::Default()->close();
|
DeviceManager::Default()->close();
|
||||||
|
|||||||
@@ -35,115 +35,11 @@ MainWindow::MainWindow(QWidget* aParent)
|
|||||||
, mIsDebugMode(false)
|
, mIsDebugMode(false)
|
||||||
{
|
{
|
||||||
mUI->setupUi(this);
|
mUI->setupUi(this);
|
||||||
this->loadStyleSheet("Dark2");
|
|
||||||
this->setWindowFlags(Qt::Window);
|
this->setWindowFlags(Qt::Window);
|
||||||
|
|
||||||
initializeTabWidget();
|
initializeTabWidget();
|
||||||
initializeLayout();
|
initializeLayout();
|
||||||
|
|
||||||
|
|
||||||
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise, [=](QObject* parent, QObject* msg) {
|
|
||||||
if (!this->isVisible()) return;
|
|
||||||
//默认旧模式
|
|
||||||
if (!mMessageDialog)
|
|
||||||
{
|
|
||||||
mMessageDialog = new GUIMessageDialog(this);
|
|
||||||
}
|
|
||||||
if (msg)
|
|
||||||
{
|
|
||||||
QString* str = (QString*)msg;
|
|
||||||
mMessageDialog->showMessage(*str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMessageDialog->showMessage("Something went error!");
|
|
||||||
}
|
|
||||||
mMessageDialog->stopLoading();
|
|
||||||
mMessageDialog->showExitButton();
|
|
||||||
if (mMessageDialog->isHidden())
|
|
||||||
{
|
|
||||||
mMessageDialog->setWindowModality(Qt::NonModal);
|
|
||||||
mMessageDialog->exec();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(EventCenter::Default(), &EventCenter::InvokeOperationStart, [=](QObject*, QObject* msg) {
|
|
||||||
if (mMessageDialog)
|
|
||||||
{
|
|
||||||
mMessageDialog->hide();
|
|
||||||
delete mMessageDialog;
|
|
||||||
}
|
|
||||||
mMessageDialog = new GUIMessageDialog(this);
|
|
||||||
if (msg)
|
|
||||||
{
|
|
||||||
QString* str = (QString*)msg;
|
|
||||||
mMessageDialog->showMessage(*str);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMessageDialog->hideMessage();
|
|
||||||
}
|
|
||||||
mMessageDialog->hideExitButton();
|
|
||||||
mMessageDialog->startLoading();
|
|
||||||
AppGlobalValues::setInProcessing(true);
|
|
||||||
// msgDialog->showFullScreen();
|
|
||||||
if (mMessageDialog->isHidden())
|
|
||||||
{
|
|
||||||
mMessageDialog->show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(EventCenter::Default(), &EventCenter::InvokeOperationProgress, [=](QObject*, QObject* msg) {
|
|
||||||
if (!mMessageDialog) mMessageDialog = new GUIMessageDialog(this);
|
|
||||||
if (msg)
|
|
||||||
{
|
|
||||||
QVariant* var = (QVariant*)msg;
|
|
||||||
if (mMessageDialog->Pending())
|
|
||||||
{
|
|
||||||
mMessageDialog->stopPending();
|
|
||||||
}
|
|
||||||
mMessageDialog->showMessage(var->toString());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mMessageDialog->hideMessage();
|
|
||||||
}
|
|
||||||
if (mMessageDialog->isHidden())
|
|
||||||
{
|
|
||||||
mMessageDialog->show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(EventCenter::Default(), &EventCenter::InvokeOperationPending, [=](QObject*, QObject* msg) {
|
|
||||||
if (!mMessageDialog) return;
|
|
||||||
if (!mMessageDialog->Pending())
|
|
||||||
{
|
|
||||||
mMessageDialog->startPending();
|
|
||||||
QVariant* var = (QVariant*)msg;
|
|
||||||
mMessageDialog->showMessage(var->toString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(EventCenter::Default(), &EventCenter::InvokeOperationEnd, [=](QObject*, QObject* v) {
|
|
||||||
if (!mMessageDialog)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!mMessageDialog->isHidden())
|
|
||||||
{
|
|
||||||
if (v && ((QVariant*)v)->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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
connect(EventCenter::Default(), &EventCenter::PatientSelected, this,&MainWindow::switchToScanTab);
|
||||||
connect(EventCenter::Default(), &EventCenter::RequestLogin, this,&MainWindow::requestLogin);
|
connect(EventCenter::Default(), &EventCenter::RequestLogin, this,&MainWindow::requestLogin);
|
||||||
connect(EventCenter::Default(), &EventCenter::LoginRoleChanged, this,&MainWindow::resetRoleLayout);
|
connect(EventCenter::Default(), &EventCenter::LoginRoleChanged, this,&MainWindow::resetRoleLayout);
|
||||||
@@ -182,14 +78,14 @@ MainWindow::~MainWindow()
|
|||||||
|
|
||||||
void MainWindow::loadStyleSheet(const QString& aSheetName)
|
void MainWindow::loadStyleSheet(const QString& aSheetName)
|
||||||
{
|
{
|
||||||
QFile file(":/stylesheet/" + aSheetName + ".css");
|
// QFile file(":/stylesheet/" + aSheetName + ".css");
|
||||||
file.open(QFile::ReadOnly);
|
// file.open(QFile::ReadOnly);
|
||||||
if (file.isOpen())
|
// if (file.isOpen())
|
||||||
{
|
// {
|
||||||
QString styleSheet = this->styleSheet();
|
// QString styleSheet = this->styleSheet();
|
||||||
styleSheet += QLatin1String(file.readAll());
|
// styleSheet += QLatin1String(file.readAll());
|
||||||
this->setStyleSheet(styleSheet);
|
// this->setStyleSheet(styleSheet);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initializeLayout()
|
void MainWindow::initializeLayout()
|
||||||
@@ -374,12 +270,14 @@ void MainWindow::requestLogin()
|
|||||||
mLoginDialog->setWindowModality(Qt::WindowModal);
|
mLoginDialog->setWindowModality(Qt::WindowModal);
|
||||||
mLoginDialog->showFullScreen();
|
mLoginDialog->showFullScreen();
|
||||||
centerWidgetHide();
|
centerWidgetHide();
|
||||||
|
QApplication::setActiveWindow(mLoginDialog);
|
||||||
while (QDialog::Accepted != mLoginDialog->result())
|
while (QDialog::Accepted != mLoginDialog->result())
|
||||||
{
|
{
|
||||||
mLoginDialog->exec();
|
mLoginDialog->exec();
|
||||||
}
|
}
|
||||||
mLoginDialog->setResult(QDialog::Rejected);
|
mLoginDialog->setResult(QDialog::Rejected);
|
||||||
centerWidgetShow();
|
centerWidgetShow();
|
||||||
|
QApplication::setActiveWindow(centralWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::resetRoleLayout() {
|
void MainWindow::resetRoleLayout() {
|
||||||
|
|||||||
Reference in New Issue
Block a user