]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Implement inline-renaming for the new view-engine
authorPeter Penz <peter.penz19@gmail.com>
Tue, 17 Apr 2012 16:13:31 +0000 (18:13 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 17 Apr 2012 16:15:12 +0000 (18:15 +0200)
BUG: 286893
FIXED-IN: 4.9.0

17 files changed:
src/CMakeLists.txt
src/dolphinmainwindow.cpp
src/kitemviews/kfileitemlistview.cpp
src/kitemviews/kfileitemlistwidget.cpp
src/kitemviews/kfileitemlistwidget.h
src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h
src/kitemviews/kitemlistwidget.cpp
src/kitemviews/kitemlistwidget.h
src/kitemviews/private/kitemlistroleeditor.cpp [new file with mode: 0644]
src/kitemviews/private/kitemlistroleeditor.h [new file with mode: 0644]
src/panels/folders/folderspanel.cpp
src/panels/folders/folderspanel.h
src/statusbar/dolphinstatusbar.cpp
src/views/dolphinview.cpp
src/views/dolphinview.h
src/views/dolphinviewactionhandler.cpp

index e9079569a589d88058a29f09c7a00dc4eab12c49..97a307b5da6a3be5c006e726629c451913ef02cc 100644 (file)
@@ -38,6 +38,7 @@ set(dolphinprivate_LIB_SRCS
     kitemviews/private/kfileitemmodelfilter.cpp
     kitemviews/private/kitemlistheaderwidget.cpp
     kitemviews/private/kitemlistkeyboardsearchmanager.cpp
+    kitemviews/private/kitemlistroleeditor.cpp
     kitemviews/private/kitemlistrubberband.cpp
     kitemviews/private/kitemlistselectiontoggle.cpp
     kitemviews/private/kitemlistsizehintresolver.cpp
index c62d685f602b563c775f4a51b94ad0b662d52bfb..dc413dcbff07e1607bfb07a09a11b7d4cdb05ddb 100644 (file)
@@ -1288,7 +1288,7 @@ void DolphinMainWindow::handleUrl(const KUrl& url)
                 this, SLOT(slotHandleUrlStatFinished(KJob*)));
 
     } else {
-        new KRun(url, this);
+        new KRun(url, this); // Automatically deletes itself after being finished
     }
 }
 
@@ -1300,7 +1300,7 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
     if (entry.isDir()) {
         activeViewContainer()->setUrl(url);
     } else {
-        new KRun(url, this);
+        new KRun(url, this);  // Automatically deletes itself after being finished
     }
 }
 
index 6464ec38acd0497c5f814b5bf49b5e935ab6000c..c5c4448750f55c4fdd4cefd3134b51d302539035 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <KDebug>
 #include <KIcon>
+#include <KTextEdit>
 
 #include <QPainter>
 #include <QTextLine>
index 5c5690c40f27e623a325a23ab4c22a03be4f1278..39ed02f07672699e6a5633abd2661ba68a255649 100644 (file)
 #include <KDebug>
 
 #include "private/kfileitemclipboard.h"
+#include "private/kitemlistroleeditor.h"
 #include "private/kpixmapmodifier.h"
 
 #include <QFontMetricsF>
+#include <QGraphicsScene>
 #include <QGraphicsSceneResizeEvent>
+#include <QGraphicsView>
 #include <QPainter>
 #include <QStyleOption>
 #include <QTextLayout>
@@ -64,7 +67,8 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
     m_customTextColor(),
     m_additionalInfoTextColor(),
     m_overlay(),
-    m_rating()
+    m_rating(),
+    m_roleEditor(0)
 {
 }
 
@@ -72,6 +76,8 @@ KFileItemListWidget::~KFileItemListWidget()
 {
     qDeleteAll(m_textInfo);
     m_textInfo.clear();
+
+    delete m_roleEditor;
 }
 
 void KFileItemListWidget::setLayout(Layout layout)
@@ -482,10 +488,76 @@ void KFileItemListWidget::siblingsInformationChanged(const QBitArray& current, c
     m_dirtyLayout = true;
 }
 
