| 1 |
#if defined(Hiro_CheckButton) |
| 2 |
|
| 3 |
namespace hiro { |
| 4 |
|
| 5 |
auto pCheckButton::construct() -> void { |
| 6 |
qtWidget = qtCheckButton = new QtCheckButton(*this); |
| 7 |
qtCheckButton->setCheckable(true); |
| 8 |
qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextOnly); |
| 9 |
qtCheckButton->connect(qtCheckButton, SIGNAL(toggled(bool)), SLOT(onToggle(bool))); |
| 10 |
|
| 11 |
pWidget::construct(); |
| 12 |
_setState(); |
| 13 |
} |
| 14 |
|
| 15 |
auto pCheckButton::destruct() -> void { |
| 16 |
delete qtCheckButton; |
| 17 |
qtCheckButton = nullptr; |
| 18 |
} |
| 19 |
|
| 20 |
auto pCheckButton::minimumSize() const -> Size { |
| 21 |
auto size = pFont::size(qtWidget->font(), state().text); |
| 22 |
|
| 23 |
if(state().orientation == Orientation::Horizontal) { |
| 24 |
size.setWidth(size.width() + state().icon.width()); |
| 25 |
size.setHeight(max(size.height(), state().icon.height())); |
| 26 |
} |
| 27 |
|
| 28 |
if(state().orientation == Orientation::Vertical) { |
| 29 |
size.setWidth(max(size.width(), state().icon.width())); |
| 30 |
size.setHeight(size.height() + state().icon.height()); |
| 31 |
} |
| 32 |
|
| 33 |
return {size.width() + 20, size.height() + 12}; |
| 34 |
} |
| 35 |
|
| 36 |
auto pCheckButton::setBordered(bool bordered) -> void { |
| 37 |
_setState(); |
| 38 |
} |
| 39 |
|
| 40 |
auto pCheckButton::setChecked(bool checked) -> void { |
| 41 |
_setState(); |
| 42 |
} |
| 43 |
|
| 44 |
auto pCheckButton::setIcon(const image& icon) -> void { |
| 45 |
_setState(); |
| 46 |
} |
| 47 |
|
| 48 |
auto pCheckButton::setOrientation(Orientation orientation) -> void { |
| 49 |
_setState(); |
| 50 |
} |
| 51 |
|
| 52 |
auto pCheckButton::setText(const string& text) -> void { |
| 53 |
_setState(); |
| 54 |
} |
| 55 |
|
| 56 |
auto pCheckButton::_setState() -> void { |
| 57 |
lock(); |
| 58 |
qtCheckButton->setAutoRaise(!state().bordered); |
| 59 |
qtCheckButton->setChecked(state().checked); |
| 60 |
qtCheckButton->setIconSize(QSize(state().icon.width(), state().icon.height())); |
| 61 |
qtCheckButton->setIcon(CreateIcon(state().icon)); |
| 62 |
qtCheckButton->setStyleSheet("text-align: top;"); |
| 63 |
switch(state().orientation) { |
| 64 |
case Orientation::Horizontal: qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); break; |
| 65 |
case Orientation::Vertical: qtCheckButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); break; |
| 66 |
} |
| 67 |
qtCheckButton->setText(QString::fromUtf8(state().text)); |
| 68 |
unlock(); |
| 69 |
} |
| 70 |
|
| 71 |
auto QtCheckButton::onToggle(bool checked) -> void { |
| 72 |
p.state().checked = checked; |
| 73 |
if(!p.locked()) p.self().doToggle(); |
| 74 |
} |
| 75 |
|
| 76 |
} |
| 77 |
|
| 78 |
#endif |