1 | /* |
2 | This file is part of the KDE project |
3 | Copyright (C) 2008 by Dmitry Suzdalev <dimsuz@gmail.com> |
4 | |
5 | This program is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; see the file COPYING. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | #ifndef ACTIONSTREEWIDGET_H |
21 | #define ACTIONSTREEWIDGET_H |
22 | |
23 | #include <QtGui/QTreeWidget> |
24 | |
25 | /** |
26 | * Custom tree widget class to make KConfigDialog properly |
27 | * highlight Apply button when some action is changed. |
28 | * We achieve this by adding custom type handling to KConfigDialogManager |
29 | * and by adding a somewhat dummy config entry which gets changed whenever |
30 | * some action is changed in treewidget. |
31 | * KConfigDialog watches this entry for changes and highlights Apply when needed |
32 | * |
33 | * @see KConfigDialogManager |
34 | */ |
35 | class ActionsTreeWidget : public QTreeWidget |
36 | { |
37 | Q_OBJECT |
38 | |
39 | // this property is int instead of (more logical) bool, because we need a custom handling of |
40 | // "default state" and because of our custom use of this property: |
41 | // |
42 | // We indicate that changes were made to this widget by changing this int value. |
43 | // We use it as "if this value is *CHANGED SOMEHOW*, this means that some changes were made to action list", |
44 | // If we'd make this property bool, KConfigDialog would highlight "Defaults" button whenever |
45 | // this property becomes false, but this is not the way we use this property. |
46 | // So we change it from 0 to 1 periodically when something changes. Both 0, 1 values indicate |
47 | // change. |
48 | // |
49 | // We set it to default only when resetModifiedState() is called, i.e. when Apply btn is being |
50 | // clicked |
51 | // |
52 | // Hope this explains it. |
53 | // Yeah, this class is a trick :) If there's a better way to properly |
54 | // update KConfigDialog buttons whenever "some change occurs to QTreeWidget", let me know (dimsuz) |
55 | Q_PROPERTY( int actionsChanged READ actionsChanged WRITE setActionsChanged USER true ) |
56 | |
57 | public: |
58 | ActionsTreeWidget(QWidget* parent = 0); |
59 | |
60 | void setActionsChanged(int); |
61 | int actionsChanged() const; |
62 | |
63 | void resetModifiedState(); |
64 | |
65 | signals: |
66 | void changed(); |
67 | |
68 | private slots: |
69 | void onItemChanged(); |
70 | |
71 | private: |
72 | int m_actionsChanged; |
73 | bool m_modified; |
74 | }; |
75 | |
76 | #endif |
77 | |