From: Peter Penz Date: Wed, 27 Oct 2010 20:11:46 +0000 (+0000) Subject: - Allow to disable the automatic horizontal scrolling of the Folders Panel X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/8559b78d7d4061bb70e6fe6ac2b787692282e69d - Allow to disable the automatic horizontal scrolling of the Folders Panel - 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 --- diff --git a/src/panels/folders/dolphin_folderspanelsettings.kcfg b/src/panels/folders/dolphin_folderspanelsettings.kcfg index a92384548..716be829c 100644 --- a/src/panels/folders/dolphin_folderspanelsettings.kcfg +++ b/src/panels/folders/dolphin_folderspanelsettings.kcfg @@ -10,5 +10,9 @@ false + + + true + diff --git a/src/panels/folders/folderspanel.cpp b/src/panels/folders/folderspanel.cpp index fae7ca6a1..1b75f36bc 100644 --- a/src/panels/folders/folderspanel.cpp +++ b/src/panels/folders/folderspanel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz * + * Copyright (C) 2006-2010 by Peter Penz * * * * 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 * @@ -31,10 +31,11 @@ #include #include -#include -#include #include +#include #include +#include +#include #include #include @@ -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 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" diff --git a/src/panels/folders/folderspanel.h b/src/panels/folders/folderspanel.h index 972dc13a7..93223ffeb 100644 --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@ -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 diff --git a/src/panels/folders/ktreeview.cpp b/src/panels/folders/ktreeview.cpp index 7c30fad33..2e9ccaa41 100644 --- a/src/panels/folders/ktreeview.cpp +++ b/src/panels/folders/ktreeview.cpp @@ -31,75 +31,54 @@ 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(); + QScrollBar* scrollBar = 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); } diff --git a/src/panels/folders/ktreeview_p.h b/src/panels/folders/ktreeview_p.h index 1cfa463cd..9ea4ac7ee 100644 --- a/src/panels/folders/ktreeview_p.h +++ b/src/panels/folders/ktreeview_p.h @@ -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 */ diff --git a/src/panels/folders/treeviewcontextmenu.cpp b/src/panels/folders/treeviewcontextmenu.cpp index 32e92e05c..aa111c6ba 100644 --- a/src/panels/folders/treeviewcontextmenu.cpp +++ b/src/panels/folders/treeviewcontextmenu.cpp @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) and * - * Cvetoslav Ludmiloff * + * Copyright (C) 2006-2010 by Peter Penz * + * 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 #include #include @@ -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" diff --git a/src/panels/folders/treeviewcontextmenu.h b/src/panels/folders/treeviewcontextmenu.h index 8da23721b..d7ebf0999 100644 --- a/src/panels/folders/treeviewcontextmenu.h +++ b/src/panels/folders/treeviewcontextmenu.h @@ -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);