flagobj.cpp
author insilmaril
Thu, 23 Feb 2006 08:37:39 +0000
changeset 218 160459d924a1
parent 172 fbb8c8560551
child 366 e95081c21da2
permissions -rw-r--r--
New translation: Italian. Minor Improvements in mmap Import
     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  canvas="<<c<<endl;
    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 	if (icon) delete (icon);
    27 }
    28 
    29 
    30 void FlagObj::init ()
    31 {
    32 	name="undefined";
    33 	group="undefined";
    34 
    35 	icon=new ImageObj (canvas);
    36 	icon->move (absPos.x(), absPos.y() );
    37 	button=NULL;
    38 	state=false;
    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 	setVisibility (other->isVisibleObj() );
    50 	// button is not copied, because
    51 	// we won't copy to a parentRow and
    52 	// all others don't need a button
    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 void FlagObj::setButton(QAction* b)
   121 {
   122     button=b;
   123 }
   124 
   125 void FlagObj::updateButton()
   126 {
   127 	if (button)
   128 		button->setOn(state);
   129 	else
   130 		qWarning ("FlagObj::updateButton  no button defined");
   131 }
   132 
   133 QPixmap FlagObj::getPixmap()
   134 {
   135 	return icon->getPixmap();
   136 }
   137 
   138 bool FlagObj::isActive()
   139 {
   140 	return state;
   141 }
   142 
   143 void FlagObj::toggle()
   144 {
   145 	if (state)
   146 		deactivate();
   147 	else
   148 		activate();
   149 }
   150 
   151 void FlagObj::activate()
   152 {
   153 	state=true;
   154 	// only show icon, if flag itself is visible 
   155 	if (visible) 
   156 	{
   157 		icon->setVisibility (true);
   158 		calcBBoxSize();
   159 	}	
   160 }
   161 
   162 void FlagObj::deactivate()
   163 {
   164 	state=false;
   165 	// if flag itself is invisible we don't need to call 
   166 	if (visible) 
   167 	{
   168 		icon->setVisibility (false);
   169 		calcBBoxSize();
   170 	}	
   171 }
   172 
   173 void FlagObj::setEnabled(bool b)
   174 {
   175 	button->setEnabled (b);
   176 }	
   177 	
   178 
   179 void FlagObj::setUsed (bool b)
   180 {
   181 	used=b;
   182 }
   183 
   184 bool FlagObj::isUsed()
   185 {
   186 	return used;
   187 }
   188 
   189 void FlagObj::saveToDir (const QString &tmpdir, const QString &prefix)
   190 {
   191 	QString fn=tmpdir + prefix + name + ".png";
   192 	icon->save (fn,"PNG");
   193 }
   194 
   195 void FlagObj::positionBBox()
   196 {
   197     bbox.moveTopLeft (absPos );
   198     clickBox.moveTopLeft (absPos );
   199 }
   200 
   201 void FlagObj::calcBBoxSize()
   202 {
   203 	if (visible && state)
   204 	{
   205 		bbox.setSize (	QSize(
   206 			icon->boundingRect().width(), 
   207 			icon->boundingRect().height() ) );
   208 	} else
   209 	{
   210 		bbox.setSize (QSize(0,0));
   211 	}
   212 	clickBox.setSize (bbox.size());
   213 }
   214