diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-20 18:40:59 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-20 18:40:59 -0300 |
commit | fdd8a4811bd598cd661cda5a9c057749dc1a11d1 (patch) | |
tree | 85f5cdec65d7d06d69c3a3021a88fa67af847ced | |
parent | 8fcd465a65546efd6dd90c6e4d29ff4e93d7dbe8 (diff) | |
download | subsurface-fdd8a4811bd598cd661cda5a9c057749dc1a11d1.tar.gz |
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 <tcanabrava@kde.org>
-rw-r--r-- | qt-ui/diveplanner.cpp | 45 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 22 | ||||
-rw-r--r-- | qt-ui/diveplanner.ui | 74 |
3 files changed, 121 insertions, 20 deletions
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 <QMouseEvent> #include <QDebug> +#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 <QGraphicsView> #include <QGraphicsPathItem> +#include <QDialog> 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<QGraphicsLineItem*> lines; QList<DiveHandler *> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>DivePlanner</class> + <widget class="QDialog" name="DivePlanner"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>575</width> + <height>451</height> + </rect> + </property> + <property name="windowTitle"> + <string>Dialog</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="DivePlannerGraphics" name="graphicsView"/> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>DivePlannerGraphics</class> + <extends>QGraphicsView</extends> + <header>diveplanner.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>DivePlanner</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>DivePlanner</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> |