]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.h
When renaming files, move to next file using tab key or up/down
[dolphin.git] / src / kitemviews / private / kitemlistroleeditor.h
1 /*
2 * SPDX-FileCopyrightText: 2012 Peter Penz <peter.penz19@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KITEMLISTROLEEDITOR_H
8 #define KITEMLISTROLEEDITOR_H
9
10 #include "dolphin_export.h"
11
12 #include <KTextEdit>
13
14 enum EditResultDirection{
15 EditDone,
16 EditNext,
17 EditPrevious,
18 };
19 Q_DECLARE_METATYPE(EditResultDirection)
20
21 struct EditResult
22 {
23 QString newName;
24 EditResultDirection direction;
25 };
26 Q_DECLARE_METATYPE(EditResult)
27
28 /**
29 * @brief Editor for renaming roles of a KItemListWidget.
30 *
31 * Provides signals when the editing got cancelled (e.g. by
32 * pressing Escape or when losing the focus) or when the editing
33 * got finished (e.g. by pressing Enter, Tab or Return).
34 *
35 * The size automatically gets increased if the text does not fit.
36 */
37 class DOLPHIN_EXPORT KItemListRoleEditor : public KTextEdit
38 {
39 Q_OBJECT
40
41 public:
42 explicit KItemListRoleEditor(QWidget* parent);
43 ~KItemListRoleEditor() override;
44
45 void setRole(const QByteArray& role);
46 QByteArray role() const;
47
48 void setAllowUpDownKeyChainEdit(bool allowChainEdit);
49 bool eventFilter(QObject* watched, QEvent* event) override;
50
51 Q_SIGNALS:
52 void roleEditingFinished(const QByteArray& role, const QVariant& value);
53 void roleEditingCanceled(const QByteArray& role, const QVariant& value);
54
55 protected:
56 bool event(QEvent* event) override;
57 void keyPressEvent(QKeyEvent* event) override;
58
59 private Q_SLOTS:
60 /**
61 * Increases the size of the editor in case if there is not
62 * enough room for the text.
63 */
64 void autoAdjustSize();
65
66 private:
67 /**
68 * Emits the signal roleEditingFinished if m_blockFinishedSignal
69 * is false.
70 */
71 void emitRoleEditingFinished(EditResultDirection direction = EditDone);
72
73 private:
74 QByteArray m_role;
75 bool m_blockFinishedSignal;
76 bool m_allowUpDownKeyChainEdit;
77 };
78
79 #endif