2020-12-05 13:08:24 +01:00
|
|
|
#include "progress_dialog.h"
|
2017-11-25 14:01:35 +01:00
|
|
|
|
2021-09-29 21:47:04 +02:00
|
|
|
#include <QApplication>
|
2019-01-06 22:32:23 +01:00
|
|
|
#include <QLabel>
|
|
|
|
|
|
2021-09-29 21:28:51 +02:00
|
|
|
progress_dialog::progress_dialog(const QString& windowTitle, const QString& labelText, const QString& cancelButtonText, int minimum, int maximum, bool delete_on_close, QWidget* parent, Qt::WindowFlags flags)
|
2018-06-09 16:27:56 +02:00
|
|
|
: QProgressDialog(labelText, cancelButtonText, minimum, maximum, parent, flags)
|
2017-11-25 14:01:35 +01:00
|
|
|
{
|
2019-09-11 09:55:43 +02:00
|
|
|
setWindowTitle(windowTitle);
|
2020-11-19 20:18:50 +01:00
|
|
|
setMinimumSize(QLabel("This is the very length of the progressdialog due to hidpi reasons.").sizeHint().width(), sizeHint().height());
|
2019-09-11 09:55:43 +02:00
|
|
|
setValue(0);
|
2019-01-06 22:32:23 +01:00
|
|
|
setWindowModality(Qt::WindowModal);
|
2020-01-07 22:44:23 +01:00
|
|
|
|
|
|
|
|
if (delete_on_close)
|
|
|
|
|
{
|
2023-11-25 03:18:26 +01:00
|
|
|
SetDeleteOnClose();
|
2020-01-07 22:44:23 +01:00
|
|
|
}
|
2019-01-06 22:32:23 +01:00
|
|
|
|
2023-01-11 00:20:08 +01:00
|
|
|
m_progress_indicator = std::make_unique<progress_indicator>(minimum, maximum);
|
2017-11-25 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progress_dialog::~progress_dialog()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 21:28:51 +02:00
|
|
|
void progress_dialog::SetRange(int min, int max)
|
|
|
|
|
{
|
2023-01-11 00:20:08 +01:00
|
|
|
m_progress_indicator->set_range(min, max);
|
2021-09-29 21:28:51 +02:00
|
|
|
|
2024-03-12 22:45:40 +01:00
|
|
|
setRange(min, max);
|
2021-09-29 21:28:51 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-25 14:01:35 +01:00
|
|
|
void progress_dialog::SetValue(int progress)
|
|
|
|
|
{
|
2018-06-09 16:27:56 +02:00
|
|
|
const int value = std::clamp(progress, minimum(), maximum());
|
|
|
|
|
|
2023-01-11 00:20:08 +01:00
|
|
|
m_progress_indicator->set_value(value);
|
2017-11-25 14:01:35 +01:00
|
|
|
|
2024-03-12 22:45:40 +01:00
|
|
|
setValue(value);
|
2017-11-25 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
2023-11-25 03:18:26 +01:00
|
|
|
void progress_dialog::SetDeleteOnClose()
|
|
|
|
|
{
|
2024-03-09 17:57:27 +01:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
connect(this, &QProgressDialog::canceled, this, &QProgressDialog::close, Qt::UniqueConnection);
|
2023-11-25 03:18:26 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 23:05:18 +02:00
|
|
|
void progress_dialog::SignalFailure() const
|
2019-10-05 17:22:40 +02:00
|
|
|
{
|
2023-01-11 00:20:08 +01:00
|
|
|
m_progress_indicator->signal_failure();
|
2021-09-29 21:47:04 +02:00
|
|
|
|
|
|
|
|
QApplication::beep();
|
2019-10-05 17:22:40 +02:00
|
|
|
}
|
2024-05-04 23:09:02 +02:00
|
|
|
|
|
|
|
|
void progress_dialog::show_progress_indicator()
|
|
|
|
|
{
|
|
|
|
|
// Try to find a window handle first
|
|
|
|
|
QWindow* handle = windowHandle();
|
|
|
|
|
|
|
|
|
|
for (QWidget* ancestor = this; !handle && ancestor;)
|
|
|
|
|
{
|
|
|
|
|
ancestor = static_cast<QWidget*>(ancestor->parent());
|
|
|
|
|
if (ancestor) handle = ancestor->windowHandle();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_progress_indicator->show(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void progress_dialog::setVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
if (visible)
|
|
|
|
|
{
|
|
|
|
|
if (!isVisible())
|
|
|
|
|
{
|
|
|
|
|
show_progress_indicator();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (isVisible())
|
|
|
|
|
{
|
|
|
|
|
m_progress_indicator->hide();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QProgressDialog::setVisible(visible);
|
|
|
|
|
}
|