From 7a9c504720e494ee07d16a6234b77c500af4da93 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 19 Feb 2012 14:50:24 +0000 Subject: Renamed class MapEntity to EntityWidget, added entity dragging. --- src/entitywidget.h | 150 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/entitywidget.h (limited to 'src/entitywidget.h') diff --git a/src/entitywidget.h b/src/entitywidget.h new file mode 100644 index 0000000..04a925b --- /dev/null +++ b/src/entitywidget.h @@ -0,0 +1,150 @@ +/* + entitywidget.h + This file is part of the Project::OSiRiON world editor + and is distributed under the terms and conditions of + the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_EDITOR_ENTITYWIDGET__ +#define __INCLUDED_EDITOR_ENTITYWIDGET__ + +#include +#include +#include + +namespace editor +{ + +/** + * @brief a Widget resembling an entity on the map + * */ +class EntityWidget : public QWidget +{ + Q_OBJECT + +public: + EntityWidget(QWidget *parent = 0); + + /** + * @brief returns the entity label + * */ + inline const QString &label() const { + return entity_label; + } + + /** + * @brief returns the entity name + * */ + inline const QString &name() const { + return entity_name; + } + + /** + * @brief returns the entity radius + * */ + inline const float radius() const { + return entity_radius; + } + + /** + * @brief returns the x, y, or z coordinate of the entity location + * */ + inline const float location(int index) const { + return entity_location[index]; + } + + /** + * @brief returns the properties string + * */ + inline const QString &properties() const { + return entity_properties; + } + +signals: + /** + * @brief this signal is emitted if the entity is clicked with the left mouse button + * */ + void clicked(EntityWidget *entity); + + /** + * @brief this signal is emitted if the entity is dragged + * */ + void dragged(EntityWidget *entity, int x, int y); + +public slots: + + /** + * @brief set the entity name + * */ + void set_label(const QString &label); + + /** + * @brief set the entity label + * */ + void set_name(const QString &name); + + /** + * @brief set the entity radius + * */ + void set_radius(const float radius); + + /** + * @brief set the entity location + * */ + void set_location(const float x, const float y, const float z); + + /** + * @brief set the entity properties string + * */ + void set_properties(const QString &properties); + + /** + * @brief add a property + * */ + void add_property(const QString &key, const QString &value); + + /** + * @brief set the selected state + * */ + void set_selected(const bool selected); + +protected: + /** + * @brief handle draw events + * */ + virtual void paintEvent(QPaintEvent *event); + + /** + * @brief handle mouse button press events + * */ + virtual void mousePressEvent(QMouseEvent *event); + + /** + * @brief handle mouse button press events + * */ + virtual void mouseReleaseEvent(QMouseEvent *event); + + /** + * @brief handle mouse move press events + * */ + virtual void mouseMoveEvent(QMouseEvent *event); + +private: + bool is_selected; + bool is_dragging; + + QString entity_label; + QString entity_name; + QString entity_type; + + QString entity_properties; + + float entity_location[3]; + float entity_radius; + + QColor entity_color; +}; + +} + +#endif // __INCLUDED_EDITOR_ENTITYWIDGET__ -- cgit v1.2.3