Wt examples
3.3.3
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
koen
project
wt
public-git
wt
examples
hangman
LettersWidget.C
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
3
*
4
* See the LICENSE file for terms of use.
5
*/
6
7
#include "
LettersWidget.h
"
8
9
#include <Wt/WPushButton>
10
#include <Wt/WTable>
11
#include <Wt/WApplication>
12
#include <Wt/WEvent>
13
14
using namespace
Wt;
15
16
LettersWidget::LettersWidget
(
WContainerWidget
*parent)
17
:
WCompositeWidget
(parent)
18
{
19
setImplementation(
impl_
=
new
WTable
());
20
21
impl_
->
resize
(13*30, WLength::Auto);
22
23
for
(
unsigned
int
i = 0; i < 26; ++i) {
24
std::string c(1,
'A'
+ i);
25
WPushButton
*character =
new
WPushButton
(c,
26
impl_
->
elementAt
(i / 13, i % 13));
27
letterButtons_
.push_back(character);
28
character->
resize
(
WLength
(30), WLength::Auto);
29
30
character->clicked().connect
31
(boost::bind(&
LettersWidget::processButton
,
this
, character));
32
33
WApplication::instance()->globalKeyPressed().connect
34
(boost::bind(&
LettersWidget::processButtonPushed
,
this
, _1, character));
35
}
36
}
37
38
void
LettersWidget::processButton
(
WPushButton
*b)
39
{
40
b->disable();
41
letterPushed_
.
emit
(b->
text
().
toUTF8
()[0]);
42
}
43
44
void
LettersWidget::processButtonPushed
(
WKeyEvent
&e,
WPushButton
*b)
45
{
46
if
(
isHidden
())
47
return
;
48
49
if
(e.
key
() == b->
text
().
toUTF8
()[0])
50
processButton
(b);
51
}
52
53
void
LettersWidget::reset
()
54
{
55
for
(
unsigned
int
i = 0; i <
letterButtons_
.size(); ++i)
56
letterButtons_
[i]->enable();
57
58
show();
59
}
Generated on Tue May 27 2014 for
the C++ Web Toolkit (Wt)
by
1.8.4