added drag and drop of URLs rel-1-7-0
authorinsilmaril
Wed, 13 Jul 2005 11:36:15 +0000
changeset 1280dc9286ad3d4
parent 127 ebfc893dde31
child 129 9b9c7e8b9147
added drag and drop of URLs
mapeditor.cpp
tex/vym.tex
version.h
     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) 
     2.1 --- a/tex/vym.tex	Wed Jul 13 10:22:14 2005 +0000
     2.2 +++ b/tex/vym.tex	Wed Jul 13 11:36:15 2005 +0000
     2.3 @@ -470,7 +470,7 @@
     2.4  	\includegraphics[width=0.5cm]{flag-url.png}
     2.5  \end{center}
     2.6  If you want to keep bookmarks in a map, select a branch where you want
     2.7 -to add the bookmark, than simply drag the URL from your browser to the
     2.8 +to add the bookmark, then simply drag the URL from your browser to the
     2.9  map. Also you could use an existing heading as URL: Right click onto the
    2.10  branch and select "Use heading for URL".
    2.11  
    2.12 @@ -691,7 +691,7 @@
    2.13  be stored in the same directory.
    2.14  
    2.15  \subsubsection*{Export a part of a map}
    2.16 -Select a branch you want to export together with its childs, than open
    2.17 +Select a branch you want to export together with its childs, then open
    2.18  the context menu and choose {\em Save Selection}. This will create a
    2.19  file with the postfix {\tt .vyp}, which is an abbreviation for \lq vym
    2.20  part\rq.
     3.1 --- a/version.h	Wed Jul 13 10:22:14 2005 +0000
     3.2 +++ b/version.h	Wed Jul 13 11:36:15 2005 +0000
     3.3 @@ -2,6 +2,6 @@
     3.4  #define VERSION_H
     3.5  
     3.6  #define __VYM_VERSION__ "1.7.0"
     3.7 -#define __BUILD_DATE__ "July 12, 2005"
     3.8 +#define __BUILD_DATE__ "July 13, 2005"
     3.9  
    3.10  #endif