2015-05-28 23:08:29 +05:30
|
|
|
// Licensed under the Apache-2.0 license. See README.md for details.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class Task;
|
|
|
|
class QProgressBar;
|
|
|
|
class QLabel;
|
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
class ProgressWidget : public QWidget {
|
2018-07-15 18:21:05 +05:30
|
|
|
Q_OBJECT
|
2022-07-15 21:48:12 +05:30
|
|
|
public:
|
|
|
|
explicit ProgressWidget(QWidget* parent = nullptr, bool show_label = true);
|
2015-05-28 23:08:29 +05:30
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
/** Whether to hide the widget automatically if it's watching no running task. */
|
|
|
|
void hideIfInactive(bool hide) { m_hide_if_inactive = hide; }
|
|
|
|
|
|
|
|
/** Reset the displayed progress to 0 */
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
/** The text that shows up in the middle of the progress bar.
|
|
|
|
* By default it's '%p%', with '%p' being the total progress in percentage.
|
|
|
|
*/
|
|
|
|
void progressFormat(QString);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
/** Watch the progress of a task. */
|
2022-11-25 17:53:46 +05:30
|
|
|
void watch(const Task* task);
|
2022-07-15 21:48:12 +05:30
|
|
|
|
|
|
|
/** Watch the progress of a task, and start it if needed */
|
2022-11-25 17:53:46 +05:30
|
|
|
void start(const Task* task);
|
2022-07-15 21:48:12 +05:30
|
|
|
|
|
|
|
/** Blocking way of waiting for a task to finish. */
|
2018-07-15 18:21:05 +05:30
|
|
|
bool exec(std::shared_ptr<Task> task);
|
2015-05-28 23:08:29 +05:30
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
/** Un-hide the widget if needed. */
|
|
|
|
void show();
|
|
|
|
|
|
|
|
/** Make the widget invisible. */
|
|
|
|
void hide();
|
|
|
|
|
|
|
|
private slots:
|
2018-07-15 18:21:05 +05:30
|
|
|
void handleTaskFinish();
|
2022-07-15 21:48:12 +05:30
|
|
|
void handleTaskStatus(const QString& status);
|
2018-07-15 18:21:05 +05:30
|
|
|
void handleTaskProgress(qint64 current, qint64 total);
|
|
|
|
void taskDestroyed();
|
2015-05-28 23:08:29 +05:30
|
|
|
|
2022-07-15 21:48:12 +05:30
|
|
|
private:
|
|
|
|
QLabel* m_label = nullptr;
|
|
|
|
QProgressBar* m_bar = nullptr;
|
2022-11-25 17:53:46 +05:30
|
|
|
const Task* m_task = nullptr;
|
2022-07-15 21:48:12 +05:30
|
|
|
|
|
|
|
bool m_hide_if_inactive = false;
|
2015-05-28 23:08:29 +05:30
|
|
|
};
|