Implement support for renaming files.

svn path=/trunk/KDE/kdebase/apps/; revision=819943
This commit is contained in:
Fredrik Höglund 2008-06-12 17:24:35 +00:00
parent 6c1379668e
commit 35408f2c52
2 changed files with 46 additions and 1 deletions

View file

@ -87,6 +87,10 @@ FolderView::FolderView(QObject *parent, const QVariantList &args)
connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), SLOT(layoutChanged(QModelIndex,QModelIndex)));
m_delegate = new KFileItemDelegate(this);
connect(m_delegate, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
connect(m_delegate, SIGNAL(commitData(QWidget*)), SLOT(commitData(QWidget*)));
m_selectionModel = new QItemSelectionModel(m_model, this);
if ( args.count() ) {
@ -577,7 +581,44 @@ void FolderView::refreshIcons()
void FolderView::renameSelectedIcon()
{
// TODO Implement me!
QModelIndex index = m_selectionModel->currentIndex();
if (!index.isValid())
return;
QStyleOptionViewItemV4 option = viewOptions();
option.rect = mapToScene(visualRect(index)).boundingRect().toRect();
// ### Note that we don't embed the editor in the applet as a
// QGraphicsProxyWidget here, because calling setFocus() on the
// editor or the proxy doesn't work properly when we do.
QWidget *editor = m_delegate->createEditor(view(), option, index);
editor->installEventFilter(m_delegate);
m_delegate->updateEditorGeometry(editor, option, index);
m_delegate->setEditorData(editor, index);
editor->show();
editor->setFocus();
m_editorIndex = index;
}
void FolderView::commitData(QWidget *editor)
{
m_delegate->setModelData(editor, m_model, m_editorIndex);
}
void FolderView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
{
Q_UNUSED(hint)
if (editor->hasFocus()) {
setFocus();
}
editor->hide();
editor->removeEventFilter(m_delegate);
editor->deleteLater();
update();
}
void FolderView::moveToTrash(Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers)

View file

@ -77,6 +77,9 @@ private slots:
void deleteSelectedIcons();
void undoTextChanged(const QString &text);
void commitData(QWidget *editor);
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint);
private:
void createActions();
KUrl::List selectedUrls() const;
@ -117,6 +120,7 @@ private:
mutable bool m_layoutValid;
QPersistentModelIndex m_hoveredIndex;
QPersistentModelIndex m_pressedIndex;
QPersistentModelIndex m_editorIndex;
QRect m_rubberBand;
QPointF m_buttonDownPos;
QTime m_pressTime;