From cfb135f24e6b1b3eb1253c8ebf7c8e7307974eea Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 23 Mar 2008 15:53:12 +0000 Subject: [PATCH] provide an option to rename files inline CCMAIL: fredrik@kde.org svn path=/trunk/KDE/kdebase/apps/; revision=789208 --- src/dolphincolumnview.cpp | 8 ++++++-- src/dolphincolumnview.h | 6 ++++++ src/dolphincolumnwidget.cpp | 12 ++++++++---- src/dolphincolumnwidget.h | 7 +++++++ src/dolphinview.cpp | 29 +++++++++++++++-------------- src/dolphinview.h | 3 +-- 6 files changed, 43 insertions(+), 22 deletions(-) diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index b0ce521728..1ed8b6b827 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -249,6 +249,11 @@ void DolphinColumnView::showColumn(const KUrl& url) assureVisibleActiveColumn(); } +void DolphinColumnView::editItem(const KFileItem& item) +{ + activeColumn()->editItem(item); +} + void DolphinColumnView::selectAll() { activeColumn()->selectAll(); @@ -305,13 +310,12 @@ void DolphinColumnView::setSelection(const QRect& rect, QItemSelectionModel::Sel { Q_UNUSED(rect); Q_UNUSED(flags); - //activeColumn()->setSelection(rect, flags); } QRegion DolphinColumnView::visualRegionForSelection(const QItemSelection& selection) const { Q_UNUSED(selection); - return QRegion(); //activeColumn()->visualRegionForSelection(selection); + return QRegion(); } int DolphinColumnView::horizontalOffset() const diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 6ac4fdb3f1..2ab4d2d5da 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -91,6 +91,12 @@ public: */ void showColumn(const KUrl& url); + /** + * Does an inline editing for the item \a item + * inside the active column. + */ + void editItem(const KFileItem& item); + public slots: /** @see QAbstractItemView::selectAll() */ virtual void selectAll(); diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index 6b1ebf1859..fba415efc5 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -229,6 +229,14 @@ void DolphinColumnWidget::setNameFilter(const QString& nameFilter) m_proxyModel->setFilterRegExp(nameFilter); } +void DolphinColumnWidget::editItem(const KFileItem& item) +{ + const QModelIndex dirIndex = m_dolphinModel->indexForItem(item); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + if (proxyIndex.isValid()) { + edit(proxyIndex); + } +} QStyleOptionViewItem DolphinColumnWidget::viewOptions() const { @@ -305,15 +313,11 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event) if (proxyIndex.isValid() && !selectionModel()->isSelected(proxyIndex)) { const QRect itemRect = visualRect(proxyIndex); QPainter painter(viewport()); - painter.save(); - QColor color = KColorScheme(QPalette::Active, KColorScheme::View).foreground().color(); color.setAlpha(32); painter.setPen(Qt::NoPen); painter.setBrush(color); painter.drawRect(itemRect); - - painter.restore(); } } diff --git a/src/dolphincolumnwidget.h b/src/dolphincolumnwidget.h index 3472f95d8b..11acb6d028 100644 --- a/src/dolphincolumnwidget.h +++ b/src/dolphincolumnwidget.h @@ -98,6 +98,11 @@ public: */ void setNameFilter(const QString& nameFilter); + /** + * Does an inline editing for the item \a item. + */ + void editItem(const KFileItem& item); + protected: virtual QStyleOptionViewItem viewOptions() const; virtual void startDrag(Qt::DropActions supportedActions); @@ -140,6 +145,8 @@ private: IconManager* m_iconManager; QRect m_dropRect; + + friend class DolphinColumnView; }; inline bool DolphinColumnWidget::isActive() const diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 4800b9e9ab..3f8933bd31 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,6 @@ #include "dolphinmodel.h" #include "dolphincolumnview.h" #include "dolphincontroller.h" -#include "dolphinfileitemdelegate.h" #include "dolphinsortfilterproxymodel.h" #include "dolphindetailsview.h" #include "dolphiniconsview.h" @@ -866,16 +866,12 @@ void DolphinView::emitContentsMoved() void DolphinView::showHoverInformation(const KFileItem& item) { - if (!hasSelection()) { - emit requestItemInfo(item); - } + emit requestItemInfo(item); } void DolphinView::clearHoverInformation() { - if (m_active) { - emit requestItemInfo(KFileItem()); - } + emit requestItemInfo(KFileItem()); } void DolphinView::createView() @@ -909,7 +905,7 @@ void DolphinView::createView() m_controller->setItemView(view); - m_fileItemDelegate = new DolphinFileItemDelegate(view); + m_fileItemDelegate = new KFileItemDelegate(view); view->setItemDelegate(m_fileItemDelegate); view->setModel(m_proxyModel); @@ -1021,14 +1017,19 @@ void DolphinView::renameSelectedItems() } } } - } else { - // Only one item has been selected for renaming. Use the custom - // renaming mechanism from the views. + } else if (DolphinSettings::instance().generalSettings()->renameInline()) { + Q_ASSERT(items.count() == 1); + + if (isColumnViewActive()) { + m_columnView->editItem(items.first()); + } else { + const QModelIndex dirIndex = m_dolphinModel->indexForItem(items.first()); + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + itemView()->edit(proxyIndex); + } + } else { Q_ASSERT(items.count() == 1); - // TODO: Think about using KFileItemDelegate as soon as it supports editing. - // Currently the RenameDialog is used, but I'm not sure whether inline renaming - // is a benefit for the user at all -> let's wait for some input first... RenameDialog dialog(this, items); if (dialog.exec() == QDialog::Rejected) { return; diff --git a/src/dolphinview.h b/src/dolphinview.h index f7d95c6e28..4f29647613 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -41,7 +41,6 @@ class DolphinController; class DolphinColumnView; class DolphinDetailsView; -class DolphinFileItemDelegate; class DolphinIconsView; class DolphinMainWindow; class DolphinModel; @@ -636,7 +635,7 @@ private: DolphinIconsView* m_iconsView; DolphinDetailsView* m_detailsView; DolphinColumnView* m_columnView; - DolphinFileItemDelegate* m_fileItemDelegate; + KFileItemDelegate* m_fileItemDelegate; QItemSelectionModel* m_selectionModel; DolphinModel* m_dolphinModel;