]> cloud.milkyroute.net Git - dolphin.git/commitdiff
- Allow to disable the automatic horizontal scrolling of the Folders Panel
authorPeter Penz <peter.penz19@gmail.com>
Wed, 27 Oct 2010 20:11:46 +0000 (20:11 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Wed, 27 Oct 2010 20:11:46 +0000 (20:11 +0000)
- Remember the 'Show Hidden Files' setting
- Improve the autoscroll behavior
- Fix issue that expanding folders might not increase the horizontal width
- Fix issue that the selected item might get hidden by the horizontal scrollbar

BUG: 191787
FIXED-IN: 4.6.0
CCMAIL: datpeter@yahoo.com>

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

src/panels/folders/dolphin_folderspanelsettings.kcfg
src/panels/folders/folderspanel.cpp
src/panels/folders/folderspanel.h
src/panels/folders/ktreeview.cpp
src/panels/folders/ktreeview_p.h
src/panels/folders/treeviewcontextmenu.cpp
src/panels/folders/treeviewcontextmenu.h

index a923845487e905517215be8cdcf912e52739da00..716be829cf328c65cb4cfe7f23c839a8160ecde7 100644 (file)
@@ -10,5 +10,9 @@
             <label>Show hidden files</label>
             <default>false</default>
         </entry>
+        <entry name="AutoScrolling" type="Bool">
+            <label>Automatic scrolling</label>
+            <default>true</default>
+        </entry>
     </group>
 </kcfg>
index fae7ca6a17003cc6841a893b24d9fb2cbad917d8..1b75f36bc213b2e6e5cbe7b3ba9bb5bc66498789 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
+ *   Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com>        *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #include <konq_operations.h>
 
 #include <QApplication>
-#include <QItemSelection>
-#include <QTreeView>
 #include <QBoxLayout>
+#include <QItemSelection>
 #include <QModelIndex>
+#include <QPointer>
+#include <QTreeView>
 #include <QScrollBar>
 #include <QTimer>
 
@@ -88,6 +89,17 @@ bool FoldersPanel::showHiddenFiles() const
     return FoldersPanelSettings::showHiddenFiles();
 }
 
+void FoldersPanel::setAutoScrolling(bool enable)
+{
+    m_treeView->setAutoHorizontalScroll(enable);
+    FoldersPanelSettings::setAutoScrolling(enable);
+}
+
+bool FoldersPanel::autoScrolling() const
+{
+    return FoldersPanelSettings::autoScrolling();
+}
+
 void FoldersPanel::rename(const KFileItem& item)
 {
     if (DolphinSettings::instance().generalSettings()->renameInline()) {
@@ -137,6 +149,7 @@ void FoldersPanel::showEvent(QShowEvent* event)
         m_dirLister->setDelayedMimeTypes(true);
         m_dirLister->setAutoErrorHandlingEnabled(false, this);
         m_dirLister->setShowingDotFiles(FoldersPanelSettings::showHiddenFiles());
+        connect(m_dirLister, SIGNAL(completed()), this, SLOT(slotDirListerCompleted()));
 
         Q_ASSERT(m_dolphinModel == 0);
         m_dolphinModel = new DolphinModel(this);
@@ -167,6 +180,9 @@ void FoldersPanel::showEvent(QShowEvent* event)
         QVBoxLayout* layout = new QVBoxLayout(this);
         layout->setMargin(0);
         layout->addWidget(m_treeView);
+
+        setAutoScrolling(FoldersPanelSettings::autoScrolling());
+        setShowHiddenFiles(FoldersPanelSettings::showHiddenFiles());
     }
 
     loadTree(url());
@@ -184,8 +200,9 @@ void FoldersPanel::contextMenuEvent(QContextMenuEvent* event)
         item = m_dolphinModel->itemForIndex(dolphinModelIndex);
     }
 
-    TreeViewContextMenu contextMenu(this, item);
-    contextMenu.open();
+    QPointer<TreeViewContextMenu> contextMenu = new TreeViewContextMenu(this, item);
+    contextMenu->open();
+    delete contextMenu;
 }
 
 void FoldersPanel::keyPressEvent(QKeyEvent* event)
