summaryrefslogtreecommitdiffstats
path: root/src/widget/wcombobox.cpp
blob: 45c1f87c2300e72a13b42ff8d6cae2df2684f0f5 (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
52
#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") {
            if (!context.hasNode(state, "Number")) {
                SKIN_WARNING(state, context)
                        << "WComboBox ignoring <State> without <Number> node.";
                continue;
            }

            int iState = context.selectInt(state, "Number");
            QString text = context.selectString(state, "Text");
            QString icon = context.selectString(state, "Icon");
            addItem(QIcon(icon), text, QVariant(iState));
        }
        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);
}