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