summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/MapItem.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-03-18 16:44:48 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-03-18 16:44:48 -0400
commitaf989f491d03263230e44f04bab2a708de793939 (patch)
tree91404c041f63f22f260bd534aba0901c94e02c4e /sigmodr/widgets/MapItem.cpp
parentcf4f88d72c135933387ccca9267610c94c9c2038 (diff)
downloadsigen-af989f491d03263230e44f04bab2a708de793939.tar.gz
sigen-af989f491d03263230e44f04bab2a708de793939.tar.xz
sigen-af989f491d03263230e44f04bab2a708de793939.zip
Added a base class for the map items
Diffstat (limited to 'sigmodr/widgets/MapItem.cpp')
-rw-r--r--sigmodr/widgets/MapItem.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/sigmodr/widgets/MapItem.cpp b/sigmodr/widgets/MapItem.cpp
new file mode 100644
index 00000000..4105d59d
--- /dev/null
+++ b/sigmodr/widgets/MapItem.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2008-2009 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Header include
+#include "MapItem.h"
+
+// Qt includes
+#include <QtGui/QGraphicsScene>
+#include <QtGui/QGraphicsSceneMouseEvent>
+#include <QtGui/QStyleOptionGraphicsItem>
+
+using namespace Sigmodr::Widgets;
+
+MapItem::MapItem(const bool resizable, QGraphicsScene* parent) :
+ QObject(parent),
+ m_resizable(resizable)
+{
+ setAcceptHoverEvents(true);
+}
+
+void MapItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+{
+ Q_UNUSED(painter)
+ Q_UNUSED(option)
+ Q_UNUSED(widget)
+ if (m_resizable && (option->state & QStyle::State_MouseOver))
+ {
+ // TODO: Draw handle for resizing
+ }
+}
+
+void MapItem::focusInEvent(QFocusEvent* event)
+{
+ QGraphicsItem::focusInEvent(event);
+ update();
+}
+
+void MapItem::focusOutEvent(QFocusEvent* event)
+{
+ QGraphicsItem::focusOutEvent(event);
+ update();
+}
+
+void MapItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
+{
+ QGraphicsItem::hoverEnterEvent(event);
+ update();
+}
+
+void MapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
+{
+ QGraphicsItem::hoverLeaveEvent(event);
+ update();
+}
+
+void MapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
+{
+ if (m_resizable && (event->button() & Qt::RightButton))
+ {
+ event->accept();
+ emit(resize(event->pos() - event->lastPos()));
+ }
+ else
+ QGraphicsItem::mouseMoveEvent(event);
+}
+
+void MapItem::resize(const QPointF& size)
+{
+}