Menu

[c54480]: / flagobj.cpp  Maximize  Restore  History

Download this file

159 lines (133 with data), 2.6 kB

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