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

« back to all changes in this revision

Viewing changes to kmenuedit/treeview.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) 2000 Matthias Elter <elter@kde.org>
 
3
 *   Copyright (C) 2001-2002 Raffaele Sandrini <sandrini@kde.org>
 
4
 *   Copyright (C) 2003 Waldo Bastian <bastian@kde.org>
 
5
 *   Copyright (C) 2008 Laurent Montel <montel@kde.org>
 
6
 *
 
7
 *   This program is free software; you can redistribute it and/or modify
 
8
 *   it under the terms of the GNU General Public License as published by
 
9
 *   the Free Software Foundation; either version 2 of the License, or
 
10
 *   (at your option) any later version.
 
11
 *
 
12
 *   This program is distributed in the hope that it will be useful,
 
13
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 *   GNU General Public License for more details.
 
16
 *
 
17
 *   You should have received a copy of the GNU General Public License
 
18
 *   along with this program; if not, write to the Free Software
 
19
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
 *
 
21
 */
 
22
 
 
23
#ifndef __treeview_h__
 
24
#define __treeview_h__
 
25
 
 
26
 
 
27
//Added by qt3to4:
 
28
#include <QMenu>
 
29
#include <QDropEvent>
 
30
#include <k3listview.h>
 
31
#include <kservice.h>
 
32
#include <kservicegroup.h>
 
33
 
 
34
class QMenu;
 
35
class KActionCollection;
 
36
class KDesktopFile;
 
37
class MenuFile;
 
38
class MenuFolderInfo;
 
39
class MenuEntryInfo;
 
40
class MenuSeparatorInfo;
 
41
class KShortcut;
 
42
 
 
43
class TreeItem : public Q3ListViewItem
 
44
{
 
45
public:
 
46
  TreeItem(Q3ListViewItem *parent, Q3ListViewItem *after, const QString &menuIdn, bool __init = false);
 
47
    TreeItem(Q3ListView *parent, Q3ListViewItem* after, const QString &menuId, bool __init = false);
 
48
 
 
49
    QString menuId() const { return _menuId; }
 
50
 
 
51
    QString directory() const { return _directoryPath; }
 
52
    void setDirectoryPath(const QString& path) { _directoryPath = path; }
 
53
 
 
54
    MenuFolderInfo *folderInfo() { return m_folderInfo; }
 
55
    void setMenuFolderInfo(MenuFolderInfo *folderInfo) { m_folderInfo = folderInfo; }
 
56
 
 
57
    MenuEntryInfo *entryInfo() { return m_entryInfo; }
 
58
    void setMenuEntryInfo(MenuEntryInfo *entryInfo) { m_entryInfo = entryInfo; }
 
59
 
 
60
    QString name() const { return _name; }
 
61
    void setName(const QString &name);
 
62
 
 
63
    bool isDirectory() const { return m_folderInfo; }
 
64
    bool isEntry() const { return m_entryInfo; }
 
65
 
 
66
    bool isHidden() const { return _hidden; }
 
67
    void setHidden(bool b);
 
68
 
 
69
    bool isLayoutDirty() { return _layoutDirty; }
 
70
    void setLayoutDirty() { _layoutDirty = true; }
 
71
    QStringList layout();
 
72
 
 
73
    virtual void setOpen(bool o);
 
74
    void load();
 
75
 
 
76
    virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
 
77
    virtual void setup();
 
78
 
 
79
private:
 
80
    void update();
 
81
 
 
82
    bool _hidden : 1;
 
83
    bool _init : 1;
 
84
    bool _layoutDirty : 1;
 
85
    QString _menuId;
 
86
    QString _name;
 
87
    QString _directoryPath;
 
88
    MenuFolderInfo *m_folderInfo;
 
89
    MenuEntryInfo *m_entryInfo;
 
90
};
 
91
 
 
92
class TreeView : public K3ListView
 
