]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.h
Fix Bug 319119 - Dolphin doesn't notice when renaming failed
[dolphin.git] / src / kitemviews / private / kitemlistroleeditor.h
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #ifndef KITEMLISTROLEEDITOR_H
21 #define KITEMLISTROLEEDITOR_H
22
23 #include "libdolphin_export.h"
24
25 #include <KTextEdit>
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 or Return).
33 *
34 * The size automatically gets increased if the text does not fit.
35 */
36 class LIBDOLPHINPRIVATE_EXPORT KItemListRoleEditor : public KTextEdit
37 {
38 Q_OBJECT
39
40 public:
41 explicit KItemListRoleEditor(QWidget* parent);
42 virtual ~KItemListRoleEditor();
43
44 void setIndex(int index);
45 int index() const;
46
47 void setRole(const QByteArray& role);
48 QByteArray role() const;
49
50 virtual bool eventFilter(QObject* watched, QEvent* event);
51
52 signals:
53 void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
54 void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
55
56 protected:
57 virtual bool event(QEvent* event);
58 virtual void keyPressEvent(QKeyEvent* event);
59
60 private slots:
61 /**
62 * Increases the size of the editor in case if there is not
63 * enough room for the text.
64 */
65 void autoAdjustSize();
66
67 private:
68 /**
69 * Emits the signal roleEditingFinished if m_blockFinishedSignal
70 * is false.
71 */
72 void emitRoleEditingFinished();
73
74 private:
75 int m_index;
76 QByteArray m_role;
77 bool m_blockFinishedSignal;
78 };
79
80 #endif