Mouse wheel handling in InputField

This commit is contained in:
jriegel 2013-12-16 00:02:31 +01:00
parent d5d9ea9c30
commit 9d217367e9
2 changed files with 26 additions and 1 deletions

View File

@ -124,6 +124,10 @@ void InputField::newInput(const QString & text)
ErrorText = "";
this->setToolTip(QString::fromAscii(ErrorText.c_str()));
actQuantity = res;
double dFactor;
res.getUserString(dFactor,actUnitStr);
// calculate the number shown
actUnitValue = res.getValue()/dFactor;
// signaling
valueChanged(res);
@ -235,7 +239,9 @@ void InputField::setValue(const Base::Quantity& quant)
if(!quant.getUnit().isEmpty())
actUnit = quant.getUnit();
setText(quant.getUserString());
double dFactor;
setText(quant.getUserString(dFactor,actUnitStr));
actUnitValue = quant.getValue()/dFactor;
}
void InputField::setUnit(const Base::Unit& unit)
@ -307,6 +313,22 @@ void InputField::selectNumber(void)
}
void InputField::wheelEvent ( QWheelEvent * event )
{
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
double val = actUnitValue + numSteps;
this->setText( QString::fromUtf8("%1 %2").arg(val).arg(actUnitStr));
//if (event->orientation() == Qt::Horizontal) {
// scrollHorizontally(numSteps);
//} else {
// scrollVertically(numSteps);
//}
event->accept();
}
// --------------------------------------------------------------------

View File

@ -129,6 +129,7 @@ Q_SIGNALS:
protected Q_SLOTS:
void newInput(const QString & text);
void wheelEvent ( QWheelEvent * event ) ;
protected:
virtual void contextMenuEvent ( QContextMenuEvent * event );
@ -142,6 +143,8 @@ private:
Base::Quantity actQuantity;
Base::Unit actUnit;
double actUnitValue;
QString actUnitStr;
double Maximum;
double Minimum;