mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-03-14 01:27:00 +00:00
Qt: clamp progress bar values
This commit is contained in:
parent
88bfdb0c05
commit
2b8cab906c
@ -125,7 +125,7 @@ void game_compatibility::RequestCompatibility(bool online)
|
||||
QNetworkReply* network_reply = m_network_access_manager->get(m_network_request);
|
||||
|
||||
// Show Progress
|
||||
m_progress_dialog.reset(new QProgressDialog(tr(".Please wait."), tr("Abort"), 0, 100));
|
||||
m_progress_dialog.reset(new progress_dialog(tr(".Please wait."), tr("Abort"), 0, 100));
|
||||
m_progress_dialog->setWindowTitle(tr("Downloading Database"));
|
||||
m_progress_dialog->setFixedWidth(QLabel("This is the very length of the progressbar due to hidpi reasons.").sizeHint().width());
|
||||
m_progress_dialog->setValue(0);
|
||||
|
@ -10,10 +10,10 @@
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QTableWidget>
|
||||
#include <QProgressDialog>
|
||||
#include <QTimer>
|
||||
|
||||
#include "gui_settings.h"
|
||||
#include "progress_dialog.h"
|
||||
|
||||
struct compat_status
|
||||
{
|
||||
@ -45,7 +45,7 @@ class game_compatibility : public QObject
|
||||
QNetworkRequest m_network_request;
|
||||
std::shared_ptr<gui_settings> m_xgui_settings;
|
||||
std::unique_ptr<QTimer> m_progress_timer;
|
||||
std::unique_ptr<QProgressDialog> m_progress_dialog;
|
||||
std::unique_ptr<progress_dialog> m_progress_dialog;
|
||||
std::unique_ptr<QNetworkAccessManager> m_network_access_manager;
|
||||
std::map<std::string, compat_status> m_compat_database;
|
||||
|
||||
|
@ -439,10 +439,10 @@ void gs_frame::progress_increment(int delta)
|
||||
#ifdef _WIN32
|
||||
if (m_tb_progress)
|
||||
{
|
||||
m_tb_progress->setValue(m_tb_progress->value() + delta);
|
||||
m_tb_progress->setValue(std::clamp(m_tb_progress->value() + delta, m_tb_progress->minimum(), m_tb_progress->maximum()));
|
||||
}
|
||||
#elif HAVE_QTDBUS
|
||||
m_progress_value += delta;
|
||||
m_progress_value = std::clamp(m_progress_value + delta, 0, m_gauge_max);
|
||||
UpdateProgress(m_progress_value);
|
||||
#endif
|
||||
}
|
||||
|
@ -418,10 +418,8 @@ void main_window::InstallPkg(const QString& dropPath)
|
||||
const std::string fileName = sstr(QFileInfo(filePath).fileName());
|
||||
const std::string path = sstr(filePath);
|
||||
|
||||
progress_dialog pdlg(0, 1000, this);
|
||||
progress_dialog pdlg(tr("Installing package ... please wait ..."), tr("Cancel"), 0, 1000, this);
|
||||
pdlg.setWindowTitle(tr("RPCS3 Package Installer"));
|
||||
pdlg.setLabelText(tr("Installing package ... please wait ..."));
|
||||
pdlg.setCancelButtonText(tr("Cancel"));
|
||||
pdlg.setWindowModality(Qt::WindowModal);
|
||||
pdlg.setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width());
|
||||
pdlg.show();
|
||||
@ -530,10 +528,8 @@ void main_window::InstallPup(const QString& dropPath)
|
||||
return;
|
||||
}
|
||||
|
||||
progress_dialog pdlg(0, static_cast<int>(updatefilenames.size()), this);
|
||||
progress_dialog pdlg(tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)), tr("Cancel"), 0, static_cast<int>(updatefilenames.size()), this);
|
||||
pdlg.setWindowTitle(tr("RPCS3 Firmware Installer"));
|
||||
pdlg.setLabelText(tr("Installing firmware version %1\nPlease wait...").arg(qstr(version_string)));
|
||||
pdlg.setCancelButtonText(tr("Cancel"));
|
||||
pdlg.setWindowModality(Qt::WindowModal);
|
||||
pdlg.setFixedWidth(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width());
|
||||
pdlg.show();
|
||||
|
@ -311,12 +311,12 @@ void msg_dialog_frame::ProgressBarInc(u32 index, u32 delta)
|
||||
|
||||
if (index == 0 && m_gauge1)
|
||||
{
|
||||
m_gauge1->setValue(m_gauge1->value() + delta);
|
||||
m_gauge1->setValue(std::min(m_gauge1->value() + (int)delta, m_gauge1->maximum()));
|
||||
}
|
||||
|
||||
if (index == 1 && m_gauge2)
|
||||
{
|
||||
m_gauge2->setValue(m_gauge2->value() + delta);
|
||||
m_gauge2->setValue(std::min(m_gauge2->value() + (int)delta, m_gauge2->maximum()));
|
||||
}
|
||||
|
||||
if (index == taskbar_index || taskbar_index == -1)
|
||||
@ -324,10 +324,10 @@ void msg_dialog_frame::ProgressBarInc(u32 index, u32 delta)
|
||||
#ifdef _WIN32
|
||||
if (m_tb_progress)
|
||||
{
|
||||
m_tb_progress->setValue(m_tb_progress->value() + delta);
|
||||
m_tb_progress->setValue(std::min(m_tb_progress->value() + (int)delta, m_tb_progress->maximum()));
|
||||
}
|
||||
#elif HAVE_QTDBUS
|
||||
m_progress_value += delta;
|
||||
m_progress_value = std::min(m_progress_value + (int)delta, m_gauge_max);
|
||||
UpdateProgress(m_progress_value);
|
||||
#endif
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
#include "progress_dialog.h"
|
||||
|
||||
progress_dialog::progress_dialog(int min, int max, QWidget* parent, Qt::WindowFlags flags) : QProgressDialog(parent, flags)
|
||||
progress_dialog::progress_dialog(const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, flags)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
m_tb_button = std::make_unique<QWinTaskbarButton>();
|
||||
m_tb_button->setWindow(parent->windowHandle());
|
||||
m_tb_progress = m_tb_button->progress();
|
||||
m_tb_progress->setRange(min, max);
|
||||
m_tb_progress->setRange(minimum, maximum);
|
||||
m_tb_progress->setVisible(true);
|
||||
#elif HAVE_QTDBUS
|
||||
m_max = max;
|
||||
UpdateProgress(0);
|
||||
#endif
|
||||
|
||||
QProgressDialog::setRange(min, max);
|
||||
}
|
||||
|
||||
progress_dialog::~progress_dialog()
|
||||
@ -27,13 +25,15 @@ progress_dialog::~progress_dialog()
|
||||
|
||||
void progress_dialog::SetValue(int progress)
|
||||
{
|
||||
const int value = std::clamp(progress, minimum(), maximum());
|
||||
|
||||
#ifdef _WIN32
|
||||
m_tb_progress->setValue(progress);
|
||||
m_tb_progress->setValue(value);
|
||||
#elif HAVE_QTDBUS
|
||||
UpdateProgress(progress);
|
||||
UpdateProgress(value);
|
||||
#endif
|
||||
|
||||
QProgressDialog::setValue(progress);
|
||||
QProgressDialog::setValue(value);
|
||||
}
|
||||
|
||||
#ifdef HAVE_QTDBUS
|
||||
@ -49,7 +49,7 @@ void progress_dialog::UpdateProgress(int progress, bool disable)
|
||||
else
|
||||
properties.insert(QStringLiteral("progress-visible"), true);
|
||||
//Progress takes a value from 0.0 to 0.1
|
||||
properties.insert(QStringLiteral("progress"), (double)progress / (double)m_max);
|
||||
properties.insert(QStringLiteral("progress"), (double)progress / (double)maximum());
|
||||
message << QStringLiteral("application://rpcs3.desktop") << properties;
|
||||
QDBusConnection::sessionBus().send(message);
|
||||
}
|
||||
|
@ -17,7 +17,7 @@
|
||||
class progress_dialog : public QProgressDialog
|
||||
{
|
||||
public:
|
||||
progress_dialog(int min, int max, QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
progress_dialog(const QString &labelText, const QString &cancelButtonText, int minimum, int maximum, QWidget *parent = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
~progress_dialog();
|
||||
void SetValue(int progress);
|
||||
|
||||
@ -26,7 +26,6 @@ private:
|
||||
std::unique_ptr<QWinTaskbarButton> m_tb_button = nullptr;
|
||||
QWinTaskbarProgress* m_tb_progress = nullptr;
|
||||
#elif HAVE_QTDBUS
|
||||
int m_max = 100;
|
||||
void UpdateProgress(int progress, bool disable = false);
|
||||
#endif
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user