|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/doublepairfield.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "toonzqt/dvdialog.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tcommon.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
shun-iwasawa |
c86c5d |
#include <cmath></cmath>
|
|
shun-iwasawa |
c86c5d |
|
|
Toshihiro Shimizu |
890ddd |
#include <qlabel></qlabel>
|
|
Toshihiro Shimizu |
890ddd |
#include <qpainter></qpainter>
|
|
Toshihiro Shimizu |
890ddd |
#include <qmouseevent></qmouseevent>
|
|
Toshihiro Shimizu |
890ddd |
#include <qslider></qslider>
|
|
Toshihiro Shimizu |
890ddd |
#include <qhboxlayout></qhboxlayout>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace DVGui;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef MACOSX
|
|
Toshihiro Shimizu |
890ddd |
#define MARGIN_OFFSET 7
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
#define MARGIN_OFFSET 2
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoubleValuePairField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
DoubleValuePairField::DoubleValuePairField(QWidget *parent,
|
|
Shinya Kitaoka |
120a6e |
bool isMaxRangeLimited,
|
|
Shinya Kitaoka |
120a6e |
DoubleValueLineEdit *leftLineEdit,
|
|
Shinya Kitaoka |
120a6e |
DoubleValueLineEdit *rightLineEdit)
|
|
Shinya Kitaoka |
120a6e |
: QWidget(parent)
|
|
Shinya Kitaoka |
120a6e |
, m_values(0, 0)
|
|
Shinya Kitaoka |
120a6e |
, m_minValue(0)
|
|
Shinya Kitaoka |
120a6e |
, m_maxValue(100)
|
|
Shinya Kitaoka |
120a6e |
, m_grabOffset(0)
|
|
Shinya Kitaoka |
120a6e |
, m_grabIndex(-1)
|
|
Shinya Kitaoka |
120a6e |
, m_leftMargin(72)
|
|
Shinya Kitaoka |
120a6e |
, m_rightMargin(72)
|
|
Shinya Kitaoka |
120a6e |
, m_isMaxRangeLimited(isMaxRangeLimited)
|
|
Shinya Kitaoka |
120a6e |
, m_leftLineEdit(leftLineEdit)
|
|
Shinya Kitaoka |
120a6e |
, m_rightLineEdit(rightLineEdit) {
|
|
Shinya Kitaoka |
120a6e |
assert(m_leftLineEdit);
|
|
Shinya Kitaoka |
120a6e |
assert(m_rightLineEdit);
|
|
Shinya Kitaoka |
120a6e |
setObjectName("DoublePairField");
|
|
Shinya Kitaoka |
120a6e |
setFixedHeight(WidgetHeight);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_leftLabel = new QLabel("", this);
|
|
Shinya Kitaoka |
120a6e |
m_rightLabel = new QLabel("", this);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setFixedWidth(60);
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setFixedWidth(60);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//---- layout
|
|
Shinya Kitaoka |
120a6e |
QHBoxLayout *m_mainLayout = new QHBoxLayout;
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->setMargin(0);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->setSpacing(3);
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addWidget(m_leftLabel, 1);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addWidget(m_leftLineEdit, 1, Qt::AlignLeft);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addSpacing(35);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addStretch(100);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addWidget(m_rightLabel, 1);
|
|
Shinya Kitaoka |
120a6e |
m_mainLayout->addWidget(m_rightLineEdit, 1, Qt::AlignRight);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
setLayout(m_mainLayout);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
//---- signal-slot connections
|
|
Shinya Kitaoka |
120a6e |
bool ret = connect(m_leftLineEdit, SIGNAL(editingFinished()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(onLeftEditingFinished()));
|
|
Shinya Kitaoka |
120a6e |
ret = ret && connect(m_rightLineEdit, SIGNAL(editingFinished()),
|
|
Shinya Kitaoka |
120a6e |
SLOT(onRightEditingFinished()));
|
|
Shinya Kitaoka |
120a6e |
assert(ret);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
double DoubleValuePairField::pos2value(int x) const {
|
|
Shinya Kitaoka |
120a6e |
int xMin = m_leftMargin, xMax = width() - m_rightMargin;
|
|
Shinya Kitaoka |
120a6e |
return m_minValue + (m_maxValue - m_minValue) * (x - xMin) / (xMax - xMin);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int DoubleValuePairField::value2pos(double v) const {
|
|
Shinya Kitaoka |
120a6e |
int xMin = m_leftMargin, xMax = width() - m_rightMargin;
|
|
Shinya Kitaoka |
120a6e |
return xMin +
|
|
Shinya Kitaoka |
120a6e |
(int)(((xMax - xMin) * (v - m_minValue)) / (m_maxValue - m_minValue));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::paintEvent(QPaintEvent *) {
|
|
Shinya Kitaoka |
120a6e |
QPainter p(this);
|
|
Shinya Kitaoka |
120a6e |
p.setBrush(Qt::NoBrush);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int x0 = value2pos(m_minValue);
|
|
Shinya Kitaoka |
120a6e |
int x1 = value2pos(m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
int y = height() / 2;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
p.setPen(getLightLineColor());
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(x0 - 1, y, x1 + 1, y);
|
|
Shinya Kitaoka |
120a6e |
p.drawPoint(x1 + 1, y - 1);
|
|
Shinya Kitaoka |
120a6e |
p.drawPoint(x1 + 1, y - 2);
|
|
Shinya Kitaoka |
120a6e |
p.drawPoint(x1 + 1, y - 3);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(QColor(0, 0, 0));
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(x0, y - 2, x1 - 1, y - 2);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(getDarkLineColor());
|
|
Shinya Kitaoka |
120a6e |
p.drawLine(x0 - 1, y - 3, x1, y - 3);
|
|
Shinya Kitaoka |
120a6e |
p.drawPoint(x0 - 1, y - 1);
|
|
Shinya Kitaoka |
120a6e |
p.drawPoint(x0 - 1, y - 2);
|
|
Shinya Kitaoka |
120a6e |
p.setPen(Qt::black);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int y1 = height() - 1;
|
|
Shinya Kitaoka |
120a6e |
int x;
|
|
Shinya Kitaoka |
120a6e |
x = value2pos(m_values.first);
|
|
Shinya Kitaoka |
120a6e |
QRect sliderRect = QRect(x0, -5, x1 - x0 + 1, 10);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (sliderRect.contains(QPoint(x, 0)))
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(x - m_handleLeftPixmap.width() + 1, 2, m_handleLeftPixmap);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(sliderRect.right() - m_handleLeftPixmap.width() + 1, 2,
|
|
Shinya Kitaoka |
120a6e |
m_handleLeftGrayPixmap);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
x = value2pos(m_values.second);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (sliderRect.contains(QPoint(x, 0)))
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(x, 2, m_handleRightPixmap);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
p.drawPixmap(sliderRect.right(), 2, m_handleRightGrayPixmap);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setLeftText(const QString &text) {
|
|
Shinya Kitaoka |
120a6e |
QString oldText = m_leftLabel->text();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int oldLabelSize = fontMetrics().width(oldText);
|
|
Shinya Kitaoka |
120a6e |
int newLabelSize = fontMetrics().width(text);
|
|
Shinya Kitaoka |
120a6e |
int labelSize = newLabelSize - oldLabelSize;
|
|
Shinya Kitaoka |
120a6e |
m_leftMargin += labelSize + MARGIN_OFFSET;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_leftLabel->setText(text);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setRightText(const QString &text) {
|
|
Shinya Kitaoka |
120a6e |
QString oldText = m_rightLabel->text();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int oldLabelSize = fontMetrics().width(oldText);
|
|
Shinya Kitaoka |
120a6e |
int newLabelSize = fontMetrics().width(text);
|
|
Shinya Kitaoka |
120a6e |
int labelSize = newLabelSize - oldLabelSize;
|
|
Shinya Kitaoka |
120a6e |
m_rightMargin += labelSize + MARGIN_OFFSET;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_rightLabel->setText(text);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setLabelsEnabled(bool enable) {
|
|
Shinya Kitaoka |
120a6e |
if (!enable) {
|
|
Shinya Kitaoka |
120a6e |
m_rightLabel->hide();
|
|
Shinya Kitaoka |
120a6e |
m_leftLabel->hide();
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
m_rightLabel->show();
|
|
Shinya Kitaoka |
120a6e |
m_leftLabel->show();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setValue(double value) {
|
|
shun-iwasawa |
c86c5d |
int decimals = std::min(m_leftLineEdit->getDecimals(), 4);
|
|
shun-iwasawa |
c86c5d |
value = tround(value * std::pow(10, decimals)) * std::pow(0.1, decimals);
|
|
Shinya Kitaoka |
120a6e |
value = tcrop(value, m_minValue, m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
if (m_grabIndex == 0) // Left grab
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_values.first = value;
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setValue(m_values.first);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value > m_values.second) {
|
|
Shinya Kitaoka |
120a6e |
m_values.second = value;
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setValue(m_values.second);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
} else // Right grab
|
|
Shinya Kitaoka |
120a6e |
{
|
|
Shinya Kitaoka |
120a6e |
m_values.second = value;
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setValue(m_values.second);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (value < m_values.first) {
|
|
Shinya Kitaoka |
120a6e |
m_values.first = value;
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setValue(m_values.first);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setValues(const std::pair<double, double=""> &values) {</double,>
|
|
Shinya Kitaoka |
120a6e |
assert(values.first <= values.second);
|
|
Shinya Kitaoka |
120a6e |
m_values.first = tcrop(values.first, m_minValue, m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setValue(m_values.first);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_values.second = values.second;
|
|
Shinya Kitaoka |
120a6e |
if (m_isMaxRangeLimited)
|
|
Shinya Kitaoka |
120a6e |
m_values.second = tcrop(values.second, m_values.first, m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setValue(m_values.second);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::setRange(double minValue, double maxValue) {
|
|
Shinya Kitaoka |
120a6e |
m_minValue = minValue;
|
|
Shinya Kitaoka |
120a6e |
m_maxValue = maxValue;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
if (!m_isMaxRangeLimited) maxValue = (std::numeric_limits<int>::max)();</int>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setRange(minValue, maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setRange(minValue, maxValue);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::getRange(double &minValue, double &maxValue) {
|
|
Shinya Kitaoka |
120a6e |
minValue = m_minValue;
|
|
Shinya Kitaoka |
120a6e |
maxValue = m_maxValue;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::mousePressEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (event->button() == Qt::LeftButton) {
|
|
Shinya Kitaoka |
120a6e |
int x = event->pos().x();
|
|
Shinya Kitaoka |
120a6e |
int cur0, cur1;
|
|
Shinya Kitaoka |
120a6e |
if (m_values.first > m_maxValue)
|
|
Shinya Kitaoka |
120a6e |
cur0 = value2pos(m_maxValue) - 5;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
cur0 = value2pos(m_values.first);
|
|
Shinya Kitaoka |
120a6e |
if (m_values.second > m_maxValue)
|
|
Shinya Kitaoka |
120a6e |
cur1 = value2pos(m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
cur1 = value2pos(m_values.second);
|
|
Shinya Kitaoka |
120a6e |
int d0 = abs(cur0 - x);
|
|
Shinya Kitaoka |
120a6e |
int d1 = abs(cur1 - x);
|
|
Shinya Kitaoka |
120a6e |
int d, cur;
|
|
Shinya Kitaoka |
120a6e |
if (d0 < d1 || (d0 == d1 && x < cur0)) {
|
|
Shinya Kitaoka |
120a6e |
d = abs(d0);
|
|
Shinya Kitaoka |
120a6e |
cur = cur0;
|
|
Shinya Kitaoka |
120a6e |
m_grabIndex = 0;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
d = abs(d1);
|
|
Shinya Kitaoka |
120a6e |
cur = cur1;
|
|
Shinya Kitaoka |
120a6e |
m_grabIndex = 1;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (d < 6)
|
|
Shinya Kitaoka |
120a6e |
m_grabOffset = cur - x;
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
m_grabOffset = 0;
|
|
Shinya Kitaoka |
120a6e |
setValue(pos2value(x));
|
|
Shinya Kitaoka |
120a6e |
emit valuesChanged(true);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::mouseMoveEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
if (event->buttons()) {
|
|
Shinya Kitaoka |
120a6e |
std::pair<double, double=""> oldValues = m_values;</double,>
|
|
Shinya Kitaoka |
120a6e |
int x = event->pos().x() + m_grabOffset;
|
|
Shinya Kitaoka |
120a6e |
setValue(pos2value(x));
|
|
Shinya Kitaoka |
120a6e |
if (oldValues != m_values) {
|
|
Shinya Kitaoka |
120a6e |
emit valuesChanged(true);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::mouseReleaseEvent(QMouseEvent *event) {
|
|
Shinya Kitaoka |
120a6e |
m_grabOffset = 0;
|
|
Shinya Kitaoka |
120a6e |
m_grabIndex = 0;
|
|
Shinya Kitaoka |
120a6e |
emit valuesChanged(false);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::onLeftEditingFinished() {
|
|
Shinya Kitaoka |
120a6e |
double value = m_leftLineEdit->getValue();
|
|
Shinya Kitaoka |
120a6e |
if (value == m_values.first) return;
|
|
Shinya Kitaoka |
120a6e |
if (!m_isMaxRangeLimited && value < m_minValue)
|
|
Shinya Kitaoka |
120a6e |
value = m_minValue;
|
|
Shinya Kitaoka |
120a6e |
else if (m_isMaxRangeLimited)
|
|
Shinya Kitaoka |
120a6e |
value = tcrop(value, m_minValue, m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_values.first = value;
|
|
Shinya Kitaoka |
120a6e |
if (m_values.first > m_values.second) {
|
|
Shinya Kitaoka |
120a6e |
m_values.second = m_values.first;
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setValue(m_values.second);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
emit valuesChanged(false);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void DoubleValuePairField::onRightEditingFinished() {
|
|
Shinya Kitaoka |
120a6e |
double value = m_rightLineEdit->getValue();
|
|
Shinya Kitaoka |
120a6e |
if (value == m_values.second) return;
|
|
Shinya Kitaoka |
120a6e |
if (m_isMaxRangeLimited) value = tcrop(value, m_minValue, m_maxValue);
|
|
Shinya Kitaoka |
120a6e |
m_values.second = value;
|
|
Shinya Kitaoka |
120a6e |
if (m_values.second < m_values.first) {
|
|
Shinya Kitaoka |
120a6e |
m_values.first = m_values.second;
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setValue(m_values.first);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
emit valuesChanged(false);
|
|
Shinya Kitaoka |
120a6e |
update();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// DoublePairField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
DoublePairField::DoublePairField(QWidget *parent, bool isMaxRangeLimited)
|
|
Shinya Kitaoka |
120a6e |
: DoubleValuePairField(parent, isMaxRangeLimited, new DoubleLineEdit(0),
|
|
Shinya Kitaoka |
120a6e |
new DoubleLineEdit(0)) {
|
|
Shinya Kitaoka |
120a6e |
DoubleLineEdit *leftLineEdit = dynamic_cast<doublelineedit *="">(m_leftLineEdit);</doublelineedit>
|
|
Shinya Kitaoka |
120a6e |
leftLineEdit->setDecimals(2);
|
|
Shinya Kitaoka |
120a6e |
DoubleLineEdit *rightLineEdit =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<doublelineedit *="">(m_rightLineEdit);</doublelineedit>
|
|
Shinya Kitaoka |
120a6e |
rightLineEdit->setDecimals(2);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//=============================================================================
|
|
Toshihiro Shimizu |
890ddd |
// MeasuredDoublePairField
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
MeasuredDoublePairField::MeasuredDoublePairField(QWidget *parent,
|
|
Shinya Kitaoka |
120a6e |
bool isMaxRangeLimited)
|
|
Shinya Kitaoka |
120a6e |
: DoubleValuePairField(parent, isMaxRangeLimited,
|
|
Shinya Kitaoka |
120a6e |
new MeasuredDoubleLineEdit(0),
|
|
Shinya Kitaoka |
120a6e |
new MeasuredDoubleLineEdit(0)) {
|
|
Shinya Kitaoka |
120a6e |
m_leftLineEdit->setFixedSize(63, WidgetHeight);
|
|
Shinya Kitaoka |
120a6e |
m_rightLineEdit->setFixedSize(63, WidgetHeight);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void MeasuredDoublePairField::setMeasure(std::string measureName) {
|
|
Shinya Kitaoka |
120a6e |
MeasuredDoubleLineEdit *leftLineEdit =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<measureddoublelineedit *="">(m_leftLineEdit);</measureddoublelineedit>
|
|
Shinya Kitaoka |
120a6e |
assert(leftLineEdit);
|
|
Shinya Kitaoka |
120a6e |
leftLineEdit->setMeasure(measureName);
|
|
Shinya Kitaoka |
120a6e |
MeasuredDoubleLineEdit *rightLineEdit =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<measureddoublelineedit *="">(m_rightLineEdit);</measureddoublelineedit>
|
|
Shinya Kitaoka |
120a6e |
assert(rightLineEdit);
|
|
Shinya Kitaoka |
120a6e |
rightLineEdit->setMeasure(measureName);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*--設定ファイルからインタフェースの精度を変える--*/
|
|
Shinya Kitaoka |
120a6e |
void MeasuredDoublePairField::setPrecision(int precision) {
|
|
Shinya Kitaoka |
120a6e |
MeasuredDoubleLineEdit *leftLineEdit =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<measureddoublelineedit *="">(m_leftLineEdit);</measureddoublelineedit>
|
|
Shinya Kitaoka |
120a6e |
if (leftLineEdit) leftLineEdit->setDecimals(precision);
|
|
Shinya Kitaoka |
120a6e |
MeasuredDoubleLineEdit *rightLineEdit =
|
|
Shinya Kitaoka |
120a6e |
dynamic_cast<measureddoublelineedit *="">(m_rightLineEdit);</measureddoublelineedit>
|
|
Shinya Kitaoka |
120a6e |
if (rightLineEdit) rightLineEdit->setDecimals(precision);
|
|
Toshihiro Shimizu |
890ddd |
}
|