| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
Size pRadioLabel::minimumSize() { |
| 4 |
Size size = pFont::size(qtWidget->font(), radioLabel.state.text); |
| 5 |
return {size.width + 26, size.height + 6}; |
| 6 |
} |
| 7 |
|
| 8 |
void pRadioLabel::setChecked() { |
| 9 |
parent().locked = true; |
| 10 |
for(auto& item : radioLabel.state.group) { |
| 11 |
bool checked = &item == &radioLabel; |
| 12 |
item.p.qtRadioLabel->setChecked(item.state.checked = checked); |
| 13 |
} |
| 14 |
parent().locked = false; |
| 15 |
} |
| 16 |
|
| 17 |
void pRadioLabel::setGroup(const group<RadioLabel>& group) { |
| 18 |
parent().locked = true; |
| 19 |
for(auto& item : radioLabel.state.group) { |
| 20 |
item.p.qtRadioLabel->setChecked(item.state.checked); |
| 21 |
} |
| 22 |
parent().locked = false; |
| 23 |
} |
| 24 |
|
| 25 |
void pRadioLabel::setText(string text) { |
| 26 |
qtRadioLabel->setText(QString::fromUtf8(text)); |
| 27 |
} |
| 28 |
|
| 29 |
pRadioLabel& pRadioLabel::parent() { |
| 30 |
if(radioLabel.state.group.size()) return radioLabel.state.group.first().p; |
| 31 |
return *this; |
| 32 |
} |
| 33 |
|
| 34 |
void pRadioLabel::constructor() { |
| 35 |
qtWidget = qtRadioLabel = new QRadioButton; |
| 36 |
qtRadioLabel->setAutoExclusive(false); |
| 37 |
connect(qtRadioLabel, SIGNAL(toggled(bool)), SLOT(onActivate())); |
| 38 |
|
| 39 |
pWidget::synchronizeState(); |
| 40 |
setGroup(radioLabel.state.group); |
| 41 |
setText(radioLabel.state.text); |
| 42 |
} |
| 43 |
|
| 44 |
void pRadioLabel::destructor() { |
| 45 |
if(qtRadioLabel) delete qtRadioLabel; |
| 46 |
qtWidget = qtRadioLabel = nullptr; |
| 47 |
} |
| 48 |
|
| 49 |
void pRadioLabel::orphan() { |
| 50 |
destructor(); |
| 51 |
constructor(); |
| 52 |
} |
| 53 |
|
| 54 |
void pRadioLabel::onActivate() { |
| 55 |
if(parent().locked) return; |
| 56 |
bool wasChecked = radioLabel.state.checked; |
| 57 |
setChecked(); |
| 58 |
if(!wasChecked) { |
| 59 |
if(radioLabel.onActivate) radioLabel.onActivate(); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
} |