|
Packit Service |
50c9f2 |
/******************************************************************************
|
|
Packit Service |
50c9f2 |
*
|
|
Packit Service |
50c9f2 |
*
|
|
Packit Service |
50c9f2 |
*
|
|
Packit Service |
50c9f2 |
* Copyright (C) 1997-2015 by Dimitri van Heesch.
|
|
Packit Service |
50c9f2 |
*
|
|
Packit Service |
50c9f2 |
* Permission to use, copy, modify, and distribute this software and its
|
|
Packit Service |
50c9f2 |
* documentation under the terms of the GNU General Public License is hereby
|
|
Packit Service |
50c9f2 |
* granted. No representations are made about the suitability of this software
|
|
Packit Service |
50c9f2 |
* for any purpose. It is provided "as is" without express or implied warranty.
|
|
Packit Service |
50c9f2 |
* See the GNU General Public License for more details.
|
|
Packit Service |
50c9f2 |
*
|
|
Packit Service |
50c9f2 |
*/
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
#include "inputint.h"
|
|
Packit Service |
50c9f2 |
#include "helplabel.h"
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
#include <QSpinBox>
|
|
Packit Service |
50c9f2 |
#include <QGridLayout>
|
|
Packit Service |
50c9f2 |
#include <QWheelEvent>
|
|
Packit Service |
50c9f2 |
#include <QTextStream>
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
class NoWheelSpinBox : public QSpinBox
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
protected:
|
|
Packit Service |
50c9f2 |
void wheelEvent(QWheelEvent *e)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
e->ignore();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
};
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
InputInt::InputInt( QGridLayout *layout,int &row,
|
|
Packit Service |
50c9f2 |
const QString & id,
|
|
Packit Service |
50c9f2 |
int defVal, int minVal,int maxVal,
|
|
Packit Service |
50c9f2 |
const QString & docs )
|
|
Packit Service |
50c9f2 |
: m_default(defVal), m_minVal(minVal), m_maxVal(maxVal), m_docs(docs), m_id(id)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
m_lab = new HelpLabel(id);
|
|
Packit Service |
50c9f2 |
m_sp = new NoWheelSpinBox;
|
|
Packit Service |
50c9f2 |
m_sp->setMinimum(minVal);
|
|
Packit Service |
50c9f2 |
m_sp->setMaximum(maxVal);
|
|
Packit Service |
50c9f2 |
m_sp->setSingleStep(1);
|
|
Packit Service |
50c9f2 |
m_val=defVal-1; // force update
|
|
Packit Service |
50c9f2 |
setValue(defVal);
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
layout->addWidget( m_lab, row, 0 );
|
|
Packit Service |
50c9f2 |
layout->addWidget( m_sp, row, 1 );
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
connect(m_sp, SIGNAL(valueChanged(int)),
|
|
Packit Service |
50c9f2 |
this, SLOT(setValue(int)) );
|
|
Packit Service |
50c9f2 |
connect( m_lab, SIGNAL(enter()), SLOT(help()) );
|
|
Packit Service |
50c9f2 |
connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
|
|
Packit Service |
50c9f2 |
row++;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::help()
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
showHelp(this);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::setValue(int val)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
val = qMax(m_minVal,val);
|
|
Packit Service |
50c9f2 |
val = qMin(m_maxVal,val);
|
|
Packit Service |
50c9f2 |
if (val!=m_val)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
m_val = val;
|
|
Packit Service |
50c9f2 |
m_sp->setValue(val);
|
|
Packit Service |
50c9f2 |
m_value = m_val;
|
|
Packit Service |
50c9f2 |
updateDefault();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::updateDefault()
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
if (m_val==m_default || !m_lab->isEnabled())
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
m_lab->setText(QString::fromLatin1("<qt>")+m_id+QString::fromLatin1("
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
else
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
m_lab->setText(QString::fromLatin1("<qt><font color='red'>")+m_id+QString::fromLatin1("</font></qt>"));
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
emit changed();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::setEnabled(bool state)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
m_lab->setEnabled(state);
|
|
Packit Service |
50c9f2 |
m_sp->setEnabled(state);
|
|
Packit Service |
50c9f2 |
updateDefault();
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
QVariant &InputInt::value()
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
return m_value;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::update()
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
setValue(m_value.toInt());
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::reset()
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
setValue(m_default);
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|
|
Packit Service |
50c9f2 |
void InputInt::writeValue(QTextStream &t,QTextCodec *)
|
|
Packit Service |
50c9f2 |
{
|
|
Packit Service |
50c9f2 |
t << m_val;
|
|
Packit Service |
50c9f2 |
}
|
|
Packit Service |
50c9f2 |
|