summaryrefslogtreecommitdiff
path: root/libopie2/opieui/okeyconfigwidget.h
Unidiff
Diffstat (limited to 'libopie2/opieui/okeyconfigwidget.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/okeyconfigwidget.h142
1 files changed, 121 insertions, 21 deletions
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h
index bcbb579..0d5d26f 100644
--- a/libopie2/opieui/okeyconfigwidget.h
+++ b/libopie2/opieui/okeyconfigwidget.h
@@ -1,102 +1,202 @@
1/*
2 * Copyright (C) 2004
3 * LGPL v2 zecke@handhelds.org
4 */
5
6
1#ifndef ODP_KEY_CONFIG_WIDGET_H 7#ifndef ODP_KEY_CONFIG_WIDGET_H
2#define ODP_KEY_CONFIG_WIDGET_H 8#define ODP_KEY_CONFIG_WIDGET_H
3 9
4#include <opie2/oconfig.h> 10#include <opie2/oconfig.h>
11#include <opie2/odevice.h>
5 12
6#include <qstring.h> 13#include <qstring.h>
7#include <qpixmap.h> 14#include <qpixmap.h>
8#include <qbytearray.h> 15#include <qbytearray.h>
9#include <qhbox.h> 16#include <qhbox.h>
10#include <qvaluelist.h> 17#include <qvaluelist.h>
11 18
12class QKeyEvent; 19class QKeyEvent;
13 20
14namespace Opie { 21namespace Opie {
15namespace Ui { 22namespace Ui {
16 23
24
25/**
26 * \brief small class representing a Key with possible modifiers
27 * This class holds information about key code and possible
28 * modifier state. That is the lowest level of the key input
29 * functions.
30 * There are also static methods to get special keys.
31 * OKeyPair will be used with \see OKeyConfigItem
32 *
33 * @since 1.2
34 */
35class OKeyPair {
36public:
37 typedef QValueList<OKeyPair> OKeyPairList;
38 OKeyPair( int key = -1, int modifier = -1);
39 ~OKeyPair();
40
41 bool operator==( const OKeyPair& );
42 bool operator!=( const OKeyPair& );
43
44 bool isEmpty()const;
45
46 int keycode()const;
47 int modifier()const;
48
49 void setKeycode( int );
50 void setModifier( int );
51
52 static OKeyPair returnKey();
53 static OKeyPair leftArrowKey();
54 static OKeyPair rightArrowKey();
55 static OKeyPair upArrowKey();
56 static OKeyPair downArrowKey();
57 static OKeyPair emptyKey();
58 static OKeyPairList hardwareKeys();
59
60private:
61 int m_key = -1;
62 int m_mod = -1;
63 class Private;
64 Private* d;
65};
66
67/**
68 * A class to represent an OKeyPair.
69 * It consists out of a Text exposed to the user, Config Key Item,
70 * Pixmap, A default OKeyPair and the set OKeyPair.
71 * You can also pass an id to it
72 *
73 * @since 1.1.2
74 */
17class OKeyConfigItem { 75class OKeyConfigItem {
18 friend class OKeyConfigManager; 76 friend class OKeyConfigManager;
19public: 77public:
20 typedef QValueList<OKeyConfigItem> OKeyConfigItemList; 78 typedef QValueList<OKeyConfigItem> OKeyConfigItemList;
21 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), 79 OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(),
22 const QPixmap& symbol = QPixmap(), 80 const QPixmap& symbol = QPixmap(),
23 int key = 0, int mod = 0, 81 int id = -1,
24 int default_key = 0, int default_modified = 0 ); 82 const OKeyPair& set = OKeyPair::emptyKey(),
83 const OKeyPair& def = OKeyPair::emptyKey() );
84 OKeyConfigItem( const Opie::Core::ODeviceButton& );
25 ~OKeyConfigItem(); 85 ~OKeyConfigItem();
26 86
87 bool operator==( const OKeyConfigItem& );
88 bool operator!=( const OKeyConfigItem& );
89
27 QString text()const; 90 QString text()const;
28 QPixmap pixmap()const; 91 QPixmap pixmap()const;
29 int key()const; 92 int id()const;
30 int modifier()const; 93
31 int defaultKey()const; 94 OKeyPair keyPair()const;
32 int defaultModifier()const; 95 OKeyPair defaultKeyPair()const;
96 QCString configKey()const;
33 97
34 void setText( const QString& text ); 98 void setText( const QString& text );
35 void setPixmap( const QPixmap& ); 99 void setPixmap( const QPixmap& );
36 void setKey( int ); 100 void setKeyPair( const OKeyPair& );
37 void setModied( int ); 101 void setDefaultKeyPair( const OKeyPair& );
38 void setDefaultKey( int );
39 void setDefaultModifier( int );
40 102
41 bool isConfigured()const;
42 bool isEmpty()const; 103 bool isEmpty()const;
104
105protected:
106 void setId( int id );
107 void setConfigKey( const QCString& );
108
43private: 109private:
110 int m_id;
44 QString m_text; 111 QString m_text;
45 QCString m_config; 112 QCString m_config;
46 QPixmap m_pix; 113 QPixmap m_pix;
47 int m_key; 114 OKeyPair m_key;
48 int m_mod; 115 OKeyPair m_def;
49 int m_defKey;
50 int m_defMod;
51 class Private; 116 class Private;
52 Private *d; 117 Private *d;
53}; 118};
54 119
55 120
56class OKeyConfig : public QObject { 121
122/**
123 * \brief A manager to load and save Key Actions and get notified
124 * This is the Manager for KeyActions.
125 * You can say from which config and group to read data, to grab the
126 * keyboard to handle hardware keys, you can supply a blacklist of
127 * keys which should not be used by allowed to be used.
128 * You can even pass this manager to a Widget to do the configuration for you.
129 * You need to add OKeyConfigItem for your keys and then issue a load() to
130 * read the Key information.
131 * You can either handle the QKeyEvent yourself and ask this class if it is
132 * handled by your action and let give you the action. Or you can install
133 * the event filter and get a signal.
134 *
135 * @since 1.1.2
136 */
137class OKeyConfigManager : public QObject {
57 Q_OBJECT 138 Q_OBJECT
58public: 139public:
59 OKeyConfig(Opie::Core::OConfig *conf = 0, bool grabkeyboard); 140 OKeyConfigManager(Opie::Core::OConfig *conf = 0,
60 ~OKeyConfig(); 141 const QString& group = QString::null,
142 OKeyPairList &block = OKeyPairList(),
143 bool grabkeyboard = false, QObject *= 0,
144 const char* name = 0 );
145 ~OKeyConfigManager();
61 146
62 void load(); 147 void load();
63 void save(); 148 void save();
64 149
65 OKeyConfigItem handleKeyEvent( QKeyEvent* ); 150 OKeyConfigItem handleKeyEvent( QKeyEvent* );
66 QString handleKeyEventString( QKeyEvent* ); 151 QString handleKeyEventString( QKeyEvent* );
67 152
68 void addKeyConfig( const OKeyConfigItem& ); 153 void addKeyConfig( const OKeyConfigItem& );
69 void removeKeyConfig( const OKeyConfigItem& ); 154 void removeKeyConfig( const OKeyConfigItem& );
70 155
156 void addBlackList( const OKeyPair& );
157 void removeBlackList( const OKeyPair& );
158 void clearBlackList();
159 OKeyPairList blackList()const;
160
71 void handleWidget( QWidget* ); 161 void handleWidget( QWidget* );
162
163 bool eventFilter( QObject*, QEvent* );
72signals: 164signals:
73 void keyConfigChanged( OKeyConfig* ); 165 void keyConfigChanged( Opie::Ui::OKeyConfigManager* );
74 void actionActivated( QWidget*, QKeyEvent*, const OKeyConfigItem& ); 166 void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& );
75 167
76private: 168private:
169 OKeyPairList m_blackKeys;
77 OKeyConfigItemList m_keys; 170 OKeyConfigItemList m_keys;
78 QValueList<QWidget*> m_widgets; 171 QValueList<QWidget*> m_widgets;
172 Opie::Core::OConfig *m_conf;
173 QString m_group;
174 bool m_grab : 1;
79 class Private; 175 class Private;
80 Private *d; 176 Private *d;
81}; 177};
82 178
83 179
84class OKeyConfigWidget : public QHBox { 180class OKeyConfigWidget : public QHBox {
85 Q_OBJECT 181 Q_OBJECT
86public: 182public:
87 enum ChangeMode { Imediate, Queu }; 183 enum ChangeMode { Imediate, Queu };
88 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 184 OKeyConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
89 OKeyConfigWidget( OKeyConfig *, QWidget* parent = 0, const char* = 0, WFlags = 0 ); 185 OKeyConfigWidget( OKeyConfigManager *, QWidget* parent = 0, const char* = 0, WFlags = 0 );
90 ~OKeyConfigWidget(); 186 ~OKeyConfigWidget();
91 187
92 void setChangeMode( enum ChangeMode ); 188 void setChangeMode( enum ChangeMode );
93 ChangeMode changeMode()const; 189 ChangeMode changeMode()const;
94 190
191 void setKeyConfig( OKeyConfigManager* );
192
95 void reload(); 193 void reload();
194 void save();
96private: 195private:
196 OKeyConfigManager* m_manager;
97 class Private; 197 class Private;
98 Private *d; 198 Private *d;
99}; 199};
100 200
101} 201}
102} 202}