93
{
 
94
    friend class TreeItem;
 
95
    Q_OBJECT
 
96
public:
 
97
    TreeView(KActionCollection *ac, QWidget *parent=0, const char *name=0);
 
98
    ~TreeView();
 
99
 
 
100
    void readMenuFolderInfo(MenuFolderInfo *folderInfo=0, KServiceGroup::Ptr folder=KServiceGroup::Ptr(), const QString &prefix=QString());
 
101
    void setViewMode(bool showHidden);
 
102
    bool save();
 
103
 
 
104
    bool dirty();
 
105
 
 
106
    void selectMenu(const QString &menu);
 
107
    void selectMenuEntry(const QString &menuEntry);
 
108
 
 
109
    void restoreMenuSystem();
 
110
 
 
111
    void updateTreeView(bool showHidden);
 
112
 
 
113
public Q_SLOTS:
 
114
    void currentChanged(MenuFolderInfo *folderInfo);
 
115
    void currentChanged(MenuEntryInfo *entryInfo);
 
116
    void findServiceShortcut(const KShortcut&, KService::Ptr &);
 
117
 
 
118
Q_SIGNALS:
 
119
    void entrySelected(MenuFolderInfo *folderInfo);
 
120
    void entrySelected(MenuEntryInfo *entryInfo);
 
121
    void disableAction();
 
122
protected Q_SLOTS:
 
123
    void itemSelected(Q3ListViewItem *);
 
124
    void slotDropped(QDropEvent *, Q3ListViewItem *, Q3ListViewItem *);
 
125
    void slotRMBPressed(Q3ListViewItem*, const QPoint&);
 
126
 
 
127
    void newsubmenu();
 
128
    void newitem();
 
129
    void newsep();
 
130
 
 
131
    void cut();
 
132
    void copy();
 
133
    void paste();
 
134
    void del();
 
135
 
 
136
protected:
 
137
    TreeItem *createTreeItem(TreeItem *parent, Q3ListViewItem *after, MenuFolderInfo *folderInfo, bool _init = false);
 
138
    TreeItem *createTreeItem(TreeItem *parent, Q3ListViewItem *after, MenuEntryInfo *entryInfo, bool _init = false);
 
139
    TreeItem *createTreeItem(TreeItem *parent, Q3ListViewItem *after, MenuSeparatorInfo *sepInfo, bool _init = false);
 
140
 
 
141
    void del(TreeItem *, bool deleteInfo);
 
142
    void fill();
 
143
    void fillBranch(MenuFolderInfo *folderInfo, TreeItem *parent);
 
144
    QString findName(KDesktopFile *df, bool deleted);
 
145
 
 
146
    void closeAllItems(Q3ListViewItem *item);
 
147
 
 
148
    // moving = src will be removed later
 
149
    void copy( bool moving );
 
150
 
 
151
    void cleanupClipboard();
 
152
 
 
153
    bool isLayoutDirty();
 
154
    void setLayoutDirty(TreeItem *);
 
155
    void saveLayout();
 
156
 
 
157
    QStringList fileList(const QString& relativePath);
 
158
    QStringList dirList(const QString& relativePath);
 
159
 
 
160
    virtual bool acceptDrag(QDropEvent* event) const;
 
161
    virtual Q3DragObject *dragObject();
 
162
    virtual void startDrag();
 
163
 
 
164
    void sendReloadMenu();
 
165
 
 
166
private:
 
167
    KActionCollection *m_ac;
 
168
    QMenu        *m_rmb;
 
169
    int                m_clipboard;
 
170
    MenuFolderInfo    *m_clipboardFolderInfo;
 
171
    MenuEntryInfo     *m_clipboardEntryInfo;
 
172
    int                m_drag;
 
173
    MenuFolderInfo    *m_dragInfo;
 
174
    TreeItem          *m_dragItem;
 
175
    QString            m_dragPath;
 
176
    bool               m_showHidden;
 
177
    MenuFile          *m_menuFile;
 
178
    MenuFolderInfo    *m_rootFolder;
 
179
    MenuSeparatorInfo *m_separator;
 
180
    QStringList        m_newMenuIds;
 
181
    QStringList        m_newDirectoryList;
 
182
    bool               m_detailedMenuEntries;
 
183
    bool               m_detailedEntriesNamesFirst;
 
184
    bool               m_layoutDirty;
 
185
};
 
186
 
 
187
 
 
188
#endif