summaryrefslogtreecommitdiff
path: root/src/ui/progressBar.cpp
blob: 4d4efad3a001a9730f2031f919b96aeee632e60a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// SPDX-License-Identifier: GPL-2.0-or-later

#include <QLabel>
#include <QPixmap>
#include <QProgressBar>
#include <QPushButton>

#include "fqterm_trace.h"
#include "fqterm_path.h"
#include "progressBar.h"

namespace FQTerm {

ProgressBar::ProgressBar(QWidget *parent, QLabel *label)
  : QProgressBar(parent),
    label_(label),
    isFinished_(false) {
  //DEBUG_FUNC_INFO
  setMaximum(100);
  label_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
  abortButton_ = new QPushButton("Abort", parent);
  abortButton_->setObjectName("Abort");
  abortButton_->hide();
  //m_abort->setText( tr("Abort") );
  abortButton_->setIcon(QPixmap(getPath(RESOURCE) + "pic/messagebox_critical.png"));
  label_->show();
  show();
}

ProgressBar::~ProgressBar() {
  //DEBUG_FUNC_INFO
}

ProgressBar &ProgressBar::setDescription(const QString &text) {
  description_ = text;
  label_->setText(text);

  return  *this;
}

ProgressBar &ProgressBar::setStatus(const QString &text) {
  QString s = description_;
  s += " [";
  s += text;
  s += ']';

  label_->setText(s);
  parentWidget()->adjustSize();

  return  *this;
}

ProgressBar &ProgressBar::setAbortSlot(QObject *receiver, const char *slot) {
  FQ_VERIFY(connect(abortButton_, SIGNAL(clicked()), receiver, slot));
  FQ_VERIFY(connect(abortButton_, SIGNAL(clicked()), this, SLOT(hide())));
  abortButton_->show();

  parentWidget()->adjustSize();

  return  *this;
}

void ProgressBar::setDone() {
  if (!isFinished_) {
    isFinished_ = true;
    abortButton_->setEnabled(false);
    setStatus(tr("Done"));
  } else {
    // then we we're aborted
    setStatus(tr("Aborted"));
  }
}

void ProgressBar::hide() {
  //NOTE naughty

  isFinished_ = true;
  abortButton_->setEnabled(false);
  setStatus(tr("Aborting..."));
}

}  // namespace FQTerm