insilmaril@0
|
1 |
#include "flagobj.h"
|
insilmaril@0
|
2 |
|
insilmaril@0
|
3 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
4 |
// FlagObj
|
insilmaril@0
|
5 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
6 |
FlagObj::FlagObj()
|
insilmaril@0
|
7 |
{
|
insilmaril@166
|
8 |
// cout << "Const FlagObj ()\n";
|
insilmaril@0
|
9 |
init ();
|
insilmaril@0
|
10 |
}
|
insilmaril@0
|
11 |
|
insilmaril@408
|
12 |
FlagObj::FlagObj(QGraphicsScene* s):MapObj(s)
|
insilmaril@0
|
13 |
{
|
insilmaril@408
|
14 |
// cout << "Const FlagObj this="<<this<<" scene="<<s<<endl;
|
insilmaril@0
|
15 |
init ();
|
insilmaril@0
|
16 |
}
|
insilmaril@0
|
17 |
|
insilmaril@0
|
18 |
FlagObj::FlagObj (FlagObj* io)
|
insilmaril@0
|
19 |
{
|
insilmaril@0
|
20 |
copy (io);
|
insilmaril@0
|
21 |
}
|
insilmaril@0
|
22 |
|
insilmaril@767
|
23 |
FlagObj::FlagObj (Flag* f)
|
insilmaril@767
|
24 |
{
|
insilmaril@767
|
25 |
init();
|
insilmaril@767
|
26 |
name=f->getName();
|
insilmaril@767
|
27 |
icon->load(f->getPixmap());
|
insilmaril@767
|
28 |
}
|
insilmaril@767
|
29 |
|
insilmaril@0
|
30 |
FlagObj::~FlagObj()
|
insilmaril@0
|
31 |
{
|
insilmaril@655
|
32 |
// cout << "Destr FlagObj this="<<this <<" " << qPrintable(name) << "\n";
|
insilmaril@166
|
33 |
if (icon) delete (icon);
|
insilmaril@0
|
34 |
}
|
insilmaril@0
|
35 |
|
insilmaril@0
|
36 |
|
insilmaril@0
|
37 |
void FlagObj::init ()
|
insilmaril@0
|
38 |
{
|
insilmaril@0
|
39 |
name="undefined";
|
insilmaril@0
|
40 |
|
insilmaril@408
|
41 |
icon=new ImageObj (scene);
|
insilmaril@408
|
42 |
icon->setPos (absPos.x(), absPos.y() );
|
insilmaril@0
|
43 |
state=false;
|
insilmaril@580
|
44 |
avis=true;
|
insilmaril@0
|
45 |
}
|
insilmaril@0
|
46 |
|
insilmaril@0
|
47 |
void FlagObj::copy (FlagObj* other)
|
insilmaril@0
|
48 |
{
|
insilmaril@0
|
49 |
MapObj::copy(other);
|
insilmaril@0
|
50 |
name=other->name;
|
insilmaril@0
|
51 |
state=other->state;
|
insilmaril@580
|
52 |
avis=other->avis;
|
insilmaril@0
|
53 |
icon->copy(other->icon);
|
insilmaril@0
|
54 |
setVisibility (other->isVisibleObj() );
|
insilmaril@0
|
55 |
}
|
insilmaril@0
|
56 |
|
insilmaril@0
|
57 |
void FlagObj::move(double x, double y)
|
insilmaril@0
|
58 |
{
|
insilmaril@0
|
59 |
MapObj::move(x,y);
|
insilmaril@408
|
60 |
icon->setPos(x,y);
|
insilmaril@0
|
61 |
positionBBox();
|
insilmaril@0
|
62 |
}
|
insilmaril@0
|
63 |
|
insilmaril@0
|
64 |
void FlagObj::moveBy(double x, double y)
|
insilmaril@0
|
65 |
{
|
insilmaril@0
|
66 |
move (x+absPos.x(),y+absPos.y() );
|
insilmaril@0
|
67 |
}
|
insilmaril@0
|
68 |
|
insilmaril@0
|
69 |
void FlagObj::setVisibility (bool v)
|
insilmaril@0
|
70 |
{
|
insilmaril@0
|
71 |
MapObj::setVisibility(v);
|
insilmaril@0
|
72 |
if (v && state)
|
insilmaril@0
|
73 |
icon->setVisibility(true);
|
insilmaril@0
|
74 |
else
|
insilmaril@0
|
75 |
icon->setVisibility(false);
|
insilmaril@0
|
76 |
}
|
insilmaril@0
|
77 |
|
insilmaril@0
|
78 |
void FlagObj::load (const QString &fn)
|
insilmaril@0
|
79 |
{
|
insilmaril@0
|
80 |
icon->load(fn);
|
insilmaril@0
|
81 |
calcBBoxSize();
|
insilmaril@0
|
82 |
positionBBox();
|
insilmaril@0
|
83 |
}
|
insilmaril@0
|
84 |
|
insilmaril@0
|
85 |
void FlagObj::load (const QPixmap &pm)
|
insilmaril@0
|
86 |
{
|
insilmaril@0
|
87 |
icon->load(pm);
|
insilmaril@0
|
88 |
calcBBoxSize();
|
insilmaril@0
|
89 |
positionBBox();
|
insilmaril@0
|
90 |
}
|
insilmaril@0
|
91 |
|
insilmaril@0
|
92 |
void FlagObj::setName(const QString &n)
|
insilmaril@0
|
93 |
{
|
insilmaril@0
|
94 |
name=n;
|
insilmaril@0
|
95 |
}
|
insilmaril@0
|
96 |
|
insilmaril@0
|
97 |
const QString FlagObj::getName()
|
insilmaril@0
|
98 |
{
|
insilmaril@0
|
99 |
return name;
|
insilmaril@0
|
100 |
}
|
insilmaril@0
|
101 |
|
insilmaril@580
|
102 |
void FlagObj::setAlwaysVisible(bool b)
|
insilmaril@580
|
103 |
{
|
insilmaril@580
|
104 |
avis=b;
|
insilmaril@580
|
105 |
}
|
insilmaril@580
|
106 |
|
insilmaril@580
|
107 |
bool FlagObj::isAlwaysVisible()
|
insilmaril@580
|
108 |
{
|
insilmaril@580
|
109 |
return avis;
|
insilmaril@366
|
110 |
}
|
insilmaril@366
|
111 |
|
insilmaril@0
|
112 |
bool FlagObj::isActive()
|
insilmaril@0
|
113 |
{
|
insilmaril@0
|
114 |
return state;
|
insilmaril@0
|
115 |
}
|
insilmaril@0
|
116 |
|
insilmaril@0
|
117 |
void FlagObj::toggle()
|
insilmaril@0
|
118 |
{
|
insilmaril@0
|
119 |
if (state)
|
insilmaril@0
|
120 |
deactivate();
|
insilmaril@0
|
121 |
else
|
insilmaril@0
|
122 |
activate();
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
void FlagObj::activate()
|
insilmaril@0
|
126 |
{
|
insilmaril@0
|
127 |
state=true;
|
insilmaril@0
|
128 |
// only show icon, if flag itself is visible
|
insilmaril@0
|
129 |
if (visible)
|
insilmaril@0
|
130 |
{
|
insilmaril@0
|
131 |
icon->setVisibility (true);
|
insilmaril@0
|
132 |
calcBBoxSize();
|
insilmaril@0
|
133 |
}
|
insilmaril@0
|
134 |
}
|
insilmaril@0
|
135 |
|
insilmaril@0
|
136 |
void FlagObj::deactivate()
|
insilmaril@0
|
137 |
{
|
insilmaril@0
|
138 |
state=false;
|
insilmaril@0
|
139 |
// if flag itself is invisible we don't need to call
|
insilmaril@0
|
140 |
if (visible)
|
insilmaril@0
|
141 |
{
|
insilmaril@0
|
142 |
icon->setVisibility (false);
|
insilmaril@0
|
143 |
calcBBoxSize();
|
insilmaril@0
|
144 |
}
|
insilmaril@0
|
145 |
}
|
insilmaril@0
|
146 |
|
insilmaril@0
|
147 |
void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
|
insilmaril@0
|
148 |
{
|
insilmaril@0
|
149 |
QString fn=tmpdir + prefix + name + ".png";
|
insilmaril@0
|
150 |
icon->save (fn,"PNG");
|
insilmaril@0
|
151 |
}
|
insilmaril@0
|
152 |
|
insilmaril@0
|
153 |
void FlagObj::positionBBox()
|
insilmaril@0
|
154 |
{
|
insilmaril@172
|
155 |
bbox.moveTopLeft (absPos );
|
insilmaril@172
|
156 |
clickBox.moveTopLeft (absPos );
|
insilmaril@0
|
157 |
}
|
insilmaril@0
|
158 |
|
insilmaril@0
|
159 |
void FlagObj::calcBBoxSize()
|
insilmaril@0
|
160 |
{
|
insilmaril@0
|
161 |
if (visible && state)
|
insilmaril@408
|
162 |
bbox.setSize ( QSizeF(
|
insilmaril@0
|
163 |
icon->boundingRect().width(),
|
insilmaril@0
|
164 |
icon->boundingRect().height() ) );
|
insilmaril@763
|
165 |
else
|
insilmaril@408
|
166 |
bbox.setSize (QSizeF(0,0));
|
insilmaril@172
|
167 |
clickBox.setSize (bbox.size());
|
insilmaril@0
|
168 |
}
|
insilmaril@0
|
169 |
|