CountDownWidget Class Reference
[Timer example]

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

#include <CountDownWidget.h>

Inheritance diagram for CountDownWidget:

Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Private Member Functions

void timerTick ()
 Process one timer tick.

Private Attributes

Wt::Signal< void > done_
int start_
int stop_
unsigned msec_
int current_
WTimertimer_


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.

00014   : WText(parent),
00015     done_(this),
00016     start_(start),
00017     stop_(stop)
00018 {
00019   stop_ = std::min(start_ - 1, stop_);  // stop must be smaller than start
00020   current_ = start_;
00021 
00022   timer_ = new WTimer(this);
00023   timer_->setInterval(msec);
00024   timer_->timeout().connect(SLOT(this, CountDownWidget::timerTick));
00025   timer_->start();
00026 
00027   setText(boost::lexical_cast<std::string>(current_));
00028 }


Member Function Documentation

Wt::Signal<void>& CountDownWidget::done (  )  [inline]

Signal emitted when the countdown reached stop.

Definition at line 38 of file CountDownWidget.h.

00038 { return done_; }

void CountDownWidget::cancel (  ) 

Cancel the count down.

Definition at line 30 of file CountDownWidget.C.

00031 {
00032   timer_->stop();
00033 }

void CountDownWidget::timerTick (  )  [private]

Process one timer tick.

Definition at line 35 of file CountDownWidget.C.

00036 {
00037   setText(boost::lexical_cast<std::string>(--current_));
00038 
00039   if (current_ <= stop_) {
00040     timer_->stop();
00041     done_.emit();
00042   }
00043 }


Member Data Documentation

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.

unsigned CountDownWidget::msec_ [private]

Definition at line 48 of file CountDownWidget.h.

Definition at line 50 of file CountDownWidget.h.

Definition at line 52 of file CountDownWidget.h.


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

Generated on Fri Mar 26 17:12:12 2010 for Wt by doxygen 1.5.6