Zoom map using HW increase and decrease keys hw_zoom_buttons
authorSami Rämö <sami.ramo@ixonos.com>
Fri, 14 May 2010 08:11:04 +0000 (11:11 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Fri, 14 May 2010 08:11:04 +0000 (11:11 +0300)
 - Reviewed by Kaj

src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h

index 7ec617d..377c4f9 100644 (file)
 #include "settingsdialog.h"
 #include "facebookservice/facebookauthentication.h"
 
+#include <QtGui/QX11Info>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
     m_email(),
@@ -65,13 +69,22 @@ MainWindow::MainWindow(QWidget *parent)
     connect(this, SIGNAL(positionReceived(QPointF)),
             m_mapViewScreen, SLOT(positionReceived(QPointF)));
 
+    connect(this, SIGNAL(zoomInKeyPressed()),
+            m_mapViewScreen, SIGNAL(zoomInKeyPressed()));
+    connect(this, SIGNAL(zoomOutKeyPressed()),
+            m_mapViewScreen, SIGNAL(zoomOutKeyPressed()));
+
     this->toggleProgressIndicator(true);
+
+    grabZoomKeys(true);
 }
 
 MainWindow::~MainWindow()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    grabZoomKeys(false);
+
     if(m_webView)
         delete m_webView;
 }
@@ -301,3 +314,45 @@ void MainWindow::loadDone(bool done)
         }
     }
 }
+
+void MainWindow::grabZoomKeys(bool grab)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+#ifdef Q_WS_MAEMO_5
+    // Can't grab keys unless we have a window id
+    if (!winId())
+        return;
+
+    unsigned long val = (grab) ? 1 : 0;
+    Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+    if (!atom)
+        return;
+
+    XChangeProperty (QX11Info::display(),
+                     winId(),
+                     atom,
+                     XA_INTEGER,
+                     32,
+                     PropModeReplace,
+                     reinterpret_cast<unsigned char *>(&val),
+                     1);
+#endif // Q_WS_MAEMO_5
+}
+
+void MainWindow::keyPressEvent(QKeyEvent* event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    switch (event->key()) {
+    case Qt::Key_F7:
+        event->accept();
+        emit zoomInKeyPressed();
+        break;
+
+    case Qt::Key_F8:
+        event->accept();
+        emit zoomOutKeyPressed();
+        break;
+    }
+    QWidget::keyPressEvent(event);
+}
index 7c13fb4..bace273 100644 (file)
@@ -62,6 +62,15 @@ public:
     ~MainWindow();
 
 /*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+private:
+    /**
+      * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
+      */
+    void keyPressEvent(QKeyEvent* event);
+
+/*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 public slots:
@@ -112,7 +121,14 @@ private:
     */
     void createMenus();
 
-       /**
+    /**
+      * @brief Grab or release HW increase and decrease buttons.
+      *
+      * @param grab Use true for grabbing and false for releasing the keys
+      */
+    void grabZoomKeys(bool grab);
+
+    /**
     * @brief Show Maemo information box with message.
     *
     * @brief message information message
@@ -159,6 +175,12 @@ private slots:
  ******************************************************************************/
 signals:
     /**
+    * @brief Signal that indicates when user has cancelled login process
+    *
+    */
+    void cancelLoginProcess();
+
+    /**
     * @brief Signal for map auto centering
     *
     * @param enabled true if map should auto center to gps location
@@ -228,10 +250,14 @@ signals:
     void userLocationReady(User *user);
 
     /**
-    * @brief Signal that indicates when user has cancelled login process
-    *
-    */
-    void cancelLoginProcess();
+      * @brief Signal for HW increase button
+      */
+    void zoomInKeyPressed();
+
+    /**
+      * @brief Signal for HW decrease button
+      */
+    void zoomOutKeyPressed();
 
 /*******************************************************************************
  * DATA MEMBERS
index e367a6c..0849490 100644 (file)
@@ -54,6 +54,11 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     connect(mapView, SIGNAL(viewZoomFinished()),
             mapEngine, SLOT(viewZoomFinished()));
 
+    connect(this, SIGNAL(zoomInKeyPressed()),
+            mapEngine, SLOT(zoomIn()));
+    connect(this, SIGNAL(zoomOutKeyPressed()),
+            mapEngine, SLOT(zoomOut()));
+
     connect(mapView, SIGNAL(viewResizedNewSize(int,int)),
             this, SLOT(drawOsmLicense(int, int)));
 
index f62cc54..0359c60 100644 (file)
@@ -78,13 +78,6 @@ private slots:
  ******************************************************************************/
 signals:
     /**
-    * @brief Signal when user location is fetched
-    *
-    * @param user User data
-    */
-    void userLocationReady(User *user);
-
-    /**
     * @brief Signal when friend list locations are fetched
     *
     * Forwarded to map engine and friends list panel
@@ -93,6 +86,23 @@ signals:
     */
     void friendsLocationsReady(QList<User *> &friendsList);
 
+    /**
+    * @brief Signal when user location is fetched
+    *
+    * @param user User data
+    */
+    void userLocationReady(User *user);
+
+    /**
+      * @brief Signal for HW increase button
+      */
+    void zoomInKeyPressed();
+
+    /**
+      * @brief Signal for HW decrease button
+      */
+    void zoomOutKeyPressed();
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/