insilmaril@0
|
1 |
#include "flagobj.h"
|
insilmaril@2
|
2 |
//Added by qt3to4:
|
insilmaril@2
|
3 |
#include <QPixmap>
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
6 |
// FlagObj
|
insilmaril@0
|
7 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
8 |
FlagObj::FlagObj()
|
insilmaril@0
|
9 |
{
|
insilmaril@2
|
10 |
// cout << "Const FlagObj ()\n";
|
insilmaril@0
|
11 |
init ();
|
insilmaril@0
|
12 |
}
|
insilmaril@0
|
13 |
|
insilmaril@2
|
14 |
FlagObj::FlagObj(Q3Canvas* c):MapObj(c)
|
insilmaril@0
|
15 |
{
|
insilmaril@2
|
16 |
// cout << "Const FlagObj canvas="<<c<<endl;
|
insilmaril@0
|
17 |
init ();
|
insilmaril@0
|
18 |
}
|
insilmaril@0
|
19 |
|
insilmaril@0
|
20 |
FlagObj::FlagObj (FlagObj* io)
|
insilmaril@0
|
21 |
{
|
insilmaril@0
|
22 |
copy (io);
|
insilmaril@0
|
23 |
}
|
insilmaril@0
|
24 |
|
insilmaril@0
|
25 |
FlagObj::~FlagObj()
|
insilmaril@0
|
26 |
{
|
insilmaril@0
|
27 |
// cout << "Destr FlagObj " << name << "\n";
|
insilmaril@2
|
28 |
if (icon) delete (icon);
|
insilmaril@0
|
29 |
}
|
insilmaril@0
|
30 |
|
insilmaril@0
|
31 |
|
insilmaril@0
|
32 |
void FlagObj::init ()
|
insilmaril@0
|
33 |
{
|
insilmaril@0
|
34 |
name="undefined";
|
insilmaril@2
|
35 |
group="undefined";
|
insilmaril@0
|
36 |
|
insilmaril@0
|
37 |
icon=new ImageObj (canvas);
|
insilmaril@0
|
38 |
icon->move (absPos.x(), absPos.y() );
|
insilmaril@0
|
39 |
state=false;
|
insilmaril@3
|
40 |
action=NULL;
|
insilmaril@0
|
41 |
}
|
insilmaril@0
|
42 |
|
insilmaril@0
|
43 |
void FlagObj::copy (FlagObj* other)
|
insilmaril@0
|
44 |
{
|
insilmaril@0
|
45 |
MapObj::copy(other);
|
insilmaril@0
|
46 |
name=other->name;
|
insilmaril@2
|
47 |
group=other->group;
|
insilmaril@0
|
48 |
tooltip=other->tooltip;
|
insilmaril@0
|
49 |
state=other->state;
|
insilmaril@0
|
50 |
icon->copy(other->icon);
|
insilmaril@3
|
51 |
action=other->action;
|
insilmaril@0
|
52 |
setVisibility (other->isVisibleObj() );
|
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@2
|
100 |
void FlagObj::setGroup (const QString &n)
|
insilmaril@2
|
101 |
{
|
insilmaril@2
|
102 |
group=n;
|
insilmaril@2
|
103 |
}
|
insilmaril@2
|
104 |
|
insilmaril@2
|
105 |
const QString FlagObj::getGroup()
|
insilmaril@2
|
106 |
{
|
insilmaril@2
|
107 |
return group;
|
insilmaril@2
|
108 |
}
|
insilmaril@2
|
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 |
QPixmap FlagObj::getPixmap()
|
insilmaril@0
|
121 |
{
|
insilmaril@0
|
122 |
return icon->getPixmap();
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@3
|
125 |
void FlagObj::setAction (QAction* a)
|
insilmaril@3
|
126 |
{
|
insilmaril@3
|
127 |
action=a;
|
insilmaril@3
|
128 |
}
|
insilmaril@3
|
129 |
|
insilmaril@3
|
130 |
void FlagObj::updateAction ()
|
insilmaril@3
|
131 |
{
|
insilmaril@3
|
132 |
if (action) action->setChecked(state);
|
insilmaril@3
|
133 |
}
|
insilmaril@3
|
134 |
|
insilmaril@0
|
135 |
bool FlagObj::isActive()
|
insilmaril@0
|
136 |
{
|
insilmaril@0
|
137 |
return state;
|
insilmaril@0
|
138 |
}
|
insilmaril@0
|
139 |
|
insilmaril@0
|
140 |
void FlagObj::toggle()
|
insilmaril@0
|
141 |
{
|
insilmaril@0
|
142 |
if (state)
|
insilmaril@0
|
143 |
deactivate();
|
insilmaril@0
|
144 |
else
|
insilmaril@0
|
145 |
activate();
|
insilmaril@0
|
146 |
}
|
insilmaril@0
|
147 |
|
insilmaril@0
|
148 |
void FlagObj::activate()
|
insilmaril@0
|
149 |
{
|
insilmaril@0
|
150 |
state=true;
|
insilmaril@0
|
151 |
// only show icon, if flag itself is visible
|
insilmaril@0
|
152 |
if (visible)
|
insilmaril@0
|
153 |
{
|
insilmaril@0
|
154 |
icon->setVisibility (true);
|
insilmaril@0
|
155 |
calcBBoxSize();
|
insilmaril@0
|
156 |
}
|
insilmaril@0
|
157 |
}
|
insilmaril@0
|
158 |
|
insilmaril@0
|
159 |
void FlagObj::deactivate()
|
insilmaril@0
|
160 |
{
|
insilmaril@0
|
161 |
state=false;
|
insilmaril@0
|
162 |
// if flag itself is invisible we don't need to call
|
insilmaril@0
|
163 |
if (visible)
|
insilmaril@0
|
164 |
{
|
insilmaril@0
|
165 |
icon->setVisibility (false);
|
insilmaril@0
|
166 |
calcBBoxSize();
|
insilmaril@0
|
167 |
}
|
insilmaril@0
|
168 |
}
|
insilmaril@0
|
169 |
|
insilmaril@0
|
170 |
void FlagObj::setUsed (bool b)
|
insilmaril@0
|
171 |
{
|
insilmaril@0
|
172 |
used=b;
|
insilmaril@0
|
173 |
}
|
insilmaril@0
|
174 |
|
insilmaril@0
|
175 |
bool FlagObj::isUsed()
|
insilmaril@0
|
176 |
{
|
insilmaril@0
|
177 |
return used;
|
insilmaril@0
|
178 |
}
|
insilmaril@0
|
179 |
|
insilmaril@0
|
180 |
void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
|
insilmaril@0
|
181 |
{
|
insilmaril@0
|
182 |
QString fn=tmpdir + prefix + name + ".png";
|
insilmaril@0
|
183 |
icon->save (fn,"PNG");
|
insilmaril@0
|
184 |
}
|
insilmaril@0
|
185 |
|
insilmaril@0
|
186 |
void FlagObj::positionBBox()
|
insilmaril@0
|
187 |
{
|
insilmaril@2
|
188 |
bbox.moveTopLeft (absPos );
|
insilmaril@2
|
189 |
clickBox.moveTopLeft (absPos );
|
insilmaril@0
|
190 |
}
|
insilmaril@0
|
191 |
|
insilmaril@0
|
192 |
void FlagObj::calcBBoxSize()
|
insilmaril@0
|
193 |
{
|
insilmaril@0
|
194 |
if (visible && state)
|
insilmaril@0
|
195 |
{
|
insilmaril@0
|
196 |
bbox.setSize ( QSize(
|
insilmaril@0
|
197 |
icon->boundingRect().width(),
|
insilmaril@0
|
198 |
icon->boundingRect().height() ) );
|
insilmaril@0
|
199 |
} else
|
insilmaril@0
|
200 |
{
|
insilmaril@0
|
201 |
bbox.setSize (QSize(0,0));
|
insilmaril@0
|
202 |
}
|
insilmaril@2
|
203 |
clickBox.setSize (bbox.size());
|
insilmaril@0
|
204 |
}
|
insilmaril@0
|
205 |
|