flagrowobj.cpp
branchqt4-port
changeset 2 608f976aa7bb
parent 0 7a96bd401351
child 3 6a0342b3c519
     1.1 --- a/flagrowobj.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.2 +++ b/flagrowobj.cpp	Tue Jun 06 14:58:11 2006 +0000
     1.3 @@ -5,11 +5,11 @@
     1.4  /////////////////////////////////////////////////////////////////
     1.5  FlagRowObj::FlagRowObj()
     1.6  {
     1.7 -    cout << "Const FlagRowObj ()\n";
     1.8 +//    cout << "Const FlagRowObj ()\n";
     1.9      init ();
    1.10  }
    1.11  
    1.12 -FlagRowObj::FlagRowObj(QCanvas* c):MapObj(c) 
    1.13 +FlagRowObj::FlagRowObj(Q3Canvas* c):MapObj(c) 
    1.14  {
    1.15  //    cout << "Const FlagRowObj\n";
    1.16      init ();
    1.17 @@ -25,6 +25,7 @@
    1.18  {
    1.19      flag.setAutoDelete (true);
    1.20  	parentRow=NULL;
    1.21 +	showFlags=true;
    1.22  }
    1.23  
    1.24  void FlagRowObj::copy (FlagRowObj* other)
    1.25 @@ -86,8 +87,8 @@
    1.26  
    1.27  void FlagRowObj::positionBBox()
    1.28  {
    1.29 -    bbox.setX (absPos.x() );
    1.30 -    bbox.setY (absPos.y() );
    1.31 +    bbox.moveTopLeft(absPos );
    1.32 +    clickBox.moveTopLeft(absPos );
    1.33  }
    1.34  
    1.35  void FlagRowObj::calcBBoxSize()
    1.36 @@ -104,15 +105,16 @@
    1.37  		if (size.height() > boxsize.height() ) 
    1.38  			boxsize.setHeight(size.height() );
    1.39  	}
    1.40 -	bbox.setSize (QSize(boxsize.width(), boxsize.height() ));
    1.41 +	bbox.setSize (boxsize);
    1.42 +	clickBox.setSize (boxsize);
    1.43  }
    1.44  
    1.45  QString FlagRowObj::getFlagName (const QPoint &p)
    1.46  {
    1.47 -	if (!inBBox (p)) return "";
    1.48 +	if (!inBox (p)) return "";
    1.49  	FlagObj *fo;
    1.50  	for (fo=flag.first();fo; fo=flag.next() )
    1.51 -		if (fo->inBBox (p)) return fo->getName();
    1.52 +		if (fo->inBox (p)) return fo->getName();
    1.53  	return "";	
    1.54  
    1.55  	
    1.56 @@ -121,19 +123,14 @@
    1.57  bool FlagRowObj::isActive (const QString &foname)
    1.58  {
    1.59  	FlagObj *fo=findFlag (foname);
    1.60 -	if (parentRow)
    1.61 -	{
    1.62 -		if (fo)
    1.63 -			return fo->isActive();
    1.64 -		else
    1.65 -			qWarning ("FlagRowObj::isActive of "+name+" couldn't find "+foname);
    1.66 -			
    1.67 -	} else
    1.68 +	if (parentRow && fo)
    1.69 +		return fo->isActive();
    1.70 +	else
    1.71  		if (fo) return true;
    1.72  	return false;
    1.73  }
    1.74  
    1.75 -void FlagRowObj::toggle (const QString &foname)
    1.76 +void FlagRowObj::toggle (const QString &foname, bool exclusive)
    1.77  {
    1.78  	FlagObj *fo=findFlag (foname);
    1.79  	if (fo)
    1.80 @@ -150,6 +147,11 @@
    1.81  		{
    1.82  			fo=addFlag (fo);
    1.83  			fo->activate();
    1.84 +			if (exclusive) 
    1.85 +			{
    1.86 +				deactivateGroup (fo);
    1.87 +				updateToolbar();
    1.88 +			}
    1.89  		} else
    1.90  			qWarning ("FlagRowObj ("+name+")::toggle ("+foname+")  failed - could not find it in parentRow");
    1.91  	}	
    1.92 @@ -159,6 +161,8 @@
    1.93  
    1.94  void FlagRowObj::activate (const QString &foname)
    1.95  {
    1.96 +	// Note: "activate" is also called during loading of a map
    1.97 +	// Here we do not check for exclusive flags!
    1.98  	FlagObj *fo=findFlag (foname);
    1.99  	if (parentRow)
   1.100  	{
   1.101 @@ -171,9 +175,11 @@
   1.102  			{
   1.103  				fo=addFlag (fo);
   1.104  				fo->activate();
   1.105 -				fo->setVisibility (visible);
   1.106 +				if (showFlags) 
   1.107 +					fo->setVisibility (visible);
   1.108 +				else
   1.109 +					fo->setVisibility (false);
   1.110  				calcBBoxSize();
   1.111 -				positionBBox();
   1.112  			} else
   1.113  				qWarning ("FlagRowObj ("+name+")::activate ("+foname+")  failed - could not find it in parentRow");
   1.114  		}	
   1.115 @@ -190,6 +196,7 @@
   1.116  	}
   1.117  }
   1.118  
   1.119 +
   1.120  void FlagRowObj::deactivate (const QString &foname)
   1.121  {
   1.122  	FlagObj *fo=findFlag (foname);
   1.123 @@ -204,13 +211,27 @@
   1.124  	{
   1.125  		FlagObj *fo;
   1.126  		for (fo=flag.first();fo; fo=flag.next() )
   1.127 -		{
   1.128  			fo->deactivate();
   1.129 -		}
   1.130  	} else
   1.131  		qWarning ("FlagRowObj::deactivateAll mustn't be called for ordinary rows");
   1.132  }
   1.133  
   1.134 +void FlagRowObj::deactivateGroup (FlagObj *keepfo)
   1.135 +{
   1.136 +	// deactivate all flags in keepof, but keep keepfo [sic!]
   1.137 +	if (keepfo)
   1.138 +	{
   1.139 +		QString g=keepfo->getGroup();
   1.140 +		if (g!="undefined")
   1.141 +		{
   1.142 +			FlagObj *fo;
   1.143 +			for (fo=flag.first();fo; fo=flag.next() )
   1.144 +				if (g==fo->getGroup() && keepfo!=fo) 
   1.145 +					flag.remove(fo);
   1.146 +		}		
   1.147 +	}	
   1.148 +}
   1.149 +
   1.150  void FlagRowObj::setEnabled (bool b)
   1.151  {
   1.152  	// If we have no parent, we are the default FlagRowObj
   1.153 @@ -223,6 +244,11 @@
   1.154  	}
   1.155  }
   1.156  
   1.157 +void FlagRowObj::setShowFlags (bool b)
   1.158 +{
   1.159 +	showFlags=b;
   1.160 +}
   1.161 +
   1.162  void FlagRowObj::resetUsedCounter()
   1.163  {
   1.164  	FlagObj *fo;
   1.165 @@ -260,26 +286,28 @@
   1.166  	name=n;
   1.167  }
   1.168  
   1.169 -void FlagRowObj::makeToolbar (QMainWindow *w, const QString &n)
   1.170 +void FlagRowObj::makeToolbar (Q3MainWindow *w, const QString &n)
   1.171  {
   1.172 +	//Only make toolbar for the parentrow, not each row in branches
   1.173  	if (!parentRow)
   1.174  	{
   1.175  		// create bar and buttons
   1.176 -		QToolBar* tb = new QToolBar( w);
   1.177 +		Q3ToolBar* tb = new Q3ToolBar( w);
   1.178  		tb->setLabel (n);
   1.179  		QAction *a;
   1.180  		FlagObj *fo;
   1.181  		for (fo=flag.first();fo; fo=flag.next() )
   1.182  		{
   1.183  			a=new QAction (
   1.184 -				fo->getToolTip(),
   1.185 +// FIXME was in QT3:				fo->getToolTip(),
   1.186  				fo->getPixmap(),
   1.187  				fo->getName(),
   1.188 -				0,
   1.189 -				w,
   1.190 -				fo->getName()
   1.191 +//				0,
   1.192 +				w
   1.193 +//				fo->getName()
   1.194  			);
   1.195  			a->setToggleAction(true);
   1.196 +//			a->setTooltip (fo->getToolTip());
   1.197  			// FIXME should not be enabled by default, later in updateToolbar
   1.198  			a->setEnabled(true);
   1.199  			a->addTo (tb);
   1.200 @@ -288,10 +316,10 @@
   1.201  					w, SLOT( standardFlagChanged() ) );
   1.202  		}
   1.203  	} else
   1.204 -		qWarning ("FlagRowObj::makeToolbar mustn't be called for ordinary rows");
   1.205 +		qWarning ("FlagRowObj::makeToolbar must not be called for ordinary rows");
   1.206  }
   1.207  
   1.208 -void  FlagRowObj::updateToolBar()
   1.209 +void  FlagRowObj::updateToolbar()
   1.210  {
   1.211  	FlagObj *fo;
   1.212  	if (parentRow)
   1.213 @@ -301,7 +329,7 @@
   1.214  		// In parentRow activate all existing (==active) flags
   1.215  		for (fo=flag.first();fo; fo=flag.next() ) 
   1.216  			parentRow->activate(fo->getName());
   1.217 -		parentRow->updateToolBar();	
   1.218 +		parentRow->updateToolbar();	
   1.219  	} else
   1.220  	{
   1.221  		// We are the toolbar default