]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kitemlistroleeditor.h
Merge branch 'master' into frameworks
[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 "dolphin_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 DOLPHIN_EXPORT KItemListRoleEditor : public KTextEdit
37 {
38 Q_OBJECT
39
40 public:
41 explicit KItemListRoleEditor(QWidget* parent);
42 virtual ~KItemListRoleEditor();
43
44 void setRole(const QByteArray& role);
45 QByteArray role() const;
46
47 virtual bool eventFilter(QObject* watched, QEvent* event);
48
49 signals:
50 void roleEditingFinished(const QByteArray& role, const QVariant& value);
51 void roleEditingCanceled(const QByteArray& role, const QVariant& value);
52
53 protected:
54 virtual bool event(QEvent* event);
55 virtual void keyPressEvent(QKeyEvent* event);
56
57 private slots:
58 /**
59 * Increases the size of the editor in case if there is not
60 * enough room for the text.
61 */
62 void autoAdjustSize();
63
64 private:
65 /**
66 * Emits the signal roleEditingFinished if m_blockFinishedSignal
67 * is false.
68 */
69 void emitRoleEditingFinished();
70
71 private:
72 QByteArray m_role;
73 bool m_blockFinishedSignal;
74 };
75
76 #endif