Added double click feature to MapView.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 16 Jun 2010 07:19:19 +0000 (10:19 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Wed, 16 Jun 2010 07:19:19 +0000 (10:19 +0300)
src/map/mapview.cpp
src/map/mapview.h
src/ui/mainwindow.cpp
tests/map/mapview/testmapview.cpp

index abef941..f1279a4 100644 (file)
@@ -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();
index 855a3f7..74cf630 100644 (file)
@@ -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
  ******************************************************************************/
index 1bb61cd..8e31618 100644 (file)
@@ -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()
index 7179447..60b0c72 100644 (file)
@@ -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()