+void KFileItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
+{
+    Q_UNUSED(previous);
+
+   QGraphicsView* parent = scene()->views()[0];
+   if (current.isEmpty() || !parent || current != "name") {
+        if (m_roleEditor) {
+            emit roleEditingCanceled(index(), current, data().value(current));
+            m_roleEditor->deleteLater();
+            m_roleEditor = 0;
+        }
+        return;
+    }
+
+    Q_ASSERT(!m_roleEditor);
+
+    const TextInfo* textInfo = m_textInfo.value("name");
+
+    m_roleEditor = new KItemListRoleEditor(parent);
+    m_roleEditor->setIndex(index());
+    m_roleEditor->setRole(current);
+
+    const QString text = data().value(current).toString();
+    m_roleEditor->setPlainText(text);
+
+    QTextOption textOption = textInfo->staticText.textOption();
+    m_roleEditor->document()->setDefaultTextOption(textOption);
+
+    // Select the text without MIME-type extension
+    int selectionLength = text.length();
+
+    const QString extension = KMimeType::extractKnownExtension(text);
+    if (!extension.isEmpty()) {
+        selectionLength -= extension.length() + 1;
+    }
+
+    if (selectionLength > 0) {
+        QTextCursor cursor = m_roleEditor->textCursor();
+        cursor.movePosition(QTextCursor::StartOfBlock);
+        cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, selectionLength);
+        m_roleEditor->setTextCursor(cursor);
+    }
+
+    connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
+            this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
+    connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+            this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+
+    // Adjust the geometry of the editor
+    QRectF rect = roleEditingRect(current);
+    const int frameWidth = m_roleEditor->frameWidth();
+    rect.adjust(-frameWidth, -frameWidth, frameWidth, frameWidth);
+    rect.translate(pos());
+    if (rect.right() > parent->width()) {
+        rect.setWidth(parent->width() - rect.left());
+    }
+    m_roleEditor->setGeometry(rect.toRect());
+    m_roleEditor->show();
+    m_roleEditor->setFocus();
+}
 
 void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
 {
+    if (m_roleEditor) {
+        setEditedRole(QByteArray());
+        Q_ASSERT(!m_roleEditor);
+    }
+
     KItemListWidget::resizeEvent(event);
+
     m_dirtyLayout = true;
 }
 
@@ -523,6 +595,26 @@ void KFileItemListWidget::slotCutItemsChanged()
     }
 }
 
+void KFileItemListWidget::slotRoleEditingCanceled(int index,
+                                                  const QByteArray& role,
+                                                  const QVariant& value)
+{
+    m_roleEditor->deleteLater();
+    m_roleEditor = 0;
+    emit roleEditingCanceled(index, role, value);
+    setEditedRole(QByteArray());
+}
+
+void KFileItemListWidget::slotRoleEditingFinished(int index,
+                                                  const QByteArray& role,
+                                                  const QVariant& value)
+{
+    m_roleEditor->deleteLater();
+    m_roleEditor = 0;
+    emit roleEditingFinished(index, role, value);
+    setEditedRole(QByteArray());
+}
+
 void KFileItemListWidget::triggerCacheRefreshing()
 {
     if ((!m_dirtyContent && !m_dirtyLayout) || index() < 0) {
@@ -1043,6 +1135,21 @@ void KFileItemListWidget::drawSiblingsInformation(QPainter* painter)
     }
 }
 
