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