flagobj.cpp
author insilmaril
Tue, 06 Jun 2006 14:58:11 +0000
branchqt4-port
changeset 2 608f976aa7bb
parent 0 7a96bd401351
child 3 6a0342b3c519
permissions -rw-r--r--
First compilation on QT4
     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 	button=NULL;
    40 	state=false;
    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 	setVisibility (other->isVisibleObj() );
    52 	// button is not copied, because
    53 	// we won't copy to a parentRow and
    54 	// all others don't need a button
    55 }
    56 
    57 void FlagObj::move(double x, double y)
    58 {
    59     MapObj::move(x,y);
    60 	icon->move(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::setToolTip(const QString &n)
   113 {
   114 	tooltip=n;
   115 }
   116 
   117 const QString FlagObj::getToolTip()
   118 {
   119 	return tooltip;
   120 }
   121 
   122 void FlagObj::setButton(QAction* b)
   123 {
   124     button=b;
   125 }
   126 
   127 void FlagObj::updateButton()
   128 {
   129 	if (button)
   130 		button->setOn(state);
   131 	else
   132 		qWarning ("FlagObj::updateButton  no button defined");
   133 }
   134 
   135 QPixmap FlagObj::getPixmap()
   136 {
   137 	return icon->getPixmap();
   138 }
   139 
   140 bool FlagObj::isActive()
   141 {
   142 	return state;
   143 }
   144 
   145 void FlagObj::toggle()
   146 {
   147 	if (state)
   148 		deactivate();
   149 	else
   150 		activate();
   151 }
   152 
   153 void FlagObj::activate()
   154 {
   155 	state=true;
   156 	// only show icon, if flag itself is visible 
   157 	if (visible) 
   158 	{
   159 		icon->setVisibility (true);
   160 		calcBBoxSize();
   161 	}	
   162 }
   163 
   164 void FlagObj::deactivate()
   165 {
   166 	state=false;
   167 	// if flag itself is invisible we don't need to call 
   168 	if (visible) 
   169 	{
   170 		icon->setVisibility (false);
   171 		calcBBoxSize();
   172 	}	
   173 }
   174 
   175 void FlagObj::setEnabled(bool b)
   176 {
   177 	button->setEnabled (b);
   178 }	
   179 	
   180 
   181 void FlagObj::setUsed (bool b)
   182 {
   183 	used=b;
   184 }
   185 
   186 bool FlagObj::isUsed()
   187 {
   188 	return used;
   189 }
   190 
   191 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   192 {
   193 	QString fn=tmpdir + prefix + name + ".png";
   194 	icon->save (fn,"PNG");
   195 }
   196 
   197 void FlagObj::positionBBox()
   198 {
   199     bbox.moveTopLeft (absPos );
   200     clickBox.moveTopLeft (absPos );
   201 }
   202 
   203 void FlagObj::calcBBoxSize()
   204 {
   205 	if (visible && state)
   206 	{
   207 		bbox.setSize (	QSize(
   208 			icon->boundingRect().width(), 
   209 			icon->boundingRect().height() ) );
   210 	} else
   211 	{
   212 		bbox.setSize (QSize(0,0));
   213 	}
   214 	clickBox.setSize (bbox.size());
   215 }
   216