[Digikam-devel] extragear/graphics/digikam/utilities/imageeditor/editor

Gilles Caulier caulier.gilles at gmail.com
Thu May 24 13:33:32 BST 2007


SVN commit 667911 by cgilles:

digikam from trunk : Image Editor now support Drag & Drop from Album Gui or Light Table. Accepted object are Physicals Albums, Items selection, and Tags Albums.
CCMAIL: digikam-devel at kde.org

 M  +130 -1    imagewindow.cpp  
 M  +7 -1      imagewindow.h  


--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/imagewindow.cpp #667910:667911
@@ -64,6 +64,7 @@
 #include "constants.h"
 #include "ddebug.h"
 #include "dpopupmenu.h"
+#include "dragobjects.h"
 #include "canvas.h"
 #include "dimginterface.h"
 #include "themeengine.h"
@@ -164,6 +165,7 @@
 {
     d = new ImageWindowPriv;
     m_instance = this;
+    setAcceptDrops(true); 
 
     // -- Build the GUI -------------------------------
 
@@ -263,6 +265,9 @@
 
     connect(ThemeEngine::instance(), SIGNAL(signalThemeChanged()),
             this, SLOT(slotThemeChanged()));
+
+    connect(m_canvas, SIGNAL(signalDroppedEvent(QDropEvent *)),
+            this, SLOT(slotDroppedEvent(QDropEvent *)));
 }
 
 void ImageWindow::setupUserArea()
@@ -436,7 +441,10 @@
         KWin::deIconifyWindow(winId());
     }
 
-    setCaption(i18n("digiKam Image Editor - %1").arg(caption));
+    if (!caption.isEmpty())
+        setCaption(i18n("Image Editor - %1").arg(caption));
+    else
+        setCaption(i18n("Image Editor"));
 
     d->allowSaving = allowSaving;
 
@@ -1081,6 +1089,127 @@
     }
 }
 
+void ImageWindow::dragMoveEvent(QDragMoveEvent *e)
+{
+    int             albumID;
+    QValueList<int> albumIDs;
+    QValueList<int> imageIDs;
+    KURL::List      urls;
+    KURL::List      kioURLs;        
+
+    if (ItemDrag::decode(e, urls, kioURLs, albumIDs, imageIDs) ||
+        AlbumDrag::decode(e, urls, albumID) ||
+        TagDrag::canDecode(e))
+    {
+        e->accept();
+        return;
+    }
+
+    e->ignore();
+}
+
+void ImageWindow::dropEvent(QDropEvent *e)
+{
+    int             albumID;
+    QValueList<int> albumIDs;
+    QValueList<int> imageIDs;
+    KURL::List      urls;
+    KURL::List      kioURLs;        
+
+    if (ItemDrag::decode(e, urls, kioURLs, albumIDs, imageIDs))
+    {
+        ImageInfoList imageInfoList;
+
+        for (QValueList<int>::const_iterator it = imageIDs.begin();
+             it != imageIDs.end(); ++it)
+        {
+            ImageInfo *info = new ImageInfo(*it);
+            imageInfoList.append(info);
+        }
+
+        if (imageInfoList.isEmpty())
+        {
+            e->ignore();
+            return;
+        }
+
+        QString ATitle;
+        AlbumManager* man  = AlbumManager::instance();
+        PAlbum* palbum     = man->findPAlbum(albumIDs.first());
+        if (palbum) ATitle = palbum->title();  
+
+        TAlbum* talbum     = man->findTAlbum(albumIDs.first());
+        if (talbum) ATitle = talbum->title();  
+
+        loadImageInfos(imageInfoList, imageInfoList.first(), 
+                       i18n("Album \"%1\"").arg(ATitle), true);
+        e->accept();
+    }
+    else if (AlbumDrag::decode(e, urls, albumID))
+    {
+        AlbumManager* man           = AlbumManager::instance();
+        QValueList<Q_LLONG> itemIDs = man->albumDB()->getItemIDsInAlbum(albumID);
+        ImageInfoList imageInfoList;
+
+        for (QValueList<Q_LLONG>::const_iterator it = itemIDs.begin();
+             it != itemIDs.end(); ++it)
+        {
+            ImageInfo *info = new ImageInfo(*it);
+            imageInfoList.append(info);
+        }
+
+        if (imageInfoList.isEmpty())
+        {
+            e->ignore();
+            return;
+        }
+
+        QString ATitle;
+        PAlbum* palbum     = man->findPAlbum(albumIDs.first());
+        if (palbum) ATitle = palbum->title();  
+
+        loadImageInfos(imageInfoList, imageInfoList.first(), 
+                       i18n("Album \"%1\"").arg(ATitle), true);
+        e->accept();
+    }
+    else if(TagDrag::canDecode(e))
+    {
+        QByteArray ba = e->encodedData("digikam/tag-id");
+        QDataStream ds(ba, IO_ReadOnly);
+        int tagID;
+        ds >> tagID;
+
+        AlbumManager* man           = AlbumManager::instance();
+        QValueList<Q_LLONG> itemIDs = man->albumDB()->getItemIDsInTag(tagID);
+        ImageInfoList imageInfoList;
+
+        for (QValueList<Q_LLONG>::const_iterator it = itemIDs.begin();
+             it != itemIDs.end(); ++it)
+        {
+            ImageInfo *info = new ImageInfo(*it);
+            imageInfoList.append(info);
+        }
+
+        if (imageInfoList.isEmpty())
+        {
+            e->ignore();
+            return;
+        }
+
+        QString ATitle;
+        TAlbum* talbum     = man->findTAlbum(tagID);
+        if (talbum) ATitle = talbum->title();  
+
+        loadImageInfos(imageInfoList, imageInfoList.first(), 
+                       i18n("Album \"%1\"").arg(ATitle), true);
+        e->accept();
+    }   
+    else 
+    {
+        e->ignore();
+    }
+}
+
 }  // namespace Digikam
 
 
--- trunk/extragear/graphics/digikam/utilities/imageeditor/editor/imagewindow.h #667910:667911
@@ -38,6 +38,9 @@
 #include "editorwindow.h"
 #include "imageinfo.h"
 
+class QDragMoveEvent;
+class QDropEvent;
+
 namespace Digikam
 {
 
@@ -80,6 +83,9 @@
 
     void loadCurrentList(const QString& caption, bool allowSaving);
     void closeEvent(QCloseEvent* e);
+    
+    void dragMoveEvent(QDragMoveEvent *e);
+    void dropEvent(QDropEvent *e);
 
     void setupActions();
     void setupConnections();
@@ -122,7 +128,7 @@
     void slotRemoveTag(int tagID);
     void slotAssignRating(int rating);
 
-    void slotFileMetadataChanged(const KURL &url);
+    void slotFileMetadataChanged(const KURL &);
 
     void slotThemeChanged();
 



More information about the Digikam-devel mailing list