Diffstat (limited to 'libopie2/opieui/opopupmenu.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opieui/opopupmenu.h | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/libopie2/opieui/opopupmenu.h b/libopie2/opieui/opopupmenu.h new file mode 100644 index 0000000..94f05f4 --- a/dev/null +++ b/libopie2/opieui/opopupmenu.h | |||
@@ -0,0 +1,256 @@ | |||
1 | /* This file is part of the ODE libraries | ||
2 | Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org> | ||
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 version 2 as published by the Free Software Foundation. | ||
7 | |||
8 | This library is distributed in the hope that it will be useful, | ||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
11 | Library General Public License for more details. | ||
12 | |||
13 | You should have received a copy of the GNU Library General Public License | ||
14 | along with this library; see the file COPYING.LIB. If not, write to | ||
15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
16 | Boston, MA 02111-1307, USA. | ||
17 | */ | ||
18 | #ifndef _OPOPUP_H | ||
19 | #define _OPOPUP_H | ||
20 | |||
21 | #define INCLUDE_MENUITEM_DEF | ||
22 | |||
23 | /* QT */ | ||
24 | |||
25 | #include <qpopupmenu.h> | ||
26 | |||
27 | /* OPIE */ | ||
28 | |||
29 | #include <opie2/opixmapeffect.h> | ||
30 | |||
31 | /** | ||
32 | * Title widget for use in @ref OPopupMenu. | ||
33 | * | ||
34 | * You usually don't have to create this manually since | ||
35 | * @ref OPopupMenu::insertTitle will do it for you, but it is allowed if | ||
36 | * you wish to customize it's look. | ||
37 | * | ||
38 | * @author Daniel M. Duley <mosfet@kde.org> | ||
39 | * @short OPopupMenu title widget. | ||
40 | */ | ||
41 | class OPopupTitle : public QWidget | ||
42 | { | ||
43 | Q_OBJECT | ||
44 | |||
45 | public: | ||
46 | /** | ||
47 | * Constructs a title widget with the user specified gradient, pixmap, | ||
48 | * and colors. | ||
49 | */ | ||
50 | OPopupTitle(QWidget *parent=0, const char *name=0); | ||
51 | /** | ||
52 | * @deprecated | ||
53 | * Constructs a title widget with the specified gradient and colors. | ||
54 | */ | ||
55 | OPopupTitle(OPixmapEffect::GradientType gradient, const QColor &color, | ||
56 | const QColor &textColor, QWidget *parent=0, | ||
57 | const char *name=0); | ||
58 | /** | ||
59 | * @deprecated | ||
60 | * Constructs a title widget with the specified pixmap and colors. | ||
61 | */ | ||
62 | OPopupTitle(const OPixmap &background, const QColor &color, | ||
63 | const QColor &textColor, QWidget *parent=0, | ||
64 | const char *name=0); | ||
65 | /** | ||
66 | * Sets the title string and optional icon for the title widget. | ||
67 | * | ||
68 | * You will want to call this before inserting into a menu. | ||
69 | */ | ||
70 | void setTitle(const QString &text, const QPixmap *icon=NULL); | ||
71 | /** | ||
72 | * Returns the current title. | ||
73 | */ | ||
74 | QString title() const { return(titleStr); } | ||
75 | /** | ||
76 | * Returns the current icon. | ||
77 | */ | ||
78 | QPixmap icon() const { return(miniicon); } | ||
79 | |||
80 | QSize sizeHint() const; | ||
81 | |||
82 | public slots: | ||
83 | /// @since 3.1 | ||
84 | void setText( const QString &text ); | ||
85 | /// @since 3.1 | ||
86 | void setIcon( const QPixmap &pix ); | ||
87 | |||
88 | protected: | ||
89 | void paintEvent(QPaintEvent *ev); | ||
90 | |||
91 | QString titleStr; | ||
92 | QPixmap miniicon; | ||
93 | |||
94 | // Remove in KDE4 | ||
95 | OPixmapEffect::GradientType grType; | ||
96 | QPixmap fill; | ||
97 | QColor fgColor, bgColor, grHigh, grLow; | ||
98 | bool useGradient; | ||
99 | |||
100 | protected: | ||
101 | virtual void virtual_hook( int id, void* data ); | ||
102 | private: | ||
103 | class OPopupTitlePrivate; | ||
104 | OPopupTitlePrivate *d; | ||
105 | }; | ||
106 | |||
107 | /** | ||
108 | * OPopupMenu is a class for menus with standard title items and keyboard | ||
109 | * accessibility for popups with many options and/or varying options. It acts | ||
110 | * identically to QPopupMenu, with the addition of insertTitle(), | ||
111 | * changeTitle(), setKeyboardShortcutsEnabled() and | ||
112 | * setKeyboardShortcutsExecute() methods. | ||
113 | * | ||
114 | * The titles support a text string, an icon, plus user defined gradients, | ||
115 | * colors, and background pixmaps. | ||
116 | * | ||
117 | * The keyboard search algorithm is incremental with additional underlining | ||
118 | * for user feedback. | ||
119 | * | ||
120 | * @short A menu with title items. | ||
121 | * @author Daniel M. Duley <mosfet@kde.org> | ||
122 | * @author Hamish Rodda <meddie@yoyo.its.monash.edu.au> | ||
123 | */ | ||
124 | class OPopupMenu : public QPopupMenu { | ||
125 | Q_OBJECT | ||
126 | public: | ||
127 | /** | ||
128 | * Constructs a OPopupMenu. | ||
129 | */ | ||
130 | OPopupMenu(QWidget *parent=0, const char *name=0); | ||
131 | |||
132 | /** | ||
133 | * Destructs the object | ||
134 | */ | ||
135 | ~OPopupMenu(); | ||
136 | |||
137 | /** | ||
138 | * Inserts a title item with no icon. | ||
139 | */ | ||
140 | int insertTitle(const QString &text, int id=-1, int index=-1); | ||
141 | /** | ||
142 | * Inserts a title item with the given icon and title. | ||
143 | */ | ||
144 | int insertTitle(const QPixmap &icon, const QString &text, int id=-1, | ||
145 | int index=-1); | ||
146 | /** | ||
147 | * Changes the title of the item at the specified id. If a icon was | ||
148 | * previously set it is cleared. | ||
149 | */ | ||
150 | void changeTitle(int id, const QString &text); | ||
151 | /** | ||
152 | * Changes the title and icon of the title item at the specified id. | ||
153 | */ | ||
154 | void changeTitle(int id, const QPixmap &icon, const QString &text); | ||
155 | /** | ||
156 | * Returns the title of the title item at the specified id. The default | ||
157 | * id of -1 is for backwards compatibility only, you should always specify | ||
158 | * the id. | ||
159 | */ | ||
160 | QString title(int id=-1) const; | ||
161 | /** | ||
162 | * Returns the icon of the title item at the specified id. | ||
163 | */ | ||
164 | QPixmap titlePixmap(int id) const; | ||
165 | |||
166 | /** | ||
167 | * Enables keyboard navigation by searching for the entered key sequence. | ||
168 | * Also underlines the currently selected item, providing feedback on the search. | ||
169 | * | ||
170 | * Defaults to off. | ||
171 | * | ||
172 | * WARNING: calls to text() of currently keyboard-selected items will | ||
173 | * contain additional ampersand characters. | ||
174 | * | ||
175 | * WARNING: though pre-existing keyboard shortcuts will not interfere with the | ||
176 | * operation of this feature, they may be confusing to the user as the existing | ||
177 | * shortcuts will not work. | ||
178 | * @since 3.1 | ||
179 | */ | ||
180 | void setKeyboardShortcutsEnabled(bool enable); | ||
181 | |||
182 | /** | ||
183 | * Enables execution of the menu item once it is uniquely specified. | ||
184 | * Defaults to off. | ||
185 | * @since 3.1 | ||
186 | */ | ||
187 | void setKeyboardShortcutsExecute(bool enable); | ||
188 | |||
189 | /** | ||
190 | * Obsolete method provided for backwards compatibility only. Use the | ||
191 | * normal constructor and insertTitle instead. | ||
192 | */ | ||
193 | OPopupMenu(const QString &title, QWidget *parent=0, const char *name=0); | ||
194 | /** | ||
195 | * Obsolete method provided for backwards compatibility only. Use | ||
196 | * insertTitle and changeTitle instead. | ||
197 | */ | ||
198 | void setTitle(const QString &title); | ||
199 | |||
200 | /** | ||
201 | * Returns the context menu associated with this menu | ||
202 | * @since 3.2 | ||
203 | */ | ||
204 | QPopupMenu* contextMenu(); | ||
205 | |||
206 | /** | ||
207 | * Hides the context menu if shown | ||
208 | * @since 3.2 | ||
209 | */ | ||
210 | void cancelContextMenuShow(); | ||
211 | |||
212 | /** | ||
213 | * Returns the OPopupMenu associated with the current context menu | ||
214 | * @since 3.2 | ||
215 | */ | ||
216 | static OPopupMenu* contextMenuFocus(); | ||
217 | |||
218 | /** | ||
219 | * returns the ID of the menuitem associated with the current context menu | ||
220 | * @since 3.2 | ||
221 | */ | ||
222 | static int contextMenuFocusItem(); | ||
223 | |||
224 | signals: | ||
225 | /** | ||
226 | * connect to this signal to be notified when a context menu is about to be shown | ||
227 | * @param menu The menu that the context menu is about to be shown for | ||
228 | * @param menuItem The menu item that the context menu is currently on | ||
229 | * @param ctxMenu The context menu itself | ||
230 | * @since 3.2 | ||
231 | */ | ||
232 | void aboutToShowContextMenu(OPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu); | ||
233 | |||
234 | protected: | ||
235 | virtual void closeEvent(QCloseEvent *); | ||
236 | virtual void keyPressEvent(QKeyEvent* e); | ||
237 | virtual bool eventFilter(QObject* obj, QEvent* event); | ||
238 | virtual void hideEvent(QHideEvent*); | ||
239 | |||
240 | virtual void virtual_hook( int id, void* data ); | ||
241 | |||
242 | protected slots: | ||
243 | /// @since 3.1 | ||
244 | QString underlineText(const QString& text, uint length); | ||
245 | /// @since 3.1 | ||
246 | void resetKeyboardVars(bool noMatches = false); | ||
247 | void itemHighlighted(int whichItem); | ||
248 | void showCtxMenu(QPoint pos); | ||
249 | void ctxMenuHiding(); | ||
250 | |||
251 | private: | ||
252 | class OPopupMenuPrivate; | ||
253 | OPopupMenuPrivate *d; | ||
254 | }; | ||
255 | |||
256 | #endif | ||