2013-03-15 13:11:33 +00:00
|
|
|
namespace phoenix {
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pComboButton::append(string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
locked = true;
|
|
|
|
qtComboButton->addItem(QString::fromUtf8(text));
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size pComboButton::minimumSize() {
|
|
|
|
unsigned maximumWidth = 0;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& text : comboButton.state.text) maximumWidth = max(maximumWidth, pFont::size(qtWidget->font(), text).width);
|
2013-03-15 13:11:33 +00:00
|
|
|
Size size = pFont::size(qtWidget->font(), " ");
|
|
|
|
return {maximumWidth + 32, size.height + 12};
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
void pComboButton::modify(unsigned row, string text) {
|
2013-03-15 13:11:33 +00:00
|
|
|
qtComboButton->setItemText(row, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::remove(unsigned row) {
|
|
|
|
locked = true;
|
|
|
|
unsigned position = selection();
|
|
|
|
qtComboButton->removeItem(row);
|
|
|
|
if(position == row) qtComboButton->setCurrentIndex(0);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::reset() {
|
|
|
|
locked = true;
|
|
|
|
while(qtComboButton->count()) qtComboButton->removeItem(0);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned pComboButton::selection() {
|
|
|
|
signed index = qtComboButton->currentIndex();
|
|
|
|
return index >= 0 ? index : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::setSelection(unsigned row) {
|
|
|
|
locked = true;
|
|
|
|
qtComboButton->setCurrentIndex(row);
|
|
|
|
locked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::constructor() {
|
|
|
|
qtWidget = qtComboButton = new QComboBox;
|
|
|
|
connect(qtComboButton, SIGNAL(currentIndexChanged(int)), SLOT(onChange()));
|
|
|
|
|
|
|
|
pWidget::synchronizeState();
|
|
|
|
unsigned selection = comboButton.state.selection;
|
|
|
|
locked = true;
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& text : comboButton.state.text) append(text);
|
2013-03-15 13:11:33 +00:00
|
|
|
locked = false;
|
|
|
|
setSelection(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::destructor() {
|
|
|
|
delete qtComboButton;
|
|
|
|
qtWidget = qtComboButton = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::orphan() {
|
|
|
|
destructor();
|
|
|
|
constructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pComboButton::onChange() {
|
|
|
|
comboButton.state.selection = selection();
|
|
|
|
if(locked == false && comboButton.onChange) comboButton.onChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|