ornamentedobj.cpp
branchqt4-port
changeset 10 e2a80d9b5858
parent 0 7a96bd401351
child 16 41c3d7f9f532
     1.1 --- a/ornamentedobj.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.2 +++ b/ornamentedobj.cpp	Thu Jul 06 15:39:54 2006 +0000
     1.3 @@ -18,7 +18,7 @@
     1.4      init ();
     1.5  }
     1.6  
     1.7 -OrnamentedObj::OrnamentedObj(QCanvas* c) :LinkableMapObj(c)
     1.8 +OrnamentedObj::OrnamentedObj(Q3Canvas* c) :LinkableMapObj(c)
     1.9  {
    1.10  //    cout << "Const OrnamentedObj\n";
    1.11      init ();
    1.12 @@ -54,20 +54,29 @@
    1.13  	standardFlags->clone(standardFlagsDefault);
    1.14  	standardFlags->setName ("standardFlags");
    1.15  
    1.16 +	hideExport=false;
    1.17 +	hidden=false;
    1.18  
    1.19 -
    1.20 +	url="";
    1.21 +	vymLink="";
    1.22 +	
    1.23  }
    1.24  
    1.25  void OrnamentedObj::copy (OrnamentedObj* other)
    1.26  {
    1.27      LinkableMapObj::copy(other);
    1.28  	heading->copy(other->heading);
    1.29 -    setColor   (other->heading->getColor(),false);	
    1.30 +    setColor   (other->heading->getColor());	
    1.31  
    1.32  	note.copy (other->note);
    1.33  	systemFlags->copy (other->systemFlags);
    1.34  	standardFlags->copy (other->standardFlags);
    1.35  
    1.36 +	ornamentsBBox=other->ornamentsBBox;
    1.37 +
    1.38 +	hideExport=other->hideExport;
    1.39 +	url=other->url;
    1.40 +	vymLink=other->vymLink;
    1.41  }
    1.42  
    1.43  QString OrnamentedObj::getHeading()
    1.44 @@ -83,27 +92,45 @@
    1.45  		LinkableMapObj::setLinkColor (mapEditor->getDefLinkColor());
    1.46  }
    1.47  
    1.48 +void OrnamentedObj::setColor (QColor col)
    1.49 +{
    1.50 +    heading->setColor(col);
    1.51 +	setLinkColor();
    1.52 +}
    1.53 +
    1.54  QColor OrnamentedObj::getColor ()
    1.55  {
    1.56      return heading->getColor();
    1.57  }
    1.58  
    1.59  
    1.60 +void OrnamentedObj::positionContents()
    1.61 +{
    1.62 +	double d=frame->getBorder()/2;
    1.63 +	double x=absPos.x();
    1.64 +	double y=absPos.y();
    1.65 +
    1.66 +	double ox,oy;	// Offset due to padding
    1.67 +
    1.68 +	ox=leftPad + d;
    1.69 +	oy=topPad + d;
    1.70 +	
    1.71 +	systemFlags-> move (ox +x , oy + y );
    1.72 +
    1.73 +	// vertical align heading to bottom
    1.74 +    heading->move (ox + x + systemFlags->getBBox().width(),
    1.75 +				   oy + y + ornamentsBBox.height() - heading->getHeight() 
    1.76 +					);
    1.77 +	standardFlags->move (ox +x + heading->getWidth() + systemFlags->getBBox().width() , oy + y );
    1.78 +
    1.79 +	ornamentsBBox.moveTopLeft ( QPoint ((int)(ox+x),(int)(oy+y)));
    1.80 +	clickBox.moveTopLeft (QPoint ((int)(ox + x), (int)(oy + y)));
    1.81 +}
    1.82 +
    1.83  void OrnamentedObj::move (double x, double y)
    1.84  {
    1.85  	MapObj::move (x,y);
    1.86 -	double dx=frame->getBorder()/2;  // care for border around object
    1.87 -	double dy=frame->getBorder()/2;
    1.88 -	systemFlags-> move (x + dx, y + dy);
    1.89 -
    1.90 -	// vertical align heading to bottom
    1.91 -	int h=max (systemFlags->getBBox().height(), standardFlags->getBBox().height());
    1.92 -	h=max (h,heading->getHeight());
    1.93 -    heading->move (x + dx + systemFlags->getBBox().width(),
    1.94 -					y + dy  + h - heading->getHeight() 
    1.95 -					);
    1.96 -	standardFlags->move (x + heading->getWidth() + systemFlags->getBBox().width(), y + dy );				
    1.97 -
    1.98 +	positionContents();
    1.99  	updateLink();
   1.100  	requestReposition();
   1.101  }
   1.102 @@ -138,8 +165,7 @@
   1.103  
   1.104  void OrnamentedObj::move2RelPos(QPoint p)
   1.105  {
   1.106 -	if (!parObj) return;
   1.107 -	move (parObj->getChildPos().x() + p.x(), parObj->getChildPos().y() + p.y() );
   1.108 +	move2RelPos (p.x(),p.y());
   1.109  }
   1.110  
   1.111  void OrnamentedObj::setNote(QString s)
   1.112 @@ -174,9 +200,72 @@
   1.113      return note.getNote();
   1.114  }
   1.115  
   1.116 -void OrnamentedObj::toggleStandardFlag(QString f)
   1.117 +QString OrnamentedObj::getNoteASCII()
   1.118  {
   1.119 -	standardFlags->toggle(f);
   1.120 +    return note.getNoteASCII();
   1.121 +}
   1.122 +
   1.123 +QString OrnamentedObj::getNoteOpenDoc()
   1.124 +{
   1.125 +    return note.getNoteOpenDoc();
   1.126 +}
   1.127 +
   1.128 +void OrnamentedObj::setURL(QString s)
   1.129 +{
   1.130 +	url=s;
   1.131 +	if (!url.isEmpty())
   1.132 +		systemFlags->activate("url");
   1.133 +	else	
   1.134 +		systemFlags->deactivate("url");
   1.135 +	calcBBoxSize();			// recalculate bbox
   1.136 +    positionBBox();			// rearrange contents
   1.137 +	forceReposition();
   1.138 +}
   1.139 +
   1.140 +QString OrnamentedObj::getURL()
   1.141 +{
   1.142 +	return url;
   1.143 +}
   1.144 +
   1.145 +void OrnamentedObj::setVymLink(QString s)
   1.146 +{
   1.147 +	if (!s.isEmpty())
   1.148 +	{
   1.149 +		// We need the relative (from loading) 
   1.150 +		// or absolute path (from User event)
   1.151 +		// and build the absolute path.
   1.152 +		// Note: If we have relative, use path of
   1.153 +		// current map to build absolute path
   1.154 +		QDir d(s);
   1.155 +		if (!d.path().startsWith ("/"))
   1.156 +		{
   1.157 +			QString p=mapEditor->getDestPath();
   1.158 +			int i=p.findRev("/",-1);
   1.159 +			d.setPath(p.left(i)+"/"+s);
   1.160 +			d.convertToAbs();
   1.161 +		}
   1.162 +		vymLink=d.path();
   1.163 +		systemFlags->activate("vymLink");
   1.164 +	}	
   1.165 +	else	
   1.166 +	{
   1.167 +		systemFlags->deactivate("vymLink");
   1.168 +		vymLink="";
   1.169 +	}	
   1.170 +	calcBBoxSize();			// recalculate bbox
   1.171 +    positionBBox();			// rearrange contents
   1.172 +	forceReposition();
   1.173 +}
   1.174 +
   1.175 +QString OrnamentedObj::getVymLink()
   1.176 +{
   1.177 +	return vymLink;
   1.178 +}
   1.179 +
   1.180 +
   1.181 +void OrnamentedObj::toggleStandardFlag(QString f, bool exclusive)
   1.182 +{
   1.183 +	standardFlags->toggle(f,exclusive);
   1.184  	calcBBoxSize();
   1.185  	positionBBox();
   1.186  	move (absPos.x(), absPos.y() );
   1.187 @@ -192,20 +281,93 @@
   1.188  	forceReposition();
   1.189  }
   1.190  
   1.191 +bool OrnamentedObj::isSetStandardFlag (QString f)
   1.192 +{
   1.193 +	return standardFlags->isActive(f);
   1.194 +}
   1.195 +
   1.196  QString OrnamentedObj::getSystemFlagName(const QPoint &p)
   1.197  {
   1.198  	return systemFlags->getFlagName(p);	
   1.199  }
   1.200  
   1.201 +bool OrnamentedObj::isActiveFlag (const QString & fname)
   1.202 +{
   1.203 +	if (standardFlags->isActive (fname) ) return true;
   1.204 +	return false;
   1.205 +}
   1.206 +
   1.207  void OrnamentedObj::updateNoteFlag()
   1.208  {
   1.209 -	// text in NoteEditor has changed, notify MapEditor 
   1.210 -	mapEditor->setChanged();
   1.211 +	if (selected) 
   1.212 +	{
   1.213 +		// text in NoteEditor has changed, notify MapEditor 
   1.214 +		mapEditor->setChanged();
   1.215  
   1.216 -	// save text
   1.217 -	setNote( textEditor->getText() );
   1.218 +		// save text
   1.219 +		setNote( textEditor->getText() );
   1.220  	
   1.221 -	// save font   
   1.222 -	note.setFontHint (textEditor->getFontHint() );
   1.223 +		// save font   
   1.224 +		note.setFontHint (textEditor->getFontHint() );
   1.225 +	}	
   1.226  }
   1.227  
   1.228 +void OrnamentedObj::setHideInExport(bool b)
   1.229 +{
   1.230 +	if (parObj)
   1.231 +	{
   1.232 +		// Don't allow to MapCenter to be hidden
   1.233 +		hideExport=b;
   1.234 +		if (b)
   1.235 +			systemFlags->activate("hideInExport");
   1.236 +		else	
   1.237 +			systemFlags->deactivate("hideInExport");
   1.238 +		calcBBoxSize();
   1.239 +		positionBBox();
   1.240 +		requestReposition();	
   1.241 +	}
   1.242 +}	
   1.243 +
   1.244 +bool OrnamentedObj::hideInExport()
   1.245 +{
   1.246 +	return hideExport;
   1.247 +}	
   1.248 +
   1.249 +bool OrnamentedObj::isHidden()
   1.250 +{
   1.251 +	return hidden;
   1.252 +}	
   1.253 +
   1.254 +QString OrnamentedObj::getOrnAttr()
   1.255 +{
   1.256 +	QString posAttr;
   1.257 +
   1.258 +	if (useRelPos)
   1.259 +		posAttr=attribut("relPosX",QString().setNum(relPos.x(),10)) +
   1.260 +                attribut("relPosY",QString().setNum(relPos.y(),10)); 
   1.261 +	else
   1.262 +	{
   1.263 +		if (depth==0 || depth==1) posAttr=
   1.264 +			attribut("absPosX",QString().setNum(absPos.x(),10)) +
   1.265 +			attribut("absPosY",QString().setNum(absPos.y(),10)); 
   1.266 +		else
   1.267 +			posAttr="";
   1.268 +	}	
   1.269 +
   1.270 +	QString urlAttr;
   1.271 +	if (!url.isEmpty())
   1.272 +		urlAttr=attribut ("url",url);
   1.273 +
   1.274 +	QString vymLinkAttr;
   1.275 +	if (!vymLink.isEmpty())
   1.276 +		vymLinkAttr=attribut ("vymLink",convertToRel(mapEditor->getDestPath(),vymLink) );
   1.277 +
   1.278 +	QString hideExpAttr;
   1.279 +	if (hideExport)
   1.280 +		hideExpAttr= attribut("hideInExport","true");
   1.281 +	else	
   1.282 +		hideExpAttr="";
   1.283 +
   1.284 +	return posAttr +urlAttr +vymLinkAttr +getLinkAttr() +hideExpAttr;
   1.285 +}
   1.286 +