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 | #include <QTreeWidget> |
27 | #include <QMimeData> |
28 | |
29 | #include <KService> |
30 | #include <KServiceGroup> |
31 | |
32 | class ; |
33 | class QDropEvent; |
34 | class QSignalMapper; |
35 | |
36 | class KActionCollection; |
37 | class KDesktopFile; |
38 | class ; |
39 | class ; |
40 | class ; |
41 | class ; |
42 | class KShortcut; |
43 | |
44 | static const QString SAVE_ACTION_NAME = "file_save" ; |
45 | static const QString NEW_ITEM_ACTION_NAME = "new_item" ; |
46 | static const QString = "new_submenu" ; |
47 | static const QString NEW_SEPARATOR_ACTION_NAME = "new_separator" ; |
48 | static const QString CUT_ACTION_NAME = "edit_cut" ; |
49 | static const QString COPY_ACTION_NAME = "edit_copy" ; |
50 | static const QString PASTE_ACTION_NAME = "edit_paste" ; |
51 | static const QString DELETE_ACTION_NAME = "delete" ; |
52 | static const QString SORT_ACTION_NAME = "sort" ; |
53 | static const QString SORT_BY_NAME_ACTION_NAME = "sort_by_name" ; |
54 | static const QString SORT_BY_DESCRIPTION_ACTION_NAME = "sort_by_description" ; |
55 | static const QString SORT_ALL_BY_NAME_ACTION_NAME = "sort_all_by_name" ; |
56 | static const QString SORT_ALL_BY_DESCRIPTION_ACTION_NAME = "sort_all_by_description" ; |
57 | static const QString MOVE_UP_ACTION_NAME = "move_up" ; |
58 | static const QString MOVE_DOWN_ACTION_NAME = "move_down" ; |
59 | |
60 | class TreeItem : public QTreeWidgetItem |
61 | { |
62 | public: |
63 | TreeItem(QTreeWidgetItem *parent, QTreeWidgetItem *after, const QString &, bool __init = false); |
64 | TreeItem(QTreeWidget *parent, QTreeWidgetItem *after, const QString &, bool __init = false); |
65 | ~TreeItem(); |
66 | static bool itemNameLessThan(QTreeWidgetItem *item1, QTreeWidgetItem *item2); |
67 | static bool itemDescriptionLessThan(QTreeWidgetItem *item1, QTreeWidgetItem *item2); |
68 | |
69 | QString () const { return m_menuId; } |
70 | |
71 | QString directory() const { return m_directoryPath; } |
72 | void setDirectoryPath(const QString& path) { m_directoryPath = path; } |
73 | |
74 | MenuFolderInfo *folderInfo() { return m_folderInfo; } |
75 | void (MenuFolderInfo *folderInfo) { m_folderInfo = folderInfo; } |
76 | |
77 | MenuEntryInfo *entryInfo() const { return m_entryInfo; } |
78 | void (MenuEntryInfo *entryInfo) { m_entryInfo = entryInfo; } |
79 | |
80 | QString name() const { return m_name; } |
81 | void setName(const QString &name); |
82 | |
83 | QString description() const; |
84 | |
85 | bool isDirectory() const { return m_folderInfo; } |
86 | bool isEntry() const { return m_entryInfo; } |
87 | bool isSeparator() const { return !isDirectory() && !isEntry(); } |
88 | |
89 | bool () const { return m_hidden; } |
90 | void (bool b); |
91 | |
92 | bool isLayoutDirty() const; |
93 | void setLayoutDirty() { m_layoutDirty = true; } |
94 | void (MenuFile *); |
95 | |
96 | void load(); |
97 | |
98 | //virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align); |
99 | |
100 | private: |
101 | void update(); |
102 | |
103 | bool m_hidden : 1; |
104 | bool m_init : 1; |
105 | bool m_layoutDirty : 1; |
106 | QString ; |
107 | QString m_name; |
108 | QString m_directoryPath; |
109 | MenuFolderInfo *m_folderInfo; |
110 | MenuEntryInfo *m_entryInfo; |
111 | }; |
112 | |
113 | class TreeView : public QTreeWidget |
114 | { |
115 | friend class TreeItem; |
116 | Q_OBJECT |
117 | public: |
118 | explicit TreeView(KActionCollection *ac, QWidget *parent=0, const char *name=0); |
119 | ~TreeView(); |
120 | |
121 | void (MenuFolderInfo *folderInfo=0, KServiceGroup::Ptr folder=KServiceGroup::Ptr(), const QString &prefix=QString()); |
122 | void setViewMode(bool showHidden); |
123 | bool save(); |
124 | |
125 | bool dirty(); |
126 | |
127 | void (const QString &); |
128 | void (const QString &); |
129 | |
130 | void (); |
131 | |
132 | void updateTreeView(bool showHidden); |
133 | |
134 | public Q_SLOTS: |
135 | void (MenuFolderInfo *folderInfo); |
136 | void (MenuEntryInfo *entryInfo); |
137 | void findServiceShortcut(const KShortcut&, KService::Ptr &); |
138 | |
139 | Q_SIGNALS: |
140 | void (MenuFolderInfo *folderInfo); |
141 | void (MenuEntryInfo *entryInfo); |
142 | void disableAction(); |
143 | |
144 | protected Q_SLOTS: |
145 | void itemSelected(QTreeWidgetItem *); |
146 | bool dropMimeData(QTreeWidgetItem *parent, int index, const QMimeData *data, Qt::DropAction action); |
147 | |
148 | void (); |
149 | void newitem(); |
150 | void newsep(); |
151 | |
152 | void cut(); |
153 | void copy(); |
154 | void paste(); |
155 | void del(); |
156 | void sort(const int sortCmd); |
157 | void moveUpItem(); |
158 | void moveDownItem(); |
159 | |
160 | protected: |
161 | enum SortType { |
162 | SortByName = 0, |
163 | SortByDescription, |
164 | SortAllByName, |
165 | SortAllByDescription |
166 | }; |
167 | |
168 | void (QContextMenuEvent *event); |
169 | void dropEvent(QDropEvent *event); |
170 | void startDrag(Qt::DropActions supportedActions); |
171 | QTreeWidgetItem *selectedItem(); |
172 | TreeItem *(TreeItem *parent, QTreeWidgetItem *after, MenuFolderInfo *folderInfo, bool _init = false); |
173 | TreeItem *(TreeItem *parent, QTreeWidgetItem *after, MenuEntryInfo *entryInfo, bool _init = false); |
174 | TreeItem *(TreeItem *parent, QTreeWidgetItem *after, MenuSeparatorInfo *sepInfo, bool _init = false); |
175 | |
176 | void del(TreeItem *, bool deleteInfo); |
177 | void fill(); |
178 | void (MenuFolderInfo *folderInfo, TreeItem *parent); |
179 | QString findName(KDesktopFile *df, bool deleted); |
180 | void sortItem(TreeItem *item, const SortType& sortType); |
181 | void sortItemChildren(const QList<QTreeWidgetItem*>::iterator& begin, const QList<QTreeWidgetItem*>::iterator& end, const SortType& sortType); |
182 | TreeItem* getParentItem(QTreeWidgetItem *item) const; |
183 | void moveUpOrDownItem(bool isMovingUpAction); |
184 | |
185 | void closeAllItems(QTreeWidgetItem *item); |
186 | TreeItem *expandPath(TreeItem *item, const QString &path); |
187 | |
188 | // moving = src will be removed later |
189 | void copy( bool moving ); |
190 | |
191 | void cleanupClipboard(); |
192 | |
193 | bool isLayoutDirty(); |
194 | void setLayoutDirty(TreeItem *); |
195 | void saveLayout(); |
196 | |
197 | QStringList fileList(const QString& relativePath); |
198 | QStringList dirList(const QString& relativePath); |
199 | |
200 | virtual QStringList mimeTypes() const; |
201 | QMimeData *mimeData(const QList<QTreeWidgetItem *> items) const; |
202 | Qt::DropActions supportedDropActions() const; |
203 | |
204 | void (); |
205 | |
206 | private: |
207 | KActionCollection *m_ac; |
208 | QMenu *; |
209 | int m_clipboard; |
210 | MenuFolderInfo *m_clipboardFolderInfo; |
211 | MenuEntryInfo *m_clipboardEntryInfo; |
212 | bool m_showHidden; |
213 | MenuFile *; |
214 | MenuFolderInfo *m_rootFolder; |
215 | MenuSeparatorInfo *m_separator; |
216 | QStringList ; |
217 | QStringList m_newDirectoryList; |
218 | bool m_layoutDirty; |
219 | bool ; |
220 | bool m_detailedEntriesNamesFirst; |
221 | QStringList m_dropMimeTypes; |
222 | QSignalMapper *m_sortSignalMapper; |
223 | }; |
224 | |
225 | class : public QMimeData |
226 | { |
227 | public: |
228 | (TreeItem *item); |
229 | virtual QStringList () const; |
230 | virtual bool (const QString &mimeType) const; |
231 | TreeItem *() const; |
232 | |
233 | protected: |
234 | virtual QVariant (const QString &mimeType, QVariant::Type type) const; |
235 | |
236 | private: |
237 | TreeItem *; |
238 | }; |
239 | |
240 | Q_DECLARE_METATYPE(TreeItem *) |
241 | |
242 | #endif |
243 | |