menu.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #if defined(Hiro_Menu)
  2. namespace hiro {
  3. auto pMenu::construct() -> void {
  4. qtMenu = new QMenu;
  5. if(auto parent = _parentMenu()) {
  6. parent->qtMenu->addMenu(qtMenu);
  7. }
  8. if(auto parent = _parentMenuBar()) {
  9. if(auto window = parent->_parent()) {
  10. window->qtMenuBar->addMenu(qtMenu);
  11. }
  12. }
  13. if(auto parent = _parentPopupMenu()) {
  14. parent->qtPopupMenu->addMenu(qtMenu);
  15. }
  16. _setState();
  17. }
  18. auto pMenu::destruct() -> void {
  19. if(Application::state().quit) return; //TODO: hack
  20. delete qtMenu;
  21. qtMenu = nullptr;
  22. }
  23. auto pMenu::append(sAction action) -> void {
  24. }
  25. auto pMenu::remove(sAction action) -> void {
  26. }
  27. auto pMenu::setIcon(const image& icon) -> void {
  28. _setState();
  29. }
  30. auto pMenu::setText(const string& text) -> void {
  31. _setState();
  32. }
  33. auto pMenu::_setState() -> void {
  34. qtMenu->setEnabled(self().enabled());
  35. qtMenu->setFont(pFont::create(self().font(true)));
  36. qtMenu->setIcon(CreateIcon(state().icon));
  37. qtMenu->setTitle(QString::fromUtf8(state().text));
  38. qtMenu->menuAction()->setVisible(self().visible());
  39. for(auto& action : state().actions) {
  40. if(auto self = action->self()) self->setFont(action->font(true));
  41. }
  42. }
  43. }
  44. #endif