Qt: Add ProgressCallback implementation

This commit is contained in:
Connor McLaughlin 2020-03-12 15:32:15 +10:00
parent 8028b7b4a3
commit f71a03202b
5 changed files with 141 additions and 0 deletions

View file

@ -34,6 +34,8 @@ add_executable(duckstation-qt
qtdisplaywidget.h qtdisplaywidget.h
qthostinterface.cpp qthostinterface.cpp
qthostinterface.h qthostinterface.h
qtprogresscallback.cpp
qtprogresscallback.h
qtsettingsinterface.cpp qtsettingsinterface.cpp
qtsettingsinterface.h qtsettingsinterface.h
qtutils.cpp qtutils.cpp

View file

@ -49,6 +49,7 @@
<ClCompile Include="opengldisplaywidget.cpp" /> <ClCompile Include="opengldisplaywidget.cpp" />
<ClCompile Include="portsettingswidget.cpp" /> <ClCompile Include="portsettingswidget.cpp" />
<ClCompile Include="qthostinterface.cpp" /> <ClCompile Include="qthostinterface.cpp" />
<ClCompile Include="qtprogresscallback.cpp" />
<ClCompile Include="qtsettingsinterface.cpp" /> <ClCompile Include="qtsettingsinterface.cpp" />
<ClCompile Include="qtutils.cpp" /> <ClCompile Include="qtutils.cpp" />
<ClCompile Include="settingsdialog.cpp" /> <ClCompile Include="settingsdialog.cpp" />
@ -61,6 +62,7 @@
<QtMoc Include="hotkeysettingswidget.h" /> <QtMoc Include="hotkeysettingswidget.h" />
<QtMoc Include="inputbindingwidgets.h" /> <QtMoc Include="inputbindingwidgets.h" />
<QtMoc Include="d3d11displaywidget.h" /> <QtMoc Include="d3d11displaywidget.h" />
<QtMoc Include="qtprogresscallback.h" />
<ClInclude Include="settingwidgetbinder.h" /> <ClInclude Include="settingwidgetbinder.h" />
<QtMoc Include="consolesettingswidget.h" /> <QtMoc Include="consolesettingswidget.h" />
<QtMoc Include="gamelistsettingswidget.h" /> <QtMoc Include="gamelistsettingswidget.h" />
@ -128,6 +130,7 @@
<ClCompile Include="$(IntDir)moc_portsettingswidget.cpp" /> <ClCompile Include="$(IntDir)moc_portsettingswidget.cpp" />
<ClCompile Include="$(IntDir)moc_qtdisplaywidget.cpp" /> <ClCompile Include="$(IntDir)moc_qtdisplaywidget.cpp" />
<ClCompile Include="$(IntDir)moc_qthostinterface.cpp" /> <ClCompile Include="$(IntDir)moc_qthostinterface.cpp" />
<ClCompile Include="$(IntDir)moc_qtprogresscallback.cpp" />
<ClCompile Include="$(IntDir)moc_settingsdialog.cpp" /> <ClCompile Include="$(IntDir)moc_settingsdialog.cpp" />
<ClCompile Include="$(IntDir)qrc_icons.cpp" /> <ClCompile Include="$(IntDir)qrc_icons.cpp" />
</ItemGroup> </ItemGroup>

View file

@ -33,11 +33,14 @@
<ClCompile Include="$(IntDir)moc_opengldisplaywidget.cpp" /> <ClCompile Include="$(IntDir)moc_opengldisplaywidget.cpp" />
<ClCompile Include="$(IntDir)moc_qtdisplaywidget.cpp" /> <ClCompile Include="$(IntDir)moc_qtdisplaywidget.cpp" />
<ClCompile Include="qtdisplaywidget.cpp" /> <ClCompile Include="qtdisplaywidget.cpp" />
<ClCompile Include="qtprogresscallback.cpp" />
<ClCompile Include="$(IntDir)moc_qtprogresscallback.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="qtsettingsinterface.h" /> <ClInclude Include="qtsettingsinterface.h" />
<ClInclude Include="qtutils.h" /> <ClInclude Include="qtutils.h" />
<ClInclude Include="settingwidgetbinder.h" /> <ClInclude Include="settingwidgetbinder.h" />
<ClInclude Include="qtprogresscallback.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Filter Include="resources"> <Filter Include="resources">

View file

@ -0,0 +1,102 @@
#include "qtprogresscallback.h"
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtWidgets/QMessageBox>
#include <array>
QtProgressCallback::QtProgressCallback(QWidget* parent_widget)
: QObject(parent_widget), m_dialog(QString(), QString(), 0, 1, parent_widget)
{
m_dialog.setWindowTitle(tr("DuckStation"));
m_dialog.setMinimumSize(QSize(500, 0));
m_dialog.setModal(parent_widget != nullptr);
m_dialog.show();
}
QtProgressCallback::~QtProgressCallback() = default;
bool QtProgressCallback::IsCancelled() const
{
return m_dialog.wasCanceled();
}
void QtProgressCallback::SetCancellable(bool cancellable)
{
BaseProgressCallback::SetCancellable(cancellable);
m_dialog.setCancelButtonText(cancellable ? tr("Cancel") : QString());
}
void QtProgressCallback::SetStatusText(const char* text)
{
BaseProgressCallback::SetStatusText(text);
m_dialog.setLabelText(QString::fromUtf8(text));
}
void QtProgressCallback::SetProgressRange(u32 range)
{
BaseProgressCallback::SetProgressRange(range);
m_dialog.setRange(0, static_cast<int>(range));
}
void QtProgressCallback::SetProgressValue(u32 value)
{
BaseProgressCallback::SetProgressValue(value);
if (m_dialog.value() == static_cast<int>(value))
return;
m_dialog.setValue(value);
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);
}
u32 QtProgressCallback::ModalPrompt(const char* message, u32 num_options, ...)
{
enum : u32
{
MAX_OPTIONS = 3,
};
std::array<QString, MAX_OPTIONS> options;
std::va_list ap;
va_start(ap, num_options);
for (u32 i = 0; i < num_options && i < MAX_OPTIONS; i++)
options[i] = QString::fromUtf8(va_arg(ap, const char*));
va_end(ap);
return static_cast<u32>(QMessageBox::question(&m_dialog, tr("Question"), QString::fromUtf8(message), options[0],
options[1], options[2], 0, 0));
}

View file

@ -0,0 +1,31 @@
#pragma once
#include "common/progress_callback.h"
#include <QtWidgets/QProgressDialog>
class QtProgressCallback final : public QObject, public BaseProgressCallback
{
Q_OBJECT
public:
QtProgressCallback(QWidget* parent_widget);
~QtProgressCallback();
bool IsCancelled() const override;
void SetCancellable(bool cancellable) override;
void SetStatusText(const char* text) override;
void SetProgressRange(u32 range) override;
void SetProgressValue(u32 value) override;
void DisplayError(const char* message) override;
void DisplayWarning(const char* message) override;
void DisplayInformation(const char* message) override;
void DisplayDebugMessage(const char* message) override;
void ModalError(const char* message) override;
bool ModalConfirmation(const char* message) override;
u32 ModalPrompt(const char* message, u32 num_options, ...) override;
private:
QProgressDialog m_dialog;
};