UI: Workaround to show initial dialog on WinPE

This commit is contained in:
Nodir Temirkhodjaev 2024-01-05 13:04:03 +03:00
parent 3ebd4a6576
commit 452ea922a5
3 changed files with 53 additions and 30 deletions

View File

@ -3,6 +3,8 @@
#include <QColorDialog>
#include <QFileDialog>
#include <util/window/widgetwindow.h>
QString DialogUtil::getOpenFileName(const QString &title, const QString &filter)
{
return QFileDialog::getOpenFileName(
@ -30,3 +32,30 @@ QColor DialogUtil::getColor(const QColor &initial, const QString &title)
{
return QColorDialog::getColor(initial, nullptr, title);
}
void DialogUtil::setupModalDialog(QWidget *box)
{
box->setWindowModality(box->parent() ? Qt::WindowModal : Qt::ApplicationModal);
}
QMessageBox *DialogUtil::createMessageBox(const MessageBoxArg &ba, QWidget *parent)
{
auto box = new QMessageBox(ba.icon, ba.title, ba.text, ba.buttons, parent);
box->setAttribute(Qt::WA_DeleteOnClose);
setupModalDialog(box);
return box;
}
void DialogUtil::showDialog(QWidget *box)
{
static bool g_isDialogShown = false;
// Workaround to show initial dialog on WinPE
if (!g_isDialogShown) {
g_isDialogShown = true;
box->show();
box->hide();
}
WidgetWindow::showWidget(box);
}

View File

@ -2,8 +2,17 @@
#define DIALOGUTIL_H
#include <QColor>
#include <QMessageBox>
#include <QObject>
struct MessageBoxArg
{
QMessageBox::Icon icon;
QMessageBox::StandardButtons buttons;
const QString text;
const QString title;
};
class DialogUtil
{
public:
@ -16,6 +25,12 @@ public:
static QString getExistingDir(const QString &title = QString());
static QColor getColor(const QColor &initial = Qt::white, const QString &title = QString());
static void setupModalDialog(QWidget *box);
static QMessageBox *createMessageBox(const MessageBoxArg &ba, QWidget *parent = nullptr);
static void showDialog(QWidget *box);
};
#endif // DIALOGUTIL_H

View File

@ -2,7 +2,6 @@
#include <QApplication>
#include <QLoggingCategory>
#include <QMessageBox>
#include <QMouseEvent>
#include <QProcess>
#include <QPushButton>
@ -13,6 +12,7 @@
#include <conf/confmanager.h>
#include <form/controls/controlutil.h>
#include <form/controls/mainwindow.h>
#include <form/dialog/dialogutil.h>
#include <form/dialog/passworddialog.h>
#include <form/graph/graphwindow.h>
#include <form/home/homewindow.h>
@ -40,27 +40,6 @@ void setupAppStyle()
QApplication::setStyle(style);
}
struct MessageBoxArg
{
QMessageBox::Icon icon;
QMessageBox::StandardButtons buttons;
const QString text;
const QString title;
};
void setupModalDialog(QDialog *box)
{
box->setWindowModality(box->parent() ? Qt::WindowModal : Qt::ApplicationModal);
}
QMessageBox *createMessageBox(const MessageBoxArg &ba, QWidget *parent = nullptr)
{
auto box = new QMessageBox(ba.icon, ba.title, ba.text, ba.buttons, parent);
box->setAttribute(Qt::WA_DeleteOnClose);
setupModalDialog(box);
return box;
}
}
WindowManager::WindowManager(QObject *parent) : QObject(parent) { }
@ -577,7 +556,7 @@ void WindowManager::showConfirmBox(const std::function<void()> &onConfirmed, con
void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &onFinished,
const QString &text, const QString &title, QWidget *parent)
{
auto box = createMessageBox(
auto box = DialogUtil::createMessageBox(
{
.icon = QMessageBox::Question,
.buttons = QMessageBox::Yes | QMessageBox::No,
@ -594,12 +573,12 @@ void WindowManager::showQuestionBox(const std::function<void(bool confirmed)> &o
},
Qt::QueuedConnection);
WidgetWindow::showWidget(box);
DialogUtil::showDialog(box);
}
void WindowManager::showErrorDialog(const QString &text, const QString &title, QWidget *parent)
{
auto box = createMessageBox(
auto box = DialogUtil::createMessageBox(
{
.icon = QMessageBox::Warning,
.buttons = QMessageBox::Ok,
@ -608,12 +587,12 @@ void WindowManager::showErrorDialog(const QString &text, const QString &title, Q
},
parent);
WidgetWindow::showWidget(box);
DialogUtil::showDialog(box);
}
void WindowManager::showInfoDialog(const QString &text, const QString &title, QWidget *parent)
{
auto box = createMessageBox(
auto box = DialogUtil::createMessageBox(
{
.icon = QMessageBox::Information,
.buttons = QMessageBox::Ok,
@ -622,7 +601,7 @@ void WindowManager::showInfoDialog(const QString &text, const QString &title, QW
},
parent);
WidgetWindow::showWidget(box);
DialogUtil::showDialog(box);
}
bool WindowManager::showPasswordDialog(QString &password, int *unlockType)
@ -630,9 +609,9 @@ bool WindowManager::showPasswordDialog(QString &password, int *unlockType)
auto box = new PasswordDialog();
QScopedPointer<PasswordDialog> deferBox(box);
setupModalDialog(box);
DialogUtil::setupModalDialog(box);
WidgetWindow::showWidget(box);
DialogUtil::showDialog(box);
if (box->exec() != QDialog::Accepted)
return false;