mapeditor.cpp
changeset 128 0dc9286ad3d4
parent 125 8cdfa8dda71e
child 129 9b9c7e8b9147
     1.1 --- a/mapeditor.cpp	Wed Jul 13 10:22:14 2005 +0000
     1.2 +++ b/mapeditor.cpp	Wed Jul 13 11:36:15 2005 +0000
     1.3 @@ -3388,8 +3388,7 @@
     1.4  	adjustCanvasSize();
     1.5  }
     1.6  
     1.7 -void 
     1.8 -MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) 
     1.9 +void MapEditor::contentsDragEnterEvent(QDragEnterEvent *event) 
    1.10  {
    1.11    if (selection && 
    1.12        (typeid(*selection) == typeid(BranchObj)) || 
    1.13 @@ -3401,39 +3400,97 @@
    1.14        return;
    1.15      }
    1.16      
    1.17 -    // If image are drag from firefox 
    1.18 +    // If image are dragged from firefox 
    1.19      if (event->provides("application/x-moz-file-promise-url") && 
    1.20  	event->provides("application/x-moz-nativeimage")) {
    1.21        event->accept(true);
    1.22        return;
    1.23      }
    1.24  
    1.25 +    // If QUriDrag can decode mime type 
    1.26 +    if (QUriDrag::canDecode(event)) {
    1.27 +      event->accept();
    1.28 +      return;
    1.29 +    }
    1.30 +    
    1.31 +	// If Uri are dragged from firefox 
    1.32 +    if (event->provides("text/x-moz-url") ){
    1.33 +      event->accept();
    1.34 +      return;
    1.35 +    }
    1.36    }
    1.37 -  
    1.38    event->ignore();
    1.39  }
    1.40        
    1.41 -void 
    1.42 -MapEditor::contentsDropEvent(QDropEvent *event) 
    1.43 +void MapEditor::contentsDropEvent(QDropEvent *event) 
    1.44  {
    1.45 -
    1.46 -  if (event->provides("image/png")) {
    1.47 -    QPixmap pix;
    1.48 -    if (QImageDrag::decode(event, pix)) {
    1.49 -      addFloatImage(pix);
    1.50 -      event->accept();
    1.51 -    } else
    1.52 -      event->ignore();
    1.53 -
    1.54 -  } else if (event->provides("application/x-moz-file-promise-url") && 
    1.55 -	     event->provides("application/x-moz-nativeimage")) {
    1.56 -    
    1.57 -    // Contains url to the img src in UTF-16
    1.58 -    QByteArray d = event->encodedData("application/x-moz-file-promise-url");
    1.59 -    QString url = QString((const QChar*)d.data(),d.size()/2);
    1.60 -    fetchImage(url);
    1.61 -    event->accept();
    1.62 -  }
    1.63 +	if (selection && 
    1.64 +      (typeid(*selection) == typeid(BranchObj)) || 
    1.65 +      (typeid(*selection) == typeid(MapCenterObj))) 
    1.66 +	{
    1.67 +		bool update=false;
    1.68 +		QStrList uris;
    1.69 +		if (event->provides("image/png")) 
    1.70 +		{
    1.71 +			QPixmap pix;
    1.72 +			if (QImageDrag::decode(event, pix)) 
    1.73 +			{
    1.74 +				addFloatImage(pix);
    1.75 +				event->accept();
    1.76 +				update=true;
    1.77 +			} else
    1.78 +				event->ignore();
    1.79 +
    1.80 +		} else if (event->provides("application/x-moz-file-promise-url") && 
    1.81 +			 event->provides("application/x-moz-nativeimage")) 
    1.82 +		{
    1.83 +			// Contains url to the img src in UTF-16
    1.84 +			QByteArray d = event->encodedData("application/x-moz-file-promise-url");
    1.85 +			QString url = QString((const QChar*)d.data(),d.size()/2);
    1.86 +			fetchImage(url);
    1.87 +			event->accept();
    1.88 +			update=true;
    1.89 +		} else if (event->provides ("text/uri-list"))
    1.90 +		{	// Uris provided e.g. by konqueror
    1.91 +			QUriDrag::decode (event,uris);
    1.92 +		} else if (event->provides ("text/x-moz-url-data"))
    1.93 +		{	// Uris provided by Mozilla
    1.94 +			QString str;
    1.95 +			QTextDrag::decode (event,str);
    1.96 +			uris.append(str);
    1.97 +		}
    1.98 +
    1.99 +		
   1.100 +		if (uris.count()>0)
   1.101 +		{
   1.102 +			QStringList files;
   1.103 +			QStringList urls;
   1.104 +			QString s;
   1.105 +			BranchObj *bo;
   1.106 +			for (const char* u=uris.first(); u; u=uris.next())
   1.107 +			{
   1.108 +				bo=((BranchObj*)(selection))->addBranch();
   1.109 +				if (bo)
   1.110 +				{
   1.111 +					s=QUriDrag::uriToLocalFile(u);
   1.112 +					if (s) 
   1.113 +						files.append(QDir::convertSeparators(s));
   1.114 +					else
   1.115 +						urls.append (u);
   1.116 +					bo->setHeading(u);
   1.117 +					bo->setURL (u);
   1.118 +				}
   1.119 +			}
   1.120 +			update=true;
   1.121 +		}
   1.122 +
   1.123 +		if (update) 
   1.124 +		{
   1.125 +			mapCenter->reposition();
   1.126 +			adjustCanvasSize();
   1.127 +			canvas()->update();
   1.128 +		}	
   1.129 +	}	
   1.130  }
   1.131  
   1.132  void MapEditor::addFloatImage(const QPixmap &img)