diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-03-18 16:44:48 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-03-18 16:44:48 -0400 |
commit | af989f491d03263230e44f04bab2a708de793939 (patch) | |
tree | 91404c041f63f22f260bd534aba0901c94e02c4e /sigmodr | |
parent | cf4f88d72c135933387ccca9267610c94c9c2038 (diff) | |
download | sigen-af989f491d03263230e44f04bab2a708de793939.tar.gz sigen-af989f491d03263230e44f04bab2a708de793939.tar.xz sigen-af989f491d03263230e44f04bab2a708de793939.zip |
Added a base class for the map items
Diffstat (limited to 'sigmodr')
-rw-r--r-- | sigmodr/widgets/CMakeLists.txt | 2 | ||||
-rw-r--r-- | sigmodr/widgets/MapItem.cpp | 83 | ||||
-rw-r--r-- | sigmodr/widgets/MapItem.h | 61 |
3 files changed, 146 insertions, 0 deletions
diff --git a/sigmodr/widgets/CMakeLists.txt b/sigmodr/widgets/CMakeLists.txt index 458babbf..a113ace0 100644 --- a/sigmodr/widgets/CMakeLists.txt +++ b/sigmodr/widgets/CMakeLists.txt @@ -17,6 +17,7 @@ set(sigmodrwidgets_HEADERS ItemUI.h ItemTypeUI.h MapUI.h + MapItem.h MapEffectUI.h MapTrainerUI.h MapTrainerTeamMemberUI.h @@ -55,6 +56,7 @@ set(sigmodrwidgets_SRCS ItemUI.cpp ItemTypeUI.cpp MapUI.cpp + MapItem.cpp MapEffectUI.cpp MapTrainerUI.cpp MapTrainerTeamMemberUI.cpp 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) +{ +} diff --git a/sigmodr/widgets/MapItem.h b/sigmodr/widgets/MapItem.h new file mode 100644 index 00000000..4595546f --- /dev/null +++ b/sigmodr/widgets/MapItem.h @@ -0,0 +1,61 @@ +/* + * 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/>. + */ + +#ifndef SIGMODRWIDGETS_MAPITEM +#define SIGMODRWIDGETS_MAPITEM + +// Sigmodr widget includes +#include "Global.h" + +// Qt includes +#include <QtCore/QObject> +#include <QtGui/QGraphicsItem> + +// Forward declarations +class QGraphicsScene; + +namespace Sigmodr +{ +namespace Widgets +{ +class SIGMODRWIDGETS_NO_EXPORT MapItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + MapItem(const bool resizable, QGraphicsScene* parent); + + virtual QRectF boundingRect() const = 0; + + virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget); + signals: + void changed(); + protected: + virtual void focusInEvent(QFocusEvent* event); + virtual void focusOutEvent(QFocusEvent* event); + virtual void hoverEnterEvent(QGraphicsSceneHoverEvent* event); + virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent* event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + + virtual void resize(const QPointF& size); + + const bool m_resizable; +}; +} +} + +#endif |