File: selection.cpp

package info (click to toggle)
vym 1.10.0-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,376 kB
  • ctags: 1,926
  • sloc: cpp: 18,468; xml: 277; sh: 211; perl: 89; makefile: 26
file content (191 lines) | stat: -rw-r--r-- 3,375 bytes parent folder | download
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "selection.h"

#include "mainwindow.h"
#include "mapeditor.h"



extern Main *mainWindow;

Selection::Selection()
{
	color= QColor(255,255,0);
}

Selection::~Selection()
{
}

void Selection::setMapEditor (MapEditor *me)
{
	mapEditor=me;
	mapCenter=me->getMapCenter();
	scene=mapCenter->getScene();
}

void Selection::copy(const Selection &other)
{
	mapCenter=other.mapCenter;
	selectList=other.selectList;
	lastSelectList=other.lastSelectList;
}

void Selection::clear()
{
	unselect();
	lastSelectList.clear();
}

void Selection::update()
{
	QRectF bbox;
	int w=0;
	for (int i=0; i< selectList.count(); ++i) 
	{
		bbox=selectList.at(i)->getBBox();
		selboxList.at(i)->setRect (
			bbox.x()-w,bbox.y()-w, 
			bbox.width()+2*w, bbox.height()+2*w);
		selboxList.at(i)->setPen (color);	
		selboxList.at(i)->setBrush (color);	
	}	
}

void Selection::setColor (QColor col)
{
	color=col;
	update();
}

QColor Selection::getColor ()
{
	return color;
}

bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
{
	if (!selectList.isEmpty()) unselect();
	selectList.append (lmo);
	QGraphicsRectItem *sb = scene->addRect(
		QRectF(0,0,0,0), 
		QPen(color),
		color);
	sb->setZValue(Z_SELBOX);
	sb->show();
	selboxList.append (sb);
	lmo->select();
	update();
	mainWindow->updateSatellites (mapEditor);	// update branchPropWindow...
	return true;
}

bool Selection::select (const QString &s)	// TODO no multiselections yet
{
	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);

	// Finally select the found object
	if (lmo)
	{
		unselect();
		select (lmo);
		return true;
	} 
	return false;

}

bool Selection::reselect ()	// TODO no multiselections yet
{
	if (!lastSelectList.isEmpty())
	{
		select (lastSelectList.first());
		return true;
	}
	return false;

}

void Selection::unselect()
{
	if (!selectList.isEmpty() )
	{
		for (int i=0; i< selectList.count(); ++i) 
			selectList.at(i)->unselect();
		lastSelectList=selectList;
		selectList.clear();
		while (!selboxList.isEmpty() )
			delete selboxList.takeFirst();

	}	
}

bool Selection::isEmpty()
{
	return selectList.isEmpty();
}

uint Selection::count()
{
	return selectList.count();
}

Selection::Type Selection::type() // TODO no multiselections yet
{
	if (!selectList.isEmpty())
	{
		LinkableMapObj *sel=selectList.first();
		if (typeid (*sel)==typeid (BranchObj)) return Branch;
		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
	}
	return Undefined;
}

LinkableMapObj* Selection::first()
{
	if (!selectList.isEmpty())
		return selectList.first();
	else	
		return NULL;
}

LinkableMapObj* Selection::single()
{
	if (selectList.count() == 1)
		return selectList.first();
	else	
		return NULL;
}

BranchObj* Selection::getBranch()
{
	if (!selectList.isEmpty())
	{
		LinkableMapObj *sel=selectList.first();
		if (typeid (*sel)==typeid (BranchObj) ||
		    typeid (*sel)==typeid (MapCenterObj)) 
			return (BranchObj*)sel;
	}
		return NULL;
}

FloatImageObj* Selection::getFloatImage()
{
	if (!selectList.isEmpty())
	{
		LinkableMapObj *sel=selectList.first();
		if (typeid (*sel)==typeid (FloatImageObj)) 
			return (FloatImageObj*)sel;
	}
		return NULL;
}

QString Selection::getSelectString()// TODO no multiselections yet
{
	if (selectList.count()==1)
		return selectList.first()->getSelectString();
	else
		return"";
}