Wt examples  4.10.4
LettersWidget.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011 Emweb bv, Herent, Belgium
3  *
4  * See the LICENSE file for terms of use.
5  */
6 
7 #include "LettersWidget.h"
8 
9 #include <Wt/WApplication.h>
10 #include <Wt/WEvent.h>
11 #include <Wt/WPushButton.h>
12 #include <Wt/WTable.h>
13 
14 using namespace Wt;
15 
17 {
18  impl_ = setNewImplementation<WTable>();
19 
20  impl_->resize(13*30, WLength::Auto);
21 
22  for (unsigned int i = 0; i < 26; ++i) {
23  std::string c(1, 'A' + i);
24  auto character = impl_->elementAt(i / 13, i % 13)->addNew<WPushButton>(c);
25  letterButtons_.push_back(character);
26  character->resize(WLength(30), WLength::Auto);
27 
28  character->clicked().connect
29  (std::bind(&LettersWidget::processButton, this, character));
30 
31  connections_.push_back(WApplication::instance()->globalKeyPressed().connect
32  (std::bind(&LettersWidget::processButtonPushed, this, std::placeholders::_1, character)));
33  }
34 }
35 
37 {
38  for (auto &connection : connections_)
39  connection.disconnect();
40 }
41 
43 {
44  b->disable();
45  letterPushed_.emit(b->text().toUTF8()[0]);
46 }
47 
49 {
50  if (isHidden())
51  return;
52 
53  if(e.key() == static_cast<Key>(b->text().toUTF8()[0]))
54  processButton(b);
55 }
56 
58 {
59  for (auto& letterButton : letterButtons_)
60  letterButton->enable();
61 
62  show();
63 }
void processButton(Wt::WPushButton *b)
Definition: LettersWidget.C:42
virtual ~LettersWidget()
Definition: LettersWidget.C:36
void processButtonPushed(const Wt::WKeyEvent &e, Wt::WPushButton *b)
Definition: LettersWidget.C:48
static WApplication * instance()
EventSignal< WKeyEvent > & globalKeyPressed()
Key key() const
static WLength Auto
const WString & text() const
std::string toUTF8() const
virtual void resize(const WLength &width, const WLength &height) override
void disable()