From 0d45c775725f23e96b018df4e23c2776a3186030 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 20 Jun 2013 12:37:41 -0300 Subject: [PATCH] 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); };