floatimageobj.cpp
author insilmaril
Mon, 07 Jan 2008 14:52:51 +0000
changeset 640 6b7b49e367b8
parent 628 d7d0708b1c60
child 680 8c6faaa1e2b1
permissions -rw-r--r--
Included french in vym.pro
insilmaril@408
     1
#include <QImageReader>
insilmaril@408
     2
#include <QPixmap>
insilmaril@408
     3
insilmaril@0
     4
#include "floatimageobj.h"
insilmaril@0
     5
#include "branchobj.h"
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@408
    22
FloatImageObj::FloatImageObj (QGraphicsScene* s):FloatObj(s)
insilmaril@0
    23
{
insilmaril@408
    24
 //   cout << "Const FloatImageObj (s)  called from MapCenterObj (s)\n";
insilmaril@0
    25
    setParObj (this);	
insilmaril@0
    26
    init();
insilmaril@0
    27
    depth=-1;
insilmaril@0
    28
}
insilmaril@0
    29
insilmaril@408
    30
FloatImageObj::FloatImageObj (QGraphicsScene *s, OrnamentedObj* p):FloatObj(s,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@417
    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@408
    44
	icon=new ImageObj (scene);
insilmaril@408
    45
	icon->setPos (absPos.x(), absPos.y() );
insilmaril@0
    46
	icon->setVisibility (true);
insilmaril@408
    47
	setZValue (Z_FLOATIMG);
insilmaril@408
    48
	bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
insilmaril@408
    49
	clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
insilmaril@0
    50
	originalFilename="no original name available";
insilmaril@0
    51
	filetype="";
insilmaril@0
    52
	saveInMap=true;
insilmaril@218
    53
	useRelPos=true;
insilmaril@258
    54
insilmaril@258
    55
	//Hide flags
insilmaril@258
    56
	systemFlags->setShowFlags(false);
insilmaril@0
    57
}
insilmaril@0
    58
insilmaril@0
    59
void FloatImageObj::copy (FloatImageObj* other)
insilmaril@0
    60
{					
insilmaril@0
    61
	FloatObj::copy (other);
insilmaril@0
    62
	icon->copy (other->icon);
insilmaril@173
    63
	filetype=other->filetype;
insilmaril@0
    64
	filename=other->filename;
insilmaril@173
    65
	originalFilename=other->originalFilename;
insilmaril@0
    66
	saveInMap=other->saveInMap;
insilmaril@0
    67
    positionBBox();
insilmaril@0
    68
}
insilmaril@0
    69
insilmaril@408
    70
void FloatImageObj::setZValue (const int &i)
insilmaril@0
    71
{
insilmaril@408
    72
	icon->setZValue (i);
insilmaril@0
    73
	zPlane=i;
insilmaril@0
    74
}
insilmaril@0
    75
insilmaril@0
    76
int FloatImageObj::z ()
insilmaril@0
    77
{
insilmaril@408
    78
	return qRound (icon->zValue());
insilmaril@0
    79
}
insilmaril@0
    80
insilmaril@113
    81
void FloatImageObj::load (const QPixmap &pixmap)
insilmaril@113
    82
{
insilmaril@408
    83
	icon->load(pixmap);
insilmaril@408
    84
	bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    85
	clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    86
	positionBBox();
insilmaril@408
    87
	filetype="PNG";
insilmaril@408
    88
	filename="No filename given";
insilmaril@113
    89
}
insilmaril@113
    90
insilmaril@0
    91
bool FloatImageObj::load (const QString &fn)
insilmaril@0
    92
{	
insilmaril@408
    93
	QImageReader reader (fn);
insilmaril@408
    94
	QImage img;
insilmaril@408
    95
insilmaril@408
    96
	if( reader.read (&img))
insilmaril@0
    97
	{
insilmaril@408
    98
		icon->setPixmap(QPixmap::fromImage(img));
insilmaril@408
    99
		bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@0
   100
		positionBBox();
insilmaril@0
   101
		filename=fn;
insilmaril@408
   102
		filetype=reader.format();
insilmaril@334
   103
		setOriginalFilename (fn);
insilmaril@0
   104
		return true;
insilmaril@0
   105
	} else
insilmaril@0
   106
		return false;
insilmaril@0
   107
	
insilmaril@0
   108
}
insilmaril@0
   109
insilmaril@366
   110
void FloatImageObj::save (const QString &fn, const QString &format)
insilmaril@0
   111
{	
insilmaril@366
   112
	icon->save (fn,qPrintable (format));
insilmaril@0
   113
}
insilmaril@0
   114
insilmaril@0
   115
void FloatImageObj::setOriginalFilename(const QString & fn)
insilmaril@0
   116
{
insilmaril@0
   117
	originalFilename=fn;
insilmaril@334
   118
insilmaril@334
   119
	// Set short name, too. Search from behind:
insilmaril@334
   120
	int i=originalFilename.findRev("/");
insilmaril@334
   121
	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
insilmaril@0
   122
}
insilmaril@0
   123
insilmaril@0
   124
QString FloatImageObj::getOriginalFilename()
insilmaril@0
   125
{
insilmaril@0
   126
	return originalFilename;
insilmaril@0
   127
}
insilmaril@0
   128
insilmaril@0
   129
void FloatImageObj::setVisibility(bool v)
insilmaril@0
   130
{
insilmaril@258
   131
    OrnamentedObj::setVisibility(v);
insilmaril@0
   132
	if (v)
insilmaril@0
   133
	    icon->setVisibility(true);
insilmaril@0
   134
	else
insilmaril@0
   135
	    icon->setVisibility(false);
insilmaril@0
   136
}
insilmaril@0
   137
