flagobj.cpp
author insilmaril
Tue, 05 Sep 2006 10:03:29 +0000
changeset 368 cd7558fa3ffc
parent 366 e95081c21da2
child 406 1c8ff1928b97
permissions -rw-r--r--
Moved qt4-port branch to head
     1 #include "flagobj.h"
     2 //Added by qt3to4:
     3 #include <QPixmap>
     4 
     5 /////////////////////////////////////////////////////////////////
     6 // FlagObj
     7 /////////////////////////////////////////////////////////////////
     8 FlagObj::FlagObj()
     9 {
    10 //	cout << "Const FlagObj ()\n";
    11     init ();
    12 }
    13 
    14 FlagObj::FlagObj(Q3Canvas* c):MapObj(c) 
    15 {
    16 //	cout << "Const FlagObj  canvas="<<c<<endl;
    17     init ();
    18 }
    19 
    20 FlagObj::FlagObj (FlagObj* io)
    21 {
    22     copy (io);
    23 }
    24 
    25 FlagObj::~FlagObj()
    26 {
    27 //    cout << "Destr FlagObj  " << name << "\n";
    28 	if (icon) delete (icon);
    29 }
    30 
    31 
    32 void FlagObj::init ()
    33 {
    34 	name="undefined";
    35 	group="undefined";
    36 
    37 	icon=new ImageObj (canvas);
    38 	icon->move (absPos.x(), absPos.y() );
    39 	state=false;
    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 	icon->copy(other->icon);
    51 	action=other->action;
    52 	setVisibility (other->isVisibleObj() );
    53 }
    54 
    55 void FlagObj::move(double x, double y)
    56 {
    57     MapObj::move(x,y);
    58 	icon->move(x,y);
    59 	positionBBox();
    60 }
    61 
    62 void FlagObj::moveBy(double x, double y)
    63 {
    64     move (x+absPos.x(),y+absPos.y() );
    65 }
    66 
    67 void FlagObj::setVisibility (bool v)
    68 {
    69     MapObj::setVisibility(v);
    70 	if (v && state)
    71 	    icon->setVisibility(true);
    72 	else
    73 	    icon->setVisibility(false);
    74 }
    75 
    76 void FlagObj::load (const QString &fn)
    77 {
    78 	icon->load(fn);
    79 	calcBBoxSize();
    80 	positionBBox();
    81 }
    82 
    83 void FlagObj::load (const QPixmap &pm)
    84 {
    85 	icon->load(pm);
    86 	calcBBoxSize();
    87 	positionBBox();
    88 }
    89 
    90 void FlagObj::setName(const QString &n)
    91 {
    92 	name=n;
    93 }
    94 
    95 const QString FlagObj::getName()
    96 {
    97 	return name;
    98 }
    99 
   100 void FlagObj::setGroup (const QString &n)
   101 {
   102 	group=n;
   103 }
   104 
   105 const QString FlagObj::getGroup()
   106 {
   107 	return group;
   108 }
   109 
   110 void FlagObj::setToolTip(const QString &n)
   111 {
   112 	tooltip=n;
   113 }
   114 
   115 const QString FlagObj::getToolTip()
   116 {
   117 	return tooltip;
   118 }
   119 
   120 QPixmap FlagObj::getPixmap()
   121 {
   122 	return icon->getPixmap();
   123 }
   124 
   125 void FlagObj::setAction (QAction* a)
   126 {
   127 	action=a;
   128 }
   129 
   130 void FlagObj::updateAction ()
   131 {
   132 	if (action) action->setChecked(state);
   133 }
   134 
   135 bool FlagObj::isActive()
   136 {
   137 	return state;
   138 }
   139 
   140 void FlagObj::toggle()
   141 {
   142 	if (state)
   143 		deactivate();
   144 	else
   145 		activate();
   146 }
   147 
   148 void FlagObj::activate()
   149 {
   150 	state=true;
   151 	// only show icon, if flag itself is visible 
   152 	if (visible) 
   153 	{
   154 		icon->setVisibility (true);
   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 (	QSize(
   197 			icon->boundingRect().width(), 
   198 			icon->boundingRect().height() ) );
   199 	} else
   200 	{
   201 		bbox.setSize (QSize(0,0));
   202 	}
   203 	clickBox.setSize (bbox.size());
   204 }
   205