floatimageobj.cpp
author insilmaril
Wed, 09 Jun 2010 13:14:08 +0000
changeset 847 43268373032d
parent 823 0bba81dde1bc
permissions -rw-r--r--
1.13.4 Various fixes
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@790
    11
FloatImageObj::FloatImageObj (QGraphicsScene* s,TreeItem *ti):FloatObj(s,ti)
insilmaril@0
    12
{
insilmaril@790
    13
   //cout << "Const FloatImageObj s="<<s<<"  ti="<<ti<<endl;
insilmaril@0
    14
    setParObj (this);	
insilmaril@0
    15
    init();
insilmaril@0
    16
}
insilmaril@0
    17
insilmaril@0
    18
FloatImageObj::~FloatImageObj ()
insilmaril@0
    19
{
insilmaril@417
    20
//	cout << "Destr FloatImageObj "<<this<<"\n";
insilmaril@0
    21
	delete(icon);
insilmaril@0
    22
}
insilmaril@0
    23
insilmaril@0
    24
void FloatImageObj::init () 
insilmaril@0
    25
{
insilmaril@408
    26
	icon=new ImageObj (scene);
insilmaril@408
    27
	icon->setPos (absPos.x(), absPos.y() );
insilmaril@0
    28
	icon->setVisibility (true);
insilmaril@408
    29
	setZValue (Z_FLOATIMG);
insilmaril@408
    30
	bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
insilmaril@408
    31
	clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
insilmaril@0
    32
	originalFilename="no original name available";
insilmaril@0
    33
	filetype="";
insilmaril@218
    34
	useRelPos=true;
insilmaril@258
    35
insilmaril@258
    36
	//Hide flags
insilmaril@258
    37
	systemFlags->setShowFlags(false);
insilmaril@0
    38
}
insilmaril@0
    39
insilmaril@0
    40
void FloatImageObj::copy (FloatImageObj* other)
insilmaril@0
    41
{					
insilmaril@0
    42
	FloatObj::copy (other);
insilmaril@0
    43
	icon->copy (other->icon);
insilmaril@173
    44
	filetype=other->filetype;
insilmaril@0
    45
	filename=other->filename;
insilmaril@173
    46
	originalFilename=other->originalFilename;
insilmaril@0
    47
    positionBBox();
insilmaril@0
    48
}
insilmaril@0
    49
insilmaril@408
    50
void FloatImageObj::setZValue (const int &i)
insilmaril@0
    51
{
insilmaril@408
    52
	icon->setZValue (i);
insilmaril@0
    53
	zPlane=i;
insilmaril@0
    54
}
insilmaril@0
    55
insilmaril@0
    56
int FloatImageObj::z ()
insilmaril@0
    57
{
insilmaril@408
    58
	return qRound (icon->zValue());
insilmaril@0
    59
}
insilmaril@0
    60
insilmaril@113
    61
void FloatImageObj::load (const QPixmap &pixmap)
insilmaril@113
    62
{
insilmaril@408
    63
	icon->load(pixmap);
insilmaril@408
    64
	bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    65
	clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    66
	positionBBox();
insilmaril@408
    67
	filetype="PNG";
insilmaril@408
    68
	filename="No filename given";
insilmaril@113
    69
}
insilmaril@113
    70
insilmaril@0
    71
bool FloatImageObj::load (const QString &fn)
insilmaril@0
    72
{	
insilmaril@408
    73
	QImageReader reader (fn);
insilmaril@408
    74
	QImage img;
insilmaril@408
    75
insilmaril@408
    76
	if( reader.read (&img))
insilmaril@0
    77
	{
insilmaril@408
    78
		icon->setPixmap(QPixmap::fromImage(img));
insilmaril@408
    79
		bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@0
    80
		positionBBox();
insilmaril@0
    81
		filename=fn;
insilmaril@408
    82
		filetype=reader.format();
insilmaril@334
    83
		setOriginalFilename (fn);
insilmaril@0
    84
		return true;
insilmaril@0
    85
	} else
insilmaril@0
    86
		return false;
insilmaril@0
    87
	
insilmaril@0
    88
}
insilmaril@0
    89
insilmaril@366
    90
void FloatImageObj::save (const QString &fn, const QString &format)
insilmaril@0
    91
{	
insilmaril@366
    92
	icon->save (fn,qPrintable (format));
insilmaril@0
    93
}
insilmaril@0
    94
insilmaril@0
    95
void FloatImageObj::setOriginalFilename(const QString & fn)
insilmaril@0
    96
{
insilmaril@0
    97
	originalFilename=fn;
insilmaril@334
    98
insilmaril@334
    99
	// Set short name, too. Search from behind:
insilmaril@334
   100
	int i=originalFilename.findRev("/");
insilmaril@334
   101
	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
insilmaril@0
   102
}
insilmaril@0
   103
insilmaril@0
   104
QString FloatImageObj::getOriginalFilename()
insilmaril@0
   105
{
insilmaril@0
   106
	return originalFilename;
insilmaril@0
   107
}
insilmaril@0
   108
insilmaril@0
   109
void FloatImageObj::setVisibility(bool v)
insilmaril@0
   110
{
insilmaril@258
   111
    OrnamentedObj::setVisibility(v);
insilmaril@0
   112
	if (v)
insilmaril@0
   113
	    icon->setVisibility(true);
insilmaril@0
   114
	else
insilmaril@0
   115
	    icon->setVisibility(false);
insilmaril@0
   116
}
insilmaril@0
   117
insilmaril@0
   118
void FloatImageObj::move (double x, double y)
insilmaril@0
   119
{
insilmaril@0
   120
	FloatObj::move(x,y);
insilmaril@408
   121
	icon->setPos (x+4,y+4);
insilmaril@0
   122
    positionBBox();
insilmaril@0
   123
}
insilmaril@0
   124
insilmaril@408
   125
void FloatImageObj::move (QPointF p)
insilmaril@0
   126
{
insilmaril@408
   127
	OrnamentedObj::move (p.x(),p.y());
insilmaril@0
   128
}
insilmaril@0
   129
insilmaril@0
   130
void FloatImageObj::positionBBox()
insilmaril@0
   131
{
insilmaril@173
   132
	clickBox=bbox;
insilmaril@0
   133
}
insilmaril@0
   134
insilmaril@0
   135
void FloatImageObj::calcBBoxSize()
insilmaril@0
   136
{
insilmaril@0
   137
	// TODO
insilmaril@0
   138
}
insilmaril@0
   139
insilmaril@721
   140
QRectF FloatImageObj::getBBoxSizeWithChildren()
insilmaril@0
   141
{
insilmaril@411
   142
	//TODO abstract in linkablemapobj.h, not calculated
insilmaril@0
   143
	return bboxTotal;
insilmaril@0
   144
}
insilmaril@0
   145
insilmaril@721
   146
void FloatImageObj::calcBBoxSizeWithChildren()
insilmaril@0
   147
{
insilmaril@411
   148
	//TODO abstract in linkablemapobj.h
insilmaril@0
   149
}
insilmaril@0
   150