]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Jippie: file previews are generated again! Thanks to Fredrik for giving me a hint...
authorPeter Penz <peter.penz19@gmail.com>
Wed, 28 Feb 2007 19:17:26 +0000 (19:17 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 28 Feb 2007 19:17:26 +0000 (19:17 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=638081

src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/dolphinview.cpp
src/dolphinview.h
src/iconsviewsettingspage.cpp

index 8089cfd2b1451dbc4596b2d5c05eb59e0cf8b813..e1d4c48e344f28e4b201238a029d48e7e683b73a 100644 (file)
@@ -20,7 +20,8 @@
 #include "dolphincontroller.h"
 
 DolphinController::DolphinController(QObject* parent) :
-    QObject(parent)
+    QObject(parent),
+    m_showPreview(false)
 {
 }
 
@@ -56,6 +57,14 @@ void DolphinController::indicateSortOrderChange(Qt::SortOrder order)
     emit sortOrderChanged(order);
 }
 
+void DolphinController::setShowPreview(bool showPreview)
+{
+    if (m_showPreview != showPreview) {
+        m_showPreview = showPreview;
+        emit showPreviewChanged(showPreview);
+    }
+}
+
 void DolphinController::triggerItem(const QModelIndex& index)
 {
     emit itemTriggered(index);
index bde01c28ecd378f7cfe5ebbf402156905842c288..08d12ea575e95fff8f982a659e228f3fd6bc3a22 100644 (file)
@@ -67,6 +67,9 @@ public:
 
     void indicateSortOrderChange(Qt::SortOrder order);
 
+    void setShowPreview(bool showPreview);
+    bool showPreview() const { return m_showPreview; }
+
 public slots:
     void triggerItem(const QModelIndex& index);
     void indicateSelectionChange();
@@ -102,6 +105,12 @@ signals:
     /** Is emitted if the sort order has been changed to \a sort order. */
     void sortOrderChanged(Qt::SortOrder order);
 
+    /**
+     * Is emitted if the state for showing previews has been
+     * changed to \a showPreview.
+     */
+    void showPreviewChanged(bool showPreview);
+
     /**
      * Is emitted if the item with the index \a index should be triggered.
      * Usually triggering on a directory opens the directory, triggering
@@ -113,6 +122,7 @@ signals:
     void selectionChanged();
 
 private:
+    bool m_showPreview;
     KUrl m_url;
 };
 
index d227e70c926b8f9e97c739f364bb49e09ff22999..1cf68c2e2ce61a36646c0d55100e196e22cdd663 100644 (file)
@@ -57,7 +57,7 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
     connect(this, SIGNAL(clicked(const QModelIndex&)),
             controller, SLOT(triggerItem(const QModelIndex&)));
 
-   // apply the details mode settings to the widget
+    // apply the details mode settings to the widget
     const DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
     assert(settings != 0);
 
index a6da79836c0b7df95ad5cfd42ea67e6c5668006e..a9328172d19c2cf9779abb8af837f054f2da8ac1 100644 (file)
@@ -34,24 +34,24 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     QListView(parent),
     m_controller(controller)
 {
-    assert(controller != 0);
+    Q_ASSERT(controller != 0);
     setViewMode(QListView::IconMode);
     setResizeMode(QListView::Adjust);
 
     connect(this, SIGNAL(clicked(const QModelIndex&)),
             controller, SLOT(triggerItem(const QModelIndex&)));
+    connect(controller, SIGNAL(showPreviewChanged(bool)),
+            this, SLOT(updateGridSize(bool)));
 
     // apply the icons mode settings to the widget
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    assert(settings != 0);
+    Q_ASSERT(settings != 0);
 
-    setGridSize(QSize(settings->gridWidth(), settings->gridHeight()));
     setSpacing(settings->gridSpacing());
 
     m_viewOptions = QListView::viewOptions();
     m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
-    const int iconSize = settings->iconSize();
-    m_viewOptions.decorationSize = QSize(iconSize, iconSize);
+    updateGridSize(controller->showPreview());
 
     if (settings->arrangement() == QListView::TopToBottom) {
         setFlow(QListView::LeftToRight);
@@ -103,4 +103,28 @@ void DolphinIconsView::dropEvent(QDropEvent* event)
     }
 }
 
+void DolphinIconsView::updateGridSize(bool showPreview)
+{
+    const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    Q_ASSERT(settings != 0);
+
+    int gridWidth = settings->gridWidth();
+    int gridHeight = settings->gridHeight();
+    int size = settings->iconSize();
+
+    if (showPreview) {
+        const int previewSize = settings->previewSize();
+        const int diff = previewSize - size;
+        Q_ASSERT(diff >= 0);
+        gridWidth += diff;
+        gridHeight += diff;
+
+        size = previewSize;
+     }
+
+
+    m_viewOptions.decorationSize = QSize(size, size);
+    setGridSize(QSize(gridWidth, gridHeight));
+}
+
 #include "dolphiniconsview.moc"
index 91faf344a412894728bc43acac0f25f128e2aaa2..22da7de21adc2f3bc093ff90155354f204a1a3d2 100644 (file)
@@ -47,6 +47,13 @@ protected:
     virtual void dragEnterEvent(QDragEnterEvent* event);
     virtual void dropEvent(QDropEvent* event);
 
+private slots:
+    /**
+     * Updates the size of the grid
+     * depending on the state of \a showPreview.
+     */
+    void updateGridSize(bool showPreview);
+
 private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
index 7a0ff6c6a59112d2d11c0a2b9a5e15289cabf0b7..edb57ef7f3e96ba60c9d02fda3c5221666c9af6a 100644 (file)
@@ -250,6 +250,13 @@ void DolphinMainWindow::slotViewModeChanged()
     updateViewActions();\r
 }\r
 \r
+void DolphinMainWindow::slowShowPreviewChanged()\r
+{\r
+    KToggleAction* showPreviewAction =\r
+        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));\r
+    showPreviewAction->setChecked(m_activeView->showPreview());\r
+}\r
+\r
 void DolphinMainWindow::slotShowHiddenFilesChanged()\r
 {\r
     KToggleAction* showHiddenFilesAction =\r
@@ -1290,6 +1297,10 @@ void DolphinMainWindow::updateViewActions()
         static_cast<KToggleAction*>(actionCollection()->action("show_filter_bar"));\r
     showFilterBarAction->setChecked(m_activeView->isFilterBarVisible());\r
 \r
+    KToggleAction* showPreviewAction =\r
+        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));\r
+    showPreviewAction->setChecked(m_activeView->showPreview());\r
+\r
     KToggleAction* showHiddenFilesAction =\r
         static_cast<KToggleAction*>(actionCollection()->action("show_hidden_files"));\r
     showHiddenFilesAction->setChecked(m_activeView->showHiddenFiles());\r
