]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Allow zooming in and zooming out in the icons view.
authorPeter Penz <peter.penz19@gmail.com>
Thu, 1 Mar 2007 19:36:37 +0000 (19:36 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 1 Mar 2007 19:36:37 +0000 (19:36 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=638386

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

index e1d4c48e344f28e4b201238a029d48e7e683b73a..ea9c25211bdbdee895dfb44b1b985f2643c22683 100644 (file)
@@ -21,7 +21,9 @@
 
 DolphinController::DolphinController(QObject* parent) :
     QObject(parent),
-    m_showPreview(false)
+    m_showPreview(false),
+    m_zoomInPossible(false),
+    m_zoomOutPossible(false)
 {
 }
 
@@ -65,6 +67,16 @@ void DolphinController::setShowPreview(bool showPreview)
     }
 }
 
+void DolphinController::triggerZoomIn()
+{
+    emit zoomIn();
+}
+
+void DolphinController::triggerZoomOut()
+{
+    emit zoomOut();
+}
+
 void DolphinController::triggerItem(const QModelIndex& index)
 {
     emit itemTriggered(index);
index 08d12ea575e95fff8f982a659e228f3fd6bc3a22..1bd283fd44f206dfe5c902ffba5de6b36e9396c5 100644 (file)
@@ -70,6 +70,14 @@ public:
     void setShowPreview(bool showPreview);
     bool showPreview() const { return m_showPreview; }
 
+    void triggerZoomIn();
+    void setZoomInPossible(bool possible) { m_zoomInPossible = possible; }
+    bool isZoomInPossible() const { return m_zoomInPossible; }
+
+    void triggerZoomOut();
+    void setZoomOutPossible(bool possible) { m_zoomOutPossible = possible; }
+    bool isZoomOutPossible() const { return m_zoomOutPossible; }
+
 public slots:
     void triggerItem(const QModelIndex& index);
     void indicateSelectionChange();
@@ -121,8 +129,16 @@ signals:
     /** Is emitted if the selection has been changed by the user. */
     void selectionChanged();
 
+    /** Is emitted if the view should zoom in. */
+    void zoomIn();
+
+    /** Is emitted if the view should zoom out. */
+    void zoomOut();
+
 private:
     bool m_showPreview;
+    bool m_zoomInPossible;
+    bool m_zoomOutPossible;
     KUrl m_url;
 };
 
index 1695b768e4f92abb27ac12f878138634af8243df..ef45250653dfd13ea5521e167ae157585b053faa 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "dolphin_iconsmodesettings.h"
 
-#include <assert.h>
 #include <kdirmodel.h>
 #include <kfileitem.h>
 #include <kfileitemdelegate.h>
@@ -43,15 +42,18 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
             controller, SLOT(triggerItem(const QModelIndex&)));
     connect(controller, SIGNAL(showPreviewChanged(bool)),
             this, SLOT(updateGridSize(bool)));
+    connect(controller, SIGNAL(zoomIn()),
+            this, SLOT(zoomIn()));
+    connect(controller, SIGNAL(zoomOut()),
+            this, SLOT(zoomOut()));
 
     // apply the icons mode settings to the widget
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     Q_ASSERT(settings != 0);
 
-    setSpacing(settings->gridSpacing());
-
     m_viewOptions = QListView::viewOptions();
     m_viewOptions.font = QFont(settings->fontFamily(), settings->fontSize());
+
     updateGridSize(controller->showPreview());
 
     if (settings->arrangement() == QListView::TopToBottom) {
@@ -132,6 +134,91 @@ void DolphinIconsView::updateGridSize(bool showPreview)
 
     m_viewOptions.decorationSize = QSize(size, size);
     setGridSize(QSize(gridWidth, gridHeight));
+
+    m_controller->setZoomInPossible(isZoomInPossible());
+    m_controller->setZoomOutPossible(isZoomOutPossible());
+}
+
+void DolphinIconsView::zoomIn()
+{
+    if (isZoomInPossible()) {
+        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+
+        const bool showPreview = m_controller->showPreview();
+        if (showPreview) {
+            const int previewSize = increasedIconSize(settings->previewSize());
+            settings->setPreviewSize(previewSize);
+        }
+        else {
+            const int iconSize = increasedIconSize(settings->iconSize());
+            settings->setIconSize(iconSize);
+        }
+
+        updateGridSize(showPreview);
+    }
+}
+
+void DolphinIconsView::zoomOut()
+{
+    if (isZoomOutPossible()) {
+        IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+
+        const bool showPreview = m_controller->showPreview();
+        if (showPreview) {
+            const int previewSize = decreasedIconSize(settings->previewSize());
+            settings->setPreviewSize(previewSize);
+        }
+        else {
+            const int iconSize = decreasedIconSize(settings->iconSize());
+            settings->setIconSize(iconSize);
+        }
+
+        updateGridSize(showPreview);
+    }
+}
+
+bool DolphinIconsView::isZoomInPossible() const
+{
+    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
+    return size < K3Icon::SizeEnormous;
+}
+
+bool DolphinIconsView::isZoomOutPossible() const
+{
+    IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
+    const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
+    return size > K3Icon::SizeSmall;
+}
+
+int DolphinIconsView::increasedIconSize(int size) const
+{
+    // TODO: get rid of K3Icon sizes
+    int incSize = 0;
+    switch (size) {
+        case K3Icon::SizeSmall:       incSize = K3Icon::SizeSmallMedium; break;
+        case K3Icon::SizeSmallMedium: incSize = K3Icon::SizeMedium; break;
+        case K3Icon::SizeMedium:      incSize = K3Icon::SizeLarge; break;
+        case K3Icon::SizeLarge:       incSize = K3Icon::SizeHuge; break;
+        case K3Icon::SizeHuge:        incSize = K3Icon::SizeEnormous; break;
+        default: Q_ASSERT(false); break;
+    }
+    return incSize;
+}
+
+int DolphinIconsView::decreasedIconSize(int size) const
+{
+    // TODO: get rid of K3Icon sizes
+    int decSize = 0;
+    switch (size) {
+        case K3Icon::SizeSmallMedium: decSize = K3Icon::SizeSmall; break;
+        case K3Icon::SizeMedium: decSize = K3Icon::SizeSmallMedium; break;
+        case K3Icon::SizeLarge: decSize = K3Icon::SizeMedium; break;
+        case K3Icon::SizeHuge: decSize = K3Icon::SizeLarge; break;
+        case K3Icon::SizeEnormous: decSize = K3Icon::SizeHuge; break;
+        default: Q_ASSERT(false); break;
+    }
+    return decSize;
 }
 
 #include "dolphiniconsview.moc"
