menu-item.cpp 847 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #if defined(Hiro_MenuItem)
  2. namespace hiro {
  3. auto pMenuItem::construct() -> void {
  4. qtMenuItem = new QtMenuItem(*this);
  5. qtMenuItem->connect(qtMenuItem, SIGNAL(triggered()), SLOT(onActivate()));
  6. if(auto parent = _parentMenu()) {
  7. parent->qtMenu->addAction(qtMenuItem);
  8. }
  9. if(auto parent = _parentPopupMenu()) {
  10. parent->qtPopupMenu->addAction(qtMenuItem);
  11. }
  12. _setState();
  13. }
  14. auto pMenuItem::destruct() -> void {
  15. delete qtMenuItem;
  16. qtMenuItem = nullptr;
  17. }
  18. auto pMenuItem::setIcon(const image& icon) -> void {
  19. _setState();
  20. }
  21. auto pMenuItem::setText(const string& text) -> void {
  22. _setState();
  23. }
  24. auto pMenuItem::_setState() -> void {
  25. qtMenuItem->setIcon(CreateIcon(state().icon));
  26. qtMenuItem->setText(QString::fromUtf8(state().text));
  27. }
  28. auto QtMenuItem::onActivate() -> void {
  29. p.self().doActivate();
  30. }
  31. }
  32. #endif