insilmaril@0
   138
void FloatImageObj::move (double x, double y)
insilmaril@0
   139
{
insilmaril@0
   140
	FloatObj::move(x,y);
insilmaril@408
   141
	icon->setPos (x+4,y+4);
insilmaril@0
   142
    positionBBox();
insilmaril@0
   143
}
insilmaril@0
   144
insilmaril@408
   145
void FloatImageObj::move (QPointF p)
insilmaril@0
   146
{
insilmaril@408
   147
	OrnamentedObj::move (p.x(),p.y());
insilmaril@0
   148
}
insilmaril@0
   149
insilmaril@0
   150
void FloatImageObj::positionBBox()
insilmaril@0
   151
{
insilmaril@173
   152
	clickBox=bbox;
insilmaril@0
   153
}
insilmaril@0
   154
insilmaril@0
   155
void FloatImageObj::calcBBoxSize()
insilmaril@0
   156
{
insilmaril@0
   157
	// TODO
insilmaril@0
   158
}
insilmaril@0
   159
insilmaril@377
   160
QString FloatImageObj::saveToDir (const QString &tmpdir,const QString &prefix)
insilmaril@0
   161
{
insilmaril@258
   162
	if (hidden) return "";
insilmaril@258
   163
insilmaril@173
   164
	saveCounter++;
insilmaril@173
   165
	
insilmaril@0
   166
	QString useOrientAttr;
insilmaril@0
   167
	if (useOrientation)
insilmaril@0
   168
		useOrientAttr=attribut ("useOrientation","true");
insilmaril@0
   169
	else	
insilmaril@0
   170
		useOrientAttr=attribut ("useOrientation","false");
insilmaril@0
   171
		
insilmaril@0
   172
	QString saveInMapAttr;
insilmaril@0
   173
	if (saveInMap)
insilmaril@0
   174
		saveInMapAttr=attribut ("saveInMap","true");
insilmaril@0
   175
	else	
insilmaril@0
   176
		
insilmaril@0
   177
		saveInMapAttr=attribut ("saveInMap","false");
insilmaril@0
   178
insilmaril@0
   179
	QString exportAttr;
insilmaril@0
   180
	if (floatExport)
insilmaril@0
   181
		exportAttr=attribut ("floatExport","true");
insilmaril@0
   182
	else	
insilmaril@0
   183
		exportAttr=attribut ("floatExport","false");
insilmaril@0
   184
insilmaril@0
   185
	QString zAttr=attribut ("zPlane",QString().setNum(zPlane));
insilmaril@0
   186
	QString url;
insilmaril@0
   187
insilmaril@173
   188
	url="images/"+prefix+"image-" + QString().number(saveCounter,10) + "." +filetype;
insilmaril@0
   189
insilmaril@0
   190
	// And really save the image
insilmaril@366
   191
	icon->save (tmpdir + "/" + url, "PNG");
insilmaril@334
   192
 
insilmaril@334
   193
	QString nameAttr=attribut ("orgName",originalFilename);
insilmaril@0
   194
insilmaril@0
   195
    return singleElement ("floatimage",  
insilmaril@628
   196
		getOrnXMLAttr() 
insilmaril@241
   197
		+useOrientAttr 
insilmaril@241
   198
		+saveInMapAttr 
insilmaril@241
   199
		+exportAttr  
insilmaril@241
   200
		+zAttr  
insilmaril@241
   201
		+attribut ("href",QString ("file:")+url)
insilmaril@334
   202
		+nameAttr
insilmaril@0
   203
	);	
insilmaril@0
   204
}
insilmaril@0
   205
insilmaril@0
   206
void FloatImageObj::resetSaveCounter()
insilmaril@0
   207
{
insilmaril@173
   208
	saveCounter=0;
insilmaril@0
   209
}
insilmaril@0
   210
insilmaril@0
   211
insilmaril@408
   212
QRectF FloatImageObj::getTotalBBox()
insilmaril@0
   213
{
insilmaril@0
   214
	return bbox;
insilmaril@0
   215
}
insilmaril@0
   216
insilmaril@408
   217
QRectF FloatImageObj::getBBoxSizeWithChilds()
insilmaril@0
   218
{
insilmaril@411
   219
	//TODO abstract in linkablemapobj.h, not calculated
insilmaril@0
   220
	return bboxTotal;
insilmaril@0
   221
}
insilmaril@0
   222
insilmaril@0
   223
void FloatImageObj::calcBBoxSizeWithChilds()
insilmaril@0
   224
{
insilmaril@411
   225
	//TODO abstract in linkablemapobj.h
insilmaril@0
   226
}
insilmaril@0
   227
insilmaril@0
   228
QString FloatImageObj::getSelectString()
insilmaril@0
   229
{
insilmaril@0
   230
	QString s;
insilmaril@0
   231
	if (parObj)
insilmaril@0
   232
	{
insilmaril@0
   233
		if (parObj->getDepth()==0)
insilmaril@0
   234
			s= "fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
insilmaril@0
   235
		else	
insilmaril@0
   236
			s= ((BranchObj*)(parObj))->getSelectString() + ",fi:" + QString("%1").arg( ((BranchObj*)(parObj))->getFloatImageNum(this));
insilmaril@0
   237
	} else
insilmaril@0
   238
		s="mc:";
insilmaril@0
   239
	
insilmaril@0
   240
	return s;
insilmaril@0
   241
insilmaril@0
   242
}
insilmaril@0
   243