author | ulf69 <ulf69> | 2004-09-15 17:53:22 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-09-15 17:53:22 (UTC) |
commit | d3925ba5bd25224bc4a60d3d6a107c464994a1ea (patch) (unidiff) | |
tree | 60f69da1d2b79ee3081e7ef5c09a46470ca6eda0 /pwmanager/pwmanager/pwmtray.h | |
parent | ce83a3479d23b9e8a59c745ccd0a0b14f64ef4e8 (diff) | |
download | kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.zip kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.gz kdepimpi-d3925ba5bd25224bc4a60d3d6a107c464994a1ea.tar.bz2 |
initial revision
Diffstat (limited to 'pwmanager/pwmanager/pwmtray.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | pwmanager/pwmanager/pwmtray.h | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/pwmanager/pwmanager/pwmtray.h b/pwmanager/pwmanager/pwmtray.h new file mode 100644 index 0000000..ffb625e --- a/dev/null +++ b/pwmanager/pwmanager/pwmtray.h | |||
@@ -0,0 +1,292 @@ | |||
1 | /*************************************************************************** | ||
2 | * * | ||
3 | * copyright (C) 2003, 2004 by Michael Buesch * | ||
4 | * email: mbuesch@freenet.de * | ||
5 | * * | ||
6 | * This program is free software; you can redistribute it and/or modify * | ||
7 | * it under the terms of the GNU General Public License version 2 * | ||
8 | * as published by the Free Software Foundation. * | ||
9 | * * | ||
10 | ***************************************************************************/ | ||
11 | |||
12 | /*************************************************************************** | ||
13 | * copyright (C) 2004 by Ulf Schenk | ||
14 | * This file is originaly based on version 1.0.1 of pwmanager | ||
15 | * and was modified to run on embedded devices that run microkde | ||
16 | * | ||
17 | * $Id$ | ||
18 | **************************************************************************/ | ||
19 | |||
20 | #ifndef __PWMTRAY_H | ||
21 | #define __PWMTRAY_H | ||
22 | |||
23 | #ifndef PWM_EMBEDDED | ||
24 | #include <ksystemtray.h> | ||
25 | #endif | ||
26 | |||
27 | #include <kpopupmenu.h> | ||
28 | |||
29 | #include <qpainter.h> | ||
30 | #include <qvaluelist.h> | ||
31 | |||
32 | //#include "pwmexception.h" | ||
33 | |||
34 | class PwMInit; | ||
35 | class PwMDoc; | ||
36 | class PwMTray; | ||
37 | |||
38 | /* wrapper to workaround MOC problems */ | ||
39 | class __ActiveTreeItem : public QCustomMenuItem | ||
40 | , public QObject | ||
41 | { | ||
42 | public: | ||
43 | __ActiveTreeItem() {} | ||
44 | }; | ||
45 | |||
46 | /** implements the "active" part of the tree */ | ||
47 | class ActiveTreeItem : public __ActiveTreeItem | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | |||
51 | public: | ||
52 | enum Task | ||
53 | { | ||
54 | pwToClipboard, | ||
55 | nameToClipboard, | ||
56 | descToClipboard, | ||
57 | urlToClipboard, | ||
58 | launcherToClipboard, | ||
59 | commentToClipboard, | ||
60 | execLauncher, | ||
61 | goToURL, | ||
62 | openMainWnd, | ||
63 | closeDoc, | ||
64 | lock, | ||
65 | deepLock, | ||
66 | unlock | ||
67 | }; | ||
68 | |||
69 | public: | ||
70 | ActiveTreeItem(const QString &_text, const QFont &_font, | ||
71 | Task _task, PwMDoc * _doc, | ||
72 | int _category, int _entry, | ||
73 | PwMTray *_tray) | ||
74 | : text (_text) | ||
75 | , font (_font) | ||
76 | , task (_task) | ||
77 | , doc (_doc) | ||
78 | , category (_category) | ||
79 | , entry (_entry) | ||
80 | , tray (_tray) | ||
81 | { } | ||
82 | |||
83 | /*~ActiveTreeItem() | ||
84 | { cout << "deleted \"" << text << "\"" << endl; } */ | ||
85 | |||
86 | void paint(QPainter *p, const QColorGroup & /*cg*/, bool /*act*/, | ||
87 | bool /*enabled*/, int x, int y, int w, int h) | ||
88 | { | ||
89 | p->setFont(font); | ||
90 | p->drawText(x, y, w, h, AlignLeft | AlignVCenter | | ||
91 | DontClip | ShowPrefix, text); | ||
92 | } | ||
93 | |||
94 | QSize sizeHint() | ||
95 | { | ||
96 | return QFontMetrics(font).size(AlignLeft | AlignVCenter | | ||
97 | ShowPrefix | DontClip, text); | ||
98 | } | ||
99 | |||
100 | bool fullSpan() const | ||
101 | { return false; } | ||
102 | |||
103 | bool isSeparator() const | ||
104 | { return false; } | ||
105 | |||
106 | void setFont(const QFont &f) | ||
107 | { font = f; } | ||
108 | |||
109 | public slots: | ||
110 | /** this is the executive part, that is triggered, when the user clicks it */ | ||
111 | void execIt(); | ||
112 | |||
113 | protected: | ||
114 | QString text; | ||
115 | QFont font; | ||
116 | Task task; | ||
117 | PwMDoc *doc; | ||
118 | int category; | ||
119 | int entry; | ||
120 | PwMTray *tray; | ||
121 | }; | ||
122 | |||
123 | /** tray icon implementation */ | ||
124 | #ifndef PWM_EMBEDDED | ||
125 | //MOC_SKIP_BEGIN | ||
126 | class PwMTray : public KSystemTray | ||
127 | { | ||
128 | Q_OBJECT | ||
129 | |||
130 | friend class ActiveTreeItem; | ||
131 | |||
132 | struct treeItem | ||
133 | { | ||
134 | int menuId; | ||
135 | PwMDoc *doc; | ||
136 | KPopupMenu *menu; | ||
137 | QValueList<int> activeItems; // ids of all active items | ||
138 | }; | ||
139 | |||
140 | public: | ||
141 | PwMTray(PwMInit *_init, QWidget* parent = 0, const char* name = 0); | ||
142 | ~PwMTray(); | ||
143 | |||
144 | /** connect all signals for this document to the tray */ | ||
145 | void connectDocToTray(PwMDoc *doc); | ||
146 | |||
147 | public slots: | ||
148 | /** for update-notification from all open documents */ | ||
149 | void updateTree(PwMDoc *document); | ||
150 | /** when a document has been closed, call this func | ||
151 | * to delete its tray-entry | ||
152 | */ | ||
153 | void closeTreeEntry(PwMDoc *document); | ||
154 | |||
155 | protected slots: | ||
156 | /** open a new document */ | ||
157 | void openDoc(); | ||
158 | /** open a new mainwnd */ | ||
159 | void newMainWnd(); | ||
160 | /** undock this tray icon */ | ||
161 | void undock(); | ||
162 | |||
163 | signals: | ||
164 | /** this icon got deleted */ | ||
165 | void closed(PwMTray *); | ||
166 | /** the user clicked on the tray icon */ | ||
167 | void clickedIcon(PwMTray *); | ||
168 | |||
169 | protected: | ||
170 | /** holds a list of all open files, its documents and | ||
171 | * its menuIDs | ||
172 | */ | ||
173 | QValueList<struct treeItem> tree; | ||
174 | /** pointer to init */ | ||
175 | PwMInit *init; | ||
176 | |||
177 | protected: | ||
178 | /** search if an entry with for the given document | ||
179 | * exists and resturn its ID and a pointer to the main | ||
180 | * KPopupMenu. If no item is found, | ||
181 | * it returns -1 as ID and a NULL-pointer. | ||
182 | */ | ||
183 | int findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem); | ||
184 | /** build the main menu-items */ | ||
185 | void buildMain(); | ||
186 | /** rebuilds the tree for the given KPopupMenu entry */ | ||
187 | void rebuildTree(KPopupMenu *popup, PwMDoc *doc, | ||
188 | QValueList<int> *activeItems); | ||
189 | /** insert a new tree-entry for the given doc and returns the ID.*/ | ||
190 | int insertTreeEntry(PwMDoc *doc, KPopupMenu **popup); | ||
191 | /** removes a tree entry */ | ||
192 | void removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu); | ||
193 | /** inserts a new active-tree-item into the given tree entry */ | ||
194 | void insertActiveTreeItem(KPopupMenu *insertIn, const QString &text, | ||
195 | ActiveTreeItem::Task task, PwMDoc *doc, | ||
196 | int docCategory, int docEntry, | ||
197 | QValueList<int> *activeItemsList); | ||
198 | /** mouse event on icon */ | ||
199 | void mouseReleaseEvent(QMouseEvent *e); | ||
200 | /** inserts the items for the main window control | ||
201 | * into the popup menu. | ||
202 | */ | ||
203 | void insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc); | ||
204 | }; | ||
205 | //MOC_SKIP_END | ||
206 | #else | ||
207 | class PwMTray : public QWidget | ||
208 | { | ||
209 | Q_OBJECT | ||
210 | |||
211 | friend class ActiveTreeItem; | ||
212 | |||
213 | struct treeItem | ||
214 | { | ||
215 | int menuId; | ||
216 | PwMDoc *doc; | ||
217 | KPopupMenu *menu; | ||
218 | QValueList<int> activeItems; // ids of all active items | ||
219 | }; | ||
220 | |||
221 | public: | ||
222 | PwMTray(PwMInit *_init, QWidget* parent = 0, const char* name = 0); | ||
223 | ~PwMTray(); | ||
224 | |||
225 | //US ENH needed for embedde version. | ||
226 | KPopupMenu* contextMenu(); | ||
227 | KPopupMenu* m_ctxMenu; | ||
228 | |||
229 | /** connect all signals for this document to the tray */ | ||
230 | void connectDocToTray(PwMDoc *doc); | ||
231 | |||
232 | public slots: | ||
233 | /** for update-notification from all open documents */ | ||
234 | void updateTree(PwMDoc *document); | ||
235 | /** when a document has been closed, call this func | ||
236 | * to delete its tray-entry | ||
237 | */ | ||
238 | void closeTreeEntry(PwMDoc *document); | ||
239 | |||
240 | protected slots: | ||
241 | /** open a new document */ | ||
242 | void openDoc(); | ||
243 | /** open a new mainwnd */ | ||
244 | void newMainWnd(); | ||
245 | /** undock this tray icon */ | ||
246 | void undock(); | ||
247 | |||
248 | signals: | ||
249 | /** this icon got deleted */ | ||
250 | void closed(PwMTray *); | ||
251 | /** the user clicked on the tray icon */ | ||
252 | void clickedIcon(PwMTray *); | ||
253 | |||
254 | protected: | ||
255 | /** holds a list of all open files, its documents and | ||
256 | * its menuIDs | ||
257 | */ | ||
258 | QValueList<struct treeItem> tree; | ||
259 | /** pointer to init */ | ||
260 | PwMInit *init; | ||
261 | |||
262 | protected: | ||
263 | /** search if an entry with for the given document | ||
264 | * exists and resturn its ID and a pointer to the main | ||
265 | * KPopupMenu. If no item is found, | ||
266 | * it returns -1 as ID and a NULL-pointer. | ||
267 | */ | ||
268 | int findTreeEntry(PwMDoc *doc, KPopupMenu **menu, int *treeItem); | ||
269 | /** build the main menu-items */ | ||
270 | void buildMain(); | ||
271 | /** rebuilds the tree for the given KPopupMenu entry */ | ||
272 | void rebuildTree(KPopupMenu *popup, PwMDoc *doc, | ||
273 | QValueList<int> *activeItems); | ||
274 | /** insert a new tree-entry for the given doc and returns the ID.*/ | ||
275 | int insertTreeEntry(PwMDoc *doc, KPopupMenu **popup); | ||
276 | /** removes a tree entry */ | ||
277 | void removeTreeEntry(int menuId, int treeItem, KPopupMenu **menu); | ||
278 | /** inserts a new active-tree-item into the given tree entry */ | ||
279 | void insertActiveTreeItem(KPopupMenu *insertIn, const QString &text, | ||
280 | ActiveTreeItem::Task task, PwMDoc *doc, | ||
281 | int docCategory, int docEntry, | ||
282 | QValueList<int> *activeItemsList); | ||
283 | /** mouse event on icon */ | ||
284 | void mouseReleaseEvent(QMouseEvent *e); | ||
285 | /** inserts the items for the main window control | ||
286 | * into the popup menu. | ||
287 | */ | ||
288 | void insertMainWndCtrl(KPopupMenu *menu, PwMDoc *doc); | ||
289 | }; | ||
290 | #endif | ||
291 | |||
292 | #endif | ||