Public Member Functions | Private Member Functions | Private Attributes

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.

  : WText(parent),
    done_(this),
    start_(start),
    stop_(stop)
{
  stop_ = std::min(start_ - 1, stop_);  // stop must be smaller than start
  current_ = start_;

  timer_ = new WTimer(this);
  timer_->setInterval(msec);
  timer_->timeout().connect(this, &CountDownWidget::timerTick);
  timer_->start();

  setText(boost::lexical_cast<std::string>(current_));
}

Member Function Documentation

void CountDownWidget::cancel (  )

Cancel the count down.

Definition at line 30 of file CountDownWidget.C.

{
  timer_->stop();
}
Wt::Signal<void>& CountDownWidget::done (  ) [inline]

Signal emitted when the countdown reached stop.

Definition at line 38 of file CountDownWidget.h.

{ return done_; }
void CountDownWidget::timerTick (  ) [private]

Process one timer tick.

Definition at line 35 of file CountDownWidget.C.

{
  setText(boost::lexical_cast<std::string>(--current_));

  if (current_ <= stop_) {
    timer_->stop();
    done_.emit();
  }
}

Member Data Documentation

Definition at line 50 of file CountDownWidget.h.

Definition at line 45 of file CountDownWidget.h.

unsigned CountDownWidget::msec_ [private]

Definition at line 48 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.

Definition at line 52 of file CountDownWidget.h.


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

Generated on Fri Jul 8 2011 for the C++ Web Toolkit (Wt) by doxygen 1.7.2