progress.cpp
1.51 KB
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
#include <openbr/openbr.h>
#include "progress.h"
/**** PROGRESS ****/
/*** PUBLIC ***/
br::Progress::Progress(QWidget *parent)
: QStatusBar(parent)
{
setContentsMargins(0, 0, 0, 0);
pbProgress.setVisible(false);
pbProgress.setMaximum(100);
pbProgress.setMinimum(0);
pbProgress.setValue(0);
pbProgress.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
pbProgress.setTextVisible(false);
addWidget(&wSpacer, 1);
addPermanentWidget(&pbProgress);
addPermanentWidget(&lTimeRemaining);
connect(&timer, SIGNAL(timeout()), this, SLOT(checkProgress()));
timer.start(1000);
}
/*** PRIVATE SLOTS ***/
void br::Progress::checkProgress()
{
const int progress = 100 * br_progress();
const bool visible = progress >= 0 && progress < 100;
if (visible) {
showMessage(br_most_recent_message());
pbProgress.setValue(progress);
if (progress > 100) pbProgress.setMaximum(0);
else pbProgress.setMaximum(100);
int s = br_time_remaining();
if (s >= 0) {
int h = s / (60*60);
int m = (s - h*60*60) / 60;
s = (s - h*60*60 - m*60);
lTimeRemaining.setText(QString("%1:%2:%3").arg(h, 2, 10, QLatin1Char('0')).arg(m, 2, 10, QLatin1Char('0')).arg(s, 2, 10, QLatin1Char('0')));
} else {
lTimeRemaining.clear();
}
} else {
clearMessage();
lTimeRemaining.clear();
}
pbProgress.setVisible(visible);
}
#include "moc_progress.cpp"