+QRectF KFileItemListWidget::roleEditingRect(const QByteArray& role) const
+{
+    const TextInfo* textInfo = m_textInfo.value(role);
+    if (!textInfo) {
+        return QRectF();
+    }
+
+    QRectF rect(textInfo->pos, textInfo->staticText.size());
+    if (m_layout == DetailsLayout) {
+        rect.setWidth(columnWidth(role) - rect.x());
+    }
+
+    return rect;
+}
+
 QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
 {
     const KIcon icon(name);
index 551b47fc33b43feb695554fc46383117518216b0..33d348babf3211e11c18fea951771843f4bdd890 100644 (file)
@@ -28,8 +28,9 @@
 #include <QPointF>
 #include <QStaticText>
 
-class KItemListView;
+class KItemListRoleEditor;
 class KItemListStyleOption;
+class KItemListView;
 
 class LIBDOLPHINPRIVATE_EXPORT KFileItemListWidget : public KItemListWidget
 {
@@ -102,12 +103,15 @@ protected:
     virtual void hoveredChanged(bool hovered);
     virtual void selectedChanged(bool selected);
     virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
+    virtual void editedRoleChanged(const QByteArray& current, const QByteArray& previous);
     virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
     virtual void showEvent(QShowEvent* event);
     virtual void hideEvent(QHideEvent* event);
 
 private slots:
     void slotCutItemsChanged();
+    void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
+    void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
 
 private:
     /**
@@ -137,6 +141,8 @@ private:
     void drawPixmap(QPainter* painter, const QPixmap& pixmap);
     void drawSiblingsInformation(QPainter* painter);
 
+    QRectF roleEditingRect(const QByteArray &role) const;
+
     static QPixmap pixmapForIcon(const QString& name, int size);
     static void applyCutEffect(QPixmap& pixmap);
     static void applyHiddenEffect(QPixmap& pixmap);
@@ -196,6 +202,8 @@ private:
 
     QPixmap m_overlay;
     QPixmap m_rating;
+
+    KItemListRoleEditor* m_roleEditor;
 };
 
 #endif
index c625234104a991acb0984aeaac2735e62f95282b..d53c245890826ae5da6b7092edde8b9a029354f4 100644 (file)
@@ -57,6 +57,7 @@ KItemListView::KItemListView(QGraphicsWidget* parent) :
     m_enabledSelectionToggles(false),
     m_grouped(false),
     m_supportsItemExpanding(false),
+    m_editingRole(false),
     m_activeTransactions(0),
     m_endTransactionAnimationHint(Animation),
     m_itemSize(),
@@ -667,6 +668,23 @@ QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
     return QPixmap();
 }
 
+void KItemListView::editRole(int index, const QByteArray& role)
+{
+    KItemListWidget* widget = m_visibleItems.value(index);
+    if (!widget) {
+        return;
+    }
+
+    Q_ASSERT(!m_editingRole);
+    m_editingRole = true;
+    widget->setEditedRole(role);
+
+    connect(widget, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
+            this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
+    connect(widget, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+            this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+}
+
 void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
 {
     QGraphicsWidget::paint(painter, option, widget);
@@ -760,7 +778,7 @@ void KItemListView::onTransactionEnd()
 bool KItemListView::event(QEvent* event)
 {
     // Forward all events to the controller and handle them there
-    if (m_controller && m_controller->processEvent(event, transform())) {
+    if (!m_editingRole && m_controller && m_controller->processEvent(event, transform())) {
         event->accept();
         return true;
     }
@@ -1331,6 +1349,18 @@ void KItemListView::slotGeometryOfGroupHeaderParentChanged()
     updateGroupHeaderLayout(widget);
 }
 
+void KItemListView::slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value)
+{
+    emit roleEditingCanceled(index, role, value);
+    m_editingRole = false;
+}
+
+void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
+{
+    emit roleEditingFinished(index, role, value);
+    m_editingRole = false;
+}
+
 void KItemListView::setController(KItemListController* controller)
 {
     if (m_controller != controller) {
index a3c11a6bf142a6584d0789a5e2e5c9ff73d0f025..13f62f89b2d5f48edf2c2993c0c9157838c55c03 100644 (file)
@@ -265,6 +265,11 @@ public:
      */
     virtual QPixmap createDragPixmap(const QSet<int>& indexes) const;
 
+    /**
+     * Lets the user edit the role \a role for item with the index \a index.
+     */
+    void editRole(int index, const QByteArray& role);
+
     /**
      * @reimp
      */
@@ -304,7 +309,14 @@ signals:
      */
     void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
 
+    void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
+    void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+
 protected:
+    /**
+     * Is called when creating a new KItemListWidget instance and allows derived
+     * classes to do a custom initialization.
+     */
     virtual void initializeItemListWidget(KItemListWidget* item);
 
     /**
@@ -394,6 +406,9 @@ private slots:
      */
     void slotGeometryOfGroupHeaderParentChanged();
 
+    void slotRoleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
+    void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+
 private:
     enum LayoutAnimationHint
     {
@@ -633,6 +648,7 @@ private:
     bool m_enabledSelectionToggles;
     bool m_grouped;
     bool m_supportsItemExpanding;
+    bool m_editingRole;
     int m_activeTransactions; // Counter for beginTransaction()/endTransaction()
     LayoutAnimationHint m_endTransactionAnimationHint;
 
index 74b96ca1f572dd3500e6bf3bc948148729a63c22..542b781f1bce82d32595a6912890d8add84faa73 100644 (file)
@@ -51,7 +51,8 @@ KItemListWidget::KItemListWidget(QGraphicsItem* parent) :
     m_hoverOpacity(0),
     m_hoverCache(0),
     m_hoverAnimation(0),
-    m_selectionToggle(0)
+    m_selectionToggle(0),
+    m_editedRole()
 {
 }
 
@@ -112,7 +113,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
         painter->fillRect(backgroundRect, backgroundColor);
     }
 
-    if (m_selected) {
+    if (m_selected && m_editedRole.isEmpty()) {
         const QStyle::State activeState(isActiveWindow() ? QStyle::State_Active : 0);
         drawItemStyleOption(painter, widget, activeState |
                                              QStyle::State_Enabled |
@@ -120,7 +121,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
                                              QStyle::State_Item);
     }
 
-    if (isCurrent()) {
+    if (m_current && m_editedRole.isEmpty()) {
         QStyleOptionFocusRect focusRectOption;
         focusRectOption.initFrom(widget);
         focusRectOption.rect = textFocusRect().toRect();
@@ -309,6 +310,20 @@ QBitArray KItemListWidget::siblingsInformation() const
     return m_siblingsInfo;
 }
 
+void KItemListWidget::setEditedRole(const QByteArray& role)
+{
+    if (m_editedRole != role) {
+        const QByteArray previous = m_editedRole;
+        m_editedRole = role;
+        editedRoleChanged(role, previous);
+    }
+}
+
+QByteArray KItemListWidget::editedRole() const
+{
+    return m_editedRole;
+}
+
 bool KItemListWidget::contains(const QPointF& point) const
 {
     if (!QGraphicsWidget::contains(point)) {
@@ -392,6 +407,12 @@ void KItemListWidget::siblingsInformationChanged(const QBitArray& current, const
     Q_UNUSED(previous);
 }
 
+void KItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
+{
+    Q_UNUSED(current);
+    Q_UNUSED(previous);
+}
+
 void KItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
 {
     QGraphicsWidget::resizeEvent(event);
index 4c8ff1a9520fd30975ab1f9f644e0274a866eed2..8a28913b663e6a0345d63a78cafa1add07ee2b78 100644 (file)
@@ -102,6 +102,16 @@ public:
     void setSiblingsInformation(const QBitArray& siblings);
     QBitArray siblingsInformation() const;
 
+    /**
+     * Allows the user to edit the role \a role. The signals
+     * roleEditingCanceled() or roleEditingFinished() will be
+     * emitted after editing. An ongoing editing gets canceled if
+     * the role is empty. Derived classes must implement
+     * editedRoleChanged().
+     */
+    void setEditedRole(const QByteArray& role);
+    QByteArray editedRole() const;
+
     /**
      * @return True if \a point is inside KItemListWidget::hoverRect(),
      *         KItemListWidget::textRect(), KItemListWidget::selectionToggleRect()
@@ -143,6 +153,10 @@ public:
      */
     virtual QRectF expansionToggleRect() const;
 
+signals:
+    void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
+    void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+
 protected:
     virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
     virtual void visibleRolesChanged(const QList<QByteArray>& current, const QList<QByteArray>& previous);
@@ -153,6 +167,7 @@ protected:
     virtual void hoveredChanged(bool hovered);
     virtual void alternateBackgroundChanged(bool enabled);
     virtual void siblingsInformationChanged(const QBitArray& current, const QBitArray& previous);
+    virtual void editedRoleChanged(const QByteArray& current, const QByteArray& previous);
     virtual void resizeEvent(QGraphicsSceneResizeEvent* event);
 
     /**
@@ -190,6 +205,8 @@ private:
     QPropertyAnimation* m_hoverAnimation;
 
     KItemListSelectionToggle* m_selectionToggle;
+
+    QByteArray m_editedRole;
 };
 #endif
 
diff --git a/src/kitemviews/private/kitemlistroleeditor.cpp b/src/kitemviews/private/kitemlistroleeditor.cpp
new file mode 100644 (file)
index 0000000..55af6a9
--- /dev/null
@@ -0,0 +1,113 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   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  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#include "kitemlistroleeditor.h"
+
+#include <KDebug>
+#include <QKeyEvent>
+
+KItemListRoleEditor::KItemListRoleEditor(QWidget *parent) :
+    KTextEdit(parent),
+    m_index(0),
+    m_role()
+{
+    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    document()->setDocumentMargin(0);
+
+    if (parent) {
+        parent->installEventFilter(this);
+    }
+}
+
+KItemListRoleEditor::~KItemListRoleEditor()
+{
+}
+
+void KItemListRoleEditor::setIndex(int index)
+{
+    m_index = index;
+}
+
+int KItemListRoleEditor::index() const
+{
+    return m_index;
+}
+
+void KItemListRoleEditor::setRole(const QByteArray& role)
+{
+    m_role = role;
+}
+
+QByteArray KItemListRoleEditor::role() const
+{
+    return m_role;
+}
+
+bool  KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
+{
+    if (watched == parentWidget() && event->type() == QEvent::Resize) {
+        autoAdjustSize();
+    }
+
+    return KTextEdit::eventFilter(watched, event);
+}
+
+bool KItemListRoleEditor::event(QEvent* event)
+{
+    if (event->type() == QEvent::FocusOut) {
+        emit roleEditingFinished(m_index, m_role, toPlainText());
+    }
+    return KTextEdit::event(event);
+}
+
+void KItemListRoleEditor::keyPressEvent(QKeyEvent* event)
+{
+    switch (event->key()) {
+    case Qt::Key_Escape:
+        emit roleEditingCanceled(m_index, m_role, toPlainText());
+        event->accept();
+        return;
+    case Qt::Key_Enter:
+    case Qt::Key_Return:
+        emit roleEditingFinished(m_index, m_role, toPlainText());
+        event->accept();
+        return;
+    default:
+        break;
+    }
+
+    KTextEdit::keyPressEvent(event);
+    autoAdjustSize();
+}
+
+void KItemListRoleEditor::autoAdjustSize()
+{
+    const qreal requiredWidth = document()->size().width();
+    const qreal availableWidth = size().width() - 2 * frameWidth();
+    if (requiredWidth > availableWidth) {
+        qreal newWidth = requiredWidth + 2 * frameWidth();
+        if (parentWidget() && pos().x() + newWidth > parentWidget()->width()) {
+            newWidth = parentWidget()->width() - pos().x();
+        }
+        resize(newWidth, size().height());
+    }
+}
+
+#include "kitemlistroleeditor.moc"
diff --git a/src/kitemviews/private/kitemlistroleeditor.h b/src/kitemviews/private/kitemlistroleeditor.h
new file mode 100644 (file)
index 0000000..14aa694
--- /dev/null
@@ -0,0 +1,67 @@
+/***************************************************************************
+ *   Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com>             *
+ *                                                                         *
+ *   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  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
+ ***************************************************************************/
+
+#ifndef KITEMLISTROLEEDITOR_H
+#define KITEMLISTROLEEDITOR_H
+
+#include "libdolphin_export.h"
+
+#include <KTextEdit>
+
+/**
+ * @brief
+ */
+class LIBDOLPHINPRIVATE_EXPORT KItemListRoleEditor : public KTextEdit
+{
+    Q_OBJECT
+
+public:
+    explicit KItemListRoleEditor(QWidget* parent);
+    virtual ~KItemListRoleEditor();
+
+    void setIndex(int index);
+    int index() const;
+
+    void setRole(const QByteArray& role);
+    QByteArray role() const;
+
+    virtual bool eventFilter(QObject* watched, QEvent* event);
+
+signals:
+    void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+    void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
+
+protected:
+    virtual bool event(QEvent* event);
+    virtual void keyPressEvent(QKeyEvent* event);
+
+private slots:
+    /**
+     * Increases the width of the editor in case if there is not
+     * enough room for the text.
+     */
+    void autoAdjustSize();
+
+private:
+    int m_index;
+    QByteArray m_role;
+
+};
+
+#endif
index 5f1b4a7e0d0c2120b9caeb4b694b06ca0733ff68..40e5eca8d118a8a1fc607deedcd1051f977c2ec5 100644 (file)
@@ -42,7 +42,6 @@
 #include <QTimer>
 
 #include <views/draganddrophelper.h>
-#include <views/renamedialog.h>
 
 #include <KDebug>
 
@@ -89,18 +88,8 @@ bool FoldersPanel::autoScrolling() const
 
 void FoldersPanel::rename(const KFileItem& item)
 {
-    // TODO: Inline renaming is not supported anymore in Dolphin 2.0
-    if (false /* GeneralSettings::renameInline() */) {
-        //const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
-        //const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
-        //m_treeView->edit(proxyIndex);
-    } else {
-        RenameDialog* dialog = new RenameDialog(this, KFileItemList() << item);
-        dialog->setAttribute(Qt::WA_DeleteOnClose);
-        dialog->show();
-        dialog->raise();
-        dialog->activateWindow();
-    }
+    const int index = fileItemModel()->index(item);
+    m_controller->view()->editRole(index, "name");
 }
 
 bool FoldersPanel::urlChanged()
@@ -147,6 +136,9 @@ void FoldersPanel::showEvent(QShowEvent* event)
         // opening the folders panel.
         view->setOpacity(0);
 
+        connect(view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+                this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+
         KFileItemModel* model = new KFileItemModel(this);
         model->setShowDirectoriesOnly(true);
         model->setShowHiddenFiles(FoldersPanelSettings::hiddenFilesShown());
@@ -261,6 +253,17 @@ void FoldersPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* eve
     }
 }
 
+void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
+{
+    if (role == "name") {
+        const KFileItem item = fileItemModel()->fileItem(index);
+        const QString newName = value.toString();
+        if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
+            KonqOperations::rename(this, item.url(), newName);
+        }
+    }
+}
+
 void FoldersPanel::slotLoadingCompleted()
 {
     if (m_controller->view()->opacity() == 0) {
index babcde64a4690af357a0ac7af6f8ee4ad3dae9fa..10a30d1f7cb8f1ebff8999d7de086cc5d840e638 100644 (file)
@@ -72,6 +72,7 @@ private slots:
     void slotItemContextMenuRequested(int index, const QPointF& pos);
     void slotViewContextMenuRequested(const QPointF& pos);
     void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
+    void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
 
     void slotLoadingCompleted();
 
index 3ab49974342d87e4f99a8b773578d4bf8f34a8e4..c19c0fe5279e4907af77277f837aca123e52246c 100644 (file)
@@ -301,6 +301,9 @@ void DolphinStatusBar::updateProgressInfo()
 {
     if (m_progress < 100) {
         // Show the progress information and hide the extensions
+        m_stopButton->show();
+        m_progressTextLabel->show();
+        m_progressBar->show();
         setExtensionsVisible(false);
     } else {
         // Hide the progress information and show the extensions
index daf6aca7601155db24ebfcdf561f95dbfa31ea24..3e1ed34ec83f5b8e7863c5738367323f79d60452 100644 (file)
@@ -156,6 +156,8 @@ DolphinView::DolphinView(const KUrl& url, QWidget* parent) :
             this, SLOT(slotSortRoleChangedByHeader(QByteArray,QByteArray)));
     connect(view, SIGNAL(visibleRolesChanged(QList<QByteArray>,QList<QByteArray>)),
             this, SLOT(slotVisibleRolesChangedByHeader(QList<QByteArray>,QList<QByteArray>)));
+    connect(view, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
+            this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
     connect(view->header(), SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
             this, SLOT(slotHeaderColumnWidthChanged(QByteArray,qreal,qreal)));
 
@@ -598,30 +600,26 @@ void DolphinView::clearSelection()
 
 void DolphinView::renameSelectedItems()
 {
-    KFileItemList items = selectedItems();
-    const int itemCount = items.count();
-    if (itemCount < 1) {
-        return;
-    }
-
-    // TODO: The new view-engine introduced with Dolphin 2.0 does not support inline
-    // renaming yet.
-    /*if ((itemCount == 1) && DolphinSettings::instance().generalSettings()->renameInline()) {
-        const QModelIndex dirIndex = m_viewAccessor.dirModel()->indexForItem(items.first());
-        const QModelIndex proxyIndex = m_viewAccessor.proxyModel()->mapFromSource(dirIndex);
-        m_viewAccessor.itemView()->edit(proxyIndex);
-    } else {*/
-        RenameDialog* dialog = new RenameDialog(this, items);
-        dialog->setAttribute(Qt::WA_DeleteOnClose);
-        dialog->show();
-        dialog->raise();
-        dialog->activateWindow();
-    //}
-
-    // Assure that the current index remains visible when KFileItemModel
-    // will notify the view about changed items (which might result in
-    // a changed sorting).
-    m_assureVisibleCurrentIndex = true;
+    const KFileItemList items = selectedItems();
+     if (items.isEmpty()) {
+         return;
+     }
+
+     if (items.count() == 1) {
+         const int index = fileItemModel()->index(items.first());
+         m_container->controller()->view()->editRole(index, "name");
+     } else {
+         RenameDialog* dialog = new RenameDialog(this, items);
+         dialog->setAttribute(Qt::WA_DeleteOnClose);
+         dialog->show();
+         dialog->raise();
+         dialog->activateWindow();
+     }
+
+     // Assure that the current index remains visible when KFileItemModel
+     // will notify the view about changed items (which might result in
+     // a changed sorting).
+     m_assureVisibleCurrentIndex = true;
 }
 
 void DolphinView::trashSelectedItems()
@@ -1291,6 +1289,17 @@ void DolphinView::slotVisibleRolesChangedByHeader(const QList<QByteArray>& curre
     emit visibleRolesChanged(m_visibleRoles, previousVisibleRoles);
 }
 
+void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
+{
+    if (role == "name") {
+        const KFileItem item = fileItemModel()->fileItem(index);
+        const QString newName = value.toString();
+        if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
+            KonqOperations::rename(this, item.url(), newName);
+        }
+    }
+}
+
 KFileItemModel* DolphinView::fileItemModel() const
 {
     return static_cast<KFileItemModel*>(m_container->controller()->model());
index f95572564d74353dfbe7e63978b358258b95a709..a9cf0ade40efd160fd80940c2d15ff4637b6440a 100644 (file)
@@ -617,6 +617,8 @@ private slots:
     void slotVisibleRolesChangedByHeader(const QList<QByteArray>& current,
                                          const QList<QByteArray>& previous);
 
+    void slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+
     /**
      * Observes the item with the URL \a url. As soon as the directory
      * model indicates that the item is available, the item will
index bc8f059a489f233586410b4fbe919bb672462071..e2293674096f066bf546f8087d822e4c5c8bccc4 100644 (file)
@@ -36,7 +36,6 @@
 #include <KNewFileMenu>
 #include <KSelectAction>
 #include <KToggleAction>
-#include <KRun>
 #include <KPropertiesDialog>
 #include <KIcon>