@@ -1337,6 +1348,8 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
     DolphinView* view = m_view[viewIndex];\r
     connect(view, SIGNAL(modeChanged()),\r
             this, SLOT(slotViewModeChanged()));\r
+    connect(view, SIGNAL(showPreviewChanged()),\r
+            this, SLOT(slowShowPreviewChanged()));\r
     connect(view, SIGNAL(showHiddenFilesChanged()),\r
             this, SLOT(slotShowHiddenFilesChanged()));\r
     connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),\r
index 7a71b685c2905801308b1d10ab0fea543be405f6..1b33c8cb06488cd16ebbcb671ac555c0cdccff47 100644 (file)
@@ -319,6 +319,9 @@ private slots:
     /** Updates the state of all 'View' menu actions. */
     void slotViewModeChanged();
 
+    /** Updates the state of the 'Show preview' menu action. */
+    void slowShowPreviewChanged();
+
     /** Updates the state of the 'Show hidden files' menu action. */
     void slotShowHiddenFilesChanged();
 
index 5ec8c901eecb9b86432aee5c7c7ba1725d7c5b29..bcbb637ad1fc8a2072657d1283461813ccf0ef01 100644 (file)
@@ -33,6 +33,7 @@
 #include <klocale.h>
 #include <kio/netaccess.h>
 #include <kio/renamedialog.h>
+#include <kio/previewjob.h>
 #include <kmimetyperesolver.h>
 #include <konq_operations.h>
 #include <kurl.h>
@@ -108,6 +109,8 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
             this, SLOT(updateStatusBar()));
     connect(m_dirLister, SIGNAL(completed()),
             this, SLOT(updateItemCount()));
+    connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)),
+            this, SLOT(generatePreviews(const KFileItemList&)));
     connect(m_dirLister, SIGNAL(infoMessage(const QString&)),
             this, SLOT(showInfoMessage(const QString&)));
     connect(m_dirLister, SIGNAL(errorMessage(const QString&)),
@@ -204,15 +207,15 @@ void DolphinView::setShowPreview(bool show)
     ViewProperties props(m_urlNavigator->url());
     props.setShowPreview(show);
 
-    // TODO: wait until previews are possible with KFileItemDelegate
+    m_controller->setShowPreview(show);
 
     emit showPreviewChanged();
+    reload();
 }
 
 bool DolphinView::showPreview() const
 {
-    // TODO: wait until previews are possible with KFileItemDelegate
-    return true;
+    return m_controller->showPreview();
 }
 
 void DolphinView::setShowHiddenFiles(bool show)
