]> cloud.milkyroute.net Git - dolphin.git/commitdiff
First step of refactoring to improve the zooming capabilities of views:
authorPeter Penz <peter.penz19@gmail.com>
Tue, 5 Aug 2008 20:15:51 +0000 (20:15 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 5 Aug 2008 20:15:51 +0000 (20:15 +0000)
* Let classes that use DolphinView know about the currently used zoom level.

* Provide more zoom levels for all views (the settings dialogs have not been adjusted yet).

* Fixed issue that when using the wheel that the enabled state of the zoom actions has not been updated.

svn path=/trunk/KDE/kdebase/apps/; revision=842715

13 files changed:
src/dolphincolumnview.cpp
src/dolphincolumnview.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphindetailsview.h
src/dolphiniconsview.cpp
src/dolphiniconsview.h
src/dolphinview.cpp
src/dolphinview.h
src/dolphinviewactionhandler.cpp
src/dolphinviewactionhandler.h
src/iconmanager.cpp

index 6d4801aeaa372c1baeba15e4008fe8026c7b59d6..8ca4a6a9bd96ebd3dc24c90a475ab53746b3376c 100644 (file)
@@ -51,10 +51,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
 
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
-    connect(controller, SIGNAL(zoomIn()),
-            this, SLOT(zoomIn()));
-    connect(controller, SIGNAL(zoomOut()),
-            this, SLOT(zoomOut()));
+    connect(controller, SIGNAL(zoomLevelChanged(int)),
+            this, SLOT(setZoomLevel(int)));
     connect(controller, SIGNAL(activationChanged(bool)),
             this, SLOT(updateColumnsBackground(bool)));
 
@@ -367,30 +365,13 @@ void DolphinColumnView::wheelEvent(QWheelEvent* event)
     QAbstractItemView::wheelEvent(event);
 }
 
-void DolphinColumnView::zoomIn()
+void DolphinColumnView::setZoomLevel(int level)
 {
-    if (isZoomInPossible()) {
-        ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeSmall:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
-}
-
-void DolphinColumnView::zoomOut()
-{
-    if (isZoomOutPossible()) {
-        ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeLarge:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
+    const int size = DolphinController::iconSizeForZoomLevel(level);
+    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
+    settings->setIconSize(size);
+    
+    updateDecorationSize();
 }
 
 void DolphinColumnView::moveContentHorizontally(int x)
@@ -413,9 +394,6 @@ void DolphinColumnView::updateDecorationSize()
         }
     }
 
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
-
     doItemsLayout();
 }
 
@@ -471,18 +449,6 @@ void DolphinColumnView::slotShowPreviewChanged()
     }
 }
 
