00001
00002
00003
00004
00005
00006
00007 #include <boost/lexical_cast.hpp>
00008
00009 #include <Wt/WTimer>
00010 #include "CountDownWidget.h"
00011
00012 CountDownWidget::CountDownWidget(int start, int stop, unsigned msec,
00013 WContainerWidget *parent)
00014 : WText(parent),
00015 done_(this),
00016 start_(start),
00017 stop_(stop)
00018 {
00019 stop_ = std::min(start_ - 1, stop_);
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 }
00029
00030 void CountDownWidget::cancel()
00031 {
00032 timer_->stop();
00033 }
00034
00035 void CountDownWidget::timerTick()
00036 {
00037 setText(boost::lexical_cast<std::string>(--current_));
00038
00039 if (current_ <= stop_) {
00040 timer_->stop();
00041 done_.emit();
00042 }
00043 }