Wt examples  3.7.1
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 <boost/lexical_cast.hpp>
8 
9 #include <Wt/WTimer>
10 #include "CountDownWidget.h"
11 
12 CountDownWidget::CountDownWidget(int start, int stop, unsigned msec,
13  WContainerWidget *parent)
14  : WText(parent),
15  done_(this),
16  start_(start),
17  stop_(stop)
18 {
19  stop_ = std::min(start_ - 1, stop_); // stop must be smaller than start
20  current_ = start_;
21 
22  timer_ = new WTimer(this);
23  timer_->setInterval(msec);
24  timer_->timeout().connect(this, &CountDownWidget::timerTick);
25  timer_->start();
26 
27  setText(boost::lexical_cast<std::string>(current_));
28 }
29 
31 {
32  timer_->stop();
33 }
34 
36 {
37  setText(boost::lexical_cast<std::string>(--current_));
38 
39  if (current_ <= stop_) {
40  timer_->stop();
41  done_.emit();
42  }
43 }
void cancel()
Cancel the count down.
void stop()
void start()
void emit(A... args) const
bool setText(const WString &text)
EventSignal< WMouseEvent > & timeout()
void timerTick()
Process one timer tick.
Wt::Signal< void > done_
CountDownWidget(int start, int stop, unsigned msec, WContainerWidget *parent=0)
Create a new CountDownWidget.
void setInterval(std::chrono::milliseconds interval)

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13