flagobj.cpp
author convert-repo
Fri Jul 23 16:43:49 2010 +0000 (2010-07-23)
changeset 849 988f1908a7c4
parent 763 8c028a5d9083
permissions -rw-r--r--
update tags
     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 (Flag* f)
    24 {
    25 	init();
    26 	name=f->getName();
    27 	icon->load(f->getPixmap());
    28 }
    29 
    30 FlagObj::~FlagObj()
    31 {
    32 //   cout << "Destr FlagObj  this="<<this <<"  " << qPrintable(name) << "\n";
    33 	if (icon) delete (icon);
    34 }
    35 
    36 
    37 void FlagObj::init ()
    38 {
    39 	name="undefined";
    40 
    41 	icon=new ImageObj (scene);
    42 	icon->setPos (absPos.x(), absPos.y() );
    43 	state=false;
    44 	avis=true;
    45 }
    46 
    47 void FlagObj::copy (FlagObj* other)
    48 {
    49     MapObj::copy(other);
    50 	name=other->name;
    51 	state=other->state;
    52 	avis=other->avis;
    53 	icon->copy(other->icon);
    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::setAlwaysVisible(bool b)
   103 {
   104 	avis=b;
   105 }
   106 
   107 bool FlagObj::isAlwaysVisible()
   108 {
   109 	return avis;
   110 }
   111 
   112 bool FlagObj::isActive()
   113 {
   114 	return state;
   115 }
   116 
   117 void FlagObj::toggle()
   118 {
   119 	if (state)
   120 		deactivate();
   121 	else
   122 		activate();
   123 }
   124 
   125 void FlagObj::activate()
   126 {
   127 	state=true;
   128 	// only show icon, if flag itself is visible 
   129 	if (visible) 
   130 	{
   131 		icon->setVisibility (true);
   132 		calcBBoxSize();
   133 	}	
   134 }
   135 
   136 void FlagObj::deactivate()
   137 {
   138 	state=false;
   139 	// if flag itself is invisible we don't need to call 
   140 	if (visible) 
   141 	{
   142 		icon->setVisibility (false);
   143 		calcBBoxSize();
   144 	}	
   145 }
   146 
   147 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   148 {
   149 	QString fn=tmpdir + prefix + name + ".png";
   150 	icon->save (fn,"PNG");
   151 }
   152 
   153 void FlagObj::positionBBox()
   154 {
   155     bbox.moveTopLeft (absPos );
   156     clickBox.moveTopLeft (absPos );
   157 }
   158 
   159 void FlagObj::calcBBoxSize()
   160 {
   161 	if (visible && state)
   162 		bbox.setSize (	QSizeF(
   163 			icon->boundingRect().width(), 
   164 			icon->boundingRect().height() ) );
   165 	else
   166 		bbox.setSize (QSizeF(0,0));
   167 	clickBox.setSize (bbox.size());
   168 }
   169