selection.cpp
author insilmaril
Wed, 11 Apr 2007 09:21:17 +0000
changeset 456 8cc3cb71f345
parent 440 c6a8651e6bbc
child 460 12e763c3e486
permissions -rw-r--r--
Updated documentation about macros
insilmaril@0
     1
#include "selection.h"
insilmaril@0
     2
insilmaril@440
     3
#include "mainwindow.h"
insilmaril@440
     4
#include "mapeditor.h"
insilmaril@440
     5
insilmaril@440
     6
insilmaril@440
     7
insilmaril@440
     8
extern Main *mainWindow;
insilmaril@0
     9
insilmaril@0
    10
Selection::Selection()
insilmaril@0
    11
{
insilmaril@440
    12
	color= QColor(255,255,0);
insilmaril@0
    13
}
insilmaril@0
    14
insilmaril@0
    15
Selection::~Selection()
insilmaril@0
    16
{
insilmaril@0
    17
}
insilmaril@0
    18
insilmaril@440
    19
void Selection::setMapEditor (MapEditor *me)
insilmaril@0
    20
{
insilmaril@440
    21
	mapEditor=me;
insilmaril@440
    22
	mapCenter=me->getMapCenter();
insilmaril@440
    23
	scene=mapCenter->getScene();
insilmaril@0
    24
}
insilmaril@0
    25
insilmaril@0
    26
void Selection::copy(const Selection &other)
insilmaril@0
    27
{
insilmaril@16
    28
	mapCenter=other.mapCenter;
insilmaril@16
    29
	selectList=other.selectList;
insilmaril@421
    30
	lastSelectList=other.lastSelectList;
insilmaril@0
    31
}
insilmaril@0
    32
insilmaril@0
    33
void Selection::clear()
insilmaril@0
    34
{
insilmaril@424
    35
	unselect();
insilmaril@421
    36
	lastSelectList.clear();
insilmaril@0
    37
}
insilmaril@0
    38
insilmaril@440
    39
void Selection::update()
insilmaril@440
    40
{
insilmaril@440
    41
	QRectF bbox;
insilmaril@440
    42
	int w=0;
insilmaril@440
    43
	for (int i=0; i< selectList.count(); ++i) 
insilmaril@440
    44
	{
insilmaril@440
    45
		bbox=selectList.at(i)->getBBox();
insilmaril@440
    46
		selboxList.at(i)->setRect (
insilmaril@440
    47
			bbox.x()-w,bbox.y()-w, 
insilmaril@440
    48
			bbox.width()+2*w, bbox.height()+2*w);
insilmaril@440
    49
		selboxList.at(i)->setPen (color);	
insilmaril@440
    50
		selboxList.at(i)->setBrush (color);	
insilmaril@440
    51
	}	
insilmaril@440
    52
}
insilmaril@440
    53
insilmaril@440
    54
void Selection::setColor (QColor col)
insilmaril@440
    55
{
insilmaril@440
    56
	color=col;
insilmaril@440
    57
	update();
insilmaril@440
    58
}
insilmaril@440
    59
insilmaril@440
    60
QColor Selection::getColor ()
insilmaril@440
    61
{
insilmaril@440
    62
	return color;
insilmaril@440
    63
}
insilmaril@440
    64
insilmaril@421
    65
bool Selection::select(LinkableMapObj *lmo)	// TODO no multiselections yet
insilmaril@0
    66
{
insilmaril@424
    67
	if (!selectList.isEmpty()) unselect();
insilmaril@16
    68
	selectList.append (lmo);
insilmaril@440
    69
	QGraphicsRectItem *sb = scene->addRect(
insilmaril@440
    70
		QRectF(0,0,0,0), 
insilmaril@440
    71
		QPen(color),
insilmaril@440
    72
		color);
insilmaril@440
    73
	sb->setZValue(Z_SELBOX);
insilmaril@440
    74
	selboxList.append (sb);
insilmaril@424
    75
	lmo->select();
insilmaril@440
    76
	mainWindow->updateSatellites (mapEditor);	// update branchPropWindow...
insilmaril@424
    77
	return true;
insilmaril@0
    78
}
insilmaril@0
    79
insilmaril@421
    80
bool Selection::select (const QString &s)	// TODO no multiselections yet
insilmaril@0
    81
{
insilmaril@16
    82
	LinkableMapObj *lmo=mapCenter->findObjBySelect(s);
insilmaril@16
    83
insilmaril@16
    84
	// Finally select the found object
insilmaril@16
    85
	if (lmo)
insilmaril@16
    86
	{
insilmaril@424
    87
		unselect();
insilmaril@16
    88
		select (lmo);
insilmaril@16
    89
		return true;
insilmaril@16
    90
	} 
insilmaril@16
    91
	return false;
insilmaril@16
    92
insilmaril@16
    93
}
insilmaril@16
    94
