Skip to content

Commit

Permalink
Mouse wheel handling in InputField
Browse files Browse the repository at this point in the history
  • Loading branch information
jriegel committed Dec 15, 2013
1 parent d5d9ea9 commit 9d21736
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/Gui/InputField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
// --------------------------------------------------------------------


Expand Down
3 changes: 3 additions & 0 deletions src/Gui/InputField.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class GuiExport InputField : public QLineEdit
protected Q_SLOTS:
void newInput(const QString & text);

void wheelEvent ( QWheelEvent * event ) ;
protected:
virtual void contextMenuEvent ( QContextMenuEvent * event );

Expand All @@ -142,6 +143,8 @@ protected Q_SLOTS:

Base::Quantity actQuantity;
Base::Unit actUnit;
double actUnitValue;
QString actUnitStr;

double Maximum;
double Minimum;
Expand Down

0 comments on commit 9d21736

Please sign in to comment.