File: floatimageobj.cpp

package info (click to toggle)
vym 1.8.1-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,000 kB
  • ctags: 1,599
  • sloc: cpp: 14,723; sh: 373; xml: 277; perl: 89; makefile: 16
file content (242 lines) | stat: -rw-r--r-- 4,894 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include "floatimageobj.h"
#include "branchobj.h"


/////////////////////////////////////////////////////////////////
// FloatImageObj
/////////////////////////////////////////////////////////////////

uint FloatImageObj::saveCounter=0;		// make instance 


FloatImageObj::FloatImageObj ():FloatObj()
{
//    cout << "Const FloatImageObj ()\n";
    setParObj (this);	
    init();
    depth=-1;
}

FloatImageObj::FloatImageObj (QCanvas* c):FloatObj(c)
{
 //   cout << "Const FloatImageObj (c)  called from MapCenterObj (c)\n";
    setParObj (this);	
    init();
    depth=-1;
}

FloatImageObj::FloatImageObj (QCanvas* c, OrnamentedObj* p):FloatObj(c,p)
{
 //   cout << "Const FloatImageObj (c,p)\n";
    init();
}

FloatImageObj::~FloatImageObj ()
{
//	cout << "Destr FloatImageObj "<<this<<"\n";
	delete(icon);
}

void FloatImageObj::init () 
{
	icon=new ImageObj (canvas);
	icon->move (absPos.x(), absPos.y() );
	icon->setVisibility (true);
	setZ (Z_FLOATIMG);
	bbox.setSize (QSize(icon->size().width(), icon->size().height()));
	clickBox.setSize (QSize(icon->size().width(), icon->size().height()));
	filename="";
	originalFilename="no original name available";
	filetype="";
	saveInMap=true;
	useRelPos=true;

	//Hide flags
	systemFlags->setShowFlags(false);
}

void FloatImageObj::copy (FloatImageObj* other)
{					
	FloatObj::copy (other);
	icon->copy (other->icon);
	filetype=other->filetype;
	filename=other->filename;
	originalFilename=other->originalFilename;
	saveInMap=other->saveInMap;
    positionBBox();
}

void FloatImageObj::setZ (const int &i)
{
	icon->setZ (i);
	zPlane=i;
}

int FloatImageObj::z ()
{
	return qRound (icon->z());
}

void FloatImageObj::load (const QPixmap &pixmap)
{
  icon->load(pixmap);
  bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
  clickBox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
  positionBBox();
  filetype="PNG";
  filename="noname.png";
}

bool FloatImageObj::load (const QString &fn)
{	
	if( icon->load (fn))
	{
		bbox.setSize (QSize(icon->size().width()+8, icon->size().height()+8));
		positionBBox();
		filename=fn;
		filetype=QPixmap::imageFormat (fn);
		setOriginalFilename (fn);
		return true;
	} else
		return false;
	
}

void FloatImageObj::save (const QString &fn, const char *format)
{	
	icon->save (fn,format);
}

void FloatImageObj::setOriginalFilename(const QString & fn)
{
	originalFilename=fn;

	// Set short name, too. Search from behind:
	int i=originalFilename.findRev("/");
	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
}

QString FloatImageObj::getOriginalFilename()
{
	return originalFilename;
}

void FloatImageObj::setVisibility(bool v)
{
    OrnamentedObj::setVisibility(v);
	if (v)
	    icon->setVisibility(true);
	else
	    icon->setVisibility(false);
}

void FloatImageObj::move (double x, double y)
{
	FloatObj::move(x,y);
	icon->move (x+4,y+4);
    positionBBox();
}

void FloatImageObj::move (QPoint p)
{
	move (p.x(), p.y());
}

void FloatImageObj::positionBBox()
{
	clickBox=bbox;
}

void FloatImageObj::calcBBoxSize()
{
	// TODO
}

QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix, const QPoint &p)
{
	if (hidden) return "";

	saveCounter++;
	
	QString useOrientAttr;
	if (useOrientation)
		useOrientAttr=attribut ("useOrientation","true");
	else	
		useOrientAttr=attribut ("useOrientation","false");
		
	QString saveInMapAttr;
	if (saveInMap)
		saveInMapAttr=attribut ("saveInMap","true");
	else	
		
		saveInMapAttr=attribut ("saveInMap","false");

	QString exportAttr;
	if (floatExport)
		exportAttr=attribut ("floatExport","true");
	else	
		exportAttr=attribut ("floatExport","false");

	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
	QString url;

	// prevent saving as GIF
	if (filetype=="GIF")
		filetype="PNG";
		
	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;

	// And really save the image
	icon->save (tmpdir + "/" + url, filetype);
 
	QString nameAttr=attribut ("orgName",originalFilename);

    return singleElement ("floatimage",  
		getOrnAttr() 
		+useOrientAttr 
		+saveInMapAttr 
		+exportAttr  
		+zAttr  
		+attribut ("href",QString ("file:")+url)
		+nameAttr
	);	
}

void FloatImageObj::resetSaveCounter()
{
	saveCounter=0;
}


QRect FloatImageObj::getTotalBBox()
{
	return bbox;
}

QRect FloatImageObj::getBBoxSizeWithChilds()
{
	//FIXME  abstract in linkablemapobj.h, not calculated
	return bboxTotal;
}

void FloatImageObj::calcBBoxSizeWithChilds()
{
	//FIXME  abstract in linkablemapobj.h
}

QString FloatImageObj::getSelectString()
{
	QString s;
	if (parObj)
	{
		if (parObj->getDepth()==0)
			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
		else	
			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
	} else
		s="mc:";
	
	return s;

}