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@0
|
8 |
// cout << "Const FlagObj ()\n";
|
insilmaril@0
|
9 |
init ();
|
insilmaril@0
|
10 |
}
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
FlagObj::FlagObj(QCanvas* c):MapObj(c)
|
insilmaril@0
|
13 |
{
|
insilmaril@0
|
14 |
// cout << "Const FlagObj\n";
|
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@0
|
23 |
FlagObj::~FlagObj()
|
insilmaril@0
|
24 |
{
|
insilmaril@0
|
25 |
// cout << "Destr FlagObj " << name << "\n";
|
insilmaril@0
|
26 |
delete (icon);
|
insilmaril@0
|
27 |
}
|
insilmaril@0
|
28 |
|
insilmaril@0
|
29 |
|
insilmaril@0
|
30 |
void FlagObj::init ()
|
insilmaril@0
|
31 |
{
|
insilmaril@0
|
32 |
name="undefined";
|
insilmaril@103
|
33 |
group="undefined";
|
insilmaril@0
|
34 |
|
insilmaril@0
|
35 |
icon=new ImageObj (canvas);
|
insilmaril@0
|
36 |
icon->move (absPos.x(), absPos.y() );
|
insilmaril@0
|
37 |
button=NULL;
|
insilmaril@0
|
38 |
state=false;
|
insilmaril@0
|
39 |
}
|
insilmaril@0
|
40 |
|
insilmaril@0
|
41 |
void FlagObj::copy (FlagObj* other)
|
insilmaril@0
|
42 |
{
|
insilmaril@0
|
43 |
MapObj::copy(other);
|
insilmaril@0
|
44 |
name=other->name;
|
insilmaril@103
|
45 |
group=other->group;
|
insilmaril@0
|
46 |
tooltip=other->tooltip;
|
insilmaril@0
|
47 |
state=other->state;
|
insilmaril@0
|
48 |
icon->copy(other->icon);
|
insilmaril@0
|
49 |
setVisibility (other->isVisibleObj() );
|
insilmaril@0
|
50 |
// button is not copied, because
|
insilmaril@0
|
51 |
// we won't copy to a parentRow and
|
insilmaril@0
|
52 |
// all others don't need a button
|
insilmaril@0
|
53 |
}
|
insilmaril@0
|
54 |
|
insilmaril@0
|
55 |
void FlagObj::move(double x, double y)
|
insilmaril@0
|
56 |
{
|
insilmaril@0
|
57 |
MapObj::move(x,y);
|
insilmaril@0
|
58 |
icon->move(x,y);
|
insilmaril@0
|
59 |
positionBBox();
|
insilmaril@0
|
60 |
}
|
insilmaril@0
|
61 |
|
insilmaril@0
|
62 |
void FlagObj::moveBy(double x, double y)
|
insilmaril@0
|
63 |
{
|
insilmaril@0
|
64 |
move (x+absPos.x(),y+absPos.y() );
|
insilmaril@0
|
65 |
}
|
insilmaril@0
|
66 |
|
insilmaril@0
|
67 |
void FlagObj::setVisibility (bool v)
|
insilmaril@0
|
68 |
{
|
insilmaril@0
|
69 |
MapObj::setVisibility(v);
|
insilmaril@0
|
70 |
if (v && state)
|
insilmaril@0
|
71 |
icon->setVisibility(true);
|
insilmaril@0
|
72 |
else
|
insilmaril@0
|
73 |
icon->setVisibility(false);
|
insilmaril@0
|
74 |
}
|
insilmaril@0
|
75 |
|
insilmaril@0
|
76 |
void FlagObj::load (const QString &fn)
|
insilmaril@0
|
77 |
{
|
insilmaril@0
|
78 |
icon->load(fn);
|
insilmaril@0
|
79 |
calcBBoxSize();
|
insilmaril@0
|
80 |
positionBBox();
|
insilmaril@0
|
81 |
}
|
insilmaril@0
|
82 |
|
insilmaril@0
|
83 |
void FlagObj::load (const QPixmap &pm)
|
insilmaril@0
|
84 |
{
|
insilmaril@0
|
85 |
icon->load(pm);
|
insilmaril@0
|
86 |
calcBBoxSize();
|
insilmaril@0
|
87 |
positionBBox();
|
insilmaril@0
|
88 |
}
|
insilmaril@0
|
89 |
|
insilmaril@0
|
90 |
void FlagObj::setName(const QString &n)
|
insilmaril@0
|
91 |
{
|
insilmaril@0
|
92 |
name=n;
|
insilmaril@0
|
93 |
}
|
insilmaril@0
|
94 |
|
insilmaril@0
|
95 |
const QString FlagObj::getName()
|
insilmaril@0
|
96 |
{
|
insilmaril@0
|
97 |
return name;
|
insilmaril@0
|
98 |
}
|
insilmaril@0
|
99 |
|
insilmaril@103
|
100 |
void FlagObj::setGroup (const QString &n)
|
insilmaril@103
|
101 |
{
|
insilmaril@103
|
102 |
group=n;
|
insilmaril@103
|
103 |
}
|
insilmaril@103
|
104 |
|
insilmaril@103
|
105 |
const QString FlagObj::getGroup()
|
insilmaril@103
|
106 |
{
|
insilmaril@103
|
107 |
return group;
|
insilmaril@103
|
108 |
}
|
insilmaril@103
|
109 |
|
insilmaril@0
|
110 |
void FlagObj::setToolTip(const QString &n)
|
insilmaril@0
|
111 |
{
|
insilmaril@0
|
112 |
tooltip=n;
|
insilmaril@0
|
113 |
}
|
insilmaril@0
|
114 |
|
insilmaril@0
|
115 |
const QString FlagObj::getToolTip()
|
insilmaril@0
|
116 |
{
|
insilmaril@0
|
117 |
return tooltip;
|
insilmaril@0
|
118 |
}
|
insilmaril@0
|
119 |
|
insilmaril@0
|
120 |
void FlagObj::setButton(QAction* b)
|
insilmaril@0
|
121 |
{
|
insilmaril@0
|
122 |
button=b;
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
void FlagObj::updateButton()
|
insilmaril@0
|
126 |
{
|
insilmaril@0
|
127 |
if (button)
|
insilmaril@0
|
128 |
button->setOn(state);
|
insilmaril@0
|
129 |
else
|
insilmaril@0
|
130 |
qWarning ("FlagObj::updateButton no button defined");
|
insilmaril@0
|
131 |
}
|
insilmaril@0
|
132 |
|
insilmaril@0
|
133 |
QPixmap FlagObj::getPixmap()
|
insilmaril@0
|
134 |
{
|
insilmaril@0
|
135 |
return icon->getPixmap();
|
insilmaril@0
|
136 |
}
|
insilmaril@0
|
137 |
|
insilmaril@0
|
138 |
bool FlagObj::isActive()
|
insilmaril@0
|
139 |
{
|
insilmaril@0
|
140 |
return state;
|
insilmaril@0
|
141 |
}
|
insilmaril@0
|
142 |
|
insilmaril@0
|
143 |
void FlagObj::toggle()
|
insilmaril@0
|
144 |
{
|
insilmaril@0
|
145 |
if (state)
|
insilmaril@0
|
146 |
deactivate();
|
insilmaril@0
|
147 |
else
|
insilmaril@0
|
148 |
activate();
|
insilmaril@0
|
149 |
}
|
insilmaril@0
|
150 |
|
insilmaril@0
|
151 |
void FlagObj::activate()
|
insilmaril@0
|
152 |
{
|
insilmaril@0
|
153 |
state=true;
|
insilmaril@0
|
154 |
// only show icon, if flag itself is visible
|
insilmaril@0
|
155 |
if (visible)
|
insilmaril@0
|
156 |
{
|
insilmaril@0
|
157 |
icon->setVisibility (true);
|
insilmaril@0
|
158 |
calcBBoxSize();
|
insilmaril@0
|
159 |
}
|
insilmaril@0
|
160 |
}
|
insilmaril@0
|
161 |
|
insilmaril@0
|
162 |
void FlagObj::deactivate()
|
insilmaril@0
|
163 |
{
|
insilmaril@0
|
164 |
state=false;
|
insilmaril@0
|
165 |
// if flag itself is invisible we don't need to call
|
insilmaril@0
|
166 |
if (visible)
|
insilmaril@0
|
167 |
{
|
insilmaril@0
|
168 |
icon->setVisibility (false);
|
insilmaril@0
|
169 |
calcBBoxSize();
|
insilmaril@0
|
170 |
}
|
insilmaril@0
|
171 |
}
|
insilmaril@0
|
172 |
|
insilmaril@0
|
173 |
void FlagObj::setEnabled(bool b)
|
insilmaril@0
|
174 |
{
|
insilmaril@0
|
175 |
button->setEnabled (b);
|
insilmaril@0
|
176 |
}
|
insilmaril@0
|
177 |
|
insilmaril@0
|
178 |
|
insilmaril@0
|
179 |
void FlagObj::setUsed (bool b)
|
insilmaril@0
|
180 |
{
|
insilmaril@0
|
181 |
used=b;
|
insilmaril@0
|
182 |
}
|
insilmaril@0
|
183 |
|
insilmaril@0
|
184 |
bool FlagObj::isUsed()
|
insilmaril@0
|
185 |
{
|
insilmaril@0
|
186 |
return used;
|
insilmaril@0
|
187 |
}
|
insilmaril@0
|
188 |
|
insilmaril@0
|
189 |
void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
|
insilmaril@0
|
190 |
{
|
insilmaril@0
|
191 |
QString fn=tmpdir + prefix + name + ".png";
|
insilmaril@0
|
192 |
icon->save (fn,"PNG");
|
insilmaril@0
|
193 |
}
|
insilmaril@0
|
194 |
|
insilmaril@0
|
195 |
void FlagObj::positionBBox()
|
insilmaril@0
|
196 |
{
|
insilmaril@0
|
197 |
bbox.setX (absPos.x() );
|
insilmaril@0
|
198 |
bbox.setY (absPos.y() );
|
insilmaril@0
|
199 |
}
|
insilmaril@0
|
200 |
|
insilmaril@0
|
201 |
void FlagObj::calcBBoxSize()
|
insilmaril@0
|
202 |
{
|
insilmaril@0
|
203 |
if (visible && state)
|
insilmaril@0
|
204 |
{
|
insilmaril@0
|
205 |
bbox.setSize ( QSize(
|
insilmaril@0
|
206 |
icon->boundingRect().width(),
|
insilmaril@0
|
207 |
icon->boundingRect().height() ) );
|
insilmaril@0
|
208 |
} else
|
insilmaril@0
|
209 |
{
|
insilmaril@0
|
210 |
bbox.setSize (QSize(0,0));
|
insilmaril@0
|
211 |
}
|
insilmaril@0
|
212 |
}
|
insilmaril@0
|
213 |
|