| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_QTGUI_TIMEDPROGRESSDIALOG_H |
| 7 |
#define AVOGADRO_QTGUI_TIMEDPROGRESSDIALOG_H |
| 8 |
|
| 9 |
#include "avogadroqtguiexport.h" |
| 10 |
|
| 11 |
#include <QProgressDialog> |
| 12 |
#include <QElapsedTimer> |
| 13 |
#include <QString> |
| 14 |
|
| 15 |
namespace Avogadro::QtGui { |
| 16 |
|
| 17 |
/** |
| 18 |
* @class TimedProgressDialog timedprogressdialog.h |
| 19 |
* <avogadro/qtgui/timedprogressdialog.h> |
| 20 |
* @brief A progress dialog with a time remaining label |
| 21 |
* @author Geoff Hutchison |
| 22 |
*/ |
| 23 |
class AVOGADROQTGUI_EXPORT TimedProgressDialog : public QProgressDialog |
| 24 |
{ |
| 25 |
Q_OBJECT |
| 26 |
|
| 27 |
public: |
| 28 |
TimedProgressDialog(QWidget* parent); |
| 29 |
TimedProgressDialog(const QString& labelText = QString(), |
| 30 |
const QString& cancelButtonText = QString(), |
| 31 |
int minimum = 0, int maximum = 100, |
| 32 |
QWidget* parent = nullptr); |
| 33 |
|
| 34 |
/** |
| 35 |
* @brief show the progress dialog and start the timer |
| 36 |
*/ |
| 37 |
void show(); |
| 38 |
|
| 39 |
/** |
| 40 |
* @brief set the default label text |
| 41 |
*/ |
| 42 |
void setLabelText(const QString& labelText) |
| 43 |
{ |
| 44 |
originalLabelText = labelText; |
| 45 |
QProgressDialog::setLabelText(labelText); |
| 46 |
} |
| 47 |
|
| 48 |
public slots: |
| 49 |
/** |
| 50 |
* @brief set the value of the progress dialog |
| 51 |
* and update the time remaining |
| 52 |
*/ |
| 53 |
void setValue(int value); |
| 54 |
|
| 55 |
private: |
| 56 |
/** |
| 57 |
* convert the time to a translatable |
| 58 |
* human-readable string like 2 minutes remaining |
| 59 |
* @param seconds the time in seconds |
| 60 |
*/ |
| 61 |
QString formatTime(double seconds); |
| 62 |
|
| 63 |
QElapsedTimer elapsedTimer; |
| 64 |
QString originalLabelText; |
| 65 |
}; |
| 66 |
|
| 67 |
} // namespace Avogadro::QtGui |
| 68 |
|
| 69 |
#endif // AVOGADRO_QTGUI_TIMEDPROGRESSDIALOG_H |