Wt examples: /home/koen/project/wt/public-git/wt/examples/hangman/LettersWidget.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/hangman/LettersWidget.C
Go to the documentation of this file.

    00001 /*
    00002  * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
    00003  *
    00004  * See the LICENSE file for terms of use.
    00005  */
    00006
    00007 #include "LettersWidget.h"
    00008
    00009 #include <Wt/WPushButton>
    00010 #include <Wt/WTable>
    00011
    00012 using namespace Wt;
    00013
    00014 LettersWidget::LettersWidget(WContainerWidget *parent)
    00015   : WCompositeWidget(parent)
    00016 {
    00017   setImplementation(impl_ = new WTable());
    00018
    00019   impl_->resize(13*30, WLength::Auto);
    00020
    00021   for (unsigned int i = 0; i < 26; ++i) {
    00022     std::string c(1, 'A' + i);
    00023     WPushButton *character = new WPushButton(c,
    00024                                              impl_->elementAt(i / 13, i % 13));
    00025     letterButtons_.push_back(character);
    00026     character->resize(WLength(30), WLength::Auto);
    00027
    00028     character->clicked().connect
    00029       (boost::bind(&LettersWidget::processButton, this, character));
    00030   }
    00031 }
    00032
    00033 void LettersWidget::processButton(WPushButton *b)
    00034 {
    00035   b->disable();
    00036   letterPushed_.emit(b->text().toUTF8()[0]);
    00037 }
    00038
    00039 void LettersWidget::reset()
    00040 {
    00041   for (unsigned int i = 0; i < letterButtons_.size(); ++i)
    00042     letterButtons_[i]->enable();
    00043
    00044   show();
    00045 }