]> git.sven.stormbind.net Git - sven/vym.git/blob - src/floatimageobj.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / floatimageobj.cpp
1 #include <QDebug>
2 #include <QImageReader>
3
4 #include "branchobj.h"
5 #include "floatimageobj.h"
6
7 /////////////////////////////////////////////////////////////////
8 // FloatImageObj
9 /////////////////////////////////////////////////////////////////
10
11 FloatImageObj::FloatImageObj(QGraphicsItem *parent, TreeItem *ti)
12     : FloatObj(parent, ti)
13 {
14     // qDebug() << "Const FloatImageObj this=" << this << "  ti=" << ti;
15     imageObj = new ImageObj(parent);
16     imageObj->setPos(absPos.x(), absPos.y());
17     imageObj->setVisibility(true);
18     clickPoly = bbox;
19     useRelPos = true;
20
21     //    setLinkStyle (LinkableMapObj::Parabel);
22 }
23
24 FloatImageObj::~FloatImageObj()
25 {
26     // qDebug() << "Destr FloatImageObj "<<this<<"";
27     delete (imageObj);
28 }
29
30 void FloatImageObj::copy(FloatImageObj *other)
31 {
32     FloatObj::copy(other);
33     imageObj->copy(other->imageObj);
34     positionBBox();
35 }
36
37 void FloatImageObj::setZValue(const int &i)
38 {
39
40     //    qDebug()<<"FIO::setZValue z="<<i;
41     //    qDebug()<<"  imageObj="<<imageObj;
42     //    qDebug()<<"  this="<<this;
43     imageObj->setZValue(i);
44 }
45
46 int FloatImageObj::z() { return qRound(imageObj->zValue()); }
47
48 bool FloatImageObj::load(const QString &fname)
49 {
50     if (!imageObj->load(fname))
51         return false;
52
53     bbox.setSize(QSizeF(imageObj->boundingRect().width(),
54                         imageObj->boundingRect().height()));
55
56     clickPoly = bbox;
57     positionBBox();
58     return true;
59 }
60
61 bool FloatImageObj::save(const QString &fname) { return imageObj->save(fname); }
62
63 QString FloatImageObj::getExtension() { return imageObj->getExtension(); }
64
65 void FloatImageObj::setParObj(QGraphicsItem *p)
66 {
67     setParentItem(p);
68     imageObj->setParentItem(p);
69     parObj = (LinkableMapObj *)p;
70     /*
71         qDebug()<<"FIO::setParentItem";
72         qDebug()<<"     this = "<<this;
73         qDebug()<<"  imageObj=" << imageObj;
74     */
75 }
76
77 void FloatImageObj::setVisibility(bool v)
78 {
79     OrnamentedObj::setVisibility(v);
80     if (v)
81         imageObj->setVisibility(true);
82     else
83         imageObj->setVisibility(false);
84 }
85
86 void FloatImageObj::setScaleFactor(qreal f)
87 {
88     imageObj->setScaleFactor(f);
89     bbox.setSize(QSizeF(imageObj->boundingRect().width(),
90                         imageObj->boundingRect().height()));
91     positionBBox();
92 }
93
94 qreal FloatImageObj::getScaleFactor() { return imageObj->getScaleFactor(); }
95
96 qreal FloatImageObj::width()
97 {
98     return imageObj->boundingRect().width();
99 }
100
101 qreal FloatImageObj::height()
102 {
103     return imageObj->boundingRect().height();
104 }
105
106 void FloatImageObj::moveCenter(double x, double y)
107 {
108     FloatObj::moveCenter(x, y);
109     imageObj->setPos(bbox.topLeft());
110 }
111
112 void FloatImageObj::move(double x, double y)
113 {
114     FloatObj::move(x, y);
115     imageObj->setPos(x, y);
116     positionBBox();
117 }
118
119 void FloatImageObj::move(QPointF p) { FloatImageObj::move(p.x(), p.y()); }
120
121 void FloatImageObj::positionBBox() { clickPoly = QPolygonF(bbox); }
122
123 void FloatImageObj::calcBBoxSize()
124 {
125     // TODO
126 }
127
128 QRectF FloatImageObj::getBBoxSizeWithChildren()
129 {
130     // TODO abstract in linkablemapobj.h, not calculated
131     return bboxTotal;
132 }
133
134 void FloatImageObj::calcBBoxSizeWithChildren()
135 {
136     // TODO abstract in linkablemapobj.h
137 }