From f129024fc7ad17638cfa9fc7c3948dbc791bd4ca Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 16:48:24 -0300 Subject: Added a 2 Ruler Items, Time and Depth. The ruler items are needed so I can get the correct coordinates of the planned dive. This is a very rudimentary ruler and it needs a bit of love, but it already gives me something to work on. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 47 +++++++++++++++++++++++++++++++++++------------ qt-ui/diveplanner.h | 11 +++++++---- 2 files changed, 42 insertions(+), 16 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index eee6e8f13..42c3bda80 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -21,6 +21,24 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedH horizontalLine = new QGraphicsLineItem(0,0,100,0); horizontalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(horizontalLine); + + timeLine = new Ruler(); + timeLine->setMinimum(0); + timeLine->setMaximum(60); + timeLine->setTickInterval(10); + timeLine->setLine( 10, 90, 99, 90); + timeLine->setOrientation(Qt::Horizontal); + timeLine->updateTicks(); + scene()->addItem(timeLine); + + depthLine = new Ruler(); + depthLine->setMinimum(0); + depthLine->setMaximum(400); + depthLine->setTickInterval(10); + depthLine->setLine( 10, 1, 10, 90); + depthLine->setOrientation(Qt::Vertical); + depthLine->updateTicks(); + scene()->addItem(depthLine); } void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) @@ -192,16 +210,12 @@ DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0) void Ruler::setMaximum(double maximum) { - qDeleteAll(ticks); max = maximum; - updateTicks(); } void Ruler::setMinimum(double minimum) { - qDeleteAll(ticks); min = minimum; - updateTicks(); } Ruler::Ruler() : orientation(Qt::Horizontal) @@ -211,20 +225,29 @@ Ruler::Ruler() : orientation(Qt::Horizontal) void Ruler::setOrientation(Qt::Orientation o) { orientation = o; - updateTicks(); } void Ruler::updateTicks() { + qDeleteAll(ticks); + QLineF m = line(); + if(orientation == Qt::Horizontal){ + double steps = (max - min) / interval; + double stepSize = (m.x2() - m.x1()) / steps; + for(qreal pos = m.x1(); pos < m.x2(); pos += stepSize){ + QGraphicsLineItem *l = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + 1, this); + } + }else{ + double steps = (max - min) / interval; + double stepSize = (m.y2() - m.y1()) / steps; + for(qreal pos = m.y1(); pos < m.y2(); pos += stepSize){ + QGraphicsLineItem *l = new QGraphicsLineItem(m.x1(), pos, m.x1() - 1, pos, this); + } + } } -void Ruler::setLine(qreal x1, qreal y1, qreal x2, qreal y2) -{ - -} - -void Ruler::setTickInterval(double interval) +void Ruler::setTickInterval(double i) { - + interval = i; } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 13218e4ae..5557a7b56 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -12,22 +12,21 @@ public: QGraphicsLineItem *to; }; -class Ruler : public QGraphicsItem{ +class Ruler : public QGraphicsLineItem{ public: Ruler(); void setMinimum(double minimum); void setMaximum(double maximum); void setTickInterval(double interval); void setOrientation(Qt::Orientation orientation); - void setLine(qreal x1, qreal y1, qreal x2, qreal y2); + void updateTicks(); private: - void updateTicks(); Qt::Orientation orientation; QList ticks; double min; double max; - + double interval; double posBegin; double posEnd; }; @@ -56,5 +55,9 @@ private: QGraphicsLineItem *verticalLine; QGraphicsLineItem *horizontalLine; DiveHandler *activeDraggedHandler; + + Ruler *timeLine; + Ruler *depthLine; + }; #endif -- cgit v1.2.3-70-g09d2