Added initial version of zoom button panel classes & related gfx
authorPekka Nissinen <pekka.nissinen@ixonos.com>
Wed, 21 Apr 2010 07:53:59 +0000 (10:53 +0300)
committerPekka Nissinen <pekka.nissinen@ixonos.com>
Wed, 21 Apr 2010 07:53:59 +0000 (10:53 +0300)
src/map/mapbutton.cpp [new file with mode: 0644]
src/map/mapbutton.h [new file with mode: 0644]
src/map/mapzoompanel.cpp [new file with mode: 0644]
src/map/mapzoompanel.h [new file with mode: 0644]
src/resources/zoom_in.png [new file with mode: 0644]
src/resources/zoom_out.png [new file with mode: 0644]

diff --git a/src/map/mapbutton.cpp b/src/map/mapbutton.cpp
new file mode 100644 (file)
index 0000000..4c73cc3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Pekka Nissinen - pekka.nissinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QDebug>
+#include <QPixmap>
+
+#include "mapbutton.h"
+#include "mapcommon.h"
+
+MapButton::MapButton(QString fileName)
+    : m_buttonMode(QIcon::Normal),
+    m_buttonWidth(MAP_ZOOM_PANEL_BUTTON_SIZE),
+    m_buttonHeight(MAP_ZOOM_PANEL_BUTTON_SIZE)
+{
+    QPixmap pixmap(fileName);
+
+    // Temporary (lazy fix) solution to get the buttons larger
+    addPixmap(pixmap.scaled(m_buttonWidth, m_buttonHeight, Qt::KeepAspectRatio, Qt::FastTransformation));
+}
+
+void MapButton::draw(QPainter *painter, int x, int y)
+{
+    paint(painter, x, y, m_buttonWidth, m_buttonHeight, NULL, m_buttonMode);
+}
+
+void MapButton::setMode(QIcon::Mode mode)
+{
+    m_buttonMode = mode;
+}
diff --git a/src/map/mapbutton.h b/src/map/mapbutton.h
new file mode 100644 (file)
index 0000000..137e340
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Pekka Nissinen - pekka.nissinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef MAPBUTTON_H
+#define MAPBUTTON_H
+
+#include <QIcon>
+#include <QString>
+#include <QPainter>
+
+class MapButton : public QIcon
+{
+public:
+    MapButton(QString fileName);
+    void draw(QPainter *painter, int x, int y);
+    void setMode(QIcon::Mode mode);
+
+private:
+    QIcon::Mode m_buttonMode;
+    int m_buttonWidth;
+    int m_buttonHeight;
+};
+
+#endif // MAPBUTTON_H
diff --git a/src/map/mapzoompanel.cpp b/src/map/mapzoompanel.cpp
new file mode 100644 (file)
index 0000000..361f7d4
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Pekka Nissinen - pekka.nissinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QDebug>
+
+#include "mapcommon.h"
+#include "mapzoompanel.h"
+
+MapZoomPanel::MapZoomPanel(QGraphicsItem *parent, int x, int y) : QGraphicsItem(parent)
+{
+    m_x = x;
+    m_y = y;
+    m_width = MAP_ZOOM_PANEL_BUTTON_SIZE;
+    m_height = MAP_ZOOM_PANEL_BUTTON_SIZE * 2;
+
+    m_zoomInBtn = new MapButton(":/resources/zoom_in.png");
+    m_zoomOutBtn = new MapButton(":/resources/zoom_out.png");
+
+    setFlag(QGraphicsItem::ItemIgnoresTransformations);
+    setZValue(static_cast<qreal>(MAP_ZOOM_PANEL_LEVEL));
+}
+
+QRectF MapZoomPanel::boundingRect() const
+{
+    return QRectF(m_x, m_y, m_width, m_height);
+}
+
+void MapZoomPanel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+    Q_UNUSED(option);
+    Q_UNUSED(widget);
+
+    m_zoomInBtn->draw(painter, m_x, m_y);
+    m_zoomOutBtn->draw(painter, m_x, m_y + MAP_ZOOM_PANEL_BUTTON_SIZE);
+}
+
+void MapZoomPanel::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+    if ( event->pos().y() < (m_y + MAP_ZOOM_PANEL_BUTTON_SIZE) )
+        m_zoomInBtn->setMode(QIcon::Selected);
+    else
+        m_zoomOutBtn->setMode(QIcon::Selected);
+
+    update();
+
+//    qDebug() << __PRETTY_FUNCTION__;
+}
+
+void MapZoomPanel::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+{
+    Q_UNUSED(event);
+
+    m_zoomInBtn->setMode(QIcon::Normal);
+    m_zoomOutBtn->setMode(QIcon::Normal);
+
+    if ( event->pos().y() < (m_y + MAP_ZOOM_PANEL_BUTTON_SIZE) )
+        emit zoomInPressed();
+    else
+        emit zoomOutPressed();
+
+    update();
+
+//    qDebug() << __PRETTY_FUNCTION__;
+}
diff --git a/src/map/mapzoompanel.h b/src/map/mapzoompanel.h
new file mode 100644 (file)
index 0000000..c136ad3
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Pekka Nissinen - pekka.nissinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#ifndef MAPZOOMPANEL_H
+#define MAPZOOMPANEL_H
+
+#include <QRectF>
+#include <QWidget>
+#include <QPainter>
+#include <QGraphicsItem>
+#include <QStyleOptionGraphicsItem>
+#include <QGraphicsSceneMouseEvent>
+
+#include "mapbutton.h"
+
+class MapZoomPanel : public QObject, public QGraphicsItem
+{
+    Q_OBJECT
+
+public:
+    MapZoomPanel(QGraphicsItem *parent = 0, int x = 0, int y = 0);
+    QRectF boundingRect() const;
+    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
+
+protected:
+    void mousePressEvent(QGraphicsSceneMouseEvent *event);
+    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+
+signals:
+    void zoomInPressed();
+    void zoomOutPressed();
+
+private:
+    MapButton *m_zoomInBtn;
+    MapButton *m_zoomOutBtn;
+
+    qreal m_x;
+    qreal m_y;
+    qreal m_width;
+    qreal m_height;
+};
+
+#endif // MAPZOOMPANEL_H
diff --git a/src/resources/zoom_in.png b/src/resources/zoom_in.png
new file mode 100644 (file)
index 0000000..c2a84fc
Binary files /dev/null and b/src/resources/zoom_in.png differ
diff --git a/src/resources/zoom_out.png b/src/resources/zoom_out.png
new file mode 100644 (file)
index 0000000..ba6ffbc
Binary files /dev/null and b/src/resources/zoom_out.png differ