summaryrefslogtreecommitdiffstats
path: root/kbstateapplet/kbstate.h
blob: a9b9601a2ca8a376290745819fce1f8acefd4a99 (plain)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
 *  Copyright (c) 2004 Gunnar Schmi Dt <gunnar@schmi-dt.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 */

#ifndef __kbstate_h__
#define __kbstate_h__

#include <kpanelapplet.h> 
#include <tqpushbutton.h>
#include <tqptrlist.h>
#include <tqtimer.h>

extern "C"
{
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
}
     
class TQLabel;      
class TQGridLayout;
class KPopupMenu;

class StatusIcon : public TQPushButton {
   Q_OBJECT
public:
   StatusIcon (const TQString &text, TQWidget *parent, const char *name=0);
   ~StatusIcon ();

   TQSize minimumSizeHint () const;
};
typedef TQPtrList<StatusIcon> IconList;

class TimeoutIcon : public StatusIcon {
   Q_OBJECT
public:
   TimeoutIcon (KInstance *instance, const TQString &text,
					 const TQString &featurename,
					 TQWidget *parent, const char *name=0);
   ~TimeoutIcon ();

   void update ();
   void setGlyth (const TQString &glyth);
   void setImage (const TQString &name, int timeout = 0);

   void drawButton (TQPainter *p);

private:
   TQString glyth;
	TQString iconname;
	TQString featurename;
   TQPixmap pixmap;
   TQPixmap image;
   TQTimer timer;
   KInstance *instance;
   
private slots:
   void timeout ();
};

class KeyIcon : public StatusIcon {
   Q_OBJECT
public:
   KeyIcon (int keyId, KInstance *instance,
            TQWidget *parent, const char *name=0);
   ~KeyIcon ();
   void setState (bool latched, bool locked);
   void drawButton (TQPainter *p);
   void updateImages ();

signals:
   void stateChangeRequest (KeyIcon *source, bool latched, bool locked);

protected:
   void resizeEvent(TQResizeEvent*);

private slots:
   void clickedSlot();

private:
   TQPixmap locked;
   TQPixmap latched;
   TQPixmap unlatched;
   bool    isLatched;
   bool    isLocked;
   bool    tristate;
   int     keyId;
   KInstance *instance;
};

class MouseIcon : public StatusIcon {
	Q_OBJECT
	public:
		MouseIcon (KInstance *instance, TQWidget *parent, const char *name=0);
		~MouseIcon ();
		void setState (int state);
		void setActiveKey (int activekey);
		void drawButton (TQPainter *p);
		void updateImages ();

	protected:
		void resizeEvent(TQResizeEvent*);

	private:
		TQPixmap mouse;
		TQPixmap leftSelected;
		TQPixmap middleSelected;
		TQPixmap rightSelected;
		TQPixmap leftDot;
		TQPixmap middleDot;
		TQPixmap rightDot;
		TQPixmap leftDotSelected;
		TQPixmap middleDotSelected;
		TQPixmap rightDotSelected;
		int state, activekey;
		KInstance *instance;
};

class KbStateApplet : public KPanelApplet {
   Q_OBJECT

public:
   KbStateApplet(const TQString& configFile, Type t = Normal, int actions = 0,
              TQWidget *parent = 0, const char *name = 0);
   ~KbStateApplet();

   int widthForHeight(int height) const;
   int heightForWidth(int width) const;

protected:
    void mousePressEvent(TQMouseEvent *e);
    void timerEvent(TQTimerEvent*);
    void resizeEvent(TQResizeEvent*);
    bool x11Event (XEvent *);

public slots:
   void about();
   void configureAccessX();
   void configureMouse();
   void configureKeyboard();
   void toggleModifier ();
   void toggleLockkeys ();
	void toggleMouse ();
	void toggleAccessX ();
	void paletteChanged();

	void toggleFillSpace ();

private slots:
	void setIconDim (int size);
   void stateChangeRequest (KeyIcon *source, bool latched, bool locked);

private:
   void loadConfig();
   void saveConfig();
   void layout();
   
   int xkb_base_event_type;

   KeyIcon *(icons[8]);
   IconList modifiers;
   IconList lockkeys;
	TimeoutIcon *sticky;
	TimeoutIcon *slow;
	TimeoutIcon *bounce;
   MouseIcon *mouse;
   
	int state;
	unsigned int accessxFeatures;
   int size;
   
   void initMasks();

   void buildPopupMenu();
   void updateMenu();
   KPopupMenu *popup;
   KPopupMenu *sizePopup;
   KPopupMenu *showPopup;
	int modifierItem, lockkeysItem, mouseItem, accessxItem;
	int fillSpaceItem;
	bool showModifiers, showLockkeys, showMouse, showAccessX;
	bool fillSpace;

	KInstance *instance;
	XkbDescPtr xkb;
};

#endif // __kbstate_h__