ParamWidget.cc 4.16 KB
Newer Older
1 2
#include "ParamWidget.h"

3
ParamWidget::ParamWidget(QString param,QWidget *parent) : QWidget(parent)
4 5
{
    ui.setupUi(this);
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
    m_param = param;

    connect(ui.doubleSpinBox,SIGNAL(editingFinished()),this,SLOT(doubleSpinEditFinished()));
    connect(ui.intSpinBox,SIGNAL(editingFinished()),this,SLOT(intSpinEditFinished()));
    connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
    connect(ui.valueSlider,SIGNAL(sliderReleased()),this,SLOT(valueSliderReleased()));
}
void ParamWidget::doubleSpinEditFinished()
{
    ui.valueSlider->setValue(((ui.doubleSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
    emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
}

void ParamWidget::intSpinEditFinished()
{
    ui.valueSlider->setValue(((ui.intSpinBox->value() - m_min) / (m_max - m_min)) * 100.0);
    emit intValueChanged(m_param,ui.intSpinBox->value());
}

void ParamWidget::comboIndexChanged(int index)
{
    emit intValueChanged(m_param,m_valueList[index].first);
}

void ParamWidget::valueSliderReleased()
{
    //Set the spin box, and emit a signal.
    if (type == INT)
    {
        ui.intSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
        emit intValueChanged(m_param,ui.intSpinBox->value());
    }
    else if (type == DOUBLE)
    {
        ui.doubleSpinBox->setValue(((ui.valueSlider->value() / 100.0) * (m_max - m_min)) + m_min);
        emit doubleValueChanged(m_param,ui.doubleSpinBox->value());
    }
43 44 45 46 47 48 49 50
}

ParamWidget::~ParamWidget()
{
}

void ParamWidget::setupInt(QString title,QString description,int value,int min,int max)
{
51 52
    Q_UNUSED(value);
    
53 54 55 56 57 58 59
    type = INT;
    ui.titleLabel->setText("<h3>" + title + "</h3>");
    ui.descriptionLabel->setText(description);
    ui.valueComboBox->hide();
    ui.valueSlider->show();
    ui.intSpinBox->show();
    ui.doubleSpinBox->hide();
60 61 62 63 64 65 66 67 68 69 70 71
    if (min == 0 && max == 0)
    {
        m_min = 0;
        m_max = 65535;
    }
    else
    {
        m_min = min;
        m_max = max;
    }
    ui.intSpinBox->setMinimum(m_min);
    ui.intSpinBox->setMaximum(m_max);
72 73 74 75
}

void ParamWidget::setupDouble(QString title,QString description,double value,double min,double max)
{
76 77
    Q_UNUSED(value);

78 79 80 81 82 83 84
    type = DOUBLE;
    ui.titleLabel->setText("<h3>" + title + "</h3>");
    ui.descriptionLabel->setText(description);
    ui.valueComboBox->hide();
    ui.valueSlider->show();
    ui.intSpinBox->hide();
    ui.doubleSpinBox->show();
85 86 87 88 89 90 91 92 93 94 95 96
    if (min == 0 && max == 0)
    {
        m_min = 0;
        m_max = 65535;
    }
    else
    {
        m_min = min;
        m_max = max;
    }
    ui.doubleSpinBox->setMinimum(m_min);
    ui.doubleSpinBox->setMaximum(m_max);
97 98 99 100 101 102 103 104 105 106 107 108 109
}

void ParamWidget::setupCombo(QString title,QString description,QList<QPair<int,QString> > list)
{
    type = COMBO;
    ui.titleLabel->setText("<h3>" + title + "</h3>");
    ui.descriptionLabel->setText(description);
    ui.valueComboBox->show();
    ui.valueSlider->hide();
    ui.intSpinBox->hide();
    ui.doubleSpinBox->hide();
    m_valueList = list;
    ui.valueComboBox->clear();
110
    disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
111 112 113 114
    for (int i=0;i<m_valueList.size();i++)
    {
        ui.valueComboBox->addItem(m_valueList[i].second);
    }
115
    connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
116 117 118 119 120 121 122
}

void ParamWidget::setValue(double value)
{
    if (type == INT)
    {
        ui.intSpinBox->setValue(value);
123
        ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
124 125 126 127
    }
    else if (type == DOUBLE)
    {
        ui.doubleSpinBox->setValue(value);
128
        ui.valueSlider->setValue(((value - m_min) / (m_max - m_min)) * 100.0);
129 130 131 132 133 134 135
    }
    else if (type == COMBO)
    {
        for (int i=0;i<m_valueList.size();i++)
        {
            if ((int)value == m_valueList[i].first)
            {
136
                disconnect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
137
                ui.valueComboBox->setCurrentIndex(i);
138
                connect(ui.valueComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(comboIndexChanged(int)));
139 140 141 142 143
                return;
            }
        }
    }
}