]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.h
Add clang-format and format code as in Frameworks
[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 QString newName;
23 EditResultDirection direction;
24 };
25 Q_DECLARE_METATYPE(EditResult)
26
27 /**
28 * @brief Editor for renaming roles of a KItemListWidget.
29 *
30 * Provides signals when the editing got cancelled (e.g. by
31 * pressing Escape or when losing the focus) or when the editing
32 * got finished (e.g. by pressing Enter, Tab or Return).
33 *
34 * The size automatically gets increased if the text does not fit.
35 */
36 class DOLPHIN_EXPORT KItemListRoleEditor : public KTextEdit
37 {
38 Q_OBJECT
39
40 public:
41 explicit KItemListRoleEditor(QWidget *parent);
42 ~KItemListRoleEditor() override;
43
44 void setRole(const QByteArray &role);
45 QByteArray role() const;
46
47 void setAllowUpDownKeyChainEdit(bool allowChainEdit);
48 bool eventFilter(QObject *watched, QEvent *event) override;
49
50 Q_SIGNALS:
51 void roleEditingFinished(const QByteArray &role, const QVariant &value);
52 void roleEditingCanceled(const QByteArray &role, const QVariant &value);
53
54 protected:
55 bool event(QEvent *event) override;
56 void keyPressEvent(QKeyEvent *event) override;
57
58 private Q_SLOTS:
59 /**
60 * Increases the size of the editor in case if there is not
61 * enough room for the text.
62 */
63 void autoAdjustSize();
64
65 private:
66 /**
67 * Emits the signal roleEditingFinished if m_blockFinishedSignal
68 * is false.
69 */
70 void emitRoleEditingFinished(EditResultDirection direction = EditDone);
71
72 private:
73 QByteArray m_role;
74 bool m_blockFinishedSignal;
75 bool m_allowUpDownKeyChainEdit;
76 };
77
78 #endif