flagrowobj.cpp
author insilmaril
Mon, 14 Dec 2009 10:17:55 +0000
changeset 817 b486ffd0fa11
parent 767 6d2b32f305f9
permissions -rw-r--r--
Bugfix for relinking mainbranches
insilmaril@766
     1
#include <QToolBar>
insilmaril@766
     2
insilmaril@766
     3
#include <iostream>
insilmaril@766
     4
using namespace std;
insilmaril@766
     5
insilmaril@767
     6
#include "flag.h"
insilmaril@0
     7
#include "flagrowobj.h"
insilmaril@766
     8
insilmaril@644
     9
#include "geometry.h"
insilmaril@0
    10
insilmaril@0
    11
/////////////////////////////////////////////////////////////////
insilmaril@0
    12
// FlagRowObj
insilmaril@0
    13
/////////////////////////////////////////////////////////////////
insilmaril@0
    14
FlagRowObj::FlagRowObj()
insilmaril@0
    15
{
insilmaril@166
    16
//    cout << "Const FlagRowObj ()\n";
insilmaril@0
    17
    init ();
insilmaril@0
    18
}
insilmaril@0
    19
insilmaril@408
    20
FlagRowObj::FlagRowObj(QGraphicsScene* s):MapObj(s) 
insilmaril@0
    21
{
insilmaril@408
    22
//    cout << "Const FlagRowObj (s)\n";
insilmaril@0
    23
    init ();
insilmaril@0
    24
}
insilmaril@0
    25
insilmaril@0
    26
FlagRowObj::~FlagRowObj()
insilmaril@0
    27
{
insilmaril@425
    28
	//cout << "Destr FlagRowObj\n";
insilmaril@406
    29
	while (!flag.isEmpty())
insilmaril@425
    30
		delete (flag.takeFirst() );
insilmaril@0
    31
}
insilmaril@0
    32
insilmaril@0
    33
void FlagRowObj::init ()
insilmaril@0
    34
{
insilmaril@256
    35
	showFlags=true;
insilmaril@0
    36
}
insilmaril@0
    37
insilmaril@0
    38
void FlagRowObj::copy (FlagRowObj* other)
insilmaril@0
    39
{
insilmaril@0
    40
    MapObj::copy(other);
insilmaril@0
    41
	flag.clear();
insilmaril@406
    42
	for (int i=0; i<flag.size(); ++i)
insilmaril@406
    43
		addFlag (flag.at(i));
insilmaril@0
    44
}
insilmaril@0
    45
insilmaril@0
    46
void FlagRowObj::move(double x, double y)
insilmaril@0
    47
{
insilmaril@0
    48
    MapObj::move(x,y);
insilmaril@408
    49
	qreal dx=0;
insilmaril@406
    50
	for (int i=0; i<flag.size(); ++i)
insilmaril@0
    51
	{
insilmaril@406
    52
		flag.at(i)->move(x+dx,y);
insilmaril@408
    53
		dx+=QSizeF(flag.at(i)->getSize() ).width();
insilmaril@0
    54
	}
insilmaril@0
    55
}
insilmaril@0
    56
insilmaril@0
    57
void FlagRowObj::moveBy(double x, double y)
insilmaril@0
    58
{
insilmaril@0
    59
    move (x+absPos.x(),y+absPos.y() );
insilmaril@0
    60
}
insilmaril@0
    61
insilmaril@0
    62
void FlagRowObj::setVisibility (bool v)
insilmaril@0
    63
{
insilmaril@0
    64
	MapObj::setVisibility(v);
insilmaril@406
    65
	for (int i=0; i<flag.size(); ++i)
insilmaril@406
    66
		flag.at(i)->setVisibility (v);
insilmaril@0
    67
}
insilmaril@0
    68
insilmaril@0
    69
FlagObj* FlagRowObj::addFlag (FlagObj *fo)
insilmaril@0
    70
{
insilmaril@408
    71
	FlagObj *newfo=new FlagObj (scene);
insilmaril@408
    72
	newfo->copy (fo);	// create a deep copy of fo
insilmaril@0
    73
	newfo->move (absPos.x() + bbox.width(), absPos.y() );
insilmaril@0
    74
	flag.append(newfo);
insilmaril@0
    75
	calcBBoxSize();
insilmaril@0
    76
	positionBBox();
insilmaril@0
    77
	return newfo;
insilmaril@0
    78
}
insilmaril@0
    79
insilmaril@767
    80
