]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphincolumnview.cpp
hide the ratings and tags column in the treeview sidebar
[dolphin.git] / src / dolphincolumnview.cpp
index a89ab184892c5db48431f8fcfa12835d6452bd7d..586b6a1c2400d2215ebb67588cf892d19f7db8dd 100644 (file)
@@ -56,19 +56,20 @@ public:
      * drawn in a lighter color. All operations are applied to this column.
      */
     void setActive(bool active);
-    inline bool isActive() const;
+    bool isActive() const;
 
     /**
      * Sets the directory URL of the child column that is shown next to
      * this column. This property is only used for a visual indication
      * of the shown directory, it does not trigger a loading of the model.
      */
-    inline void setChildUrl(const KUrl& url);
-    inline const KUrl& childUrl() const;
+    void setChildUrl(const KUrl& url);
+    const KUrl& childUrl() const;
 
-    /**
-     * Returns the directory URL that is shown inside the column widget.
-     */
+    /** Sets the directory URL that is shown inside the column widget. */
+    void setUrl(const KUrl& url);
+
+    /** Returns the directory URL that is shown inside the column widget. */
     inline const KUrl& url() const;
 
 protected:
@@ -187,6 +188,11 @@ inline const KUrl& ColumnWidget::childUrl() const
     return m_childUrl;
 }
 
+inline void ColumnWidget::setUrl(const KUrl& url)
+{
+    m_url = url;
+}
+
 const KUrl& ColumnWidget::url() const
 {
     return m_url;
@@ -289,7 +295,7 @@ void ColumnWidget::keyPressEvent(QKeyEvent* event)
                              && (event->key() == Qt::Key_Return)
                              && (selModel->selectedIndexes().count() <= 1);
     if (triggerItem) {
-        m_view->triggerItem(currentIndex);
+        m_view->m_controller->triggerItem(currentIndex);
     }
 }
 
@@ -331,10 +337,10 @@ void ColumnWidget::activate()
     // necessary connecting the signal 'singleClick()' or 'doubleClick'.
     if (KGlobalSettings::singleClick()) {
         connect(this, SIGNAL(clicked(const QModelIndex&)),
-                m_view, SLOT(triggerItem(const QModelIndex&)));
+                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     } else {
         connect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                m_view, SLOT(triggerItem(const QModelIndex&)));
+                m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     }
 
     const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
@@ -360,10 +366,10 @@ void ColumnWidget::deactivate()
     // necessary connecting the signal 'singleClick()' or 'doubleClick'.
     if (KGlobalSettings::singleClick()) {
         disconnect(this, SIGNAL(clicked(const QModelIndex&)),
-                   m_view, SLOT(triggerItem(const QModelIndex&)));
+                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     } else {
         disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)),
-                   m_view, SLOT(triggerItem(const QModelIndex&)));
+                   m_view->m_controller, SLOT(triggerItem(const QModelIndex&)));
     }
 
     const QPalette palette = m_view->viewport()->palette();
@@ -493,17 +499,27 @@ void DolphinColumnView::reload()
     KDirLister* dirLister = m_dolphinModel->dirLister();
     connect(dirLister, SIGNAL(completed()),
             this, SLOT(expandToActiveUrl()));
