| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
Size pRadioButton::minimumSize() { |
| 4 |
Size size = pFont::size(qtWidget->font(), radioButton.state.text); |
| 5 |
|
| 6 |
if(radioButton.state.orientation == Orientation::Horizontal) { |
| 7 |
size.width += radioButton.state.image.width; |
| 8 |
size.height = max(radioButton.state.image.height, size.height); |
| 9 |
} |
| 10 |
|
| 11 |
if(radioButton.state.orientation == Orientation::Vertical) { |
| 12 |
size.width = max(radioButton.state.image.width, size.width); |
| 13 |
size.height += radioButton.state.image.height; |
| 14 |
} |
| 15 |
|
| 16 |
return {size.width + 20, size.height + 12}; |
| 17 |
} |
| 18 |
|
| 19 |
void pRadioButton::setChecked() { |
| 20 |
parent().locked = true; |
| 21 |
for(auto& item : radioButton.state.group) { |
| 22 |
bool checked = &item.p == this; |
| 23 |
item.p.qtRadioButton->setChecked(item.state.checked = checked); |
| 24 |
} |
| 25 |
parent().locked = false; |
| 26 |
} |
| 27 |
|
| 28 |
void pRadioButton::setGroup(const group<RadioButton>& group) { |
| 29 |
parent().locked = true; |
| 30 |
for(auto& item : radioButton.state.group) { |
| 31 |
item.p.qtRadioButton->setChecked(item.state.checked); |
| 32 |
} |
| 33 |
parent().locked = false; |
| 34 |
} |
| 35 |
|
| 36 |
void pRadioButton::setImage(const image& image, Orientation orientation) { |
| 37 |
qtRadioButton->setIconSize(QSize(image.width, image.height)); |
| 38 |
qtRadioButton->setIcon(CreateIcon(image)); |
| 39 |
qtRadioButton->setStyleSheet("text-align: top;"); |
| 40 |
switch(orientation) { |
| 41 |
case Orientation::Horizontal: qtRadioButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; |
| 42 |
case Orientation::Vertical: qtRadioButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void pRadioButton::setText(string text) { |
| 47 |
qtRadioButton->setText(QString::fromUtf8(text)); |
| 48 |
} |
| 49 |
|
| 50 |
pRadioButton& pRadioButton::parent() { |
| 51 |
if(radioButton.state.group.size()) return radioButton.state.group.first().p; |
| 52 |
return *this; |
| 53 |
} |
| 54 |
|
| 55 |
void pRadioButton::constructor() { |
| 56 |
qtWidget = qtRadioButton = new QToolButton; |
| 57 |
qtRadioButton->setCheckable(true); |
| 58 |
qtRadioButton->setToolButtonStyle(Qt::ToolButtonTextOnly); |
| 59 |
connect(qtRadioButton, SIGNAL(toggled(bool)), SLOT(onActivate())); |
| 60 |
|
| 61 |
pWidget::synchronizeState(); |
| 62 |
setGroup(radioButton.state.group); |
| 63 |
setText(radioButton.state.text); |
| 64 |
} |
| 65 |
|
| 66 |
void pRadioButton::destructor() { |
| 67 |
if(qtRadioButton) delete qtRadioButton; |
| 68 |
qtWidget = qtRadioButton = nullptr; |
| 69 |
} |
| 70 |
|
| 71 |
void pRadioButton::orphan() { |
| 72 |
destructor(); |
| 73 |
constructor(); |
| 74 |
} |
| 75 |
|
| 76 |
void pRadioButton::onActivate() { |
| 77 |
if(parent().locked) return; |
| 78 |
bool wasChecked = radioButton.state.checked; |
| 79 |
setChecked(); |
| 80 |
if(!wasChecked) { |
| 81 |
if(radioButton.onActivate) radioButton.onActivate(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
} |