summaryrefslogtreecommitdiffstats
path: root/weather
diff options
context:
space:
mode:
authorLuiz Agostini <luiz.agostini@openbossa.org>2009-10-31 18:37:53 -0300
committerLuiz Agostini <luiz.agostini@openbossa.org>2009-11-05 00:42:09 -0300
commit20d5aea3940dd19b3c5c6235f13476c6d14e05b0 (patch)
tree78ceeda12ec7c8a7862a597734ffd1567b801348 /weather
parent811d314901d68ee14eedda6369201a978a2db666 (diff)
Weather: pixmap button.
Signed-off-by: Luiz Agostini <luiz.agostini@openbossa.org>
Diffstat (limited to 'weather')
-rw-r--r--weather/pixmapbutton.cpp30
-rw-r--r--weather/pixmapbutton.h25
-rw-r--r--weather/weather.pro6
3 files changed, 59 insertions, 2 deletions
diff --git a/weather/pixmapbutton.cpp b/weather/pixmapbutton.cpp
new file mode 100644
index 0000000..6ec8be5
--- /dev/null
+++ b/weather/pixmapbutton.cpp
@@ -0,0 +1,30 @@
+#include "pixmapbutton.h"
+
+// PixmapButton
+
+PixmapButton::PixmapButton(qreal minSize, const QPixmap &pixmap, QGraphicsItem *parent)
+ : QGraphicsPixmapItem(pixmap, parent)
+ , m_minSize(minSize)
+{
+ setShapeMode(BoundingRectShape);
+}
+
+void PixmapButton::mousePressEvent(QGraphicsSceneMouseEvent *event)
+{
+ Q_UNUSED(event);
+ emit clicked();
+}
+
+QPainterPath PixmapButton::shape() const
+{
+ return QGraphicsItem::shape();
+}
+
+QRectF PixmapButton::boundingRect() const
+{
+ QRectF result(QGraphicsPixmapItem::boundingRect());
+ qreal hMargin = m_minSize < result.width() ? 0 : (m_minSize - result.width()) / 2;
+ qreal vMargin = m_minSize < result.height() ? 0 : (m_minSize - result.height()) / 2;
+ result.adjust(-hMargin, -vMargin, hMargin, vMargin);
+ return result;
+}
diff --git a/weather/pixmapbutton.h b/weather/pixmapbutton.h
new file mode 100644
index 0000000..51ed153
--- /dev/null
+++ b/weather/pixmapbutton.h
@@ -0,0 +1,25 @@
+#ifndef PIXMAPBUTTON_H
+#define PIXMAPBUTTON_H
+
+#include <QObject>
+#include <QGraphicsPixmapItem>
+
+class PixmapButton: public QObject, public QGraphicsPixmapItem
+{
+ Q_OBJECT
+public:
+ PixmapButton(qreal minSize, const QPixmap &pixmap, QGraphicsItem *parent = 0);
+ QRectF boundingRect() const;
+ QPainterPath shape() const;
+
+signals:
+ void clicked();
+
+protected:
+ void mousePressEvent(QGraphicsSceneMouseEvent *event);
+
+private:
+ const qreal m_minSize;
+};
+
+#endif // PIXMAPBUTTON_H
diff --git a/weather/weather.pro b/weather/weather.pro
index 33635bc..cb72ac4 100644
--- a/weather/weather.pro
+++ b/weather/weather.pro
@@ -43,7 +43,8 @@ HEADERS += mainview.h \
loading.h \
forecastprovider.h \
forecastdata.h \
- bootmanager.h
+ bootmanager.h \
+ pixmapbutton.h
SOURCES += mainview.cpp \
main.cpp \
settings.cpp \
@@ -59,4 +60,5 @@ SOURCES += mainview.cpp \
pixmaploader.cpp \
loading.cpp \
forecastprovider.cpp \
- bootmanager.cpp
+ bootmanager.cpp \
+ pixmapbutton.cpp