summaryrefslogtreecommitdiffstats
path: root/src/widget/wcombobox.cpp
blob: 5bf9314c8d7083c1bfc042f817d2ccddc62fe349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <QtDebug>
#include <QIcon>

#include "widget/wcombobox.h"

WComboBox::WComboBox(QWidget* pParent)
        : QComboBox(pParent),
          WBaseWidget(this) {
    connect(this, SIGNAL(currentIndexChanged(int)),
            this, SLOT(slotCurrentIndexChanged(int)));
}

void WComboBox::setup(const QDomNode& node, const SkinContext& context) {
    // Load pixmaps for associated states
    QDomNode state = context.selectNode(node, "State");
    while (!state.isNull()) {
        if (state.isElement() && state.nodeName() == "State") {
            int iState = 0;
            if (context.hasNodeSelectInt(state, "Number", &iState)) {
                QString text = context.selectString(state, "Text");
                QString icon = context.selectString(state, "Icon");
                addItem(QIcon(icon), text, QVariant(iState));
            } else {
                SKIN_WARNING(state, context)
                        << "WComboBox ignoring <State> without <Number> node.";
            }
        }
        state = state.nextSibling();
    }
}

bool WComboBox::event(QEvent* pEvent) {
    if (pEvent->type() == QEvent::ToolTip) {
        updateTooltip();
    }
    return QComboBox::event(pEvent);
}

void WComboBox::onConnectedControlChanged(double dParameter, double dValue) {
    Q_UNUSED(dParameter);
    // Enums are not currently represented using parameter space so it doesn't
    // make sense to use the parameter here yet.
    int index = findData(static_cast<int>(dValue));
    if (index != -1) {
        setCurrentIndex(index);
    }
}

void WComboBox::slotCurrentIndexChanged(int index) {
    setControlParameter(index);
}