floatimageobj.cpp
author insilmaril
Fri, 27 Nov 2009 15:00:51 +0000
changeset 812 62d4137bfb90
parent 790 133e2ed6b9c5
child 823 0bba81dde1bc
permissions -rw-r--r--
Select MapEditor after closing FindWidget
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
/* FIXME-3
insilmaril@0
    12
FloatImageObj::FloatImageObj ():FloatObj()
insilmaril@0
    13
{
insilmaril@0
    14
//    cout << "Const FloatImageObj ()\n";
insilmaril@0
    15
    setParObj (this);	
insilmaril@0
    16
    init();
insilmaril@0
    17
}
insilmaril@790
    18
*/
insilmaril@0
    19
insilmaril@790
    20
FloatImageObj::FloatImageObj (QGraphicsScene* s,TreeItem *ti):FloatObj(s,ti)
insilmaril@0
    21
{
insilmaril@790
    22
   //cout << "Const FloatImageObj s="<<s<<"  ti="<<ti<<endl;
insilmaril@0
    23
    setParObj (this);	
insilmaril@0
    24
    init();
insilmaril@0
    25
}
insilmaril@0
    26
insilmaril@790
    27
/* FIXME-3 needed
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@790
    33
*/
insilmaril@0
    34
insilmaril@0
    35
FloatImageObj::~FloatImageObj ()
insilmaril@0
    36
{
insilmaril@417
    37
//	cout << "Destr FloatImageObj "<<this<<"\n";
insilmaril@0
    38
	delete(icon);
insilmaril@0
    39
}
insilmaril@0
    40
insilmaril@0
    41
void FloatImageObj::init () 
insilmaril@0
    42
{
insilmaril@408
    43
	icon=new ImageObj (scene);
insilmaril@408
    44
	icon->setPos (absPos.x(), absPos.y() );
insilmaril@0
    45
	icon->setVisibility (true);
insilmaril@408
    46
	setZValue (Z_FLOATIMG);
insilmaril@408
    47
	bbox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));
insilmaril@408
    48
	clickBox.setSize (QSizeF(icon->boundingRect().width(), icon->boundingRect().height()));filename="";
insilmaril@0
    49
	originalFilename="no original name available";
insilmaril@0
    50
	filetype="";
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
    positionBBox();
insilmaril@0
    65
}
insilmaril@0
    66
insilmaril@408
    67
void FloatImageObj::setZValue (const int &i)
insilmaril@0
    68
{
insilmaril@408
    69
	icon->setZValue (i);
insilmaril@0
    70
	zPlane=i;
insilmaril@0
    71
}
insilmaril@0
    72
insilmaril@0
    73
int FloatImageObj::z ()
insilmaril@0
    74
{
insilmaril@408
    75
	return qRound (icon->zValue());
insilmaril@0
    76
}
insilmaril@0
    77
insilmaril@113
    78
void FloatImageObj::load (const QPixmap &pixmap)
insilmaril@113
    79
{
insilmaril@408
    80
	icon->load(pixmap);
insilmaril@408
    81
	bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    82
	clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@408
    83
	positionBBox();
insilmaril@408
    84
	filetype="PNG";
insilmaril@408
    85
	filename="No filename given";
insilmaril@113
    86
}
insilmaril@113
    87
insilmaril@0
    88
bool FloatImageObj::load (const QString &fn)
insilmaril@0
    89
{	
insilmaril@408
    90
	QImageReader reader (fn);
insilmaril@408
    91
	QImage img;
insilmaril@408
    92
insilmaril@408
    93
	if( reader.read (&img))
insilmaril@0
    94
	{
insilmaril@408
    95
		icon->setPixmap(QPixmap::fromImage(img));
insilmaril@408
    96
		bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
insilmaril@0
    97
		positionBBox();
insilmaril@0
    98
		filename=fn;
insilmaril@408
    99
		filetype=reader.format();
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@408
   138
	icon->setPos (x+4,y+4);
insilmaril@0
   139
    positionBBox();
insilmaril@0
   140
}
insilmaril@0
   141
insilmaril@408
   142
void FloatImageObj::move (QPointF p)
insilmaril@0
   143
{
insilmaril@408
   144
	OrnamentedObj::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@408
   157
QRectF FloatImageObj::getTotalBBox()
insilmaril@0
   158
{
insilmaril@0
   159
	return bbox;
insilmaril@0
   160
}
insilmaril@0
   161
insilmaril@721
   162
QRectF FloatImageObj::getBBoxSizeWithChildren()
insilmaril@0
   163
{
insilmaril@411
   164
	//TODO abstract in linkablemapobj.h, not calculated
insilmaril@0
   165
	return bboxTotal;
insilmaril@0
   166
}
insilmaril@0
   167
insilmaril@721
   168
void FloatImageObj::calcBBoxSizeWithChildren()
insilmaril@0
   169
{
insilmaril@411
   170
	//TODO abstract in linkablemapobj.h
insilmaril@0
   171
}
insilmaril@0
   172