Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 559fdde9e559ce9f281cf19be93b424384ca97c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
   mapwidget.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_MAPWIDGET__
#define __INCLUDED_EDITOR_MAPWIDGET__

#include "entityproperties.h"

#include <QWidget>
#include <QList>

namespace editor
{

class EntityWidget;
class Manipulator;

/**
 * @brief MapWidget shows the zone map with the blue grid line
 * */
class MapWidget : public QWidget
{
	Q_OBJECT
	
public:
	MapWidget(QWidget *parent = 0);
	
	/**
	 * @brief add an entity to the map
	 * */
	EntityWidget *addEntity();
	
	void save(QTextStream &textstream);
	
	/**
	 * @brief return the currently selected entity
	 * */
	inline EntityWidget *selected() {
		return mapwidget_selected;
	}
	
	/**
	 * @return the current map zoom factor
	 * */
	float zoom() const;

protected:
	
	/**
	 * @brief handle draw events
	 * */
	virtual void paintEvent(QPaintEvent *event);
	
	/**
	 * @brief handle resize events
	 * */
	virtual void resizeEvent(QResizeEvent *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);

	/**
	 * @brief handle mousewheel events
	 * */	
	virtual void wheelEvent(QWheelEvent *event);
	
	/**
	 * @brief handle keypress events
	 * */	
	virtual void keyPressEvent(QKeyEvent *event);

signals:
	/**
	 * @brief the selected() signal is emitted if an entity on the map is selected
	 * */
	void propertiesChanged(EntityProperties *properties);

public slots:
	/**
	 * @brief move and resize child widgets
	 * This should be called whenever a child location on the map has changed.
	 * */
	void resizeChildren();
	
	/**
	 * @brief delete selected entities
	 * */
	void deleteSelected();
	
	/**
	 * @brief duplicate selected entities
	 * */
	void duplicateSelected();
	
	/**
	 * @brief called when an entity on the map has been clicked
	 * */
	void select(EntityWidget *entity);
	
private slots:	
	/**
	 * @brief clear current selection
	 * */
	void deselect();
	
	/**
	 * @brief entity is dragged
	 * */
	void dragEntity(EntityWidget *entity, int x, int y);
	
private:
	void doBoxSelect();
	
	typedef QList<EntityWidget *> Entities;
	
	int dragstart_x;
	int dragstart_y;
	
	int dragstop_x;
	int dragstop_y;
	
	bool is_dragging;
	bool is_box_selecting;
	
	// zoom factor, as a power of 2
	int			mapwidget_zoomfactor;
	
	// center of the map, in world coordinates
	Vector3f		mapwidget_center;

	Entities		mapwidget_enties;
	EntityWidget		*mapwidget_selected;
	
	Manipulator		*mapwidget_manipulator;
};

}

#endif // __INCLUDED_EDITOR_MAPWIDGET__