QStringList FlagRowObj::activeFlagNames()
insilmaril@767
    81
{
insilmaril@767
    82
	QStringList list;
insilmaril@767
    83
	for (int i=0; i<flag.size(); ++i)
insilmaril@767
    84
		list.append (flag.at(i)->getName());
insilmaril@767
    85
	return list;
insilmaril@767
    86
}
insilmaril@767
    87
insilmaril@0
    88
void FlagRowObj::positionBBox()
insilmaril@0
    89
{
insilmaril@173
    90
    bbox.moveTopLeft(absPos );
insilmaril@173
    91
    clickBox.moveTopLeft(absPos );
insilmaril@0
    92
}
insilmaril@0
    93
insilmaril@0
    94
void FlagRowObj::calcBBoxSize()
insilmaril@0
    95
{
insilmaril@408
    96
	QSizeF size(0,0);
insilmaril@408
    97
	QSizeF boxsize(0,0);
insilmaril@406
    98
	for (int i=0; i<flag.size(); ++i)
insilmaril@0
    99
	{
insilmaril@406
   100
		size=flag.at(i)->getSize();
insilmaril@0
   101
		// add widths
insilmaril@0
   102
		boxsize.setWidth(boxsize.width() + size.width() );
insilmaril@0
   103
		// maximize height
insilmaril@0
   104
		if (size.height() > boxsize.height() ) 
insilmaril@0
   105
			boxsize.setHeight(size.height() );
insilmaril@0
   106
	}
insilmaril@173
   107
	bbox.setSize (boxsize);
insilmaril@173
   108
	clickBox.setSize (boxsize);
insilmaril@0
   109
}
insilmaril@0
   110
insilmaril@408
   111
QString FlagRowObj::getFlagName (const QPointF &p)
insilmaril@0
   112
{
insilmaril@754
   113
	if (!isInBox (p,clickBox)) return "";
insilmaril@406
   114
	for (int i=0; i<flag.size(); ++i)
insilmaril@754
   115
		if (isInBox (p,flag.at(i)->getClickBox ())) return flag.at(i)->getName();
insilmaril@0
   116
	return "";	
insilmaril@0
   117
insilmaril@0
   118
	
insilmaril@0
   119
}
insilmaril@0
   120
insilmaril@0
   121
bool FlagRowObj::isActive (const QString &foname)
insilmaril@0
   122
{
insilmaril@767
   123
insilmaril@0
   124
	FlagObj *fo=findFlag (foname);
insilmaril@767
   125
	if (fo) 
insilmaril@767
   126
		return true;
insilmaril@236
   127
	else
insilmaril@767
   128
		return false;
insilmaril@0
   129
}
insilmaril@0
   130
insilmaril@767
   131
void FlagRowObj::activate (Flag *flag)	
insilmaril@0
   132
{
insilmaril@767
   133
	if (flag) 
insilmaril@0
   134
	{
insilmaril@767
   135
		FlagObj *fo=addFlag (new FlagObj (flag));
insilmaril@767
   136
		fo->activate();
insilmaril@767
   137
		if (showFlags)	// FIXME-3 necessary? only called from FIO::init
insilmaril@767
   138
			fo->setVisibility (visible);
insilmaril@0
   139
		else
insilmaril@767
   140
			fo->setVisibility (false);
insilmaril@767
   141
		calcBBoxSize();
insilmaril@0
   142
	}
insilmaril@0
   143
}
insilmaril@0
   144
insilmaril@0
   145
void FlagRowObj::deactivate (const QString &foname)
insilmaril@0
   146
{
insilmaril@0
   147
	FlagObj *fo=findFlag (foname);
insilmaril@408
   148
	if (fo) 
insilmaril@408
   149
	{
insilmaril@408
   150
		flag.remove(fo);
insilmaril@408
   151
		delete (fo);
insilmaril@408
   152
	}	
insilmaril@0
   153
	calcBBoxSize();
insilmaril@0
   154
	positionBBox();
insilmaril@0
   155
}
insilmaril@0
   156
insilmaril@256
   157
void FlagRowObj::setShowFlags (bool b)
insilmaril@256
   158
{
insilmaril@256
   159
	showFlags=b;
insilmaril@256
   160
}
insilmaril@256
   161
insilmaril@0
   162
FlagObj* FlagRowObj::findFlag (const QString &name)
insilmaril@0
   163
{
insilmaril@406
   164
	for (int i=0; i<flag.size(); ++i)
insilmaril@406
   165
		if (flag.at(i)->getName()==name) return flag.at(i);
insilmaril@0
   166
	return NULL;
insilmaril@0
   167
}
insilmaril@0
   168