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