Fix header
[kdeaccessibility.git] / kbstateapplet / kbstate.h
blob2e14e29ba6b7a52cf2650783f6b0ed343db110bc
1 /*
2 * Copyright (c) 2004 Gunnar Schmi Dt <gunnar@schmi-dt.de>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
18 #ifndef __kbstate_h__
19 #define __kbstate_h__
21 #include <plasma/kpanelapplet.h>
22 #include <QPushButton>
23 #include <q3ptrlist.h>
24 #include <QTimer>
25 //Added by qt3to4:
26 #include <QPixmap>
27 #include <QMouseEvent>
28 #include <QLabel>
29 #include <QTimerEvent>
30 #include <QGridLayout>
31 #include <QResizeEvent>
33 extern "C"
35 #include <X11/Xlib.h>
36 #include <X11/XKBlib.h>
39 class QLabel;
40 class QGridLayout;
41 class KMenu;
43 class StatusIcon : public QPushButton {
44 Q_OBJECT
45 public:
46 StatusIcon (const QString &text, QWidget *parent, const char *name=0);
47 ~StatusIcon ();
49 QSize minimumSizeHint () const;
51 typedef Q3PtrList<StatusIcon> IconList;
53 class TimeoutIcon : public StatusIcon {
54 Q_OBJECT
55 public:
56 TimeoutIcon (KInstance *instance, const QString &text,
57 const QString &featurename,
58 QWidget *parent, const char *name=0);
59 ~TimeoutIcon ();
61 void update ();
62 void setGlyth (const QString &glyth);
63 void setImage (const QString &name, int timeout = 0);
65 void drawButton (QPainter *p);
67 private:
68 QString glyth;
69 QString iconname;
70 QString featurename;
71 QPixmap pixmap;
72 QPixmap image;
73 QTimer timer;
74 KInstance *instance;
76 private slots:
77 void timeout ();
80 class KeyIcon : public StatusIcon {
81 Q_OBJECT
82 public:
83 KeyIcon (int keyId, KInstance *instance,
84 QWidget *parent, const char *name=0);
85 ~KeyIcon ();
86 void setState (bool latched, bool locked);
87 void drawButton (QPainter *p);
88 void updateImages ();
90 signals:
91 void stateChangeRequest (KeyIcon *source, bool latched, bool locked);
93 protected:
94 void resizeEvent(QResizeEvent*);
96 private slots:
97 void clickedSlot();
99 private:
100 QPixmap locked;
101 QPixmap latched;
102 QPixmap unlatched;
103 bool isLatched;
104 bool isLocked;
105 bool tristate;
106 int keyId;
107 KInstance *instance;
110 class MouseIcon : public StatusIcon {
111 Q_OBJECT
112 public:
113 MouseIcon (KInstance *instance, QWidget *parent, const char *name=0);
114 ~MouseIcon ();
115 void setState (int state);
116 void setActiveKey (int activekey);
117 void drawButton (QPainter *p);
118 void updateImages ();
120 protected:
121 void resizeEvent(QResizeEvent*);
123 private:
124 QPixmap mouse;
125 QPixmap leftSelected;
126 QPixmap middleSelected;
127 QPixmap rightSelected;
128 QPixmap leftDot;
129 QPixmap middleDot;
130 QPixmap rightDot;
131 QPixmap leftDotSelected;
132 QPixmap middleDotSelected;
133 QPixmap rightDotSelected;
134 int state, activekey;
135 KInstance *instance;
138 class KbStateApplet : public KPanelApplet {
139 Q_OBJECT
141 public:
142 KbStateApplet(const QString& configFile, Plasma::Type t = Plasma::Normal, int actions = 0,
143 QWidget *parent = 0, const char *name = 0);
144 ~KbStateApplet();
146 int widthForHeight(int height) const;
147 int heightForWidth(int width) const;
149 protected:
150 void mousePressEvent(QMouseEvent *e);
151 void timerEvent(QTimerEvent*);
152 void resizeEvent(QResizeEvent*);
153 bool x11Event (XEvent *);
155 public slots:
156 void about();
157 void configureAccessX();
158 void configureMouse();
159 void configureKeyboard();
160 void toggleModifier ();
161 void toggleLockkeys ();
162 void toggleMouse ();
163 void toggleAccessX ();
164 void paletteChanged();
166 void toggleFillSpace ();
168 private slots:
169 void setIconDim (int size);
170 void stateChangeRequest (KeyIcon *source, bool latched, bool locked);
172 private:
173 void loadConfig();
174 void saveConfig();
175 void layout();
177 int xkb_base_event_type;
179 KeyIcon *(icons[8]);
180 IconList modifiers;
181 IconList lockkeys;
182 TimeoutIcon *sticky;
183 TimeoutIcon *slow;
184 TimeoutIcon *bounce;
185 MouseIcon *mouse;
187 int state;
188 unsigned int accessxFeatures;
189 int size;
191 void initMasks();
193 void buildPopupMenu();
194 void updateMenu();
195 KMenu *popup;
196 KMenu *sizePopup;
197 KMenu *showPopup;
198 int modifierItem, lockkeysItem, mouseItem, accessxItem;
199 int fillSpaceItem;
200 bool showModifiers, showLockkeys, showMouse, showAccessX;
201 bool fillSpace;
203 KInstance *instance;
204 XkbDescPtr xkb;
207 #endif // __kbstate_h__