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