@@ -224,7 +241,6 @@ void FoldersPanel::expandToDir(const QModelIndex& index)
 {
     m_treeView->setExpanded(index, true);
     selectLeafDirectory();
-    m_treeView->resizeColumnToContents(DolphinModel::Name);
 }
 
 void FoldersPanel::scrollToLeaf()
@@ -241,6 +257,19 @@ void FoldersPanel::updateMouseButtons()
     m_mouseButtons = QApplication::mouseButtons();
 }
 
+void FoldersPanel::slotDirListerCompleted()
+{
+    m_treeView->resizeColumnToContents(DolphinModel::Name);
+
+    if (m_setLeafVisible) {
+        // Invoke scrollToLeaf() asynchronously. This assures that
+        // the horizontal scrollbar is shown after resizing the column
+        // (otherwise the scrollbar might hide the leaf).
+        QTimer::singleShot(0, this, SLOT(scrollToLeaf()));
+        m_setLeafVisible = false;
+    }
+}
+
 void FoldersPanel::loadTree(const KUrl& url)
 {
     Q_ASSERT(m_dirLister != 0);
@@ -267,21 +296,10 @@ void FoldersPanel::selectLeafDirectory()
 {
     const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_leafDir);
     const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-    if (!proxyIndex.isValid()) {
-        return;
-    }
-
-    if (m_setLeafVisible) {
-        // Invoke m_treeView->scrollTo(proxyIndex) asynchronously by
-        // scrollToLeaf(). This assures that the scrolling is done after
-        // the horizontal scrollbar gets visible (otherwise the scrollbar
-        // might hide the leaf).
-        QTimer::singleShot(100, this, SLOT(scrollToLeaf()));
-        m_setLeafVisible = false;
+    if (proxyIndex.isValid()) {
+        QItemSelectionModel* selModel = m_treeView->selectionModel();
+        selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
     }
-
-    QItemSelectionModel* selModel = m_treeView->selectionModel();
-    selModel->setCurrentIndex(proxyIndex, QItemSelectionModel::ClearAndSelect);
 }
 
 #include "folderspanel.moc"
index 972dc13a767ef6fa22c93673330586cf3f0172d6..93223ffeb07a2bc0edb4fa651e520eb891e92e1a 100644 (file)
@@ -51,6 +51,9 @@ public:
     void setShowHiddenFiles(bool show);
     bool showHiddenFiles() const;
 
+    void setAutoScrolling(bool enable);
+    bool autoScrolling() const;
+
     void rename(const KFileItem& item);
 
 signals:
@@ -98,6 +101,8 @@ private slots:
 
     void updateMouseButtons();
 
+    void slotDirListerCompleted();
+
 private:
     /**
      * Initializes the base URL of the tree and expands all
index 7c30fad337bbb24c008eb467220b69c017c19910..2e9ccaa4189322ea96e0a2fe05efc5235b407fc3 100644 (file)
 KTreeView::KTreeViewPrivate::KTreeViewPrivate(KTreeView *parent) :
     parent(parent),
     autoHorizontalScroll(false),
-    timeLine(0),
-    startScrollTimer(0)
+    timeLine(0)
 {
-    startScrollTimer = new QTimer(this);
-    startScrollTimer->setSingleShot(true);
-    startScrollTimer->setInterval(300);
-    connect(startScrollTimer, SIGNAL(timeout()),
-            this, SLOT(startScrolling()));
-
-    timeLine = new QTimeLine(300, this);
+    timeLine = new QTimeLine(500, this);
     connect(timeLine, SIGNAL(frameChanged(int)),
             this, SLOT(updateVerticalScrollBar(int)));
 
     connect(parent->verticalScrollBar(), SIGNAL(rangeChanged(int, int)),
-            startScrollTimer, SLOT(start()));
+            this, SLOT(startScrolling()));
     connect(parent->verticalScrollBar(), SIGNAL(valueChanged(int)),
-            startScrollTimer, SLOT(start()));
+            this, SLOT(startScrolling()));
     connect(parent, SIGNAL(collapsed(const QModelIndex&)),
-            startScrollTimer, SLOT(start()));
+            this, SLOT(startScrolling()));
     connect(parent, SIGNAL(expanded(const QModelIndex&)),
-            startScrollTimer, SLOT(start()));
+            this, SLOT(startScrolling()));
 }
 
 void KTreeView::KTreeViewPrivate::startScrolling()
 {
-    QModelIndex index;
-
-    const int viewportHeight = parent->viewport()->height();
-
-    // check whether there is a selected index which is partly visible
-    const QModelIndexList selectedIndexes = parent->selectionModel()->selectedIndexes();
-    if (selectedIndexes.count() == 1) {
-        QModelIndex selectedIndex = selectedIndexes.first();
-        const QRect rect = parent->visualRect(selectedIndex);
-        if ((rect.bottom() >= 0) && (rect.top() <= viewportHeight)) {
-            // the selected index is (at least partly) visible, use it as
-            // scroll target
-            index = selectedIndex;
-        }
+    if (!autoHorizontalScroll) {
+        return;
     }
 
-    if (!index.isValid()) {
-        // no partly selected index is visible, determine the most left visual index
-        QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0));
-        if (!visibleIndex.isValid()) {
-            return;
-        }
-
-        index = visibleIndex;
-        int minimum = parent->width();
-        do {
-            const QRect rect = parent->visualRect(visibleIndex);
-            if (rect.top() > viewportHeight) {
-                // the current index and all successors are not visible anymore
-                break;
-            }
-            if (rect.left() < minimum) {
-                minimum = rect.left();
-                index = visibleIndex;
-            }
-            visibleIndex = parent->indexBelow(visibleIndex);
-        } while (visibleIndex.isValid());
+    // Determine the most left visual index
+    QModelIndex visibleIndex = parent->indexAt(QPoint(0, 0));
+    if (!visibleIndex.isValid()) {
+        return;
     }
 
-    // start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible
+    QModelIndex index = visibleIndex;
+    int minimum = parent->width();
+    do {
+        const QRect rect = parent->visualRect(visibleIndex);
+        if (rect.top() > parent->viewport()->height()) {
+            // the current index and all successors are not visible anymore
+            break;
+        }
+        if (rect.left() < minimum) {
+            minimum = rect.left();
+            index = visibleIndex;
+        }
+        visibleIndex = parent->indexBelow(visibleIndex);
+    } while (visibleIndex.isValid());
+
+    // Start the horizontal scrolling to assure that the item indicated by 'index' gets fully visible
     Q_ASSERT(index.isValid());
     const QRect rect = parent->visualRect(index);
 
-    QScrollBar *scrollBar = parent->horizontalScrollBar();
+    QScrollBarscrollBar = parent->horizontalScrollBar();
     const int oldScrollBarPos = scrollBar->value();
 
     const int itemRight = oldScrollBarPos + rect.left() + rect.width() - 1;
@@ -120,7 +99,6 @@ void KTreeView::KTreeViewPrivate::updateVerticalScrollBar(int value)
 {
     QScrollBar *scrollBar = parent->horizontalScrollBar();
     scrollBar->setValue(value);
-    startScrollTimer->stop();
 }
 
 // ************************************************
@@ -140,12 +118,12 @@ KTreeView::~KTreeView()
 
 void KTreeView::setAutoHorizontalScroll(bool value)
 {
-       d->autoHorizontalScroll = value;
+    d->autoHorizontalScroll = value;
 }
 
 bool KTreeView::autoHorizontalScroll() const
 {
-       return d->autoHorizontalScroll;
+    return d->autoHorizontalScroll;
 }
 
 void KTreeView::setSelectionModel(QItemSelectionModel *selectionModel)
@@ -153,25 +131,18 @@ void KTreeView::setSelectionModel(QItemSelectionModel *selectionModel)
     QTreeView::setSelectionModel(selectionModel);
     connect(selectionModel,
             SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-            d->startScrollTimer, SLOT(start()));
+            this, SLOT(startScrolling()));
 }
 
 void KTreeView::scrollTo(const QModelIndex& index, ScrollHint hint)
 {
-    if (d->autoHorizontalScroll) {
-        // assure that the value of the horizontal scrollbar stays on its current value,
-        // KTreeView will adjust the value manually
-        const int value = horizontalScrollBar()->value();
-        QTreeView::scrollTo(index, hint);
-        horizontalScrollBar()->setValue(value);
-    } else {
-        QTreeView::scrollTo(index, hint);
-    }
+    const int value = horizontalScrollBar()->value();
+    QTreeView::scrollTo(index, hint);
+    horizontalScrollBar()->setValue(value);
 }
 
 void KTreeView::hideEvent(QHideEvent *event)
 {
-    d->startScrollTimer->stop();
     d->timeLine->stop();
     QTreeView::hideEvent(event);
 }
index 1cfa463cd89e9e3b6669db3d8e1f5faa54352564..9ea4ac7eee0cc7bd9959b9b298fbc1a09e04f41c 100644 (file)
@@ -25,7 +25,6 @@
 
 #include "ktreeview.h"
 
-class QTimer;
 class QTimeLine;
 
 class KTreeView::KTreeViewPrivate : public QObject
@@ -39,11 +38,9 @@ public Q_SLOTS:
 public:
     KTreeViewPrivate(KTreeView *parent);
     KTreeView *parent;
-    void setScrollTowards( int scrollTowards );
 
     bool autoHorizontalScroll;
     QTimeLine *timeLine;
-    QTimer *startScrollTimer;
 };
 
 #endif /* ifndef KTREEVIEW_P_H */
index 32e92e05c2e8fcb874580c9d7536cff0960d291c..aa111c6bac194fe80abdefa19d3330c0c71d2283 100644 (file)
@@ -1,6 +1,6 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and              *
- *   Cvetoslav Ludmiloff                                                   *
+ *   Copyright (C) 2006-2010 by Peter Penz <peter.penz19@gmail.com>        *
+ *   Copyright (C) 2006 by Cvetoslav Ludmiloff                             *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -20,8 +20,6 @@
 
 #include "treeviewcontextmenu.h"
 
-#include "dolphin_folderspanelsettings.h"
-
 #include <kfileitem.h>
 #include <kiconloader.h>
 #include <kio/deletejob.h>
@@ -87,7 +85,7 @@ void TreeViewContextMenu::open()
         KConfigGroup configGroup(globalConfig, "KDE");
         bool showDeleteCommand = configGroup.readEntry("ShowDeleteCommand", false);
 
-        const KUrl& url = m_fileInfo.url();
+        const KUrl url = m_fileInfo.url();
         if (url.isLocalFile()) {
             QAction* moveToTrashAction = new QAction(KIcon("user-trash"),
                                                     i18nc("@action:inmenu", "Move to Trash"), this);
@@ -118,11 +116,17 @@ void TreeViewContextMenu::open()
 
     QAction* showHiddenFilesAction = new QAction(i18nc("@action:inmenu", "Show Hidden Files"), this);
     showHiddenFilesAction->setCheckable(true);
-    showHiddenFilesAction->setChecked(FoldersPanelSettings::showHiddenFiles());
+    showHiddenFilesAction->setChecked(m_parent->showHiddenFiles());
     popup->addAction(showHiddenFilesAction);
-
     connect(showHiddenFilesAction, SIGNAL(toggled(bool)), this, SLOT(setShowHiddenFiles(bool)));
 
+    QAction* autoScrollingAction = new QAction(i18nc("@action:inmenu", "Automatic Scrolling"), this);
+    autoScrollingAction->setCheckable(true);
+    autoScrollingAction->setChecked(m_parent->autoScrolling());
+    popup->addAction(autoScrollingAction);
+    connect(autoScrollingAction, SIGNAL(toggled(bool)), this, SLOT(setAutoScrolling(bool)));
+
+
     popup->exec(QCursor::pos());
     popup->deleteLater();
 }
@@ -193,4 +197,9 @@ void TreeViewContextMenu::setShowHiddenFiles(bool show)
     m_parent->setShowHiddenFiles(show);
 }
 
+void TreeViewContextMenu::setAutoScrolling(bool enable)
+{
+    m_parent->setAutoScrolling(enable);
+}
+
 #include "treeviewcontextmenu.moc"
index 8da23721b2a4abb9ca59f70ea929189c11b780a4..d7ebf09996f684284c536ea993e0d785ac589b78 100644 (file)
@@ -77,6 +77,12 @@ private slots:
      */
     void setShowHiddenFiles(bool show);
 
+    /**
+     * Sets the 'Automatic Scrolling' setting for the
+     * folders panel to \a enable.
+     */
+    void setAutoScrolling(bool enable);
+
 private:
     void populateMimeData(QMimeData* mimeData, bool cut);