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