insilmaril@0
|
1 |
#include "floatimageobj.h"
|
insilmaril@0
|
2 |
#include "branchobj.h"
|
insilmaril@0
|
3 |
|
insilmaril@0
|
4 |
|
insilmaril@0
|
5 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
6 |
// FloatImageObj
|
insilmaril@0
|
7 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
8 |
|
insilmaril@173
|
9 |
uint FloatImageObj::saveCounter=0; // make instance
|
insilmaril@0
|
10 |
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
FloatImageObj::FloatImageObj ():FloatObj()
|
insilmaril@0
|
13 |
{
|
insilmaril@0
|
14 |
// cout << "Const FloatImageObj ()\n";
|
insilmaril@0
|
15 |
setParObj (this);
|
insilmaril@0
|
16 |
init();
|
insilmaril@0
|
17 |
depth=-1;
|
insilmaril@0
|
18 |
}
|
insilmaril@0
|
19 |
|
insilmaril@0
|
20 |
FloatImageObj::FloatImageObj (QCanvas* c):FloatObj(c)
|
insilmaril@0
|
21 |
{
|
insilmaril@0
|
22 |
// cout << "Const FloatImageObj (c) called from MapCenterObj (c)\n";
|
insilmaril@0
|
23 |
setParObj (this);
|
insilmaril@0
|
24 |
init();
|
insilmaril@0
|
25 |
depth=-1;
|
insilmaril@0
|
26 |
}
|
insilmaril@0
|
27 |
|
insilmaril@0
|
28 |
FloatImageObj::FloatImageObj (QCanvas* c, LinkableMapObj* p):FloatObj(c,p)
|
insilmaril@0
|
29 |
{
|
insilmaril@0
|
30 |
// cout << "Const FloatImageObj (c,p)\n";
|
insilmaril@0
|
31 |
init();
|
insilmaril@0
|
32 |
}
|
insilmaril@0
|
33 |
|
insilmaril@0
|
34 |
FloatImageObj::~FloatImageObj ()
|
insilmaril@0
|
35 |
{
|
insilmaril@0
|
36 |
// cout << "Destr FloatImageObj "<<this<<"\n";
|
insilmaril@0
|
37 |
delete(icon);
|
insilmaril@0
|
38 |
}
|
insilmaril@0
|
39 |
|
insilmaril@0
|
40 |
void FloatImageObj::init ()
|
insilmaril@0
|
41 |
{
|
insilmaril@0
|
42 |
icon=new ImageObj (canvas);
|
insilmaril@0
|
43 |
icon->move (absPos.x(), absPos.y() );
|
insilmaril@0
|
44 |
icon->setVisibility (true);
|
insilmaril@0
|
45 |
bbox.setSize (QSize(icon->size().width(), icon->size().height()));
|
insilmaril@173
|
46 |
clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
|
insilmaril@0
|
47 |
filename="";
|
insilmaril@0
|
48 |
originalFilename="no original name available";
|
insilmaril@0
|
49 |
filetype="";
|
insilmaril@0
|
50 |
saveInMap=true;
|
insilmaril@0
|
51 |
}
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
void FloatImageObj::copy (FloatImageObj* other)
|
insilmaril@0
|
54 |
{
|
insilmaril@0
|
55 |
FloatObj::copy (other);
|
insilmaril@0
|
56 |
icon->copy (other->icon);
|
insilmaril@173
|
57 |
filetype=other->filetype;
|
insilmaril@0
|
58 |
filename=other->filename;
|
insilmaril@173
|
59 |
originalFilename=other->originalFilename;
|
insilmaril@0
|
60 |
saveInMap=other->saveInMap;
|
insilmaril@0
|
61 |
positionBBox();
|
insilmaril@0
|
62 |
}
|
insilmaril@0
|
63 |
|
insilmaril@0
|
64 |
void FloatImageObj::setZ (const int &i)
|
insilmaril@0
|
65 |
{
|
insilmaril@0
|
66 |
icon->setZ (i);
|
insilmaril@0
|
67 |
zPlane=i;
|
insilmaril@0
|
68 |
}
|
insilmaril@0
|
69 |
|
insilmaril@0
|
70 |
int FloatImageObj::z ()
|
insilmaril@0
|
71 |
{
|
insilmaril@104
|
72 |
return qRound (icon->z());
|
insilmaril@0
|
73 |
}
|
insilmaril@0
|
74 |
|
insilmaril@113
|
75 |
void FloatImageObj::load (const QPixmap &pixmap)
|
insilmaril@113
|
76 |
{
|
insilmaril@113
|
77 |
icon->load(pixmap);
|
insilmaril@113
|
78 |
bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
|
insilmaril@173
|
79 |
clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
|
insilmaril@113
|
80 |
positionBBox();
|
insilmaril@113
|
81 |
filetype="PNG";
|
insilmaril@113
|
82 |
filename="noname.png";
|
insilmaril@113
|
83 |
}
|
insilmaril@113
|
84 |
|
insilmaril@0
|
85 |
bool FloatImageObj::load (const QString &fn)
|
insilmaril@0
|
86 |
{
|
insilmaril@0
|
87 |
if( icon->load (fn))
|
insilmaril@0
|
88 |
{
|
insilmaril@0
|
89 |
bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
|
insilmaril@0
|
90 |
positionBBox();
|
insilmaril@0
|
91 |
filename=fn;
|
insilmaril@0
|
92 |
filetype=QPixmap::imageFormat (fn);
|
insilmaril@0
|
93 |
return true;
|
insilmaril@0
|
94 |
} else
|
insilmaril@0
|
95 |
return false;
|
insilmaril@0
|
96 |
|
insilmaril@0
|
97 |
}
|
insilmaril@0
|
98 |
|
insilmaril@0
|
99 |
void FloatImageObj::save (const QString &fn, const char *format)
|
insilmaril@0
|
100 |
{
|
insilmaril@0
|
101 |
icon->save (fn,format);
|
insilmaril@0
|
102 |
}
|
insilmaril@0
|
103 |
|
insilmaril@0
|
104 |
void FloatImageObj::setOriginalFilename(const QString & fn)
|
insilmaril@0
|
105 |
{
|
insilmaril@0
|
106 |
originalFilename=fn;
|
insilmaril@0
|
107 |
}
|
insilmaril@0
|
108 |
|
insilmaril@0
|
109 |
QString FloatImageObj::getOriginalFilename()
|
insilmaril@0
|
110 |
{
|
insilmaril@0
|
111 |
return originalFilename;
|
insilmaril@0
|
112 |
}
|
insilmaril@0
|
113 |
|
insilmaril@0
|
114 |
void FloatImageObj::setVisibility(bool v)
|
insilmaril@0
|
115 |
{
|
insilmaril@0
|
116 |
LinkableMapObj::setVisibility(v);
|
insilmaril@0
|
117 |
if (v)
|
insilmaril@0
|
118 |
icon->setVisibility(true);
|
insilmaril@0
|
119 |
else
|
insilmaril@0
|
120 |
icon->setVisibility(false);
|
insilmaril@0
|
121 |
}
|
insilmaril@0
|
122 |
|
insilmaril@0
|
123 |
void FloatImageObj::move (double x, double y)
|
insilmaril@0
|
124 |
{
|
insilmaril@0
|
125 |
FloatObj::move(x,y);
|
insilmaril@0
|
126 |
icon->move (x+4,y+4);
|
insilmaril@0
|
127 |
positionBBox();
|
insilmaril@0
|
128 |
}
|
insilmaril@0
|
129 |
|
insilmaril@0
|
130 |
void FloatImageObj::move (QPoint p)
|
insilmaril@0
|
131 |
{
|
insilmaril@0
|
132 |
move (p.x(), p.y());
|
insilmaril@0
|
133 |
}
|
insilmaril@0
|
134 |
|
insilmaril@0
|
135 |
void FloatImageObj::positionBBox()
|
insilmaril@0
|
136 |
{
|
insilmaril@173
|
137 |
clickBox=bbox;
|
insilmaril@0
|
138 |
}
|
insilmaril@0
|
139 |
|
insilmaril@0
|
140 |
void FloatImageObj::calcBBoxSize()
|
insilmaril@0
|
141 |
{
|
insilmaril@0
|
142 |
// TODO
|
insilmaril@0
|
143 |
}
|
insilmaril@0
|
144 |
|
insilmaril@166
|
145 |
QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
|
insilmaril@0
|
146 |
{
|
insilmaril@173
|
147 |
saveCounter++;
|
insilmaril@0
|
148 |
|
insilmaril@0
|
149 |
QString posAttr=
|
insilmaril@0
|
150 |
attribut("relPosX",QString().setNum(relPos.x(),10)) +
|
insilmaril@0
|
151 |
attribut("relPosY",QString().setNum(relPos.y(),10));
|
insilmaril@0
|
152 |
|
insilmaril@173
|
153 |
QString linkAttr=getLinkAttr();
|
insilmaril@173
|
154 |
|
insilmaril@0
|
155 |
QString useOrientAttr;
|
insilmaril@0
|
156 |
if (useOrientation)
|
insilmaril@0
|
157 |
useOrientAttr=attribut ("useOrientation","true");
|
insilmaril@0
|
158 |
else
|
insilmaril@0
|
159 |
useOrientAttr=attribut ("useOrientation","false");
|
insilmaril@0
|
160 |
|
insilmaril@0
|
161 |
QString saveInMapAttr;
|
insilmaril@0
|
162 |
if (saveInMap)
|
insilmaril@0
|
163 |
saveInMapAttr=attribut ("saveInMap","true");
|
insilmaril@0
|
164 |
else
|
insilmaril@0
|
165 |
|
insilmaril@0
|
166 |
saveInMapAttr=attribut ("saveInMap","false");
|
insilmaril@0
|
167 |
|
insilmaril@0
|
168 |
QString exportAttr;
|
insilmaril@0
|
169 |
if (floatExport)
|
insilmaril@0
|
170 |
exportAttr=attribut ("floatExport","true");
|
insilmaril@0
|
171 |
else
|
insilmaril@0
|
172 |
exportAttr=attribut ("floatExport","false");
|
insilmaril@0
|
173 |
|
insilmaril@0
|
174 |
QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
|
insilmaril@0
|
175 |
QString url;
|
insilmaril@0
|
176 |
|
insilmaril@0
|
177 |
// prevent saving as GIF
|
insilmaril@0
|
178 |
if (filetype=="GIF")
|
insilmaril@0
|
179 |
filetype="PNG";
|
insilmaril@0
|
180 |
|
insilmaril@173
|
181 |
url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
|
insilmaril@0
|
182 |
|
insilmaril@0
|
183 |
// And really save the image
|
insilmaril@0
|
184 |
icon->save (tmpdir + "/" + url, filetype);
|
insilmaril@0
|
185 |
|
insilmaril@0
|
186 |
return singleElement ("floatimage",
|
insilmaril@0
|
187 |
posAttr +
|
insilmaril@173
|
188 |
linkAttr +
|
insilmaril@0
|
189 |
useOrientAttr +
|
insilmaril@0
|
190 |
saveInMapAttr +
|
insilmaril@0
|
191 |
exportAttr +
|
insilmaril@0
|
192 |
zAttr +
|
insilmaril@0
|
193 |
attribut ("href",QString ("file:")+url)
|
insilmaril@0
|
194 |
);
|
insilmaril@0
|
195 |
}
|
insilmaril@0
|
196 |
|
insilmaril@0
|
197 |
void FloatImageObj::resetSaveCounter()
|
insilmaril@0
|
198 |
{
|
insilmaril@173
|
199 |
saveCounter=0;
|
insilmaril@0
|
200 |
}
|
insilmaril@0
|
201 |
|
insilmaril@0
|
202 |
|
insilmaril@0
|
203 |
QRect FloatImageObj::getTotalBBox()
|
insilmaril@0
|
204 |
{
|
insilmaril@0
|
205 |
return bbox;
|
insilmaril@0
|
206 |
}
|
insilmaril@0
|
207 |
|
insilmaril@0
|
208 |
QRect FloatImageObj::getBBoxSizeWithChilds()
|
insilmaril@0
|
209 |
{
|
insilmaril@0
|
210 |
//FIXME abstract in linkablemapobj.h, not calculated
|
insilmaril@0
|
211 |
return bboxTotal;
|
insilmaril@0
|
212 |
}
|
insilmaril@0
|
213 |
|
insilmaril@0
|
214 |
void FloatImageObj::calcBBoxSizeWithChilds()
|
insilmaril@0
|
215 |
{
|
insilmaril@0
|
216 |
//FIXME abstract in linkablemapobj.h
|
insilmaril@0
|
217 |
}
|
insilmaril@0
|
218 |
|
insilmaril@0
|
219 |
QString FloatImageObj::getSelectString()
|
insilmaril@0
|
220 |
{
|
insilmaril@0
|
221 |
QString s;
|
insilmaril@0
|
222 |
if (parObj)
|
insilmaril@0
|
223 |
{
|
insilmaril@0
|
224 |
if (parObj->getDepth()==0)
|
insilmaril@0
|
225 |
s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
|
insilmaril@0
|
226 |
else
|
insilmaril@0
|
227 |
s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
|
insilmaril@0
|
228 |
} else
|
insilmaril@0
|
229 |
s="mc:";
|
insilmaril@0
|
230 |
|
insilmaril@0
|
231 |
return s;
|
insilmaril@0
|
232 |
|
insilmaril@0
|
233 |
}
|
insilmaril@0
|
234 |
|