summaryrefslogtreecommitdiffstats
path: root/src/progress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/progress.cpp')
-rw-r--r--src/progress.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/progress.cpp b/src/progress.cpp
new file mode 100644
index 0000000..6d01482
--- /dev/null
+++ b/src/progress.cpp
@@ -0,0 +1,60 @@
+#include "progress.h"
+
+#include <QProgressBar>
+#include <QHBoxLayout>
+#include <QResizeEvent>
+#include <QLabel>
+
+Progress::Progress(QString text, QWidget *parent)
+ : QWidget(parent)
+ , _label(new QLabel(text, this))
+ , _progress(new QProgressBar(this))
+ , _hidden(false)
+{
+ auto *l = new QHBoxLayout(this);
+ l->setMargin(0);
+ setLayout(l);
+ _progress->setRange(0, 100);
+}
+
+Progress::~Progress()
+{
+
+}
+
+void Progress::resizeEvent(QResizeEvent *event)
+{
+ QWidget::resizeEvent(event);
+ auto size = event->size();
+ int width = size.width() - 150;
+ if (width < 250) {
+ width = size.width();
+ _progress->hide();
+ } else if (_progress->value() != -1) {
+ _progress->show();
+ }
+ _label->setMinimumWidth(width);
+}
+
+void Progress::setProgress(int percent)
+{
+ if (percent == -1) {
+ if (!_hidden || _progress->isVisible()) {
+ _hidden = true;
+ _progress->hide();
+ }
+ } else {
+ _progress->setValue(percent);
+ if (_hidden) {
+ _hidden = false;
+ if (_label->width() > 250) {
+ _progress->show();
+ }
+ }
+ }
+}
+
+void Progress::setCaption(const QString &caption)
+{
+ _label->setText(caption);
+}