summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-04-02 23:12:17 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-04-02 23:12:17 -0400
commit2fde19547c222ff6bb3fce6e462f53336939aa2b (patch)
tree3072309ebc8010a0b8002ce241284f43f6e57635
parentd911d9fe8bb2378070142610c8bdfe9ed505c56a (diff)
Allow for pressing spacebar to lock the item
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapItem.cpp45
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapItem.h4
2 files changed, 47 insertions, 2 deletions
diff --git a/sigmodr/widgets/mapeditor/WorldMapItem.cpp b/sigmodr/widgets/mapeditor/WorldMapItem.cpp
index 588cecb1..9b44b143 100644
--- a/sigmodr/widgets/mapeditor/WorldMapItem.cpp
+++ b/sigmodr/widgets/mapeditor/WorldMapItem.cpp
@@ -29,15 +29,23 @@
#include <KColorScheme>
// Qt includes
+#include <QtCore/QtConcurrentFilter>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QGraphicsSimpleTextItem>
+#include <QtGui/QKeyEvent>
#include <QtGui/QPainter>
#include <QtGui/QStyleOptionGraphicsItem>
using namespace Sigmod;
using namespace Sigmodr::Widgets;
+bool isSetWorldMapItem(QGraphicsItem* item)
+{
+ WorldMapItem* world = qgraphicsitem_cast<WorldMapItem*>(item);
+ return world && world->isLocked();
+}
+
WorldMapItem::WorldMapItem(Game* game, Map* map, QGraphicsScene* parent) :
QObject(parent),
m_game(game),
@@ -96,6 +104,11 @@ int WorldMapItem::type() const
return Type;
}
+bool WorldMapItem::isLocked() const
+{
+ return m_locked;
+}
+
void WorldMapItem::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
m_label->show();
@@ -112,11 +125,39 @@ void WorldMapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
void WorldMapItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
+ QList<QGraphicsItem*> items = scene()->items();
+ QtConcurrent::blockingFilter(items, isSetWorldMapItem);
+ items.removeAll(this);
+ if (items.size())
{
+ }
+ else
QGraphicsItem::mouseMoveEvent(event);
- moveTo(scenePos().toPoint());
- update();
+ moveTo(scenePos().toPoint());
+ update();
+}
+
+void WorldMapItem::keyPressEvent(QKeyEvent* event)
+{
+ if (event->key() == Qt::Key_Space)
+ {
+ QList<QGraphicsItem*> items;
+ if (!m_locked)
+ {
+ items = scene()->items(QRectF(scenePos(), boundingRect().adjusted(1, 1, -1, -1).size()));
+ QtConcurrent::blockingFilter(items, isSetWorldMapItem);
+ items.removeAll(this);
+ }
+ if (!items.size())
+ {
+ event->accept();
+ m_locked = !m_locked;
+ setFlag(ItemIsMovable, !m_locked);
+ update();
+ return;
+ }
}
+ event->ignore();
}
void WorldMapItem::moveTo(const QPoint& point)
diff --git a/sigmodr/widgets/mapeditor/WorldMapItem.h b/sigmodr/widgets/mapeditor/WorldMapItem.h
index e6cef81b..38e70098 100644
--- a/sigmodr/widgets/mapeditor/WorldMapItem.h
+++ b/sigmodr/widgets/mapeditor/WorldMapItem.h
@@ -59,6 +59,8 @@ class SIGMODRWIDGETS_NO_EXPORT WorldMapItem : public QObject, public QGraphicsIt
bool collidesWithItem(const QGraphicsItem* other, const Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
int type() const;
+
+ bool isLocked() const;
signals:
void changed();
@@ -67,6 +69,7 @@ class SIGMODRWIDGETS_NO_EXPORT WorldMapItem : public QObject, public QGraphicsIt
void hoverEnterEvent(QGraphicsSceneHoverEvent* event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent* event);
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
+ void keyPressEvent(QKeyEvent* event);
void moveTo(const QPoint& point);
protected slots:
@@ -76,6 +79,7 @@ class SIGMODRWIDGETS_NO_EXPORT WorldMapItem : public QObject, public QGraphicsIt
Sigmod::Game* m_game;
Sigmod::Map* m_map;
+ bool m_locked;
QList<TileItem*> m_tiles;
QGraphicsSimpleTextItem* m_tag;
QGraphicsSimpleTextItem* m_label;