insilmaril@421
    95
bool Selection::reselect ()	// TODO no multiselections yet
insilmaril@421
    96
{
insilmaril@421
    97
	if (!lastSelectList.isEmpty())
insilmaril@421
    98
	{
insilmaril@421
    99
		select (lastSelectList.first());
insilmaril@421
   100
		return true;
insilmaril@421
   101
	}
insilmaril@421
   102
	return false;
insilmaril@421
   103
insilmaril@421
   104
}
insilmaril@421
   105
insilmaril@16
   106
void Selection::unselect()
insilmaril@16
   107
{
insilmaril@424
   108
	if (!selectList.isEmpty() )
insilmaril@424
   109
	{
insilmaril@424
   110
		for (int i=0; i< selectList.count(); ++i) 
insilmaril@424
   111
			selectList.at(i)->unselect();
insilmaril@424
   112
		lastSelectList=selectList;
insilmaril@424
   113
		selectList.clear();
insilmaril@440
   114
		while (!selboxList.isEmpty() )
insilmaril@440
   115
			delete selboxList.takeFirst();
insilmaril@440
   116
insilmaril@424
   117
	}	
insilmaril@0
   118
}
insilmaril@0
   119
insilmaril@0
   120
bool Selection::isEmpty()
insilmaril@0
   121
{
insilmaril@0
   122
	return selectList.isEmpty();
insilmaril@0
   123
}
insilmaril@0
   124
insilmaril@0
   125
uint Selection::count()
insilmaril@0
   126
{
insilmaril@0
   127
	return selectList.count();
insilmaril@0
   128
}
insilmaril@16
   129
insilmaril@421
   130
SelectionType Selection::type() // TODO no multiselections yet
insilmaril@16
   131
{
insilmaril@421
   132
	if (!selectList.isEmpty())
insilmaril@421
   133
	{
insilmaril@421
   134
		LinkableMapObj *sel=selectList.first();
insilmaril@421
   135
		if (typeid (*sel)==typeid (BranchObj)) return Branch;
insilmaril@421
   136
		if (typeid (*sel)==typeid (MapCenterObj)) return MapCenter;
insilmaril@421
   137
		if (typeid (*sel)==typeid (FloatImageObj)) return FloatImage;
insilmaril@421
   138
	}
insilmaril@421
   139
	return Undefined;
insilmaril@421
   140
}
insilmaril@421
   141
insilmaril@424
   142
LinkableMapObj* Selection::first()
insilmaril@424
   143
{
insilmaril@424
   144
	if (!selectList.isEmpty())
insilmaril@424
   145
		return selectList.first();
insilmaril@424
   146
	else	
insilmaril@424
   147
		return NULL;
insilmaril@424
   148
}
insilmaril@424
   149
insilmaril@424
   150
LinkableMapObj* Selection::single()
insilmaril@424
   151
{
insilmaril@424
   152
	if (selectList.count() == 1)
insilmaril@424
   153
		return selectList.first();
insilmaril@424
   154
	else	
insilmaril@424
   155
		return NULL;
insilmaril@424
   156
}
insilmaril@424
   157
insilmaril@424
   158
BranchObj* Selection::getBranch()
insilmaril@424
   159
{
insilmaril@424
   160
	if (!selectList.isEmpty())
insilmaril@424
   161
	{
insilmaril@424
   162
		LinkableMapObj *sel=selectList.first();
insilmaril@424
   163
		if (typeid (*sel)==typeid (BranchObj) ||
insilmaril@424
   164
		    typeid (*sel)==typeid (MapCenterObj)) 
insilmaril@424
   165
			return (BranchObj*)sel;
insilmaril@424
   166
	}
insilmaril@424
   167
		return NULL;
insilmaril@424
   168
}
insilmaril@424
   169
insilmaril@424
   170
FloatImageObj* Selection::getFloatImage()
insilmaril@424
   171
{
insilmaril@424
   172
	if (!selectList.isEmpty())
insilmaril@424
   173
	{
insilmaril@424
   174
		LinkableMapObj *sel=selectList.first();
insilmaril@424
   175
		if (typeid (*sel)==typeid (FloatImageObj)) 
insilmaril@424
   176
			return (FloatImageObj*)sel;
insilmaril@424
   177
	}
insilmaril@424
   178
		return NULL;
insilmaril@424
   179
}
insilmaril@424
   180
insilmaril@421
   181
QString Selection::getSelectString()// TODO no multiselections yet
insilmaril@421
   182
{
insilmaril@16
   183
	if (selectList.count()==1)
insilmaril@16
   184
		return selectList.first()->getSelectString();
insilmaril@16
   185
	else
insilmaril@16
   186
		return"";
insilmaril@16
   187
}
insilmaril@16
   188
insilmaril@16
   189