flagobj.cpp
branchrelease-1-12-maintained
changeset 51 b2224ebf331f
child 2 608f976aa7bb
child 103 c810a11d11d9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/flagobj.cpp	Mon Oct 06 12:28:25 2008 +0000
     1.3 @@ -0,0 +1,201 @@
     1.4 +#include "flagobj.h"
     1.5 +
     1.6 +/////////////////////////////////////////////////////////////////
     1.7 +// FlagObj
     1.8 +/////////////////////////////////////////////////////////////////
     1.9 +FlagObj::FlagObj()
    1.10 +{
    1.11 +//    cout << "Const FlagObj ()\n";
    1.12 +    init ();
    1.13 +}
    1.14 +
    1.15 +FlagObj::FlagObj(QCanvas* c):MapObj(c) 
    1.16 +{
    1.17 +//    cout << "Const FlagObj\n";
    1.18 +    init ();
    1.19 +}
    1.20 +
    1.21 +FlagObj::FlagObj (FlagObj* io)
    1.22 +{
    1.23 +    copy (io);
    1.24 +}
    1.25 +
    1.26 +FlagObj::~FlagObj()
    1.27 +{
    1.28 +//    cout << "Destr FlagObj  " << name << "\n";
    1.29 +	delete (icon);
    1.30 +}
    1.31 +
    1.32 +
    1.33 +void FlagObj::init ()
    1.34 +{
    1.35 +	name="undefined";
    1.36 +
    1.37 +	icon=new ImageObj (canvas);
    1.38 +	icon->move (absPos.x(), absPos.y() );
    1.39 +	button=NULL;
    1.40 +	state=false;
    1.41 +}
    1.42 +
    1.43 +void FlagObj::copy (FlagObj* other)
    1.44 +{
    1.45 +    MapObj::copy(other);
    1.46 +	name=other->name;
    1.47 +	tooltip=other->tooltip;
    1.48 +	state=other->state;
    1.49 +	icon->copy(other->icon);
    1.50 +	setVisibility (other->isVisibleObj() );
    1.51 +	// button is not copied, because
    1.52 +	// we won't copy to a parentRow and
    1.53 +	// all others don't need a button
    1.54 +}
    1.55 +
    1.56 +void FlagObj::move(double x, double y)
    1.57 +{
    1.58 +    MapObj::move(x,y);
    1.59 +	icon->move(x,y);
    1.60 +	positionBBox();
    1.61 +}
    1.62 +
    1.63 +void FlagObj::moveBy(double x, double y)
    1.64 +{
    1.65 +    move (x+absPos.x(),y+absPos.y() );
    1.66 +}
    1.67 +
    1.68 +void FlagObj::setVisibility (bool v)
    1.69 +{
    1.70 +    MapObj::setVisibility(v);
    1.71 +	if (v && state)
    1.72 +	    icon->setVisibility(true);
    1.73 +	else
    1.74 +	    icon->setVisibility(false);
    1.75 +}
    1.76 +
    1.77 +void FlagObj::load (const QString &fn)
    1.78 +{
    1.79 +	icon->load(fn);
    1.80 +	calcBBoxSize();
    1.81 +	positionBBox();
    1.82 +}
    1.83 +
    1.84 +void FlagObj::load (const QPixmap &pm)
    1.85 +{
    1.86 +	icon->load(pm);
    1.87 +	calcBBoxSize();
    1.88 +	positionBBox();
    1.89 +}
    1.90 +
    1.91 +void FlagObj::setName(const QString &n)
    1.92 +{
    1.93 +	name=n;
    1.94 +}
    1.95 +
    1.96 +const QString FlagObj::getName()
    1.97 +{
    1.98 +	return name;
    1.99 +}
   1.100 +
   1.101 +void FlagObj::setToolTip(const QString &n)
   1.102 +{
   1.103 +	tooltip=n;
   1.104 +}
   1.105 +
   1.106 +const QString FlagObj::getToolTip()
   1.107 +{
   1.108 +	return tooltip;
   1.109 +}
   1.110 +
   1.111 +void FlagObj::setButton(QAction* b)
   1.112 +{
   1.113 +    button=b;
   1.114 +}
   1.115 +
   1.116 +void FlagObj::updateButton()
   1.117 +{
   1.118 +	if (button)
   1.119 +		button->setOn(state);
   1.120 +	else
   1.121 +		qWarning ("FlagObj::updateButton  no button defined");
   1.122 +}
   1.123 +
   1.124 +QPixmap FlagObj::getPixmap()
   1.125 +{
   1.126 +	return icon->getPixmap();
   1.127 +}
   1.128 +
   1.129 +bool FlagObj::isActive()
   1.130 +{
   1.131 +	return state;
   1.132 +}
   1.133 +
   1.134 +void FlagObj::toggle()
   1.135 +{
   1.136 +	if (state)
   1.137 +		deactivate();
   1.138 +	else
   1.139 +		activate();
   1.140 +}
   1.141 +
   1.142 +void FlagObj::activate()
   1.143 +{
   1.144 +	state=true;
   1.145 +	// only show icon, if flag itself is visible 
   1.146 +	if (visible) 
   1.147 +	{
   1.148 +		icon->setVisibility (true);
   1.149 +		calcBBoxSize();
   1.150 +	}	
   1.151 +}
   1.152 +
   1.153 +void FlagObj::deactivate()
   1.154 +{
   1.155 +	state=false;
   1.156 +	// if flag itself is invisible we don't need to call 
   1.157 +	if (visible) 
   1.158 +	{
   1.159 +		icon->setVisibility (false);
   1.160 +		calcBBoxSize();
   1.161 +	}	
   1.162 +}
   1.163 +
   1.164 +void FlagObj::setEnabled(bool b)
   1.165 +{
   1.166 +	button->setEnabled (b);
   1.167 +}	
   1.168 +	
   1.169 +
   1.170 +void FlagObj::setUsed (bool b)
   1.171 +{
   1.172 +	used=b;
   1.173 +}
   1.174 +
   1.175 +bool FlagObj::isUsed()
   1.176 +{
   1.177 +	return used;
   1.178 +}
   1.179 +
   1.180 +void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   1.181 +{
   1.182 +	QString fn=tmpdir + prefix + name + ".png";
   1.183 +	icon->save (fn,"PNG");
   1.184 +}
   1.185 +
   1.186 +void FlagObj::positionBBox()
   1.187 +{
   1.188 +    bbox.setX (absPos.x() );
   1.189 +    bbox.setY (absPos.y() );
   1.190 +}
   1.191 +
   1.192 +void FlagObj::calcBBoxSize()
   1.193 +{
   1.194 +	if (visible && state)
   1.195 +	{
   1.196 +		bbox.setSize (	QSize(
   1.197 +			icon->boundingRect().width(), 
   1.198 +			icon->boundingRect().height() ) );
   1.199 +	} else
   1.200 +	{
   1.201 +		bbox.setSize (QSize(0,0));
   1.202 +	}
   1.203 +}
   1.204 +