mapeditor.cpp
changeset 406 1c8ff1928b97
parent 404 53efc2562a7d
child 407 5db8dfd30ea2
     1.1 --- a/mapeditor.cpp	Mon Nov 20 12:12:05 2006 +0000
     1.2 +++ b/mapeditor.cpp	Thu Nov 23 13:53:08 2006 +0000
     1.3 @@ -1,8 +1,6 @@
     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 <q3urloperator.h>
    1.10  #include <q3paintdevicemetrics.h>
    1.11  #include <q3filedialog.h>
    1.12  
    1.13 @@ -310,6 +308,7 @@
    1.14  	standardFlagsDefault->resetUsedCounter();
    1.15  	
    1.16  	// Reset the counters before saving
    1.17 +	// TODO constr. of FIO creates lots of objects, better do this in some other way...
    1.18  	FloatImageObj (mapCanvas).resetSaveCounter();
    1.19  
    1.20  	// Build xml recursivly
    1.21 @@ -3986,50 +3985,68 @@
    1.22  
    1.23  void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) 
    1.24  {
    1.25 -
    1.26 -//  for (unsigned int i=0;event->format(i);i++) // Debug mime type
    1.27 -//    cerr << event->format(i) << endl;
    1.28 -
    1.29 -  if (selection && 
    1.30 -      (typeid(*selection) == typeid(BranchObj)) || 
    1.31 -      (typeid(*selection) == typeid(MapCenterObj))) {
    1.32 -    
    1.33 -    // If QImageDrag can decode mime type 
    1.34 -    if (Q3ImageDrag::canDecode(event)) {
    1.35 -      event->accept();
    1.36 -      return;
    1.37 -    }
    1.38 -    
    1.39 -    // If image are dragged from firefox 
    1.40 -    if (event->provides("application/x-moz-file-promise-url") && 
    1.41 -	event->provides("application/x-moz-nativeimage")) {
    1.42 -      event->accept(true);
    1.43 -      return;
    1.44 -    }
    1.45 -
    1.46 -    // If QUriDrag can decode mime type 
    1.47 -    if (Q3UriDrag::canDecode(event)) {
    1.48 -      event->accept();
    1.49 -      return;
    1.50 -    }
    1.51 -    
    1.52 +	if (selection && 
    1.53 +		(typeid(*selection) == typeid(BranchObj)) || 
    1.54 +		(typeid(*selection) == typeid(MapCenterObj))) 
    1.55 +	{
    1.56 +		if (event->mimeData()->hasFormat("image/png"))
    1.57 +		{
    1.58 +		cout <<"found png in dragenterevent\n";
    1.59 +		event->accept();
    1.60 +		return;
    1.61 +	}
    1.62 +
    1.63 +	if (event->mimeData()->hasFormat("text/uri-list"))
    1.64 +	{
    1.65 +		cout <<"found uri-list in dragenterevent\n";
    1.66 +		event->accept();
    1.67 +		return;
    1.68 +	}
    1.69 +
    1.70 +/*
    1.71 +	// If QImageDrag can decode mime type 
    1.72 +	if (Q3ImageDrag::canDecode(event)) 
    1.73 +	{
    1.74 +		cout << "dragenterevent q3imagedrag\n";
    1.75 +		event->accept();
    1.76 +		return;
    1.77 +	}
    1.78 +*/
    1.79 +	// If image are dragged from firefox 
    1.80 +	if (event->mimeData()->hasFormat("application/x-moz-file-promise-url") && 
    1.81 +		event->mimeData()->hasFormat("application/x-moz-nativeimage")) {
    1.82 +		event->accept(true);
    1.83 +		cout << "dragenterevent firefox\n";
    1.84 +		return;
    1.85 +	}
    1.86 +/*
    1.87 +	// If QUriDrag can decode mime type 
    1.88 +	if (Q3UriDrag::canDecode(event)) {
    1.89 +		event->accept();
    1.90 +		cout << "accepted uri drag\n";	
    1.91 +		return;
    1.92 +	}
    1.93  	// If Uri are dragged from firefox 
    1.94 -    if (event->provides("_NETSCAPE_URL")){
    1.95 -      event->accept();
    1.96 -      return;
    1.97 -    }
    1.98 -
    1.99 -    // If QTextDrag can decode mime type
   1.100 -    if (Q3TextDrag::canDecode(event)) {
   1.101 -      event->accept();
   1.102 -      return;
   1.103 -    }
   1.104 -
   1.105 -  }
   1.106 -  event->ignore();
   1.107 +	if (event->provides("_NETSCAPE_URL")){
   1.108 +		event->accept();
   1.109 +		cout << "dragenterevent NETSCAPE\n";
   1.110 +		return;
   1.111 +	}
   1.112 +
   1.113 +	// If QTextDrag can decode mime type
   1.114 +	if (Q3TextDrag::canDecode(event)) {
   1.115 +		event->accept();
   1.116 +		cout << "dragenterevent textdrag\n";
   1.117 +		return;
   1.118 +	}
   1.119 +*/
   1.120 +	}
   1.121 +	event->ignore();
   1.122  }
   1.123  
   1.124 -bool isUnicode16(const QByteArray &d) 
   1.125 +
   1.126 +
   1.127 +/* FIXME needed in QT4?  bool isUnicode16(const QByteArray &d) 
   1.128  {
   1.129    // TODO: make more precise check for unicode 16.
   1.130    // Guess unicode16 if any of second bytes are zero
   1.131 @@ -4038,7 +4055,8 @@
   1.132      if (d.at(i*2+1)==0) return true;
   1.133    return false;
   1.134  }
   1.135 -      
   1.136 +*/
   1.137 +
   1.138  void MapEditor::contentsDropEvent(QDropEvent *event) 
   1.139  {
   1.140  	if (selection && 
   1.141 @@ -4046,32 +4064,30 @@
   1.142        (typeid(*selection) == typeid(MapCenterObj))) 
   1.143  	{
   1.144  		bool update=false;
   1.145 -		Q3StrList uris;
   1.146 +		QStringList uris;
   1.147 +		QList <QUrl> urls;
   1.148  		QString heading;
   1.149 -		if (event->provides("image/png")) 
   1.150 +
   1.151 +
   1.152 +		if (event->mimeData()->hasFormat("image/png"))
   1.153  		{
   1.154 -			QPixmap pix;
   1.155 -			if (Q3ImageDrag::decode(event, pix)) 
   1.156 -			{
   1.157 -				addFloatImageInt(pix);
   1.158 -				event->accept();
   1.159 -				update=true;
   1.160 -			} else
   1.161 -				event->ignore();
   1.162 -
   1.163 -		} else if (event->provides("application/x-moz-file-promise-url") && 
   1.164 -			 event->provides("application/x-moz-nativeimage")) 
   1.165 +            event->acceptProposedAction();
   1.166 +			addFloatImageInt(event->mimeData()->imageData().value<QPixmap>());
   1.167 +			cout << "Drop png...\n";
   1.168 +		} else if (event->mimeData()->hasFormat("application/x-moz-file-promise-url")&&
   1.169 +			 event->mimeData()->hasFormat("application/x-moz-nativeimage")) 
   1.170  		{
   1.171 +			cout << "Drop Mozilla...\n";
   1.172  			// Contains url to the img src in unicode16
   1.173  			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
   1.174  			QString url = QString((const QChar*)d.data(),d.size()/2);
   1.175  			fetchImage(url);
   1.176 -			event->accept();
   1.177 +            event->acceptProposedAction();
   1.178  			update=true;
   1.179 -		} else if (event->provides ("text/uri-list"))
   1.180 -		{	// Uris provided e.g. by konqueror
   1.181 -			Q3UriDrag::decode (event,uris);
   1.182 -		} else if (event->provides ("_NETSCAPE_URL"))
   1.183 +		} else if (event->mimeData()->hasUrls())
   1.184 +		{
   1.185 +			urls=event->mimeData()->urls();
   1.186 +		} /*else if (event->provides ("_NETSCAPE_URL"))
   1.187  		{	// Uris provided by Mozilla
   1.188  		  QStringList l = QStringList::split("\n", event->encodedData("_NETSCAPE_URL"));
   1.189  		  uris.append(l[0]);
   1.190 @@ -4104,7 +4120,13 @@
   1.191  		  event->accept();
   1.192  		  update= true;
   1.193  		}
   1.194 -
   1.195 +		*/
   1.196 +
   1.197 +		for (int i=0; i<urls.size(); ++i)
   1.198 +		{
   1.199 +			cout << "Found URL: "<<urls.at(i).toString().ascii()<<endl;
   1.200 +		}
   1.201 +		/* FIXME not ported yet  QSTRINGLIST has no next... 
   1.202  		if (uris.count()>0)
   1.203  		{
   1.204  			QStringList files;
   1.205 @@ -4140,7 +4162,7 @@
   1.206  			}
   1.207  			update=true;
   1.208  		}
   1.209 -
   1.210 +		*/
   1.211  		if (update) 
   1.212  		{
   1.213  			//FIXME saveState has to be called earlier for each of the drops...
   1.214 @@ -4159,6 +4181,7 @@
   1.215        (typeid(*selection) == typeid(MapCenterObj))  )
   1.216    {
   1.217      BranchObj *bo=((BranchObj*)selection);
   1.218 +	qWarning ("Warning: Image added by drop event: no undo/redo so far.");
   1.219      //FIXME XXX saveStateChangingPart(selection,QString("Add floatimage to %1").arg(getName(bo)));
   1.220      //QString fn=fd->selectedFile();
   1.221      //lastImageDir=fn.left(fn.findRev ("/"));