flagobj.cpp
author insilmaril
Sat, 31 Mar 2007 09:28:27 +0000
changeset 443 0a4b622d5dc3
parent 425 7014be3ac7d0
child 580 8099ebaf4515
permissions -rw-r--r--
1.8.70 Fixes in property window
     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 	group="undefined";
    34 
    35 	icon=new ImageObj (scene);
    36 	icon->setPos (absPos.x(), absPos.y() );
    37 	state=false;
    38 	action=NULL;
    39 }
    40 
    41 void FlagObj::copy (FlagObj* other)
    42 {
    43     MapObj::copy(other);
    44 	name=other->name;
    45 	group=other->group;
    46 	tooltip=other->tooltip;
    47 	state=other->state;
    48 	icon->copy(other->icon);
    49 	action=other->action;
    50 	setVisibility (other->isVisibleObj() );
    51 }
    52 
    53 void FlagObj::move(double x, double y)
    54 {
    55     MapObj::move(x,y);
    56 	icon->setPos(x,y);
    57 	positionBBox();
    58 }
    59 
    60 void FlagObj::moveBy(double x, double y)
    61 {
    62     move (x+absPos.x(),y+absPos.y() );
    63 }
    64 
    65 void FlagObj::setVisibility (bool v)
    66 {
    67     MapObj::setVisibility(v);
    68 	if (v && state)
    69 	    icon->setVisibility(true);
    70 	else
    71 	    icon->setVisibility(false);
    72 }
    73 
    74 void FlagObj::load (const QString &fn)
    75 {
    76 	icon->load(fn);
    77 	calcBBoxSize();
    78 	positionBBox();
    79 }
    80 
    81 void FlagObj::load (const QPixmap &pm)
    82 {
    83 	icon->load(pm);
    84 	calcBBoxSize();
    85 	positionBBox();
    86 }
    87 
    88 void FlagObj::setName(const QString &n)
    89 {
    90 	name=n;
    91 }
    92 
    93 const QString FlagObj::getName()
    94 {
    95 	return name;
    96 }
    97 
    98 void FlagObj::setGroup (const QString &n)
    99 {
   100 	group=n;
   101 }
   102 
   103 const QString FlagObj::getGroup()
   104 {
   105 	return group;
   106 }
   107 
   108 void FlagObj::setToolTip(const QString &n)
   109 {
   110 	tooltip=n;
   111 }
   112 
   113 const QString FlagObj::getToolTip()
   114 {
   115 	return tooltip;
   116 }
   117 
   118 QPixmap FlagObj::getPixmap()
   119 {
   120 	return icon->pixmap();
   121 }
   122 
   123 void FlagObj::setAction (QAction* a)
   124 {
   125 	action=a;
   126 }
   127 
   128 void FlagObj::updateAction ()
   129 {
   130 	if (action) action->setChecked(state);
   131 }
   132 
   133 bool FlagObj::isActive()
   134 {
   135 	return state;
   136 }
   137 
   138 void FlagObj::toggle()
   139 {
   140 	if (state)
   141 		deactivate();
   142 	else
   143 		activate();
   144 }
   145 
   146 void FlagObj::activate()
   147 {
   148 	state=true;
   149 	// only show icon, if flag itself is visible 
   150 	if (visible) 
   151 	{
   152 		icon->setVisibility (true);
   153 		//icon->setPos (100,100);
   154 		//icon->setPos (rand()%100,rand()%130);
   155 		calcBBoxSize();
   156 	}	
   157 }
   158 
   159 void FlagObj::deactivate()
   160 {
   161 	state=false;
   162 	// if flag itself is invisible we don't need to call 
   163 	if (visible) 
   164 	{
   165 		icon->setVisibility (false);
   166 		calcBBoxSize();
   167 	}	
   168 }
   169 
   170 void FlagObj::setUsed (bool b)
   171 {
   172 	used=b;
   173 }
   174 
   175 bool FlagObj::isUsed()
   176 {
   177 	return used;
   178 }
   179 
   180 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   181 {
   182 	QString fn=tmpdir + prefix + name + ".png";
   183 	icon->save (fn,"PNG");
   184 }
   185 
   186 void FlagObj::positionBBox()
   187 {
   188     bbox.moveTopLeft (absPos );
   189     clickBox.moveTopLeft (absPos );
   190 }
   191 
   192 void FlagObj::calcBBoxSize()
   193 {
   194 	if (visible && state)
   195 	{
   196 		bbox.setSize (	QSizeF(
   197 			icon->boundingRect().width(), 
   198 			icon->boundingRect().height() ) );
   199 	} else
   200 	{
   201 		bbox.setSize (QSizeF(0,0));
   202 	}
   203 	clickBox.setSize (bbox.size());
   204 }
   205