[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [patch]Bug 50138: copy paste images throughout
From:       Sven Langkamp <longamp () reallygood ! de>
Date:       2004-12-01 22:10:58
Message-ID: 200412012310.58602.longamp () reallygood ! de
[Download RAW message or body]

I ported the image drop code from KPresenter to KWord to fix bug 50138.
Patch is attached.

Sven

["imagedrop.diff" (text/x-diff)]

? kexi/migration/txt/Makefile
? kexi/migration/txt/Makefile.in
Index: kword/kwcanvas.cc
===================================================================
RCS file: /home/kde/koffice/kword/kwcanvas.cc,v
retrieving revision 1.459
diff -U3 -r1.459 kwcanvas.cc
--- kword/kwcanvas.cc	20 Oct 2004 21:31:42 -0000	1.459
+++ kword/kwcanvas.cc	1 Dec 2004 21:58:08 -0000
@@ -47,6 +47,10 @@
 #include <kapplication.h>
 #include <kmessagebox.h>
 #include <kmultipledrag.h>
+#include <kurl.h>
+#include <kurldrag.h>
+#include <kio/netaccess.h>
+#include <kmimemagic.h>
 
 #include <assert.h>
 
@@ -2265,7 +2269,7 @@
 {
     bool providesImage, providesKWordText, providesKWord, providesFormula;
     KWView::checkClipboard( e, providesImage, providesKWordText, providesKWord, \
                providesFormula );
-    if ( providesImage )
+    if ( providesImage || KURLDrag::canDecode( e ) )
     {
         m_imageDrag = true;
         e->acceptAction();
@@ -2312,9 +2316,47 @@
 {
     QPoint normalPoint = m_viewMode->viewToNormal( e->pos() );
     KoPoint docPoint = m_doc->unzoomPoint( normalPoint );
-    if ( m_imageDrag )
-    {
+
+    if ( QImageDrag::canDecode( e ) ) {
         pasteImage( e, docPoint );
+    } else if ( KURLDrag::canDecode( e ) ) {
+
+        KURL::List lst;
+        KURLDrag::decode( e, lst );
+
+        KURL::List::ConstIterator it = lst.begin();
+        for ( ; it != lst.end(); ++it ) {
+            const KURL &url( *it );
+
+            QString filename;
+            if ( !url.isLocalFile() ) {
+                if ( !KIO::NetAccess::download( url, filename, this ) )
+                    continue;
+            } else {
+                filename = url.path();
+            }
+
+            KMimeMagicResult *res = KMimeMagic::self()->findFileType( filename );
+
+            if ( res && res->isValid() ) {
+                QString mimetype = res->mimeType();
+                if ( mimetype.contains( "image" ) ) {
+                    QImage i( filename );
+                    m_pixmapSize = i.size();
+                    // Prepare things for mrCreatePixmap
+                    KoPictureKey key;
+                    key.setKeyFromFile( filename );
+                    KoPicture newKoPicture;
+                    newKoPicture.setKey( key );
+                    newKoPicture.loadFromFile( filename );
+                    m_kopicture = newKoPicture;
+                    m_insRect = KoRect( docPoint.x(), docPoint.y(), \
m_doc->unzoomItX( i.width() ), m_doc->unzoomItY( i.height() ) ); +                    \
m_keepRatio = true; +                    mrCreatePixmap();
+                }
+            }
+            KIO::NetAccess::removeTempFile( filename );
+        }
     }
     else if ( m_currentFrameSetEdit )
     {



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic