diff options
Diffstat (limited to 'src/mainwindow/widgets/loadingbar.cpp')
-rw-r--r-- | src/mainwindow/widgets/loadingbar.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/mainwindow/widgets/loadingbar.cpp b/src/mainwindow/widgets/loadingbar.cpp new file mode 100644 index 0000000..99f44d2 --- /dev/null +++ b/src/mainwindow/widgets/loadingbar.cpp @@ -0,0 +1,50 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: git://neueland.iserlohn-fortress.net/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "loadingbar.h" +#include <QTimer> +#include "webengine/webview.h" + +LoadingBar::LoadingBar(QWidget *parent) + : QProgressBar(parent) +{ + setMaximum(100); +} + +void LoadingBar::connectWebView(WebView *view) +{ + Q_CHECK_PTR(view); + + disconnect(loadStartedConnection); + disconnect(loadProgressConnection); + disconnect(loadFinishedConnection); + + if(view->isLoaded()) { + this->hide(); + } else { + loadStarted(); + setValue(view->loadProgress()); + } + + loadStartedConnection = connect(view, &QWebEngineView::loadStarted, this, &LoadingBar::loadStarted); + loadProgressConnection = connect(view, &QWebEngineView::loadProgress, this, &QProgressBar::setValue); + loadFinishedConnection = connect(view, &QWebEngineView::loadFinished, this, &LoadingBar::loadFinished); +} + +void LoadingBar::loadStarted() +{ + resetFormat(); + show(); + setValue(0); +} + +void LoadingBar::loadFinished(bool ok) +{ + setFormat(QString("%p% %1").arg(ok ? tr("Finished") : tr("Failed"))); + QTimer::singleShot(2000, this, SLOT(hide())); +} |