mapeditor.cpp
changeset 417 1cc7bbf75f0b
parent 412 8059b6aa74d7
child 420 b7447adddc9a
     1.1 --- a/mapeditor.cpp	Fri Dec 29 13:52:19 2006 +0000
     1.2 +++ b/mapeditor.cpp	Fri Jan 05 11:17:32 2007 +0000
     1.3 @@ -62,7 +62,6 @@
     1.4  	//cout << "Constructor ME "<<this<<endl;
     1.5  	mapNum++;
     1.6  
     1.7 -    viewport()->setAcceptDrops(true);
     1.8  
     1.9  	mapScene= new QGraphicsScene(parent);
    1.10  	//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
    1.11 @@ -134,8 +133,7 @@
    1.12  	// Create temporary files
    1.13  	makeTmpDirs();
    1.14  
    1.15 -	// Initially set movingCentre
    1.16 -	updateViewCenter();
    1.17 +	setAcceptDrops (true);	
    1.18  
    1.19  	mapCenter->reposition();	//	for positioning heading
    1.20  
    1.21 @@ -522,20 +520,6 @@
    1.22  				addMapInsertInt(t,y);	
    1.23  			}
    1.24  		}
    1.25 -	} else if (com=="colorItem")
    1.26 -	{
    1.27 -		if (!selection)
    1.28 -		{
    1.29 -			api.setError (Aborted,"Nothing selected");
    1.30 -		} else if ( typeid(*selection) != typeid(BranchObj) && 
    1.31 -					typeid(*selection) != typeid(MapCenterObj))
    1.32 -		{				  
    1.33 -			api.setError (Aborted,"Type of selection is not a branch");
    1.34 -		} else if (api.checkParamCount(1))
    1.35 -		{	
    1.36 -			QColor c=api.parColor (ok,0);
    1.37 -			if (ok) colorItem (c);
    1.38 -		}	
    1.39  	} else if (com=="colorBranch")
    1.40  	{
    1.41  		if (!selection)
    1.42 @@ -550,6 +534,20 @@
    1.43  			QColor c=api.parColor (ok,0);
    1.44  			if (ok) colorBranch (c);
    1.45  		}	
    1.46 +	} else if (com=="colorSubtree")
    1.47 +	{
    1.48 +		if (!selection)
    1.49 +		{
    1.50 +			api.setError (Aborted,"Nothing selected");
    1.51 +		} else if ( typeid(*selection) != typeid(BranchObj) && 
    1.52 +					typeid(*selection) != typeid(MapCenterObj))
    1.53 +		{				  
    1.54 +			api.setError (Aborted,"Type of selection is not a branch");
    1.55 +		} else if (api.checkParamCount(1))
    1.56 +		{	
    1.57 +			QColor c=api.parColor (ok,0);
    1.58 +			if (ok) colorSubtree (c);
    1.59 +		}	
    1.60  	} else if (com=="cut")
    1.61  	{
    1.62  		if (!selection)
    1.63 @@ -1126,7 +1124,6 @@
    1.64  	{
    1.65  		QPainter pp(printer);
    1.66  
    1.67 -		//pp.setRenderHints(renderHints());
    1.68  		pp.setRenderHint(QPainter::Antialiasing,true);
    1.69  
    1.70  		// Don't print the visualisation of selection
    1.71 @@ -1140,79 +1137,49 @@
    1.72  		QRectF mapRect=totalBBox;
    1.73  		QGraphicsRectItem *frame=NULL;
    1.74  
    1.75 -		if (printFrame || printFooter)
    1.76 +		if (printFrame) 
    1.77  		{
    1.78 -			
    1.79 -			if (printFrame) 
    1.80 -			{
    1.81 -				// Print frame around map
    1.82 -				mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
    1.83 -					totalBBox.width()+20, totalBBox.height()+20);
    1.84 -				frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
    1.85 -				frame->setZValue(0);
    1.86 -				frame->show();    
    1.87 -			}		
    1.88 -
    1.89 -			if (printFooter) 
    1.90 -			{
    1.91 -				// Print footer below map
    1.92 -				QFont font;		
    1.93 -				font.setPointSize(10);
    1.94 -				pp.setFont (font);
    1.95 -				QRectF footerBox(0,printer->height()-15,printer->width(),15);
    1.96 -				pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
    1.97 -				pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
    1.98 -			}
    1.99 -		}
   1.100 -
   1.101 -		/*
   1.102 +			// Print frame around map
   1.103 +			mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
   1.104 +				totalBBox.width()+20, totalBBox.height()+20);
   1.105 +			frame=mapScene->addRect (mapRect, QPen(Qt::black),QBrush(Qt::NoBrush));
   1.106 +			frame->setZValue(0);
   1.107 +			frame->show();    
   1.108 +		}		
   1.109 +
   1.110 +
   1.111  		double paperAspect = (double)printer->width()   / (double)printer->height();
   1.112  		double   mapAspect = (double)mapRect.width() / (double)mapRect.height();
   1.113 -		cout <<"mapAspect="<<mapAspect<<"   paperAspect"<<paperAspect<<endl;
   1.114 +		int viewBottom;
   1.115  		if (mapAspect>=paperAspect)
   1.116  		{
   1.117  			// Fit horizontally to paper width
   1.118 -			pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
   1.119 -			qWarning ("Fit hor");
   1.120 +			//pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
   1.121 +			viewBottom=(int)(printer->width()/mapAspect);	
   1.122  		}	else
   1.123  		{
   1.124  			// Fit vertically to paper height
   1.125 -			pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
   1.126 -			qWarning ("Fit ver");
   1.127 +			//pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
   1.128 +			viewBottom=printer->height();	
   1.129  		}	
   1.130 -		*/
   1.131 +		
   1.132 +		if (printFooter) 
   1.133 +		{
   1.134 +			// Print footer below map
   1.135 +			QFont font;		
   1.136 +			font.setPointSize(10);
   1.137 +			pp.setFont (font);
   1.138 +			QRectF footerBox(0,viewBottom,printer->width(),15);
   1.139 +			pp.drawText ( footerBox,Qt::AlignLeft,"VYM - " +fileName);
   1.140 +			pp.drawText ( footerBox, Qt::AlignRight, QDate::currentDate().toString(Qt::TextDate));
   1.141 +		}
   1.142  		mapScene->render (
   1.143  			&pp, 
   1.144 -			//pp.viewport(),
   1.145  			QRectF (0,0,printer->width(),printer->height()-15),
   1.146  			QRectF(mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height())
   1.147  		);
   1.148  		
   1.149 -		//render (&pp,printer->pageRect(), QRect ((int)mapRect.x(),(int)mapRect.y(),400,400));
   1.150 -
   1.151 -		//pp.setWindow (QRect (mapRect.x(),mapRect.y(),mapRect.width(),mapRect.height()));
   1.152 -		//mapScene->render(&pp);	// draw scene to printer
   1.153 -
   1.154  		// Viewport has paper dimension
   1.155 -		pp.drawLine (QLine (0,0,printer->width(),printer->height()));
   1.156 -		cout << "sceneRect: "
   1.157 -			<<mapScene->sceneRect().x()<<","
   1.158 -			<<mapScene->sceneRect().y()<<","
   1.159 -			<<mapScene->sceneRect().width()<<","
   1.160 -			<<mapScene->sceneRect().height()<<","<<endl;
   1.161 -		cout << "mapRect: "
   1.162 -			<<mapRect.x()<<","
   1.163 -			<<mapRect.y()<<","
   1.164 -			<<mapRect.width()<<","
   1.165 -			<<mapRect.height()<<","<<endl;
   1.166 -		cout << "pp.viewport: "
   1.167 -			<<pp.viewport().x()<<","
   1.168 -			<<pp.viewport().y()<<","
   1.169 -			<<pp.viewport().width()<<","
   1.170 -			<<pp.viewport().height()<<","<<endl;
   1.171 -		cout << "painter: w,h="<<pp.viewport().width()<<","<<pp.viewport().height()<<endl;
   1.172 -		cout << "printer: w,h="<<printer->width()<<","<<printer->height()<<endl;
   1.173 -
   1.174  		if (frame)  delete (frame);
   1.175  
   1.176  		// Restore selection
   1.177 @@ -1243,7 +1210,7 @@
   1.178  {
   1.179  /* FIXME getPixmap not ported yet to QT4
   1.180  	QRectF mapRect=mapCenter->getTotalBBox();
   1.181 -	QPixmap pix (mapRect.size());
   1.182 +	QPixmap pix ();
   1.183  	QPainter pp (&pix);
   1.184  
   1.185  	// Don't print the visualisation of selection
   1.186 @@ -1256,7 +1223,9 @@
   1.187  
   1.188  	pp.setWindow (mapRect);
   1.189  
   1.190 -	mapScene->drawArea(mapRect, &pp);	// draw scene to painter
   1.191 +	//mapScene->drawArea(mapRect, &pp);	// draw scene to painter
   1.192 +	mapScene->render(&pp);	// draw scene to painter
   1.193 +
   1.194  
   1.195  
   1.196  	// Restore selection
   1.197 @@ -1268,7 +1237,6 @@
   1.198  	
   1.199  	return pix;
   1.200  */
   1.201 -return QPixmap();
   1.202  }
   1.203  
   1.204  void MapEditor::setHideTmpMode (HideTmpMode mode)
   1.205 @@ -1885,7 +1853,7 @@
   1.206  		if (newbo)
   1.207  		{
   1.208  			saveState(
   1.209 -				selection,		// FIXME addNewBranch (int pos) sholdnt newbo be deleted here???
   1.210 +				newbo,		
   1.211  				"delete ()",
   1.212  				selection,
   1.213  				QString ("addBranch (%1)").arg(pos-2),
   1.214 @@ -2449,7 +2417,7 @@
   1.215  	return Qt::black;
   1.216  }
   1.217  
   1.218 -void MapEditor::colorItem(QColor c) 
   1.219 +void MapEditor::colorBranch (QColor c)
   1.220  {
   1.221  	if (selection) 
   1.222  	{
   1.223 @@ -2459,9 +2427,9 @@
   1.224  			BranchObj *bo=(BranchObj*)selection;
   1.225  			saveState(
   1.226  				selection, 
   1.227 -				QString ("colorItem (%1)").arg(bo->getColor().name()),
   1.228 +				QString ("colorBranch (%1)").arg(bo->getColor().name()),
   1.229  				selection,
   1.230 -				QString ("colorItem (%1)").arg(c.name()),
   1.231 +				QString ("colorBranch (%1)").arg(c.name()),
   1.232  				QString("Set color of %1 to %2").arg(getName(bo)).arg(c.name())
   1.233  			);	
   1.234  			bo->setColor(c); // color branch
   1.235 @@ -2469,7 +2437,7 @@
   1.236  	}
   1.237  }
   1.238  
   1.239 -void MapEditor::colorBranch(QColor c)
   1.240 +void MapEditor::colorSubtree (QColor c)
   1.241  {
   1.242  	if (selection) 
   1.243  	{
   1.244 @@ -2480,10 +2448,10 @@
   1.245  			saveStateChangingPart(
   1.246  				selection, 
   1.247  				selection,
   1.248 -				QString ("colorBranch (%1)").arg(c.name()),
   1.249 +				QString ("colorSubtree (%1)").arg(c.name()),
   1.250  				QString ("Set color of %1 and childs to %2").arg(getName(bo)).arg(c.name())
   1.251  			);	
   1.252 -			bo->setColorChilds(c); // color links, color childs
   1.253 +			bo->setColorSubtree (c); // color links, color childs
   1.254  		}    
   1.255  	}
   1.256  }
   1.257 @@ -2519,14 +2487,6 @@
   1.258  	}	
   1.259  }
   1.260  
   1.261 -void MapEditor::setViewCenter()
   1.262 -{
   1.263 -	// transform to sceneView Coord:
   1.264 -	QPointF p=matrix().map(movingCenter);
   1.265 -	//FIXME setViewCenter not ported yet to QT4 (center ist TextStream there)
   1.266 -	//center ( p.x(), p.y());
   1.267 -}
   1.268 -
   1.269  
   1.270  BranchObj* MapEditor::findText (QString s, bool cs)
   1.271  {
   1.272 @@ -3393,18 +3353,6 @@
   1.273  
   1.274  }
   1.275  
   1.276 -void MapEditor::updateViewCenter()
   1.277 -{
   1.278 -/* FIXME updateViewCenter still to port to QT4 inverseworldmatrix
   1.279 -	// Update movingCenter, so that we can zoom comfortably later
   1.280 -	QRectF rc = QRectF( contentsX(), contentsY(),
   1.281 -				  visibleWidth(), visibleHeight() );
   1.282 -	QRectF canvasRect = inverseWorldMatrix().mapRect(rc);
   1.283 -	movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
   1.284 -	movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
   1.285 -	*/
   1.286 -}
   1.287 -
   1.288  void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
   1.289  {
   1.290  	// Lineedits are already closed by preceding
   1.291 @@ -3751,15 +3699,9 @@
   1.292  		if (dst && selection) 
   1.293  		{	
   1.294  			if (e->state() & Qt::ShiftModifier)
   1.295 -			{
   1.296 -				((BranchObj*)selection)->setColor (((BranchObj*)(dst))->getColor());
   1.297 -				((BranchObj*)selection)->setLinkColor ();
   1.298 -			}	
   1.299 +				colorBranch (((BranchObj*)(dst))->getColor());
   1.300  			else	
   1.301 -			{
   1.302 -				((BranchObj*)selection)->setColorChilds (((BranchObj*)(dst))->getColor());
   1.303 -				((BranchObj*)selection)->setLinkColor ();
   1.304 -			}	
   1.305 +				colorSubtree (((BranchObj*)(dst))->getColor());
   1.306  		} 
   1.307  		return;
   1.308  	}
   1.309 @@ -3921,48 +3863,81 @@
   1.310  
   1.311  void MapEditor::dragEnterEvent(QDragEnterEvent *event)
   1.312  {
   1.313 -  for (unsigned int i=0;event->format(i);i++) // Debug mime type
   1.314 -    cerr << event->format(i) << endl;
   1.315 -
   1.316 -	if (event->mimeData()->hasFormat("image/png"))
   1.317 -	event->acceptProposedAction();
   1.318 +	//for (unsigned int i=0;event->format(i);i++) // Debug mime type
   1.319 +	//	cerr << event->format(i) << endl;
   1.320 +
   1.321 +	if (event->mimeData()->hasImage())
   1.322 +		event->acceptProposedAction();
   1.323 +	else	
   1.324 +		if (event->mimeData()->hasUrls())
   1.325 +			event->acceptProposedAction();
   1.326 +}
   1.327 +
   1.328 +void MapEditor::dragMoveEvent(QDragMoveEvent *event)
   1.329 +{
   1.330 +}
   1.331 +
   1.332 +void MapEditor::dragLeaveEvent(QDragLeaveEvent *event)
   1.333 +{
   1.334 +	event->accept();
   1.335  }
   1.336  
   1.337  void MapEditor::dropEvent(QDropEvent *event)
   1.338  {
   1.339 -	if (event->mimeData()->hasFormat("image/png"))
   1.340 -}
   1.341 -
   1.342 -void MapEditor::contentsDropEvent(QDropEvent *event) 
   1.343 -{
   1.344 -	//FIXME dropEvent not ported to QT4 yet
   1.345  	if (selection && 
   1.346        (typeid(*selection) == typeid(BranchObj)) || 
   1.347        (typeid(*selection) == typeid(MapCenterObj))) 
   1.348  	{
   1.349 -		bool update=false;
   1.350 -		QStringList uris;
   1.351 -		QString heading;
   1.352 -
   1.353 -
   1.354 -		if (event->mimeData()->hasFormat("image/png"))
   1.355 +		QList <QUrl> uris;
   1.356 +		if (event->mimeData()->hasImage()) 
   1.357  		{
   1.358 -            event->acceptProposedAction();
   1.359 -			addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
   1.360 -			cout << "accepted drop\n";
   1.361 -		}	
   1.362 -
   1.363 -		/*
   1.364 -		if (event->provides("image/png")) 
   1.365 +			 QVariant imageData = event->mimeData()->imageData();
   1.366 +			 addFloatImageInt (qvariant_cast<QPixmap>(imageData));
   1.367 +		} else
   1.368 +		if (event->mimeData()->hasUrls())
   1.369 +			uris=event->mimeData()->urls();
   1.370 +
   1.371 +		if (uris.count()>0)
   1.372  		{
   1.373 -			QPixmap pix;
   1.374 -			if (Q3ImageDrag::decode(event, pix)) 
   1.375 +			QStringList files;
   1.376 +			QString s;
   1.377 +			QString heading;
   1.378 +			BranchObj *bo;
   1.379 +			for (int i=0; i<uris.count();++i)
   1.380  			{
   1.381 -				addFloatImageInt(pix);
   1.382 -				event->accept();
   1.383 -				update=true;
   1.384 -			} else
   1.385 -				event->ignore();
   1.386 +				bo=((BranchObj*)selection)->addBranch();
   1.387 +				if (bo)
   1.388 +				{
   1.389 +					s=uris.at(i).toLocalFile();
   1.390 +					if (!s.isEmpty()) 
   1.391 +					{
   1.392 +                       QString file = QDir::convertSeparators(s);
   1.393 +                       heading = QFileInfo(file).baseName();
   1.394 +                       files.append(file);
   1.395 +                       if (file.endsWith(".vym", false))
   1.396 +                           bo->setVymLink(file);
   1.397 +                       else
   1.398 +                           bo->setURL(uris.at(i).toString());
   1.399 +                   } else 
   1.400 +				   {
   1.401 +                       bo->setURL(uris.at(i).toString());
   1.402 +                   }
   1.403 +
   1.404 +                   if (!heading.isEmpty())
   1.405 +                       bo->setHeading(heading);
   1.406 +                   else
   1.407 +                       bo->setHeading(uris.at(i).toString());
   1.408 +				}
   1.409 +			}
   1.410 +		mapCenter->reposition();
   1.411 +		}
   1.412 +	}	
   1.413 +	event->acceptProposedAction();
   1.414 +}
   1.415 +
   1.416 +/*
   1.417 +void MapEditor::contentsDropEvent(QDropEvent *event) 
   1.418 +{
   1.419  
   1.420  		} else if (event->provides("application/x-moz-file-promise-url") && 
   1.421  			 event->provides("application/x-moz-nativeimage")) 
   1.422 @@ -4009,101 +3984,10 @@
   1.423  		  event->accept();
   1.424  		  update= true;
   1.425  		}
   1.426 +
   1.427  		*/
   1.428  
   1.429 -		/* not ported yet  QSTRINGLIST has no next... 
   1.430 -		if (uris.count()>0)
   1.431 -		{
   1.432 -			QStringList files;
   1.433 -			QStringList urls;
   1.434 -			QString s;
   1.435 -			BranchObj *bo;
   1.436 -			for (const char* u=uris.first(); u; u=uris.next())
   1.437 -			{
   1.438 -				bo=((BranchObj*)selection)->addBranch();
   1.439 -				if (bo)
   1.440 -				{
   1.441 -					s=Q3UriDrag::uriToLocalFile(u);
   1.442 -					if (!s.isEmpty()) 
   1.443 -					{
   1.444 -                       QString file = QDir::convertSeparators(s);
   1.445 -                       heading = QFileInfo(file).baseName();
   1.446 -                       files.append(file);
   1.447 -                       if (file.endsWith(".vym", false))
   1.448 -                           bo->setVymLink(file);
   1.449 -                       else
   1.450 -                           bo->setURL(u);
   1.451 -                   } else 
   1.452 -				   {
   1.453 -                       urls.append (u);
   1.454 -                       bo->setURL(u);
   1.455 -                   }
   1.456 -
   1.457 -                   if (!heading.isEmpty())
   1.458 -                       bo->setHeading(heading);
   1.459 -                   else
   1.460 -                       bo->setHeading(u);
   1.461 -				}
   1.462 -			}
   1.463 -			update=true;
   1.464 -		}
   1.465 -		*/
   1.466 -		if (update) 
   1.467 -		{
   1.468 -			//FIXME dropEvent: saveState has to be called earlier for each of the drops...
   1.469 -			//saveStateComplete("Drop Event");	//TODO undo Command
   1.470 -			mapCenter->reposition();
   1.471 -			scene()->update();
   1.472 -		}	
   1.473 -	}	
   1.474 -}
   1.475 -
   1.476 -
   1.477 -void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) 
   1.478 -{
   1.479 -	//FIXME contentsDragEnterEvent not ported to QT4 yet
   1.480 -
   1.481 -//  for (unsigned int i=0;event->format(i);i++) // Debug mime type
   1.482 -//    cerr << event->format(i) << endl;
   1.483 -
   1.484 -  if (selection && 
   1.485 -      (typeid(*selection) == typeid(BranchObj)) || 
   1.486 -      (typeid(*selection) == typeid(MapCenterObj))) {
   1.487 -    
   1.488 -    // If QImageDrag can decode mime type 
   1.489 -    if (Q3ImageDrag::canDecode(event)) {
   1.490 -      event->accept();
   1.491 -      return;
   1.492 -    }
   1.493 -    
   1.494 -    // If image are dragged from firefox 
   1.495 -    if (event->provides("application/x-moz-file-promise-url") && 
   1.496 -	event->provides("application/x-moz-nativeimage")) {
   1.497 -      event->accept(true);
   1.498 -      return;
   1.499 -    }
   1.500 -
   1.501 -    // If QUriDrag can decode mime type 
   1.502 -    if (Q3UriDrag::canDecode(event)) {
   1.503 -      event->accept();
   1.504 -      return;
   1.505 -    }
   1.506 -    
   1.507 -	// If Uri are dragged from firefox 
   1.508 -    if (event->provides("_NETSCAPE_URL")){
   1.509 -      event->accept();
   1.510 -      return;
   1.511 -    }
   1.512 -
   1.513 -    // If QTextDrag can decode mime type
   1.514 -    if (Q3TextDrag::canDecode(event)) {
   1.515 -      event->accept();
   1.516 -      return;
   1.517 -    }
   1.518 -
   1.519 -  }
   1.520 -  event->ignore();
   1.521 -}
   1.522 +
   1.523  
   1.524  bool isUnicode16(const QByteArray &d) 
   1.525  {