]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.h
Build with QT_NO_KEYWORDS
[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 /**
15 * @brief Editor for renaming roles of a KItemListWidget.
16 *
17 * Provides signals when the editing got cancelled (e.g. by
18 * pressing Escape or when losing the focus) or when the editing
19 * got finished (e.g. by pressing Enter or Return).
20 *
21 * The size automatically gets increased if the text does not fit.
22 */
23 class DOLPHIN_EXPORT KItemListRoleEditor : public KTextEdit
24 {
25 Q_OBJECT
26
27 public:
28 explicit KItemListRoleEditor(QWidget* parent);
29 ~KItemListRoleEditor() override;
30
31 void setRole(const QByteArray& role);
32 QByteArray role() const;
33
34 bool eventFilter(QObject* watched, QEvent* event) override;
35
36 Q_SIGNALS:
37 void roleEditingFinished(const QByteArray& role, const QVariant& value);
38 void roleEditingCanceled(const QByteArray& role, const QVariant& value);
39
40 protected:
41 bool event(QEvent* event) override;
42 void keyPressEvent(QKeyEvent* event) override;
43
44 private Q_SLOTS:
45 /**
46 * Increases the size of the editor in case if there is not
47 * enough room for the text.
48 */
49 void autoAdjustSize();
50
51 private:
52 /**
53 * Emits the signal roleEditingFinished if m_blockFinishedSignal
54 * is false.
55 */
56 void emitRoleEditingFinished();
57
58 private:
59 QByteArray m_role;
60 bool m_blockFinishedSignal;
61 };
62
63 #endif