Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/intfield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qintvalidator></qintvalidator>
Toshihiro Shimizu 890ddd
#include <qslider></qslider>
Toshihiro Shimizu 890ddd
#include <qhboxlayout></qhboxlayout>
Toshihiro Shimizu 890ddd
#include <qaction></qaction>
Toshihiro Shimizu 890ddd
#include <qfocusevent></qfocusevent>
Toshihiro Shimizu 890ddd
#include <qpainter></qpainter>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// RollerField
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
RollerField::RollerField(QWidget *parent)
Toshihiro Shimizu 890ddd
	: QWidget(parent), m_value(0), m_minValue(-100000.0), m_maxValue(100000.0), m_xPos(0), m_step(1.0)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setMinimumSize(43, 7);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::setValue(double value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_value == value)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	if (value < m_minValue)
Toshihiro Shimizu 890ddd
		m_value = m_minValue;
Toshihiro Shimizu 890ddd
	if (value > m_maxValue)
Toshihiro Shimizu 890ddd
		m_value = m_maxValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_value = value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
double RollerField::getValue() const
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_value;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::setRange(double minValue, double maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_minValue = minValue;
Toshihiro Shimizu 890ddd
	m_maxValue = maxValue;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::getRange(double &minValue, double &maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	minValue = m_minValue;
Toshihiro Shimizu 890ddd
	maxValue = m_maxValue;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::paintEvent(QPaintEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QPainter p(this);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int w = width();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	drawArrow(p, QPointF(3, 3), QPointF(5, 5), QPointF(5, 1), true, Qt::black, Qt::black);
Toshihiro Shimizu 890ddd
	drawArrow(p, QPointF(w - 4, 3), QPointF(w - 6, 5), QPointF(w - 6, 1), true, Qt::black, Qt::black);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	p.drawLine(QPoint(3, 3), QPoint(w - 4, 3));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::mousePressEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (e->buttons() == Qt::LeftButton) {
Toshihiro Shimizu 890ddd
		m_xPos = e->pos().x();
Toshihiro Shimizu 890ddd
		e->accept();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::mouseMoveEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (e->buttons() == Qt::LeftButton) {
Toshihiro Shimizu 890ddd
		if (m_xPos < e->pos().x())
Toshihiro Shimizu 890ddd
			addValue(true);
Toshihiro Shimizu 890ddd
		else if (m_xPos > e->pos().x())
Toshihiro Shimizu 890ddd
			removeValue(true);
Toshihiro Shimizu 890ddd
		m_xPos = e->pos().x();
Toshihiro Shimizu 890ddd
		e->accept();
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::mouseReleaseEvent(QMouseEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	e->accept();
Toshihiro Shimizu 890ddd
	emit valueChanged(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::addValue(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double newValue = tcrop(m_value + m_step, m_minValue, m_maxValue);
Toshihiro Shimizu 890ddd
	if (newValue == m_value)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_value = newValue;
Toshihiro Shimizu 890ddd
	emit valueChanged(isDragging);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RollerField::removeValue(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double newValue = tcrop(m_value - m_step, m_minValue, m_maxValue);
Toshihiro Shimizu 890ddd
	if (newValue == m_value)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_value = newValue;
Toshihiro Shimizu 890ddd
	emit valueChanged(isDragging);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// IntLineEdit
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IntLineEdit::IntLineEdit(QWidget *parent,
Toshihiro Shimizu 890ddd
						 int value,
Toshihiro Shimizu 890ddd
						 int minValue, int maxValue,
Toshihiro Shimizu 890ddd
						 int showedDigits)
Toshihiro Shimizu 890ddd
	: LineEdit(parent), m_showedDigits(showedDigits)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setFixedWidth(54);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_validator = new QIntValidator(this);
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
	setRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	setValidator(m_validator);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::setValue(int value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	if (value < minValue)
Toshihiro Shimizu 890ddd
		value = minValue;
Toshihiro Shimizu 890ddd
	if (value > maxValue)
Toshihiro Shimizu 890ddd
		value = maxValue;
Toshihiro Shimizu 890ddd
	QString str;
Toshihiro Shimizu 890ddd
	str.setNum(value);
Toshihiro Shimizu 890ddd
	if (m_showedDigits > 0) {
Toshihiro Shimizu 890ddd
		while (str.length() < m_showedDigits)
Toshihiro Shimizu 890ddd
			str.push_front("0");
Toshihiro Shimizu 890ddd
		while (str.length() > m_showedDigits)
Toshihiro Shimizu 890ddd
			str.remove(0, 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setText(str);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa da visualizzare
Toshihiro Shimizu 890ddd
	//e' piu' lunga del campo le cifre che vengono troncate sono le ultime e non le prime.
Toshihiro Shimizu 890ddd
	setCursorPosition(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int IntLineEdit::getValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return text().toInt();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::setRange(int minValue, int maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_validator->setRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::getRange(int &minValue, int &maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	minValue = m_validator->bottom();
Toshihiro Shimizu 890ddd
	maxValue = m_validator->top();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::setBottomRange(int minValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_validator->setBottom(minValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::setTopRange(int maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_validator->setTop(maxValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntLineEdit::focusOutEvent(QFocusEvent *e)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int value = getValue();
Toshihiro Shimizu 890ddd
	int minValue, maxValue;
Toshihiro Shimizu 890ddd
	getRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (e->lostFocus())
Toshihiro Shimizu 890ddd
		setValue(value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QLineEdit::focusOutEvent(e);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// for fps edit in flip console
Toshihiro Shimizu 890ddd
void IntLineEdit::setLineEditBackgroundColor(QColor color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	QString sheet = QString("background-color: rgb(") + QString::number(color.red()) + QString(",") + QString::number(color.green()) + QString(",") + QString::number(color.blue()) + QString(",") + QString::number(color.alpha()) + QString(");");
Toshihiro Shimizu 890ddd
	setStyleSheet(sheet);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// IntField
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
IntField::IntField(QWidget *parent, bool isMaxRangeLimited, bool isRollerHide)
Toshihiro Shimizu 890ddd
	: QWidget(parent), m_lineEdit(0), m_slider(0), m_roller(0), m_isMaxRangeLimited(isMaxRangeLimited)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setObjectName("IntField");
Toshihiro Shimizu 890ddd
	QHBoxLayout *layout = new QHBoxLayout(this);
Toshihiro Shimizu 890ddd
	layout->setMargin(0);
Toshihiro Shimizu 890ddd
	layout->setSpacing(5);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QWidget *field = new QWidget(this);
Toshihiro Shimizu 890ddd
	field->setMaximumWidth(43);
Toshihiro Shimizu 890ddd
	QVBoxLayout *vLayout = new QVBoxLayout(field);
Toshihiro Shimizu 890ddd
	vLayout->setMargin(0);
Toshihiro Shimizu 890ddd
	vLayout->setSpacing(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_lineEdit = new IntLineEdit(field);
Toshihiro Shimizu 890ddd
	bool ret = connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
Toshihiro Shimizu 890ddd
	vLayout->addWidget(m_lineEdit);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_roller = new RollerField(field);
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_roller, SIGNAL(valueChanged(bool)), this, SLOT(onRollerValueChanged(bool)));
Toshihiro Shimizu 890ddd
	vLayout->addWidget(m_roller);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (isRollerHide)
Toshihiro Shimizu 890ddd
		enableRoller(false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	layout->addWidget(field);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_slider = new QSlider(Qt::Horizontal, this);
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int)));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this, SLOT(onSliderReleased()));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_lineEdit, SIGNAL(editingFinished()), this, SIGNAL(valueEditedByHand()));
Toshihiro Shimizu 890ddd
	ret = ret && connect(m_slider, SIGNAL(sliderReleased()), this, SIGNAL(valueEditedByHand()));
Toshihiro Shimizu 890ddd
	layout->addWidget(m_slider);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setValues(0, 0, 100);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	setLayout(layout);
Toshihiro Shimizu 890ddd
	assert(ret);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::getRange(int &minValue, int &maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double min, max;
Toshihiro Shimizu 890ddd
	m_roller->getRange(min, max);
Toshihiro Shimizu 890ddd
	minValue = tround(min);
Toshihiro Shimizu 890ddd
	maxValue = tround(max);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::setRange(int minValue, int maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_lineEdit->setRange(minValue, m_isMaxRangeLimited ? maxValue : (std::numeric_limits<int>::max)());</int>
Toshihiro Shimizu 890ddd
	m_slider->setRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	m_roller->setRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::setValue(int value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_lineEdit->getValue() == value)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_lineEdit->setValue(value);
Toshihiro Shimizu 890ddd
	m_slider->setSliderPosition(value);
Toshihiro Shimizu 890ddd
	m_roller->setValue((double)value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int IntField::getValue()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return (m_lineEdit->getValue());
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::setValues(int value, int minValue, int maxValue)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setRange(minValue, maxValue);
Toshihiro Shimizu 890ddd
	setValue(value);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::enableSlider(bool enable)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_slider->setEnabled(enable);
Toshihiro Shimizu 890ddd
	if (enable)
Toshihiro Shimizu 890ddd
		m_slider->show();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_slider->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool IntField::sliderIsEnabled()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_slider->isEnabled();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::enableRoller(bool enable)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_roller->setEnabled(enable);
Toshihiro Shimizu 890ddd
	if (enable)
Toshihiro Shimizu 890ddd
		m_roller->show();
Toshihiro Shimizu 890ddd
	else
Toshihiro Shimizu 890ddd
		m_roller->hide();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool IntField::rollerIsEnabled()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_roller->isEnabled();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::setLineEditBackgroundColor(QColor color)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_lineEdit->setLineEditBackgroundColor(color);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::onSliderChanged(int value)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	//Controllo necessario per evitare che il segnale di cambiamento venga emesso piu' volte.
Toshihiro Shimizu 890ddd
	if (m_lineEdit->getValue() == value ||
Toshihiro Shimizu 890ddd
		((int)m_roller->getValue() == value && m_roller->isVisible()))
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_lineEdit->setValue(value);
Toshihiro Shimizu 890ddd
	m_roller->setValue((double)value);
Toshihiro Shimizu 890ddd
	//Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa
Toshihiro Shimizu 890ddd
	//da visualizzare e' piu' lunga del campo le cifre che vengono troncate sono
Toshihiro Shimizu 890ddd
	//le ultime e non le prime (dovrebbero essere quelle dopo la virgola).
Toshihiro Shimizu 890ddd
	m_lineEdit->setCursorPosition(0);
Toshihiro Shimizu 890ddd
	emit valueChanged(true);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::onEditingFinished()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	double value = m_lineEdit->getValue();
Toshihiro Shimizu 890ddd
	//Controllo necessario per evitare che il segnale di cambiamento venga emesso piu' volte.
Toshihiro Shimizu 890ddd
	if ((m_slider->value() == value && m_slider->isVisible()) ||
Toshihiro Shimizu 890ddd
		(int)m_roller->getValue() == value && m_roller->isVisible())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_slider->setValue(value);
Toshihiro Shimizu 890ddd
	m_roller->setValue((double)value);
Toshihiro Shimizu 890ddd
	emit valueChanged(false);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void IntField::onRollerValueChanged(bool isDragging)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	int value = m_roller->getValue();
Toshihiro Shimizu 890ddd
	if (value == m_lineEdit->getValue()) {
Toshihiro Shimizu 890ddd
		assert(m_slider->value() == value || !m_slider->isVisible());
Toshihiro Shimizu 890ddd
		// Se isDragging e' falso e' giusto che venga emessa la notifica di cambiamento.
Toshihiro Shimizu 890ddd
		if (!isDragging)
Toshihiro Shimizu 890ddd
			emit valueChanged(isDragging);
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	m_slider->setValue(value);
Toshihiro Shimizu 890ddd
	m_lineEdit->setValue(value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//Faccio in modo che il cursore sia sulla prima cifra, cosi' se la stringa
Toshihiro Shimizu 890ddd
	//da visualizzare e' piu' lunga del campo le cifre che vengono troncate sono
Toshihiro Shimizu 890ddd
	//le ultime e non le prime (dovrebbero essere quelle dopo la virgola).
Toshihiro Shimizu 890ddd
	m_lineEdit->setCursorPosition(0);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	emit valueChanged(isDragging);
Toshihiro Shimizu 890ddd
}