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