[Kde-imaging] extragear/libs/libkipi/libkipi

Gilles Caulier caulier.gilles at gmail.com
Thu Nov 22 14:03:28 CET 2007


SVN commit 740062 by cgilles:

kipi-plugins from trunk (KDE4) : improvement of ImageDialog again : now preview of pictures is generated by kipi host
RAW files preview can be displayed properlly.
CCMAIL: kde-imaging at kde.org


 M  +129 -11   imagedialog.cpp  
 M  +32 -1     imagedialog.h  


--- trunk/extragear/libs/libkipi/libkipi/imagedialog.cpp #740061:740062
@@ -20,6 +20,11 @@
  * 
  * ============================================================ */
 
+// Qt includes.
+
+#include <QLabel>
+#include <QLayout>
+
 // KDE includes.
 
 #include <kdebug.h>
@@ -36,15 +41,118 @@
 // Local includes.
 
 #include "version.h"
-#include "interface.h"
 #include "imagecollection.h"
 #include "imagedialog.h"
+#include "imagedialog.moc"
 
 namespace KIPI
 {
 
+class ImageDialogPreviewPrivate 
+{
+
+public:
+
+    ImageDialogPreviewPrivate()
+    {
+        imageLabel = 0;
+        iface      = 0;
+    }
+
+    QLabel          *imageLabel;
+
+    KUrl             currentURL;
+
+    KIPI::Interface *iface;
+};
+
+ImageDialogPreview::ImageDialogPreview(KIPI::Interface *iface, QWidget *parent)
+                  : KPreviewWidgetBase(parent)
+{
+    d = new ImageDialogPreviewPrivate;
+    d->iface = iface;
+
+    QVBoxLayout *vlay = new QVBoxLayout(this);
+    d->imageLabel     = new QLabel(this);
+    d->imageLabel->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
+    d->imageLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+
+    vlay->setMargin(0);
+    vlay->setSpacing(KDialog::spacingHint());
+    vlay->addWidget(d->imageLabel);
+
+    setSupportedMimeTypes(KImageIO::mimeTypes());
+    setMinimumWidth(64);
+
+    connect(d->iface, SIGNAL(gotThumbnail( const KUrl&, const QPixmap& )),
+            this, SLOT(slotThumbnail(const KUrl&, const QPixmap&)));
+}
+
+ImageDialogPreview::~ImageDialogPreview() 
+{
+    delete d;
+}
+
+QSize ImageDialogPreview::sizeHint() const
+{
+    return QSize(100, 200);
+}
+
+void ImageDialogPreview::resizeEvent(QResizeEvent *)
+{
+    QMetaObject::invokeMethod(this, "showPreview", Qt::QueuedConnection);
+}
+
+void ImageDialogPreview::showPreview()
+{
+    KUrl url(d->currentURL);
+    clearPreview();
+    showPreview(url);
+}
+
+void ImageDialogPreview::showPreview(const KUrl& url)
+{
+    if (!url.isValid()) 
+    {
+        clearPreview();
+        return;
+    }
+    
+    if (url != d->currentURL) 
+    {
+        clearPreview();
+        d->currentURL = url;
+        d->iface->thumbnail(d->currentURL, 256);
+    }
+}
+
+void ImageDialogPreview::slotThumbnail(const KUrl& url, const QPixmap& pix)
+{
+    if (url == d->currentURL)
+    {
+        QPixmap pixmap;
+        QSize s = d->imageLabel->contentsRect().size();
+
+        if (s.width() < pix.width() || s.height() < pix.height())
+            pixmap = pix.scaled(s, Qt::KeepAspectRatio);
+        else 
+            pixmap = pix;
+
+        d->imageLabel->setPixmap(pixmap);
+    }
+}
+
+void ImageDialogPreview::clearPreview()
+{
+    d->imageLabel->clear();
+    d->currentURL = KUrl();
+}
+
+// ------------------------------------------------------------------------
+
 class ImageDialogPrivate 
 {
+
 public:
 
     ImageDialogPrivate()
@@ -53,17 +161,17 @@
         iface        = 0;
     }
 
-    bool             singleSelect;
+    bool                singleSelect;
 
-    QString          fileformats;
+    QString             fileformats;
 
-    KUrl             url;
-    KUrl::List       urls;
+    KUrl                url;
+    KUrl::List          urls;
 
-    KIPI::Interface *iface;
+    KIPI::Interface    *iface;
 };
 
-ImageDialog::ImageDialog(QWidget* parent, KIPI::Interface* iface, bool singleSelect)
+ImageDialog::ImageDialog(QWidget* parent, Interface* iface, bool singleSelect)
 {
     d = new ImageDialogPrivate;
     d->iface        = iface;
@@ -90,15 +198,25 @@
     
     d->fileformats = patternList.join("\n");
 
+    KFileDialog dlg(d->iface->currentAlbum().path(), d->fileformats, parent);
+    ImageDialogPreview *preview = new ImageDialogPreview(d->iface, &dlg);
+    dlg.setPreviewWidget(preview);
+    dlg.setOperationMode( KFileDialog::Opening );
+
     if (singleSelect)
     {
-        d->url = KFileDialog::getOpenUrl(d->iface->currentAlbum().path(), 
-                                         d->fileformats, parent, i18n("Select an Image"));
+        dlg.setMode( KFile::File );
+        dlg.setWindowTitle(i18n("Select an Image"));
+        dlg.exec();
+        d->url = dlg.selectedUrl();
+    
     }
     else
     {
-        d->urls = KFileDialog::getOpenUrls(d->iface->currentAlbum().path(), 
-                                           d->fileformats, parent, i18n("Select Images"));
+        dlg.setMode( KFile::Files );
+        dlg.setWindowTitle(i18n("Select Images"));
+        dlg.exec();
+        d->urls = dlg.selectedUrls();
     }
 }
 
--- trunk/extragear/libs/libkipi/libkipi/imagedialog.h #740061:740062
@@ -27,26 +27,57 @@
 
 #include <QtCore/QList>
 #include <QtGui/QWidget>
+#include <QStringList>
 
 // KDE includes.
 
 #include <kurl.h>
+#include <kpreviewwidgetbase.h>
 
 // LibKipi includes.
 
+#include "interface.h"
 #include "libkipi_export.h"
 
 namespace KIPI
 {
 
 class ImageDialogPrivate;
+class ImageDialogPreviewPrivate;
 
+class LIBKIPI_EXPORT ImageDialogPreview : public KPreviewWidgetBase
+{
+    Q_OBJECT
+
+public:
+
+    ImageDialogPreview(Interface *iface, QWidget *parent=0);
+    ~ImageDialogPreview();
+
+    QSize sizeHint() const;
+
+private slots:
+
+    void showPreview();
+    void showPreview(const KUrl &url);
+    void slotThumbnail(const KUrl& url, const QPixmap& pix);
+    void clearPreview();
+
+private:
+
+    void resizeEvent(QResizeEvent *e);
+
+private:
+
+    class ImageDialogPreviewPrivate *d;
+};
+
 class LIBKIPI_EXPORT ImageDialog
 {
 
 public:
 
-    ImageDialog(QWidget*, Interface*, bool singleSelection=false);
+    ImageDialog(QWidget* parent, Interface* iface, bool singleSelection=false);
     ~ImageDialog();
 
     KUrl       url() const;


More information about the Kde-imaging mailing list