|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <math.h></math.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/doublefield.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tunit.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <qdoublevalidator></qdoublevalidator>
|
|
Toshihiro Shimizu |
890ddd |
#include <qhboxlayout></qhboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
#include <qfocusevent></qfocusevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qslider></qslider>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoubleValueLineEdit
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueLineEdit::focusOutEvent(QFocusEvent *e)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double value = getValue();
|
|
Toshihiro Shimizu |
890ddd |
double minValue, maxValue;
|
|
Toshihiro Shimizu |
890ddd |
getRange(minValue, maxValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool isOutOfRange;
|
|
Toshihiro Shimizu |
890ddd |
/*---誤差を吸収する---*/
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleLineEdit *lineEdit = qobject_cast<measureddoublelineedit *="">(this);</measureddoublelineedit>
|
|
Toshihiro Shimizu |
890ddd |
if (lineEdit) {
|
|
Toshihiro Shimizu |
890ddd |
int decimal = lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
isOutOfRange = (value < minValue - pow(0.1, decimal + 1) ||
|
|
Toshihiro Shimizu |
890ddd |
value > maxValue + pow(0.1, decimal + 1));
|
|
Toshihiro Shimizu |
890ddd |
} else
|
|
Toshihiro Shimizu |
890ddd |
isOutOfRange = (value < minValue || value > maxValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (isOutOfRange) {
|
|
Toshihiro Shimizu |
890ddd |
setValue(tcrop(value, minValue, maxValue));
|
|
Toshihiro Shimizu |
890ddd |
emit editingFinished();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
QLineEdit::focusOutEvent(e);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoubleValueField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DoubleValueField::DoubleValueField(QWidget *parent, DoubleValueLineEdit *lineEdit)
|
|
Toshihiro Shimizu |
890ddd |
: QWidget(parent), m_lineEdit(lineEdit), m_slider(0), m_roller(0)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(m_lineEdit);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
QWidget *field = new QWidget(this);
|
|
Toshihiro Shimizu |
890ddd |
m_roller = new RollerField(field);
|
|
Toshihiro Shimizu |
890ddd |
m_slider = new QSlider(Qt::Horizontal, this);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
field->setMaximumWidth(100);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---layout
|
|
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 |
QVBoxLayout *vLayout = new QVBoxLayout(field);
|
|
Toshihiro Shimizu |
890ddd |
vLayout->setMargin(0);
|
|
Toshihiro Shimizu |
890ddd |
vLayout->setSpacing(0);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
vLayout->addWidget(m_lineEdit);
|
|
Toshihiro Shimizu |
890ddd |
vLayout->addWidget(m_roller);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
layout->addWidget(field);
|
|
Toshihiro Shimizu |
890ddd |
layout->addWidget(m_slider);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
setLayout(layout);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----signal/slot connections
|
|
Toshihiro Shimizu |
890ddd |
bool ret = true;
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(m_lineEdit, SIGNAL(valueChanged()), SLOT(onLineEditValueChanged()));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(m_roller, SIGNAL(valueChanged(bool)), SLOT(onRollerValueChanged(bool)));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(m_slider, SIGNAL(valueChanged(int)), SLOT(onSliderChanged(int)));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(m_slider, SIGNAL(sliderReleased()), SLOT(onSliderReleased()));
|
|
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 |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_spaceWidget = new QWidget();
|
|
Toshihiro Shimizu |
890ddd |
m_spaceWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
Toshihiro Shimizu |
890ddd |
layout->addWidget(m_spaceWidget, 1, Qt::AlignLeft);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setRange(-100.0, 100.0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueField::getRange(double &minValue, double &maxValue)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_lineEdit->getRange(minValue, maxValue);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueField::setRange(double minValue, double maxValue)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_lineEdit->setRange(minValue, maxValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_roller->setRange(minValue, maxValue);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dicimal = m_lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
int sliderMax = maxValue * pow(10., dicimal);
|
|
Toshihiro Shimizu |
890ddd |
int sliderMin = minValue * pow(10., dicimal);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_slider->setRange(sliderMin, sliderMax);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
enableSlider(maxValue - minValue < 10000);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueField::setValue(double 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_roller->setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dicimal = m_lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
int sliderValue = value * pow(10., dicimal);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
m_slider->setValue(sliderValue);
|
|
Toshihiro Shimizu |
890ddd |
//forzo il repaint... non sempre si aggiorna e l'update non sembra risolvere il ptroblema!!!
|
|
Toshihiro Shimizu |
890ddd |
m_slider->repaint();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double DoubleValueField::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 DoubleValueField::setValues(double value, double minValue, double 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 DoubleValueField::enableSlider(bool enable)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_slider->setEnabled(enable);
|
|
Toshihiro Shimizu |
890ddd |
m_spaceWidget->setEnabled(!enable);
|
|
Toshihiro Shimizu |
890ddd |
if (enable) {
|
|
Toshihiro Shimizu |
890ddd |
m_slider->show();
|
|
Toshihiro Shimizu |
890ddd |
m_spaceWidget->hide();
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
m_slider->hide();
|
|
Toshihiro Shimizu |
890ddd |
m_spaceWidget->show();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool DoubleValueField::isSliderEnabled()
|
|
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 DoubleValueField::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 DoubleValueField::isRollerEnabled()
|
|
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 DoubleValueField::onSliderChanged(int value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int dicimal = m_lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
double val = double(value) * pow(0.1, dicimal);
|
|
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() == val ||
|
|
Toshihiro Shimizu |
890ddd |
(m_roller->getValue() == val && m_roller->isVisible()))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_lineEdit->setValue(val);
|
|
Toshihiro Shimizu |
890ddd |
m_roller->setValue(val);
|
|
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(true);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueField::onLineEditValueChanged()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double value = m_lineEdit->getValue();
|
|
Toshihiro Shimizu |
890ddd |
int dicimal = m_lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
double sliderValue = value * pow(10., dicimal);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//Controllo necessario per evitare che il segnale di cambiamento venga emesso piu' volte.
|
|
Toshihiro Shimizu |
890ddd |
if ((m_slider->value() == sliderValue && m_slider->isVisible()) ||
|
|
Toshihiro Shimizu |
890ddd |
(m_roller->getValue() == value && m_roller->isVisible()))
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_slider->setValue(sliderValue);
|
|
Toshihiro Shimizu |
890ddd |
m_roller->setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
emit valueChanged(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleValueField::onRollerValueChanged(bool isDragging)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double value = m_roller->getValue();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int dicimal = m_lineEdit->getDecimals();
|
|
Toshihiro Shimizu |
890ddd |
double sliderValue = value * pow(10., dicimal);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (sliderValue == 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(sliderValue);
|
|
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 |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoubleLineEdit
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DoubleLineEdit::DoubleLineEdit(QWidget *parent, double value)
|
|
Toshihiro Shimizu |
890ddd |
: DoubleValueLineEdit(parent)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_validator = new QDoubleValidator(-(std::numeric_limits<double>::max)(), (std::numeric_limits<double>::max)(), 8, this);</double></double>
|
|
Toshihiro Shimizu |
890ddd |
setValidator(m_validator);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
setValue(value);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool ret = connect(this, SIGNAL(editingFinished()), SIGNAL(valueChanged()));
|
|
Toshihiro Shimizu |
890ddd |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleLineEdit::setValue(double value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
double 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 |
setText(str);
|
|
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 |
setCursorPosition(0);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double DoubleLineEdit::getValue()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return text().toDouble();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleLineEdit::setRange(double minValue, double maxValue)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_validator->setRange(minValue, maxValue, m_validator->decimals());
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void DoubleLineEdit::getRange(double &minValue, double &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 DoubleLineEdit::setDecimals(int decimals)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_validator->setDecimals(decimals);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int DoubleLineEdit::getDecimals()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_validator->decimals();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoubleField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DoubleField::DoubleField(QWidget *parent, bool isRollerHide, int decimals)
|
|
Toshihiro Shimizu |
890ddd |
: DoubleValueField(parent, new DoubleLineEdit(0))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (isRollerHide)
|
|
Toshihiro Shimizu |
890ddd |
enableRoller(false);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DoubleLineEdit *lineEdit = dynamic_cast<doublelineedit *="">(m_lineEdit);</doublelineedit>
|
|
Toshihiro Shimizu |
890ddd |
lineEdit->setDecimals(decimals);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--rollerにもStepを設定--*/
|
|
Toshihiro Shimizu |
890ddd |
if (!isRollerHide)
|
|
Toshihiro Shimizu |
890ddd |
m_roller->setStep(pow(0.1, decimals));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// MeasuredDoubleLineEdit
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleLineEdit::MeasuredDoubleLineEdit(QWidget *parent)
|
|
Toshihiro Shimizu |
890ddd |
: DoubleValueLineEdit(parent), m_minValue(-(std::numeric_limits<double>::max)()), m_maxValue((std::numeric_limits<double>::max)()), m_modified(false), m_errorHighlighting(0), m_errorHighlightingTimerId(0), m_decimals(7)</double></double>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setObjectName("ValueLineEdit");
|
|
Toshihiro Shimizu |
890ddd |
m_value = new TMeasuredValue("length");
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
bool ret = connect(this, SIGNAL(editingFinished()), this, SLOT(onEditingFinished()));
|
|
Toshihiro Shimizu |
890ddd |
ret = ret && connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(onTextChanged(const QString &)));
|
|
Toshihiro Shimizu |
890ddd |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleLineEdit::~MeasuredDoubleLineEdit()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_value;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::valueToText()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
bool oldModified = m_modified;
|
|
Toshihiro Shimizu |
890ddd |
setText(QString::fromStdWString(m_value->toWideString(m_decimals)));
|
|
Toshihiro Shimizu |
890ddd |
setCursorPosition(0);
|
|
Toshihiro Shimizu |
890ddd |
m_modified = oldModified;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::setValue(double value)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_value->setValue(TMeasuredValue::MainUnit, value);
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
m_modified = false;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double MeasuredDoubleLineEdit::getValue()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_value->getValue(TMeasuredValue::MainUnit);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::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 MeasuredDoubleLineEdit::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 |
|
|
Shinya Kitaoka |
3bfa54 |
void MeasuredDoubleLineEdit::setMeasure(std::string name)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
delete m_value;
|
|
Toshihiro Shimizu |
890ddd |
m_value = new TMeasuredValue(name != "" ? name : "dummy");
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::setDecimals(int decimals)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_decimals = decimals;
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int MeasuredDoubleLineEdit::getDecimals()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return m_decimals;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::onTextChanged(const QString &)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_modified = true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::onEditingFinished()
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (!m_modified)
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
m_modified = false;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double oldValue = getValue();
|
|
Toshihiro Shimizu |
890ddd |
QString oldStyleSheet = styleSheet();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int err = -10;
|
|
Toshihiro Shimizu |
890ddd |
m_value->setValue(text().toStdWString(), &err);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
bool outOfRange = false;
|
|
Toshihiro Shimizu |
890ddd |
if (!err) {
|
|
Toshihiro Shimizu |
890ddd |
double v = getValue();
|
|
Toshihiro Shimizu |
890ddd |
outOfRange = m_minValue > v || m_maxValue < v;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (err) {
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlighting = 1;
|
|
Toshihiro Shimizu |
890ddd |
if (m_errorHighlightingTimerId == 0)
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlightingTimerId = startTimer(40);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
if (m_errorHighlightingTimerId != 0)
|
|
Toshihiro Shimizu |
890ddd |
killTimer(m_errorHighlightingTimerId);
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlightingTimerId = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlighting = 0;
|
|
Toshihiro Shimizu |
890ddd |
setStyleSheet("");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double newValue = getValue();
|
|
Toshihiro Shimizu |
890ddd |
if (m_minValue > newValue || m_maxValue < newValue) {
|
|
Toshihiro Shimizu |
890ddd |
m_value->setValue(TMeasuredValue::MainUnit, oldValue);
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
emit valueChanged();
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
valueToText();
|
|
Toshihiro Shimizu |
890ddd |
emit valueChanged();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleLineEdit::timerEvent(QTimerEvent *)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
if (m_errorHighlighting < 0.01) {
|
|
Toshihiro Shimizu |
890ddd |
if (m_errorHighlightingTimerId != 0)
|
|
Toshihiro Shimizu |
890ddd |
killTimer(m_errorHighlightingTimerId);
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlightingTimerId = 0;
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlighting = 0;
|
|
Toshihiro Shimizu |
890ddd |
setStyleSheet("");
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
int v = 255 - (int)(m_errorHighlighting * 255);
|
|
Toshihiro Shimizu |
890ddd |
m_errorHighlighting = m_errorHighlighting * 0.8;
|
|
Toshihiro Shimizu |
890ddd |
int c = 255 << 16 | v << 8 | v;
|
|
Toshihiro Shimizu |
890ddd |
setStyleSheet(QString("#ValueLineEdit {background-color:#%1}").arg(c, 6, 16, QLatin1Char('0')));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// MeasuredDoubleField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleField::MeasuredDoubleField(QWidget *parent, bool isRollerHide)
|
|
Toshihiro Shimizu |
890ddd |
: DoubleValueField(parent, new MeasuredDoubleLineEdit(0))
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
m_lineEdit->setMaximumWidth(100);
|
|
Toshihiro Shimizu |
890ddd |
if (isRollerHide)
|
|
Toshihiro Shimizu |
890ddd |
enableRoller(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
///----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
3bfa54 |
void MeasuredDoubleField::setMeasure(std::string measureName)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleLineEdit *lineEdit = dynamic_cast<measureddoublelineedit *="">(m_lineEdit);</measureddoublelineedit>
|
|
Toshihiro Shimizu |
890ddd |
assert(lineEdit);
|
|
Toshihiro Shimizu |
890ddd |
lineEdit->setMeasure(measureName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void MeasuredDoubleField::setDecimals(int decimals)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
MeasuredDoubleLineEdit *lineEdit = qobject_cast<measureddoublelineedit *="">(m_lineEdit);</measureddoublelineedit>
|
|
Toshihiro Shimizu |
890ddd |
if (lineEdit)
|
|
Toshihiro Shimizu |
890ddd |
lineEdit->setDecimals(decimals);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*--- rollerにもStepを設定 ---*/
|
|
Toshihiro Shimizu |
890ddd |
if (isRollerEnabled())
|
|
Toshihiro Shimizu |
890ddd |
m_roller->setStep(pow(0.1, tmax(decimals - 1, 1)));
|
|
Toshihiro Shimizu |
890ddd |
}
|