From beadeffaf51f59a5d587861121f371c14d5dcaff Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 12:33:26 -0300 Subject: Added the first scope of the visual dive planner. Added the first files and skeleton code for the visual dive planner. now I need to fill things. The code is using the print action borrowed, this will need to move to a better choice in the future. Signed-off-by: Tomaz Canabrava --- Makefile | 2 ++ qt-ui/diveplanner.cpp | 11 +++++++++++ qt-ui/diveplanner.h | 14 ++++++++++++++ qt-ui/mainwindow.cpp | 3 +++ 4 files changed, 30 insertions(+) create mode 100644 qt-ui/diveplanner.cpp create mode 100644 qt-ui/diveplanner.h diff --git a/Makefile b/Makefile index f8770d344..17f1dcd1a 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ HEADERS = \ qt-ui/simplewidgets.h \ qt-ui/subsurfacewebservices.h \ qt-ui/divecomputermanagementdialog.h \ + qt-ui/diveplanner.h \ SOURCES = \ @@ -85,6 +86,7 @@ SOURCES = \ qt-ui/simplewidgets.cpp \ qt-ui/subsurfacewebservices.cpp \ qt-ui/divecomputermanagementdialog.cpp \ + qt-ui/diveplanner.cpp \ $(RESFILE) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp new file mode 100644 index 000000000..d8d1bfbfc --- /dev/null +++ b/qt-ui/diveplanner.cpp @@ -0,0 +1,11 @@ +#include "diveplanner.h" + +DivePlanner* DivePlanner::instance() +{ + static DivePlanner *self = new DivePlanner(); + return self; +} + +DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) +{ +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h new file mode 100644 index 000000000..9a7d0859f --- /dev/null +++ b/qt-ui/diveplanner.h @@ -0,0 +1,14 @@ +#ifndef DIVEPLANNER_H +#define DIVEPLANNER_H + +#include +#include + +class DivePlanner : public QGraphicsView { + Q_OBJECT +public: + static DivePlanner *instance(); +private: + DivePlanner(QWidget* parent = 0); +}; +#endif diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 06e6b7734..75fb21a64 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -32,6 +32,7 @@ #include "subsurfacewebservices.h" #include "divecomputermanagementdialog.h" #include "simplewidgets.h" +#include "diveplanner.h" static MainWindow* instance = 0; @@ -178,6 +179,8 @@ void MainWindow::on_actionExportUDDF_triggered() void MainWindow::on_actionPrint_triggered() { + // hijacking the print action for a while. + DivePlanner::instance()->show(); qDebug("actionPrint"); } -- cgit v1.2.3-70-g09d2 From 0d45c775725f23e96b018df4e23c2776a3186030 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 12:37:41 -0300 Subject: Make double click work to put new items on the canvas. Make double click work to put new items on the canvas. Those items right now are QGraphicsEllipseItems, but it will change to 'draggable' items. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 11 +++++++++++ qt-ui/diveplanner.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d8d1bfbfc..46147bfc7 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,4 +1,5 @@ #include "diveplanner.h" +#include DivePlanner* DivePlanner::instance() { @@ -8,4 +9,14 @@ DivePlanner* DivePlanner::instance() DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) { + setScene( new QGraphicsScene()); + scene()->setSceneRect(0,0,100,100); } + +void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) +{ + QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-10,-10,20,20); + item->setPos( mapToScene(event->pos())); + scene()->addItem(item); +} + diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 9a7d0859f..6e73db718 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -8,6 +8,9 @@ class DivePlanner : public QGraphicsView { Q_OBJECT public: static DivePlanner *instance(); +protected: + virtual void mouseDoubleClickEvent(QMouseEvent* event); + private: DivePlanner(QWidget* parent = 0); }; -- cgit v1.2.3-70-g09d2 From ab6aea73c17a10bfb934ba74fcda59cb916f278d Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 13:20:41 -0300 Subject: Plots Lines and handles on the Planner This is still a bit bugged - the lines are going to the wrong end - most probaly I messed something on the math. I'll now fix the sizing issue then I'll try to make it behave in the proper way. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 34 +++++++++++++++++++++++++++++++++- qt-ui/diveplanner.h | 6 +++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 46147bfc7..90d677177 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,5 +1,6 @@ #include "diveplanner.h" #include +#include DivePlanner* DivePlanner::instance() { @@ -16,7 +17,38 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) { QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-10,-10,20,20); - item->setPos( mapToScene(event->pos())); + QPointF mappedPos = mapToScene(event->pos()); + + item->setPos( mappedPos ); scene()->addItem(item); + handles << item; + + if (lines.empty()){ + QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y()); + lines << first; + create_deco_stop(); + scene()->addItem(first); + }else{ + clear_generated_deco(); + create_deco_stop(); + } +} + +void DivePlanner::clear_generated_deco() +{ + for(int i = handles.count(); i < lines.count(); i++){ + scene()->removeItem(lines.last()); + delete lines.last(); + lines.removeLast(); + } +} + +void DivePlanner::create_deco_stop() +{ + // this needs to create everything + // for the calculated deco. + QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0); + scene()->addItem(item); + lines << item; } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 6e73db718..fc9575cfa 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -10,8 +10,12 @@ public: static DivePlanner *instance(); protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); - + void clear_generated_deco(); + void create_deco_stop(); + private: DivePlanner(QWidget* parent = 0); + QList lines; + QList handles; }; #endif -- cgit v1.2.3-70-g09d2 From 364254ed36d98ebe61385ddd7d2062c0f7214df3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 13:28:04 -0300 Subject: Better handling of the scene size for the dive Plan Better handling of the scene size for the dive plan, The scene can be resized and a transform will be applied, the handles will not resize however - they are 10x10px and that's it. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 15 ++++++++++++++- qt-ui/diveplanner.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 90d677177..a22efb200 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -16,7 +16,8 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) { - QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-10,-10,20,20); + QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10); + item->setFlag(QGraphicsItem::ItemIgnoresTransformations); QPointF mappedPos = mapToScene(event->pos()); item->setPos( mappedPos ); @@ -52,3 +53,15 @@ void DivePlanner::create_deco_stop() lines << item; } +void DivePlanner::resizeEvent(QResizeEvent* event) +{ + QGraphicsView::resizeEvent(event); + fitInView(sceneRect(), Qt::KeepAspectRatio); +} + +void DivePlanner::showEvent(QShowEvent* event) +{ + QGraphicsView::showEvent(event); + fitInView(sceneRect(), Qt::KeepAspectRatio); +} + diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index fc9575cfa..682c56ae4 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -10,6 +10,9 @@ public: static DivePlanner *instance(); protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); + virtual void showEvent(QShowEvent* event); + virtual void resizeEvent(QResizeEvent* event); + void clear_generated_deco(); void create_deco_stop(); -- cgit v1.2.3-70-g09d2 From b1c526ddb4508a0694e46a6e48a1b0f900072f37 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 13:39:41 -0300 Subject: Fix creation of the poligon-based lines for the dive planner This fixes the creation of the poligon-based lines next thing to do is to forbit creation of the next point before the last one. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 10 +++++++--- qt-ui/diveplanner.h | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index a22efb200..0176e2c85 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,6 +1,6 @@ #include "diveplanner.h" #include -#include +#include DivePlanner* DivePlanner::instance() { @@ -26,18 +26,22 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) if (lines.empty()){ QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y()); - lines << first; + lines.push_back(first); create_deco_stop(); scene()->addItem(first); }else{ clear_generated_deco(); + QGraphicsEllipseItem *prevHandle = handles.at( handles.count()-2); + QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y()); + lines.push_back(line); + scene()->addItem(line); create_deco_stop(); } } void DivePlanner::clear_generated_deco() { - for(int i = handles.count(); i < lines.count(); i++){ + for(int i = handles.count(); i <= lines.count(); i++){ scene()->removeItem(lines.last()); delete lines.last(); lines.removeLast(); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 682c56ae4..9d87b0c78 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -12,7 +12,7 @@ protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); virtual void showEvent(QShowEvent* event); virtual void resizeEvent(QResizeEvent* event); - + void clear_generated_deco(); void create_deco_stop(); -- cgit v1.2.3-70-g09d2 From 88e7aa36be99d9ae985a374a23d84d8e0f969b5a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 13:53:12 -0300 Subject: Created a cross that follows the mouse on the dive planner. Created a cross that follows the mouse on the dive planner, this will help the user to know where it is placing the stop. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 22 ++++++++++++++++++++++ qt-ui/diveplanner.h | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 0176e2c85..13f15a2e0 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -10,8 +10,17 @@ DivePlanner* DivePlanner::instance() DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) { + setMouseTracking(true); setScene( new QGraphicsScene()); scene()->setSceneRect(0,0,100,100); + + verticalLine = new QGraphicsLineItem(0,0,0, 100); + verticalLine->setPen(QPen(Qt::DotLine)); + scene()->addItem(verticalLine); + + horizontalLine = new QGraphicsLineItem(0,0,100,0); + horizontalLine->setPen(QPen(Qt::DotLine)); + scene()->addItem(horizontalLine); } void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) @@ -69,3 +78,16 @@ void DivePlanner::showEvent(QShowEvent* event) fitInView(sceneRect(), Qt::KeepAspectRatio); } +void DivePlanner::mouseMoveEvent(QMouseEvent* event) +{ + QPointF mappedPos = mapToScene(event->pos()); + if (mappedPos.x() > sceneRect().width() + || mappedPos.x() < 0 + || mappedPos.y() < 0 + || mappedPos.y() > sceneRect().height()) + { + return; + } + verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); + horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 9d87b0c78..e66b50d57 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -12,13 +12,14 @@ protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); virtual void showEvent(QShowEvent* event); virtual void resizeEvent(QResizeEvent* event); - + virtual void mouseMoveEvent(QMouseEvent* event); void clear_generated_deco(); void create_deco_stop(); - private: DivePlanner(QWidget* parent = 0); QList lines; QList handles; + QGraphicsLineItem *verticalLine; + QGraphicsLineItem *horizontalLine; }; #endif -- cgit v1.2.3-70-g09d2 From 46483a096f98b3dc7186bb6971d6e5009cfb2b13 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 13:56:28 -0300 Subject: Better defaults for placement of dive stops. This patch makes it impossible to create a dive stop outside of the scene - this, messing the complete planning system. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 25 ++++++++++++++++++------- qt-ui/diveplanner.h | 2 ++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 13f15a2e0..d4dd7d5bf 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -25,9 +25,13 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) { + QPointF mappedPos = mapToScene(event->pos()); + if(isPointOutOfBoundaries(mappedPos)) + return; + QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); - QPointF mappedPos = mapToScene(event->pos()); + item->setPos( mappedPos ); scene()->addItem(item); @@ -81,13 +85,20 @@ void DivePlanner::showEvent(QShowEvent* event) void DivePlanner::mouseMoveEvent(QMouseEvent* event) { QPointF mappedPos = mapToScene(event->pos()); - if (mappedPos.x() > sceneRect().width() - || mappedPos.x() < 0 - || mappedPos.y() < 0 - || mappedPos.y() > sceneRect().height()) - { + if (isPointOutOfBoundaries(mappedPos)) return; - } verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); } + +bool DivePlanner::isPointOutOfBoundaries(QPointF point) +{ + if (point.x() > sceneRect().width() + || point.x() < 0 + || point.y() < 0 + || point.y() > sceneRect().height()) + { + return true; + } + return false; +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index e66b50d57..7dca3bb85 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -15,6 +15,8 @@ protected: virtual void mouseMoveEvent(QMouseEvent* event); void clear_generated_deco(); void create_deco_stop(); + bool isPointOutOfBoundaries(QPointF point); + private: DivePlanner(QWidget* parent = 0); QList lines; -- cgit v1.2.3-70-g09d2 From 1fb023d3c67834df047c3bd97f7c701a92afbd97 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 14:20:45 -0300 Subject: Make the cross red when you cant plot a dive stop Make the cross red when you cant plot a dive stop, also make impossible to put a dive stop before the last one. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d4dd7d5bf..fc5b701a7 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -29,6 +29,10 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) if(isPointOutOfBoundaries(mappedPos)) return; + if(handles.count() && handles.last()->x() > mappedPos.x()){ + return; + } + QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); @@ -87,8 +91,20 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) QPointF mappedPos = mapToScene(event->pos()); if (isPointOutOfBoundaries(mappedPos)) return; + verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); + + if (!handles.count()) + return; + + if (handles.last()->x() > mappedPos.x()){ + verticalLine->setPen( QPen(QBrush(Qt::red), 0, Qt::SolidLine)); + horizontalLine->setPen( QPen(QBrush(Qt::red), 0, Qt::SolidLine)); + }else{ + verticalLine->setPen(QPen(Qt::DotLine)); + horizontalLine->setPen(QPen(Qt::DotLine)); + } } bool DivePlanner::isPointOutOfBoundaries(QPointF point) -- cgit v1.2.3-70-g09d2 From 021a6a076e76e45bf5f6f8b976e2178a666ec1bd Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 14:29:32 -0300 Subject: Created a class DiveHandle to make drag drop work. Create d a class DiveHandle to make drag drop works, it has a from and to Lines, and it will move them around. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 19 ++++++++++++++----- qt-ui/diveplanner.h | 11 +++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index fc5b701a7..07f195120 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -33,23 +33,25 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) return; } - QGraphicsEllipseItem *item = new QGraphicsEllipseItem(-5,-5,10,10); + DiveHandler *item = new DiveHandler (); + item->setRect(-5,-5,10,10); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); - - item->setPos( mappedPos ); scene()->addItem(item); handles << item; if (lines.empty()){ QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y()); + item->from = first; lines.push_back(first); create_deco_stop(); scene()->addItem(first); }else{ clear_generated_deco(); - QGraphicsEllipseItem *prevHandle = handles.at( handles.count()-2); + DiveHandler *prevHandle = handles.at( handles.count()-2); QGraphicsLineItem *line = new QGraphicsLineItem(prevHandle->x(), prevHandle->y(), item->x(), item->y()); + prevHandle->to = line; + item->from = line; lines.push_back(line); scene()->addItem(line); create_deco_stop(); @@ -68,7 +70,8 @@ void DivePlanner::clear_generated_deco() void DivePlanner::create_deco_stop() { // this needs to create everything - // for the calculated deco. + // for the calculated deco. it should return the *first* + // line that's calculated, so the QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0); scene()->addItem(item); lines << item; @@ -118,3 +121,9 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point) } return false; } + + + +DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0) +{ +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 7dca3bb85..33f647fe6 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -4,6 +4,13 @@ #include #include +class DiveHandler : public QGraphicsEllipseItem{ +public: + DiveHandler(); + + QGraphicsLineItem *from; + QGraphicsLineItem *to; +}; class DivePlanner : public QGraphicsView { Q_OBJECT public: @@ -16,11 +23,11 @@ protected: void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(QPointF point); - + private: DivePlanner(QWidget* parent = 0); QList lines; - QList handles; + QList handles; QGraphicsLineItem *verticalLine; QGraphicsLineItem *horizontalLine; }; -- cgit v1.2.3-70-g09d2 From 607f82ade30e7d72370654a158e1d58f6444d67e Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 14:46:40 -0300 Subject: Added drag and drop code to the dive plan Added drag and drop code to the dive plan, it can move the user- inputted data, but will not touch the computer generated ones. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 36 +++++++++++++++++++++++++++++++++++- qt-ui/diveplanner.h | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 07f195120..d64eab18f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -8,7 +8,7 @@ DivePlanner* DivePlanner::instance() return self; } -DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent) +DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) { setMouseTracking(true); setScene( new QGraphicsScene()); @@ -98,6 +98,25 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); + if (activeDraggedHandler){ + int idx = handles.indexOf(activeDraggedHandler); + activeDraggedHandler->setPos(mappedPos); + if (activeDraggedHandler->from){ + QLineF f = activeDraggedHandler->from->line(); + activeDraggedHandler->from->setLine(f.x1(), f.y1(), mappedPos.x(), mappedPos.y()); + } + + if(activeDraggedHandler == handles.last()){ + clear_generated_deco(); + create_deco_stop(); + } + + if (activeDraggedHandler->to){ + QLineF f = activeDraggedHandler->to->line(); + activeDraggedHandler->to->setLine(mappedPos.x(), mappedPos.y(), f.x2(), f.y2()); + } + } + if (!handles.count()) return; @@ -122,7 +141,22 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point) return false; } +void DivePlanner::mousePressEvent(QMouseEvent* event) +{ + QPointF mappedPos = mapToScene(event->pos()); + Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos)){ + if (DiveHandler *h = qgraphicsitem_cast(item)){ + activeDraggedHandler = h; + activeDraggedHandler->setBrush(Qt::red); + } + } +} +void DivePlanner::mouseReleaseEvent(QMouseEvent* event) +{ + if (activeDraggedHandler) + activeDraggedHandler = 0; +} DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0) { diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 33f647fe6..db94900c1 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -20,6 +20,9 @@ protected: virtual void showEvent(QShowEvent* event); virtual void resizeEvent(QResizeEvent* event); virtual void mouseMoveEvent(QMouseEvent* event); + virtual void mousePressEvent(QMouseEvent* event); + virtual void mouseReleaseEvent(QMouseEvent* event); + void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(QPointF point); @@ -30,5 +33,6 @@ private: QList handles; QGraphicsLineItem *verticalLine; QGraphicsLineItem *horizontalLine; + DiveHandler *activeDraggedHandler; }; #endif -- cgit v1.2.3-70-g09d2 From 52a0e6c82d60076361fd0a3de7d2417c3fbc2e99 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 15:15:10 -0300 Subject: Make the plan handlers to not move across other handlers. This patch disables the hability to move handlers across the others, making a 'zigzag' in the time line. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 64 ++++++++++++++++++++++++++++++++++++--------------- qt-ui/diveplanner.h | 3 ++- 2 files changed, 48 insertions(+), 19 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d64eab18f..9fead0191 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -98,24 +98,8 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); - if (activeDraggedHandler){ - int idx = handles.indexOf(activeDraggedHandler); - activeDraggedHandler->setPos(mappedPos); - if (activeDraggedHandler->from){ - QLineF f = activeDraggedHandler->from->line(); - activeDraggedHandler->from->setLine(f.x1(), f.y1(), mappedPos.x(), mappedPos.y()); - } - - if(activeDraggedHandler == handles.last()){ - clear_generated_deco(); - create_deco_stop(); - } - - if (activeDraggedHandler->to){ - QLineF f = activeDraggedHandler->to->line(); - activeDraggedHandler->to->setLine(mappedPos.x(), mappedPos.y(), f.x2(), f.y2()); - } - } + if(activeDraggedHandler) + moveActiveHandler(mappedPos); if (!handles.count()) return; @@ -129,6 +113,50 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) } } +void DivePlanner::moveActiveHandler(QPointF pos) +{ + int idx = handles.indexOf(activeDraggedHandler); + bool moveLines = false;; + // do not allow it to move between handlers. + if (handles.count() > 1){ + if (idx == 0 ){ // first + if (pos.x() < handles[1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + }else if (idx == handles.count()-1){ // last + if (pos.x() > handles[idx-1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + }else{ // middle + if (pos.x() > handles[idx-1]->x() && pos.x() < handles[idx+1]->x()){ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + } + }else{ + activeDraggedHandler->setPos(pos); + moveLines = true; + } + if (moveLines){ + if (activeDraggedHandler->from){ + QLineF f = activeDraggedHandler->from->line(); + activeDraggedHandler->from->setLine(f.x1(), f.y1(), pos.x(), pos.y()); + } + + if (activeDraggedHandler->to){ + QLineF f = activeDraggedHandler->to->line(); + activeDraggedHandler->to->setLine(pos.x(), pos.y(), f.x2(), f.y2()); + } + + if(activeDraggedHandler == handles.last()){ + clear_generated_deco(); + create_deco_stop(); + } + } +} + bool DivePlanner::isPointOutOfBoundaries(QPointF point) { if (point.x() > sceneRect().width() diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index db94900c1..48f254bcd 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -22,13 +22,14 @@ protected: virtual void mouseMoveEvent(QMouseEvent* event); virtual void mousePressEvent(QMouseEvent* event); virtual void mouseReleaseEvent(QMouseEvent* event); - + void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(QPointF point); private: DivePlanner(QWidget* parent = 0); + void moveActiveHandler(QPointF pos); QList lines; QList handles; QGraphicsLineItem *verticalLine; -- cgit v1.2.3-70-g09d2 From 636550d413093bee27e86b26c1a4ae408e89a8cd Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 15:52:27 -0300 Subject: Added the skeleton for the Ruler Item, The ruler will deliver the Time and the Depth, later. it should be vertical or horizontal, and will have ticks Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 39 +++++++++++++++++++++++++++++++++++++++ qt-ui/diveplanner.h | 21 +++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 9fead0191..eee6e8f13 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -189,3 +189,42 @@ void DivePlanner::mouseReleaseEvent(QMouseEvent* event) 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) +{ +} + +void Ruler::setOrientation(Qt::Orientation o) +{ + orientation = o; + updateTicks(); +} + +void Ruler::updateTicks() +{ + +} + +void Ruler::setLine(qreal x1, qreal y1, qreal x2, qreal y2) +{ + +} + +void Ruler::setTickInterval(double interval) +{ + +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 48f254bcd..13218e4ae 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -11,6 +11,27 @@ public: QGraphicsLineItem *from; QGraphicsLineItem *to; }; + +class Ruler : public QGraphicsItem{ +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); + +private: + void updateTicks(); + Qt::Orientation orientation; + QList ticks; + double min; + double max; + + double posBegin; + double posEnd; +}; + class DivePlanner : public QGraphicsView { Q_OBJECT public: -- cgit v1.2.3-70-g09d2 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(-) 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 From 2d683b66a8a7d514c8cd766303832876ccbab9bb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 17:34:42 -0300 Subject: Added the code to set the Depth / Time on the user Handlers. Added the code to set the Depth / Time on the user handlers, I think this finishes the difficult part. ( well, not really ) the depth and time is being set when handler is added or moved, but as soon as the deco calculations enters on the code, the handlers will need to be repositioned - and this code is not ready yet. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 26 +++++++++++++++++++++++++- qt-ui/diveplanner.h | 6 ++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 42c3bda80..fa7be75b3 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -74,6 +74,18 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) scene()->addItem(line); create_deco_stop(); } + item->setTime(timeLine->valueAt(mappedPos)); + item->setDepth(depthLine->valueAt(mappedPos)); +} + +void DiveHandler::setDepth(qreal d) +{ + depth = d; +} + +void DiveHandler::setTime(qreal t) +{ + time =t; } void DivePlanner::clear_generated_deco() @@ -200,8 +212,12 @@ void DivePlanner::mousePressEvent(QMouseEvent* event) void DivePlanner::mouseReleaseEvent(QMouseEvent* event) { - if (activeDraggedHandler) + if (activeDraggedHandler){ + QPointF mappedPos = mapToScene(event->pos()); + activeDraggedHandler ->setTime(timeLine->valueAt(mappedPos)); + activeDraggedHandler ->setDepth(depthLine->valueAt(mappedPos)); activeDraggedHandler = 0; + } } DiveHandler::DiveHandler(): QGraphicsEllipseItem(), from(0), to(0) @@ -251,3 +267,11 @@ void Ruler::setTickInterval(double i) { interval = i; } + +qreal Ruler::valueAt(const QPointF& p) +{ + QLineF m = line(); + return orientation == Qt::Horizontal + ? max * (p.x() - m.x1()) / (m.x2() - m.x1()) + : max * (p.y() - m.y1()) / (m.y2() - m.y1()); +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 5557a7b56..f7af25113 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -7,9 +7,14 @@ class DiveHandler : public QGraphicsEllipseItem{ public: DiveHandler(); + void setTime(qreal t); + void setDepth(qreal d); QGraphicsLineItem *from; QGraphicsLineItem *to; +private: + qreal time; + qreal depth; }; class Ruler : public QGraphicsLineItem{ @@ -20,6 +25,7 @@ public: void setTickInterval(double interval); void setOrientation(Qt::Orientation orientation); void updateTicks(); + qreal valueAt(const QPointF& p); private: Qt::Orientation orientation; -- cgit v1.2.3-70-g09d2 From cbdd78c0fca06645248dafe3999bbabd91c48449 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 17:54:36 -0300 Subject: Added text to the rules so the user knows what's happening at that point. Added text to the rules, so the user knows what's happening at that point The text will move left / right ( for time ) and up / down ( for depth ) Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 15 ++++++++++++++- qt-ui/diveplanner.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index fa7be75b3..33a759f1d 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -39,6 +39,16 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedH depthLine->setOrientation(Qt::Vertical); depthLine->updateTicks(); scene()->addItem(depthLine); + + timeString = new QGraphicsSimpleTextItem(); + timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations); + scene()->addItem(timeString); + + depthString = new QGraphicsSimpleTextItem(); + depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); + scene()->addItem(depthString); + + } void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) @@ -127,10 +137,13 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); + depthString->setText(QString::number(depthLine->valueAt(mappedPos))); + depthString->setPos(0, mappedPos.y()); + timeString->setText(QString::number( (int) timeLine->valueAt(mappedPos)) + "min"); + timeString->setPos(mappedPos.x()+1, 90); if(activeDraggedHandler) moveActiveHandler(mappedPos); - if (!handles.count()) return; diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index f7af25113..0e7f6f4b2 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -63,7 +63,10 @@ private: DiveHandler *activeDraggedHandler; Ruler *timeLine; + QGraphicsSimpleTextItem *timeString; + Ruler *depthLine; + QGraphicsSimpleTextItem *depthString; }; #endif -- cgit v1.2.3-70-g09d2 From 0539a5fab67a83da223425e6fcbf2d8775be90e3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 18:02:01 -0300 Subject: Restore the original color of the Handler as soon as mouseRelease. Restore the original color of the handler as soon as mouseRelease, also a bit of code cleanup. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 33a759f1d..4d9aefcb1 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -47,8 +47,6 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedH depthString = new QGraphicsSimpleTextItem(); depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); scene()->addItem(depthString); - - } void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) @@ -109,9 +107,6 @@ void DivePlanner::clear_generated_deco() void DivePlanner::create_deco_stop() { - // this needs to create everything - // for the calculated deco. it should return the *first* - // line that's calculated, so the QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0); scene()->addItem(item); lines << item; @@ -227,8 +222,9 @@ void DivePlanner::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler){ QPointF mappedPos = mapToScene(event->pos()); - activeDraggedHandler ->setTime(timeLine->valueAt(mappedPos)); - activeDraggedHandler ->setDepth(depthLine->valueAt(mappedPos)); + activeDraggedHandler->setTime(timeLine->valueAt(mappedPos)); + activeDraggedHandler->setDepth(depthLine->valueAt(mappedPos)); + activeDraggedHandler->setBrush(QBrush()); activeDraggedHandler = 0; } } -- cgit v1.2.3-70-g09d2 From 8fcd465a65546efd6dd90c6e4d29ff4e93d7dbe8 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 18:25:03 -0300 Subject: Make skeleton of 'create_deco_stop'. This is a skeleton of 'create_deco_stop' plus a bit of code cleanup. I'v commented the create_deco_stop so that the other developers can help me a bit here - since I don't know too well the internals of subsurface. In the original GTK code - a new dive was created every time a user changed something on the dive, I don't know if this will be needed, I jusst need two things: the correct time of dive calculated by the app, and the points to put the decompression lines. The usability of the widget right now is 'ok', nothing to be proud of, it's ugly as hell too, and the Rules are in the wrong position ( they are 'inside' the area where the lines are being drawn, but htis is easily fixable. ) Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 49 +++++++++++++++++++++++++++++++++++-------------- qt-ui/diveplanner.h | 5 +---- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 4d9aefcb1..28a5b5590 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -82,18 +82,8 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) scene()->addItem(line); create_deco_stop(); } - item->setTime(timeLine->valueAt(mappedPos)); - item->setDepth(depthLine->valueAt(mappedPos)); -} - -void DiveHandler::setDepth(qreal d) -{ - depth = d; -} - -void DiveHandler::setTime(qreal t) -{ - time =t; + item->time = (timeLine->valueAt(mappedPos)); + item->depth = (depthLine->valueAt(mappedPos)); } void DivePlanner::clear_generated_deco() @@ -107,6 +97,30 @@ void DivePlanner::clear_generated_deco() void DivePlanner::create_deco_stop() { + // This needs to be done in the following steps: + // Get the user-input and calculate the dive info + Q_FOREACH(DiveHandler *h, handles){ + // use this somewhere. + h->time; + h->depth; + } + // create the dive info here. + + // set the new 'end time' of the dive. + // note that this is not the user end, + // but the real end of the dive. + timeLine->setMaximum(60); + timeLine->updateTicks(); + + // Re-position the user generated dive handlers + Q_FOREACH(DiveHandler *h, handles){ + // uncomment this as soon as the posAtValue is implemented. + // h->setPos( timeLine->posAtValue(h->time), + // depthLine->posAtValue(h->depth)); + } + + // Create all 'deco' GraphicsLineItems and put it on the canvas.This following three lines will + // most probably need to enter on a loop. QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0); scene()->addItem(item); lines << item; @@ -222,8 +236,8 @@ void DivePlanner::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler){ QPointF mappedPos = mapToScene(event->pos()); - activeDraggedHandler->setTime(timeLine->valueAt(mappedPos)); - activeDraggedHandler->setDepth(depthLine->valueAt(mappedPos)); + activeDraggedHandler->time = (timeLine->valueAt(mappedPos)); + activeDraggedHandler->depth = (depthLine->valueAt(mappedPos)); activeDraggedHandler->setBrush(QBrush()); activeDraggedHandler = 0; } @@ -284,3 +298,10 @@ qreal Ruler::valueAt(const QPointF& p) ? max * (p.x() - m.x1()) / (m.x2() - m.x1()) : max * (p.y() - m.y1()) / (m.y2() - m.y1()); } + +qreal Ruler::posAtValue(qreal value) +{ + QLineF m = line(); + // I need to finish this later. hungry as hell. + +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 0e7f6f4b2..ac0d7ebd9 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -7,12 +7,8 @@ class DiveHandler : public QGraphicsEllipseItem{ public: DiveHandler(); - void setTime(qreal t); - void setDepth(qreal d); - QGraphicsLineItem *from; QGraphicsLineItem *to; -private: qreal time; qreal depth; }; @@ -26,6 +22,7 @@ public: void setOrientation(Qt::Orientation orientation); void updateTicks(); qreal valueAt(const QPointF& p); + qreal posAtValue(qreal value); private: Qt::Orientation orientation; -- cgit v1.2.3-70-g09d2 From fdd8a4811bd598cd661cda5a9c057749dc1a11d1 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 18:40:59 -0300 Subject: Added a new class to handle the DivePlanner dialog Added a new class named DivePlanner that is a QDialog, and renamed the old DivePlanner class to DivePlannerGraphics. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 45 +++++++++++++++++++------------ qt-ui/diveplanner.h | 22 ++++++++++++--- qt-ui/diveplanner.ui | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+), 20 deletions(-) create mode 100644 qt-ui/diveplanner.ui diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 28a5b5590..51d018a90 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,14 +1,9 @@ #include "diveplanner.h" #include #include +#include "ui_diveplanner.h" -DivePlanner* DivePlanner::instance() -{ - static DivePlanner *self = new DivePlanner(); - return self; -} - -DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) +DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) { setMouseTracking(true); setScene( new QGraphicsScene()); @@ -49,7 +44,7 @@ DivePlanner::DivePlanner(QWidget* parent): QGraphicsView(parent), activeDraggedH scene()->addItem(depthString); } -void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) +void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) { QPointF mappedPos = mapToScene(event->pos()); if(isPointOutOfBoundaries(mappedPos)) @@ -86,7 +81,7 @@ void DivePlanner::mouseDoubleClickEvent(QMouseEvent* event) item->depth = (depthLine->valueAt(mappedPos)); } -void DivePlanner::clear_generated_deco() +void DivePlannerGraphics::clear_generated_deco() { for(int i = handles.count(); i <= lines.count(); i++){ scene()->removeItem(lines.last()); @@ -95,7 +90,7 @@ void DivePlanner::clear_generated_deco() } } -void DivePlanner::create_deco_stop() +void DivePlannerGraphics::create_deco_stop() { // This needs to be done in the following steps: // Get the user-input and calculate the dive info @@ -126,19 +121,19 @@ void DivePlanner::create_deco_stop() lines << item; } -void DivePlanner::resizeEvent(QResizeEvent* event) +void DivePlannerGraphics::resizeEvent(QResizeEvent* event) { QGraphicsView::resizeEvent(event); fitInView(sceneRect(), Qt::KeepAspectRatio); } -void DivePlanner::showEvent(QShowEvent* event) +void DivePlannerGraphics::showEvent(QShowEvent* event) { QGraphicsView::showEvent(event); fitInView(sceneRect(), Qt::KeepAspectRatio); } -void DivePlanner::mouseMoveEvent(QMouseEvent* event) +void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) { QPointF mappedPos = mapToScene(event->pos()); if (isPointOutOfBoundaries(mappedPos)) @@ -165,7 +160,7 @@ void DivePlanner::mouseMoveEvent(QMouseEvent* event) } } -void DivePlanner::moveActiveHandler(QPointF pos) +void DivePlannerGraphics::moveActiveHandler(QPointF pos) { int idx = handles.indexOf(activeDraggedHandler); bool moveLines = false;; @@ -209,7 +204,7 @@ void DivePlanner::moveActiveHandler(QPointF pos) } } -bool DivePlanner::isPointOutOfBoundaries(QPointF point) +bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point) { if (point.x() > sceneRect().width() || point.x() < 0 @@ -221,7 +216,7 @@ bool DivePlanner::isPointOutOfBoundaries(QPointF point) return false; } -void DivePlanner::mousePressEvent(QMouseEvent* event) +void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) { QPointF mappedPos = mapToScene(event->pos()); Q_FOREACH(QGraphicsItem *item, scene()->items(mappedPos)){ @@ -232,7 +227,7 @@ void DivePlanner::mousePressEvent(QMouseEvent* event) } } -void DivePlanner::mouseReleaseEvent(QMouseEvent* event) +void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) { if (activeDraggedHandler){ QPointF mappedPos = mapToScene(event->pos()); @@ -303,5 +298,21 @@ qreal Ruler::posAtValue(qreal value) { QLineF m = line(); // I need to finish this later. hungry as hell. +} + + +DivePlanner::DivePlanner() : ui(new Ui::DivePlanner()) +{ + ui->setupUi(this); +} + +struct dive* DivePlanner::getDive() +{ + return 0; +} +DivePlanner* DivePlanner::instance() +{ + static DivePlanner *self = new DivePlanner(); + return self; } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index ac0d7ebd9..4a28f2ec1 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -3,6 +3,7 @@ #include #include +#include class DiveHandler : public QGraphicsEllipseItem{ public: @@ -34,10 +35,10 @@ private: double posEnd; }; -class DivePlanner : public QGraphicsView { +class DivePlannerGraphics : public QGraphicsView { Q_OBJECT public: - static DivePlanner *instance(); + DivePlannerGraphics(QWidget* parent = 0); protected: virtual void mouseDoubleClickEvent(QMouseEvent* event); virtual void showEvent(QShowEvent* event); @@ -51,7 +52,7 @@ protected: bool isPointOutOfBoundaries(QPointF point); private: - DivePlanner(QWidget* parent = 0); + void moveActiveHandler(QPointF pos); QList lines; QList handles; @@ -66,4 +67,19 @@ private: QGraphicsSimpleTextItem *depthString; }; + +namespace Ui{ + class DivePlanner; +} + +class DivePlanner : public QDialog{ + Q_OBJECT +public: + static DivePlanner *instance(); + struct dive* getDive(); + +private: + DivePlanner(); + Ui::DivePlanner *ui; +}; #endif diff --git a/qt-ui/diveplanner.ui b/qt-ui/diveplanner.ui new file mode 100644 index 000000000..e4903f0f8 --- /dev/null +++ b/qt-ui/diveplanner.ui @@ -0,0 +1,74 @@ + + + DivePlanner + + + + 0 + 0 + 575 + 451 + + + + Dialog + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + DivePlannerGraphics + QGraphicsView +
diveplanner.h
+
+
+ + + + buttonBox + accepted() + DivePlanner + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + DivePlanner + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
-- cgit v1.2.3-70-g09d2 From 062515ba6f92fa7b4d72403ed195b28ad6d996f7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 18:48:21 -0300 Subject: Added back the menu entry 'Dive Planner' Added back the menu entry Dive Planner, and removed the calee code from the Print action. Signed-off-by: Tomaz Canabrava --- qt-ui/mainwindow.cpp | 12 ++++++++++-- qt-ui/mainwindow.h | 1 + qt-ui/mainwindow.ui | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 75fb21a64..b61f962c4 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -179,11 +179,19 @@ void MainWindow::on_actionExportUDDF_triggered() void MainWindow::on_actionPrint_triggered() { - // hijacking the print action for a while. - DivePlanner::instance()->show(); qDebug("actionPrint"); } +void MainWindow::on_actionDivePlanner_triggered() +{ + DivePlanner *planner = DivePlanner::instance(); + if (planner->exec() == QDialog::Accepted){ + struct dive *d = planner->getDive(); + qDebug() << "Finish me."; + } +} + + void MainWindow::on_actionPreferences_triggered() { PreferencesDialog::instance()->show(); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 0693f07fd..85825958d 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -83,6 +83,7 @@ private slots: void on_actionInputPlan_triggered(); void on_actionAboutSubsurface_triggered(); void on_actionUserManual_triggered(); + void on_actionDivePlanner_triggered(); void current_dive_changed(int divenr); void initialUiSetup(); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index 1a985f812..1dfb8a27b 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -103,7 +103,7 @@ 0 0 763 - 34 + 20 @@ -152,6 +152,8 @@ + + @@ -368,6 +370,11 @@ Ctrl+4 + + + Dive Planner + + -- cgit v1.2.3-70-g09d2 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(-) 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 From 1e4d360d0c12969477122ecf72e6a4e6686142f3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:07:44 -0300 Subject: Do not plot dive handlers outside of the Plane area. This patch makes the behavior of inserting new hanflers correct. it can only be inserted now inside of the plane defined by the Depth ruler and Time ruler. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 22 ++++++++++++++++++---- qt-ui/diveplanner.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 21d134d04..bc774cc83 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -206,10 +206,13 @@ void DivePlannerGraphics::moveActiveHandler(QPointF pos) bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point) { - if (point.x() > sceneRect().width() - || point.x() < 0 - || point.y() < 0 - || point.y() > sceneRect().height()) + double xpos = timeLine->valueAt(point); + double ypos = depthLine->valueAt(point); + + if (xpos > timeLine->maximum() + || xpos < timeLine->minimum() + || ypos > depthLine->maximum() + || ypos < depthLine->minimum()) { return true; } @@ -325,3 +328,14 @@ DivePlanner* DivePlanner::instance() static DivePlanner *self = new DivePlanner(); return self; } + +double Ruler::maximum() const +{ + return max; +} + +double Ruler::minimum() const +{ + return min; +} + diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 4a28f2ec1..ce4dd6d4f 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -22,6 +22,8 @@ public: void setTickInterval(double interval); void setOrientation(Qt::Orientation orientation); void updateTicks(); + double minimum() const; + double maximum() const; qreal valueAt(const QPointF& p); qreal posAtValue(qreal value); -- cgit v1.2.3-70-g09d2 From 43657d99442e4b33f6df502d16e76a8b577b1381 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:12:04 -0300 Subject: Makes the first and last line of the plot inside of the boundingrect This patch makes the first line and the last line of the plot inside of the boundingRect defined by the timeLine and depthLine Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index bc774cc83..65be6f608 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -62,7 +62,9 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) handles << item; if (lines.empty()){ - QGraphicsLineItem *first = new QGraphicsLineItem(0,0, mappedPos.x(), mappedPos.y()); + double xpos = timeLine->posAtValue(0); + double ypos = depthLine->posAtValue(0); + QGraphicsLineItem *first = new QGraphicsLineItem(xpos,ypos, mappedPos.x(), mappedPos.y()); item->from = first; lines.push_back(first); create_deco_stop(); @@ -116,7 +118,9 @@ void DivePlannerGraphics::create_deco_stop() // Create all 'deco' GraphicsLineItems and put it on the canvas.This following three lines will // most probably need to enter on a loop. - QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), 100, 0); + double xpos = timeLine->posAtValue(timeLine->maximum()); + double ypos = depthLine->posAtValue(depthLine->minimum()); + QGraphicsLineItem *item = new QGraphicsLineItem(handles.last()->x(), handles.last()->y(), xpos, ypos); scene()->addItem(item); lines << item; } -- cgit v1.2.3-70-g09d2 From c9159da43a5971d163340f3c2bb1e916952b8e1a Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:14:22 -0300 Subject: Depth doesn't suppose to show broken numbers. This patch makes the depth to show only integers, as dirk asked. I'v also added a 'm' at the end, I know that this will need to be taken from the settings but i feel lazy today =p Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 65be6f608..d9179b038 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -145,7 +145,7 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) verticalLine->setLine(mappedPos.x(), 0, mappedPos.x(), 100); horizontalLine->setLine(0, mappedPos.y(), 100, mappedPos.y()); - depthString->setText(QString::number(depthLine->valueAt(mappedPos))); + depthString->setText(QString::number( (int) depthLine->valueAt(mappedPos)) + "m" ); depthString->setPos(0, mappedPos.y()); timeString->setText(QString::number( (int) timeLine->valueAt(mappedPos)) + "min"); timeString->setPos(mappedPos.x()+1, 90); -- cgit v1.2.3-70-g09d2 From 01d1a49d9448a2b4fd6363cf69260cc305b5e9f3 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:28:17 -0300 Subject: Make the plot and handle movement stick to an 'Grid' Make the plot and the handle stick to a grid, the grid is defined by the integers in the rulers, so a time of 10,2 is converted to 10, and will put the point at 10. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 37 +++++++++++++++++++++++-------------- qt-ui/diveplanner.h | 4 ++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index d9179b038..5d907a627 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -1,4 +1,5 @@ #include "diveplanner.h" +#include #include #include #include "ui_diveplanner.h" @@ -19,7 +20,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) timeLine = new Ruler(); timeLine->setMinimum(0); - timeLine->setMaximum(60); + timeLine->setMaximum(20); timeLine->setTickInterval(10); timeLine->setLine( 10, 90, 99, 90); timeLine->setOrientation(Qt::Horizontal); @@ -28,7 +29,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) depthLine = new Ruler(); depthLine->setMinimum(0); - depthLine->setMaximum(400); + depthLine->setMaximum(10); depthLine->setTickInterval(10); depthLine->setLine( 10, 1, 10, 90); depthLine->setOrientation(Qt::Vertical); @@ -57,7 +58,10 @@ void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) DiveHandler *item = new DiveHandler (); item->setRect(-5,-5,10,10); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); - item->setPos( mappedPos ); + + double xpos = timeLine->posAtValue(rint(timeLine->valueAt(mappedPos))); + double ypos = depthLine->posAtValue(rint(depthLine->valueAt(mappedPos))); + item->setPos( QPointF(xpos, ypos)); scene()->addItem(item); handles << item; @@ -164,41 +168,46 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) } } -void DivePlannerGraphics::moveActiveHandler(QPointF pos) +void DivePlannerGraphics::moveActiveHandler(const QPointF& pos) { int idx = handles.indexOf(activeDraggedHandler); + + double xpos = timeLine->posAtValue(rint(timeLine->valueAt(pos))); + double ypos = depthLine->posAtValue(rint(depthLine->valueAt(pos))); + + QPointF newPos(xpos, ypos); bool moveLines = false;; // do not allow it to move between handlers. if (handles.count() > 1){ if (idx == 0 ){ // first - if (pos.x() < handles[1]->x()){ - activeDraggedHandler->setPos(pos); + if (newPos.x() < handles[1]->x()){ + activeDraggedHandler->setPos(newPos); moveLines = true; } }else if (idx == handles.count()-1){ // last - if (pos.x() > handles[idx-1]->x()){ - activeDraggedHandler->setPos(pos); + if (newPos.x() > handles[idx-1]->x()){ + activeDraggedHandler->setPos(newPos); moveLines = true; } }else{ // middle - if (pos.x() > handles[idx-1]->x() && pos.x() < handles[idx+1]->x()){ - activeDraggedHandler->setPos(pos); + if (newPos.x() > handles[idx-1]->x() && newPos.x() < handles[idx+1]->x()){ + activeDraggedHandler->setPos(newPos); moveLines = true; } } }else{ - activeDraggedHandler->setPos(pos); + activeDraggedHandler->setPos(newPos); moveLines = true; } if (moveLines){ if (activeDraggedHandler->from){ QLineF f = activeDraggedHandler->from->line(); - activeDraggedHandler->from->setLine(f.x1(), f.y1(), pos.x(), pos.y()); + activeDraggedHandler->from->setLine(f.x1(), f.y1(), newPos.x(), newPos.y()); } if (activeDraggedHandler->to){ QLineF f = activeDraggedHandler->to->line(); - activeDraggedHandler->to->setLine(pos.x(), pos.y(), f.x2(), f.y2()); + activeDraggedHandler->to->setLine(newPos.x(), newPos.y(), f.x2(), f.y2()); } if(activeDraggedHandler == handles.last()){ @@ -208,7 +217,7 @@ void DivePlannerGraphics::moveActiveHandler(QPointF pos) } } -bool DivePlannerGraphics::isPointOutOfBoundaries(QPointF point) +bool DivePlannerGraphics::isPointOutOfBoundaries(const QPointF& point) { double xpos = timeLine->valueAt(point); double ypos = depthLine->valueAt(point); diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index ce4dd6d4f..621e8a2a5 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -51,11 +51,11 @@ protected: void clear_generated_deco(); void create_deco_stop(); - bool isPointOutOfBoundaries(QPointF point); + bool isPointOutOfBoundaries(const QPointF& point); private: - void moveActiveHandler(QPointF pos); + void moveActiveHandler(const QPointF& pos); QList lines; QList handles; QGraphicsLineItem *verticalLine; -- cgit v1.2.3-70-g09d2 From 28f48227f72bf7db16b1f53b4d50df7fb5a54131 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:44:38 -0300 Subject: Added a new class to handle the pseudo-buttons on the canvas. Added a new class, named Button, that has a clicked() signal, and can be connected to the view to emulate buttons. While I know that Qt supports widgets on canvas - I think it's too nineties to have such square controls on something that can have rounded borders. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 18 ++++++++++++++++++ qt-ui/diveplanner.h | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 5d907a627..026e9f312 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -43,6 +43,14 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) depthString = new QGraphicsSimpleTextItem(); depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); scene()->addItem(depthString); + + plusDepth = new Button(); + plusDepth->setPos(15, 1); + scene()->addItem(plusDepth); + + plusTime = new Button(); + plusTime->setPos( 95, 90); + scene()->addItem(plusTime); } void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) @@ -352,3 +360,13 @@ double Ruler::minimum() const return min; } +Button::Button(QObject* parent): QObject(parent), QGraphicsPixmapItem() +{ + setPixmap(QPixmap(":plus").scaled(20,20)); + setFlag(ItemIgnoresTransformations); +} + +void Button::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + emit clicked(); +} diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 621e8a2a5..c3ae3eb60 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -5,6 +5,16 @@ #include #include +class Button : public QObject, public QGraphicsPixmapItem { + Q_OBJECT +public: + explicit Button(QObject* parent = 0); +protected: + virtual void mousePressEvent(QGraphicsSceneMouseEvent* event); +signals: + void clicked(); +}; + class DiveHandler : public QGraphicsEllipseItem{ public: DiveHandler(); @@ -52,7 +62,6 @@ protected: void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(const QPointF& point); - private: void moveActiveHandler(const QPointF& pos); @@ -68,6 +77,11 @@ private: Ruler *depthLine; QGraphicsSimpleTextItem *depthString; + Button *plusTime; + Button *plusDepth; + Button *lessTime; + Button *lessDepth; + }; namespace Ui{ -- cgit v1.2.3-70-g09d2 From 880b98ed35c2dbf3b5a015784323894c59bc7feb Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 21 Jun 2013 16:51:13 -0300 Subject: Added the skeleton implementation of the increaseTime and depth Added the skeleton implementation of the increaseTime and increaseDepth methods - they will increase the time / depth by 10 units ( feets / minutes ) each time they are clicked. Signed-off-by: Tomaz Canabrava --- qt-ui/diveplanner.cpp | 13 +++++++++++++ qt-ui/diveplanner.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 026e9f312..d6096f4bb 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -47,10 +47,22 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) plusDepth = new Button(); plusDepth->setPos(15, 1); scene()->addItem(plusDepth); + connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth())); plusTime = new Button(); plusTime->setPos( 95, 90); scene()->addItem(plusTime); + connect(plusTime, SIGNAL(clicked()), this, SLOT(increaseTime())); +} + +void DivePlannerGraphics::increaseDepth() +{ + qDebug() << "Increase Depth Clicked"; +} + +void DivePlannerGraphics::increaseTime() +{ + qDebug() << "Increase Time Clicked"; } void DivePlannerGraphics::mouseDoubleClickEvent(QMouseEvent* event) @@ -249,6 +261,7 @@ void DivePlannerGraphics::mousePressEvent(QMouseEvent* event) activeDraggedHandler->setBrush(Qt::red); } } + QGraphicsView::mousePressEvent(event); } void DivePlannerGraphics::mouseReleaseEvent(QMouseEvent* event) diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index c3ae3eb60..453cec63e 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -62,6 +62,11 @@ protected: void clear_generated_deco(); void create_deco_stop(); bool isPointOutOfBoundaries(const QPointF& point); + +private slots: + void increaseTime(); + void increaseDepth(); + private: void moveActiveHandler(const QPointF& pos); -- cgit v1.2.3-70-g09d2