LettersWidget.C 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (C) 2011 Emweb bvba, Heverlee, Belgium
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include "LettersWidget.h"
  7. #include <Wt/WPushButton>
  8. #include <Wt/WTable>
  9. #include <Wt/WApplication>
  10. #include <Wt/WEvent>
  11. using namespace Wt;
  12. LettersWidget::LettersWidget(WContainerWidget *parent)
  13. : WCompositeWidget(parent)
  14. {
  15. setImplementation(impl_ = new WTable());
  16. impl_->resize(13*30, WLength::Auto);
  17. for (unsigned int i = 0; i < 26; ++i) {
  18. std::string c(1, 'A' + i);
  19. WPushButton *character = new WPushButton(c,
  20. impl_->elementAt(i / 13, i % 13));
  21. letterButtons_.push_back(character);
  22. character->resize(WLength(30), WLength::Auto);
  23. character->clicked().connect
  24. (boost::bind(&LettersWidget::processButton, this, character));
  25. WApplication::instance()->globalKeyPressed().connect
  26. (boost::bind(&LettersWidget::processButtonPushed, this, _1, character));
  27. }
  28. }
  29. void LettersWidget::processButton(WPushButton *b)
  30. {
  31. b->disable();
  32. letterPushed_.emit(b->text().toUTF8()[0]);
  33. }
  34. void LettersWidget::processButtonPushed(const WKeyEvent &e, WPushButton *b)
  35. {
  36. if(isHidden())
  37. return;
  38. if(e.key() == b->text().toUTF8()[0])
  39. processButton(b);
  40. }
  41. void LettersWidget::reset()
  42. {
  43. for (unsigned int i = 0; i < letterButtons_.size(); ++i)
  44. letterButtons_[i]->enable();
  45. show();
  46. }