combo-button-item.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #if defined(Hiro_ComboButton)
  2. namespace hiro {
  3. auto pComboButtonItem::construct() -> void {
  4. if(auto parent = _parent()) {
  5. parent->lock();
  6. parent->qtComboButton->addItem("");
  7. _setState();
  8. parent->unlock();
  9. }
  10. }
  11. auto pComboButtonItem::destruct() -> void {
  12. if(auto parent = _parent()) {
  13. parent->lock();
  14. parent->qtComboButton->removeItem(self().offset());
  15. parent->unlock();
  16. }
  17. }
  18. auto pComboButtonItem::setIcon(const image& icon) -> void {
  19. _setState();
  20. }
  21. auto pComboButtonItem::setSelected() -> void {
  22. _setState();
  23. }
  24. auto pComboButtonItem::setText(const string& text) -> void {
  25. _setState();
  26. }
  27. auto pComboButtonItem::_parent() -> maybe<pComboButton&> {
  28. if(auto parent = self().parentComboButton()) {
  29. if(auto self = parent->self()) return *self;
  30. }
  31. return nothing;
  32. }
  33. auto pComboButtonItem::_setState() -> void {
  34. if(auto parent = _parent()) {
  35. auto lock = parent->acquire();
  36. parent->qtComboButton->setItemIcon(self().offset(), CreateIcon(state().icon));
  37. if(state().selected) parent->qtComboButton->setCurrentIndex(self().offset());
  38. parent->qtComboButton->setItemText(self().offset(), QString::fromUtf8(state().text));
  39. }
  40. }
  41. }
  42. #endif