]> git.sven.stormbind.net Git - sven/vym.git/blob - flagobj.cpp
fbf251073e9ceaccc9a06fb9d254c3b6fb204f15
[sven/vym.git] / flagobj.cpp
1 #include <QDebug>
2
3 #include "flagobj.h"
4
5 /////////////////////////////////////////////////////////////////
6 // FlagObj
7 /////////////////////////////////////////////////////////////////
8 FlagObj::FlagObj(QGraphicsItem *parent):MapObj(parent) 
9 {
10 //  qDebug() << "Const FlagObj  this="<<this<<"  scene="<<s;
11     init ();
12 }
13
14 FlagObj::~FlagObj()
15 {
16 //   qDebug() << "Destr FlagObj  this="<<this <<"  " <<name;
17     if (icon) delete (icon);
18 }
19
20
21 void FlagObj::init ()
22 {
23     name="undefined";
24
25     icon=new ImageObj (parentItem());
26     icon->setPos (absPos.x(), absPos.y() );
27     state=false;
28     avis=true;
29 }
30
31 void FlagObj::copy (FlagObj* other)
32 {
33     MapObj::copy(other);
34     name=other->name;
35     state=other->state;
36     avis=other->avis;
37     icon->copy(other->icon);
38     setVisibility (other->isVisibleObj() );
39 }
40
41 void FlagObj::move(double x, double y)
42 {
43     MapObj::move(x,y);
44     icon->setPos(x,y);
45     positionBBox();
46 }
47
48 void FlagObj::moveBy(double x, double y)
49 {
50     move (x+absPos.x(),y+absPos.y() );
51 }
52
53 void FlagObj::setZValue (double z)
54 {
55     icon->setZValue (z);
56 }
57
58 void FlagObj::setVisibility (bool v)
59 {
60     MapObj::setVisibility(v);
61     if (v && state)
62         icon->setVisibility(true);
63     else
64         icon->setVisibility(false);
65 }
66
67 void FlagObj::load (const QString &fn)
68 {
69     icon->load(fn);
70     calcBBoxSize();
71     positionBBox();
72 }
73
74 void FlagObj::load (const QPixmap &pm)
75 {
76     icon->load(pm);
77     calcBBoxSize();
78     positionBBox();
79 }
80
81 void FlagObj::setName(const QString &n)
82 {
83     name=n;
84 }
85
86 const QString FlagObj::getName()
87 {
88     return name;
89 }
90
91 void FlagObj::setAlwaysVisible(bool b)
92 {
93     avis=b;
94 }
95
96 bool FlagObj::isAlwaysVisible()
97 {
98     return avis;
99 }
100
101 bool FlagObj::isActive()
102 {
103     return state;
104 }
105
106 void FlagObj::toggle()
107 {
108     if (state)
109         deactivate();
110     else
111         activate();
112 }
113
114 void FlagObj::activate()
115 {
116     state=true;
117     // only show icon, if flag itself is visible 
118     if (visible) 
119     {
120         icon->setVisibility (true);
121         calcBBoxSize();
122     }   
123 }
124
125 void FlagObj::deactivate()
126 {
127     state=false;
128     // if flag itself is invisible we don't need to call 
129     if (visible) 
130     {
131         icon->setVisibility (false);
132         calcBBoxSize();
133     }   
134 }
135
136 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
137 {
138     QString fn=tmpdir + prefix + name + ".png";
139     icon->save (fn,"PNG");
140 }
141
142 void FlagObj::positionBBox()
143 {
144     bbox.moveTopLeft (absPos );
145     clickPoly=QPolygonF (bbox);
146 }
147
148 void FlagObj::calcBBoxSize()
149 {
150     if (visible && state)
151         bbox.setSize (  QSizeF(
152             icon->boundingRect().width(), 
153             icon->boundingRect().height() ) );
154     else
155         bbox.setSize (QSizeF(0,0));
156     clickPoly= QPolygonF (bbox); 
157 }
158