diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 4d180442b7..16d72c0f06 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -59,6 +59,8 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control this, SLOT(setZoomLevel(int))); connect(controller, SIGNAL(activationChanged(bool)), this, SLOT(updateColumnsBackground(bool))); + connect(controller, SIGNAL(scrollToCurrentItem()), + this, SLOT(scrollToCurrentItem())); const DolphinView* view = controller->dolphinView(); connect(view, SIGNAL(sortingChanged(DolphinView::Sorting)), @@ -465,6 +467,12 @@ void DolphinColumnView::slotShowPreviewChanged() } } +void DolphinColumnView::scrollToCurrentItem() +{ + const QModelIndex activeIndex = activeColumn()->currentIndex(); + activeColumn()->scrollTo(activeIndex); +} + void DolphinColumnView::setActiveColumnIndex(int index) { if (m_index == index) { diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index caa54eab84..756037874f 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -112,7 +112,7 @@ public: * Returns the selected items of the active column. */ KFileItemList selectedItems() const; - + /** * Returns the MIME data for the selected items * of the active column. @@ -169,6 +169,7 @@ private slots: void slotSortOrderChanged(Qt::SortOrder order); void slotShowHiddenFilesChanged(); void slotShowPreviewChanged(); + void scrollToCurrentItem(); private: DolphinColumnWidget* activeColumn() const; diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index b128c90335..cfa0d62c82 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -124,6 +124,11 @@ void DolphinController::setZoomLevel(int level) } } +void DolphinController::triggerScrollToCurrentItem() +{ + emit scrollToCurrentItem(); +} + void DolphinController::handleKeyPressEvent(QKeyEvent* event) { Q_ASSERT(m_itemView != 0); diff --git a/src/dolphincontroller.h b/src/dolphincontroller.h index 29dd7dfb1b..ba10360602 100644 --- a/src/dolphincontroller.h +++ b/src/dolphincontroller.h @@ -73,6 +73,7 @@ class QWidget; * - setShowPreview() * - indicateActivationChange() * - setZoomLevel() + * - triggerScrollToCurrentItem() */ class LIBDOLPHINPRIVATE_EXPORT DolphinController : public QObject { @@ -189,6 +190,12 @@ public: void setZoomLevel(int level); int zoomLevel() const; + /** + * Triggers the view implementation to assure having a fully visible + * current item. The signal scrollToCurrentItem() will be emitted. + */ + void triggerScrollToCurrentItem(); + /** * Tells the view implementation to zoom out by emitting the signal zoomOut() * and is invoked by the abstract Dolphin view. @@ -369,6 +376,12 @@ signals: */ void hideToolTip(); + /** + * Is emitted if the view implementation should scroll to the current item, so + * that it is fully visible. + */ + void scrollToCurrentItem(); + private slots: void updateMouseButtonState(); diff --git a/src/dolphindetailsview.cpp b/src/dolphindetailsview.cpp index dd58e58424..fbd7e41d5c 100644 --- a/src/dolphindetailsview.cpp +++ b/src/dolphindetailsview.cpp @@ -128,6 +128,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent, DolphinController* contr this, SLOT(updateColumnVisibility())); connect(controller, SIGNAL(activationChanged(bool)), this, SLOT(slotActivationChanged(bool))); + connect(controller, SIGNAL(scrollToCurrentItem()), + this, SLOT(scrollToCurrentItem())); if (settings->useSystemFont()) { m_font = KGlobalSettings::generalFont(); @@ -866,6 +868,11 @@ void DolphinDetailsView::setFoldersExpandable(bool expandable) setItemsExpandable(expandable); } +void DolphinDetailsView::scrollToCurrentItem() +{ + scrollTo(currentIndex()); +} + void DolphinDetailsView::updateDecorationSize(bool showPreview) { DetailsModeSettings* settings = DolphinSettings::instance().detailsModeSettings(); diff --git a/src/dolphindetailsview.h b/src/dolphindetailsview.h index 38aea12dee..e60400b445 100644 --- a/src/dolphindetailsview.h +++ b/src/dolphindetailsview.h @@ -159,6 +159,8 @@ private slots: */ void setFoldersExpandable(bool expandable); + void scrollToCurrentItem(); + private: /** * Updates the size of the decoration dependent on the diff --git a/src/dolphiniconsview.cpp b/src/dolphiniconsview.cpp index f5b69bade4..4b861df449 100644 --- a/src/dolphiniconsview.cpp +++ b/src/dolphiniconsview.cpp @@ -88,6 +88,8 @@ DolphinIconsView::DolphinIconsView(QWidget* parent, DolphinController* controlle controller, SLOT(emitViewportEntered())); connect(controller, SIGNAL(zoomLevelChanged(int)), this, SLOT(setZoomLevel(int))); + connect(controller, SIGNAL(scrollToCurrentItem()), + this, SLOT(scrollToCurrentItem())); const DolphinView* view = controller->dolphinView(); connect(view, SIGNAL(showPreviewChanged()), @@ -390,6 +392,13 @@ void DolphinIconsView::slotGlobalSettingsChanged(int category) } } +void DolphinIconsView::scrollToCurrentItem() +{ + m_enableScrollTo = true; + scrollTo(currentIndex()); + m_enableScrollTo = false; +} + void DolphinIconsView::updateGridSize(bool showPreview, int additionalInfoCount) { const IconsModeSettings* settings = DolphinSettings::instance().iconsModeSettings(); diff --git a/src/dolphiniconsview.h b/src/dolphiniconsview.h index 76a369db98..8a1f1f8dd6 100644 --- a/src/dolphiniconsview.h +++ b/src/dolphiniconsview.h @@ -76,6 +76,7 @@ private slots: void setZoomLevel(int level); void requestActivation(); void slotGlobalSettingsChanged(int category); + void scrollToCurrentItem(); private: /** diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index f40accddea..638e6e7cb0 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -88,6 +88,7 @@ DolphinView::DolphinView(QWidget* parent, m_tabsForFiles(false), m_isContextMenuOpen(false), m_ignoreViewProperties(false), + m_assureVisibleCurrentIndex(false), m_mode(DolphinView::IconsView), m_topLayout(0), m_controller(0), @@ -142,6 +143,8 @@ DolphinView::DolphinView(QWidget* parent, this, SIGNAL(redirection(KUrl, KUrl))); connect(m_dirLister, SIGNAL(completed()), this, SLOT(restoreCurrentItem())); + connect(m_dirLister, SIGNAL(refreshItems(const QList>&)), + this, SLOT(slotRefreshItems())); applyViewProperties(url); m_topLayout->addWidget(itemView()); @@ -629,30 +632,31 @@ void DolphinView::renameSelectedItems() const QString newName = dialog.newName(); if (newName.isEmpty()) { emit errorMessage(dialog.errorString()); - } else { - // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations - // as one operation instead of n rename operations like it is done now... - Q_ASSERT(newName.contains('#')); + return; + } - // currently the items are sorted by the selection order, resort - // them by the file name - qSort(items.begin(), items.end(), lessThan); + // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations + // as one operation instead of n rename operations like it is done now... + Q_ASSERT(newName.contains('#')); - // iterate through all selected items and rename them... - int index = 1; - foreach (const KFileItem& item, items) { - const KUrl& oldUrl = item.url(); - QString number; - number.setNum(index++); + // currently the items are sorted by the selection order, resort + // them by the file name + qSort(items.begin(), items.end(), lessThan); - QString name = newName; - name.replace('#', number); + // iterate through all selected items and rename them... + int index = 1; + foreach (const KFileItem& item, items) { + const KUrl& oldUrl = item.url(); + QString number; + number.setNum(index++); - if (oldUrl.fileName() != name) { - KUrl newUrl = oldUrl; - newUrl.setFileName(name); - KonqOperations::rename(this, oldUrl, newUrl); - } + QString name = newName; + name.replace('#', number); + + if (oldUrl.fileName() != name) { + KUrl newUrl = oldUrl; + newUrl.setFileName(name); + KonqOperations::rename(this, oldUrl, newUrl); } } } else if (DolphinSettings::instance().generalSettings()->renameInline()) { @@ -676,13 +680,18 @@ void DolphinView::renameSelectedItems() const QString& newName = dialog.newName(); if (newName.isEmpty()) { emit errorMessage(dialog.errorString()); - } else { - const KUrl& oldUrl = items.first().url(); - KUrl newUrl = oldUrl; - newUrl.setFileName(newName); - KonqOperations::rename(this, oldUrl, newUrl); + return; } + + const KUrl& oldUrl = items.first().url(); + KUrl newUrl = oldUrl; + newUrl.setFileName(newName); + KonqOperations::rename(this, oldUrl, newUrl); } + + // assure that the current index remains visible when KDirLister + // will notify the view about changed items + m_assureVisibleCurrentIndex = true; } void DolphinView::trashSelectedItems() @@ -1147,6 +1156,17 @@ void DolphinView::restoreCurrentItem() } } +void DolphinView::slotRefreshItems() +{ + if (m_assureVisibleCurrentIndex) { + m_assureVisibleCurrentIndex = false; + // Invoking itemView()->scrollTo(itemView()->currentIndex()) is + // not sufficient, as QListView and QTreeView have an inconsistent + // default behavior. + m_controller->triggerScrollToCurrentItem(); + } +} + void DolphinView::loadDirectory(const KUrl& url, bool reload) { if (!url.isValid()) { diff --git a/src/dolphinview.h b/src/dolphinview.h index 5cedeecfa8..1498de08aa 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -630,6 +630,11 @@ private slots: */ void restoreCurrentItem(); + /** + * Is invoked when the KDirLister indicates refreshed items. + */ + void slotRefreshItems(); + /** * If \a view can be positively identified as not being the source for the * current drag operation, deleteLater() it immediately. Else stores @@ -716,6 +721,7 @@ private: bool m_tabsForFiles : 1; bool m_isContextMenuOpen : 1; // TODO: workaround for Qt-issue 207192 bool m_ignoreViewProperties : 1; + bool m_assureVisibleCurrentIndex : 1; Mode m_mode; @@ -739,7 +745,7 @@ private: KUrl m_rootUrl; KUrl m_currentItemUrl; - QAbstractItemView* m_expandedDragSource; + QAbstractItemView* m_expandedDragSource; }; inline bool DolphinView::isColumnViewActive() const