| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
Size pCheckButton::minimumSize() { |
| 4 |
Size size = pFont::size(qtWidget->font(), checkButton.state.text); |
| 5 |
|
| 6 |
if(checkButton.state.orientation == Orientation::Horizontal) { |
| 7 |
size.width += checkButton.state.image.width; |
| 8 |
size.height = max(checkButton.state.image.height, size.height); |
| 9 |
} |
| 10 |
|
| 11 |
if(checkButton.state.orientation == Orientation::Vertical) { |
| 12 |
size.width = max(checkButton.state.image.width, size.width); |
| 13 |
size.height += checkButton.state.image.height; |
| 14 |
} |
| 15 |
|
| 16 |
return {size.width + 20, size.height + 12}; |
| 17 |
} |
| 18 |
|
| 19 |
void pCheckButton::setChecked(bool checked) { |
| 20 |
locked = true; |
| 21 |
qtCheckButton->setChecked(checked); |
| 22 |
locked = false; |
| 23 |
} |
| 24 |
|
| 25 |
void pCheckButton::setImage(const image& image, Orientation orientation) { |
| 26 |
qtCheckButton->setIconSize(QSize(image.width, image.height)); |
| 27 |
qtCheckButton->setIcon(CreateIcon(image)); |
| 28 |
qtCheckButton->setStyleSheet("text-align: top;"); |
| 29 |
switch(orientation) { |
| 30 |
case Orientation::Horizontal: qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; |
| 31 |
case Orientation::Vertical: qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
void pCheckButton::setText(string text) { |
| 36 |
qtCheckButton->setText(QString::fromUtf8(text)); |
| 37 |
} |
| 38 |
|
| 39 |
void pCheckButton::constructor() { |
| 40 |
qtWidget = qtCheckButton = new QToolButton; |
| 41 |
qtCheckButton->setCheckable(true); |
| 42 |
qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextOnly); |
| 43 |
connect(qtCheckButton, SIGNAL(toggled(bool)), SLOT(onToggle(bool))); |
| 44 |
|
| 45 |
pWidget::synchronizeState(); |
| 46 |
setChecked(checkButton.state.checked); |
| 47 |
setText(checkButton.state.text); |
| 48 |
} |
| 49 |
|
| 50 |
void pCheckButton::destructor() { |
| 51 |
} |
| 52 |
|
| 53 |
void pCheckButton::orphan() { |
| 54 |
destructor(); |
| 55 |
constructor(); |
| 56 |
} |
| 57 |
|
| 58 |
void pCheckButton::onToggle(bool checked) { |
| 59 |
checkButton.state.checked = checked; |
| 60 |
if(!locked && checkButton.onToggle) checkButton.onToggle(); |
| 61 |
} |
| 62 |
|
| 63 |
} |