]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnview.cpp
Remove ScrollPerPixel again. Beside a crash with a non-patched version of Qt it also...
[dolphin.git] / src / dolphincolumnview.cpp
index 6df71cc1e81a057801265da5871c23b8a93d3d22..b75de47356a6558c0dd502a97064e99453ab9fb3 100644 (file)
@@ -33,6 +33,7 @@
 #include <QApplication>
 #include <QPoint>
 #include <QScrollBar>
+#include <QTimer>
 #include <QTimeLine>
 
 /**
@@ -386,6 +387,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control
     QAbstractItemView(parent),
     m_controller(controller),
     m_restoreActiveColumnFocus(false),
+    m_dirListerCompleted(false),
     m_index(-1),
     m_contentX(0),
     m_columns(),
@@ -472,10 +474,33 @@ void DolphinColumnView::setModel(QAbstractItemModel* model)
     connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
             this, SLOT(triggerReloadColumns(const QModelIndex&)));
 
+    KDirLister* dirLister = m_dolphinModel->dirLister();
+    connect(dirLister, SIGNAL(started(const KUrl&)),
+            this, SLOT(slotDirListerStarted(const KUrl&)));
+    connect(dirLister, SIGNAL(completed()),
+            this, SLOT(slotDirListerCompleted()));
+
     activeColumn()->setModel(model);
     QAbstractItemView::setModel(model);
 }
 
+void DolphinColumnView::invertSelection()
+{
+    // TODO: this approach of inverting the selection is quite slow. It should
+    // be possible to speedup the implementation by using QItemSelection, but
+    // all adempts have failed yet...
+
+    ColumnWidget* column = activeColumn();
+    QItemSelectionModel* selModel = column->selectionModel();
+
+    KDirLister* dirLister = m_dolphinModel->dirLister();
+    const KFileItemList list = dirLister->itemsForDir(column->url());
+    foreach (KFileItem* item, list) {
+        const QModelIndex index = m_dolphinModel->indexForUrl(item->url());
+        selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle);
+    }
+}
+
 void DolphinColumnView::reload()
 {
     // Due to the reloading of the model all columns will be reset to show
@@ -493,31 +518,13 @@ void DolphinColumnView::reload()
             m_restoreActiveColumnFocus = true;
         }
         column->hide();
-   }
+    }
 
     // all columns are hidden, now reload the directory lister
     KDirLister* dirLister = m_dolphinModel->dirLister();
-    connect(dirLister, SIGNAL(completed()),
-            this, SLOT(expandToActiveUrl()));
-    const KUrl rootUrl = m_columns[0]->url();
+    const KUrl& rootUrl = m_columns[0]->url();
     dirLister->openUrl(rootUrl, false, true);
-}
-
-void DolphinColumnView::invertSelection()
-{
-    // TODO: this approach of inverting the selection is quite slow. It should
-    // be possible to speedup the implementation by using QItemSelection, but
-    // all adempts have failed yet...
-
-    ColumnWidget* column = activeColumn();
-    QItemSelectionModel* selModel = column->selectionModel();
-
-    KDirLister* dirLister = m_dolphinModel->dirLister();
-    const KFileItemList list = dirLister->itemsForDir(column->url());
-    foreach (KFileItem* item, list) {
-        const QModelIndex index = m_dolphinModel->indexForUrl(item->url());
-        selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle);
-    }
+    updateColumns();
 }
 
 void DolphinColumnView::showColumn(const KUrl& url)
@@ -608,8 +615,6 @@ void DolphinColumnView::showColumn(const KUrl& url)
             columnIndex++;
 
             ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
-            column->setVerticalScrollMode(ColumnWidget::ScrollPerPixel);
-            column->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel);
             column->setModel(model());
             column->setRootIndex(proxyIndex);
             column->setActive(false);
@@ -634,8 +639,6 @@ void DolphinColumnView::showColumn(const KUrl& url)
     activeColumn()->setActive(false);
     m_index = columnIndex;
     activeColumn()->setActive(true);
-
-    expandToActiveUrl();
 }
 
 void DolphinColumnView::selectAll()
@@ -782,30 +785,32 @@ void DolphinColumnView::expandToActiveUrl()
     Q_ASSERT(lastIndex >= 0);
     const KUrl& activeUrl = m_columns[lastIndex]->url();
     const KUrl rootUrl = m_dolphinModel->dirLister()->url();
-    const bool expand = rootUrl.isParentOf(activeUrl)
+    const bool expand = m_dirListerCompleted
+                        && rootUrl.isParentOf(activeUrl)
                         && !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash);
     if (expand) {
         m_dolphinModel->expandToUrl(activeUrl);
-        reloadColumns();
     }
+    updateColumns();
 }
 
-void DolphinColumnView::triggerReloadColumns(const QModelIndex& index)
+void DolphinColumnView::triggerUpdateColumns(const QModelIndex& index)
 {
     Q_UNUSED(index);
-    // the reloading of the columns may not be done in the context of this slot
-    QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection);
+    // the updating of the columns may not be done in the context of this slot
+    QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection);
 }
 
-void DolphinColumnView::reloadColumns()
+void DolphinColumnView::updateColumns()
 {
+    KDirLister* dirLister = m_dolphinModel->dirLister();
+    foreach (ColumnWidget* column, m_columns) {
+        dirLister->updateDirectory(column->url());
+    }
+
     const int end = m_columns.count() - 2; // next to last column
     for (int i = 0; i <= end; ++i) {
         ColumnWidget* nextColumn = m_columns[i + 1];
-
-        KDirLister* dirLister = m_dolphinModel->dirLister();
-        dirLister->updateDirectory(nextColumn->url());
-
         const QModelIndex rootIndex = nextColumn->rootIndex();
         if (rootIndex.isValid()) {
             nextColumn->show();
@@ -825,6 +830,18 @@ void DolphinColumnView::reloadColumns()
     assureVisibleActiveColumn();
 }
 
+void DolphinColumnView::slotDirListerStarted(const KUrl& url)
+{
+    Q_UNUSED(url);
+    m_dirListerCompleted = false;
+}
+
+void DolphinColumnView::slotDirListerCompleted()
+{
+    m_dirListerCompleted = true;
+    QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection);
+}
+
 bool DolphinColumnView::isZoomInPossible() const
 {
     ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings();