2020-03-12 05:32:15 +00:00
|
|
|
#include "qtprogresscallback.h"
|
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
#include <QtCore/QDebug>
|
|
|
|
#include <QtWidgets/QMessageBox>
|
|
|
|
#include <array>
|
|
|
|
|
2021-01-24 08:55:35 +00:00
|
|
|
QtProgressCallback::QtProgressCallback(QWidget* parent_widget, float show_delay)
|
|
|
|
: QObject(parent_widget), m_dialog(QString(), QString(), 0, 1, parent_widget), m_show_delay(show_delay)
|
2020-03-12 05:32:15 +00:00
|
|
|
{
|
|
|
|
m_dialog.setWindowTitle(tr("DuckStation"));
|
|
|
|
m_dialog.setMinimumSize(QSize(500, 0));
|
|
|
|
m_dialog.setModal(parent_widget != nullptr);
|
2021-01-24 08:55:35 +00:00
|
|
|
checkForDelayedShow();
|
2020-03-12 05:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QtProgressCallback::~QtProgressCallback() = default;
|
|
|
|
|
|
|
|
bool QtProgressCallback::IsCancelled() const
|
|
|
|
{
|
|
|
|
return m_dialog.wasCanceled();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::SetCancellable(bool cancellable)
|
|
|
|
{
|
2020-06-07 15:19:54 +00:00
|
|
|
if (m_cancellable == cancellable)
|
|
|
|
return;
|
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
BaseProgressCallback::SetCancellable(cancellable);
|
|
|
|
m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString());
|
|
|
|
}
|
|
|
|
|
2020-08-06 09:32:53 +00:00
|
|
|
void QtProgressCallback::SetTitle(const char* title)
|
|
|
|
{
|
|
|
|
m_dialog.setWindowTitle(QString::fromUtf8(title));
|
|
|
|
}
|
|
|
|
|
2020-03-12 05:32:15 +00:00
|
|
|
void QtProgressCallback::SetStatusText(const char* text)
|
|
|
|
{
|
|
|
|
BaseProgressCallback::SetStatusText(text);
|
2021-01-24 08:55:35 +00:00
|
|
|
checkForDelayedShow();
|
|
|
|
|
|
|
|
if (m_dialog.isVisible())
|
|
|
|
m_dialog.setLabelText(QString::fromUtf8(text));
|
2020-03-12 05:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::SetProgressRange(u32 range)
|
|
|
|
{
|
|
|
|
BaseProgressCallback::SetProgressRange(range);
|
2021-01-24 08:55:35 +00:00
|
|
|
checkForDelayedShow();
|
|
|
|
|
|
|
|
if (m_dialog.isVisible())
|
|
|
|
m_dialog.setRange(0, m_progress_range);
|
2020-03-12 05:32:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::SetProgressValue(u32 value)
|
|
|
|
{
|
|
|
|
BaseProgressCallback::SetProgressValue(value);
|
2021-01-24 08:55:35 +00:00
|
|
|
checkForDelayedShow();
|
2020-03-12 05:32:15 +00:00
|
|
|
|
2021-01-24 08:55:35 +00:00
|
|
|
if (!m_dialog.isVisible() || static_cast<u32>(m_dialog.value()) == m_progress_range)
|
2020-03-12 05:32:15 +00:00
|
|
|
return;
|
|
|
|
|
2020-06-07 15:19:54 +00:00
|
|
|
m_dialog.setValue(m_progress_value);
|
2020-03-12 05:32:15 +00:00
|
|
|
QCoreApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::DisplayError(const char* message)
|
|
|
|
{
|
|
|
|
qWarning() << message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::DisplayWarning(const char* message)
|
|
|
|
{
|
|
|
|
qWarning() << message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::DisplayInformation(const char* message)
|
|
|
|
{
|
|
|
|
qWarning() << message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::DisplayDebugMessage(const char* message)
|
|
|
|
{
|
|
|
|
qWarning() << message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QtProgressCallback::ModalError(const char* message)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(&m_dialog, tr("Error"), QString::fromUtf8(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool QtProgressCallback::ModalConfirmation(const char* message)
|
|
|
|
{
|
|
|
|
return (QMessageBox::question(&m_dialog, tr("Question"), QString::fromUtf8(message), QMessageBox::Yes,
|
|
|
|
QMessageBox::No) == QMessageBox::Yes);
|
|
|
|
}
|
|
|
|
|
2020-08-06 09:32:53 +00:00
|
|
|
void QtProgressCallback::ModalInformation(const char* message)
|
2020-03-12 05:32:15 +00:00
|
|
|
{
|
2020-08-06 09:32:53 +00:00
|
|
|
QMessageBox::information(&m_dialog, tr("Information"), QString::fromUtf8(message));
|
2020-03-12 05:32:15 +00:00
|
|
|
}
|
2021-01-24 08:55:35 +00:00
|
|
|
|
|
|
|
void QtProgressCallback::checkForDelayedShow()
|
|
|
|
{
|
|
|
|
if (m_dialog.isVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_show_timer.GetTimeSeconds() >= m_show_delay)
|
|
|
|
{
|
|
|
|
m_dialog.setRange(0, m_progress_range);
|
|
|
|
m_dialog.setValue(m_progress_value);
|
|
|
|
m_dialog.show();
|
|
|
|
}
|
|
|
|
}
|