From d24a30a854c82d981d53ed6551aafa3725b7ad3c Mon Sep 17 00:00:00 2001 From: Jussi Laitinen Date: Wed, 16 Jun 2010 10:19:19 +0300 Subject: [PATCH] Added double click feature to MapView. --- src/map/mapview.cpp | 7 +++++++ src/map/mapview.h | 14 +++++++++++++- src/ui/mainwindow.cpp | 3 +++ tests/map/mapview/testmapview.cpp | 13 +++++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/map/mapview.cpp b/src/map/mapview.cpp index abef941..f1279a4 100644 --- a/src/map/mapview.cpp +++ b/src/map/mapview.cpp @@ -50,6 +50,13 @@ void MapView::centerToSceneCoordinates(QPoint sceneCoordinate) centerOn(sceneCoordinate); } +void MapView::mouseDoubleClickEvent(QMouseEvent *event) +{ + qWarning() << __PRETTY_FUNCTION__ << event->pos().x() << event->pos().y(); + + emit zoomIn(); +} + void MapView::mouseMoveEvent(QMouseEvent *event) { m_scenePosition += m_mousePosition - mapToScene(event->pos()).toPoint(); diff --git a/src/map/mapview.h b/src/map/mapview.h index 855a3f7..74cf630 100644 --- a/src/map/mapview.h +++ b/src/map/mapview.h @@ -57,13 +57,20 @@ public: ******************************************************************************/ protected: /** + * @brief Event handler for mouse double click event + * + * Emits zoomIn signal. + * @param event QMouseEvent + */ + void mouseDoubleClickEvent(QMouseEvent *event); + + /** * @brief Called when view is resized. * * @param event resize event */ void resizeEvent(QResizeEvent *event); -private: /** * @brief Event handler for mouse move events * @@ -140,6 +147,11 @@ signals: */ void viewZoomFinished(); + /** + * @brief Signal for zooming in. + */ + void zoomIn(); + /******************************************************************************* * DATA MEMBERS ******************************************************************************/ diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 1bb61cd..8e31618 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -255,6 +255,9 @@ void MainWindow::buildMap() connect(m_mapView, SIGNAL(viewZoomFinished()), this, SIGNAL(viewZoomFinished())); + + connect(m_mapView, SIGNAL(zoomIn()), + this, SIGNAL(zoomIn())); } void MainWindow::buildMapScale() diff --git a/tests/map/mapview/testmapview.cpp b/tests/map/mapview/testmapview.cpp index 7179447..60b0c72 100644 --- a/tests/map/mapview/testmapview.cpp +++ b/tests/map/mapview/testmapview.cpp @@ -32,6 +32,7 @@ public: private slots: void init(); void cleanup(); + void doubleClick(); void zoomLevelChange_data(); void zoomLevelChange(); @@ -66,6 +67,18 @@ void TestMapView::cleanup() } /** + * @brief Test view double click + */ +void TestMapView::doubleClick() +{ + QSignalSpy doubleClickSpy(m_mapView, SIGNAL(zoomIn())); + QVERIFY(doubleClickSpy.isValid()); + + QTest::mouseDClick(m_mapView, Qt::LeftButton); + QCOMPARE(doubleClickSpy.count(), 1); +} + +/** * @brief Test data for zoom level change test */ void TestMapView::zoomLevelChange_data() -- 1.7.9.5