482 lines
14 KiB
C++
482 lines
14 KiB
C++
//
|
||
// Created by Krad on 2022/7/19.
|
||
//
|
||
|
||
#include "DialogManager.h"
|
||
|
||
#include <QApplication>
|
||
#include <QDebug>
|
||
|
||
#include "event/EventCenter.h"
|
||
#include "dialogs/GUIMessageDialog.h"
|
||
#include "dialogs/ChangePasswordFormDialog.h"
|
||
#include "dialogs/AccountFormDialog.h"
|
||
#include "dialogs/MultyMessageDialogManager.h"
|
||
#include "dialogs/EditPatientDialog.h"
|
||
#include "dialogs/AlertDialog.h"
|
||
#include "dialogs/DateSelectDialog.h"
|
||
#include "dialogs/SelectDialog.h"
|
||
#include "dialogs/GetWorkListDialog.h"
|
||
|
||
#include "network/DicomCfgDialog.h"
|
||
#include "network/GetAdminPsw.h"
|
||
#include "network/NetworkCfgDialog.h"
|
||
#include "network/GetIPDialog.h"
|
||
#include "network/GetRouteDialog.h"
|
||
|
||
#include "windows/LoginDialog.h"
|
||
#include "screensaver/ScreenSaverWindow.h"
|
||
|
||
#include "appvals/AppGlobalValues.h"
|
||
#include "json/jsonobject.h"
|
||
#include "shimlib/ShimLib.h"
|
||
|
||
namespace
|
||
{
|
||
const int GUIMESSAGEDIALOG_OFFSET = 30;
|
||
}
|
||
|
||
DialogManager::DialogManager()
|
||
: QObject()
|
||
, mFunctionDialog(nullptr)
|
||
, mScreenSaverWindow(nullptr)
|
||
, mOperationMessageDialog(nullptr)
|
||
, mSyncDialog(nullptr)
|
||
, mTopWidget(nullptr)
|
||
{
|
||
|
||
}
|
||
|
||
void DialogManager::init(QWidget* aParent) {
|
||
connect(EventCenter::Default(), &EventCenter::DeviceErrorRaise,this,&DialogManager::raiseDeviceError);
|
||
connect(EventCenter::Default(), &EventCenter::DeviceInfoRaise,this,&DialogManager::raiseDeviceInfo);
|
||
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);
|
||
MultyMessageDialogManager::getInstance()->setDialogParent(aParent);
|
||
mTopWidget = aParent;
|
||
mScreenSaverWindow = new ScreenSaverWindow();
|
||
}
|
||
|
||
//得考虑多线程的问题
|
||
void DialogManager::setTopWidget(QWidget* widget) {
|
||
std::lock_guard<std::mutex> lockGuard(mMutex);
|
||
if (nullptr == widget)
|
||
{
|
||
return;
|
||
}
|
||
qDebug()<<"last top:"<<mTopWidget<<", new top:"<<widget;
|
||
mTopWidget = widget;
|
||
++mDialogCount;
|
||
}
|
||
|
||
void DialogManager::releaseTopWidget(QWidget* expectedTopWidget) {
|
||
std::lock_guard<std::mutex> lockGuard(mMutex);
|
||
if (nullptr == expectedTopWidget)
|
||
{
|
||
return;
|
||
}
|
||
if (mTopWidget == expectedTopWidget){
|
||
mTopWidget = expectedTopWidget->parentWidget();
|
||
--mDialogCount;
|
||
}
|
||
}
|
||
|
||
void DialogManager::requestLogin(QWidget* aParent)
|
||
{
|
||
//Login 直接最顶层模态
|
||
if (!mFunctionDialog){
|
||
mFunctionDialog = new LoginDialog(aParent);
|
||
}
|
||
setTopWidget(mFunctionDialog);
|
||
mFunctionDialog->setWindowModality(Qt::WindowModal);
|
||
mFunctionDialog->exec();
|
||
while (QDialog::Accepted != mFunctionDialog->result())
|
||
{
|
||
mFunctionDialog->exec();
|
||
}
|
||
releaseTopWidget(mFunctionDialog);
|
||
}
|
||
|
||
void DialogManager::requestScreenSaverPlay()
|
||
{
|
||
setFocusToTopDialog();
|
||
mScreenSaverWindow->play();
|
||
}
|
||
|
||
void DialogManager::requestScreenSaverStop(bool aIsStopLocker)
|
||
{
|
||
mScreenSaverWindow->stop(aIsStopLocker);
|
||
}
|
||
|
||
int DialogManager::requestAddAccount(QSqlTableModel* model) {
|
||
AccountFormDialog dialog(mTopWidget, New);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setReferenceModel(model);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
int DialogManager::requestEditSelfAccount() {
|
||
AccountFormDialog dialog(mTopWidget, Self);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
int DialogManager::requestEditAdminAccount(const QMap<QString, QVariant>& values) {
|
||
AccountFormDialog dialog(mTopWidget, Admin);
|
||
setTopWidget(&dialog);
|
||
dialog.setAccountInformation(values);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
void DialogManager::requestChangePassword() {
|
||
ChangePasswordFormDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setGeometry(dialog.parentWidget()->geometry());
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
}
|
||
|
||
int DialogManager::requestEditPatientInfo(PatientInformation* aPatientFrom, QSqlTableModel* aModel)
|
||
{
|
||
EditPatientDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setPatientInformation(aPatientFrom);
|
||
dialog.setModel(aModel);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
int DialogManager::requestAlertMessage(const QString& aMessage, DialogButtonMode aButtonMode, const QString& aTitle)
|
||
{
|
||
AlertDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setAlertMessage(aMessage);
|
||
if (!aTitle.isEmpty())
|
||
{
|
||
dialog.setTitle(aTitle);
|
||
}
|
||
dialog.setButtonMode(aButtonMode);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
|
||
}
|
||
|
||
DialogResult DialogManager::requestSelectDate(const QString& aDate)
|
||
{
|
||
DateSelectDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setSelectedValue(aDate);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getSelectedValue());
|
||
}
|
||
|
||
DialogResult DialogManager::requestSelectLanguage()
|
||
{
|
||
SelectDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setValues(JsonObject::Instance()->language());
|
||
dialog.setSelectedValue(JsonObject::Instance()->defaultLanguage());
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getSelectedValue());
|
||
}
|
||
|
||
DialogResult DialogManager::requestSelectProtocal()
|
||
{
|
||
SelectDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setValues(JsonObject::Instance()->protocals());
|
||
dialog.setSelectedValue(JsonObject::Instance()->defaultProtocal());
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getSelectedValue());
|
||
}
|
||
|
||
DialogResult DialogManager::requestSelectFilter()
|
||
{
|
||
SelectDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setValues(JsonObject::Instance()->worklistFilters());
|
||
dialog.setSelectedValue(JsonObject::Instance()->defaultFilter());
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getSelectedValue());
|
||
}
|
||
|
||
int DialogManager::requestEditDicomConfig()
|
||
{
|
||
DicomCfgDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
int DialogManager::requestInputAdminPasswd()
|
||
{
|
||
GetAdminPsw dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
int DialogManager::requestEditNetworkConfig()
|
||
{
|
||
NetworkCfgDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
DialogResult DialogManager::requestEditIpAndNetMask()
|
||
{
|
||
GetIPDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getList());
|
||
}
|
||
|
||
DialogResult DialogManager::requestEditIpAndNetMask(const QStringList& aEditData)
|
||
{
|
||
GetIPDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setList(aEditData);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getList());
|
||
}
|
||
|
||
DialogResult DialogManager::requestEditRouteInfo()
|
||
{
|
||
GetRouteDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getList());
|
||
}
|
||
|
||
DialogResult DialogManager::requestEditRouteInfo(const QStringList& aEditData)
|
||
{
|
||
GetRouteDialog dialog(mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
dialog.setList(aEditData);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return DialogResult(ret,dialog.getList());
|
||
}
|
||
|
||
int DialogManager::requestGetWorkList(QSqlTableModel* aModel)
|
||
{
|
||
GetWorkListDialog dialog(aModel,mTopWidget);
|
||
setTopWidget(&dialog);
|
||
dialog.setWindowModality(Qt::WindowModal);
|
||
int ret = dialog.exec();
|
||
releaseTopWidget(&dialog);
|
||
return ret;
|
||
}
|
||
|
||
void DialogManager::raiseDeviceInfo(QObject* parent, QObject* aInfoData)
|
||
{
|
||
QPair<QString, unsigned int>* infoData = (QPair<QString, unsigned int>*)(aInfoData);
|
||
raiseMultyMessageDialog(infoData->first,MessageLevel(infoData->second));
|
||
}
|
||
|
||
//考虑以后使用另外的dialog显示错误
|
||
void DialogManager::raiseDeviceError(QObject *parent, QObject *msg) {
|
||
clearMessageDialog();
|
||
auto dialog = new GUIMessageDialog(mTopWidget);
|
||
|
||
if (nullptr != mTopWidget && mTopWidget->inherits("GUIMessageDialog"))
|
||
{
|
||
GUIMessageDialog* parent = qobject_cast<GUIMessageDialog*>(mTopWidget);
|
||
if (parent->getDialogPos().y() + 320 + GUIMESSAGEDIALOG_OFFSET < 1080)
|
||
{
|
||
dialog->moveDialog(parent->getDialogPos() + QPoint(GUIMESSAGEDIALOG_OFFSET, GUIMESSAGEDIALOG_OFFSET));
|
||
}
|
||
}
|
||
|
||
if (msg) {
|
||
QString *str = (QString *) msg;
|
||
dialog->showMessage(*str);
|
||
} else {
|
||
dialog->showMessage("Something went error!");
|
||
}
|
||
dialog->stopLoading();
|
||
dialog->showExitButton();
|
||
setTopWidget(dialog);
|
||
dialog->setWindowModality(Qt::WindowModal);
|
||
mScreenSaverWindow->stop(true);
|
||
dialog->showFullScreen ();
|
||
dialog->exec();
|
||
releaseTopWidget(dialog);
|
||
dialog->deleteLater();
|
||
if (nullptr != mTopWidget && !mTopWidget->inherits("GUIMessageDialog"))
|
||
{
|
||
mScreenSaverWindow->startLocker();
|
||
}
|
||
}
|
||
|
||
// 扫描过程 dialog 只能为最底层,并且会被error dialog 清除!
|
||
void DialogManager::invokeOperationStart(QObject *parent, QObject *msg) {
|
||
//没有目标parent 撤销操作
|
||
if (!QApplication::activeWindow()) return;
|
||
//只能在最底层窗口上模态
|
||
if (mDialogCount>0) return;
|
||
clearMessageDialog();
|
||
mOperationMessageDialog = new GUIMessageDialog(QApplication::activeWindow());
|
||
if (msg)
|
||
{
|
||
QString* str = (QString*)msg;
|
||
mOperationMessageDialog->showMessage(*str);
|
||
}
|
||
else
|
||
{
|
||
mOperationMessageDialog->hideMessage();
|
||
}
|
||
mOperationMessageDialog->hideExitButton();
|
||
mOperationMessageDialog->startLoading();
|
||
AppGlobalValues::setInProcessing(true);
|
||
if (mOperationMessageDialog->isHidden())
|
||
{
|
||
mOperationMessageDialog->showFullScreen();
|
||
//mOperationMessageDialog->exec();
|
||
}
|
||
}
|
||
|
||
void DialogManager::invokeOperationProgress(QObject *parent, QObject *msg) {
|
||
//窗口不存在,撤销操作
|
||
if (!mOperationMessageDialog) return;
|
||
if (msg)
|
||
{
|
||
QVariant* var = (QVariant*)msg;
|
||
if (mOperationMessageDialog->Pending())
|
||
{
|
||
mOperationMessageDialog->stopPending();
|
||
}
|
||
mOperationMessageDialog->showMessage(var->toString());
|
||
}
|
||
else
|
||
{
|
||
mOperationMessageDialog->hideMessage();
|
||
}
|
||
if (mOperationMessageDialog->isHidden())
|
||
{
|
||
mOperationMessageDialog->showFullScreen();
|
||
//mOperationMessageDialog->exec();
|
||
}
|
||
}
|
||
|
||
void DialogManager::invokeOperationPending(QObject *parent, QObject *msg) {
|
||
//窗口不存在,撤销操作
|
||
if (!mOperationMessageDialog) return;
|
||
if (!mOperationMessageDialog->Pending())
|
||
{
|
||
mOperationMessageDialog->startPending();
|
||
QVariant* var = (QVariant*)msg;
|
||
mOperationMessageDialog->showMessage(var->toString());
|
||
}
|
||
}
|
||
|
||
void DialogManager::invokeOperationEnd(QObject *parent, QObject *msg) {
|
||
//窗口不存在,撤销操作
|
||
if (!mOperationMessageDialog) return;
|
||
if (!mOperationMessageDialog->isHidden())
|
||
{
|
||
if (msg && ((QVariant*)msg)->toBool())
|
||
{
|
||
mOperationMessageDialog->stopLoading();
|
||
mOperationMessageDialog->showMessage("Scan completed!");
|
||
mOperationMessageDialog->showExitButton();
|
||
mOperationMessageDialog->setWindowModality(Qt::WindowModal);
|
||
mOperationMessageDialog->showFullScreen();
|
||
mOperationMessageDialog->exec();
|
||
}
|
||
else
|
||
{
|
||
mOperationMessageDialog->accept();
|
||
}
|
||
delete mOperationMessageDialog;
|
||
AppGlobalValues::setInProcessing(false);
|
||
}
|
||
}
|
||
|
||
void DialogManager::clearMessageDialog() {
|
||
if (mOperationMessageDialog)
|
||
{
|
||
releaseTopWidget(mOperationMessageDialog);
|
||
delete mOperationMessageDialog;
|
||
}
|
||
}
|
||
|
||
DialogManager::~DialogManager() {
|
||
clearMessageDialog();
|
||
delete mScreenSaverWindow;
|
||
}
|
||
|
||
void DialogManager::raiseMultyMessageDialog(const QString& aMessage, MessageLevel aMessageLevel)
|
||
{
|
||
MultyMessageDialogManager::getInstance()->raiseDialog(aMessage, aMessageLevel);
|
||
}
|
||
|
||
void DialogManager::raiseSyncDialog(const QString& aMessage)
|
||
{
|
||
if (!mSyncDialog)
|
||
{
|
||
mSyncDialog = new GUIMessageDialog(mTopWidget);
|
||
}
|
||
mSyncDialog->showMessage(aMessage);
|
||
setTopWidget(mSyncDialog);
|
||
mSyncDialog->setWindowModality(Qt::WindowModal);
|
||
mSyncDialog->showFullScreen ();
|
||
mSyncDialog->exec();
|
||
releaseTopWidget(mSyncDialog);
|
||
delete mSyncDialog;
|
||
}
|
||
|
||
void DialogManager::hideTopSyncDialog()
|
||
{
|
||
if (mSyncDialog)
|
||
{
|
||
mSyncDialog->accept();
|
||
}
|
||
}
|
||
|
||
void DialogManager::setFocusToTopDialog()
|
||
{
|
||
if (0 < mDialogCount && nullptr != mTopWidget)
|
||
{
|
||
mTopWidget->setFocus();
|
||
}
|
||
}
|