diff options
| author | Méven Car <[email protected]> | 2021-04-19 05:10:11 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2021-04-19 05:10:11 +0000 |
| commit | 5a0da4a9c8d10dc1921077d84bdabf05d20150b0 (patch) | |
| tree | f80eeabb2a24b1da2a0adf248f43fa1db64b623b /src/kitemviews/private | |
| parent | a27b4c5c608174e0164a02275749238b423d01a5 (diff) | |
When renaming files, move to next file using tab key or up/down
To rename previous file:
Up or Shift-Tab
To rename next file:
Down or Tab
Credit goes to msciubidlo
FEATURE: 403931
FEATURE: 269987
BUG: 334533
FIXED-IN: 21.08
Diffstat (limited to 'src/kitemviews/private')
| -rw-r--r-- | src/kitemviews/private/kitemlistroleeditor.cpp | 26 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistroleeditor.h | 20 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistsmoothscroller.cpp | 3 | ||||
| -rw-r--r-- | src/kitemviews/private/kitemlistsmoothscroller.h | 5 |
4 files changed, 50 insertions, 4 deletions
diff --git a/src/kitemviews/private/kitemlistroleeditor.cpp b/src/kitemviews/private/kitemlistroleeditor.cpp index df142a456..cc10bd58a 100644 --- a/src/kitemviews/private/kitemlistroleeditor.cpp +++ b/src/kitemviews/private/kitemlistroleeditor.cpp @@ -40,6 +40,11 @@ QByteArray KItemListRoleEditor::role() const return m_role; } +void KItemListRoleEditor::setAllowUpDownKeyChainEdit(bool allowChainEdit) +{ + m_allowUpDownKeyChainEdit = allowChainEdit; +} + bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event) { if (watched == parentWidget() && event->type() == QEvent::Resize) { @@ -78,6 +83,20 @@ void KItemListRoleEditor::keyPressEvent(QKeyEvent* event) emitRoleEditingFinished(); event->accept(); return; + case Qt::Key_Tab: + case Qt::Key_Down: + if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Tab) { + emitRoleEditingFinished(EditNext); + event->accept(); + return; + } + case Qt::Key_Backtab: + case Qt::Key_Up: + if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Backtab) { + emitRoleEditingFinished(EditPrevious); + event->accept(); + return; + } case Qt::Key_Left: case Qt::Key_Right: { QTextCursor cursor = textCursor(); @@ -143,10 +162,13 @@ void KItemListRoleEditor::autoAdjustSize() } } -void KItemListRoleEditor::emitRoleEditingFinished() +void KItemListRoleEditor::emitRoleEditingFinished(EditResultDirection direction) { + QVariant ret; + ret.setValue(EditResult {KIO::encodeFileName(toPlainText()), direction}); + if (!m_blockFinishedSignal) { - Q_EMIT roleEditingFinished(m_role, KIO::encodeFileName(toPlainText())); + Q_EMIT roleEditingFinished(m_role, ret); } } diff --git a/src/kitemviews/private/kitemlistroleeditor.h b/src/kitemviews/private/kitemlistroleeditor.h index 070cf5ce9..a0f55df51 100644 --- a/src/kitemviews/private/kitemlistroleeditor.h +++ b/src/kitemviews/private/kitemlistroleeditor.h @@ -11,12 +11,26 @@ #include <KTextEdit> +enum EditResultDirection{ + EditDone, + EditNext, + EditPrevious, +}; +Q_DECLARE_METATYPE(EditResultDirection) + +struct EditResult +{ + QString newName; + EditResultDirection direction; +}; +Q_DECLARE_METATYPE(EditResult) + /** * @brief Editor for renaming roles of a KItemListWidget. * * Provides signals when the editing got cancelled (e.g. by * pressing Escape or when losing the focus) or when the editing - * got finished (e.g. by pressing Enter or Return). + * got finished (e.g. by pressing Enter, Tab or Return). * * The size automatically gets increased if the text does not fit. */ @@ -31,6 +45,7 @@ public: void setRole(const QByteArray& role); QByteArray role() const; + void setAllowUpDownKeyChainEdit(bool allowChainEdit); bool eventFilter(QObject* watched, QEvent* event) override; Q_SIGNALS: @@ -53,11 +68,12 @@ private: * Emits the signal roleEditingFinished if m_blockFinishedSignal * is false. */ - void emitRoleEditingFinished(); + void emitRoleEditingFinished(EditResultDirection direction = EditDone); private: QByteArray m_role; bool m_blockFinishedSignal; + bool m_allowUpDownKeyChainEdit; }; #endif diff --git a/src/kitemviews/private/kitemlistsmoothscroller.cpp b/src/kitemviews/private/kitemlistsmoothscroller.cpp index 1465361ed..f77d3df58 100644 --- a/src/kitemviews/private/kitemlistsmoothscroller.cpp +++ b/src/kitemviews/private/kitemlistsmoothscroller.cpp @@ -175,6 +175,9 @@ void KItemListSmoothScroller::slotAnimationStateChanged(QAbstractAnimation::Stat if (newState == QAbstractAnimation::Stopped && m_smoothScrolling && !m_scrollBarPressed) { m_smoothScrolling = false; } + if (newState == QAbstractAnimation::Stopped) { + Q_EMIT scrollingStopped(); + } } void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event) diff --git a/src/kitemviews/private/kitemlistsmoothscroller.h b/src/kitemviews/private/kitemlistsmoothscroller.h index 55548219e..7b2839884 100644 --- a/src/kitemviews/private/kitemlistsmoothscroller.h +++ b/src/kitemviews/private/kitemlistsmoothscroller.h @@ -69,6 +69,11 @@ public: */ void handleWheelEvent(QWheelEvent* event); +Q_SIGNALS: + /** + * Emitted when the scrolling animation has finished + */ + void scrollingStopped(); protected: bool eventFilter(QObject* obj, QEvent* event) override; |