-bool DolphinColumnView::isZoomInPossible() const
-{
-    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    return settings->iconSize() < KIconLoader::SizeLarge;
-}
-
-bool DolphinColumnView::isZoomOutPossible() const
-{
-    ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();
-    return settings->iconSize() > KIconLoader::SizeSmall;
-}
-
 void DolphinColumnView::setActiveColumnIndex(int index)
 {
     if (m_index == index) {
index 24353ad34e7ef1cf31305c36495c89d307141049..c563888b99d3ead46b85c3d52fe52004d2fd2db4 100644 (file)
@@ -130,8 +130,7 @@ protected:
     virtual void wheelEvent(QWheelEvent* event);
 
 private slots:
-    void zoomIn();
-    void zoomOut();
+    void setZoomLevel(int level);
 
     /**
      * Moves the content of the columns view to represent
@@ -159,9 +158,6 @@ private slots:
     void slotShowPreviewChanged();
 
 private:
-    bool isZoomInPossible() const;
-    bool isZoomOutPossible() const;
-
     DolphinColumnWidget* activeColumn() const;
 
     /**
index 375eb44035736f06e5394be24098efc5a9b3ba0b..edc5dad9895eaba161bdba290918f28246947f81 100644 (file)
@@ -27,8 +27,7 @@
 
 DolphinController::DolphinController(DolphinView* dolphinView) :
     QObject(dolphinView),
-    m_zoomInPossible(false),
-    m_zoomOutPossible(false),
+    m_zoomLevel(0),
     m_openTab(false),
     m_url(),
     m_dolphinView(dolphinView),
@@ -58,6 +57,17 @@ void DolphinController::setItemView(QAbstractItemView* view)
     m_itemView = view;
 
     if (m_itemView != 0) {
+        switch (m_itemView->iconSize().height()) {
+        case KIconLoader::SizeSmallMedium:      m_zoomLevel = 0; break;
+        case KIconLoader::SizeMedium:           m_zoomLevel = 1; break;
+        case KIconLoader::SizeLarge:            m_zoomLevel = 2; break;
+        case KIconLoader::SizeHuge:             m_zoomLevel = 3; break;
+        case KIconLoader::SizeEnormous:         m_zoomLevel = 4; break;
+        case KIconLoader::SizeEnormous * 3 / 2: m_zoomLevel = 5; break;
+        case KIconLoader::SizeEnormous * 2:     m_zoomLevel = 6; break;
+        default: Q_ASSERT(false);               m_zoomLevel = 2; break;
+        }
+        
         // TODO: this is a workaround until  Qt-issue 176832 has been fixed
         connect(m_itemView, SIGNAL(pressed(const QModelIndex&)),
                 this, SLOT(updateOpenTabState()));
@@ -110,14 +120,30 @@ void DolphinController::indicateActivationChange(bool active)
     emit activationChanged(active);
 }
 
-void DolphinController::triggerZoomIn()
+void DolphinController::setZoomLevel(int level)
 {
-    emit zoomIn();
+    Q_ASSERT(level >= zoomLevelMinimum());
+    Q_ASSERT(level <= zoomLevelMaximum());
+    if (level != m_zoomLevel) {
+        m_zoomLevel = level;
+        emit zoomLevelChanged(m_zoomLevel);
+    }
 }
 
-void DolphinController::triggerZoomOut()
+int DolphinController::iconSizeForZoomLevel(int level)
 {
-    emit zoomOut();
+    int size = KIconLoader::SizeMedium;
+    switch (level) {
+    case 0: size = KIconLoader::SizeSmallMedium; break;
+    case 1: size = KIconLoader::SizeMedium; break;
+    case 2: size = KIconLoader::SizeLarge; break;
+    case 3: size = KIconLoader::SizeHuge; break;
+    case 4: size = KIconLoader::SizeEnormous; break;
+    case 5: size = KIconLoader::SizeEnormous * 3 / 2; break;
+    case 6: size = KIconLoader::SizeEnormous * 2; break;
+    default: Q_ASSERT(false); break;
+    }
+    return size;
 }
 
 void DolphinController::handleKeyPressEvent(QKeyEvent* event)
index d5e9325d360616bd932b5c4f89c931cae912bdf4..4e8885ef920b3d80d1aadf2a11f5a11cb8afd573 100644 (file)
@@ -59,8 +59,6 @@ class QWidget;
  * - indicateDroppedUrls()
  * - indicateSortingChange()
  * - indicateSortOrderChanged()
- * - setZoomInPossible()
- * - setZoomOutPossible()
  * - triggerItem()
  * - handleKeyPressEvent()
  * - emitItemEntered()
@@ -72,8 +70,7 @@ class QWidget;
  * - setShowHiddenFiles()
  * - setShowPreview()
  * - indicateActivationChange()
- * - triggerZoomIn()
- * - triggerZoomOut()
+ * - setZoomLevel()
  */
 class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject
 {
@@ -179,18 +176,24 @@ public:
     void indicateActivationChange(bool active);
 
     /**
-     * Tells the view implementation to zoom in by emitting the signal zoomIn()
-     * and is invoked by the abstract Dolphin view.
+     * Sets the zoom level to \a level and emits the signal zoomLevelChanged().
+     * It must be assured that the used level is inside the range 
+     * DolphinController::zoomLevelMinimum() and
+     * DolphinController::zoomLevelMaximum().
+     * Is invoked by the abstract Dolphin view.
      */
-    void triggerZoomIn();
-
+    void setZoomLevel(int level);
+    int zoomLevel() const;
+    
+    int zoomLevelMinimum() const;
+    int zoomLevelMaximum() const;
+    
     /**
-     * Is invoked by the view implementation to indicate whether a zooming in
-     * is possible. The abstract Dolphin view updates the corresponding menu
-     * action depending on this state.
+     * Helper method for the view implementation to get
+     * the icon size for the zoom level \a level
+     * (see DolphinController::zoomLevel()).
      */
-    void setZoomInPossible(bool possible);
-    bool isZoomInPossible() const;
+    static int iconSizeForZoomLevel(int level);
 
     /**
      * Tells the view implementation to zoom out by emitting the signal zoomOut()
@@ -198,14 +201,6 @@ public:
      */
     void triggerZoomOut();
 
-    /**
-     * Is invoked by the view implementation to indicate whether a zooming out
-     * is possible. The abstract Dolphin view updates the corresponding menu
-     * action depending on this state.
-     */
-    void setZoomOutPossible(bool possible);
-    bool isZoomOutPossible() const;
-
     /**
      * Should be invoked in each view implementation whenever a key has been
      * pressed. If the selection model of \a view is not empty and
@@ -345,23 +340,16 @@ signals:
     void viewportEntered();
 
     /**
-     * Is emitted if the view should zoom in. The view implementation
-     * must connect to this signal if it supports zooming.
-     */
-    void zoomIn();
-
-    /**
-     * Is emitted if the view should zoom out. The view implementation
+     * Is emitted if the view should change the zoom to \a level. The view implementation
      * must connect to this signal if it supports zooming.
      */
-    void zoomOut();
+    void zoomLevelChanged(int level);
 
 private slots:
     void updateOpenTabState();
 
 private:
-    bool m_zoomInPossible;
-    bool m_zoomOutPossible;
+    int m_zoomLevel;
     bool m_openTab; // TODO: this is a workaround until  Qt-issue 176832 has been fixed
     KUrl m_url;
     DolphinView* m_dolphinView;
@@ -383,24 +371,19 @@ inline QAbstractItemView* DolphinController::itemView() const
     return m_itemView;
 }
 
-inline void DolphinController::setZoomInPossible(bool possible)
-{
-    m_zoomInPossible = possible;
-}
-
-inline bool DolphinController::isZoomInPossible() const
+inline int DolphinController::zoomLevel() const
 {
-    return m_zoomInPossible;
+    return m_zoomLevel;
 }
 
-inline void DolphinController::setZoomOutPossible(bool possible)
+inline int DolphinController::zoomLevelMinimum() const
 {
-    m_zoomOutPossible = possible;
+    return 0;
 }
 
-inline bool DolphinController::isZoomOutPossible() const
+inline int DolphinController::zoomLevelMaximum() const
 {
-    return m_zoomOutPossible;
+    return 6;
 }
 
 #endif
index 7c42d13fc56f0cf5383ce1db4a99208750aeabad..41e4746841e3a70800e1e9a083f7f80f9d6e1ca0 100644 (file)
@@ -117,10 +117,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr
             this, SLOT(slotEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
-    connect(controller, SIGNAL(zoomIn()),
-            this, SLOT(zoomIn()));
-    connect(controller, SIGNAL(zoomOut()),
-            this, SLOT(zoomOut()));
+    connect(controller, SIGNAL(zoomLevelChanged(int)),
+            this, SLOT(setZoomLevel(int)));
     connect(controller->dolphinView(), SIGNAL(additionalInfoChanged()),
             this, SLOT(updateColumnVisibility()));
 
@@ -489,30 +487,13 @@ QRect DolphinDetailsView::elasticBandRect() const
     return QRect(topLeft, m_elasticBandDestination).normalized();
 }
 
-void DolphinDetailsView::zoomIn()
+void DolphinDetailsView::setZoomLevel(int level)
 {
-    if (isZoomInPossible()) {
-        DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeSmall:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeLarge); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
-}
-
-void DolphinDetailsView::zoomOut()
-{
-    if (isZoomOutPossible()) {
-        DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-        switch (settings->iconSize()) {
-        case KIconLoader::SizeLarge:  settings->setIconSize(KIconLoader::SizeMedium); break;
-        case KIconLoader::SizeMedium: settings->setIconSize(KIconLoader::SizeSmall); break;
-        default: Q_ASSERT(false); break;
-        }
-        updateDecorationSize();
-    }
+    const int size = DolphinController::iconSizeForZoomLevel(level);
+    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
+    settings->setIconSize(size);
+    
+    updateDecorationSize();
 }
 
 void DolphinDetailsView::configureColumns(const QPoint& pos)
@@ -595,18 +576,6 @@ void DolphinDetailsView::updateFont()
     }
 }
 
