Wt examples
4.11.3
mission
CountDownWidget.C
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2008 Emweb bv, Herent, Belgium.
3
*
4
* See the LICENSE file for terms of use.
5
*/
6
7
#include <Wt/WTimer.h>
8
#include "
CountDownWidget.h
"
9
#include <string>
10
#include <algorithm>
11
12
CountDownWidget::CountDownWidget
(
int
start,
int
stop, std::chrono::milliseconds msec)
13
:
WText
(),
14
done_(),
15
start_(start),
16
stop_(stop)
17
{
18
stop_
= std::min(
start_
- 1,
stop_
);
// stop must be smaller than start
19
current_
=
start_
;
20
21
timer_
= std::make_unique<WTimer>();
22
timer_
->setInterval(msec);
23
timer_
->timeout().connect(
this
, &
CountDownWidget::timerTick
);
24
timer_
->start();
25
26
setText
(std::to_string(
current_
));
27
}
28
29
void
CountDownWidget::cancel
()
30
{
31
timer_
->stop();
32
}
33
34
void
CountDownWidget::timerTick
()
35
{
36
setText
(std::to_string(--
current_
));
37
38
if
(
current_
<=
stop_
) {
39
timer_
->stop();
40
done_
.
emit
();
41
}
42
}
CountDownWidget.h
CountDownWidget::current_
int current_
Definition:
CountDownWidget.h:49
CountDownWidget::start_
int start_
Definition:
CountDownWidget.h:46
CountDownWidget::cancel
void cancel()
Cancel the count down.
Definition:
CountDownWidget.C:29
CountDownWidget::timer_
std::unique_ptr< WTimer > timer_
Definition:
CountDownWidget.h:51
CountDownWidget::timerTick
void timerTick()
Process one timer tick.
Definition:
CountDownWidget.C:34
CountDownWidget::stop_
int stop_
Definition:
CountDownWidget.h:47
CountDownWidget::CountDownWidget
CountDownWidget(int start, int stop, std::chrono::milliseconds msec)
Create a new CountDownWidget.
Definition:
CountDownWidget.C:12
CountDownWidget::done_
Signal done_
Definition:
CountDownWidget.h:45
Wt::Signal::emit
void emit(A... args) const
Wt::WText
Wt::WText::setText
bool setText(const WString &text)
Generated on Wed Feb 19 2025 for
the C++ Web Toolkit (Wt)
by
1.9.1