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)
     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 	saveInMap=true;
    48 	useRelPos=true;
    49 
    50 	//Hide flags
    51 	systemFlags->setShowFlags(false);
    52 }
    53 
    54 void FloatImageObj::copy (FloatImageObj* other)
    55 {					
    56 	FloatObj::copy (other);
    57 	icon->copy (other->icon);
    58 	filetype=other->filetype;
    59 	filename=other->filename;
    60 	originalFilename=other->originalFilename;
    61 	saveInMap=other->saveInMap;
    62     positionBBox();
    63 }
    64 
    65 void FloatImageObj::setZValue (const int &i)
    66 {
    67 	icon->setZValue (i);
    68 	zPlane=i;
    69 }
    70 
    71 int FloatImageObj::z ()
    72 {
    73 	return qRound (icon->zValue());
    74 }
    75 
    76 void FloatImageObj::load (const QPixmap &pixmap)
    77 {
    78 	icon->load(pixmap);
    79 	bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    80 	clickBox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    81 	positionBBox();
    82 	filetype="PNG";
    83 	filename="No filename given";
    84 }
    85 
    86 bool FloatImageObj::load (const QString &fn)
    87 {	
    88 	QImageReader reader (fn);
    89 	QImage img;
    90 
    91 	if( reader.read (&img))
    92 	{
    93 		icon->setPixmap(QPixmap::fromImage(img));
    94 		bbox.setSize (QSizeF(icon->boundingRect().width()+8, icon->boundingRect().height()+8));
    95 		positionBBox();
    96 		filename=fn;
    97 		filetype=reader.format();
    98 		setOriginalFilename (fn);
    99 		return true;
   100 	} else
   101 		return false;
   102 	
   103 }
   104 
   105 void FloatImageObj::save (const QString &fn, const QString &format)
   106 {	
   107 	icon->save (fn,qPrintable (format));
   108 }
   109 
   110 void FloatImageObj::setOriginalFilename(const QString & fn)
   111 {
   112 	originalFilename=fn;
   113 
   114 	// Set short name, too. Search from behind:
   115 	int i=originalFilename.findRev("/");
   116 	if (i>=0) originalFilename=originalFilename.remove (0,i+1);
   117 }
   118 
   119 QString FloatImageObj::getOriginalFilename()
   120 {
   121 	return originalFilename;
   122 }
   123 
   124 void FloatImageObj::setVisibility(bool v)
   125 {
   126     OrnamentedObj::setVisibility(v);
   127 	if (v)
   128 	    icon->setVisibility(true);
   129 	else
   130 	    icon->setVisibility(false);
   131 }
   132 
   133 void FloatImageObj::move (double x, double y)
   134 {
   135 	FloatObj::move(x,y);
   136 	icon->setPos (x+4,y+4);
   137     positionBBox();
   138 }
   139 
   140 void FloatImageObj::move (QPointF p)
   141 {
   142 	OrnamentedObj::move (p.x(),p.y());
   143 }
   144 
   145 void FloatImageObj::positionBBox()
   146 {
   147 	clickBox=bbox;
   148 }
   149 
   150 void FloatImageObj::calcBBoxSize()
   151 {
   152 	// TODO
   153 }
   154 
   155 QRectF FloatImageObj::getTotalBBox()
   156 {
   157 	return bbox;
   158 }
   159 
   160 QRectF FloatImageObj::getBBoxSizeWithChildren()
   161 {
   162 	//TODO abstract in linkablemapobj.h, not calculated
   163 	return bboxTotal;
   164 }
   165 
   166 void FloatImageObj::calcBBoxSizeWithChildren()
   167 {
   168 	//TODO abstract in linkablemapobj.h
   169 }
   170