~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/hotkeys_model.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Library General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2 of the License, or (at your option) any later version.
 
8
 
 
9
   This library 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 GNU
 
12
   Library General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Library General Public License
 
15
   along with this library; see the file COPYING.LIB.  If not, write to
 
16
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
17
   Boston, MA 02110-1301, USA.
 
18
*/
 
19
#ifndef KHOTKEYSMODEL_H
 
20
#define KHOTKEYSMODEL_H
 
21
 
 
22
#include "libkhotkeysfwd.h"
 
23
#include "settings.h"
 
24
 
 
25
#include <QtCore/QAbstractItemModel>
 
26
 
 
27
 
 
28
/**
 
29
 */
 
30
class KHotkeysModel : public QAbstractItemModel
 
31
    {
 
32
    Q_OBJECT
 
33
 
 
34
    public:
 
35
 
 
36
    enum ItemType {
 
37
        Other                          //!< Some unknown action type
 
38
        ,ActionDataGroup               //!< A shortcut group
 
39
        ,SimpleActionData
 
40
    };
 
41
 
 
42
    enum Column {
 
43
        NameColumn,
 
44
        EnabledColumn,
 
45
        IsGroupColumn,
 
46
        TypeColumn };
 
47
 
 
48
    /**
 
49
     * Default constructor
 
50
     *
 
51
     * @param 
 
52
     */
 
53
    KHotkeysModel( QObject *parent = 0 );
 
54
 
 
55
    /**
 
56
     * Destructor
 
57
     */
 
58
    virtual ~KHotkeysModel();
 
59
 
 
60
    /**
 
61
     * \group Qt Model/View Framework methods
 
62
     */
 
63
    //@{
 
64
    QModelIndex index( int, int, const QModelIndex &parent = QModelIndex() ) const;
 
65
    QModelIndex parent( const QModelIndex &index ) const;
 
66
    int rowCount( const QModelIndex &index ) const;
 
67
    int columnCount( const QModelIndex &index ) const;
 
68
    QVariant headerData( int section, Qt::Orientation, int role = Qt::DisplayRole ) const;
 
69
    QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
 
70
    bool setData( const QModelIndex &index, const QVariant &value, int role );
 
71
    Qt::ItemFlags flags( const QModelIndex &index ) const;
 
72
    //@}
 
73
 
 
74
    /**
 
75
     * \group Drag and Drop Support
 
76
     */
 
77
    //@{
 
78
    bool dropMimeData(
 
79
            const QMimeData *data
 
80
            ,Qt::DropAction action
 
81
            ,int row
 
82
            ,int column
 
83
            ,const QModelIndex &parent);
 
84
    QMimeData *mimeData(const QModelIndexList &indexes) const;
 
85
    QStringList mimeTypes() const;
 
86
    //@}
 
87
 
 
88
    /**
 
89
     * Add a group as child of @a parent.
 
90
     *
 
91
     * @return the index for the new group
 
92
     */
 
93
    QModelIndex addGroup( const QModelIndex &parent );
 
94
 
 
95
    /**
 
96
     * Export the input actions into @a config.
 
97
     */
 
98
    void exportInputActions(
 
99
            const QModelIndex &index,
 
100
            KConfigBase &config,
 
101
            const QString& id,
 
102
            const KHotKeys::ActionState state,
 
103
            bool allowMerging);
 
104
 
 
105
    /**
 
106
     *Import the input actions from @a config.
 
107
     */
 
108
    void importInputActions(const QModelIndex &index, KConfigBase const &config);
 
109
 
 
110
    /**
 
111
     * Get the KHotKeys::ActionDataBase behind the index.
 
112
     */
 
113
    KHotKeys::ActionDataBase *indexToActionDataBase( const QModelIndex &index ) const;
 
114
 
 
115
    /**
 
116
     * Get the KHotKeys::ActionDataBase behind the index or 0.
 
117
     *
 
118
     * Getting 0 doesn't mean the index is invalid. It means you provided a
 
119
     * action object.
 
120
     */
 
121
    KHotKeys::ActionDataGroup *indexToActionDataGroup( const QModelIndex &index ) const;
 
122
 
 
123
    /**
 
124
     * Insert @a data as a child of @a parent.
 
125
     */
 
126
    QModelIndex insertActionData( KHotKeys::ActionDataBase *data, const QModelIndex &parent );
 
127
 
 
128
    /**
 
129
     * Load the settings from the file
 
130
     */
 
131
    void load();
 
132
 
 
133
    /**
 
134
     * Move @p element to @p newGroup at @position.
 
135
     *
 
136
     * @param element  move this element
 
137
     * @param newGroup to this group
 
138
     * @param position and put it at this position. default is last
 
139
     *
 
140
     * @return @c true if moved, @c false if not.
 
141
     */
 
142
    bool moveElement(
 
143
            KHotKeys::ActionDataBase *element
 
144
            ,KHotKeys::ActionDataGroup *newGroup
 
145
            ,int position = -1);
 
146
 
 
147
    /**
 
148
     * Remove @a count rows starting with @a row under @a parent.
 
149
     */
 
150
    bool removeRows( int row, int count, const QModelIndex &parent );
 
151
 
 
152
    /**
 
153
     * Save the settings to the file
 
154
     */
 
155
    void save();
 
156
 
 
157
    /**
 
158
     * Return the settings we handle
 
159
     */
 
160
    KHotKeys::Settings *settings();
 
161
 
 
162
    void emitChanged( KHotKeys::ActionDataBase *item );
 
163
 
 
164
  private:
 
165
 
 
166
    KHotKeys::Settings _settings;
 
167
    KHotKeys::ActionDataGroup *_actions;
 
168
 
 
169
};
 
170
 
 
171
#endif /* #ifndef KHOTKEYSMODEL_HPP */