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