Wt examples: /home/koen/project/wt/public-git/wt/examples/mission/CountDownWidget.C Source File

Wt examples 3.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

/home/koen/project/wt/public-git/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     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(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 }