@@ -456,7 +459,7 @@ KFileItemList DolphinView::selectedItems() const
 
     // Our view has a selection, we will map them back to the DirModel
     // and then fill the KFileItemList.
-    assert((view != 0) && (view->selectionModel() != 0));
+    Q_ASSERT((view != 0) && (view->selectionModel() != 0));
 
     const QItemSelection selection = m_proxyModel->mapSelectionToSource(view->selectionModel()->selection());
     KFileItemList itemList;
@@ -464,7 +467,7 @@ KFileItemList DolphinView::selectedItems() const
     const QModelIndexList indexList = selection.indexes();
     QModelIndexList::const_iterator end = indexList.end();
     for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
-        assert((*it).isValid());
+        Q_ASSERT((*it).isValid());
 
         KFileItem* item = m_dirModel->itemForIndex(*it);
         if (item != 0) {
@@ -603,7 +606,11 @@ void DolphinView::loadDirectory(const KUrl& url)
         emit sortOrderChanged(sortOrder);
     }
 
-    // TODO: handle previews (props.showPreview())
+    const bool showPreview = props.showPreview();
+    if (showPreview != m_controller->showPreview()) {
+        m_controller->setShowPreview(showPreview);
+        emit showPreviewChanged();
+    }
 
     startDirLister(url);
     emit urlChanged(url);
@@ -682,6 +689,23 @@ void DolphinView::updateItemCount()
     QTimer::singleShot(0, this, SLOT(restoreContentsPos()));
 }
 
+void DolphinView::generatePreviews(const KFileItemList& items)
+{
+    if (m_controller->showPreview()) {
+        KIO::PreviewJob* job = KIO::filePreview(items, 128);
+        connect(job, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
+                this, SLOT(showPreview(const KFileItem*, const QPixmap&)));
+    }
+}
+
+void DolphinView::showPreview(const KFileItem* item, const QPixmap& pixmap)
+{
+    const QModelIndex idx = m_dirModel->indexForItem(item);
+    Q_ASSERT(idx.isValid());
+    Q_ASSERT(idx.column() == 0);
+    m_dirModel->setData(idx, pixmap, Qt::DecorationRole);
+}
+
 void DolphinView::restoreContentsPos()
 {
     int index = 0;
@@ -991,7 +1015,7 @@ void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
 
 QAbstractItemView* DolphinView::itemView() const
 {
-    assert((m_iconsView == 0) || (m_detailsView == 0));
+    Q_ASSERT((m_iconsView == 0) || (m_detailsView == 0));
     if (m_detailsView != 0) {
         return m_detailsView;
     }
index cffa52880d5722095c716f6fac543bca5a0c9d78..63ceb983a9f1ca4346f1289255ef22fc7e6134de 100644 (file)
@@ -404,6 +404,19 @@ private slots:
      */
     void updateItemCount();
 
+    /**
+     * Generates a preview image for each file item in \a items.
+     * The current preview settings (maximum size, 'Show Preview' menu)
+     * are respected.
+     */
+    void generatePreviews(const KFileItemList& items);
+
+    /**
+     * Replaces the icon of the item \a item by the preview pixmap
+     * \a pixmap.
+     */
+    void showPreview(const KFileItem* item, const QPixmap& pixmap);
+
     /**
      * Restores the x- and y-position of the contents if the
      * current view is part of the history.
index f4c8de577a0d5ee7803ecfc749f48335c42e7e6d..743ca936b7a2c363dd72a2a3fbe32173d937d545 100644 (file)
@@ -184,9 +184,7 @@ void IconsViewSettingsPage::applySettings()
     const int defaultSize = iconSize(m_iconSizeSlider->value());
     settings->setIconSize(defaultSize);
 
-    int previewSize = //(m_mode == DolphinIconsView::Previews) ?
-                      //iconSize(m_previewSizeSlider->value()) :
-                      defaultSize;
+    int previewSize = iconSize(m_previewSizeSlider->value());
     if (previewSize < defaultSize) {
         // assure that the preview size is never smaller than the icon size
         previewSize = defaultSize;