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