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