| 1 |
namespace phoenix { |
| 2 |
|
| 3 |
void pComboButton::append(string text) { |
| 4 |
locked = true; |
| 5 |
qtComboButton->addItem(QString::fromUtf8(text)); |
| 6 |
locked = false; |
| 7 |
} |
| 8 |
|
| 9 |
Size pComboButton::minimumSize() { |
| 10 |
unsigned maximumWidth = 0; |
| 11 |
for(auto& text : comboButton.state.text) maximumWidth = max(maximumWidth, pFont::size(qtWidget->font(), text).width); |
| 12 |
Size size = pFont::size(qtWidget->font(), " "); |
| 13 |
return {maximumWidth + 32, size.height + 12}; |
| 14 |
} |
| 15 |
|
| 16 |
void pComboButton::remove(unsigned selection) { |
| 17 |
locked = true; |
| 18 |
qtComboButton->removeItem(selection); |
| 19 |
locked = false; |
| 20 |
|
| 21 |
if(selection == comboButton.state.selection) comboButton.setSelection(0); |
| 22 |
} |
| 23 |
|
| 24 |
void pComboButton::reset() { |
| 25 |
locked = true; |
| 26 |
while(qtComboButton->count()) qtComboButton->removeItem(0); |
| 27 |
locked = false; |
| 28 |
} |
| 29 |
|
| 30 |
void pComboButton::setSelection(unsigned selection) { |
| 31 |
locked = true; |
| 32 |
qtComboButton->setCurrentIndex(selection); |
| 33 |
locked = false; |
| 34 |
} |
| 35 |
|
| 36 |
void pComboButton::setText(unsigned selection, string text) { |
| 37 |
qtComboButton->setItemText(selection, text); |
| 38 |
} |
| 39 |
|
| 40 |
void pComboButton::constructor() { |
| 41 |
qtWidget = qtComboButton = new QComboBox; |
| 42 |
connect(qtComboButton, SIGNAL(currentIndexChanged(int)), SLOT(onChange())); |
| 43 |
|
| 44 |
pWidget::synchronizeState(); |
| 45 |
unsigned selection = comboButton.state.selection; |
| 46 |
locked = true; |
| 47 |
for(auto& text : comboButton.state.text) append(text); |
| 48 |
locked = false; |
| 49 |
comboButton.setSelection(selection); |
| 50 |
} |
| 51 |
|
| 52 |
void pComboButton::destructor() { |
| 53 |
delete qtComboButton; |
| 54 |
qtWidget = qtComboButton = nullptr; |
| 55 |
} |
| 56 |
|
| 57 |
void pComboButton::orphan() { |
| 58 |
destructor(); |
| 59 |
constructor(); |
| 60 |
} |
| 61 |
|
| 62 |
void pComboButton::onChange() { |
| 63 |
comboButton.state.selection = qtComboButton->currentIndex(); |
| 64 |
if(!locked && comboButton.onChange) comboButton.onChange(); |
| 65 |
} |
| 66 |
|
| 67 |
} |