| 1 |
#if defined(Hiro_MenuRadioItem) |
| 2 |
|
| 3 |
namespace hiro { |
| 4 |
|
| 5 |
auto pMenuRadioItem::construct() -> void { |
| 6 |
qtMenuRadioItem = new QtMenuRadioItem(*this); |
| 7 |
qtActionGroup = new QActionGroup(nullptr); |
| 8 |
qtMenuRadioItem->setCheckable(true); |
| 9 |
qtMenuRadioItem->setActionGroup(qtActionGroup); |
| 10 |
qtMenuRadioItem->setChecked(true); |
| 11 |
qtMenuRadioItem->connect(qtMenuRadioItem, SIGNAL(triggered()), SLOT(onActivate())); |
| 12 |
|
| 13 |
if(auto parent = _parentMenu()) { |
| 14 |
parent->qtMenu->addAction(qtMenuRadioItem); |
| 15 |
} |
| 16 |
|
| 17 |
if(auto parent = _parentPopupMenu()) { |
| 18 |
parent->qtPopupMenu->addAction(qtMenuRadioItem); |
| 19 |
} |
| 20 |
|
| 21 |
setGroup(state().group); |
| 22 |
_setState(); |
| 23 |
} |
| 24 |
|
| 25 |
auto pMenuRadioItem::destruct() -> void { |
| 26 |
if(Application::state().quit) return; //TODO: hack |
| 27 |
delete qtMenuRadioItem; |
| 28 |
delete qtActionGroup; |
| 29 |
qtMenuRadioItem = nullptr; |
| 30 |
qtActionGroup = nullptr; |
| 31 |
} |
| 32 |
|
| 33 |
auto pMenuRadioItem::setChecked() -> void { |
| 34 |
_setState(); |
| 35 |
} |
| 36 |
|
| 37 |
auto pMenuRadioItem::setGroup(sGroup group) -> void { |
| 38 |
bool first = true; |
| 39 |
if(auto& group = state().group) { |
| 40 |
for(auto& weak : group->state.objects) { |
| 41 |
if(auto object = weak.lock()) { |
| 42 |
if(auto menuRadioItem = dynamic_cast<mMenuRadioItem*>(object.get())) { |
| 43 |
if(auto self = menuRadioItem->self()) { |
| 44 |
self->qtMenuRadioItem->setChecked(menuRadioItem->state.checked = first); |
| 45 |
first = false; |
| 46 |
} |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
_setState(); |
| 52 |
} |
| 53 |
|
| 54 |
auto pMenuRadioItem::setText(const string& text) -> void { |
| 55 |
_setState(); |
| 56 |
} |
| 57 |
|
| 58 |
auto pMenuRadioItem::_setState() -> void { |
| 59 |
if(auto& group = state().group) { |
| 60 |
if(auto object = group->object(0)) { |
| 61 |
if(auto menuRadioItem = dynamic_cast<mMenuRadioItem*>(object.get())) { |
| 62 |
if(auto self = menuRadioItem->self()) { |
| 63 |
qtMenuRadioItem->setActionGroup(self->qtActionGroup); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
qtMenuRadioItem->setChecked(state().checked); |
| 69 |
qtMenuRadioItem->setText(QString::fromUtf8(state().text)); |
| 70 |
} |
| 71 |
|
| 72 |
auto QtMenuRadioItem::onActivate() -> void { |
| 73 |
if(p.state().checked) return; |
| 74 |
p.self().setChecked(); |
| 75 |
p.self().doActivate(); |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
#endif |