From: Peter Penz Date: Sun, 2 Nov 2008 13:57:35 +0000 (+0000) Subject: Assure that automatically expanding of a folder also works when the new folder has... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/4469d4d5a45c0f5de821a3b45d20abc9ee5755bf Assure that automatically expanding of a folder also works when the new folder has a different view mode. CCMAIL: simon@etotheipiplusone.com svn path=/trunk/KDE/kdebase/apps/; revision=879143 --- diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 1300d9937..3e1cddfda 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -90,7 +90,8 @@ DolphinView::DolphinView(QWidget* parent, m_previewGenerator(0), m_toolTipManager(0), m_rootUrl(), - m_currentItemUrl() + m_currentItemUrl(), + m_expandedViews() { m_topLayout = new QVBoxLayout(this); m_topLayout->setSpacing(0); @@ -136,6 +137,7 @@ DolphinView::DolphinView(QWidget* parent, DolphinView::~DolphinView() { + deleteExpandedViews(); } const KUrl& DolphinView::url() const @@ -810,8 +812,25 @@ void DolphinView::wheelEvent(QWheelEvent* event) bool DolphinView::eventFilter(QObject* watched, QEvent* event) { - if ((watched == itemView()) && (event->type() == QEvent::FocusIn)) { - m_controller->requestActivation(); + switch (event->type()) { + case QEvent::FocusIn: + if (watched == itemView()) { + m_controller->requestActivation(); + } + break; + + case QEvent::MouseButtonPress: + if ((watched == itemView()->viewport()) && (m_expandedViews.count() > 0)) { + // Listening to a mousebutton press event to delete expanded views is a + // workaround, as it seems impossible for the FolderExpander to know when + // a dragging outside a view has been finished. However it works quite well: + // A mousebutton press event indicates that a drag operation must be + // finished already. + deleteExpandedViews(); + } + break; + default: + break; } return QWidget::eventFilter(watched, event); @@ -1049,6 +1068,16 @@ void DolphinView::restoreCurrentItem() } } +void DolphinView::enterDir(const QModelIndex& index, QAbstractItemView* view) +{ + // Deleting a view that is the root of a drag operation is not allowed, otherwise + // the dragging gets automatically cancelled by Qt. So before entering a new + // directory, the current view is remembered in m_expandedViews and deleted + // later when the drag operation has been finished (see DolphinView::eventFilter()). + m_expandedViews.append(view); + m_controller->triggerItem(index); +} + void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { @@ -1187,6 +1216,7 @@ void DolphinView::createView() Q_ASSERT(view != 0); view->installEventFilter(this); + view->viewport()->installEventFilter(this); if (m_mode != ColumnView) { // Give the view the ability to auto-expand its directories on hovering @@ -1198,8 +1228,8 @@ void DolphinView::createView() FolderExpander* folderExpander = new FolderExpander(view, m_proxyModel); folderExpander->setEnabled(enabled); - connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)), - m_controller, SLOT(triggerItem(const QModelIndex&))); + connect(folderExpander, SIGNAL(enterDir(const QModelIndex&, QAbstractItemView*)), + this, SLOT(enterDir(const QModelIndex&, QAbstractItemView*))); } m_controller->setItemView(view); @@ -1253,8 +1283,21 @@ void DolphinView::deleteView() m_topLayout->removeWidget(view); view->close(); - view->deleteLater(); + + bool deleteView = true; + foreach (const QAbstractItemView* expandedView, m_expandedViews) { + if (view == expandedView) { + // the current view got already expanded and must stay alive + // until the dragging has been completed + deleteView = false; + break; + } + } + if (deleteView) { + view->deleteLater(); + } view = 0; + m_iconsView = 0; m_detailsView = 0; m_columnView = 0; @@ -1325,6 +1368,17 @@ KUrl::List DolphinView::simplifiedSelectedUrls() const return list; } +void DolphinView::deleteExpandedViews() +{ + const QAbstractItemView* view = itemView(); + foreach (QAbstractItemView* expandedView, m_expandedViews) { + if (expandedView != view) { + expandedView->deleteLater(); + } + } + m_expandedViews.clear(); +} + bool DolphinView::itemsExpandable() const { return (m_detailsView != 0) && m_detailsView->itemsExpandable(); diff --git a/src/dolphinview.h b/src/dolphinview.h index 170bc6bf8..a2d5f93cf 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -625,6 +625,12 @@ private slots: * to m_currentItemUrl. */ void restoreCurrentItem(); + + /** + * Is connected to the enterDir() signal from the FolderExpander + * and triggers the entering of the directory indicated by \a index. + */ + void enterDir(const QModelIndex& index, QAbstractItemView* view); private: void loadDirectory(const KUrl& url, bool reload = false); @@ -691,6 +697,12 @@ private: * this method has been introduced for convenience. */ bool isColumnViewActive() const; + + /** + * Deletes all views from m_expandedViews except if the view + * is currently shown. + */ + void deleteExpandedViews(); private: bool m_active : 1; @@ -721,6 +733,8 @@ private: KUrl m_rootUrl; KUrl m_currentItemUrl; + + QList m_expandedViews; }; inline bool DolphinView::isColumnViewActive() const diff --git a/src/folderexpander.cpp b/src/folderexpander.cpp index 777f7ffa3..a5b6b35ee 100644 --- a/src/folderexpander.cpp +++ b/src/folderexpander.cpp @@ -133,8 +133,7 @@ void FolderExpander::autoExpandTimeout() viewAsTreeView->setExpanded(proxyIndexToExpand, !viewAsTreeView->isExpanded(proxyIndexToExpand)); } else { - // Enter this directory. - emit enterDir(proxyIndexToExpand); + emit enterDir(proxyIndexToExpand, m_view); } } } diff --git a/src/folderexpander.h b/src/folderexpander.h index bca98ae29..b3ae78da3 100644 --- a/src/folderexpander.h +++ b/src/folderexpander.h @@ -63,7 +63,8 @@ signals: * signal is not emitted when a QTreeView is used, as the entering of * the directory is already provided by expanding the tree node. */ - void enterDir(const QModelIndex& dirModelIndex); + void enterDir(const QModelIndex& dirModelIndex, QAbstractItemView* view); + private slots: void viewScrolled();