-    const KUrl baseUrl = m_columns[0]->url();
-    dirLister->openUrl(baseUrl, false, true);
+    const KUrl rootUrl = m_columns[0]->url();
+    dirLister->openUrl(rootUrl, false, true);
 }
 
 void DolphinColumnView::showColumn(const KUrl& url)
 {
-    if (!m_columns[0]->url().isParentOf(url)) {
+    const KUrl& rootUrl = m_columns[0]->url();
+    if (!rootUrl.isParentOf(url)) {
         // the URL is no child URL of the column view, hence do nothing
         return;
     }
 
+    KDirLister* dirLister = m_dolphinModel->dirLister();
+    const KUrl dirListerUrl = dirLister->url();
+    if (dirListerUrl != rootUrl) {
+        // It is possible that root URL of the directory lister is adjusted
+        // after creating the column widget (e. g. when restoring the history
+        // having a different root URL than the controller indicates).
+        m_columns[0]->setUrl(dirListerUrl);
+    }
+
     int columnIndex = 0;
     foreach (ColumnWidget* column, m_columns) {
         if (column->url() == url) {
@@ -514,8 +530,18 @@ void DolphinColumnView::showColumn(const KUrl& url)
             // the column is no parent of the requested URL, hence
             // just delete all remaining columns
             if (columnIndex > 0) {
-                setActiveColumnIndex(columnIndex - 1);
-                deleteInactiveChildColumns();
+                QList<ColumnWidget*>::iterator start = m_columns.begin() + columnIndex;
+                QList<ColumnWidget*>::iterator end = m_columns.end();
+                for (QList<ColumnWidget*>::iterator it = start; it != end; ++it) {
+                    (*it)->deleteLater();
+                }
+                m_columns.erase(start, end);
+
+                const int maxIndex = m_columns.count() - 1;
+                Q_ASSERT(maxIndex >= 0);
+                if (m_index > maxIndex) {
+                    m_index = maxIndex;
+                }
                 break;
             }
         }
@@ -534,6 +560,8 @@ void DolphinColumnView::showColumn(const KUrl& url)
 
     QString path = activeUrl.url(KUrl::AddTrailingSlash);
     const QString targetPath = url.url(KUrl::AddTrailingSlash);
+
+    columnIndex = lastIndex;
     int slashIndex = path.count('/');
     bool hasSubPath = (slashIndex >= 0);
     while (hasSubPath) {
@@ -544,12 +572,40 @@ void DolphinColumnView::showColumn(const KUrl& url)
             path += subPath + '/';
             ++slashIndex;
 
+            const KUrl childUrl = KUrl(path);
             const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path));
-            if (dirIndex.isValid()) {
-                triggerItem(m_proxyModel->mapFromSource(dirIndex));
-            }
+            const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+
+            m_columns[columnIndex]->setChildUrl(childUrl);
+            columnIndex++;
+
+            ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
+            column->setModel(model());
+            column->setRootIndex(proxyIndex);
+            column->setActive(false);
+
+            m_columns.append(column);
+
+            // Before invoking layoutColumns() the column must be set visible temporary.
+            // To prevent a flickering the initial geometry is set to a hidden position.
+            column->setGeometry(QRect(-1, -1, 1, 1));
+            column->show();
+            layoutColumns();
+            updateScrollBar();
+
+            // the layout is finished, now let the column be invisible until it
+            // gets a valid root index due to expandToActiveUrl()
+            column->hide();
         }
     }
+
+    // set the last column as active column without modifying the controller
+    // and hence the history
+    activeColumn()->setActive(false);
+    m_index = columnIndex;
+    activeColumn()->setActive(true);
+
+    expandToActiveUrl();
 }
 
 bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const
@@ -661,41 +717,6 @@ void DolphinColumnView::zoomOut()
     }
 }
 
-void DolphinColumnView::triggerItem(const QModelIndex& index)
-{
-    m_controller->triggerItem(index);
-
-    const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
-    if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
-        return;
-    }
-
-    const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index));
-    if ((item.url() != activeColumn()->url()) && item.isDir()) {
-        deleteInactiveChildColumns();
-
-        const KUrl& childUrl = m_controller->url();
-        activeColumn()->setChildUrl(childUrl);
-
-        ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl);
-        column->setModel(model());
-        column->setRootIndex(index);
-
-        m_columns.append(column);
-
-        setActiveColumnIndex(m_index + 1);
-
-        // Before invoking layoutColumns() the column must be shown. To prevent
-        // a flickering the initial geometry is set to be invisible.
-        column->setGeometry(QRect(-1, -1, 1, 1));
-        column->show();
-
-        layoutColumns();
-        updateScrollBar();
-        assureVisibleActiveColumn();
-    }
-}
-
 void DolphinColumnView::moveContentHorizontally(int x)
 {
     m_contentX = -x;
@@ -725,8 +746,8 @@ void DolphinColumnView::expandToActiveUrl()
     const int lastIndex = m_columns.count() - 1;
     Q_ASSERT(lastIndex >= 0);
     const KUrl& activeUrl = m_columns[lastIndex]->url();
-    const KUrl baseUrl = m_dolphinModel->dirLister()->url();
-    if (baseUrl.isParentOf(activeUrl) && (baseUrl != activeUrl)) {
+    const KUrl rootUrl = m_dolphinModel->dirLister()->url();
+    if (rootUrl.isParentOf(activeUrl) && (rootUrl != activeUrl)) {
         m_dolphinModel->expandToUrl(activeUrl);
         reloadColumns();
     }
@@ -735,8 +756,6 @@ void DolphinColumnView::expandToActiveUrl()
 void DolphinColumnView::triggerReloadColumns(const QModelIndex& index)
 {
     Q_UNUSED(index);
-    disconnect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)),
-               this, SLOT(triggerReloadColumns(const QModelIndex&)));
     // the reloading of the columns may not be done in the context of this slot
     QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection);
 }
@@ -747,7 +766,9 @@ void DolphinColumnView::reloadColumns()
     for (int i = 0; i <= end; ++i) {
         ColumnWidget* nextColumn = m_columns[i + 1];
         const QModelIndex rootIndex = nextColumn->rootIndex();
-        if (!rootIndex.isValid()) {
+        if (rootIndex.isValid()) {
+            nextColumn->show();
+        } else {
             const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_columns[i]->childUrl());
             const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
             if (proxyIndex.isValid()) {
@@ -760,6 +781,7 @@ void DolphinColumnView::reloadColumns()
             }
         }
     }
+    assureVisibleActiveColumn();
 }
 
 bool DolphinColumnView::isZoomInPossible() const