Wt examples  4.0.0
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.h>
10 #include <Wt/WTable.h>
11 #include <Wt/WApplication.h>
12 #include <Wt/WEvent.h>
13 #include <Wt/WAny.h>
14 
15 using namespace Wt;
16 
19 {
20  impl_ = new WTable();
21  setImplementation(std::unique_ptr<WTable>(impl_));
22 
23  impl_->resize(13*30, WLength::Auto);
24 
25  for (unsigned int i = 0; i < 26; ++i) {
26  std::string c(1, 'A' + i);
27  WPushButton *character
28  = impl_->elementAt(i / 13, i % 13)->addWidget(cpp14::make_unique<WPushButton>(c));
29  letterButtons_.push_back(character);
30  character->resize(WLength(30), WLength::Auto);
31 
32  character->clicked().connect
33  (std::bind(&LettersWidget::processButton, this, character));
34 
35  WApplication::instance()->globalKeyPressed().connect
36  (std::bind(&LettersWidget::processButtonPushed, this, std::placeholders::_1, character));
37  }
38 }
39 
41 {
42  b->disable();
43  letterPushed_.emit(b->text().toUTF8()[0]);
44 }
45 
47 {
48  if(isHidden())
49  return;
50 
51  if(e.key() == static_cast<Key>(b->text().toUTF8()[0]))
52  processButton(b);
53 }
54 
56 {
57  for (auto& letterButton : letterButtons_)
58  letterButton->enable();
59 
60  show();
61 }
Key key() const
EventSignal< WMouseEvent > & clicked()
void disable()
void emit(A...args) const
virtual bool isHidden() const override
Wt::Signals::connection connect(const F &function)
const WString & text() const
std::string toUTF8() const
WTableCell * elementAt(int row, int column)
void processButton(WPushButton *b)
Definition: LettersWidget.C:40
void setImplementation(std::unique_ptr< WWidget > widget)
Signal< char > letterPushed_
Definition: LettersWidget.h:34
virtual void resize(const WLength &width, const WLength &height) override
void processButtonPushed(const WKeyEvent &e, WPushButton *b)
Definition: LettersWidget.C:46
std::vector< WPushButton * > letterButtons_
Definition: LettersWidget.h:32
virtual void addWidget(std::unique_ptr< WWidget > widget)
WTable * impl_
Definition: LettersWidget.h:31

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11