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