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