blob: f9787fb6a605694d93c65638a2152ace0cbf9a11 (
plain) (
blame)
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
|
// Copyright 2013, University of Freiburg,
// Author: Manuel Schneider <ms1144>
#include "timeoutdialog.h"
#include <QProgressBar>
#include <QDebug>
TimeOutDialog::TimeOutDialog(int time, QWidget *parent)
: QProgressDialog(parent), _time(time)
{
QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update()));
QObject::connect(this, SIGNAL(canceled()), this, SLOT(cancel()));
// QProgressDialog takes ownership of QProgressBar
QProgressBar *qbar = new QProgressBar(this);
qbar->setFormat(trUtf8("%v seconds"));
qbar->setMaximum(_time);
qbar->setMinimum(0);
qbar->setValue(_time);
setBar(qbar);
_timer.start(1000);
}
void TimeOutDialog::hideEvent(QHideEvent *e)
{
QProgressDialog::hideEvent(e);
_timer.stop();
}
//___________________________________________________________________________
void TimeOutDialog::update()
{
--_time;
if (_time == 0) {
_timer.stop();
accept();
} else {
setValue(_time);
}
}
//___________________________________________________________________________
void TimeOutDialog::cancel()
{
_timer.stop();
}
|