diff options
Diffstat (limited to 'client/widgets/combobox.cc')
-rw-r--r-- | client/widgets/combobox.cc | 148 |
1 files changed, 63 insertions, 85 deletions
diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index f81d989..5980400 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -25,6 +25,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "combobox.h" + +#include <QComboBox> + #include <QDomNodeList> #include <QCompleter> #include <QRegExpValidator> @@ -32,6 +35,9 @@ #include <QLineEdit> #include <QCoreApplication> +#include <QEvent> +#include <QWheelEvent> + #include "common.h" // Enable this to make the combobox drawn in windows style. @@ -44,15 +50,18 @@ QWindowsStyle s; #endif/*STYLE_HACK*/ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) - : QComboBox(), Widget(node, macrowindow) + : Widget(node, macrowindow) { - setCommonAttributes(this, node); + combobox = new QComboBox(); + widget = combobox; + + setCommonAttributes(combobox, node); #ifdef STYLE_HACK - setStyle(&s); + combobox->setStyle(&s); #endif/*STYLE_HACK*/ - setInsertPolicy(QComboBox::InsertAlphabetically); + combobox->setInsertPolicy(QComboBox::InsertAlphabetically); QDomNodeList children = node.childNodes(); QStringList itemlist; @@ -61,15 +70,16 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) QDomNode child = children.at(i); QDomElement combo_elem = child.toElement(); if(combo_elem.hasAttribute("caption") && combo_elem.hasAttribute("value")) { - addItem(combo_elem.attribute("caption"), combo_elem.attribute("value")); + combobox->addItem(combo_elem.attribute("caption"), + combo_elem.attribute("value")); itemlist << combo_elem.attribute("caption"); } else { - printf("XML Error!!! Combobox item is missing one or more attributes...\n"); + printf("XML Error!!! Combobox is missing one or more attributes...\n"); } } // Make empty default selection. - setCurrentIndex(-1); + combobox->setCurrentIndex(-1); QDomElement elem = node.toElement(); @@ -82,25 +92,26 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) switch(combotype) { case SELECT: - setEditable(false); + combobox->setEditable(false); #ifndef STYLE_HACK - setEditable(true); - lineEdit()->setReadOnly(true); - lineEdit()->installEventFilter(this); + combobox->setEditable(true); + combobox->lineEdit()->setReadOnly(true); + combobox->lineEdit()->installEventFilter(this); #endif/*STYLE_HACK*/ - connect(this, SIGNAL(currentIndexChanged(QString)), this, SLOT(changed())); + connect(combobox, SIGNAL(currentIndexChanged(QString)), + this, SLOT(changed())); break; case EDIT: - setEditable(true); + combobox->setEditable(true); - connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); + connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); break; case SEARCH: - setEditable(true); + combobox->setEditable(true); { QString rxs = "("; for(int i = 0; i < itemlist.size(); i++) { @@ -115,11 +126,11 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) QCompleter *completer = new QCompleter(itemlist, this); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setCompletionMode(QCompleter::PopupCompletion); - setCompleter(completer); - setValidator(new QRegExpValidator(rx, this)); + combobox->setCompleter(completer); + combobox->setValidator(new QRegExpValidator(rx, this)); } - connect(this, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); + connect(combobox, SIGNAL(editTextChanged(QString)), this, SLOT(changed())); break; } @@ -128,14 +139,20 @@ ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) ischangingbyuser = true; } -QString ComboBox::getValue() +ComboBox::~ComboBox() +{ + // delete combobox; +} + +QString ComboBox::value() { QString value; - int idx = currentIndex(); + int idx = combobox->currentIndex(); - if(idx != -1 && itemText(idx) == currentText()) value = itemData(idx).toString(); - else value = currentText(); + if(idx != -1 && combobox->itemText(idx) == combobox->currentText()) + value = combobox->itemData(idx).toString(); + else value = combobox->currentText(); return value; } @@ -144,93 +161,38 @@ void ComboBox::setValue(QString value, QString source) { if(isUserSource(source)) emit wasChanged(); - int idx = findData(value); + int idx = combobox->findData(value); // printf("setValue(\"%s\") - %d\n", value.toStdString().c_str(), idx); ischangingbyuser = false; - setCurrentIndex(idx); + combobox->setCurrentIndex(idx); ischangingbyuser = true; setInitialValue(value); } -bool ComboBox::isValid() +bool ComboBox::preValid() { if(combotype == SELECT) { - if(currentIndex() != -1) return true; + if(combobox->currentIndex() != -1) return true; else return false; } - return rx.exactMatch(currentText()) && luaValidator(); + return true; } void ComboBox::changed() { if(ischangingbyuser) emit wasChanged(); - - QPalette palette; - - if(isEnabled()) { - if(isValid() && luaValidator()) { - // valid string - palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); - } else { - // invalid string - palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); - } - } else { - // valid string - palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); - } - - if(lineEdit()) lineEdit()->setPalette(palette); - else setPalette(palette); -} - -void ComboBox::enable() -{ - setEnabled(true); -} - -void ComboBox::disable() -{ - setEnabled(false); -} - -bool ComboBox::isDisabled() -{ - return isEnabled() == false; -} - -void ComboBox::connectFrom(const char *signal, - const QObject *receiver, const char *method) -{ - connect(this, signal, receiver, method); -} - -void ComboBox::connectTo(const QObject *sender, const char *signal, - const char *method) -{ - connect(sender, signal, this, method); -} - -bool ComboBox::setKeyboardFocus() -{ - setFocus(); - return true; -} - -void ComboBox::setVisibility(bool visible) -{ - setVisible(visible); + eventOnChange(); } bool ComboBox::eventFilter(QObject *obj, QEvent *event) { if(combotype == SELECT) { if(event->type() == QEvent::MouseButtonRelease) { - showPopup(); + combobox->showPopup(); } } @@ -239,7 +201,7 @@ bool ComboBox::eventFilter(QObject *obj, QEvent *event) void ComboBox::wheelEvent(QWheelEvent *e) { - QCoreApplication::sendEvent(nativeParentWidget(), e); + QCoreApplication::sendEvent(combobox->nativeParentWidget(), e); } void ComboBox::changeEvent(QEvent *event) @@ -248,3 +210,19 @@ void ComboBox::changeEvent(QEvent *event) changed(); } } + +void ComboBox::setWdgValid(bool valid) +{ + QPalette palette; + + if(valid) { + // valid string + palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255))); + } else { + // invalid string + palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200))); + } + + if(combobox->lineEdit()) combobox->lineEdit()->setPalette(palette); + combobox->setPalette(palette); +} |