| 1 |
#if defined(Hiro_RadioLabel) |
| 2 |
|
| 3 |
namespace hiro { |
| 4 |
|
| 5 |
auto pRadioLabel::construct() -> void { |
| 6 |
qtWidget = qtRadioLabel = new QtRadioLabel(*this); |
| 7 |
qtRadioLabel->setAutoExclusive(false); |
| 8 |
qtRadioLabel->connect(qtRadioLabel, SIGNAL(toggled(bool)), SLOT(onActivate())); |
| 9 |
|
| 10 |
pWidget::construct(); |
| 11 |
setGroup(state().group); |
| 12 |
_setState(); |
| 13 |
} |
| 14 |
|
| 15 |
auto pRadioLabel::destruct() -> void { |
| 16 |
if(qtRadioLabel) delete qtRadioLabel; |
| 17 |
qtWidget = qtRadioLabel = nullptr; |
| 18 |
} |
| 19 |
|
| 20 |
auto pRadioLabel::minimumSize() const -> Size { |
| 21 |
auto size = pFont::size(qtWidget->font(), state().text); |
| 22 |
return {size.width() + 26, size.height() + 6}; |
| 23 |
} |
| 24 |
|
| 25 |
auto pRadioLabel::setChecked() -> void { |
| 26 |
_setState(); |
| 27 |
} |
| 28 |
|
| 29 |
auto pRadioLabel::setGroup(sGroup group) -> void { |
| 30 |
bool first = true; |
| 31 |
if(auto& group = state().group) { |
| 32 |
group->self()->lock(); |
| 33 |
for(auto& weak : group->state.objects) { |
| 34 |
if(auto object = weak.lock()) { |
| 35 |
if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.get())) { |
| 36 |
if(auto self = radioLabel->self()) { |
| 37 |
self->qtRadioLabel->setChecked(radioLabel->state.checked = first); |
| 38 |
first = false; |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
group->self()->unlock(); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
auto pRadioLabel::setText(const string& text) -> void { |
| 48 |
_setState(); |
| 49 |
} |
| 50 |
|
| 51 |
auto pRadioLabel::_setState() -> void { |
| 52 |
if(auto& group = state().group) { |
| 53 |
group->self()->lock(); |
| 54 |
for(auto& weak : group->state.objects) { |
| 55 |
if(auto object = weak.lock()) { |
| 56 |
if(auto radioLabel = dynamic_cast<mRadioLabel*>(object.get())) { |
| 57 |
if(auto self = radioLabel->self()) { |
| 58 |
self->qtRadioLabel->setChecked(radioLabel->state.checked); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
group->self()->unlock(); |
| 64 |
} |
| 65 |
qtRadioLabel->setText(QString::fromUtf8(state().text)); |
| 66 |
} |
| 67 |
|
| 68 |
auto QtRadioLabel::onActivate() -> void { |
| 69 |
if(auto& group = p.state().group) { |
| 70 |
if(!group->self()->locked()) { |
| 71 |
bool wasChecked = p.state().checked; |
| 72 |
p.self().setChecked(); |
| 73 |
if(!wasChecked) p.self().doActivate(); |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
#endif |