1
/*****************************************************************
3
Copyright (c) 1996-2000 the kicker authors. See file AUTHORS.
4
(c) 2001 Michael Goffioul <kdeprint@swing.be>
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
******************************************************************/
25
#ifndef __KPANELMENU_H__
26
#define __KPANELMENU_H__
30
#include <kgenericfactory.h>
33
* @short Base class to build dynamically loaded menu entries for the K-menu, or the panel.
35
* This class allows to build menu entries that will be dynamically added either to
36
* the K-menu, or to the panel as a normal button. These dynamic menus are located
37
* in shared libraries that will be loaded at runtime by Kicker (the %KDE panel).
39
* To build such a menu, you have to inherit this class and implement the pure virtual
40
* functions #initialize() and slotExec(). You also have to provide a factory
41
* object in your library, see KLibFactory. This factory is only used to construct
44
* Finally, you also have to provide a desktop file describing your dynamic menu. The
45
* relevant entries are: Name, Comment, Icon and X-KDE-Library (which contains the
46
* library name without any extension). This desktop file has to be installed in
47
* $KDEDIR/share/apps/kicker/menuext/.
49
* @author The kicker maintainers, Michael Goffioul <kdeprint@swing.be>
51
class KDE_EXPORT KPanelMenu : public KMenu
57
* Construct a KPanelMenu object. This is the normal constructor to use when
58
* building extrernal menu entries.
60
KPanelMenu(QWidget *parent);
62
* Constructor used internally by Kicker. You don't really want to use it.
63
* @param startDir a directory to associate with this menu
64
* @param parent parent object
65
* @param name name of the object
66
* @see path(), setPath()
68
KPanelMenu(const QString &startDir, QWidget *parent);
72
virtual ~KPanelMenu();
75
* Get the directory path associated with this menu, or QString() if
76
* there's no such associated path.
77
* @return the associated directory path
80
const QString& path() const;
82
* Set a directory path to be associated with this menu.
83
* @param p the directory path
86
void setPath(const QString &p);
88
* Tell if the menu has been initialized, that is it already contains items.
89
* This is useful when you need to know if you have to clear the menu, or to
91
* @return the initial state
92
* @see setInitialized(), initialize()
94
bool initialized() const;
96
* Set the initial state. Set it to true when you menu is filled with the items
98
* @param on the initial state
99
* @see initialized(), initialize()
101
void setInitialized(bool on);
104
* Disable the automatic clearing of the menu. Kicker uses a cache system for
105
* its menus. After a specific configurable delay, the menu will be cleared.
106
* Use this function if you want to disable kicker's cache system, and avoid
107
* the clearing of your menu.
109
void disableAutoClear();
113
* Reinitialize the menu: the menu is first cleared, the initial state is set
114
* to false, and finally #initialize() is called. Use this if you want to
115
* refill your menu immediately.
119
* Deinitialize the menu: the menu is cleared and the initialized state is set to
120
* false. #initialize() is NOT called. It will be called before the menu is
121
* next shown, however. Use this slot if you want a delayed reinitialization.
127
* This slot is called just before the menu is shown. This allows your menu
128
* to update itself if needed. However you should instead re-implement
129
* #initialize to provide this feature. This function is responsible for
130
* the cache system handling, so if you re-implement it, you should call
131
* the base function also. Calls #initialize().
132
* @see disableAutoClear()
134
virtual void slotAboutToShow();
136
* This is slot is called when an item from the menu has been selected. Your
137
* applet is then supposed to perform some action. You must re-implement this
139
* @param id the ID associated with the selected item
141
virtual void slotExec(int id) = 0;
143
* This slots is called to initialize the menu. It is called automatically by
144
* slotAboutToShow(). By re-implementing this functions, you can reconstruct
145
* the menu before it is being shown. At the end of this function, you should
146
* call setInitialize() with true to tell the system that the menu is OK.
147
* You applet must re-implement this function.
148
* @see slotAboutToShow(), initialized(), setInitialized()
150
virtual void initialize() = 0;
152
* Clears the menu, and update the initial state accordingly.
159
* Re-implemented for internal reasons.
161
virtual void hideEvent(QHideEvent *ev);
163
* For internal use only. Used by constructors.
165
void init(const QString& path = QString());
168
void internalInitialize();
173
#define K_EXPORT_KICKER_MENUEXT( libname, classname ) \
174
K_EXPORT_COMPONENT_FACTORY( \
175
kickermenu_##libname, \
176
KGenericFactory<classname>("libkickermenu_" #libname) )