author | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-13 14:53:58 (UTC) |
commit | b51d88d7b0b517b71ae3b59d8228335f38ca9fc7 (patch) (unidiff) | |
tree | 302377973a897934c944c7a126e5e0a510694979 | |
parent | c4c842558e1457f64d43b237f24f6ea1a4f9d76b (diff) | |
download | opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.zip opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.gz opie-b51d88d7b0b517b71ae3b59d8228335f38ca9fc7.tar.bz2 |
Split the KeyConfig Manager and Widget into Ui and Core parts
Adjust the only user...
Don't add a 2nd example to core but mention the one for the classes
in opieui/okeyconfigwidget
-rw-r--r-- | libopie2/examples/opiecore/okeyconfigmanager/README | 1 | ||||
-rw-r--r-- | libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp | 30 | ||||
-rw-r--r-- | libopie2/examples/opieui/okeyconfigwidget/testwidget.h | 10 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.cpp | 733 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager.h | 205 | ||||
-rw-r--r-- | libopie2/opiecore/okeyconfigmanager_p.h | 9 | ||||
-rw-r--r-- | libopie2/opiecore/opiecore.pro | 2 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.cpp | 742 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget.h | 199 | ||||
-rw-r--r-- | libopie2/opieui/okeyconfigwidget_p.h | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 28 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.cpp | 26 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.cpp | 22 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageview.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 4 |
17 files changed, 1046 insertions, 1005 deletions
diff --git a/libopie2/examples/opiecore/okeyconfigmanager/README b/libopie2/examples/opiecore/okeyconfigmanager/README new file mode 100644 index 0000000..327b7c2 --- a/dev/null +++ b/libopie2/examples/opiecore/okeyconfigmanager/README | |||
@@ -0,0 +1 @@ | |||
See opieui/okeyconfigwidget for an example of possible usage \ No newline at end of file | |||
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp index 10b52f9..5c7bac2 100644 --- a/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.cpp | |||
@@ -29,7 +29,7 @@ public: | |||
29 | private slots: | 29 | private slots: |
30 | void slotClicked(); | 30 | void slotClicked(); |
31 | private: | 31 | private: |
32 | Opie::Ui::OKeyConfigManager *m_manager; | 32 | Opie::Core::OKeyConfigManager *m_manager; |
33 | }; | 33 | }; |
34 | 34 | ||
35 | 35 | ||
@@ -76,23 +76,23 @@ TestMainWindow::TestMainWindow( QWidget* parent, const char* slot, WFlags fl ) | |||
76 | m_config = new Opie::Core::OConfig( "test_config_foo" ); | 76 | m_config = new Opie::Core::OConfig( "test_config_foo" ); |
77 | 77 | ||
78 | /* generate the black list */ | 78 | /* generate the black list */ |
79 | Opie::Ui::OKeyPair::List blackList; | 79 | Opie::Core::OKeyPair::List blackList; |
80 | blackList.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 80 | blackList.append( Opie::Core::OKeyPair::leftArrowKey() ); |
81 | blackList.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 81 | blackList.append( Opie::Core::OKeyPair::rightArrowKey() ); |
82 | blackList.append( Opie::Ui::OKeyPair::downArrowKey() ); | 82 | blackList.append( Opie::Core::OKeyPair::downArrowKey() ); |
83 | blackList.append( Opie::Ui::OKeyPair::upArrowKey() ); | 83 | blackList.append( Opie::Core::OKeyPair::upArrowKey() ); |
84 | 84 | ||
85 | m_manager = new Opie::Ui::OKeyConfigManager( m_config, "Key Group", | 85 | m_manager = new Opie::Core::OKeyConfigManager( m_config, "Key Group", |
86 | blackList, false, this, "Key Manager" ); | 86 | blackList, false, this, "Key Manager" ); |
87 | 87 | ||
88 | m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), | 88 | m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Delete Action" ), "delete_key", QPixmap(), |
89 | 10, Opie::Ui::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this, | 89 | 10, Opie::Core::OKeyPair( Qt::Key_D, Qt::ShiftButton ), this, |
90 | SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); | 90 | SLOT(slotDelete(QWidget*,QKeyEvent*)) ) ); |
91 | m_manager->addKeyConfig( Opie::Ui::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(), | 91 | m_manager->addKeyConfig( Opie::Core::OKeyConfigItem( tr( "Show Action" ), "show_key", QPixmap(), |
92 | 11, Opie::Ui::OKeyPair( Qt::Key_S, Qt::AltButton ) ) ); | 92 | 11, Opie::Core::OKeyPair( Qt::Key_S, Qt::AltButton ) ) ); |
93 | 93 | ||
94 | connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | 94 | connect(m_manager, SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), |
95 | this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem&)) ); | 95 | this, SLOT(slotAction(QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem&)) ); |
96 | // when commenting the line below out the keyPressEvent will work | 96 | // when commenting the line below out the keyPressEvent will work |
97 | m_manager->handleWidget( this ); | 97 | m_manager->handleWidget( this ); |
98 | m_manager->load(); | 98 | m_manager->load(); |
@@ -103,7 +103,7 @@ TestMainWindow::~TestMainWindow() { | |||
103 | delete m_config; | 103 | delete m_config; |
104 | } | 104 | } |
105 | 105 | ||
106 | Opie::Ui::OKeyConfigManager* TestMainWindow::manager() { | 106 | Opie::Core::OKeyConfigManager* TestMainWindow::manager() { |
107 | return m_manager; | 107 | return m_manager; |
108 | } | 108 | } |
109 | 109 | ||
@@ -121,7 +121,7 @@ void TestMainWindow::slotDelete( QWidget* wid, QKeyEvent* ev ) { | |||
121 | qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); | 121 | qWarning( "Slot Delete %d %d %d", wid, ev->key(), ev->state() ); |
122 | } | 122 | } |
123 | 123 | ||
124 | void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Ui::OKeyConfigItem& item) { | 124 | void TestMainWindow::slotAction( QWidget* wid, QKeyEvent* ev, const Opie::Core::OKeyConfigItem& item) { |
125 | qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() ); | 125 | qWarning( "Slot Action %d %d %d %s %d", wid, ev->key(), ev->state(), item.text().latin1(), item.id() ); |
126 | } | 126 | } |
127 | 127 | ||
diff --git a/libopie2/examples/opieui/okeyconfigwidget/testwidget.h b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h index b95c225..6ecb346 100644 --- a/libopie2/examples/opieui/okeyconfigwidget/testwidget.h +++ b/libopie2/examples/opieui/okeyconfigwidget/testwidget.h | |||
@@ -8,12 +8,12 @@ | |||
8 | namespace Opie{ | 8 | namespace Opie{ |
9 | namespace Ui{ | 9 | namespace Ui{ |
10 | class OTabWidget; | 10 | class OTabWidget; |
11 | class OKeyConfigManager; | ||
12 | class OListView; | 11 | class OListView; |
13 | class OKeyConfigItem; | ||
14 | } | 12 | } |
15 | namespace Core { | 13 | namespace Core { |
16 | class OConfig; | 14 | class OConfig; |
15 | class OKeyConfigManager; | ||
16 | class OKeyConfigItem; | ||
17 | } | 17 | } |
18 | } | 18 | } |
19 | class QKeyEvent; | 19 | class QKeyEvent; |
@@ -26,15 +26,15 @@ public: | |||
26 | TestMainWindow(QWidget* parent, const char*, WFlags fl ); | 26 | TestMainWindow(QWidget* parent, const char*, WFlags fl ); |
27 | ~TestMainWindow(); | 27 | ~TestMainWindow(); |
28 | 28 | ||
29 | Opie::Ui::OKeyConfigManager *manager(); | 29 | Opie::Core::OKeyConfigManager *manager(); |
30 | protected: | 30 | protected: |
31 | void keyPressEvent( QKeyEvent* ); | 31 | void keyPressEvent( QKeyEvent* ); |
32 | private slots: | 32 | private slots: |
33 | void slotDelete( QWidget*, QKeyEvent* ); | 33 | void slotDelete( QWidget*, QKeyEvent* ); |
34 | void slotAction( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | 34 | void slotAction( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); |
35 | private: | 35 | private: |
36 | Opie::Core::OConfig *m_config; | 36 | Opie::Core::OConfig *m_config; |
37 | Opie::Ui::OKeyConfigManager *m_manager; | 37 | Opie::Core::OKeyConfigManager *m_manager; |
38 | }; | 38 | }; |
39 | 39 | ||
40 | #endif | 40 | #endif |
diff --git a/libopie2/opiecore/okeyconfigmanager.cpp b/libopie2/opiecore/okeyconfigmanager.cpp new file mode 100644 index 0000000..e6055e0 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager.cpp | |||
@@ -0,0 +1,733 @@ | |||
1 | #include "okeyconfigmanager.h" | ||
2 | |||
3 | #include "okeyconfigmanager_p.h" | ||
4 | |||
5 | namespace Opie { | ||
6 | namespace Core { | ||
7 | namespace Internal { | ||
8 | /* | ||
9 | * the virtual and hardware key events have both issues... | ||
10 | */ | ||
11 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
12 | key = e->key(); | ||
13 | mod = e->state(); | ||
14 | /* | ||
15 | * virtual keyboard | ||
16 | * else change the button mod only | ||
17 | */ | ||
18 | if ( key == 0 ) { | ||
19 | key = e->ascii(); | ||
20 | if ( key > 96 && key < 123) | ||
21 | key -= 32; | ||
22 | }else{ | ||
23 | int new_mod = 0; | ||
24 | if ( mod & 256 ) | ||
25 | new_mod |= Qt::ShiftButton; | ||
26 | else if ( mod & 512 ) | ||
27 | new_mod |= Qt::ControlButton; | ||
28 | else if ( mod & 1024 ) | ||
29 | new_mod |= Qt::AltButton; | ||
30 | |||
31 | mod = new_mod == 0? mod : new_mod; | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * The default Constructor of a OKeyPair. | ||
38 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | ||
39 | * needs to be supplied. | ||
40 | * Use Qt::Key for the information. | ||
41 | * The default arguments create an Empty OKeyPair. If you | ||
42 | * want to get an empty OKeyPair use the static method for getting | ||
43 | * the emptyKey() | ||
44 | * | ||
45 | * @see OKeyPair OKeyPair::emptyKey() | ||
46 | */ | ||
47 | OKeyPair::OKeyPair( int key, int mod ) | ||
48 | : m_key( key ), m_mod( mod ) | ||
49 | {} | ||
50 | |||
51 | /** | ||
52 | * The destructor | ||
53 | */ | ||
54 | OKeyPair::~OKeyPair() {} | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Is this OKeyPair empty/valid? | ||
59 | */ | ||
60 | bool OKeyPair::isEmpty()const { | ||
61 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | ||
66 | * | ||
67 | * @see Qt::Key | ||
68 | * @see setKey | ||
69 | */ | ||
70 | int OKeyPair::keycode()const { | ||
71 | return m_key; | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * get the modifier key for this OKeyPair. The Modifier State relates | ||
76 | * to the Qt::ButtonState | ||
77 | * | ||
78 | * @see Qt::ButtonState | ||
79 | * @see setModifier | ||
80 | */ | ||
81 | int OKeyPair::modifier()const { | ||
82 | return m_mod; | ||
83 | } | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Set the keycode | ||
88 | * @param key The Keycode to set | ||
89 | * | ||
90 | * @see keycode() | ||
91 | * @see Qt::Key | ||
92 | */ | ||
93 | void OKeyPair::setKeycode( int key ) { | ||
94 | m_key = key; | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Set the modifier key | ||
99 | * | ||
100 | * @param the Modifier key | ||
101 | * @see Qt::ButtonState | ||
102 | * @see modifier() | ||
103 | */ | ||
104 | void OKeyPair::setModifier( int mod ) { | ||
105 | m_mod = mod; | ||
106 | } | ||
107 | |||
108 | /** | ||
109 | * Return an OKeyPair for the Return Key without any modifier. | ||
110 | */ | ||
111 | OKeyPair OKeyPair::returnKey() { | ||
112 | return OKeyPair( Qt::Key_Return, 0 ); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * Return an OKeyPair for the Left Arrow Key | ||
117 | * without any modifier Key | ||
118 | */ | ||
119 | OKeyPair OKeyPair::leftArrowKey() { | ||
120 | return OKeyPair( Qt::Key_Left, 0 ); | ||
121 | } | ||
122 | |||
123 | /** | ||
124 | * Return an OKeyPair for the Right Arrow Key | ||
125 | * without any modifier Key | ||
126 | */ | ||
127 | OKeyPair OKeyPair::rightArrowKey() { | ||
128 | return OKeyPair( Qt::Key_Right, 0 ); | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * Return an OKeyPair for the Up Arrow Key | ||
133 | * without any modifier Key | ||
134 | */ | ||
135 | OKeyPair OKeyPair::upArrowKey() { | ||
136 | return OKeyPair( Qt::Key_Up, 0 ); | ||
137 | } | ||
138 | |||
139 | /** | ||
140 | * Return an OKeyPair for the Down Arrow Key | ||
141 | * without any modifier Key | ||
142 | */ | ||
143 | OKeyPair OKeyPair::downArrowKey() { | ||
144 | return OKeyPair( Qt::Key_Down, 0 ); | ||
145 | } | ||
146 | |||
147 | /** | ||
148 | * Return an Empty OKeyPair | ||
149 | */ | ||
150 | OKeyPair OKeyPair::emptyKey() { | ||
151 | return OKeyPair(); | ||
152 | } | ||
153 | |||
154 | /** | ||
155 | * This functions uses the Opie::Core::ODevice::buttons | ||
156 | * for OKeyPairList | ||
157 | * | ||
158 | * @see Opie::Core::ODevice | ||
159 | * @see Opie::Core::ODeviceButton | ||
160 | * @see Opie::Core::ODevice::button | ||
161 | */ | ||
162 | OKeyPair::List OKeyPair::hardwareKeys() { | ||
163 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | ||
164 | OKeyPair::List lst; | ||
165 | |||
166 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | ||
167 | it != but.end(); ++it ) | ||
168 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | ||
169 | |||
170 | |||
171 | return lst; | ||
172 | } | ||
173 | |||
174 | /** | ||
175 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
176 | * @see operator!= | ||
177 | */ | ||
178 | bool OKeyPair::operator==( const OKeyPair& pair)const { | ||
179 | if ( m_key != pair.m_key ) return false; | ||
180 | if ( m_mod != pair.m_mod ) return false; | ||
181 | |||
182 | return true; | ||
183 | } | ||
184 | |||
185 | /** | ||
186 | * Not equal operator. calls the equal operator internally | ||
187 | */ | ||
188 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | ||
189 | return !(*this == pair); | ||
190 | } | ||
191 | |||
192 | |||
193 | /** | ||
194 | * The normal Constructor to create a OKeyConfigItem | ||
195 | * | ||
196 | * You can set the the key paramater of this item but if | ||
197 | * you use this item with the OKeyConfigManager your setting | ||
198 | * will be overwritten. | ||
199 | * You can also specify a QObject and slot which sould get called | ||
200 | * once this item is activated. This slot only works if you | ||
201 | * use the OKeyConfigManager. | ||
202 | * The actual Key is read by load() | ||
203 | * | ||
204 | * \code | ||
205 | * void MySlot::create(){ | ||
206 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
207 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
208 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
209 | * } | ||
210 | * \endcode | ||
211 | * | ||
212 | * @param text The text exposed to the user | ||
213 | * @param config_key The key used in the config | ||
214 | * @param pix A Pixmap associated with this Item | ||
215 | * @param def The OKeyPair used as default | ||
216 | * @param caller The object where the slot exists | ||
217 | * @param slot The slot which should get called | ||
218 | * | ||
219 | */ | ||
220 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | ||
221 | const QPixmap& pix, int id, const OKeyPair& def, | ||
222 | QObject *caller, | ||
223 | const char* slot ) | ||
224 | : m_text( text ), m_config( config_key ), m_pix( pix ), | ||
225 | m_id( id ), m_def( def ), | ||
226 | m_obj( caller ), m_str( slot ) {} | ||
227 | |||
228 | /** | ||
229 | * A special Constructor for converting from an Opie::Core::ODeviceButton | ||
230 | * delivered by Opie::Core::ODevice::buttons() | ||
231 | * There is no Config Key set and both default key and key are set | ||
232 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | ||
233 | * | ||
234 | * @see Opie::Core::ODevice | ||
235 | * @see Opie::Core::ODeviceButton | ||
236 | * @see Opie::Core::ODevice::buttons() | ||
237 | */ | ||
238 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | ||
239 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | ||
240 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | ||
241 | {} | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Destructor | ||
246 | */ | ||
247 | OKeyConfigItem::~OKeyConfigItem() {} | ||
248 | |||
249 | |||
250 | /** | ||
251 | * The text exposed to the user | ||
252 | * | ||
253 | * @see setText | ||
254 | */ | ||
255 | QString OKeyConfigItem::text()const { | ||
256 | return m_text; | ||
257 | } | ||
258 | |||
259 | /** | ||
260 | * The pixmap shown to the user for your action/key | ||
261 | * | ||
262 | * @see setPixmap | ||
263 | */ | ||
264 | QPixmap OKeyConfigItem::pixmap()const { | ||
265 | return m_pix; | ||
266 | } | ||
267 | |||
268 | /** | ||
269 | * Return the OKeyPair this OKeyConfigItem is configured for. | ||
270 | * | ||
271 | * @see setKeyPair | ||
272 | */ | ||
273 | OKeyPair OKeyConfigItem::keyPair()const { | ||
274 | return m_key; | ||
275 | } | ||
276 | |||
277 | /** | ||
278 | * Return the default OKeyPair | ||
279 | * @see setDefaultKeyPair | ||
280 | */ | ||
281 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | ||
282 | return m_def; | ||
283 | } | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Return the Id you assigned to this item. | ||
288 | * setting is only possible by the constructor | ||
289 | */ | ||
290 | int OKeyConfigItem::id()const{ | ||
291 | return m_id; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * reutrn the Config Key. Setting it is only possible | ||
296 | * by the constructor | ||
297 | */ | ||
298 | QCString OKeyConfigItem::configKey()const { | ||
299 | return m_config; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * @internal | ||
304 | */ | ||
305 | QObject* OKeyConfigItem::object()const{ | ||
306 | return m_obj; | ||
307 | } | ||
308 | |||
309 | /** | ||
310 | * @internal | ||
311 | */ | ||
312 | QCString OKeyConfigItem::slot()const { | ||
313 | return m_str; | ||
314 | } | ||
315 | |||
316 | /** | ||
317 | * Set the text | ||
318 | * | ||
319 | * @param text Set the Text of this Action to text | ||
320 | * @see text() | ||
321 | */ | ||
322 | void OKeyConfigItem::setText( const QString& text ) { | ||
323 | m_text = text; | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Set the pixmap of this action | ||
328 | * | ||
329 | * @param pix The Pixmap to set | ||
330 | * @see pixmap() | ||
331 | */ | ||
332 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | ||
333 | m_pix = pix; | ||
334 | } | ||
335 | |||
336 | /** | ||
337 | * Set the KeyPair the OKeyConfigItem uses. | ||
338 | * Your set Key could get overwritten if you use | ||
339 | * the manager or GUI to configure the key | ||
340 | * | ||
341 | * @param key Set the OKeyPair used | ||
342 | * @see keyPair() | ||
343 | */ | ||
344 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | ||
345 | m_key = key; | ||
346 | } | ||
347 | |||
348 | /** | ||
349 | * Set the default KeyPair. | ||
350 | * | ||
351 | * @param key The default keypair | ||
352 | * @see defaultKeyPair() | ||
353 | */ | ||
354 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | ||
355 | m_def = key; | ||
356 | } | ||
357 | |||
358 | /** | ||
359 | * @internal | ||
360 | */ | ||
361 | void OKeyConfigItem::setConfigKey( const QCString& str) { | ||
362 | m_config = str; | ||
363 | m_config.detach(); | ||
364 | } | ||
365 | |||
366 | /** | ||
367 | * @internal | ||
368 | */ | ||
369 | void OKeyConfigItem::setId( int id ) { | ||
370 | m_id = id; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * If the item is not configured isEmpty() will return true | ||
375 | * It is empty if no text is present and no default | ||
376 | * and no configured key | ||
377 | */ | ||
378 | bool OKeyConfigItem::isEmpty()const { | ||
379 | if ( !m_def.isEmpty() ) return false; | ||
380 | if ( !m_key.isEmpty() ) return false; | ||
381 | if ( !m_text.isEmpty() ) return false; | ||
382 | if ( m_id != -1 ) return false; | ||
383 | |||
384 | return true; | ||
385 | } | ||
386 | |||
387 | /** | ||
388 | * Check if the KeyPairs are the same | ||
389 | */ | ||
390 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | ||
391 | /* if ( isEmpty() == conf.isEmpty() ) return true; | ||
392 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
393 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
394 | */ | ||
395 | |||
396 | if ( m_id != conf.m_id ) return false; | ||
397 | if ( m_obj != conf.m_obj ) return false; | ||
398 | if ( m_text != conf.m_text ) return false; | ||
399 | if ( m_key != conf.m_key ) return false; | ||
400 | if ( m_def != conf.m_def ) return false; | ||
401 | |||
402 | |||
403 | |||
404 | return true; | ||
405 | |||
406 | } | ||
407 | |||
408 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | ||
409 | return !( *this == conf ); | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * \brief c'tor | ||
414 | * The Constructor for a OKeyConfigManager | ||
415 | * | ||
416 | * You can use this manager in multiple ways. Either make it handle | ||
417 | * QKeyEvents | ||
418 | * | ||
419 | * \code | ||
420 | * Opie::Core::Config conf = oApp->config(); | ||
421 | * Opie::Core::OKeyPairList blackList; | ||
422 | * blackList.append(Opie::Core::OKeyPair::leftArrowKey()); | ||
423 | * blackList.append(Opie::Core::OKeyPair::rightArrowKey()); | ||
424 | * Opie::Core::OKeyConfigManager *manager = new Opie::Core::OKeyConfigManager(conf,"key_actions",blackList, | ||
425 | * false); | ||
426 | * QListView *view = new QListView(); | ||
427 | * manager->handleWidget(view); | ||
428 | * manager->addKeyConfig( Opie::Core::OKeyPair::returnKey()); | ||
429 | * manager->load(); | ||
430 | * | ||
431 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&)), | ||
432 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Core::OKeyConfigItem&))); | ||
433 | * | ||
434 | * .... | ||
435 | * | ||
436 | * void update(){ | ||
437 | * QDialog diag(true); | ||
438 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | ||
439 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | ||
440 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | ||
441 | * lay->addWidget(wid); | ||
442 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | ||
443 | * wid->save(); | ||
444 | * } | ||
445 | * } | ||
446 | * | ||
447 | * .... | ||
448 | * MyListView::keyPressEvent( QKeyEvent* e ){ | ||
449 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | ||
450 | * if(!item.isEmpty() ){ | ||
451 | * switch(item.id()){ | ||
452 | * case My_Delete_Key: | ||
453 | * break; | ||
454 | * } | ||
455 | * } | ||
456 | * } | ||
457 | * | ||
458 | * \endcode | ||
459 | * | ||
460 | * @param conf The Config where the KeySetting should be stored | ||
461 | * @param group The group where the KeySetting will be stored | ||
462 | * @param black Which keys shouldn't be allowed to handle | ||
463 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | ||
464 | * @param par The parent/owner of this manager | ||
465 | * @param name The name of this object | ||
466 | */ | ||
467 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | ||
468 | const QString& group, | ||
469 | const OKeyPair::List& black, | ||
470 | bool grabkeyboard, QObject* par, | ||
471 | const char* name) | ||
472 | : QObject( par, name ), m_conf( conf ), m_group( group ), | ||
473 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | ||
474 | if ( m_grab ) | ||
475 | QPEApplication::grabKeyboard(); | ||
476 | } | ||
477 | |||
478 | |||
479 | /** | ||
480 | * Destructor | ||
481 | */ | ||
482 | OKeyConfigManager::~OKeyConfigManager() { | ||
483 | if ( m_grab ) | ||
484 | QPEApplication::ungrabKeyboard(); | ||
485 | } | ||
486 | |||
487 | /** | ||
488 | * Load the Configuration from the OConfig | ||
489 | * If a Key is restricted but was in the config we will | ||
490 | * make it be the empty key paur | ||
491 | * We will change the group but restore to the previous. | ||
492 | * | ||
493 | * @see OKeyPair::emptyKey | ||
494 | */ | ||
495 | void OKeyConfigManager::load() { | ||
496 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
497 | |||
498 | /* | ||
499 | * Read each item | ||
500 | */ | ||
501 | int key, mod; | ||
502 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | ||
503 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | ||
504 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | ||
505 | OKeyPair okey( key, mod ); | ||
506 | |||
507 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
508 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
509 | else | ||
510 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
511 | } | ||
512 | delete m_map; m_map = 0; | ||
513 | } | ||
514 | |||
515 | /** | ||
516 | * We will save the current configuration | ||
517 | * to the OConfig. We will change the group but restore | ||
518 | * to the previous | ||
519 | */ | ||
520 | void OKeyConfigManager::save() { | ||
521 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
522 | |||
523 | /* | ||
524 | * Write each item | ||
525 | */ | ||
526 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | ||
527 | /* skip empty items */ | ||
528 | if ( (*it).isEmpty() ) | ||
529 | continue; | ||
530 | OKeyPair pair = (*it).keyPair(); | ||
531 | OKeyPair deft = (*it).defaultKeyPair(); | ||
532 | /* | ||
533 | * don't write if it is the default setting | ||
534 | * FIXME allow to remove Keys from config | ||
535 | if ( (pair.keycode() == deft.keycode()) && | ||
536 | (pair.modifier()== deft.modifier() ) ) | ||
537 | return; | ||
538 | */ | ||
539 | |||
540 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | ||
541 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | ||
542 | } | ||
543 | m_conf->write(); | ||
544 | } | ||
545 | |||
546 | /** | ||
547 | * This is function uses a QMap internally but you can have the same keycode | ||
548 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
549 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
550 | * cofigure two keys. | ||
551 | * | ||
552 | * Make sure you call e->ignore if you don't want to handle this event | ||
553 | */ | ||
554 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
555 | /* | ||
556 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
557 | * methods | ||
558 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
559 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
560 | * case ascii | ||
561 | */ | ||
562 | int key, mod; | ||
563 | Opie::Core::Internal::fixupKeys( key, mod, e ); | ||
564 | |||
565 | OKeyConfigItem::List _keyList = keyList( key ); | ||
566 | if ( _keyList.isEmpty() ) | ||
567 | return OKeyConfigItem(); | ||
568 | |||
569 | OKeyConfigItem item; | ||
570 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | ||
571 | ++it ) { | ||
572 | if ( (*it).keyPair().modifier() == mod ) { | ||
573 | item = *it; | ||
574 | break; | ||
575 | } | ||
576 | |||
577 | } | ||
578 | |||
579 | return item; | ||
580 | } | ||
581 | |||
582 | /** | ||
583 | * Return the associated id of the item or -1 if no item | ||
584 | * matched the key | ||
585 | * | ||
586 | * @see handleKeyEvent | ||
587 | */ | ||
588 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
589 | return handleKeyEvent( ev ).id(); | ||
590 | } | ||
591 | |||
592 | /** | ||
593 | * Add Key Config to the List of items | ||
594 | */ | ||
595 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
596 | m_keys.append( item ); | ||
597 | delete m_map; m_map = 0; | ||
598 | } | ||
599 | |||
600 | /** | ||
601 | * Remove the Key from the Config. Internal lists will be destroyed | ||
602 | * and rebuild on demand later | ||
603 | */ | ||
604 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
605 | m_keys.remove( item ); | ||
606 | delete m_map; m_map = 0; | ||
607 | } | ||
608 | |||
609 | /** | ||
610 | * Clears the complete list | ||
611 | */ | ||
612 | void OKeyConfigManager::clearKeyConfig() { | ||
613 | m_keys.clear(); | ||
614 | delete m_map; m_map = 0; | ||
615 | } | ||
616 | |||
617 | /** | ||
618 | * | ||
619 | */ | ||
620 | Opie::Core::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | ||
621 | return m_keys; | ||
622 | } | ||
623 | |||
624 | /** | ||
625 | * Add this OKeyPair to the blackList. | ||
626 | * Internal lists will be destroyed | ||
627 | */ | ||
628 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
629 | m_blackKeys.append( key ); | ||
630 | delete m_map; m_map = 0; | ||
631 | } | ||
632 | |||
633 | |||
634 | /** | ||
635 | * Remove this OKeyPair from the black List | ||
636 | * Internal lists will be destroyed | ||
637 | */ | ||
638 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
639 | m_blackKeys.remove( key ); | ||
640 | delete m_map; m_map = 0; | ||
641 | } | ||
642 | |||
643 | |||
644 | /** | ||
645 | * Clear the blackList | ||
646 | */ | ||
647 | void OKeyConfigManager::clearBlackList() { | ||
648 | m_blackKeys.clear(); | ||
649 | delete m_map; m_map = 0; | ||
650 | } | ||
651 | |||
652 | |||
653 | /** | ||
654 | * Return a copy of the blackList | ||
655 | */ | ||
656 | OKeyPair::List OKeyConfigManager::blackList()const { | ||
657 | return m_blackKeys; | ||
658 | } | ||
659 | |||
660 | |||
661 | /** | ||
662 | * Ask the Manager to handle KeyEvents for you. | ||
663 | * All handled keys will emit a QSignal and return true | ||
664 | * that it handled the keyevent | ||
665 | */ | ||
666 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
667 | wid->installEventFilter( this ); | ||
668 | } | ||
669 | |||
670 | /** | ||
671 | * @internal | ||
672 | */ | ||
673 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
674 | if ( !obj->isWidgetType() ) | ||
675 | return false; | ||
676 | |||
677 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
678 | return false; | ||
679 | |||
680 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
681 | OKeyConfigItem item = handleKeyEvent( key ); | ||
682 | |||
683 | if ( item.isEmpty() ) | ||
684 | return false; | ||
685 | |||
686 | QWidget *wid = static_cast<QWidget*>( obj ); | ||
687 | |||
688 | if ( item.object() && !item.slot().isEmpty() ) { | ||
689 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
690 | item.object(), item.slot().data() ); | ||
691 | emit actionActivated(wid, key); | ||
692 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
693 | item.object(), item.slot().data() ); | ||
694 | } | ||
695 | emit actionActivated( wid, key, item ); | ||
696 | |||
697 | return true; | ||
698 | } | ||
699 | |||
700 | /** | ||
701 | * @internal | ||
702 | */ | ||
703 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | ||
704 | /* | ||
705 | * Create the map if not existing anymore | ||
706 | */ | ||
707 | if ( !m_map ) { | ||
708 | m_map = new OKeyMapConfigPrivate; | ||
709 | /* for every key */ | ||
710 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | ||
711 | it!= m_keys.end(); ++it ) { | ||
712 | |||
713 | bool add = true; | ||
714 | /* see if this key is blocked */ | ||
715 | OKeyPair pair = (*it).keyPair(); | ||
716 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
717 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
718 | if ( (*pairIt).keycode() == pair.keycode() && | ||
719 | (*pairIt).modifier() == pair.modifier() ) { | ||
720 | add = false; | ||
721 | break; | ||
722 | } | ||
723 | } | ||
724 | /* check if we added it */ | ||
725 | if ( add ) | ||
726 | (*m_map)[pair.keycode()].append( *it ); | ||
727 | } | ||
728 | } | ||
729 | return (*m_map)[keycode]; | ||
730 | } | ||
731 | |||
732 | } | ||
733 | } | ||
diff --git a/libopie2/opiecore/okeyconfigmanager.h b/libopie2/opiecore/okeyconfigmanager.h new file mode 100644 index 0000000..d610375 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager.h | |||
@@ -0,0 +1,205 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2004 | ||
3 | * LGPL v2 zecke@handhelds.org | ||
4 | */ | ||
5 | |||
6 | |||
7 | #ifndef ODP_KEY_MANAGER_WIDGET_H | ||
8 | #define ODP_KEY_MANAGER_WIDGET_H | ||
9 | |||
10 | #include <opie2/oconfig.h> | ||
11 | #include <opie2/odevice.h> | ||
12 | |||
13 | #include <qstring.h> | ||
14 | #include <qpixmap.h> | ||
15 | #include <qcstring.h> | ||
16 | #include <qvaluelist.h> | ||
17 | |||
18 | namespace Opie { | ||
19 | namespace Core { | ||
20 | |||
21 | /** | ||
22 | * \brief small class representing a Key with possible modifiers | ||
23 | * This class holds information about key code and possible | ||
24 | * modifier state. That is the lowest level of the key input | ||
25 | * functions. | ||
26 | * There are also static methods to get special keys. | ||
27 | * OKeyPair will be used with \see OKeyConfigItem | ||
28 | * | ||
29 | * @since 1.2 | ||
30 | */ | ||
31 | class OKeyPair { | ||
32 | public: | ||
33 | typedef QValueList<OKeyPair> List; | ||
34 | OKeyPair( int key = -1, int modifier = -1); | ||
35 | ~OKeyPair(); | ||
36 | |||
37 | bool operator==( const OKeyPair& )const; | ||
38 | bool operator!=( const OKeyPair& )const; | ||
39 | |||
40 | bool isEmpty()const; | ||
41 | |||
42 | int keycode()const; | ||
43 | int modifier()const; | ||
44 | |||
45 | void setKeycode( int ); | ||
46 | void setModifier( int ); | ||
47 | |||
48 | static OKeyPair returnKey(); | ||
49 | static OKeyPair leftArrowKey(); | ||
50 | static OKeyPair rightArrowKey(); | ||
51 | static OKeyPair upArrowKey(); | ||
52 | static OKeyPair downArrowKey(); | ||
53 | static OKeyPair emptyKey(); | ||
54 | static OKeyPair::List hardwareKeys(); | ||
55 | |||
56 | private: | ||
57 | int m_key; | ||
58 | int m_mod; | ||
59 | class Private; | ||
60 | Private* d; | ||
61 | }; | ||
62 | |||
63 | /** | ||
64 | * A class to represent an OKeyPair. | ||
65 | * It consists out of a Text exposed to the user, Config Key Item, | ||
66 | * Pixmap, A default OKeyPair and the set OKeyPair. | ||
67 | * You can also pass an id to it | ||
68 | * | ||
69 | * @since 1.1.2 | ||
70 | */ | ||
71 | class OKeyConfigItem { | ||
72 | friend class OKeyConfigManager; | ||
73 | public: | ||
74 | typedef QValueList<OKeyConfigItem> List; | ||
75 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | ||
76 | const QPixmap& symbol = QPixmap(), | ||
77 | int id = -1, | ||
78 | const OKeyPair& def = OKeyPair::emptyKey(), | ||
79 | QObject *caller = 0, const char* slot = 0); | ||
80 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | ||
81 | ~OKeyConfigItem(); | ||
82 | |||
83 | bool operator==( const OKeyConfigItem& )const; | ||
84 | bool operator!=( const OKeyConfigItem& )const; | ||
85 | |||
86 | QString text()const; | ||
87 | QPixmap pixmap()const; | ||
88 | int id()const; | ||
89 | |||
90 | |||
91 | |||
92 | OKeyPair keyPair()const; | ||
93 | OKeyPair defaultKeyPair()const; | ||
94 | QCString configKey()const; | ||
95 | |||
96 | |||
97 | void setText( const QString& text ); | ||
98 | void setPixmap( const QPixmap& ); | ||
99 | void setKeyPair( const OKeyPair& ); | ||
100 | void setDefaultKeyPair( const OKeyPair& ); | ||
101 | |||
102 | bool isEmpty()const; | ||
103 | |||
104 | protected: | ||
105 | QObject *object()const; | ||
106 | QCString slot()const; | ||
107 | void setId( int id ); | ||
108 | void setConfigKey( const QCString& ); | ||
109 | |||
110 | private: | ||
111 | QString m_text; | ||
112 | QCString m_config; | ||
113 | QPixmap m_pix; | ||
114 | int m_id; | ||
115 | OKeyPair m_key; | ||
116 | OKeyPair m_def; | ||
117 | QObject *m_obj; | ||
118 | QCString m_str; | ||
119 | class Private; | ||
120 | Private *d; | ||
121 | }; | ||
122 | |||
123 | |||
124 | |||
125 | /** | ||
126 | * \brief A manager to load and save Key Actions and get notified | ||
127 | * This is the Manager for KeyActions. | ||
128 | * You can say from which config and group to read data, to grab the | ||
129 | * keyboard to handle hardware keys, you can supply a blacklist of | ||
130 | * keys which should not be used by allowed to be used. | ||
131 | * You can even pass this manager to a Widget to do the configuration for you. | ||
132 | * You need to add OKeyConfigItem for your keys and then issue a load() to | ||
133 | * read the Key information. | ||
134 | * You can either handle the QKeyEvent yourself and ask this class if it is | ||
135 | * handled by your action and let give you the action. Or you can install | ||
136 | * the event filter and get a signal. | ||
137 | * You need to load ans save yourself! | ||
138 | * | ||
139 | * @since 1.1.2 | ||
140 | */ | ||
141 | class OKeyConfigManager : public QObject { | ||
142 | Q_OBJECT | ||
143 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | ||
144 | public: | ||
145 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | ||
146 | const QString& group = QString::null, | ||
147 | const OKeyPair::List &block = OKeyPair::List(), | ||
148 | bool grabkeyboard = false, QObject * par = 0, | ||
149 | const char* name = 0 ); | ||
150 | ~OKeyConfigManager(); | ||
151 | |||
152 | void load(); | ||
153 | void save(); | ||
154 | |||
155 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | ||
156 | int handleKeyEventId( QKeyEvent* ); | ||
157 | |||
158 | void addKeyConfig( const OKeyConfigItem& ); | ||
159 | void removeKeyConfig( const OKeyConfigItem& ); | ||
160 | void clearKeyConfig(); | ||
161 | |||
162 | void addToBlackList( const OKeyPair& ); | ||
163 | void removeFromBlackList( const OKeyPair& ); | ||
164 | void clearBlackList(); | ||
165 | OKeyPair::List blackList()const; | ||
166 | |||
167 | void handleWidget( QWidget* ); | ||
168 | |||
169 | bool eventFilter( QObject*, QEvent* ); | ||
170 | |||
171 | OKeyConfigItem::List keyConfigList()const; | ||
172 | signals: | ||
173 | /** | ||
174 | * The Signals are triggered on KeyPress and KeyRelease! | ||
175 | * You can check the isDown of the QKeyEvent | ||
176 | * @see QKeyEvent | ||
177 | */ | ||
178 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Core::OKeyConfigItem& ); | ||
179 | |||
180 | /** | ||
181 | * This Signal correspondents to the OKeyConfigItem slot | ||
182 | * and object | ||
183 | * | ||
184 | * @see OKeyConfigItem::slot | ||
185 | * @see OKeyConfigItem::object | ||
186 | */ | ||
187 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
188 | |||
189 | private: | ||
190 | OKeyConfigItem::List keyList( int ); | ||
191 | OKeyConfigItem::List m_keys; | ||
192 | QValueList<QWidget*> m_widgets; | ||
193 | Opie::Core::OConfig *m_conf; | ||
194 | QString m_group; | ||
195 | OKeyPair::List m_blackKeys; | ||
196 | bool m_grab : 1; | ||
197 | OKeyMapConfigPrivate *m_map; | ||
198 | class Private; | ||
199 | Private *d; | ||
200 | }; | ||
201 | |||
202 | } | ||
203 | } | ||
204 | |||
205 | #endif | ||
diff --git a/libopie2/opiecore/okeyconfigmanager_p.h b/libopie2/opiecore/okeyconfigmanager_p.h new file mode 100644 index 0000000..0fe1056 --- a/dev/null +++ b/libopie2/opiecore/okeyconfigmanager_p.h | |||
@@ -0,0 +1,9 @@ | |||
1 | |||
2 | namespace Opie { | ||
3 | namespace Core { | ||
4 | namespace Internal { | ||
5 | void fixupKeys( int&, int&, QKeyEvent* ); | ||
6 | } | ||
7 | } | ||
8 | } | ||
9 | |||
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro index ae0af77..171bb0c 100644 --- a/libopie2/opiecore/opiecore.pro +++ b/libopie2/opiecore/opiecore.pro | |||
@@ -6,6 +6,7 @@ HEADERS = oapplication.h \ | |||
6 | odebug.h \ | 6 | odebug.h \ |
7 | oglobal.h \ | 7 | oglobal.h \ |
8 | oglobalsettings.h \ | 8 | oglobalsettings.h \ |
9 | okeyconfigmanager.h \ | ||
9 | oprocess.h \ | 10 | oprocess.h \ |
10 | oprocctrl.h \ | 11 | oprocctrl.h \ |
11 | osmartpointer.h \ | 12 | osmartpointer.h \ |
@@ -17,6 +18,7 @@ SOURCES = oapplication.cpp \ | |||
17 | odebug.cpp \ | 18 | odebug.cpp \ |
18 | oglobal.cpp \ | 19 | oglobal.cpp \ |
19 | oglobalsettings.cpp \ | 20 | oglobalsettings.cpp \ |
21 | okeyconfigmanager.cpp \ | ||
20 | oprocess.cpp \ | 22 | oprocess.cpp \ |
21 | oprocctrl.cpp \ | 23 | oprocctrl.cpp \ |
22 | ostorageinfo.cpp \ | 24 | ostorageinfo.cpp \ |
diff --git a/libopie2/opieui/okeyconfigwidget.cpp b/libopie2/opieui/okeyconfigwidget.cpp index d6d34f5..1991381 100644 --- a/libopie2/opieui/okeyconfigwidget.cpp +++ b/libopie2/opieui/okeyconfigwidget.cpp | |||
@@ -14,707 +14,9 @@ | |||
14 | /* non gui */ | 14 | /* non gui */ |
15 | #include <qtimer.h> | 15 | #include <qtimer.h> |
16 | 16 | ||
17 | 17 | using Opie::Core::OKeyConfigItem; | |
18 | using namespace Opie::Ui; | 18 | using Opie::Core::OKeyPair; |
19 | 19 | using Opie::Core::OKeyConfigManager; | |
20 | |||
21 | |||
22 | /** | ||
23 | * The default Constructor of a OKeyPair. | ||
24 | * A Key and a Modifier ( Alt/Shift/Ctrl ) | ||
25 | * needs to be supplied. | ||
26 | * Use Qt::Key for the information. | ||
27 | * The default arguments create an Empty OKeyPair. If you | ||
28 | * want to get an empty OKeyPair use the static method for getting | ||
29 | * the emptyKey() | ||
30 | * | ||
31 | * @see OKeyPair OKeyPair::emptyKey() | ||
32 | */ | ||
33 | OKeyPair::OKeyPair( int key, int mod ) | ||
34 | : m_key( key ), m_mod( mod ) | ||
35 | {} | ||
36 | |||
37 | /** | ||
38 | * The destructor | ||
39 | */ | ||
40 | OKeyPair::~OKeyPair() {} | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Is this OKeyPair empty/valid? | ||
45 | */ | ||
46 | bool OKeyPair::isEmpty()const { | ||
47 | return ( ( m_key == -1 )&& ( m_mod == -1 ) ); | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | * get the keycode for this OKeyPair. The Key relates to Qt::Key. | ||
52 | * | ||
53 | * @see Qt::Key | ||
54 | * @see setKey | ||
55 | */ | ||
56 | int OKeyPair::keycode()const { | ||
57 | return m_key; | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * get the modifier key for this OKeyPair. The Modifier State relates | ||
62 | * to the Qt::ButtonState | ||
63 | * | ||
64 | * @see Qt::ButtonState | ||
65 | * @see setModifier | ||
66 | */ | ||
67 | int OKeyPair::modifier()const { | ||
68 | return m_mod; | ||
69 | } | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Set the keycode | ||
74 | * @param key The Keycode to set | ||
75 | * | ||
76 | * @see keycode() | ||
77 | * @see Qt::Key | ||
78 | */ | ||
79 | void OKeyPair::setKeycode( int key ) { | ||
80 | m_key = key; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Set the modifier key | ||
85 | * | ||
86 | * @param the Modifier key | ||
87 | * @see Qt::ButtonState | ||
88 | * @see modifier() | ||
89 | */ | ||
90 | void OKeyPair::setModifier( int mod ) { | ||
91 | m_mod = mod; | ||
92 | } | ||
93 | |||
94 | /** | ||
95 | * Return an OKeyPair for the Return Key without any modifier. | ||
96 | */ | ||
97 | OKeyPair OKeyPair::returnKey() { | ||
98 | return OKeyPair( Qt::Key_Return, 0 ); | ||
99 | } | ||
100 | |||
101 | /** | ||
102 | * Return an OKeyPair for the Left Arrow Key | ||
103 | * without any modifier Key | ||
104 | */ | ||
105 | OKeyPair OKeyPair::leftArrowKey() { | ||
106 | return OKeyPair( Qt::Key_Left, 0 ); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * Return an OKeyPair for the Right Arrow Key | ||
111 | * without any modifier Key | ||
112 | */ | ||
113 | OKeyPair OKeyPair::rightArrowKey() { | ||
114 | return OKeyPair( Qt::Key_Right, 0 ); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * Return an OKeyPair for the Up Arrow Key | ||
119 | * without any modifier Key | ||
120 | */ | ||
121 | OKeyPair OKeyPair::upArrowKey() { | ||
122 | return OKeyPair( Qt::Key_Up, 0 ); | ||
123 | } | ||
124 | |||
125 | /** | ||
126 | * Return an OKeyPair for the Down Arrow Key | ||
127 | * without any modifier Key | ||
128 | */ | ||
129 | OKeyPair OKeyPair::downArrowKey() { | ||
130 | return OKeyPair( Qt::Key_Down, 0 ); | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Return an Empty OKeyPair | ||
135 | */ | ||
136 | OKeyPair OKeyPair::emptyKey() { | ||
137 | return OKeyPair(); | ||
138 | } | ||
139 | |||
140 | /** | ||
141 | * This functions uses the Opie::Core::ODevice::buttons | ||
142 | * for OKeyPairList | ||
143 | * | ||
144 | * @see Opie::Core::ODevice | ||
145 | * @see Opie::Core::ODeviceButton | ||
146 | * @see Opie::Core::ODevice::button | ||
147 | */ | ||
148 | OKeyPair::List OKeyPair::hardwareKeys() { | ||
149 | const QValueList<Opie::Core::ODeviceButton> but = Opie::Core::ODevice::inst()->buttons(); | ||
150 | OKeyPair::List lst; | ||
151 | |||
152 | for ( QValueList<Opie::Core::ODeviceButton>::ConstIterator it = but.begin(); | ||
153 | it != but.end(); ++it ) | ||
154 | lst.append( OKeyPair( (*it).keycode(), 0 ) ); | ||
155 | |||
156 | |||
157 | return lst; | ||
158 | } | ||
159 | |||
160 | /** | ||
161 | * Equals operator. Check if two OKeyPairs have the same key and modifier | ||
162 | * @see operator!= | ||
163 | */ | ||
164 | bool OKeyPair::operator==( const OKeyPair& pair)const { | ||
165 | if ( m_key != pair.m_key ) return false; | ||
166 | if ( m_mod != pair.m_mod ) return false; | ||
167 | |||
168 | return true; | ||
169 | } | ||
170 | |||
171 | /** | ||
172 | * Not equal operator. calls the equal operator internally | ||
173 | */ | ||
174 | bool OKeyPair::operator!=( const OKeyPair& pair)const { | ||
175 | return !(*this == pair); | ||
176 | } | ||
177 | |||
178 | |||
179 | /** | ||
180 | * The normal Constructor to create a OKeyConfigItem | ||
181 | * | ||
182 | * You can set the the key paramater of this item but if | ||
183 | * you use this item with the OKeyConfigManager your setting | ||
184 | * will be overwritten. | ||
185 | * You can also specify a QObject and slot which sould get called | ||
186 | * once this item is activated. This slot only works if you | ||
187 | * use the OKeyConfigManager. | ||
188 | * The actual Key is read by load() | ||
189 | * | ||
190 | * \code | ||
191 | * void MySlot::create(){ | ||
192 | * OKeyConfigItem item(tr("Delete"),"delete",Resource::loadPixmap("trash"), | ||
193 | * 123, OKeyPair(Qt::Key_D,Qt::ControlButton), | ||
194 | * this,SLOT(slotDelete(QWidget*,QKeyEvent*))); | ||
195 | * } | ||
196 | * \endcode | ||
197 | * | ||
198 | * @param text The text exposed to the user | ||
199 | * @param config_key The key used in the config | ||
200 | * @param pix A Pixmap associated with this Item | ||
201 | * @param def The OKeyPair used as default | ||
202 | * @param caller The object where the slot exists | ||
203 | * @param slot The slot which should get called | ||
204 | * | ||
205 | */ | ||
206 | OKeyConfigItem::OKeyConfigItem( const QString& text, const QCString& config_key, | ||
207 | const QPixmap& pix, int id, const OKeyPair& def, | ||
208 | QObject *caller, | ||
209 | const char* slot ) | ||
210 | : m_text( text ), m_config( config_key ), m_pix( pix ), | ||
211 | m_id( id ), m_def( def ), | ||
212 | m_obj( caller ), m_str( slot ) {} | ||
213 | |||
214 | /** | ||
215 | * A special Constructor for converting from an Opie::Core::ODeviceButton | ||
216 | * delivered by Opie::Core::ODevice::buttons() | ||
217 | * There is no Config Key set and both default key and key are set | ||
218 | * to Opie::Core::ODeviceButton::keycode() and 0 to modifier | ||
219 | * | ||
220 | * @see Opie::Core::ODevice | ||
221 | * @see Opie::Core::ODeviceButton | ||
222 | * @see Opie::Core::ODevice::buttons() | ||
223 | */ | ||
224 | OKeyConfigItem::OKeyConfigItem( const Opie::Core::ODeviceButton& b ) | ||
225 | : m_text( b.userText() ), m_pix( b.pixmap() ), m_id( -1 ), | ||
226 | m_key( OKeyPair( b.keycode(), 0 ) ), m_def( OKeyPair( b.keycode(), 0 ) ) | ||
227 | {} | ||
228 | |||
229 | |||
230 | /** | ||
231 | * Destructor | ||
232 | */ | ||
233 | OKeyConfigItem::~OKeyConfigItem() {} | ||
234 | |||
235 | |||
236 | /** | ||
237 | * The text exposed to the user | ||
238 | * | ||
239 | * @see setText | ||
240 | */ | ||
241 | QString OKeyConfigItem::text()const { | ||
242 | return m_text; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * The pixmap shown to the user for your action/key | ||
247 | * | ||
248 | * @see setPixmap | ||
249 | */ | ||
250 | QPixmap OKeyConfigItem::pixmap()const { | ||
251 | return m_pix; | ||
252 | } | ||
253 | |||
254 | /** | ||
255 | * Return the OKeyPair this OKeyConfigItem is configured for. | ||
256 | * | ||
257 | * @see setKeyPair | ||
258 | */ | ||
259 | OKeyPair OKeyConfigItem::keyPair()const { | ||
260 | return m_key; | ||
261 | } | ||
262 | |||
263 | /** | ||
264 | * Return the default OKeyPair | ||
265 | * @see setDefaultKeyPair | ||
266 | */ | ||
267 | OKeyPair OKeyConfigItem::defaultKeyPair()const { | ||
268 | return m_def; | ||
269 | } | ||
270 | |||
271 | |||
272 | /** | ||
273 | * Return the Id you assigned to this item. | ||
274 | * setting is only possible by the constructor | ||
275 | */ | ||
276 | int OKeyConfigItem::id()const{ | ||
277 | return m_id; | ||
278 | } | ||
279 | |||
280 | /** | ||
281 | * reutrn the Config Key. Setting it is only possible | ||
282 | * by the constructor | ||
283 | */ | ||
284 | QCString OKeyConfigItem::configKey()const { | ||
285 | return m_config; | ||
286 | } | ||
287 | |||
288 | /** | ||
289 | * @internal | ||
290 | */ | ||
291 | QObject* OKeyConfigItem::object()const{ | ||
292 | return m_obj; | ||
293 | } | ||
294 | |||
295 | /** | ||
296 | * @internal | ||
297 | */ | ||
298 | QCString OKeyConfigItem::slot()const { | ||
299 | return m_str; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | * Set the text | ||
304 | * | ||
305 | * @param text Set the Text of this Action to text | ||
306 | * @see text() | ||
307 | */ | ||
308 | void OKeyConfigItem::setText( const QString& text ) { | ||
309 | m_text = text; | ||
310 | } | ||
311 | |||
312 | /** | ||
313 | * Set the pixmap of this action | ||
314 | * | ||
315 | * @param pix The Pixmap to set | ||
316 | * @see pixmap() | ||
317 | */ | ||
318 | void OKeyConfigItem::setPixmap( const QPixmap& pix ) { | ||
319 | m_pix = pix; | ||
320 | } | ||
321 | |||
322 | /** | ||
323 | * Set the KeyPair the OKeyConfigItem uses. | ||
324 | * Your set Key could get overwritten if you use | ||
325 | * the manager or GUI to configure the key | ||
326 | * | ||
327 | * @param key Set the OKeyPair used | ||
328 | * @see keyPair() | ||
329 | */ | ||
330 | void OKeyConfigItem::setKeyPair( const OKeyPair& key) { | ||
331 | m_key = key; | ||
332 | } | ||
333 | |||
334 | /** | ||
335 | * Set the default KeyPair. | ||
336 | * | ||
337 | * @param key The default keypair | ||
338 | * @see defaultKeyPair() | ||
339 | */ | ||
340 | void OKeyConfigItem::setDefaultKeyPair( const OKeyPair& key ) { | ||
341 | m_def = key; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * @internal | ||
346 | */ | ||
347 | void OKeyConfigItem::setConfigKey( const QCString& str) { | ||
348 | m_config = str; | ||
349 | m_config.detach(); | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * @internal | ||
354 | */ | ||
355 | void OKeyConfigItem::setId( int id ) { | ||
356 | m_id = id; | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * If the item is not configured isEmpty() will return true | ||
361 | * It is empty if no text is present and no default | ||
362 | * and no configured key | ||
363 | */ | ||
364 | bool OKeyConfigItem::isEmpty()const { | ||
365 | if ( !m_def.isEmpty() ) return false; | ||
366 | if ( !m_key.isEmpty() ) return false; | ||
367 | if ( !m_text.isEmpty() ) return false; | ||
368 | if ( m_id != -1 ) return false; | ||
369 | |||
370 | return true; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * Check if the KeyPairs are the same | ||
375 | */ | ||
376 | bool OKeyConfigItem::operator==( const OKeyConfigItem& conf )const { | ||
377 | /* if ( isEmpty() == conf.isEmpty() ) return true; | ||
378 | else if ( isEmpty() != conf.isEmpty() ) return false; | ||
379 | else if ( !isEmpty()!= conf.isEmpty() ) return false; | ||
380 | */ | ||
381 | |||
382 | if ( m_id != conf.m_id ) return false; | ||
383 | if ( m_obj != conf.m_obj ) return false; | ||
384 | if ( m_text != conf.m_text ) return false; | ||
385 | if ( m_key != conf.m_key ) return false; | ||
386 | if ( m_def != conf.m_def ) return false; | ||
387 | |||
388 | |||
389 | |||
390 | return true; | ||
391 | |||
392 | } | ||
393 | |||
394 | bool OKeyConfigItem::operator!=( const OKeyConfigItem& conf )const { | ||
395 | return !( *this == conf ); | ||
396 | } | ||
397 | |||
398 | /** | ||
399 | * \brief c'tor | ||
400 | * The Constructor for a OKeyConfigManager | ||
401 | * | ||
402 | * You can use this manager in multiple ways. Either make it handle | ||
403 | * QKeyEvents | ||
404 | * | ||
405 | * \code | ||
406 | * Opie::Core::Config conf = oApp->config(); | ||
407 | * Opie::Ui::OKeyPairList blackList; | ||
408 | * blackList.append(Opie::Ui::OKeyPair::leftArrowKey()); | ||
409 | * blackList.append(Opie::Ui::OKeyPair::rightArrowKey()); | ||
410 | * Opie::Ui::OKeyConfigManager *manager = new Opie::Ui::OKeyConfigManager(conf,"key_actions",blackList, | ||
411 | * false); | ||
412 | * QListView *view = new QListView(); | ||
413 | * manager->handleWidget(view); | ||
414 | * manager->addKeyConfig( Opie::Ui::OKeyPair::returnKey()); | ||
415 | * manager->load(); | ||
416 | * | ||
417 | * connect(manager,SIGNAL(actionActivated(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&)), | ||
418 | * this,SLOT(slotHandleKey(QWidget*,QKeyEvent*,const Opie::Ui::OKeyConfigItem&))); | ||
419 | * | ||
420 | * .... | ||
421 | * | ||
422 | * void update(){ | ||
423 | * QDialog diag(true); | ||
424 | * QHBoxLayout *lay = new QHBoxLayout(&diag); | ||
425 | * Opie::Ui::OKeyConfigWidget *wid = new Opie::Ui::OKeyConfigWidget(manager,&diag); | ||
426 | * wid->setChangeMode(Opie::Ui::OKeyConfigWidget::Queu); | ||
427 | * lay->addWidget(wid); | ||
428 | * if(QPEApplication::execDialog( &diag)== QDialog::Accepted){ | ||
429 | * wid->save(); | ||
430 | * } | ||
431 | * } | ||
432 | * | ||
433 | * .... | ||
434 | * MyListView::keyPressEvent( QKeyEvent* e ){ | ||
435 | * Opie::Ui::OKeyConfigItem item = manager->handleKeyEvent(e); | ||
436 | * if(!item.isEmpty() ){ | ||
437 | * switch(item.id()){ | ||
438 | * case My_Delete_Key: | ||
439 | * break; | ||
440 | * } | ||
441 | * } | ||
442 | * } | ||
443 | * | ||
444 | * \endcode | ||
445 | * | ||
446 | * @param conf The Config where the KeySetting should be stored | ||
447 | * @param group The group where the KeySetting will be stored | ||
448 | * @param black Which keys shouldn't be allowed to handle | ||
449 | * @param grabkeyboard Calls QPEApplication::grabKeyboard to allow handling of DeviceButtons | ||
450 | * @param par The parent/owner of this manager | ||
451 | * @param name The name of this object | ||
452 | */ | ||
453 | OKeyConfigManager::OKeyConfigManager( Opie::Core::OConfig* conf, | ||
454 | const QString& group, | ||
455 | const OKeyPair::List& black, | ||
456 | bool grabkeyboard, QObject* par, | ||
457 | const char* name) | ||
458 | : QObject( par, name ), m_conf( conf ), m_group( group ), | ||
459 | m_blackKeys( black ), m_grab( grabkeyboard ), m_map( 0 ){ | ||
460 | if ( m_grab ) | ||
461 | QPEApplication::grabKeyboard(); | ||
462 | } | ||
463 | |||
464 | |||
465 | /** | ||
466 | * Destructor | ||
467 | */ | ||
468 | OKeyConfigManager::~OKeyConfigManager() { | ||
469 | if ( m_grab ) | ||
470 | QPEApplication::ungrabKeyboard(); | ||
471 | } | ||
472 | |||
473 | /** | ||
474 | * Load the Configuration from the OConfig | ||
475 | * If a Key is restricted but was in the config we will | ||
476 | * make it be the empty key paur | ||
477 | * We will change the group but restore to the previous. | ||
478 | * | ||
479 | * @see OKeyPair::emptyKey | ||
480 | */ | ||
481 | void OKeyConfigManager::load() { | ||
482 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
483 | |||
484 | /* | ||
485 | * Read each item | ||
486 | */ | ||
487 | int key, mod; | ||
488 | for( OKeyConfigItem::List::Iterator it = m_keys.begin(); it != m_keys.end(); ++it ) { | ||
489 | key = m_conf->readNumEntry( (*it).configKey()+"key", (*it).defaultKeyPair().keycode() ); | ||
490 | mod = m_conf->readNumEntry( (*it).configKey()+"mod", (*it).defaultKeyPair().modifier() ); | ||
491 | OKeyPair okey( key, mod ); | ||
492 | |||
493 | if ( !m_blackKeys.contains( okey ) && key != -1 && mod != -1 ) | ||
494 | (*it).setKeyPair( OKeyPair(key, mod) ); | ||
495 | else | ||
496 | (*it).setKeyPair( OKeyPair::emptyKey() ); | ||
497 | } | ||
498 | delete m_map; m_map = 0; | ||
499 | } | ||
500 | |||
501 | /** | ||
502 | * We will save the current configuration | ||
503 | * to the OConfig. We will change the group but restore | ||
504 | * to the previous | ||
505 | */ | ||
506 | void OKeyConfigManager::save() { | ||
507 | Opie::Core::OConfigGroupSaver( m_conf, m_group ); | ||
508 | |||
509 | /* | ||
510 | * Write each item | ||
511 | */ | ||
512 | for( OKeyConfigItem::List::Iterator it = m_keys.begin();it != m_keys.end(); ++it ) { | ||
513 | /* skip empty items */ | ||
514 | if ( (*it).isEmpty() ) | ||
515 | continue; | ||
516 | OKeyPair pair = (*it).keyPair(); | ||
517 | OKeyPair deft = (*it).defaultKeyPair(); | ||
518 | /* | ||
519 | * don't write if it is the default setting | ||
520 | * FIXME allow to remove Keys from config | ||
521 | if ( (pair.keycode() == deft.keycode()) && | ||
522 | (pair.modifier()== deft.modifier() ) ) | ||
523 | return; | ||
524 | */ | ||
525 | |||
526 | m_conf->writeEntry((*it).configKey()+"key", pair.keycode() ); | ||
527 | m_conf->writeEntry((*it).configKey()+"mod", pair.modifier() ); | ||
528 | } | ||
529 | m_conf->write(); | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * This is function uses a QMap internally but you can have the same keycode | ||
534 | * with different modifier key. The behaviour is undefined if you add a OKeyConfigItem | ||
535 | * with same keycode and modifier key. The GUI takes care that a user can't | ||
536 | * cofigure two keys. | ||
537 | * | ||
538 | * Make sure you call e->ignore if you don't want to handle this event | ||
539 | */ | ||
540 | OKeyConfigItem OKeyConfigManager::handleKeyEvent( QKeyEvent* e ) { | ||
541 | /* | ||
542 | * Fix Up issues with Qt/E, my keybard, and virtual input | ||
543 | * methods | ||
544 | * First my Keyboard delivers 256,512,1024 for shift/ctrl/alt instead of the button state | ||
545 | * Also key() on virtual inputmethods are zero and only ascii. We need to fix upper and lower | ||
546 | * case ascii | ||
547 | */ | ||
548 | int key, mod; | ||
549 | Opie::Ui::Internal::fixupKeys( key, mod, e ); | ||
550 | |||
551 | OKeyConfigItem::List _keyList = keyList( key ); | ||
552 | if ( _keyList.isEmpty() ) | ||
553 | return OKeyConfigItem(); | ||
554 | |||
555 | OKeyConfigItem item; | ||
556 | for ( OKeyConfigItem::List::Iterator it = _keyList.begin(); it != _keyList.end(); | ||
557 | ++it ) { | ||
558 | if ( (*it).keyPair().modifier() == mod ) { | ||
559 | item = *it; | ||
560 | break; | ||
561 | } | ||
562 | |||
563 | } | ||
564 | |||
565 | return item; | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * Return the associated id of the item or -1 if no item | ||
570 | * matched the key | ||
571 | * | ||
572 | * @see handleKeyEvent | ||
573 | */ | ||
574 | int OKeyConfigManager::handleKeyEventId( QKeyEvent* ev) { | ||
575 | return handleKeyEvent( ev ).id(); | ||
576 | } | ||
577 | |||
578 | /** | ||
579 | * Add Key Config to the List of items | ||
580 | */ | ||
581 | void OKeyConfigManager::addKeyConfig( const OKeyConfigItem& item ) { | ||
582 | m_keys.append( item ); | ||
583 | delete m_map; m_map = 0; | ||
584 | } | ||
585 | |||
586 | /** | ||
587 | * Remove the Key from the Config. Internal lists will be destroyed | ||
588 | * and rebuild on demand later | ||
589 | */ | ||
590 | void OKeyConfigManager::removeKeyConfig( const OKeyConfigItem& item ) { | ||
591 | m_keys.remove( item ); | ||
592 | delete m_map; m_map = 0; | ||
593 | } | ||
594 | |||
595 | /** | ||
596 | * Clears the complete list | ||
597 | */ | ||
598 | void OKeyConfigManager::clearKeyConfig() { | ||
599 | m_keys.clear(); | ||
600 | delete m_map; m_map = 0; | ||
601 | } | ||
602 | |||
603 | /** | ||
604 | * | ||
605 | */ | ||
606 | Opie::Ui::OKeyConfigItem::List OKeyConfigManager::keyConfigList()const{ | ||
607 | return m_keys; | ||
608 | } | ||
609 | |||
610 | /** | ||
611 | * Add this OKeyPair to the blackList. | ||
612 | * Internal lists will be destroyed | ||
613 | */ | ||
614 | void OKeyConfigManager::addToBlackList( const OKeyPair& key) { | ||
615 | m_blackKeys.append( key ); | ||
616 | delete m_map; m_map = 0; | ||
617 | } | ||
618 | |||
619 | |||
620 | /** | ||
621 | * Remove this OKeyPair from the black List | ||
622 | * Internal lists will be destroyed | ||
623 | */ | ||
624 | void OKeyConfigManager::removeFromBlackList( const OKeyPair& key ) { | ||
625 | m_blackKeys.remove( key ); | ||
626 | delete m_map; m_map = 0; | ||
627 | } | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Clear the blackList | ||
632 | */ | ||
633 | void OKeyConfigManager::clearBlackList() { | ||
634 | m_blackKeys.clear(); | ||
635 | delete m_map; m_map = 0; | ||
636 | } | ||
637 | |||
638 | |||
639 | /** | ||
640 | * Return a copy of the blackList | ||
641 | */ | ||
642 | OKeyPair::List OKeyConfigManager::blackList()const { | ||
643 | return m_blackKeys; | ||
644 | } | ||
645 | |||
646 | |||
647 | /** | ||
648 | * Ask the Manager to handle KeyEvents for you. | ||
649 | * All handled keys will emit a QSignal and return true | ||
650 | * that it handled the keyevent | ||
651 | */ | ||
652 | void OKeyConfigManager::handleWidget( QWidget* wid ) { | ||
653 | wid->installEventFilter( this ); | ||
654 | } | ||
655 | |||
656 | /** | ||
657 | * @internal | ||
658 | */ | ||
659 | bool OKeyConfigManager::eventFilter( QObject* obj, QEvent* ev) { | ||
660 | if ( !obj->isWidgetType() ) | ||
661 | return false; | ||
662 | |||
663 | if ( ev->type() != QEvent::KeyPress && ev->type() != QEvent::KeyRelease ) | ||
664 | return false; | ||
665 | |||
666 | QKeyEvent *key = static_cast<QKeyEvent*>( ev ); | ||
667 | OKeyConfigItem item = handleKeyEvent( key ); | ||
668 | |||
669 | if ( item.isEmpty() ) | ||
670 | return false; | ||
671 | |||
672 | QWidget *wid = static_cast<QWidget*>( obj ); | ||
673 | |||
674 | if ( item.object() && !item.slot().isEmpty() ) { | ||
675 | connect( this, SIGNAL( actionActivated(QWidget*, QKeyEvent*)), | ||
676 | item.object(), item.slot().data() ); | ||
677 | emit actionActivated(wid, key); | ||
678 | disconnect( this, SIGNAL(actionActivated(QWidget*,QKeyEvent*)), | ||
679 | item.object(), item.slot().data() ); | ||
680 | } | ||
681 | emit actionActivated( wid, key, item ); | ||
682 | |||
683 | return true; | ||
684 | } | ||
685 | |||
686 | /** | ||
687 | * @internal | ||
688 | */ | ||
689 | OKeyConfigItem::List OKeyConfigManager::keyList( int keycode) { | ||
690 | /* | ||
691 | * Create the map if not existing anymore | ||
692 | */ | ||
693 | if ( !m_map ) { | ||
694 | m_map = new OKeyMapConfigPrivate; | ||
695 | /* for every key */ | ||
696 | for ( OKeyConfigItem::List::Iterator it = m_keys.begin(); | ||
697 | it!= m_keys.end(); ++it ) { | ||
698 | |||
699 | bool add = true; | ||
700 | /* see if this key is blocked */ | ||
701 | OKeyPair pair = (*it).keyPair(); | ||
702 | for ( OKeyPair::List::Iterator pairIt = m_blackKeys.begin(); | ||
703 | pairIt != m_blackKeys.end(); ++pairIt ) { | ||
704 | if ( (*pairIt).keycode() == pair.keycode() && | ||
705 | (*pairIt).modifier() == pair.modifier() ) { | ||
706 | add = false; | ||
707 | break; | ||
708 | } | ||
709 | } | ||
710 | /* check if we added it */ | ||
711 | if ( add ) | ||
712 | (*m_map)[pair.keycode()].append( *it ); | ||
713 | } | ||
714 | } | ||
715 | return (*m_map)[keycode]; | ||
716 | } | ||
717 | |||
718 | 20 | ||
719 | namespace Opie { | 21 | namespace Opie { |
720 | namespace Ui { | 22 | namespace Ui { |
@@ -762,33 +64,6 @@ namespace Internal { | |||
762 | return QAccel::keyToString( mod + pair.keycode() ); | 64 | return QAccel::keyToString( mod + pair.keycode() ); |
763 | } | 65 | } |
764 | 66 | ||
765 | /* | ||
766 | * the virtual and hardware key events have both issues... | ||
767 | */ | ||
768 | void fixupKeys( int& key, int &mod, QKeyEvent* e ) { | ||
769 | key = e->key(); | ||
770 | mod = e->state(); | ||
771 | /* | ||
772 | * virtual keyboard | ||
773 | * else change the button mod only | ||
774 | */ | ||
775 | if ( key == 0 ) { | ||
776 | key = e->ascii(); | ||
777 | if ( key > 96 && key < 123) | ||
778 | key -= 32; | ||
779 | }else{ | ||
780 | int new_mod = 0; | ||
781 | if ( mod & 256 ) | ||
782 | new_mod |= Qt::ShiftButton; | ||
783 | else if ( mod & 512 ) | ||
784 | new_mod |= Qt::ControlButton; | ||
785 | else if ( mod & 1024 ) | ||
786 | new_mod |= Qt::AltButton; | ||
787 | |||
788 | mod = new_mod == 0? mod : new_mod; | ||
789 | } | ||
790 | } | ||
791 | |||
792 | struct OKeyConfigWidgetPrivate{ | 67 | struct OKeyConfigWidgetPrivate{ |
793 | OKeyConfigWidgetPrivate(const QString& = QString::null, | 68 | OKeyConfigWidgetPrivate(const QString& = QString::null, |
794 | OKeyConfigManager* = 0); | 69 | OKeyConfigManager* = 0); |
@@ -809,8 +84,7 @@ namespace Internal { | |||
809 | } | 84 | } |
810 | 85 | ||
811 | } | 86 | } |
812 | } | 87 | |
813 | } | ||
814 | 88 | ||
815 | 89 | ||
816 | 90 | ||
@@ -1156,7 +430,7 @@ OKeyChooserConfigDialog::OKeyChooserConfigDialog( QWidget* par, const char* nam, | |||
1156 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { | 430 | OKeyChooserConfigDialog::~OKeyChooserConfigDialog() { |
1157 | } | 431 | } |
1158 | 432 | ||
1159 | Opie::Ui::OKeyPair OKeyChooserConfigDialog::keyPair()const{ | 433 | Opie::Core::OKeyPair OKeyChooserConfigDialog::keyPair()const{ |
1160 | return m_keyPair; | 434 | return m_keyPair; |
1161 | } | 435 | } |
1162 | 436 | ||
@@ -1167,7 +441,7 @@ void OKeyChooserConfigDialog::keyPressEvent( QKeyEvent* ev ) { | |||
1167 | return; | 441 | return; |
1168 | 442 | ||
1169 | int mod, key; | 443 | int mod, key; |
1170 | Opie::Ui::Internal::fixupKeys( key,mod, ev ); | 444 | Opie::Core::Internal::fixupKeys( key,mod, ev ); |
1171 | 445 | ||
1172 | /* either we used software keyboard | 446 | /* either we used software keyboard |
1173 | * or we've true support | 447 | * or we've true support |
@@ -1247,3 +521,7 @@ void OKeyChooserConfigDialog::slotTimeUp() { | |||
1247 | m_mod = m_key = 0; | 521 | m_mod = m_key = 0; |
1248 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); | 522 | QTimer::singleShot(0, this, SIGNAL(keyCaptured()) ); |
1249 | } | 523 | } |
524 | |||
525 | |||
526 | } | ||
527 | } | ||
diff --git a/libopie2/opieui/okeyconfigwidget.h b/libopie2/opieui/okeyconfigwidget.h index bb8eb6c..d11054c 100644 --- a/libopie2/opieui/okeyconfigwidget.h +++ b/libopie2/opieui/okeyconfigwidget.h | |||
@@ -7,14 +7,10 @@ | |||
7 | #ifndef ODP_KEY_CONFIG_WIDGET_H | 7 | #ifndef ODP_KEY_CONFIG_WIDGET_H |
8 | #define ODP_KEY_CONFIG_WIDGET_H | 8 | #define ODP_KEY_CONFIG_WIDGET_H |
9 | 9 | ||
10 | #include <opie2/oconfig.h> | 10 | #include <opie2/okeyconfigmanager.h> |
11 | #include <opie2/odevice.h> | ||
12 | 11 | ||
13 | #include <qstring.h> | ||
14 | #include <qpixmap.h> | ||
15 | #include <qcstring.h> | ||
16 | #include <qhbox.h> | 12 | #include <qhbox.h> |
17 | #include <qvaluelist.h> | 13 | |
18 | 14 | ||
19 | class QKeyEvent; | 15 | class QKeyEvent; |
20 | class QLabel; | 16 | class QLabel; |
@@ -33,187 +29,6 @@ namespace Internal { | |||
33 | class OListViewItem; | 29 | class OListViewItem; |
34 | class OListView; | 30 | class OListView; |
35 | 31 | ||
36 | /** | ||
37 | * \brief small class representing a Key with possible modifiers | ||
38 | * This class holds information about key code and possible | ||
39 | * modifier state. That is the lowest level of the key input | ||
40 | * functions. | ||
41 | * There are also static methods to get special keys. | ||
42 | * OKeyPair will be used with \see OKeyConfigItem | ||
43 | * | ||
44 | * @since 1.2 | ||
45 | */ | ||
46 | class OKeyPair { | ||
47 | public: | ||
48 | typedef QValueList<OKeyPair> List; | ||
49 | OKeyPair( int key = -1, int modifier = -1); | ||
50 | ~OKeyPair(); | ||
51 | |||
52 | bool operator==( const OKeyPair& )const; | ||
53 | bool operator!=( const OKeyPair& )const; | ||
54 | |||
55 | bool isEmpty()const; | ||
56 | |||
57 | int keycode()const; | ||
58 | int modifier()const; | ||
59 | |||
60 | void setKeycode( int ); | ||
61 | void setModifier( int ); | ||
62 | |||
63 | static OKeyPair returnKey(); | ||
64 | static OKeyPair leftArrowKey(); | ||
65 | static OKeyPair rightArrowKey(); | ||
66 | static OKeyPair upArrowKey(); | ||
67 | static OKeyPair downArrowKey(); | ||
68 | static OKeyPair emptyKey(); | ||
69 | static OKeyPair::List hardwareKeys(); | ||
70 | |||
71 | private: | ||
72 | int m_key; | ||
73 | int m_mod; | ||
74 | class Private; | ||
75 | Private* d; | ||
76 | }; | ||
77 | |||
78 | /** | ||
79 | * A class to represent an OKeyPair. | ||
80 | * It consists out of a Text exposed to the user, Config Key Item, | ||
81 | * Pixmap, A default OKeyPair and the set OKeyPair. | ||
82 | * You can also pass an id to it | ||
83 | * | ||
84 | * @since 1.1.2 | ||
85 | */ | ||
86 | class OKeyConfigItem { | ||
87 | friend class OKeyConfigManager; | ||
88 | public: | ||
89 | typedef QValueList<OKeyConfigItem> List; | ||
90 | OKeyConfigItem( const QString& text = QString::null , const QCString& config_key = QCString(), | ||
91 | const QPixmap& symbol = QPixmap(), | ||
92 | int id = -1, | ||
93 | const OKeyPair& def = OKeyPair::emptyKey(), | ||
94 | QObject *caller = 0, const char* slot = 0); | ||
95 | OKeyConfigItem( const Opie::Core::ODeviceButton& ); | ||
96 | ~OKeyConfigItem(); | ||
97 | |||
98 | bool operator==( const OKeyConfigItem& )const; | ||
99 | bool operator!=( const OKeyConfigItem& )const; | ||
100 | |||
101 | QString text()const; | ||
102 | QPixmap pixmap()const; | ||
103 | int id()const; | ||
104 | |||
105 | |||
106 | |||
107 | OKeyPair keyPair()const; | ||
108 | OKeyPair defaultKeyPair()const; | ||
109 | QCString configKey()const; | ||
110 | |||
111 | |||
112 | void setText( const QString& text ); | ||
113 | void setPixmap( const QPixmap& ); | ||
114 | void setKeyPair( const OKeyPair& ); | ||
115 | void setDefaultKeyPair( const OKeyPair& ); | ||
116 | |||
117 | bool isEmpty()const; | ||
118 | |||
119 | protected: | ||
120 | QObject *object()const; | ||
121 | QCString slot()const; | ||
122 | void setId( int id ); | ||
123 | void setConfigKey( const QCString& ); | ||
124 | |||
125 | private: | ||
126 | QString m_text; | ||
127 | QCString m_config; | ||
128 | QPixmap m_pix; | ||
129 | int m_id; | ||
130 | OKeyPair m_key; | ||
131 | OKeyPair m_def; | ||
132 | QObject *m_obj; | ||
133 | QCString m_str; | ||
134 | class Private; | ||
135 | Private *d; | ||
136 | }; | ||
137 | |||
138 | |||
139 | |||
140 | /** | ||
141 | * \brief A manager to load and save Key Actions and get notified | ||
142 | * This is the Manager for KeyActions. | ||
143 | * You can say from which config and group to read data, to grab the | ||
144 | * keyboard to handle hardware keys, you can supply a blacklist of | ||
145 | * keys which should not be used by allowed to be used. | ||
146 | * You can even pass this manager to a Widget to do the configuration for you. | ||
147 | * You need to add OKeyConfigItem for your keys and then issue a load() to | ||
148 | * read the Key information. | ||
149 | * You can either handle the QKeyEvent yourself and ask this class if it is | ||
150 | * handled by your action and let give you the action. Or you can install | ||
151 | * the event filter and get a signal. | ||
152 | * You need to load ans save yourself! | ||
153 | * | ||
154 | * @since 1.1.2 | ||
155 | */ | ||
156 | class OKeyConfigManager : public QObject { | ||
157 | Q_OBJECT | ||
158 | typedef QMap<int, OKeyConfigItem::List> OKeyMapConfigPrivate; | ||
159 | public: | ||
160 | OKeyConfigManager(Opie::Core::OConfig *conf = 0, | ||
161 | const QString& group = QString::null, | ||
162 | const OKeyPair::List &block = OKeyPair::List(), | ||
163 | bool grabkeyboard = false, QObject * par = 0, | ||
164 | const char* name = 0 ); | ||
165 | ~OKeyConfigManager(); | ||
166 | |||
167 | void load(); | ||
168 | void save(); | ||
169 | |||
170 | OKeyConfigItem handleKeyEvent( QKeyEvent* ); | ||
171 | int handleKeyEventId( QKeyEvent* ); | ||
172 | |||
173 | void addKeyConfig( const OKeyConfigItem& ); | ||
174 | void removeKeyConfig( const OKeyConfigItem& ); | ||
175 | void clearKeyConfig(); | ||
176 | |||
177 | void addToBlackList( const OKeyPair& ); | ||
178 | void removeFromBlackList( const OKeyPair& ); | ||
179 | void clearBlackList(); | ||
180 | OKeyPair::List blackList()const; | ||
181 | |||
182 | void handleWidget( QWidget* ); | ||
183 | |||
184 | bool eventFilter( QObject*, QEvent* ); | ||
185 | |||
186 | OKeyConfigItem::List keyConfigList()const; | ||
187 | signals: | ||
188 | /** | ||
189 | * The Signals are triggered on KeyPress and KeyRelease! | ||
190 | * You can check the isDown of the QKeyEvent | ||
191 | * @see QKeyEvent | ||
192 | */ | ||
193 | void actionActivated( QWidget*, QKeyEvent*, const Opie::Ui::OKeyConfigItem& ); | ||
194 | |||
195 | /** | ||
196 | * This Signal correspondents to the OKeyConfigItem slot | ||
197 | * and object | ||
198 | * | ||
199 | * @see OKeyConfigItem::slot | ||
200 | * @see OKeyConfigItem::object | ||
201 | */ | ||
202 | void actionActivated( QWidget* par, QKeyEvent* key); | ||
203 | |||
204 | private: | ||
205 | OKeyConfigItem::List keyList( int ); | ||
206 | OKeyConfigItem::List m_keys; | ||
207 | QValueList<QWidget*> m_widgets; | ||
208 | Opie::Core::OConfig *m_conf; | ||
209 | QString m_group; | ||
210 | OKeyPair::List m_blackKeys; | ||
211 | bool m_grab : 1; | ||
212 | OKeyMapConfigPrivate *m_map; | ||
213 | class Private; | ||
214 | Private *d; | ||
215 | }; | ||
216 | |||
217 | 32 | ||
218 | /** | 33 | /** |
219 | * With this Widget you can let the Keyboard Shortcuts | 34 | * With this Widget you can let the Keyboard Shortcuts |
@@ -240,7 +55,7 @@ public: | |||
240 | void setChangeMode( enum ChangeMode ); | 55 | void setChangeMode( enum ChangeMode ); |
241 | ChangeMode changeMode()const; | 56 | ChangeMode changeMode()const; |
242 | 57 | ||
243 | void insert( const QString& name, OKeyConfigManager* ); | 58 | void insert( const QString& name, Opie::Core::OKeyConfigManager* ); |
244 | 59 | ||
245 | void load(); | 60 | void load(); |
246 | void save(); | 61 | void save(); |
@@ -254,9 +69,9 @@ private slots: | |||
254 | 69 | ||
255 | private: | 70 | private: |
256 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, | 71 | static bool sanityCheck( Opie::Ui::Internal::OKeyListViewItem* man, |
257 | const OKeyPair& newItem ); | 72 | const Opie::Core::OKeyPair& newItem ); |
258 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, | 73 | void updateItem( Opie::Ui::Internal::OKeyListViewItem* man, |
259 | const OKeyPair& newItem); | 74 | const Opie::Core::OKeyPair& newItem); |
260 | void initUi(); | 75 | void initUi(); |
261 | Opie::Ui::OListView *m_view; | 76 | Opie::Ui::OListView *m_view; |
262 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; | 77 | Opie::Ui::Internal::OKeyConfigWidgetPrivateList m_list; |
@@ -293,7 +108,7 @@ public: | |||
293 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); | 108 | OKeyChooserConfigDialog( QWidget* parent = 0, const char* name = 0, bool modal = false, WFlags fl = 0 ); |
294 | ~OKeyChooserConfigDialog(); | 109 | ~OKeyChooserConfigDialog(); |
295 | 110 | ||
296 | OKeyPair keyPair()const; | 111 | Opie::Core::OKeyPair keyPair()const; |
297 | 112 | ||
298 | protected: | 113 | protected: |
299 | void keyPressEvent( QKeyEvent* ); | 114 | void keyPressEvent( QKeyEvent* ); |
@@ -309,7 +124,7 @@ private: | |||
309 | QTimer *m_timer; | 124 | QTimer *m_timer; |
310 | QLabel *m_lbl; | 125 | QLabel *m_lbl; |
311 | bool m_virtKey : 1; | 126 | bool m_virtKey : 1; |
312 | OKeyPair m_keyPair; | 127 | Opie::Core::OKeyPair m_keyPair; |
313 | int m_key, m_mod; | 128 | int m_key, m_mod; |
314 | class Private; | 129 | class Private; |
315 | Private *d; | 130 | Private *d; |
diff --git a/libopie2/opieui/okeyconfigwidget_p.h b/libopie2/opieui/okeyconfigwidget_p.h index 7690846..4dece4d 100644 --- a/libopie2/opieui/okeyconfigwidget_p.h +++ b/libopie2/opieui/okeyconfigwidget_p.h | |||
@@ -3,29 +3,31 @@ | |||
3 | */ | 3 | */ |
4 | #include <opie2/olistview.h> | 4 | #include <opie2/olistview.h> |
5 | 5 | ||
6 | #include <opie2/okeyconfigmanager_p.h> | ||
6 | 7 | ||
7 | namespace Opie { | 8 | namespace Opie { |
8 | namespace Ui { | 9 | namespace Ui { |
9 | namespace Internal { | 10 | namespace Internal { |
10 | static QString keyToString( const OKeyPair& ); | 11 | static QString keyToString( const Opie::Core::OKeyPair& ); |
11 | static void fixupKeys( int&, int&, QKeyEvent* ); | ||
12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { | 12 | class OKeyListViewItem : public Opie::Ui::OListViewItem { |
13 | public: | 13 | public: |
14 | OKeyListViewItem( const OKeyConfigItem& item, OKeyConfigManager*, Opie::Ui::OListViewItem* parent); | 14 | OKeyListViewItem( const Opie::Core::OKeyConfigItem& item, |
15 | Opie::Core::OKeyConfigManager*, | ||
16 | Opie::Ui::OListViewItem* parent); | ||
15 | ~OKeyListViewItem(); | 17 | ~OKeyListViewItem(); |
16 | 18 | ||
17 | void setDefault(); | 19 | void setDefault(); |
18 | 20 | ||
19 | OKeyConfigItem& item(); | 21 | Opie::Core::OKeyConfigItem& item(); |
20 | OKeyConfigItem origItem()const; | 22 | Opie::Core::OKeyConfigItem origItem()const; |
21 | void setItem( const OKeyConfigItem& item ); | 23 | void setItem( const Opie::Core::OKeyConfigItem& item ); |
22 | void updateText(); | 24 | void updateText(); |
23 | 25 | ||
24 | OKeyConfigManager *manager(); | 26 | Opie::Core::OKeyConfigManager *manager(); |
25 | private: | 27 | private: |
26 | OKeyConfigItem m_item; | 28 | Opie::Core::OKeyConfigItem m_item; |
27 | OKeyConfigItem m_origItem; | 29 | Opie::Core::OKeyConfigItem m_origItem; |
28 | OKeyConfigManager* m_manager; | 30 | Opie::Core::OKeyConfigManager* m_manager; |
29 | 31 | ||
30 | }; | 32 | }; |
31 | } | 33 | } |
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 7e4164b..2a49786 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -33,7 +33,7 @@ | |||
33 | #include <qstyle.h> | 33 | #include <qstyle.h> |
34 | 34 | ||
35 | 35 | ||
36 | using Opie::Ui::OKeyConfigItem; | 36 | using Opie::Core::OKeyConfigItem; |
37 | 37 | ||
38 | /* | 38 | /* |
39 | * The Icons, Request Cache and IconViewItem for the IconView | 39 | * The Icons, Request Cache and IconViewItem for the IconView |
@@ -156,7 +156,7 @@ PIconView::~PIconView() { | |||
156 | delete m_viewManager; | 156 | delete m_viewManager; |
157 | } | 157 | } |
158 | 158 | ||
159 | Opie::Ui::OKeyConfigManager* PIconView::manager() { | 159 | Opie::Core::OKeyConfigManager* PIconView::manager() { |
160 | return m_viewManager; | 160 | return m_viewManager; |
161 | } | 161 | } |
162 | 162 | ||
@@ -166,30 +166,30 @@ Opie::Ui::OKeyConfigManager* PIconView::manager() { | |||
166 | * called from the c'tor | 166 | * called from the c'tor |
167 | */ | 167 | */ |
168 | void PIconView::initKeys() { | 168 | void PIconView::initKeys() { |
169 | Opie::Ui::OKeyPair::List lst; | 169 | Opie::Core::OKeyPair::List lst; |
170 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 170 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
171 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 171 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
172 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 172 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
173 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 173 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
174 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 174 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
175 | 175 | ||
176 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 176 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
177 | lst, false,this, "keyconfig name" ); | 177 | lst, false,this, "keyconfig name" ); |
178 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 178 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
179 | Resource::loadPixmap("beam"), BeamItem, | 179 | Resource::loadPixmap("beam"), BeamItem, |
180 | Opie::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 180 | Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
181 | this, SLOT(slotBeam())) ); | 181 | this, SLOT(slotBeam())) ); |
182 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 182 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
183 | Resource::loadPixmap("trash"), DeleteItem, | 183 | Resource::loadPixmap("trash"), DeleteItem, |
184 | Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 184 | Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
185 | this, SLOT(slotTrash())) ); | 185 | this, SLOT(slotTrash())) ); |
186 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 186 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
187 | Resource::loadPixmap("1to1"), ViewItem, | 187 | Resource::loadPixmap("1to1"), ViewItem, |
188 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 188 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
189 | this, SLOT(slotShowImage()))); | 189 | this, SLOT(slotShowImage()))); |
190 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 190 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
191 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 191 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
192 | Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 192 | Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
193 | this, SLOT(slotImageInfo()) ) ); | 193 | this, SLOT(slotImageInfo()) ) ); |
194 | m_viewManager->load(); | 194 | m_viewManager->load(); |
195 | m_viewManager->handleWidget( m_view ); | 195 | m_viewManager->handleWidget( m_view ); |
diff --git a/noncore/graphics/opie-eye/gui/iconview.h b/noncore/graphics/opie-eye/gui/iconview.h index a4ca0bc..9cf7b3e 100644 --- a/noncore/graphics/opie-eye/gui/iconview.h +++ b/noncore/graphics/opie-eye/gui/iconview.h | |||
@@ -19,8 +19,6 @@ class Ir; | |||
19 | namespace Opie { | 19 | namespace Opie { |
20 | namespace Core{ | 20 | namespace Core{ |
21 | class OConfig; | 21 | class OConfig; |
22 | } | ||
23 | namespace Ui { | ||
24 | class OKeyConfigManager; | 22 | class OKeyConfigManager; |
25 | } | 23 | } |
26 | } | 24 | } |
@@ -35,7 +33,7 @@ public: | |||
35 | PIconView( QWidget* wid, Opie::Core::OConfig *cfg ); | 33 | PIconView( QWidget* wid, Opie::Core::OConfig *cfg ); |
36 | ~PIconView(); | 34 | ~PIconView(); |
37 | void resetView(); | 35 | void resetView(); |
38 | Opie::Ui::OKeyConfigManager* manager(); | 36 | Opie::Core::OKeyConfigManager* manager(); |
39 | 37 | ||
40 | signals: | 38 | signals: |
41 | void sig_showInfo( const QString& ); | 39 | void sig_showInfo( const QString& ); |
@@ -73,7 +71,7 @@ private slots: | |||
73 | void slotThumbInfo(const QString&, const QString&); | 71 | void slotThumbInfo(const QString&, const QString&); |
74 | void slotThumbNail(const QString&, const QPixmap&); | 72 | void slotThumbNail(const QString&, const QPixmap&); |
75 | private: | 73 | private: |
76 | Opie::Ui::OKeyConfigManager *m_viewManager; | 74 | Opie::Core::OKeyConfigManager *m_viewManager; |
77 | Opie::Core::OConfig *m_cfg; | 75 | Opie::Core::OConfig *m_cfg; |
78 | QComboBox* m_views; | 76 | QComboBox* m_views; |
79 | QIconView* m_view; | 77 | QIconView* m_view; |
diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.cpp b/noncore/graphics/opie-eye/gui/imageinfoui.cpp index 0b3250c..27a67a6 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.cpp +++ b/noncore/graphics/opie-eye/gui/imageinfoui.cpp | |||
@@ -46,7 +46,7 @@ imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WF | |||
46 | slotChangeName(_path); | 46 | slotChangeName(_path); |
47 | } | 47 | } |
48 | 48 | ||
49 | Opie::Ui::OKeyConfigManager* imageinfo::manager() | 49 | Opie::Core::OKeyConfigManager* imageinfo::manager() |
50 | { | 50 | { |
51 | if (!m_viewManager) { | 51 | if (!m_viewManager) { |
52 | initKeys(); | 52 | initKeys(); |
@@ -63,19 +63,19 @@ void imageinfo::initKeys() | |||
63 | m_cfg->setGroup("imageinfo_keys" ); | 63 | m_cfg->setGroup("imageinfo_keys" ); |
64 | } | 64 | } |
65 | #endif | 65 | #endif |
66 | Opie::Ui::OKeyPair::List lst; | 66 | Opie::Core::OKeyPair::List lst; |
67 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 67 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
68 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 68 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
69 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 69 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
70 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 70 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
71 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 71 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
72 | 72 | ||
73 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "imageinfo_keys", | 73 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "imageinfo_keys", |
74 | lst, false,this, "keyconfig name" ); | 74 | lst, false,this, "keyconfig name" ); |
75 | m_viewManager->addKeyConfig( Opie::Ui::OKeyConfigItem(tr("View Full Image"), "infoview", | 75 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Full Image"), "infoview", |
76 | Resource::loadPixmap("1to1"), ViewItem, | 76 | Resource::loadPixmap("1to1"), ViewItem, |
77 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 77 | Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
78 | this, SLOT(slotShowImage()))); | 78 | this, SLOT(slotShowImage()))); |
79 | m_viewManager->load(); | 79 | m_viewManager->load(); |
80 | m_viewManager->handleWidget( this ); | 80 | m_viewManager->handleWidget( this ); |
81 | m_viewManager->handleWidget( TextView1 ); | 81 | m_viewManager->handleWidget( TextView1 ); |
diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.h b/noncore/graphics/opie-eye/gui/imageinfoui.h index c9b83a1..bc99bf9 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.h +++ b/noncore/graphics/opie-eye/gui/imageinfoui.h | |||
@@ -15,8 +15,6 @@ class QTextView; | |||
15 | namespace Opie { | 15 | namespace Opie { |
16 | namespace Core { | 16 | namespace Core { |
17 | class OConfig; | 17 | class OConfig; |
18 | } | ||
19 | namespace Ui { | ||
20 | class OKeyConfigManager; | 18 | class OKeyConfigManager; |
21 | } | 19 | } |
22 | } | 20 | } |
@@ -34,7 +32,7 @@ public: | |||
34 | virtual ~imageinfo(); | 32 | virtual ~imageinfo(); |
35 | 33 | ||
36 | void setDestructiveClose(); | 34 | void setDestructiveClose(); |
37 | Opie::Ui::OKeyConfigManager* manager(); | 35 | Opie::Core::OKeyConfigManager* manager(); |
38 | 36 | ||
39 | signals: | 37 | signals: |
40 | void dispImage(const QString&); | 38 | void dispImage(const QString&); |
@@ -56,7 +54,7 @@ protected: | |||
56 | QString currentFile; | 54 | QString currentFile; |
57 | 55 | ||
58 | Opie::Core::OConfig * m_cfg; | 56 | Opie::Core::OConfig * m_cfg; |
59 | Opie::Ui::OKeyConfigManager*m_viewManager; | 57 | Opie::Core::OKeyConfigManager*m_viewManager; |
60 | void initKeys(); | 58 | void initKeys(); |
61 | 59 | ||
62 | protected slots: | 60 | protected slots: |
diff --git a/noncore/graphics/opie-eye/gui/imageview.cpp b/noncore/graphics/opie-eye/gui/imageview.cpp index e43bbff..2078b19 100644 --- a/noncore/graphics/opie-eye/gui/imageview.cpp +++ b/noncore/graphics/opie-eye/gui/imageview.cpp | |||
@@ -23,7 +23,7 @@ ImageView::~ImageView() | |||
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | Opie::Ui::OKeyConfigManager* ImageView::manager() | 26 | Opie::Core::OKeyConfigManager* ImageView::manager() |
27 | { | 27 | { |
28 | if (!m_viewManager) { | 28 | if (!m_viewManager) { |
29 | initKeys(); | 29 | initKeys(); |
@@ -38,18 +38,18 @@ void ImageView::initKeys() | |||
38 | m_cfg = new Opie::Core::OConfig("phunkview"); | 38 | m_cfg = new Opie::Core::OConfig("phunkview"); |
39 | m_cfg->setGroup("image_view_keys" ); | 39 | m_cfg->setGroup("image_view_keys" ); |
40 | } | 40 | } |
41 | Opie::Ui::OKeyPair::List lst; | 41 | Opie::Core::OKeyPair::List lst; |
42 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 42 | lst.append( Opie::Core::OKeyPair::upArrowKey() ); |
43 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 43 | lst.append( Opie::Core::OKeyPair::downArrowKey() ); |
44 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 44 | lst.append( Opie::Core::OKeyPair::leftArrowKey() ); |
45 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 45 | lst.append( Opie::Core::OKeyPair::rightArrowKey() ); |
46 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 46 | lst.append( Opie::Core::OKeyPair::returnKey() ); |
47 | 47 | ||
48 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "image_view_keys", | 48 | m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys", |
49 | lst, false,this, "image_view_keys" ); | 49 | lst, false,this, "image_view_keys" ); |
50 | m_viewManager->addKeyConfig( Opie::Ui::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", | 50 | m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo", |
51 | Resource::loadPixmap("1to1"), ViewInfo, | 51 | Resource::loadPixmap("1to1"), ViewInfo, |
52 | Opie::Ui::OKeyPair(Qt::Key_I,Qt::ShiftButton), | 52 | Opie::Core::OKeyPair(Qt::Key_I,Qt::ShiftButton), |
53 | this, SLOT(slotShowImageInfo()))); | 53 | this, SLOT(slotShowImageInfo()))); |
54 | m_viewManager->handleWidget( this ); | 54 | m_viewManager->handleWidget( this ); |
55 | m_viewManager->load(); | 55 | m_viewManager->load(); |
diff --git a/noncore/graphics/opie-eye/gui/imageview.h b/noncore/graphics/opie-eye/gui/imageview.h index f61c93f..87e2b32 100644 --- a/noncore/graphics/opie-eye/gui/imageview.h +++ b/noncore/graphics/opie-eye/gui/imageview.h | |||
@@ -7,8 +7,6 @@ | |||
7 | namespace Opie { | 7 | namespace Opie { |
8 | namespace Core { | 8 | namespace Core { |
9 | class OConfig; | 9 | class OConfig; |
10 | } | ||
11 | namespace Ui { | ||
12 | class OKeyConfigManager; | 10 | class OKeyConfigManager; |
13 | } | 11 | } |
14 | } | 12 | } |
@@ -24,7 +22,7 @@ class ImageView:public ImageScrollView | |||
24 | public: | 22 | public: |
25 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); | 23 | ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name = 0, WFlags fl = 0 ); |
26 | virtual ~ImageView(); | 24 | virtual ~ImageView(); |
27 | Opie::Ui::OKeyConfigManager* manager(); | 25 | Opie::Core::OKeyConfigManager* manager(); |
28 | 26 | ||
29 | signals: | 27 | signals: |
30 | void dispImageInfo(const QString&); | 28 | void dispImageInfo(const QString&); |
@@ -32,7 +30,7 @@ signals: | |||
32 | 30 | ||
33 | protected: | 31 | protected: |
34 | Opie::Core::OConfig * m_cfg; | 32 | Opie::Core::OConfig * m_cfg; |
35 | Opie::Ui::OKeyConfigManager*m_viewManager; | 33 | Opie::Core::OKeyConfigManager*m_viewManager; |
36 | void initKeys(); | 34 | void initKeys(); |
37 | protected slots: | 35 | protected slots: |
38 | virtual void slotShowImageInfo(); | 36 | virtual void slotShowImageInfo(); |
diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index 042d568..59dba30 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h | |||
@@ -14,9 +14,11 @@ | |||
14 | 14 | ||
15 | namespace Opie { | 15 | namespace Opie { |
16 | namespace Ui{ | 16 | namespace Ui{ |
17 | class OKeyConfigManager; | ||
18 | class OWidgetStack; | 17 | class OWidgetStack; |
19 | } | 18 | } |
19 | namespace Core{ | ||
20 | class OKeyConfigManager; | ||
21 | } | ||
20 | } | 22 | } |
21 | 23 | ||
22 | class PIconView; | 24 | class PIconView; |