From 397a94fcd1deb56240403a6e33e61f49460cc1c8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 15:53:20 -0300 Subject: 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 --- qt-ui/diveplanner.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 51d018a90..21d134d04 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -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); -- cgit v1.2.3-70-g09d2