feat(ui): introduce retryEnabled in ZLoadingWidget

This commit is contained in:
uncor3
2026-04-04 10:37:40 +00:00
parent 56fa9310a6
commit 05d0445a10
2 changed files with 25 additions and 20 deletions
+6 -8
View File
@@ -5,14 +5,12 @@
#include <QLabel>
#include <QStackedWidget>
ZLoadingWidget::ZLoadingWidget(bool start, QWidget *parent)
: QStackedWidget{parent}, m_loadingIndicator(new QProcessIndicator())
ZLoadingWidget::ZLoadingWidget(bool retryEnabled, QWidget *parent)
: QStackedWidget{parent}, m_loadingIndicator(new QProcessIndicator()),
m_retryEnabled(retryEnabled)
{
m_loadingIndicator->setType(QProcessIndicator::line_rotate);
m_loadingIndicator->setFixedSize(64, 32);
if (start) {
m_loadingIndicator->start();
}
// Create a proper container widget for the loading indicator
QWidget *loadingWidget = new QWidget(this);
@@ -22,7 +20,7 @@ ZLoadingWidget::ZLoadingWidget(bool start, QWidget *parent)
loadingLayout->addWidget(m_loadingIndicator);
loadingLayout->addStretch();
m_errorWidget = new ZLoadingErrorWidget(this);
m_errorWidget = new ZLoadingErrorWidget(m_retryEnabled, this);
connect(static_cast<ZLoadingErrorWidget *>(m_errorWidget),
&ZLoadingErrorWidget::retryClicked, this,
[this]() { emit retryClicked(); });
@@ -65,9 +63,9 @@ void ZLoadingWidget::setupErrorWidget(QLayout *errorLayout)
addWidget(m_errorWidget);
}
void ZLoadingWidget::setupAditionalWidget(QWidget *customWidget)
int ZLoadingWidget::setupAditionalWidget(QWidget *customWidget)
{
addWidget(customWidget);
return addWidget(customWidget);
}
void ZLoadingWidget::switchToWidget(QWidget *widget)
+19 -12
View File
@@ -1,38 +1,43 @@
#ifndef ZLOADINGWIDGET_H
#define ZLOADINGWIDGET_H
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QStackedWidget>
#include <QWidget>
#include <QHBoxLayout>
class ZLoadingErrorWidget : public QWidget
{
Q_OBJECT
public:
ZLoadingErrorWidget(QWidget *parent = nullptr)
ZLoadingErrorWidget(bool retryEnabled, QWidget *parent = nullptr)
{
QHBoxLayout *layout = new QHBoxLayout(this);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->addStretch();
m_errorLabel = new QLabel("An error occurred.", this);
m_errorLabel->setAlignment(Qt::AlignCenter);
m_errorLabel->setWordWrap(true);
m_errorLabel->setStyleSheet("QLabel { color: red; }");
layout->addWidget(m_errorLabel);
m_retryButton = new QPushButton("Retry", this);
m_retryButton->setMaximumWidth(m_retryButton->sizeHint().width());
layout->addWidget(m_retryButton);
if (retryEnabled) {
layout->addSpacing(10);
m_retryButton = new QPushButton("Retry", this);
m_retryButton->setMaximumWidth(m_retryButton->sizeHint().width());
layout->addWidget(m_retryButton, 0, Qt::AlignCenter);
connect(m_retryButton, &QPushButton::clicked, this,
[this]() { emit retryClicked(); });
}
layout->addStretch();
connect(m_retryButton, &QPushButton::clicked, this,
[this]() { emit retryClicked(); });
}
void setText(const QString &text) { m_errorLabel->setText(text); };
private:
QLabel *m_errorLabel;
QPushButton *m_retryButton;
QLabel *m_errorLabel = nullptr;
QPushButton *m_retryButton = nullptr;
signals:
void retryClicked();
};
@@ -41,7 +46,8 @@ class ZLoadingWidget : public QStackedWidget
{
Q_OBJECT
public:
explicit ZLoadingWidget(bool start = true, QWidget *parent = nullptr);
explicit ZLoadingWidget(bool retryEnabled = false,
QWidget *parent = nullptr);
~ZLoadingWidget();
void stop(bool showContent = true);
void showLoading();
@@ -49,7 +55,7 @@ public:
void setupContentWidget(QLayout *contentLayout);
void setupErrorWidget(QWidget *errorWidget);
void setupErrorWidget(QLayout *errorLayout);
void setupAditionalWidget(QWidget *customWidget);
int setupAditionalWidget(QWidget *customWidget);
void switchToWidget(QWidget *widget);
void showError();
void showError(const QString &errorMessage);
@@ -58,6 +64,7 @@ private:
class QProcessIndicator *m_loadingIndicator = nullptr;
QWidget *m_contentWidget = nullptr;
QWidget *m_errorWidget = nullptr;
bool m_retryEnabled = false;
signals:
void retryClicked();
};