]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphiniconsview.cpp
fixed most regressions due to the previous column-view refactoring
[dolphin.git] / src / dolphiniconsview.cpp
index 3da04c113a69cbd46dde69239519b5f13dc2483d..f1ad25e3dd62b9300b119e44e511d3fcf80b58c6 100644 (file)
@@ -26,6 +26,7 @@
 #include "dolphin_iconsmodesettings.h"
 
 #include <kdialog.h>
+#include <kdirmodel.h>
 
 #include <QAbstractProxyModel>
 #include <QApplication>
@@ -53,24 +54,25 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     // RETURN-key in keyPressEvent().
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-                controller, SLOT(triggerItem(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                controller, SLOT(triggerItem(const QModelIndex&)));
+                this, SLOT(triggerItem(const QModelIndex&)));
     }
-    connect(this, SIGNAL(entered(const QModelIndex&)),
-            controller, SLOT(emitItemEntered(const QModelIndex&)));
     connect(this, SIGNAL(viewportEntered()),
             controller, SLOT(emitViewportEntered()));
     connect(controller, SIGNAL(showPreviewChanged(bool)),
             this, SLOT(slotShowPreviewChanged(bool)));
-    connect(controller, SIGNAL(showAdditionalInfoChanged(bool)),
-            this, SLOT(slotShowAdditionalInfoChanged(bool)));
+    connect(controller, SIGNAL(additionalInfoCountChanged(int)),
+            this, SLOT(slotAdditionalInfoCountChanged(int)));
     connect(controller, SIGNAL(zoomIn()),
             this, SLOT(zoomIn()));
     connect(controller, SIGNAL(zoomOut()),
             this, SLOT(zoomOut()));
 
+    connect(this, SIGNAL(entered(const QModelIndex&)),
+            this, SLOT(slotEntered(const QModelIndex&)));
+
     // apply the icons mode settings to the widget
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     Q_ASSERT(settings != 0);
@@ -84,7 +86,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle
     m_viewOptions.font = font;
 
     setWordWrap(settings->numberOfTextlines() > 1);
-    updateGridSize(controller->showPreview(), controller->showAdditionalInfo());
+    updateGridSize(controller->showPreview(), controller->additionalInfoCount());
 
     if (settings->arrangement() == QListView::TopToBottom) {
         setFlow(QListView::LeftToRight);
@@ -220,22 +222,32 @@ void DolphinIconsView::keyPressEvent(QKeyEvent* event)
 
     const QItemSelectionModel* selModel = selectionModel();
     const QModelIndex currentIndex = selModel->currentIndex();
-    const bool triggerItem = currentIndex.isValid()
-                             && (event->key() == Qt::Key_Return)
-                             && (selModel->selectedIndexes().count() <= 1);
-    if (triggerItem) {
-        m_controller->triggerItem(currentIndex);
+    const bool trigger = currentIndex.isValid()
+                         && (event->key() == Qt::Key_Return)
+                         && (selModel->selectedIndexes().count() <= 1);
+    if (trigger) {
+        triggerItem(currentIndex);
     }
 }
 
+void DolphinIconsView::triggerItem(const QModelIndex& index)
+{
+    m_controller->triggerItem(itemForIndex(index));
+}
+
+void DolphinIconsView::slotEntered(const QModelIndex& index)
+{
+    m_controller->emitItemEntered(itemForIndex(index));
+}
+
 void DolphinIconsView::slotShowPreviewChanged(bool showPreview)
 {
-    updateGridSize(showPreview, m_controller->showAdditionalInfo());
+    updateGridSize(showPreview, m_controller->additionalInfoCount());
 }
 
-void DolphinIconsView::slotShowAdditionalInfoChanged(bool showAdditionalInfo)
+void DolphinIconsView::slotAdditionalInfoCountChanged(int count)
 {
-    updateGridSize(m_controller->showPreview(), showAdditionalInfo);
+    updateGridSize(m_controller->showPreview(), count);
 }
 
 void DolphinIconsView::zoomIn()
@@ -264,7 +276,7 @@ void DolphinIconsView::zoomIn()
         settings->setItemWidth(settings->itemWidth() + diff);
         settings->setItemHeight(settings->itemHeight() + diff);
 
-        updateGridSize(showPreview, m_controller->showAdditionalInfo());
+        updateGridSize(showPreview, m_controller->additionalInfoCount());
     }
 }
 
@@ -295,7 +307,7 @@ void DolphinIconsView::zoomOut()
         settings->setItemWidth(settings->itemWidth() - diff);
         settings->setItemHeight(settings->itemHeight() - diff);
 
-        updateGridSize(showPreview, m_controller->showAdditionalInfo());
+        updateGridSize(showPreview, m_controller->additionalInfoCount());
     }
 }
 
@@ -303,26 +315,25 @@ bool DolphinIconsView::isZoomInPossible() const
 {
     IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
-    return size < K3Icon::SizeEnormous;
+    return size < KIconLoader::SizeEnormous;
 }
 
 bool DolphinIconsView::isZoomOutPossible() const
 {
     IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     const int size = m_controller->showPreview() ? settings->previewSize() : settings->iconSize();
-    return size > K3Icon::SizeSmall;
+    return size > KIconLoader::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;
+    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;
@@ -330,20 +341,19 @@ int DolphinIconsView::increasedIconSize(int size) const
 
 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;
+    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, bool showAdditionalInfo)
+void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount)
 {
     const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings();
     Q_ASSERT(settings != 0);
@@ -362,9 +372,8 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
         size = previewSize;
     }
 
-    if (showAdditionalInfo) {
-        itemHeight += m_viewOptions.font.pointSize() * 2;
-    }
+    Q_ASSERT(additionalInfoCount >= 0);
+    itemHeight += additionalInfoCount * m_viewOptions.font.pointSize() * 2;
 
     if (settings->arrangement() == QListView::TopToBottom) {
         // The decoration width indirectly defines the maximum
@@ -384,4 +393,13 @@ void DolphinIconsView::updateGridSize(bool showPreview, bool showAdditionalInfo)
     m_controller->setZoomOutPossible(isZoomOutPossible());
 }
 
+KFileItem DolphinIconsView::itemForIndex(const QModelIndex& index) const
+{
+    QAbstractProxyModel* proxyModel = static_cast<QAbstractProxyModel*>(model());
+    KDirModel* dirModel = static_cast<KDirModel*>(proxyModel->sourceModel());
+    const QModelIndex dirIndex = proxyModel->mapToSource(index);
+    return dirModel->itemForIndex(dirIndex);
+}
+
+
 #include "dolphiniconsview.moc"