Wt examples  3.3.8
CountDownWidget.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, 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 emit(A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none) const
void cancel()
Cancel the count down.
void stop()
void start()
bool setText(const WString &text)
EventSignal< WMouseEvent > & timeout()
void setInterval(int msec)
void timerTick()
Process one timer tick.
Wt::Signal< void > done_
CountDownWidget(int start, int stop, unsigned msec, WContainerWidget *parent=0)
Create a new CountDownWidget.

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11