File: kaccelmenuwatch.h

package info (click to toggle)
kdeutils 4%3A2.2.2-9.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,892 kB
  • ctags: 10,879
  • sloc: cpp: 82,942; sh: 11,754; ansic: 4,638; perl: 1,852; makefile: 706; python: 258
file content (113 lines) | stat: -rw-r--r-- 2,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* kaccelmenuwatch.h -- Declaration of class KAccelMenuWatch.
* Generated by newclass on Thu Jan  7 15:05:26 EST 1999.
*/
#ifndef SSK_KACCELMENUWATCH_H
#define SSK_KACCELMENUWATCH_H

#include<qobject.h>
#include<qpopupmenu.h>
#include<qlist.h>

#include<kaccel.h>

/**
* Easy updating of menu accels when changing a @ref KAccel object.
*
* Since a KAccel object does not keep track of menu items to which it
* is connected, we normally have to manually call 
* @ref KAccel::changeMenuAccel again for each update of the KAccel object.
*
* With KAccelMenuWatch you provide the kaccel object and the menu
* items to which it connects, and if you update the kaccel you just have
* to call @ref ::updateMenus and the menu items will be updated.
*
* It is safe to delete menus that have connections handled by this class.
* On deletion of a menu, all associated accelerators will be deleted.
*
* Note that you _have_ to call updateMenus after you connect the
* accelerators, as they are not activated till then.
*
 @author Sirtaj Singh Kang (taj@kde.org)
* @version $Id: kaccelmenuwatch.h,v 1.4 2000/02/07 21:17:31 hadacek Exp $
*/
class KAccelMenuWatch : public QObject
{
	Q_OBJECT

private:
	enum AccelType { StdAccel, StringAccel };

	typedef struct AccelItem {
		QPopupMenu	*menu;
		int 		itemId;

		AccelType	type;

		// only one of these is used at a time
		QString		action;
		KStdAccel::StdAccel stdAction;
		
	} AccelItem;

	KAccel		 *_accel;
	QList<AccelItem> _accList;
	QList<QPopupMenu> _menuList;

	QPopupMenu	*_menu;

	KAccelMenuWatch::AccelItem *newAccelItem( QPopupMenu *menu, 
			int itemId, AccelType type );

public:
	/**
	* KAccelMenuWatch Constructor
	*/
	KAccelMenuWatch( KAccel *accel, QObject *parent = 0 );

	/**
	* KAccelMenuWatch Destructor
	*/
	virtual ~KAccelMenuWatch() {}

	/** 
	 * Set the menu on which connectAccel calls will operate.
	 * All subsequent calls to connectAccel will be associated
	 * with this menu. You can call this function any number of
	 * times, so multiple menus can be handled.
	 */
	void setMenu( QPopupMenu *menu );

	/** 
	 * Return the last menu set with @ref ::setMenu, or 0 if none
	 * has been set.
	 */
	QPopupMenu *currentMenu() const  { return _menu; }

	/** 
	 * Connect the menu item identified to currentMenu()/id to
	 * the accelerator action.
	 */
	void connectAccel( int itemId, const char *action );

	/** 
	 * Same as above, but connects to standard accelerators.
	 */
	void connectAccel( int itemId, KStdAccel::StdAccel );
	
public slots:
	/** 
	 * Updates all menu accelerators. Call this after all accelerators
	 * have been connected or the kaccel object has been updated.
	 */
	void updateMenus();

private slots:
	void removeDeadMenu();

private:
	KAccelMenuWatch& operator=( const KAccelMenuWatch& );
	KAccelMenuWatch( const KAccelMenuWatch& );
};

#endif // SSK_KACCELMENUWATCH_H