Wt examples  3.3.4
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CountDownWidget Class Reference

A widget which displays a decrementing number. More...

#include <CountDownWidget.h>

Inheritance diagram for CountDownWidget:
Inheritance graph
[legend]

Public Member Functions

 CountDownWidget (int start, int stop, unsigned msec, WContainerWidget *parent=0)
 Create a new CountDownWidget. More...
 
Wt::Signal< void > & done ()
 Signal emitted when the countdown reached stop. More...
 
void cancel ()
 Cancel the count down. More...
 

Private Member Functions

void timerTick ()
 Process one timer tick. More...
 

Private Attributes

Wt::Signal< void > done_
 
int start_
 
int stop_
 
int current_
 
WTimer * timer_
 

Detailed Description

A widget which displays a decrementing number.

Definition at line 25 of file CountDownWidget.h.

Constructor & Destructor Documentation

CountDownWidget::CountDownWidget ( int  start,
int  stop,
unsigned  msec,
WContainerWidget *  parent = 0 
)

Create a new CountDownWidget.

The widget will count down from start to stop, decrementing the number every msec milliseconds.

Definition at line 12 of file CountDownWidget.C.

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 }
void timerTick()
Process one timer tick.
Wt::Signal< void > done_

Member Function Documentation

void CountDownWidget::cancel ( )

Cancel the count down.

Definition at line 30 of file CountDownWidget.C.

31 {
32  timer_->stop();
33 }
Wt::Signal<void>& CountDownWidget::done ( )
inline

Signal emitted when the countdown reached stop.

Definition at line 38 of file CountDownWidget.h.

38 { return done_; }
Wt::Signal< void > done_
void CountDownWidget::timerTick ( )
private

Process one timer tick.

Definition at line 35 of file CountDownWidget.C.

36 {
37  setText(boost::lexical_cast<std::string>(--current_));
38 
39  if (current_ <= stop_) {
40  timer_->stop();
41  done_.emit();
42  }
43 }
Wt::Signal< void > done_

Member Data Documentation

int CountDownWidget::current_
private

Definition at line 49 of file CountDownWidget.h.

Wt::Signal<void> CountDownWidget::done_
private

Definition at line 45 of file CountDownWidget.h.

int CountDownWidget::start_
private

Definition at line 46 of file CountDownWidget.h.

int CountDownWidget::stop_
private

Definition at line 47 of file CountDownWidget.h.

WTimer* CountDownWidget::timer_
private

Definition at line 51 of file CountDownWidget.h.


The documentation for this class was generated from the following files:

Generated on Thu Nov 12 2015 for the C++ Web Toolkit (Wt) by doxygen 1.8.9.1