index 22da7de21adc2f3bc093ff90155354f204a1a3d2..db3d5d6cdad1fcf25d4f161366c2c47334086081 100644 (file)
@@ -54,6 +54,19 @@ private slots:
      */
     void updateGridSize(bool showPreview);
 
+    void zoomIn();
+    void zoomOut();
+
+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;
+
 private:
     DolphinController* m_controller;
     QStyleOptionViewItem m_viewOptions;
index edb57ef7f3e96ba60c9d02fda3c5221666c9af6a..491411cb21d937570b3ef813ca5f1c0f3cd18f18 100644 (file)
@@ -250,11 +250,11 @@ void DolphinMainWindow::slotViewModeChanged()
     updateViewActions();\r
 }\r
 \r
-void DolphinMainWindow::slowShowPreviewChanged()\r
+void DolphinMainWindow::slotShowPreviewChanged()\r
 {\r
-    KToggleAction* showPreviewAction =\r
-        static_cast<KToggleAction*>(actionCollection()->action("show_preview"));\r
-    showPreviewAction->setChecked(m_activeView->showPreview());\r
+    // It is not enough to update the 'Show Preview' action, also\r
+    // the 'Zoom In' and 'Zoom Out' actions must be adapted.\r
+    updateViewActions();\r
 }\r
 \r
 void DolphinMainWindow::slotShowHiddenFilesChanged()\r
@@ -329,6 +329,7 @@ void DolphinMainWindow::slotHistoryChanged()
 void DolphinMainWindow::slotUrlChanged(const KUrl& url)\r
 {\r
     updateEditActions();\r
+    updateViewActions();\r
     updateGoActions();\r
     setCaption(url.fileName());\r
 }\r
@@ -1349,7 +1350,7 @@ void DolphinMainWindow::connectViewSignals(int viewIndex)
     connect(view, SIGNAL(modeChanged()),\r
             this, SLOT(slotViewModeChanged()));\r
     connect(view, SIGNAL(showPreviewChanged()),\r
-            this, SLOT(slowShowPreviewChanged()));\r
+            this, SLOT(slotShowPreviewChanged()));\r
     connect(view, SIGNAL(showHiddenFilesChanged()),\r
             this, SLOT(slotShowHiddenFilesChanged()));\r
     connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)),\r
index 1b33c8cb06488cd16ebbcb671ac555c0cdccff47..137fdfc9ef76db25df9d5732cf5fae98a909ce7e 100644 (file)
@@ -320,7 +320,7 @@ private slots:
     void slotViewModeChanged();
 
     /** Updates the state of the 'Show preview' menu action. */
-    void slowShowPreviewChanged();
+    void slotShowPreviewChanged();
 
     /** Updates the state of the 'Show hidden files' menu action. */
     void slotShowHiddenFilesChanged();
index 81eaf21b482057d69793753f68568f99371661fc..fd6b1409e7d6f5450cc3e2dc41a6390be1d74c5e 100644 (file)
@@ -376,22 +376,22 @@ bool DolphinView::isUrlEditable() const
 
 void DolphinView::zoomIn()
 {
-    //itemEffectsManager()->zoomIn();
+    m_controller->triggerZoomIn();
 }
 
 void DolphinView::zoomOut()
 {
-    //itemEffectsManager()->zoomOut();
+    m_controller->triggerZoomOut();
 }
 
 bool DolphinView::isZoomInPossible() const
 {
-    return false; //itemEffectsManager()->isZoomInPossible();
+    return m_controller->isZoomInPossible();
 }
 
 bool DolphinView::isZoomOutPossible() const
 {
-    return false; //itemEffectsManager()->isZoomOutPossible();
+    return m_controller->isZoomOutPossible();
 }
 
 void DolphinView::setSorting(Sorting sorting)