-bool DolphinDetailsView::isZoomInPossible() const
-{
-    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-    return settings->iconSize() < KIconLoader::SizeLarge;
-}
-
-bool DolphinDetailsView::isZoomOutPossible() const
-{
-    DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
-    return settings->iconSize() > KIconLoader::SizeSmall;
-}
-
 void DolphinDetailsView::updateDecorationSize()
 {
     DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings();
@@ -614,9 +583,6 @@ void DolphinDetailsView::updateDecorationSize()
     setIconSize(QSize(iconSize, iconSize));
     m_decorationSize = QSize(iconSize, iconSize);
 
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
-
     if (m_selectionManager != 0) {
         m_selectionManager->reset();
     }
index eae04646a6ee8b0678102c557eb7e998a7bbbfef..d3bb0eb27a83f930374e2c77f8999d6db45a0d86 100644 (file)
@@ -107,8 +107,7 @@ private slots:
      */
     QRect elasticBandRect() const;
 
-    void zoomIn();
-    void zoomOut();
+    void setZoomLevel(int level);
 
     /**
      * Opens a context menu at the position \a pos and allows to
@@ -135,9 +134,6 @@ private slots:
     void updateFont();
 
 private:
-    bool isZoomInPossible() const;
-    bool isZoomOutPossible() const;
-
     /**
      * Updates the size of the decoration dependent on the
      * icon size of the DetailsModeSettings. The controller
index 059ce89ab1c6b2907386ca75de64bbdf28131ea2..689707de6d3b17a3fb414894c147d35c21d81d05 100644 (file)
@@ -84,10 +84,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
             controller, SLOT(emitItemEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
-    connect(controller, SIGNAL(zoomIn()),
-            this, SLOT(zoomIn()));
-    connect(controller, SIGNAL(zoomOut()),
-            this, SLOT(zoomOut()));
+    connect(controller, SIGNAL(zoomLevelChanged(int)),
+            this, SLOT(setZoomLevel(int)));
 
     const DolphinView* view = controller->dolphinView();
     connect(view, SIGNAL(showPreviewChanged()),
@@ -331,56 +329,28 @@ void DolphinIconsView::slotAdditionalInfoChanged()
     updateGridSize(showPreview, view->additionalInfo().count());
 }
 
-void DolphinIconsView::zoomIn()
+void DolphinIconsView::setZoomLevel(int level)
 {
-    if (isZoomInPossible()) {
-        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-
-        const int oldIconSize = settings->iconSize();
-        int newIconSize = oldIconSize;
-
-        const bool showPreview = m_controller->dolphinView()->showPreview();
-        if (showPreview) {
-            const int previewSize = increasedIconSize(settings->previewSize());
-            settings->setPreviewSize(previewSize);
-        } else {
-            newIconSize = increasedIconSize(oldIconSize);
-            settings->setIconSize(newIconSize);
-        }
+    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
 
-        // increase also the grid size
-        const int diff = newIconSize - oldIconSize;
-        settings->setItemWidth(settings->itemWidth() + diff);
-        settings->setItemHeight(settings->itemHeight() + diff);
+    const int oldIconSize = settings->iconSize();
+    int newIconSize = oldIconSize;
 
-        updateGridSize(showPreview, additionalInfoCount());
+    const bool showPreview = m_controller->dolphinView()->showPreview();
+    if (showPreview) {
+        const int previewSize = DolphinController::iconSizeForZoomLevel(level);
+        settings->setPreviewSize(previewSize);
+    } else {
+        newIconSize = DolphinController::iconSizeForZoomLevel(level);
+        settings->setIconSize(newIconSize);
     }
-}
 
-void DolphinIconsView::zoomOut()
-{
-    if (isZoomOutPossible()) {
-        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-
-        const int oldIconSize = settings->iconSize();
-        int newIconSize = oldIconSize;
-
-        const bool showPreview = m_controller->dolphinView()->showPreview();
-        if (showPreview) {
-            const int previewSize = decreasedIconSize(settings->previewSize());
-            settings->setPreviewSize(previewSize);
-        } else {
-            newIconSize = decreasedIconSize(settings->iconSize());
-            settings->setIconSize(newIconSize);
-        }
+    // increase also the grid size
+    const int diff = newIconSize - oldIconSize;
+    settings->setItemWidth(settings->itemWidth() + diff);
+    settings->setItemHeight(settings->itemHeight() + diff);
 
-        // decrease also the grid size
-        const int diff = oldIconSize - newIconSize;
-        settings->setItemWidth(settings->itemWidth() - diff);
-        settings->setItemHeight(settings->itemHeight() - diff);
-
-        updateGridSize(showPreview, additionalInfoCount());
-    }
+    updateGridSize(showPreview, additionalInfoCount());
 }
 
 void DolphinIconsView::requestActivation()
@@ -398,50 +368,6 @@ void DolphinIconsView::updateFont()
     }
 }
 
-bool DolphinIconsView::isZoomInPossible() const
-{
-    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    const bool showPreview = m_controller->dolphinView()->showPreview();
-    const int size = showPreview ? settings->previewSize() : settings->iconSize();
-    return size < KIconLoader::SizeEnormous;
-}
-
-bool DolphinIconsView::isZoomOutPossible() const
-{
-    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
-    const bool showPreview = m_controller->dolphinView()->showPreview();
-    const int size = showPreview ? settings->previewSize() : settings->iconSize();
-    return size > KIconLoader::SizeSmall;
-}
-
-int DolphinIconsView::increasedIconSize(int size) const
-{
-    int incSize = 0;
-    switch (size) {
-    case KIconLoader::SizeSmall:       incSize = KIconLoader::SizeSmallMedium; break;
-    case KIconLoader::SizeSmallMedium: incSize = KIconLoader::SizeMedium; break;
-    case KIconLoader::SizeMedium:      incSize = KIconLoader::SizeLarge; break;
-    case KIconLoader::SizeLarge:       incSize = KIconLoader::SizeHuge; break;
-    case KIconLoader::SizeHuge:        incSize = KIconLoader::SizeEnormous; break;
-    default: Q_ASSERT(false); break;
-    }
-    return incSize;
-}
-
-int DolphinIconsView::decreasedIconSize(int size) const
-{
-    int decSize = 0;
-    switch (size) {
-    case KIconLoader::SizeSmallMedium: decSize = KIconLoader::SizeSmall; break;
-    case KIconLoader::SizeMedium: decSize = KIconLoader::SizeSmallMedium; break;
-    case KIconLoader::SizeLarge: decSize = KIconLoader::SizeMedium; break;
-    case KIconLoader::SizeHuge: decSize = KIconLoader::SizeLarge; break;
-    case KIconLoader::SizeEnormous: decSize = KIconLoader::SizeHuge; break;
-    default: Q_ASSERT(false); break;
-    }
-    return decSize;
-}
-
 void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 {
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
@@ -479,9 +405,6 @@ void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
     const int spacing = settings->gridSpacing();
     setGridSize(QSize(itemWidth + spacing * 2, itemHeight + spacing));
 
-    m_controller->setZoomInPossible(isZoomInPossible());
-    m_controller->setZoomOutPossible(isZoomOutPossible());
-
     KFileItemDelegate* delegate = dynamic_cast<KFileItemDelegate*>(itemDelegate());
     if (delegate != 0) {
         delegate->setMaximumSize(m_itemSize);
index 83672d2f568036925da8b08a1b766a1fffffabc2..3465f6bfcfd551fbb2e18e6ad10a3615ebeb4f1c 100644 (file)
@@ -70,21 +70,11 @@ protected:
 private slots:
     void slotShowPreviewChanged();
     void slotAdditionalInfoChanged();
-    void zoomIn();
-    void zoomOut();
+    void setZoomLevel(int level);
     void requestActivation();
     void updateFont();
 
 private:
-    bool isZoomInPossible() const;
-    bool isZoomOutPossible() const;
-
-    /** Returns the increased icon size for the size \a size. */
-    int increasedIconSize(int size) const;
-
-    /** Returns the decreased icon size for the size \a size. */
-    int decreasedIconSize(int size) const;
-
     /**
      * Updates the size of the grid depending on the state
      * of \a showPreview and \a additionalInfoCount.
index e1cbaee8c35c55b66000f2c43aa0d0dd6d82b5ac..d02059059a4bd4fe4b9aeefca5e44263fc4c9d06 100644 (file)
@@ -360,26 +360,34 @@ QPoint DolphinView::contentsPosition() const
     return QPoint(x, y);
 }
 
-void DolphinView::zoomIn()
+void DolphinView::setZoomLevel(int level)
 {
-    m_controller->triggerZoomIn();
-    m_iconManager->updatePreviews();
+    if (level < zoomLevelMinimum()) {
+        level = zoomLevelMinimum();
+    } else if (level > zoomLevelMaximum()) {
+        level = zoomLevelMaximum();
+    }
+    
+    if (level != zoomLevel()) {
+        m_controller->setZoomLevel(level);
+        m_iconManager->updatePreviews();
+        emit zoomLevelChanged(level);
+    }
 }
 
-void DolphinView::zoomOut()
+int DolphinView::zoomLevel() const
 {
-    m_controller->triggerZoomOut();
-    m_iconManager->updatePreviews();
+    return m_controller->zoomLevel();
 }
 
-bool DolphinView::isZoomInPossible() const
+int DolphinView::zoomLevelMinimum() const
 {
-    return m_controller->isZoomInPossible();
+    return m_controller->zoomLevelMinimum();
 }
 
-bool DolphinView::isZoomOutPossible() const
+int DolphinView::zoomLevelMaximum() const
 {
-    return m_controller->isZoomOutPossible();
+    return m_controller->zoomLevelMaximum();
 }
 
 void DolphinView::setSorting(Sorting sorting)
@@ -737,10 +745,11 @@ void DolphinView::wheelEvent(QWheelEvent* event)
 {
     if (event->modifiers() & Qt::ControlModifier) {
         const int delta = event->delta();
-        if ((delta > 0) && isZoomInPossible()) {
-            zoomIn();
-        } else if ((delta < 0) && isZoomOutPossible()) {
-            zoomOut();
+        const int level = zoomLevel();
+        if (delta > 0) {
+            setZoomLevel(level + 1);
+        } else if (delta < 0) {
+            setZoomLevel(level - 1);
         }
         event->accept();
     }
index e74975f67a492ced15c9f03a3b748bc092ce59da..8060ebd4eb3bcba60cd59e405620695853fb09df 100644 (file)
@@ -234,12 +234,17 @@ public:
     /** Returns the upper left position of the view content. */
     QPoint contentsPosition() const;
 
-    /** Increases the size of the current set view mode. */
-    void zoomIn();
-
-    /** Decreases the size of the current set view mode. */
-    void zoomOut();
-
+    /**
+     * Sets the zoom level to \a level. It is assured that the used
+     * level is adjusted to be inside the range DolphinView::zoomLevelMinimum() and
+     * DolphinView::zoomLevelMaximum().
+     */
+    void setZoomLevel(int level);
+    int zoomLevel() const;
+    
+    int zoomLevelMinimum() const;
+    int zoomLevelMaximum() const;
+    
     /**
      * Returns true, if zooming in is possible. If false is returned,
      * the minimal zoom size is possible.
@@ -460,6 +465,9 @@ signals:
 
     /** Is emitted if the additional information shown for this view has been changed. */
     void additionalInfoChanged();
+    
+    /** Is emitted if the zoom level has been changed by zooming in or out. */
+    void zoomLevelChanged(int level);
 
     /**
      * Is emitted if information of an item is requested to be shown e. g. in the sidebar.
index cd5880c794b7a776a751a2e7f69fc27d6c87460a..6d735b587c10d5eb1c6f4eb41f93865c6622c70b 100644 (file)
@@ -63,6 +63,8 @@ void DolphinViewActionHandler::setCurrentView(DolphinView* view)
             this, SLOT(slotShowHiddenFilesChanged()));
     connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(slotSortingChanged(DolphinView::Sorting)));
+    connect(view, SIGNAL(zoomLevelChanged(int)),
+            this, SLOT(slotZoomLevelChanged(int)));
 }
 
 void DolphinViewActionHandler::createActions()
@@ -341,16 +343,6 @@ void DolphinViewActionHandler::updateViewActions()
         viewModeAction->setChecked(true);
     }
 
-    QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
-    if (zoomInAction != 0) {
-        zoomInAction->setEnabled(m_currentView->isZoomInPossible());
-    }
-
-    QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut));
-    if (zoomOutAction != 0) {
-        zoomOutAction->setEnabled(m_currentView->isZoomOutPossible());
-    }
-
     QAction* showPreviewAction = m_actionCollection->action("show_preview");
     showPreviewAction->setChecked(m_currentView->showPreview());
 
@@ -358,6 +350,7 @@ void DolphinViewActionHandler::updateViewActions()
     slotAdditionalInfoChanged();
     slotCategorizedSortingChanged();
     slotSortingChanged(m_currentView->sorting());
+    slotZoomLevelChanged(m_currentView->zoomLevel());
 
     QAction* showHiddenFilesAction = m_actionCollection->action("show_hidden_files");
     showHiddenFilesAction->setChecked(m_currentView->showHiddenFiles());
@@ -366,13 +359,15 @@ void DolphinViewActionHandler::updateViewActions()
 
 void DolphinViewActionHandler::zoomIn()
 {
-    m_currentView->zoomIn();
+    const int level = m_currentView->zoomLevel();
+    m_currentView->setZoomLevel(level + 1);
     updateViewActions();
 }
 
 void DolphinViewActionHandler::zoomOut()
 {
-    m_currentView->zoomOut();
+    const int level = m_currentView->zoomLevel();
+    m_currentView->setZoomLevel(level - 1);
     updateViewActions();
 }
 
@@ -496,6 +491,19 @@ void DolphinViewActionHandler::slotSortingChanged(DolphinView::Sorting sorting)
     }
 }
 
+void DolphinViewActionHandler::slotZoomLevelChanged(int level)
+{
+    QAction* zoomInAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomIn));
+    if (zoomInAction != 0) {
+        zoomInAction->setEnabled(level < m_currentView->zoomLevelMaximum());
+    }
+
+    QAction* zoomOutAction = m_actionCollection->action(KStandardAction::name(KStandardAction::ZoomOut));
+    if (zoomOutAction != 0) {
+        zoomOutAction->setEnabled(level > m_currentView->zoomLevelMinimum());
+    }
+}
+
 void DolphinViewActionHandler::slotSortTriggered(QAction* action)
 {
     const DolphinView::Sorting sorting = action->data().value<DolphinView::Sorting>();
index af25cc48cb47af1df1d0d611cafee1edc7a54f6a..5084d06fe1d0e070970e5901fae7fe0722fa6b3e 100644 (file)
@@ -130,6 +130,11 @@ private Q_SLOTS:
      * Updates the state of the 'Sort by' actions.
      */
     void slotSortingChanged(DolphinView::Sorting sorting);
+    
+    /**
+     * Updates the state of the 'Zoom In' and 'Zoom Out' actions.
+     */    
+    void slotZoomLevelChanged(int level);
 
     /**
      * Switches on or off the displaying of additional information
index 11a3e28641bb104086ec09c407d794a00055d23c..56c2b627cfc5c00dc55074c0e735bb4a3ba6bd8a 100644 (file)
@@ -506,7 +506,14 @@ void IconManager::startPreviewJob(const KFileItemList& items)
     m_hasCutSelection = KonqMimeData::decodeIsCutSelection(mimeData);
 
     const QSize size = m_view->iconSize();
-    KIO::PreviewJob* job = KIO::filePreview(items, 128, 128);
+
+    // PreviewJob internally caches items always with the size of
+    // 128 x 128 pixels or 256 x 256 pixels. A downscaling is done 
+    // by PreviewJob if a smaller size is requested. As the IconManager must
+    // do a downscaling anyhow because of the frame, only the provided
+    // cache sizes are requested.
+    const int cacheSize = (size.width() > 128) || (size.height() > 128) ? 256 : 128;
+    KIO::PreviewJob* job = KIO::filePreview(items, cacheSize, cacheSize);
     connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
             this, SLOT(addToPreviewQueue(const KFileItem&, const QPixmap&)));
     connect(job, SIGNAL(finished(KJob*)),