/home/koen/project/wt/cvs/wt/examples/mission/CountDownWidget.C

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
00003  *
00004  * See the LICENSE file for terms of use.
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     start_(start),
00016     stop_(stop)
00017 {
00018   stop_ = std::min(start_ - 1, stop_);  // stop must be smaller than start
00019   current_ = start_;
00020 
00021   timer_ = new WTimer(this);
00022   timer_->setInterval(msec);
00023   timer_->timeout.connect(SLOT(this, CountDownWidget::timerTick));
00024   timer_->start();
00025 
00026   setText(boost::lexical_cast<std::wstring>(current_));
00027 }
00028 
00029 void CountDownWidget::cancel()
00030 {
00031   timer_->stop();
00032 }
00033 
00034 void CountDownWidget::timerTick()
00035 {
00036   setText(boost::lexical_cast<std::wstring>(--current_));
00037 
00038   if (current_ <= stop_) {
00039     timer_->stop();
00040     done.emit();
00041   }
00042 }

Generated on Fri Jul 25 17:05:59 2008 for Wt by doxygen 1.5.3