mapeditor.cpp
changeset 408 c2a05fa925a1
parent 407 5db8dfd30ea2
child 411 910ba9fab728
     1.1 --- a/mapeditor.cpp	Thu Nov 23 16:18:26 2006 +0000
     1.2 +++ b/mapeditor.cpp	Fri Dec 08 20:18:56 2006 +0000
     1.3 @@ -1,5 +1,9 @@
     1.4  #include "mapeditor.h"
     1.5  
     1.6 +#include <q3dragobject.h>
     1.7 +#include <q3urloperator.h>
     1.8 +#include <q3networkprotocol.h>
     1.9 +#include <q3paintdevicemetrics.h>
    1.10  #include <q3filedialog.h>
    1.11  
    1.12  #include <iostream>
    1.13 @@ -53,30 +57,34 @@
    1.14  
    1.15  ///////////////////////////////////////////////////////////////////////
    1.16  ///////////////////////////////////////////////////////////////////////
    1.17 -MapEditor::MapEditor(
    1.18 -	QWidget* parent, const char* name, Qt::WFlags f) :
    1.19 -  Q3CanvasView(parent,name,f), urlOperator(0), imageBuffer(0)
    1.20 +MapEditor::MapEditor( QWidget* parent) :
    1.21 +  QGraphicsView(parent), urlOperator(0), imageBuffer(0)
    1.22  {
    1.23  	//cout << "Constructor ME "<<this<<endl;
    1.24  	mapNum++;
    1.25  
    1.26      viewport()->setAcceptDrops(true);
    1.27  
    1.28 -    mapCanvas = new Q3Canvas(width(),height());
    1.29 -	mapCanvas->setAdvancePeriod(30);
    1.30 -	mapCanvas->setBackgroundColor (Qt::white);
    1.31 -
    1.32 -    setCanvas (mapCanvas);
    1.33 +	mapScene= new QGraphicsScene(parent);
    1.34 +	//mapScene= new QGraphicsScene(QRectF(0,0,width(),height()), parent);
    1.35 +	mapScene->setBackgroundBrush (QBrush(Qt::white, Qt::SolidPattern));
    1.36 +
    1.37 +
    1.38 +    setScene (mapScene);
    1.39  	
    1.40 +    /* FIXME not needed in QT4? 
    1.41 +	// Maybe check QAbstractScrollArea...
    1.42  	// Always show scroll bars (automatic would flicker sometimes)
    1.43 -	setVScrollBarMode ( Q3ScrollView::AlwaysOn );
    1.44 -	setHScrollBarMode ( Q3ScrollView::AlwaysOn );
    1.45 -
    1.46 -    mapCenter = new MapCenterObj(mapCanvas);
    1.47 +	setVScrollBarMode ( QScrollView::AlwaysOn );
    1.48 +	setHScrollBarMode ( QScrollView::AlwaysOn );
    1.49 +	*/
    1.50 +
    1.51 +    mapCenter = new MapCenterObj(mapScene);
    1.52      mapCenter->setVisibility (true);
    1.53  	mapCenter->setMapEditor (this);
    1.54  	mapCenter->setHeading (tr("New Map","Heading of mapcenter in new map"));
    1.55 -	mapCenter->move(mapCanvas->width()/2-mapCenter->width()/2,mapCanvas->height()/2-mapCenter->height()/2);
    1.56 +	//mapCenter->move(mapScene->width()/2-mapCenter->width()/2,mapScene->height()/2-mapCenter->height()/2);
    1.57 +	mapCenter->move(0,0);
    1.58  
    1.59      printer=NULL;
    1.60  
    1.61 @@ -157,60 +165,64 @@
    1.62      return mapCenter;
    1.63  }
    1.64  
    1.65 -Q3Canvas* MapEditor::getCanvas()
    1.66 +QGraphicsScene * MapEditor::getScene()
    1.67  {
    1.68 -    return mapCanvas;
    1.69 +    return mapScene;
    1.70  }
    1.71  
    1.72  void MapEditor::adjustCanvasSize()
    1.73  {
    1.74 -	// To adjust the canvas to map, viewport size and position, we have to
    1.75 +
    1.76 +/* FIXME QT4 probably not needed any longer!
    1.77 +
    1.78 +	// To adjust the scene to map, viewport size and position, we have to
    1.79  	// do some coordinate magic...
    1.80  	//
    1.81  	// Get rectangle of (scroll-)view. 
    1.82 -	// We want to be in canvas coords, so
    1.83 +	// We want to be in scene coords, so
    1.84  	// we map. Important if view is zoomed...
    1.85 -	QRect view = inverseWorldMatrix().mapRect( QRect( contentsX(), contentsY(),
    1.86 +	QRectF view = inverseWorldMatrix().mapRect( QRectF( contentsX(), contentsY(),
    1.87  												visibleWidth(), visibleHeight()) );	
    1.88  												
    1.89 -	// Now we need the bounding box of view AND map to calc the correct canvas size.
    1.90 +	// Now we need the bounding box of view AND map to calc the correct scene size.
    1.91  	// Why? Because if the map itself is moved out of view, the view has to be enlarged
    1.92  	// to avoid jumping aroung...
    1.93 -	QRect map=mapCenter->getTotalBBox();
    1.94 +	QRectF map=mapCenter->getTotalBBox();
    1.95  
    1.96  	// right edge - left edge
    1.97  	int cw= max(map.x() + map.width(),  view.x() + view.width())  - min(map.x(), view.x());
    1.98  	int ch= max(map.y() + map.height(), view.y() + view.height()) - min(map.y(), view.y());
    1.99  
   1.100  
   1.101 -	if ( (cw!=mapCanvas->width()) || (ch!=mapCanvas->height()) ||
   1.102 -		!mapCanvas->onCanvas (map.topLeft()) || !mapCanvas->onCanvas (map.bottomRight())
   1.103 +	if ( (cw!=mapScene->width()) || (ch!=mapScene->height()) ||
   1.104 +		!mapScene->onCanvas (map.topLeft()) || !mapScene->onCanvas (map.bottomRight())
   1.105  	)	
   1.106  	{	
   1.107 -		// move the map on canvas (in order to not move it on screen) this is neccessary
   1.108 -		// a) if topleft corner of canvas is left or above topleft corner of view and also left of
   1.109 +		// move the map on scene (in order to not move it on screen) this is neccessary
   1.110 +		// a) if topleft corner of scene is left or above topleft corner of view and also left of
   1.111  		//    above topleft corner of map. E.g. if map is completly inside view, but it would be possible 
   1.112 -		//    to scroll to an empty area of canvas to the left.
   1.113 -		// b) if topleft corner of map left of or above topleft of canvas
   1.114 +		//    to scroll to an empty area of scene to the left.
   1.115 +		// b) if topleft corner of map left of or above topleft of scene
   1.116  		int dx=0;
   1.117  		int dy=0;
   1.118  
   1.119 -		if (cw > mapCanvas->width() )
   1.120 +		if (cw > mapScene->width() )
   1.121  		{
   1.122  			if (map.x()<0) dx=-map.x();	
   1.123  		}
   1.124 -		if (cw <  mapCanvas->width() )
   1.125 +		if (cw <  mapScene->width() )
   1.126  			dx=-min (view.x(),map.x());
   1.127 -		if (ch > mapCanvas->height() )
   1.128 +		if (ch > mapScene->height() )
   1.129  		{
   1.130  			if (map.y()<0) dy=-map.y();	
   1.131  		}
   1.132 -		if (ch <  mapCanvas->height() )
   1.133 +		if (ch <  mapScene->height() )
   1.134  		{
   1.135  			dy=-min (view.y(),map.y());
   1.136  		}
   1.137  		// We really have to resize now. Let's go...
   1.138 -		mapCanvas->resize (cw,ch);
   1.139 +		// FIXME old code mapScene->resize (cw,ch);
   1.140 +		mapScene->setSceneRect (QRectFF(0,0,cw,ch));
   1.141  		if ( (dx!=0) || (dy!=0) ) 
   1.142  		{
   1.143  			mapCenter->moveAllBy(dx,dy);
   1.144 @@ -221,6 +233,8 @@
   1.145  			scrollBy (dx,dy);
   1.146  		}	
   1.147  	}
   1.148 +
   1.149 +	*/
   1.150  }
   1.151  
   1.152  bool MapEditor::isRepositionBlocked()
   1.153 @@ -257,12 +271,12 @@
   1.154  	d.mkdir (tmpMapDir);
   1.155  }
   1.156  
   1.157 -QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPoint &offset, LinkableMapObj *saveSel)
   1.158 +QString MapEditor::saveToDir(const QString &tmpdir, const QString &prefix, bool writeflags, const QPointF &offset, LinkableMapObj *saveSel)
   1.159  {
   1.160  	// tmpdir		temporary directory to which data will be written
   1.161  	// prefix		mapname, which will be appended to images etc.
   1.162  	// writeflags	Only write flags for "real" save of map, not undo
   1.163 -	// offset		offset of bbox of whole map in canvas. 
   1.164 +	// offset		offset of bbox of whole map in scene. 
   1.165  	//				Needed for XML export
   1.166  	
   1.167  	// Save Header
   1.168 @@ -293,7 +307,7 @@
   1.169  		mapAttr+= attribut("author",mapCenter->getAuthor()) +
   1.170  				  attribut("comment",mapCenter->getComment()) +
   1.171  			      attribut("date",mapCenter->getDate()) +
   1.172 -		          attribut("backgroundColor", mapCanvas->backgroundColor().name() ) +
   1.173 +		          attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
   1.174  		          attribut("linkStyle", ls ) +
   1.175  		          attribut("linkColor", defLinkColor.name() ) +
   1.176  		          attribut("defXLinkColor", defXLinkColor.name() ) +
   1.177 @@ -307,7 +321,7 @@
   1.178  	
   1.179  	// Reset the counters before saving
   1.180  	// TODO constr. of FIO creates lots of objects, better do this in some other way...
   1.181 -	FloatImageObj (mapCanvas).resetSaveCounter();
   1.182 +	FloatImageObj (mapScene).resetSaveCounter();
   1.183  
   1.184  	// Build xml recursivly
   1.185  	if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
   1.186 @@ -447,7 +461,7 @@
   1.187  
   1.188  	// Save depending on how much needs to be saved	
   1.189  	if (saveSel)
   1.190 -		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),saveSel);
   1.191 +		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPointF (),saveSel);
   1.192  		
   1.193  	QString undoCommand="";
   1.194  	if (savemode==UndoCommand)
   1.195 @@ -496,8 +510,8 @@
   1.196  	if (saveSel) cout << "    saveSel="<<saveSel->getSelectString().ascii()<<endl;
   1.197  	cout << "    ---------------------------"<<endl;
   1.198  
   1.199 +	mainWindow->updateHistory (undoSet);
   1.200  	setChanged();
   1.201 -	mainWindow->updateHistory (undoSet);
   1.202  	updateActions();
   1.203  }
   1.204  
   1.205 @@ -1136,9 +1150,9 @@
   1.206  
   1.207  	QString saveFile;
   1.208  	if (savemode==CompleteMap || selection==NULL)
   1.209 -		saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),NULL);
   1.210 +		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL);
   1.211  	else	
   1.212 -		saveFile=saveToDir (fileDir,mapName+"-",true,QPoint(),selection);
   1.213 +		saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection);
   1.214  
   1.215  	if (!saveStringToDisk(fileDir+fname,saveFile))
   1.216  		return 1;
   1.217 @@ -1172,7 +1186,7 @@
   1.218  		printer->setPrinterName (settings.value("/mainwindow/printerName",printer->printerName()).toString());
   1.219  	}
   1.220  
   1.221 -	QRect totalBBox=mapCenter->getTotalBBox();
   1.222 +	QRectF totalBBox=mapCenter->getTotalBBox();
   1.223  
   1.224  	// Try to set orientation automagically
   1.225  	// Note: Interpretation of generated postscript is amibiguous, if 
   1.226 @@ -1201,15 +1215,18 @@
   1.227  
   1.228  		// Handle sizes of map and paper:
   1.229  		//
   1.230 -		// setWindow defines which part of the canvas will be transformed 
   1.231 +		// setWindow defines which part of the scene will be transformed 
   1.232  		// setViewport defines area on paper in device coordinates (dpi)
   1.233  		// e.g. (0,50,700,700) is upper part on A4
   1.234  		// see also /usr/lib/qt3/doc/html/coordsys.html
   1.235  
   1.236 -		double paperAspect = (double)printer->width()   / (double)printer->height();
   1.237 +		Q3PaintDeviceMetrics metrics (printer);
   1.238 +
   1.239 +		double paperAspect = (double)metrics.width()   / (double)metrics.height();
   1.240  		double   mapAspect = (double)totalBBox.width() / (double)totalBBox.height();
   1.241  
   1.242 -		QRect mapRect=totalBBox;
   1.243 +		QRectF mapRect=totalBBox;
   1.244 +/* FIXME todo for QT4
   1.245  		Q3CanvasRectangle *frame=NULL;
   1.246  		Q3CanvasText *footerFN=NULL;
   1.247  		Q3CanvasText *footerDate=NULL;
   1.248 @@ -1221,32 +1238,31 @@
   1.249  				// Print frame around map
   1.250  				mapRect.setRect (totalBBox.x()-10, totalBBox.y()-10, 
   1.251  					totalBBox.width()+20, totalBBox.height()+20);
   1.252 -				frame=new Q3CanvasRectangle (mapRect,mapCanvas);
   1.253 +				frame=new Q3CanvasRectangle (mapRect,mapScene);
   1.254  				frame->setBrush (QColor(Qt::white));
   1.255  				frame->setPen (QColor(Qt::black));
   1.256  				frame->setZ(0);
   1.257  				frame->show();    
   1.258  			}		
   1.259 -			/* TODO remove after testing 
   1.260 -			QCanvasLine *l=new QCanvasLine (mapCanvas);
   1.261 -			l->setPoints (0,0,mapRect.width(),mapRect.height());
   1.262 -			l->setPen (QPen(QColor(black), 1));
   1.263 -			l->setZ (200);
   1.264 -			l->show();
   1.265 -			*/
   1.266 +			// TODO remove after testing 
   1.267 +			//QCanvasLine *l=new QCanvasLine (mapScene);
   1.268 +			//l->setPoints (0,0,mapRect.width(),mapRect.height());
   1.269 +			//l->setPen (QPen(QColor(black), 1));
   1.270 +			//l->setZ (200);
   1.271 +			//l->show();
   1.272  
   1.273  			if (printFooter) 
   1.274  			{
   1.275  				// Print footer below map
   1.276  				QFont font;		
   1.277  				font.setPointSize(10);
   1.278 -				footerFN=new Q3CanvasText (mapCanvas);
   1.279 +				footerFN=new Q3CanvasText (mapScene);
   1.280  				footerFN->setText ("VYM - " + fileName);
   1.281  				footerFN->setFont(font);
   1.282  				footerFN->move (mapRect.x(), mapRect.y() + mapRect.height() );
   1.283  				footerFN->setZ(Z_TEXT);
   1.284  				footerFN->show();    
   1.285 -				footerDate=new Q3CanvasText (mapCanvas);
   1.286 +				footerDate=new Q3CanvasText (mapScene);
   1.287  				footerDate->setText (QDate::currentDate().toString(Qt::TextDate));
   1.288  				footerDate->setFont(font);
   1.289  				footerDate->move (mapRect.x()+mapRect.width()-footerDate->boundingRect().width(), mapRect.y() + mapRect.height() );
   1.290 @@ -1258,19 +1274,21 @@
   1.291  		{
   1.292  			pp.setWindow (mapRect);
   1.293  		}	
   1.294 +*/
   1.295  
   1.296  		if (mapAspect>=paperAspect)
   1.297  		{
   1.298  			// Fit horizontally to paper width
   1.299 -			pp.setViewport(0,0, printer->width(),(int)(printer->width()/mapAspect) );	
   1.300 +			pp.setViewport(0,0, metrics.width(),(int)(metrics.width()/mapAspect) );	
   1.301  		}	else
   1.302  		{
   1.303  			// Fit vertically to paper height
   1.304 -			pp.setViewport(0,0,(int)(printer->height()*mapAspect),printer->height());	
   1.305 +			pp.setViewport(0,0,(int)(metrics.height()*mapAspect),metrics.height());	
   1.306  		}	
   1.307  
   1.308 -		mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to printer
   1.309 -
   1.310 +		mapScene->render(&pp);	// draw scene to printer
   1.311 +
   1.312 +/*
   1.313  		// Delete Frame and footer
   1.314  		if (footerFN) 
   1.315  		{
   1.316 @@ -1278,6 +1296,7 @@
   1.317  			delete (footerDate);
   1.318  		}	
   1.319  		if (frame)  delete (frame);
   1.320 +*/		
   1.321  
   1.322  		// Restore selection
   1.323  		if (oldselection) 
   1.324 @@ -1291,9 +1310,20 @@
   1.325  	}
   1.326  }
   1.327  
   1.328 +void MapEditor::setAntiAlias (bool b)
   1.329 +{
   1.330 +	setRenderHint(QPainter::Antialiasing,b);
   1.331 +}
   1.332 +
   1.333 +void MapEditor::setSmoothPixmap(bool b)
   1.334 +{
   1.335 +	setRenderHint(QPainter::SmoothPixmapTransform,b);
   1.336 +}
   1.337 +
   1.338  QPixmap MapEditor::getPixmap()
   1.339  {
   1.340 -	QRect mapRect=mapCenter->getTotalBBox();
   1.341 +/* FIXME not ported yet to QT4
   1.342 +	QRectF mapRect=mapCenter->getTotalBBox();
   1.343  	QPixmap pix (mapRect.size());
   1.344  	QPainter pp (&pix);
   1.345  
   1.346 @@ -1307,7 +1337,7 @@
   1.347  
   1.348  	pp.setWindow (mapRect);
   1.349  
   1.350 -	mapCanvas->drawArea(mapRect, &pp);	// draw Canvas to painter
   1.351 +	mapScene->drawArea(mapRect, &pp);	// draw scene to painter
   1.352  
   1.353  
   1.354  	// Restore selection
   1.355 @@ -1318,6 +1348,8 @@
   1.356  	}	
   1.357  	
   1.358  	return pix;
   1.359 +*/
   1.360 +return QPixmap();
   1.361  }
   1.362  
   1.363  void MapEditor::setHideTmpMode (HideTmpMode mode)
   1.364 @@ -1326,7 +1358,7 @@
   1.365  	mapCenter->setHideTmp (hidemode);
   1.366  	mapCenter->reposition();
   1.367  	adjustCanvasSize();
   1.368 -	canvas()->update();
   1.369 +	scene()->update();
   1.370  }
   1.371  
   1.372  HideTmpMode MapEditor::getHideTmpMode()
   1.373 @@ -1424,7 +1456,7 @@
   1.374  	{
   1.375  		// write to directory
   1.376  		QString clipfile="part";
   1.377 -		QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPoint(),selection);
   1.378 +		QString saveFile=saveToDir (fileDir,clipfile+"-",true,QPointF(),selection);
   1.379  		QFile file;
   1.380  
   1.381  		file.setName ( clipboardDir + "/"+clipfile+".xml");
   1.382 @@ -1505,8 +1537,8 @@
   1.383  	undoSet.setEntry ("/history/curStep",QString::number(curStep));
   1.384  	undoSet.writeSettings(histPath);
   1.385  
   1.386 +	mainWindow->updateHistory (undoSet);
   1.387  	updateActions();
   1.388 -	mainWindow->updateHistory (undoSet);
   1.389  
   1.390  	/* TODO remove testing
   1.391  	cout << "ME::redo() end\n";
   1.392 @@ -1747,11 +1779,11 @@
   1.393  {
   1.394  	if (selection)
   1.395  	{
   1.396 -		QString ps=qpointToString (selection->getAbsPos());
   1.397 +		QString ps=qpointfToString (selection->getAbsPos());
   1.398  		QString s=selection->getSelectString();
   1.399  		saveState(
   1.400  			s, "move "+ps, 
   1.401 -			s, "move "+qpointToString (QPoint (x,y)), 
   1.402 +			s, "move "+qpointfToString (QPointF (x,y)), 
   1.403  			QString("Move %1 to  %2").arg(getName(selection)).arg(ps));
   1.404  		selection->move(x,y);
   1.405  		mapCenter->reposition();
   1.406 @@ -1766,11 +1798,11 @@
   1.407  				      typeid(*selection) == typeid(MapCenterObj) ||
   1.408  					  typeid(*selection) == typeid (FloatImageObj))) 
   1.409  	{
   1.410 -		QString ps=qpointToString (selection->getRelPos());
   1.411 +		QString ps=qpointfToString (selection->getRelPos());
   1.412  		QString s=selection->getSelectString();
   1.413  		saveState(
   1.414  			s, "moveRel "+ps, 
   1.415 -			s, "moveRel "+qpointToString (QPoint (x,y)), 
   1.416 +			s, "moveRel "+qpointfToString (QPointF (x,y)), 
   1.417  			QString("Move %1 to relativ position %2").arg(getName(selection)).arg(ps));
   1.418  		((OrnamentedObj*)selection)->move2RelPos (x,y);
   1.419  		mapCenter->reposition();
   1.420 @@ -1822,9 +1854,7 @@
   1.421  	{
   1.422  		ok=true;
   1.423  		ensureSelectionVisible();
   1.424 -		p = ((BranchObj*)selection)->getAbsPos();
   1.425 -		p.setX (p.x() - contentsX());
   1.426 -		p.setY (p.y() - contentsY() + ((BranchObj*)selection)->height()/2);
   1.427 +		p=mapFromScene(selection->getAbsPos());
   1.428  		return ((BranchObj*)selection)->getHeading();
   1.429  	}
   1.430  	ok=false;
   1.431 @@ -1967,7 +1997,7 @@
   1.432  		 // We accept no MapCenterObj here, so we _have_ a parent
   1.433  	{
   1.434  		BranchObj* bo = (BranchObj*) selection;
   1.435 -		QPoint p=bo->getRelPos();
   1.436 +		QPointF p=bo->getRelPos();
   1.437  
   1.438  
   1.439  		BranchObj *parbo=(BranchObj*)(selection->getParObj());
   1.440 @@ -2443,29 +2473,67 @@
   1.441  	}
   1.442  }
   1.443  
   1.444 +void MapEditor::selectMapBackgroundImage ()
   1.445 +{
   1.446 +	Q3FileDialog *fd=new Q3FileDialog( this);
   1.447 +	fd->setMode (Q3FileDialog::ExistingFile);
   1.448 +	fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)"));
   1.449 +	ImagePreview *p =new ImagePreview (fd);
   1.450 +	fd->setContentsPreviewEnabled( TRUE );
   1.451 +	fd->setContentsPreview( p, p );
   1.452 +	fd->setPreviewMode( Q3FileDialog::Contents );
   1.453 +	fd->setCaption(vymName+" - " +tr("Load background image"));
   1.454 +	fd->setDir (lastImageDir);
   1.455 +	fd->show();
   1.456 +
   1.457 +	if ( fd->exec() == QDialog::Accepted )
   1.458 +	{
   1.459 +		// FIXME in QT4 use:	lastImageDir=fd->directory();
   1.460 +		lastImageDir=QDir (fd->dirPath());
   1.461 +		setMapBackgroundImage (fd->selectedFile());
   1.462 +	}
   1.463 +}	
   1.464 +
   1.465 +void MapEditor::setMapBackgroundImage (const QString &fn)
   1.466 +{
   1.467 +	QColor oldcol=mapScene->backgroundBrush().color();
   1.468 +	/*
   1.469 +	saveState(
   1.470 +		selection,
   1.471 +		QString ("setMapBackgroundImage (%1)").arg(oldcol.name()),
   1.472 +		selection,
   1.473 +		QString ("setMapBackgroundImage (%1)").arg(col.name()),
   1.474 +		QString("Set background color of map to %1").arg(col.name()));
   1.475 +	*/	
   1.476 +	cout << "Trying to load "<<fn.ascii()<<endl;
   1.477 +	QBrush brush;
   1.478 +	brush.setTextureImage (QPixmap (fn));
   1.479 +	mapScene->setBackgroundBrush(brush);
   1.480 +}
   1.481 +
   1.482  void MapEditor::selectMapBackgroundColor()
   1.483  {
   1.484 -	QColor col = QColorDialog::getColor( mapCanvas->backgroundColor(), this );
   1.485 +	QColor col = QColorDialog::getColor( mapScene->backgroundBrush().color(), this );
   1.486  	if ( !col.isValid() ) return;
   1.487 -	setBackgroundColor( col );
   1.488 +	setMapBackgroundColor( col );
   1.489  }
   1.490  
   1.491  
   1.492  void MapEditor::setMapBackgroundColor(QColor col)
   1.493  {
   1.494 -	QColor oldcol=mapCanvas->backgroundColor();
   1.495 +	QColor oldcol=mapScene->backgroundBrush().color();
   1.496  	saveState(
   1.497  		selection,
   1.498  		QString ("setMapBackgroundColor (%1)").arg(oldcol.name()),
   1.499  		selection,
   1.500  		QString ("setMapBackgroundColor (%1)").arg(col.name()),
   1.501  		QString("Set background color of map to %1").arg(col.name()));
   1.502 -	mapCanvas->setBackgroundColor (col);
   1.503 +	mapScene->setBackgroundBrush(col);
   1.504  }
   1.505  
   1.506  QColor MapEditor::getMapBackgroundColor()
   1.507  {
   1.508 -    return mapCanvas->backgroundColor();
   1.509 +    return mapScene->backgroundBrush().color();
   1.510  }
   1.511  
   1.512  QColor MapEditor::getCurrentHeadingColor()
   1.513 @@ -2557,9 +2625,10 @@
   1.514  
   1.515  void MapEditor::setViewCenter()
   1.516  {
   1.517 -	// transform to CanvasView Coord:
   1.518 -	QPoint p=worldMatrix().map(movingCenter);
   1.519 -	center ( p.x(), p.y());
   1.520 +	// transform to sceneView Coord:
   1.521 +	QPointF p=matrix().map(movingCenter);
   1.522 +	//FIXME not ported yet to QT4 (center ist TextStream there)
   1.523 +	//center ( p.x(), p.y());
   1.524  }
   1.525  
   1.526  
   1.527 @@ -2756,7 +2825,7 @@
   1.528  			updateActions();
   1.529  			mapCenter->reposition();
   1.530  			adjustCanvasSize();
   1.531 -			canvas()->update();
   1.532 +			scene()->update();
   1.533  		}
   1.534  	}
   1.535  }
   1.536 @@ -2778,7 +2847,7 @@
   1.537  		updateActions();
   1.538  		mapCenter->reposition();
   1.539  		adjustCanvasSize();
   1.540 -		canvas()->update();
   1.541 +		scene()->update();
   1.542  	}
   1.543  }
   1.544  
   1.545 @@ -2802,7 +2871,7 @@
   1.546  		updateActions();
   1.547  		mapCenter->reposition();
   1.548  		adjustCanvasSize();
   1.549 -		canvas()->update();
   1.550 +		scene()->update();
   1.551  	}
   1.552  }
   1.553  
   1.554 @@ -2848,7 +2917,7 @@
   1.555  	{		
   1.556  		BranchObj* bo=(BranchObj*)selection;
   1.557  		BranchObj* par=(BranchObj*)(bo->getParObj());
   1.558 -		QPoint p=bo->getRelPos();
   1.559 +		QPointF p=bo->getRelPos();
   1.560  		saveStateChangingPart(
   1.561  			selection->getParObj(),
   1.562  			selection,
   1.563 @@ -2892,11 +2961,7 @@
   1.564  
   1.565  	// Calc some stats
   1.566  	QString stats;
   1.567 -    int i=0;
   1.568 -    Q3CanvasItemList l=canvas()->allItems();
   1.569 -    for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) 
   1.570 -        i++;
   1.571 -    stats+=QString ("%1 items on canvas\n").arg (i,6);
   1.572 +    stats+=tr("%1 items on map\n","Info about map").arg (mapScene->items().size(),6);
   1.573  
   1.574  	uint b=0;
   1.575  	uint f=0;
   1.576 @@ -3109,7 +3174,7 @@
   1.577  		);
   1.578  		bo->toggleScroll();
   1.579  		adjustCanvasSize();
   1.580 -		canvas()->update();
   1.581 +		scene()->update();
   1.582  	}
   1.583  }
   1.584  
   1.585 @@ -3171,7 +3236,7 @@
   1.586  
   1.587  			mapCenter->reposition();
   1.588  			adjustCanvasSize();
   1.589 -			canvas()->update();
   1.590 +			scene()->update();
   1.591  		}
   1.592  		delete (p);
   1.593  		delete (fd);
   1.594 @@ -3335,7 +3400,7 @@
   1.595  			importDirInt (bo,QDir(fd->selectedFile()) );
   1.596  			mapCenter->reposition();
   1.597  			adjustCanvasSize();
   1.598 -			canvas()->update();
   1.599 +			scene()->update();
   1.600  		}
   1.601  	}	
   1.602  }
   1.603 @@ -3386,17 +3451,6 @@
   1.604  
   1.605  void MapEditor::testFunction()
   1.606  {
   1.607 -	cout << "MapEditor::testFunction() called\n";
   1.608 -
   1.609 -	if (selection && 
   1.610 -		(typeid(*selection) == typeid(BranchObj)) || 
   1.611 -		(typeid(*selection) == typeid(MapCenterObj))  )
   1.612 -	{
   1.613 -		BranchObj* bo=(BranchObj*)selection;
   1.614 -		cout << bo->getHeading().ascii() <<" is scrolled: "<<bo->isScrolled()<<endl;
   1.615 -	}
   1.616 -	return;
   1.617 -	
   1.618  	WarningDialog dia;
   1.619  	dia.showCancelButton (true);
   1.620  	dia.setText("This is a longer \nWarning");
   1.621 @@ -3415,18 +3469,18 @@
   1.622  	{
   1.623  		setHideTmpMode (HideExport);
   1.624  		mapCenter->calcBBoxSizeWithChilds();
   1.625 -		QRect totalBBox=mapCenter->getTotalBBox();
   1.626 -		QRect mapRect=totalBBox;
   1.627 +		QRectF totalBBox=mapCenter->getTotalBBox();
   1.628 +		QRectF mapRect=totalBBox;
   1.629  		QCanvasRectangle *frame=NULL;
   1.630  
   1.631  		cout << "  map has =("<<totalBBox.x()<<","<<totalBBox.y()<<","<<totalBBox.width()<<","<<totalBBox.height()<<")\n";
   1.632  	
   1.633  		mapRect.setRect (totalBBox.x(), totalBBox.y(), 
   1.634  			totalBBox.width(), totalBBox.height());
   1.635 -		frame=new QCanvasRectangle (mapRect,mapCanvas);
   1.636 +		frame=new QCanvasRectangle (mapRect,mapScene);
   1.637  		frame->setBrush (QColor(white));
   1.638  		frame->setPen (QColor(black));
   1.639 -		frame->setZ(0);
   1.640 +		frame->setZValue(0);
   1.641  		frame->show();    
   1.642  	}	
   1.643  	else	
   1.644 @@ -3442,32 +3496,35 @@
   1.645  	if (selection)
   1.646  	{
   1.647  		LinkableMapObj* lmo= dynamic_cast <LinkableMapObj*> (selection);
   1.648 -		QPoint p;
   1.649 +		QPointF p;
   1.650  		if (selection->getOrientation() == OrientLeftOfCenter)
   1.651 -			p= worldMatrix().map(QPoint (lmo->x(),lmo->y()));
   1.652 -		else	
   1.653 -			p= worldMatrix().map(QPoint (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
   1.654 -		ensureVisible (p.x(), p.y() );
   1.655 +			p= matrix().map(QPointF (lmo->x(),lmo->y()));
   1.656 +		else   
   1.657 +			p= matrix().map(QPointF (lmo->x()+lmo->width(),lmo->y()+lmo->height()));
   1.658 +		ensureVisible (QRectF(p.x(), p.y(),0,0 ));
   1.659 +
   1.660  	}
   1.661  
   1.662  }
   1.663  
   1.664  void MapEditor::updateViewCenter()
   1.665  {
   1.666 +/* FIXME still to port to QT4 inverseworldmatrix
   1.667  	// Update movingCenter, so that we can zoom comfortably later
   1.668 -	QRect rc = QRect( contentsX(), contentsY(),
   1.669 +	QRectF rc = QRectF( contentsX(), contentsY(),
   1.670  				  visibleWidth(), visibleHeight() );
   1.671 -	QRect canvasRect = inverseWorldMatrix().mapRect(rc);
   1.672 +	QRectF canvasRect = inverseWorldMatrix().mapRect(rc);
   1.673  	movingCenter.setX((canvasRect.right() + canvasRect.left())/2);
   1.674  	movingCenter.setY((canvasRect.top() + canvasRect.bottom())/2);
   1.675 +	*/
   1.676  }
   1.677  
   1.678 -void MapEditor::contentsContextMenuEvent ( QContextMenuEvent * e )
   1.679 +void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
   1.680  {
   1.681  	// Lineedits are already closed by preceding
   1.682  	// mouseEvent, we don't need to close here.
   1.683  
   1.684 -    QPoint p = inverseWorldMatrix().map(e->pos());
   1.685 +    QPointF p = mapToScene(e->pos());
   1.686      LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
   1.687  	
   1.688      if (lmo) 
   1.689 @@ -3499,7 +3556,7 @@
   1.690  		}	
   1.691  	} else 
   1.692  	{ // No MapObj found, we are on the Canvas itself
   1.693 -		// Context Menu on Canvas
   1.694 +		// Context Menu on scene
   1.695  		updateActions();
   1.696  		canvasContextMenu->popup(e->globalPos() );
   1.697      } 
   1.698 @@ -3534,7 +3591,7 @@
   1.699  		setCursor (Qt::ArrowCursor);
   1.700  }
   1.701  
   1.702 -void MapEditor::contentsMousePressEvent(QMouseEvent* e)
   1.703 +void MapEditor::mousePressEvent(QMouseEvent* e)
   1.704  {
   1.705  	// Ignore right clicks, these will go to context menus
   1.706  	if (e->button() == Qt::RightButton )
   1.707 @@ -3543,7 +3600,7 @@
   1.708  		return;
   1.709  	}
   1.710  
   1.711 -    QPoint p = inverseWorldMatrix().map(e->pos());
   1.712 +    QPointF p = mapToScene(e->pos());
   1.713      LinkableMapObj* lmo=mapCenter->findMapObj(p, NULL);
   1.714  	
   1.715  	e->accept();
   1.716 @@ -3602,7 +3659,7 @@
   1.717  			{
   1.718  				drawingLink=true;
   1.719  				linkingObj_src=bo_begin;
   1.720 -				tmpXLink=new XLinkObj (mapCanvas);
   1.721 +				tmpXLink=new XLinkObj (mapScene);
   1.722  				tmpXLink->setBegin (bo_begin);
   1.723  				tmpXLink->setEnd   (p);
   1.724  				tmpXLink->setColor(defXLinkColor);
   1.725 @@ -3649,27 +3706,31 @@
   1.726  				toggleScroll();
   1.727  		updateActions();
   1.728  	} else 
   1.729 -	{ // No MapObj found, we are on the Canvas itself
   1.730 -		// Left Button	    move Pos of CanvasView
   1.731 +	{ // No MapObj found, we are on the scene itself
   1.732 +		// Left Button	    move Pos of sceneView
   1.733  		if (e->button() == Qt::LeftButton )
   1.734  		{
   1.735  			movingObj=NULL;	// move Content not Obj
   1.736  			movingObj_start=e->globalPos();
   1.737 -			movingCont_start=QPoint (contentsX(), contentsY() );
   1.738 -			movingVec=QPoint(0,0);
   1.739 +			// FIXME not ported to QT4 yet (move canvasView)
   1.740 +			//movingCont_start=QPointF (contentsX(), contentsY() );
   1.741 +			movingCont_start=QPointF (
   1.742 +				horizontalScrollBar()->value(),
   1.743 +				verticalScrollBar()->value());
   1.744 +			movingVec=QPointF(0,0);
   1.745  			setCursor(HandOpenCursor);
   1.746  		} 
   1.747      } 
   1.748  }
   1.749  
   1.750 -void MapEditor::contentsMouseMoveEvent(QMouseEvent* e)
   1.751 +void MapEditor::mouseMoveEvent(QMouseEvent* e)
   1.752  {
   1.753 -	QPoint p = inverseWorldMatrix().map(e->pos());
   1.754 +    QPointF p = mapToScene(e->pos());
   1.755  
   1.756      // Move the selected MapObj
   1.757      if ( selection && movingObj) 
   1.758      {	
   1.759 -		// To avoid jumping of the CanvasView, only 
   1.760 +		// To avoid jumping of the sceneView, only 
   1.761  		// ensureSelectionVisible, if not tmp linked
   1.762  		if (!selection->hasParObjTmp())
   1.763  			ensureSelectionVisible ();
   1.764 @@ -3691,7 +3752,7 @@
   1.765  			FloatObj *fo=(FloatObj*)selection;
   1.766  			fo->move   (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   1.767  			fo->setRelPos();
   1.768 -			fo->reposition();
   1.769 +			fo->updateLink(); //no need for reposition, if we update link here
   1.770  
   1.771  			// Relink float to new mapcenter or branch, if shift is pressed	
   1.772  			// Only relink, if selection really has a new parent
   1.773 @@ -3703,7 +3764,8 @@
   1.774  			{
   1.775  				if (typeid(*fo) == typeid(FloatImageObj)) 
   1.776  				{
   1.777 -					//TODO undocom
   1.778 +					//FIXME undocom for relinking of floats
   1.779 +
   1.780  					//saveStateComplete(QString("Relink %1 to %2").arg(getName(fo)).arg(getName(lmo) ) );
   1.781  					FloatImageObj *fio=(FloatImageObj*)(fo);
   1.782  					((BranchObj*)(lmo))->addFloatImage (fio);
   1.783 @@ -3769,7 +3831,7 @@
   1.784  
   1.785  		} // no FloatImageObj
   1.786  
   1.787 -		canvas()->update();
   1.788 +		scene()->update();
   1.789  		return;
   1.790  	} // selection && moving_obj
   1.791  		
   1.792 @@ -3780,22 +3842,25 @@
   1.793  		 tmpXLink->updateXLink();
   1.794  	}	 
   1.795  	
   1.796 -    // Move CanvasView 
   1.797 -    if (!movingObj && !pickingColor &&!drawingLink) 
   1.798 +    // Move sceneView 
   1.799 +    //if (!movingObj && !pickingColor &&!drawingLink && e->button() == Qt::LeftButton ) 
   1.800 +    if (e->buttons() == Qt::LeftButton ) 
   1.801  	{
   1.802 -		QPoint p=e->globalPos();
   1.803 +		QPointF p=e->globalPos();
   1.804  		movingVec.setX(-p.x() + movingObj_start.x() );
   1.805  		movingVec.setY(-p.y() + movingObj_start.y() );
   1.806 -		setContentsPos( movingCont_start.x() + movingVec.x(),
   1.807 -	    movingCont_start.y() + movingVec.y());
   1.808 -
   1.809 -		updateViewCenter();
   1.810 +		// FIXME not ported to QT4 yet (move canvasView)
   1.811 +		//setContentsPos( movingCont_start.x() + movingVec.x(),
   1.812 +	    //movingCont_start.y() + movingVec.y();
   1.813 +		horizontalScrollBar()->setSliderPosition((int)( movingCont_start.x()+movingVec.x() ));
   1.814 +		verticalScrollBar()->setSliderPosition((int)( movingCont_start.y()+movingVec.y() ) );
   1.815      }
   1.816  }
   1.817  
   1.818  
   1.819 -void MapEditor::contentsMouseReleaseEvent(QMouseEvent* e)
   1.820 +void MapEditor::mouseReleaseEvent(QMouseEvent* e)
   1.821  {
   1.822 +    QPointF p = mapToScene(e->pos());
   1.823  	LinkableMapObj *dst;
   1.824  	// Have we been picking color?
   1.825  	if (pickingColor)
   1.826 @@ -3803,7 +3868,7 @@
   1.827  		pickingColor=false;
   1.828  		setCursor (Qt::ArrowCursor);
   1.829  		// Check if we are over another branch
   1.830 -		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
   1.831 +		dst=mapCenter->findMapObj(p, NULL);
   1.832  		if (dst && selection) 
   1.833  		{	
   1.834  			if (e->state() & Qt::ShiftModifier)
   1.835 @@ -3825,7 +3890,7 @@
   1.836  	{
   1.837  		drawingLink=false;
   1.838  		// Check if we are over another branch
   1.839 -		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), NULL);
   1.840 +		dst=mapCenter->findMapObj(p, NULL);
   1.841  		if (dst && selection) 
   1.842  		{	
   1.843  			tmpXLink->setEnd ( ((BranchObj*)(dst)) );
   1.844 @@ -3847,8 +3912,8 @@
   1.845  		{
   1.846  			// Moved FloatObj. Maybe we need to reposition
   1.847  			FloatImageObj *fo=(FloatImageObj*)selection;
   1.848 -		    QString pold=qpointToString(movingObj_orgRelPos);
   1.849 -		    QString pnow=qpointToString(fo->getRelPos());
   1.850 +		    QString pold=qpointfToString(movingObj_orgRelPos);
   1.851 +		    QString pnow=qpointfToString(fo->getRelPos());
   1.852  			saveState(
   1.853  				selection,
   1.854  				"moveRel "+pold,
   1.855 @@ -3863,7 +3928,7 @@
   1.856  
   1.857  		// Check if we are over another branch, but ignore 
   1.858  		// any found LMOs, which are FloatObjs
   1.859 -		dst=mapCenter->findMapObj(inverseWorldMatrix().map(e->pos() ), 
   1.860 +		dst=mapCenter->findMapObj(mapToScene(e->pos() ), 
   1.861  			((LinkableMapObj*)selection) );
   1.862  
   1.863  		if (dst && (typeid(*dst)!=typeid(BranchObj) && typeid(*dst)!=typeid(MapCenterObj))) 
   1.864 @@ -3878,7 +3943,7 @@
   1.865  		{	// A branch was moved
   1.866  			
   1.867  			// save the position in case we link to mapcenter
   1.868 -			QPoint savePos=QPoint (selection->x(),selection->y() );
   1.869 +			QPointF savePos=QPointF (selection->x(),selection->y() );
   1.870  
   1.871  			// Reset the temporary drawn link to the original one
   1.872  			((LinkableMapObj*)selection)->unsetParObjTmp();
   1.873 @@ -3934,9 +3999,9 @@
   1.874  					// Therefor reposition and then use string of old selection, too
   1.875  					mapCenter->reposition();
   1.876  
   1.877 -					QString ps=qpointToString ( ((BranchObj*)selection)->getRelPos() );
   1.878 +					QString ps=qpointfToString ( ((BranchObj*)selection)->getRelPos() );
   1.879  					saveState(
   1.880 -						selection->getSelectString(), "moveRel "+qpointToString(movingObj_orgRelPos), 
   1.881 +						selection->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
   1.882  						preSelStr, "moveRel "+ps, 
   1.883  						QString("Move %1 to relative position %2").arg(getName(selection)).arg(ps));
   1.884  			
   1.885 @@ -3944,9 +4009,9 @@
   1.886  			// Draw the original link, before selection was moved around
   1.887  			mapCenter->reposition();
   1.888  		}
   1.889 -		// Finally resize canvas, if needed
   1.890 +		// Finally resize scene, if needed
   1.891  		adjustCanvasSize();
   1.892 -		canvas()->update();
   1.893 +		scene()->update();
   1.894  		movingObj=NULL;		
   1.895  
   1.896  		// Just make sure, that actions are still ok,e.g. the move branch up/down buttons...
   1.897 @@ -3957,11 +4022,11 @@
   1.898      
   1.899  }
   1.900  
   1.901 -void MapEditor::contentsMouseDoubleClickEvent(QMouseEvent* e)
   1.902 +void MapEditor::mouseDoubleClickEvent(QMouseEvent* e)
   1.903  {
   1.904  	if (e->button() == Qt::LeftButton )
   1.905  	{
   1.906 -		QPoint p = inverseWorldMatrix().map(e->pos());
   1.907 +		QPointF p = mapToScene(e->pos());
   1.908  		LinkableMapObj *lmo=mapCenter->findMapObj(p, NULL);
   1.909  		if (lmo) {	// MapObj was found
   1.910  			// First select the MapObj than edit heading
   1.911 @@ -3975,74 +4040,57 @@
   1.912  
   1.913  void MapEditor::resizeEvent (QResizeEvent* e)
   1.914  {
   1.915 -	Q3CanvasView::resizeEvent( e );
   1.916 +	QGraphicsView::resizeEvent( e );
   1.917  	adjustCanvasSize();
   1.918  }
   1.919  
   1.920  void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) 
   1.921  {
   1.922 -	if (selection && 
   1.923 -		(typeid(*selection) == typeid(BranchObj)) || 
   1.924 -		(typeid(*selection) == typeid(MapCenterObj))) 
   1.925 -	{
   1.926 -		if (event->mimeData()->hasFormat("image/png"))
   1.927 -		{
   1.928 -		cout <<"found png in dragenterevent\n";
   1.929 -		event->accept();
   1.930 -		return;
   1.931 -	}
   1.932 -
   1.933 -	if (event->mimeData()->hasFormat("text/uri-list"))
   1.934 -	{
   1.935 -		cout <<"found uri-list in dragenterevent\n";
   1.936 -		event->accept();
   1.937 -		return;
   1.938 -	}
   1.939 -
   1.940 -/*
   1.941 -	// If QImageDrag can decode mime type 
   1.942 -	if (Q3ImageDrag::canDecode(event)) 
   1.943 -	{
   1.944 -		cout << "dragenterevent q3imagedrag\n";
   1.945 -		event->accept();
   1.946 -		return;
   1.947 -	}
   1.948 -*/
   1.949 -	// If image are dragged from firefox 
   1.950 -	if (event->mimeData()->hasFormat("application/x-moz-file-promise-url") && 
   1.951 -		event->mimeData()->hasFormat("application/x-moz-nativeimage")) {
   1.952 -		event->accept(true);
   1.953 -		cout << "dragenterevent firefox\n";
   1.954 -		return;
   1.955 -	}
   1.956 -/*
   1.957 -	// If QUriDrag can decode mime type 
   1.958 -	if (Q3UriDrag::canDecode(event)) {
   1.959 -		event->accept();
   1.960 -		cout << "accepted uri drag\n";	
   1.961 -		return;
   1.962 -	}
   1.963 +	//FIXME not ported to QT4 yet
   1.964 +
   1.965 +//  for (unsigned int i=0;event->format(i);i++) // Debug mime type
   1.966 +//    cerr << event->format(i) << endl;
   1.967 +
   1.968 +  if (selection && 
   1.969 +      (typeid(*selection) == typeid(BranchObj)) || 
   1.970 +      (typeid(*selection) == typeid(MapCenterObj))) {
   1.971 +    
   1.972 +    // If QImageDrag can decode mime type 
   1.973 +    if (Q3ImageDrag::canDecode(event)) {
   1.974 +      event->accept();
   1.975 +      return;
   1.976 +    }
   1.977 +    
   1.978 +    // If image are dragged from firefox 
   1.979 +    if (event->provides("application/x-moz-file-promise-url") && 
   1.980 +	event->provides("application/x-moz-nativeimage")) {
   1.981 +      event->accept(true);
   1.982 +      return;
   1.983 +    }
   1.984 +
   1.985 +    // If QUriDrag can decode mime type 
   1.986 +    if (Q3UriDrag::canDecode(event)) {
   1.987 +      event->accept();
   1.988 +      return;
   1.989 +    }
   1.990 +    
   1.991  	// If Uri are dragged from firefox 
   1.992 -	if (event->provides("_NETSCAPE_URL")){
   1.993 -		event->accept();
   1.994 -		cout << "dragenterevent NETSCAPE\n";
   1.995 -		return;
   1.996 -	}
   1.997 -
   1.998 -	// If QTextDrag can decode mime type
   1.999 -	if (Q3TextDrag::canDecode(event)) {
  1.1000 -		event->accept();
  1.1001 -		cout << "dragenterevent textdrag\n";
  1.1002 -		return;
  1.1003 -	}
  1.1004 -*/
  1.1005 -	}
  1.1006 -	event->ignore();
  1.1007 +    if (event->provides("_NETSCAPE_URL")){
  1.1008 +      event->accept();
  1.1009 +      return;
  1.1010 +    }
  1.1011 +
  1.1012 +    // If QTextDrag can decode mime type
  1.1013 +    if (Q3TextDrag::canDecode(event)) {
  1.1014 +      event->accept();
  1.1015 +      return;
  1.1016 +    }
  1.1017 +
  1.1018 +  }
  1.1019 +  event->ignore();
  1.1020  }
  1.1021  
  1.1022 -
  1.1023 -
  1.1024 -/* FIXME needed in QT4?  bool isUnicode16(const QByteArray &d) 
  1.1025 +bool isUnicode16(const QByteArray &d) 
  1.1026  {
  1.1027    // TODO: make more precise check for unicode 16.
  1.1028    // Guess unicode16 if any of second bytes are zero
  1.1029 @@ -4051,17 +4099,16 @@
  1.1030      if (d.at(i*2+1)==0) return true;
  1.1031    return false;
  1.1032  }
  1.1033 -*/
  1.1034 -
  1.1035 +      
  1.1036  void MapEditor::contentsDropEvent(QDropEvent *event) 
  1.1037  {
  1.1038 +	//FIXME not ported to QT4 yet
  1.1039  	if (selection && 
  1.1040        (typeid(*selection) == typeid(BranchObj)) || 
  1.1041        (typeid(*selection) == typeid(MapCenterObj))) 
  1.1042  	{
  1.1043  		bool update=false;
  1.1044  		QStringList uris;
  1.1045 -		QList <QUrl> urls;
  1.1046  		QString heading;
  1.1047  
  1.1048  
  1.1049 @@ -4069,21 +4116,34 @@
  1.1050  		{
  1.1051              event->acceptProposedAction();
  1.1052  			addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
  1.1053 -			cout << "Drop png...\n";
  1.1054 -		} else if (event->mimeData()->hasFormat("application/x-moz-file-promise-url")&&
  1.1055 -			 event->mimeData()->hasFormat("application/x-moz-nativeimage")) 
  1.1056 +			cout << "accepted drop\n";
  1.1057 +		}	
  1.1058 +
  1.1059 +		/*
  1.1060 +		if (event->provides("image/png")) 
  1.1061  		{
  1.1062 -			cout << "Drop Mozilla...\n";
  1.1063 +			QPixmap pix;
  1.1064 +			if (Q3ImageDrag::decode(event, pix)) 
  1.1065 +			{
  1.1066 +				addFloatImageInt(pix);
  1.1067 +				event->accept();
  1.1068 +				update=true;
  1.1069 +			} else
  1.1070 +				event->ignore();
  1.1071 +
  1.1072 +		} else if (event->provides("application/x-moz-file-promise-url") && 
  1.1073 +			 event->provides("application/x-moz-nativeimage")) 
  1.1074 +		{
  1.1075  			// Contains url to the img src in unicode16
  1.1076  			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
  1.1077  			QString url = QString((const QChar*)d.data(),d.size()/2);
  1.1078 -			//FIXME fetchImage(url);
  1.1079 -            event->acceptProposedAction();
  1.1080 +			fetchImage(url);
  1.1081 +			event->accept();
  1.1082  			update=true;
  1.1083 -		} else if (event->mimeData()->hasUrls())
  1.1084 -		{
  1.1085 -			urls=event->mimeData()->urls();
  1.1086 -		} /*else if (event->provides ("_NETSCAPE_URL"))
  1.1087 +		} else if (event->provides ("text/uri-list"))
  1.1088 +		{	// Uris provided e.g. by konqueror
  1.1089 +			Q3UriDrag::decode (event,uris);
  1.1090 +		} else if (event->provides ("_NETSCAPE_URL"))
  1.1091  		{	// Uris provided by Mozilla
  1.1092  		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
  1.1093  		  uris.append(l[0]);
  1.1094 @@ -4118,10 +4178,6 @@
  1.1095  		}
  1.1096  		*/
  1.1097  
  1.1098 -		for (int i=0; i<urls.size(); ++i)
  1.1099 -		{
  1.1100 -			cout << "Found URL: "<<urls.at(i).toString().ascii()<<endl;
  1.1101 -		}
  1.1102  		/* FIXME not ported yet  QSTRINGLIST has no next... 
  1.1103  		if (uris.count()>0)
  1.1104  		{
  1.1105 @@ -4165,7 +4221,7 @@
  1.1106  			//saveStateComplete("Drop Event");	//TODO undo Command
  1.1107  			mapCenter->reposition();
  1.1108  			adjustCanvasSize();
  1.1109 -			canvas()->update();
  1.1110 +			scene()->update();
  1.1111  		}	
  1.1112  	}	
  1.1113  }
  1.1114 @@ -4177,7 +4233,6 @@
  1.1115        (typeid(*selection) == typeid(MapCenterObj))  )
  1.1116    {
  1.1117      BranchObj *bo=((BranchObj*)selection);
  1.1118 -	qWarning ("Warning: Image added by drop event: no undo/redo so far.");
  1.1119      //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
  1.1120      //QString fn=fd->selectedFile();
  1.1121      //lastImageDir=fn.left(fn.findRev ("/"));
  1.1122 @@ -4186,13 +4241,12 @@
  1.1123      fio->setOriginalFilename("Image added by Drag and Drop");
  1.1124      mapCenter->reposition();
  1.1125      adjustCanvasSize();
  1.1126 -    canvas()->update();
  1.1127 +    scene()->update();
  1.1128    }
  1.1129  }
  1.1130  
  1.1131  
  1.1132 -//void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) 
  1.1133 -/* FIXME not needed in QT4
  1.1134 +void MapEditor::imageDataFetched(const QByteArray &a, Q3NetworkOperation */*nop*/) 
  1.1135  {
  1.1136    if (!imageBuffer) imageBuffer = new QBuffer();
  1.1137    if (!imageBuffer->isOpen()) {
  1.1138 @@ -4235,5 +4289,3 @@
  1.1139  	  this, SLOT(imageDataFetched(const QByteArray &, Q3NetworkOperation *)));
  1.1140    urlOperator->get();
  1.1141  }
  1.1142 -
  1.1143 -*/