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