summaryrefslogtreecommitdiff
path: root/libopie2/opieui/okeyconfigwidget.cpp
Unidiff
Diffstat (limited to 'libopie2/opieui/okeyconfigwidget.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.cpp408
1 files changed, 408 insertions, 0 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp
new file mode 100644
index 0000000..d52a55f
--- a/dev/null
+++ b/libopie2/opieui/okeyconfigwidget.cpp
@@ -0,0 +1,408 @@
1#include "okeyconfigwidget.h"
2
3
4
5
6using namespace Opie::Ui;
7
8
9/**
10 * The default Constructor of a OKeyPair.
11 * A Key and a Modifier ( Alt/Shift/Ctrl )
12 * needs to be supplied.
13 * Use Qt::Key for the information.
14 * The default arguments create an Empty OKeyPair. If you
15 * want to get an empty OKeyPair use the static method for getting
16 * the emptyKey()
17 *
18 * @see OKeyPair OKeyPair::emptyKey()
19 */
20OKeyPair::OKeyPair( int key, int mod )
21 : m_key( key ), m_mod( mod )
22{}
23
24/**
25 * The destructor
26 */
27OKeyPair::~OKeyPair() {}
28
29
30/**
31 * Is this OKeyPair empty/valid?
32 */
33bool OKeyPair::isEmpty()const {
34 return ( ( m_key == -1 )&& ( m_mod == -1 ) );
35}
36
37/**
38 * get the keycode for this OKeyPair. The Key relates to Qt::Key.
39 *
40 * @see Qt::Key
41 * @see setKey
42 */
43int OKeyPair::keycode()const {
44 return m_key;
45}
46
47/**
48 * get the modifier key for this OKeyPair. The Modifier State relates
49 * to the Qt::Modifier
50 *
51 * @see Qt::Modifier
52 * @see setModifier
53 */
54int OKeyPair::modifier()const {
55 return m_mod;
56}
57
58
59/**
60 * Set the keycode
61 * @param key The Keycode to set
62 *
63 * @see keycode()
64 * @see Qt::Key
65 */
66void OKeyPair::setKeycode( int key ) {
67
68}
69
70/**
71 * Set the modifier key
72 *
73 * @param the Modifier key
74 * @see Qt::Modifier
75 * @see modifier()
76 */
77void OKeyPair::setModifier( int mod ) {
78
79}
80
81/**
82 * Return an OKeyPair for the Return Key without any modifier.
83 */
84OKeyPair OKeyPair::returnKey() {
85 return OKeyPair( Qt::Key_Return, 0 );
86}
87
88/**
89 * Return an OKeyPair for the Left Arrow Key
90 * without any modifier Key
91 */
92OKeyPair OKeyPair::leftArrowKey() {
93 return OKeyPair( Qt::Key_Left, 0 );
94}
95
96/**
97 * Return an OKeyPair for the Right Arrow Key
98 * without any modifier Key
99 */
100OKeyPair OKeyPair::rightArrowKey() {
101 return OKeyPair( Qt::Key_Right, 0 );
102}
103
104/**
105 * Return an OKeyPair for the Up Arrow Key
106 * without any modifier Key
107 */
108OKeyPair OKeyPair::upArrowKey() {
109 return OKeyPair( Qt::Key_Up, 0 );
110}
111
112/**
113 * Return an OKeyPair for the Down Arrow Key
114 * without any modifier Key
115 */
116OKeyPair OKeyPair::downArrowKey() {
117 return OKeyPair( Qt::Key_Down, 0 );
118}
119
120/**
121 * Return an Empty OKeyPair
122 */
123OKeyPair OKeyPair::emptyKey() {
124 return OKeyPair;
125}
126
127/**
128 * This functions uses the Opie::Core::ODevice::buttons
129 * for OKeyPairList
130 *
131 * @see Opie::Core::ODevice
132 * @see Opie::Core::ODeviceButton
133 * @see Opie::Core::ODevice::button
134 */
135OKeyPairList OKeyPair::hardwareKeys() {
136 const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons();
137 OKeyPairList lst;
138
139 for ( QValueList<Opie::Core::ODeviceButton>::Iterator it = but.begin();
140 it != but.end(); ++it )
141 lst.append( OKeyPair( (*it).keycode(), 0 ) );
142
143
144 return lst;
145}
146
147/**
148 * The normal Constructor to create a OKeyConfigItem
149 *
150 * You can set the the key paramater of this item but if
151 * you use this item with the OKeyConfigManager your setting
152 * will be overwritten.
153 *
154 * @param text The text exposed to the user
155 * @param config_key The key used in the config
156 * @param pix A Pixmap associated with this Item
157 * @param key The OKeyPair used
158 * @param def The OKeyPair used as default
159 *
160 */
161OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key,
162 const QPixmap& pix, int id, const OKeyPair& def,
163 const OKeyPair& key)
164 : m_text( text ), m_config( config_key ), m_pix( pix ),
165 m_id( id ), m_def( def ), m_key( key ) {}
166
167/**
168 * A special Constructor for converting from an Opie::Core::ODeviceButton
169 * delivered by Opie::Core::ODevice::buttons()
170 * There is no Config Key set and both default key and key are set
171 * to Opie::Core::ODeviceButton::keycode() and 0 to modifier
172 *
173 * @see Opie::Core::ODevice
174 * @see Opie::Core::ODeviceButton
175 * @see Opie::Core::ODevice::buttons()
176 */
177OKeyConfigItem::OKeyConfigItem( Opie::Core::ODeviceButton& b )
178 : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 )
179 m_def( OKeyPair( b.keycode(), 0 ) ), m_key( OKeyPair( b.keycode(), 0 ) )
180{}
181
182
183/**
184 * Destructor
185 */
186OKeyConfigItem::~OKeyConfigItem() {}
187
188
189/**
190 * The text exposed to the user
191 *
192 * @see setText
193 */
194QString OKeyConfigItem::text()const {
195 return m_text;
196}
197
198/**
199 * The pixmap shown to the user for your action/key
200 *
201 * @see setPixmap
202 */
203QPixmap OKeyConfigItem::pixmap()const {
204 return m_pix;
205}
206
207/**
208 * Return the OKeyPair this OKeyConfigItem is configured for.
209 *
210 * @see setKeyPair
211 */
212OKeyPair OKeyConfigItem::keyPair()const {
213 return m_key;
214}
215
216/**
217 * Return the default OKeyPair
218 * @see setDefaultKeyPair
219 */
220OKeyPair OKeyConfigItem::defaultKeyPair()const {
221 return m_def;
222}
223
224
225/**
226 * Return the Id you assigned to this item.
227 * setting is only possible by the constructor
228 */
229int OKeyConfigItem::id()const{
230 return m_id;
231}
232
233/**
234 * reutrn the Config Key. Setting it is only possible
235 * by the constructor
236 */
237QCString OKeyConfigItem::configKey()const {
238 return m_config;
239}
240
241/**
242 * Set the text
243 *
244 * @param text Set the Text of this Action to text
245 * @see text()
246 */
247void OKeyConfigItem::setText( const QString& text ) {
248 m_text = text;
249}
250
251/**
252 * Set the pixmap of this action
253 *
254 * @param pix The Pixmap to set
255 * @see pixmap()
256 */
257void OKeyConfigItem::setPixmap( const QPixmap& pix ) {
258 m_pix = pix;
259}
260
261/**
262 * Set the KeyPair the OKeyConfigItem uses.
263 * Your set Key could get overwritten if you use
264 * the manager or GUI to configure the key
265 *
266 * @param key Set the OKeyPair used
267 * @see keyPair()
268 */
269void OKeyConfigItem::setKeyPair( const OKeyPair& key) {
270 m_key = key;
271}
272
273/**
274 * Set the default KeyPair.
275 *
276 * @param key The default keypair
277 * @see defaultKeyPair()
278 */
279void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) {
280 m_def = key;
281}
282
283/**
284 * @internal
285 */
286void OKeyConfigItem::setConfigKey( const QCString& str) {
287 m_config = str;
288 m_config.detach();
289}
290
291/**
292 * @internal
293 */
294void OKeyConfigItem::setId( int id ) {
295 m_id = id;
296}
297
298/**
299 * If the item is not configured isEmpty() will return true
300 * It is empty if no text is present and no default
301 * and no configured key
302 */
303bool OKeyConfigItem::isEmpty()const {
304 if ( !m_def.isEmpty() ) return false;
305 if ( !m_key.isEmpty() ) return false;
306 if ( !m_text.isEmpty() ) return false;
307
308 return true;
309}
310
311/**
312 * \brief c'tor
313 * The Constructor for a OKeyConfigManager
314 *
315 * You can use this manager in multiple ways. Either make it handle
316 * QKeyEvents
317 *
318 * \code
319 * Opie::Core::Config conf = oApp->config();
320 * Opie::Ui::OKeyPairList blackList;
321 * blackList.append(Opie::Ui::OKeyPair::leftArrowKey());
322 * blackList.append(Opie::Ui::OKeyPair::rightArrowKey());
323 * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList,
324 * false);
325 * QListView *view = new QListView();
326 * manager->handleWidget(view);
327 * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey());
328 * manager->load();
329 *
330 * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)),
331 * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)));
332 *
333 * ....
334 *
335 * void update(){
336 * QDialog diag(true);
337 * QHBoxLayout *lay = new QHBoxLayout(&diag);
338 * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag);
339 * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu);
340 * lay->addWidget(wid);
341 * if(QPEApplication::execDialog( &diag)== QDialog::Accept){
342 * wid->save();
343 * }
344 * }
345 *
346 * ....
347 * MyListView::keyPressEvent( QKeyEvent* e ){
348 * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e);
349 * if(!item.isEmpty() ){
350 * switch(item.id()){
351 * case My_Delete_Key:
352 * break;
353 * }
354 * }
355 * }
356 *
357 * \endcode
358 *
359 * @param conf The Config where the KeySetting should be stored
360 * @param group The group where the KeySetting will be stored
361 * @param black Which keys shouldn't be allowed to handle
362 * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons
363 * @param par The parent/owner of this manager
364 * @param name The name of this object
365 */
366OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf,
367 const QString& group,
368 OKeyPairList black,
369 bool grabkeyboard, QObject* par,
370 const char* name)
371 : QObject( par, name ), m_conf( conf ), m_group( group ),
372 m_blackKeys( black ), m_grab( grabkeyboard )
373{}
374
375
376/**
377 * Destructor
378 */
379OKeyConfigWidget::~OKeyConfigWidget() {}
380
381/**
382 * Load the Configuration from the OConfig
383 * If a Key is restricted but was in the config we will
384 * make the empty
385 * We will change the group of the OConfig Item!
386 */
387void OKeyConfigWidget::load() {
388 m_conf->setGroup( m_group );
389
390 /*
391 * Read each item
392 */
393 int key, mod;
394 for( OKeyConfigItemList::Iterator it = m_keys.begin();
395 it != m_keys.end(); ++it ) {
396 key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() );
397 mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() );
398 (*it).setKeyPair( OKeyPair(key, mod) );
399 }
400}
401
402/**
403 * We will save the current configuration
404 * to the OConfig. We will change the group.
405 */
406void OKeyConfigWidget::save() {
407
408}