flagobj.cpp
author insilmaril
Mon, 14 Jan 2008 16:26:59 +0000
changeset 644 954221e01e4e
parent 580 8099ebaf4515
child 655 d4b49c6c6069
permissions -rw-r--r--
Added french manual by Claude
     1 #include "flagobj.h"
     2 
     3 /////////////////////////////////////////////////////////////////
     4 // FlagObj
     5 /////////////////////////////////////////////////////////////////
     6 FlagObj::FlagObj()
     7 {
     8 //	cout << "Const FlagObj ()\n";
     9     init ();
    10 }
    11 
    12 FlagObj::FlagObj(QGraphicsScene* s):MapObj(s) 
    13 {
    14 //	cout << "Const FlagObj  this="<<this<<"  scene="<<s<<endl;
    15     init ();
    16 }
    17 
    18 FlagObj::FlagObj (FlagObj* io)
    19 {
    20     copy (io);
    21 }
    22 
    23 FlagObj::~FlagObj()
    24 {
    25 //   cout << "Destr FlagObj  this="<<this <<"  " << name.ascii() << "\n";
    26 	if (icon) delete (icon);
    27 }
    28 
    29 
    30 void FlagObj::init ()
    31 {
    32 	name="undefined";
    33 	unsetGroup();
    34 
    35 	icon=new ImageObj (scene);
    36 	icon->setPos (absPos.x(), absPos.y() );
    37 	state=false;
    38 	used=false;
    39 	avis=true;
    40 	action=NULL;
    41 }
    42 
    43 void FlagObj::copy (FlagObj* other)
    44 {
    45     MapObj::copy(other);
    46 	name=other->name;
    47 	group=other->group;
    48 	tooltip=other->tooltip;
    49 	state=other->state;
    50 	avis=other->avis;
    51 	used=other->used;
    52 	icon->copy(other->icon);
    53 	action=other->action;
    54 	setVisibility (other->isVisibleObj() );
    55 }
    56 
    57 void FlagObj::move(double x, double y)
    58 {
    59     MapObj::move(x,y);
    60 	icon->setPos(x,y);
    61 	positionBBox();
    62 }
    63 
    64 void FlagObj::moveBy(double x, double y)
    65 {
    66     move (x+absPos.x(),y+absPos.y() );
    67 }
    68 
    69 void FlagObj::setVisibility (bool v)
    70 {
    71     MapObj::setVisibility(v);
    72 	if (v && state)
    73 	    icon->setVisibility(true);
    74 	else
    75 	    icon->setVisibility(false);
    76 }
    77 
    78 void FlagObj::load (const QString &fn)
    79 {
    80 	icon->load(fn);
    81 	calcBBoxSize();
    82 	positionBBox();
    83 }
    84 
    85 void FlagObj::load (const QPixmap &pm)
    86 {
    87 	icon->load(pm);
    88 	calcBBoxSize();
    89 	positionBBox();
    90 }
    91 
    92 void FlagObj::setName(const QString &n)
    93 {
    94 	name=n;
    95 }
    96 
    97 const QString FlagObj::getName()
    98 {
    99 	return name;
   100 }
   101 
   102 void FlagObj::setGroup (const QString &n)
   103 {
   104 	group=n;
   105 }
   106 
   107 const QString FlagObj::getGroup()
   108 {
   109 	return group;
   110 }
   111 
   112 void FlagObj::unsetGroup()
   113 {
   114 	group="undefined";
   115 }
   116 
   117 void FlagObj::setToolTip(const QString &n)
   118 {
   119 	tooltip=n;
   120 }
   121 
   122 const QString FlagObj::getToolTip()
   123 {
   124 	return tooltip;
   125 }
   126 
   127 QPixmap FlagObj::getPixmap()
   128 {
   129 	return icon->pixmap();
   130 }
   131 
   132 void FlagObj::setAction (QAction* a)
   133 {
   134 	action=a;
   135 }
   136 
   137 void FlagObj::updateAction ()
   138 {
   139 	if (action) 
   140 	{
   141 		action->setChecked(state);
   142 		if (!avis)
   143 			action->setVisible(state);
   144 	}
   145 }
   146 
   147 void FlagObj::setAlwaysVisible(bool b)
   148 {
   149 	avis=b;
   150 }
   151 
   152 bool FlagObj::isAlwaysVisible()
   153 {
   154 	return avis;
   155 }
   156 
   157 bool FlagObj::isActive()
   158 {
   159 	return state;
   160 }
   161 
   162 void FlagObj::toggle()
   163 {
   164 	if (state)
   165 		deactivate();
   166 	else
   167 		activate();
   168 }
   169 
   170 void FlagObj::activate()
   171 {
   172 	state=true;
   173 	// only show icon, if flag itself is visible 
   174 	if (visible) 
   175 	{
   176 		icon->setVisibility (true);
   177 		//icon->setPos (100,100);
   178 		//icon->setPos (rand()%100,rand()%130);
   179 		calcBBoxSize();
   180 	}	
   181 }
   182 
   183 void FlagObj::deactivate()
   184 {
   185 	state=false;
   186 	// if flag itself is invisible we don't need to call 
   187 	if (visible) 
   188 	{
   189 		icon->setVisibility (false);
   190 		calcBBoxSize();
   191 	}	
   192 }
   193 
   194 void FlagObj::setUsed (bool b)
   195 {
   196 	used=b;
   197 }
   198 
   199 bool FlagObj::isUsed()
   200 {
   201 	return used;
   202 }
   203 
   204 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   205 {
   206 	QString fn=tmpdir + prefix + name + ".png";
   207 	icon->save (fn,"PNG");
   208 }
   209 
   210 void FlagObj::positionBBox()
   211 {
   212     bbox.moveTopLeft (absPos );
   213     clickBox.moveTopLeft (absPos );
   214 }
   215 
   216 void FlagObj::calcBBoxSize()
   217 {
   218 	if (visible && state)
   219 	{
   220 		bbox.setSize (	QSizeF(
   221 			icon->boundingRect().width(), 
   222 			icon->boundingRect().height() ) );
   223 	} else
   224 	{
   225 		bbox.setSize (QSizeF(0,0));
   226 	}
   227 	clickBox.setSize (bbox.size());
   228 }
   229