not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kmenuedit / treeview.h
blob7146da61b2f7330d1dcc45dd1fe55d13646e094d
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>
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.
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.
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.
23 #ifndef __treeview_h__
24 #define __treeview_h__
27 //Added by qt3to4:
28 #include <QMenu>
29 #include <QDropEvent>
30 #include <k3listview.h>
31 #include <kservice.h>
32 #include <kservicegroup.h>
34 class QMenu;
35 class KActionCollection;
36 class KDesktopFile;
37 class MenuFile;
38 class MenuFolderInfo;
39 class MenuEntryInfo;
40 class MenuSeparatorInfo;
41 class KShortcut;
43 class TreeItem : public Q3ListViewItem
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);
49 QString menuId() const { return _menuId; }
51 QString directory() const { return _directoryPath; }
52 void setDirectoryPath(const QString& path) { _directoryPath = path; }
54 MenuFolderInfo *folderInfo() { return m_folderInfo; }
55 void setMenuFolderInfo(MenuFolderInfo *folderInfo) { m_folderInfo = folderInfo; }
57 MenuEntryInfo *entryInfo() { return m_entryInfo; }
58 void setMenuEntryInfo(MenuEntryInfo *entryInfo) { m_entryInfo = entryInfo; }
60 QString name() const { return _name; }
61 void setName(const QString &name);
63 bool isDirectory() const { return m_folderInfo; }
64 bool isEntry() const { return m_entryInfo; }
66 bool isHidden() const { return _hidden; }
67 void setHidden(bool b);
69 bool isLayoutDirty() { return _layoutDirty; }
70 void setLayoutDirty() { _layoutDirty = true; }
71 QStringList layout();
73 virtual void setOpen(bool o);
74 void load();
76 virtual void paintCell(QPainter * p, const QColorGroup & cg, int column, int width, int align);
77 virtual void setup();
79 private:
80 void update();
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;
92 class TreeView : public K3ListView
94 friend class TreeItem;
95 Q_OBJECT
96 public:
97 TreeView(KActionCollection *ac, QWidget *parent=0, const char *name=0);
98 ~TreeView();
100 void readMenuFolderInfo(MenuFolderInfo *folderInfo=0, KServiceGroup::Ptr folder=KServiceGroup::Ptr(), const QString &prefix=QString());
101 void setViewMode(bool showHidden);
102 bool save();
104 bool dirty();
106 void selectMenu(const QString &menu);
107 void selectMenuEntry(const QString &menuEntry);
109 void restoreMenuSystem();
111 void updateTreeView(bool showHidden);
113 public Q_SLOTS:
114 void currentChanged(MenuFolderInfo *folderInfo);
115 void currentChanged(MenuEntryInfo *entryInfo);
116 void findServiceShortcut(const KShortcut&, KService::Ptr &);
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&);
127 void newsubmenu();
128 void newitem();
129 void newsep();
131 void cut();
132 void copy();
133 void paste();
134 void del();
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);
141 void del(TreeItem *, bool deleteInfo);
142 void fill();
143 void fillBranch(MenuFolderInfo *folderInfo, TreeItem *parent);
144 QString findName(KDesktopFile *df, bool deleted);
146 void closeAllItems(Q3ListViewItem *item);
148 // moving = src will be removed later
149 void copy( bool moving );
151 void cleanupClipboard();
153 bool isLayoutDirty();
154 void setLayoutDirty(TreeItem *);
155 void saveLayout();
157 QStringList fileList(const QString& relativePath);
158 QStringList dirList(const QString& relativePath);
160 virtual bool acceptDrag(QDropEvent* event) const;
161 virtual Q3DragObject *dragObject();
162 virtual void startDrag();
164 void sendReloadMenu();
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;
188 #endif