Subversion Repositories svn1-original

Rev

Rev 318 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#include "twinspinbox.h"
#include "ui_twinspinbox.h"

TwinSpinBox::TwinSpinBox(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::TwinSpinBox),
    populating(false)
{
    ui->setupUi(this);

    connect(ui->spinBoxL,SIGNAL(valueChanged(int)), this, SLOT(adjustL(void)));
    connect(ui->spinBoxU,SIGNAL(valueChanged(int)), this, SLOT(adjustU(void)));

}

TwinSpinBox::~TwinSpinBox()
{
    delete ui;
}

void TwinSpinBox::adjustL(void)
{
    if ( ! populating )
    {
        emit changed();

        populating = true;
        if (ui->spinBoxL->value() > ui->spinBoxU->value())
        {
            ui->spinBoxU->setValue(ui->spinBoxL->value());
        }
        populating = false;
    }
}

void TwinSpinBox::adjustU(void)
{
    if ( ! populating )
    {
        //qDebug("Changed");
        emit changed();

        populating = true;
        if (ui->spinBoxU->value() < ui->spinBoxL->value())
        {
            ui->spinBoxL->setValue(ui->spinBoxU->value());
        }
        populating = false;
    }
}

void TwinSpinBox::setLimits( int lower, int upper)
{
    populating = true;
    ui->spinBoxL->setMinimum(lower);
    ui->spinBoxL->setMaximum(upper);

    ui->spinBoxU->setMinimum(lower);
    ui->spinBoxU->setMaximum(upper);
    populating = false;
}

void TwinSpinBox::setData( int lower, int upper)
{
    populating = true;
    ui->spinBoxL->setValue(lower);
    ui->spinBoxU->setValue(upper);
    populating = false;
}

void TwinSpinBox::getData( short int *lptr, short int *uptr)
{
    if ( lptr )
        *lptr = ui->spinBoxL->value();
    if (uptr)
        *uptr = ui->spinBoxU->value();
}