flagobj.cpp
author insilmaril
Mon, 18 Apr 2005 06:17:00 +0000
changeset 95 f688a9913724
parent 0 7a96bd401351
child 2 608f976aa7bb
child 103 c810a11d11d9
permissions -rw-r--r--
added basic xLink functions
     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(QCanvas* c):MapObj(c) 
    13 {
    14 //    cout << "Const FlagObj\n";
    15     init ();
    16 }
    17 
    18 FlagObj::FlagObj (FlagObj* io)
    19 {
    20     copy (io);
    21 }
    22 
    23 FlagObj::~FlagObj()
    24 {
    25 //    cout << "Destr FlagObj  " << name << "\n";
    26 	delete (icon);
    27 }
    28 
    29 
    30 void FlagObj::init ()
    31 {
    32 	name="undefined";
    33 
    34 	icon=new ImageObj (canvas);
    35 	icon->move (absPos.x(), absPos.y() );
    36 	button=NULL;
    37 	state=false;
    38 }
    39 
    40 void FlagObj::copy (FlagObj* other)
    41 {
    42     MapObj::copy(other);
    43 	name=other->name;
    44 	tooltip=other->tooltip;
    45 	state=other->state;
    46 	icon->copy(other->icon);
    47 	setVisibility (other->isVisibleObj() );
    48 	// button is not copied, because
    49 	// we won't copy to a parentRow and
    50 	// all others don't need a button
    51 }
    52 
    53 void FlagObj::move(double x, double y)
    54 {
    55     MapObj::move(x,y);
    56 	icon->move(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::setToolTip(const QString &n)
    99 {
   100 	tooltip=n;
   101 }
   102 
   103 const QString FlagObj::getToolTip()
   104 {
   105 	return tooltip;
   106 }
   107 
   108 void FlagObj::setButton(QAction* b)
   109 {
   110     button=b;
   111 }
   112 
   113 void FlagObj::updateButton()
   114 {
   115 	if (button)
   116 		button->setOn(state);
   117 	else
   118 		qWarning ("FlagObj::updateButton  no button defined");
   119 }
   120 
   121 QPixmap FlagObj::getPixmap()
   122 {
   123 	return icon->getPixmap();
   124 }
   125 
   126 bool FlagObj::isActive()
   127 {
   128 	return state;
   129 }
   130 
   131 void FlagObj::toggle()
   132 {
   133 	if (state)
   134 		deactivate();
   135 	else
   136 		activate();
   137 }
   138 
   139 void FlagObj::activate()
   140 {
   141 	state=true;
   142 	// only show icon, if flag itself is visible 
   143 	if (visible) 
   144 	{
   145 		icon->setVisibility (true);
   146 		calcBBoxSize();
   147 	}	
   148 }
   149 
   150 void FlagObj::deactivate()
   151 {
   152 	state=false;
   153 	// if flag itself is invisible we don't need to call 
   154 	if (visible) 
   155 	{
   156 		icon->setVisibility (false);
   157 		calcBBoxSize();
   158 	}	
   159 }
   160 
   161 void FlagObj::setEnabled(bool b)
   162 {
   163 	button->setEnabled (b);
   164 }	
   165 	
   166 
   167 void FlagObj::setUsed (bool b)
   168 {
   169 	used=b;
   170 }
   171 
   172 bool FlagObj::isUsed()
   173 {
   174 	return used;
   175 }
   176 
   177 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   178 {
   179 	QString fn=tmpdir + prefix + name + ".png";
   180 	icon->save (fn,"PNG");
   181 }
   182 
   183 void FlagObj::positionBBox()
   184 {
   185     bbox.setX (absPos.x() );
   186     bbox.setY (absPos.y() );
   187 }
   188 
   189 void FlagObj::calcBBoxSize()
   190 {
   191 	if (visible && state)
   192 	{
   193 		bbox.setSize (	QSize(
   194 			icon->boundingRect().width(), 
   195 			icon->boundingRect().height() ) );
   196 	} else
   197 	{
   198 		bbox.setSize (QSize(0,0));
   199 	}
   200 }
   201