Created the posAtValue method for the ruler

Created the posAtValue method for the ruler, you enter
a value, and it will return the coordinates in double
( coordinate system of a QGraphicsScene is double based )
this is not the best name for the function, but I couldn't
find any better suitable name.

Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
Tomaz Canabrava 2013-06-21 15:53:20 -03:00
parent 062515ba6f
commit 397a94fcd1

View file

@ -289,18 +289,27 @@ void Ruler::setTickInterval(double i)
qreal Ruler::valueAt(const QPointF& p)
{
QLineF m = line();
return orientation == Qt::Horizontal
double retValue = orientation == Qt::Horizontal
? max * (p.x() - m.x1()) / (m.x2() - m.x1())
: max * (p.y() - m.y1()) / (m.y2() - m.y1());
return retValue;
}
qreal Ruler::posAtValue(qreal value)
{
QLineF m = line();
// I need to finish this later. hungry as hell.
double size = max - min;
double percent = value / size;
double realSize = orientation == Qt::Horizontal
? m.x2() - m.x1()
: m.y2() - m.y1();
double retValue = realSize * percent;
retValue = (orientation == Qt::Horizontal)
? retValue + m.x1()
: retValue + m.y1();
return retValue;
}
DivePlanner::DivePlanner() : ui(new Ui::DivePlanner())
{
ui->setupUi(this);