-rw-r--r-- | core/settings/button/buttonsettings.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/settings/button/buttonsettings.cpp b/core/settings/button/buttonsettings.cpp index 8b0b0a8..eabb779 100644 --- a/core/settings/button/buttonsettings.cpp +++ b/core/settings/button/buttonsettings.cpp | |||
@@ -1,257 +1,257 @@ | |||
1 | /* | 1 | /* |
2 | =. This file is part of the OPIE Project | 2 | =. This file is part of the OPIE Project |
3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | 3 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> |
4 | .>+-= | 4 | .>+-= |
5 | _;:, .> :=|. This file is free software; you can | 5 | _;:, .> :=|. This file is free software; you can |
6 | .> <`_, > . <= redistribute it and/or modify it under | 6 | .> <`_, > . <= redistribute it and/or modify it under |
7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 7 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
8 | .="- .-=="i, .._ License as published by the Free Software | 8 | .="- .-=="i, .._ License as published by the Free Software |
9 | - . .-<_> .<> Foundation; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
11 | .%`+i> _;_. | 11 | .%`+i> _;_. |
12 | .i_,=:_. -<s. This file is distributed in the hope that | 12 | .i_,=:_. -<s. This file is distributed in the hope that |
13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 13 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
14 | : .. .:, . . . without even the implied warranty of | 14 | : .. .:, . . . without even the implied warranty of |
15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 15 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 16 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
17 | ..}^=.= = ; Public License for more details. | 17 | ..}^=.= = ; Public License for more details. |
18 | ++= -. .` .: | 18 | ++= -. .` .: |
19 | : = ...= . :.=- You should have received a copy of the GNU | 19 | : = ...= . :.=- You should have received a copy of the GNU |
20 | -. .:....=;==+<; General Public License along with this file; | 20 | -. .:....=;==+<; General Public License along with this file; |
21 | -_. . . )=. = see the file COPYING. If not, write to the | 21 | -_. . . )=. = see the file COPYING. If not, write to the |
22 | -- :-=` Free Software Foundation, Inc., | 22 | -- :-=` Free Software Foundation, Inc., |
23 | 59 Temple Place - Suite 330, | 23 | 59 Temple Place - Suite 330, |
24 | Boston, MA 02111-1307, USA. | 24 | Boston, MA 02111-1307, USA. |
25 | 25 | ||
26 | */ | 26 | */ |
27 | 27 | ||
28 | #include <qlayout.h> | 28 | #include <qlayout.h> |
29 | #include <qlabel.h> | 29 | #include <qlabel.h> |
30 | #include <qtimer.h> | 30 | #include <qtimer.h> |
31 | 31 | ||
32 | #include <qpe/qpeapplication.h> | 32 | #include <qpe/qpeapplication.h> |
33 | 33 | ||
34 | #include <opie/odevice.h> | 34 | #include <opie/odevice.h> |
35 | 35 | ||
36 | #include "buttonsettings.h" | 36 | #include "buttonsettings.h" |
37 | #include "buttonutils.h" | 37 | #include "buttonutils.h" |
38 | #include "remapdlg.h" | 38 | #include "remapdlg.h" |
39 | 39 | ||
40 | using namespace Opie; | 40 | using namespace Opie; |
41 | 41 | ||
42 | struct buttoninfo { | 42 | struct buttoninfo { |
43 | const ODeviceButton *m_button; | 43 | const ODeviceButton *m_button; |
44 | int m_index; | 44 | int m_index; |
45 | 45 | ||
46 | OQCopMessage m_pmsg; | 46 | OQCopMessage m_pmsg; |
47 | QLabel *m_picon; | 47 | QLabel *m_picon; |
48 | QLabel *m_plabel; | 48 | QLabel *m_plabel; |
49 | 49 | ||
50 | OQCopMessage m_hmsg; | 50 | OQCopMessage m_hmsg; |
51 | QLabel *m_hicon; | 51 | QLabel *m_hicon; |
52 | QLabel *m_hlabel; | 52 | QLabel *m_hlabel; |
53 | 53 | ||
54 | bool m_pdirty : 1; | 54 | bool m_pdirty : 1; |
55 | bool m_hdirty : 1; | 55 | bool m_hdirty : 1; |
56 | }; | 56 | }; |
57 | 57 | ||
58 | 58 | ||
59 | ButtonSettings::ButtonSettings ( ) | 59 | ButtonSettings::ButtonSettings ( ) |
60 | : QDialog ( 0, "ButtonSettings", false, WStyle_ContextHelp ) | 60 | : QDialog ( 0, "ButtonSettings", false, WStyle_ContextHelp ) |
61 | { | 61 | { |
62 | const QValueList <ODeviceButton> &buttons = ODevice::inst ( )-> buttons ( ); | 62 | const QValueList <ODeviceButton> &buttons = ODevice::inst ( )-> buttons ( ); |
63 | (void) ButtonUtils::inst ( ); // initialise | 63 | (void) ButtonUtils::inst ( ); // initialise |
64 | 64 | ||
65 | setCaption ( tr( "Button Settings" )); | 65 | setCaption ( tr( "Button Settings" )); |
66 | 66 | ||
67 | QVBoxLayout *toplay = new QVBoxLayout ( this, 3, 3 ); | 67 | QVBoxLayout *toplay = new QVBoxLayout ( this, 3, 3 ); |
68 | 68 | ||
69 | QLabel *l = new QLabel ( tr( "<center>Press or hold the button you want to remap.</center>" ), this ); | 69 | QLabel *l = new QLabel ( tr( "<center>Press or hold the button you want to remap.</center>" ), this ); |
70 | toplay-> addWidget ( l ); | 70 | toplay-> addWidget ( l ); |
71 | 71 | ||
72 | QGridLayout *lay = new QGridLayout ( toplay ); | 72 | QGridLayout *lay = new QGridLayout ( toplay ); |
73 | lay-> setMargin ( 0 ); | 73 | lay-> setMargin ( 0 ); |
74 | lay-> setColStretch ( 0, 0 ); | 74 | lay-> setColStretch ( 0, 0 ); |
75 | lay-> setColStretch ( 1, 0 ); | 75 | lay-> setColStretch ( 1, 0 ); |
76 | lay-> setColStretch ( 2, 0 ); | 76 | lay-> setColStretch ( 2, 0 ); |
77 | lay-> setColStretch ( 3, 10 ); | 77 | lay-> setColStretch ( 3, 10 ); |
78 | 78 | ||
79 | m_infos. setAutoDelete ( true ); | 79 | m_infos. setAutoDelete ( true ); |
80 | 80 | ||
81 | int i = 1; | 81 | int i = 1; |
82 | int index = 0; | 82 | int index = 0; |
83 | for ( QValueList<ODeviceButton>::ConstIterator it = buttons. begin ( ); it != buttons. end ( ); it++ ) { | 83 | for ( QValueList<ODeviceButton>::ConstIterator it = buttons. begin ( ); it != buttons. end ( ); it++ ) { |
84 | if ( it != buttons. begin ( )) { | 84 | if ( it != buttons. begin ( )) { |
85 | QFrame *f = new QFrame ( this ); | 85 | QFrame *f = new QFrame ( this ); |
86 | f-> setFrameStyle ( QFrame::Sunken | QFrame::VLine ); | 86 | f-> setFrameStyle ( QFrame::Sunken | QFrame::VLine ); |
87 | lay-> addMultiCellWidget ( f, i, i, 0, 2 ); | 87 | lay-> addMultiCellWidget ( f, i, i, 0, 3 ); |
88 | i++; | 88 | i++; |
89 | } | 89 | } |
90 | 90 | ||
91 | buttoninfo *bi = new buttoninfo ( ); | 91 | buttoninfo *bi = new buttoninfo ( ); |
92 | bi-> m_button = &(*it); | 92 | bi-> m_button = &(*it); |
93 | bi-> m_index = index++; | 93 | bi-> m_index = index++; |
94 | bi-> m_pmsg = (*it). pressedAction ( ); | 94 | bi-> m_pmsg = (*it). pressedAction ( ); |
95 | bi-> m_hmsg = (*it). heldAction ( ); | 95 | bi-> m_hmsg = (*it). heldAction ( ); |
96 | bi-> m_pdirty = false; | 96 | bi-> m_pdirty = false; |
97 | bi-> m_hdirty = false; | 97 | bi-> m_hdirty = false; |
98 | 98 | ||
99 | l = new QLabel ( this ); | 99 | l = new QLabel ( this ); |
100 | l-> setPixmap (( *it ). pixmap ( )); | 100 | l-> setPixmap (( *it ). pixmap ( )); |
101 | 101 | ||
102 | lay-> addMultiCellWidget ( l, i, i + 1, 0, 0 ); | 102 | lay-> addMultiCellWidget ( l, i, i + 1, 0, 0 ); |
103 | 103 | ||
104 | l = new QLabel ( tr( "Press:" ), this ); | 104 | l = new QLabel ( tr( "Press:" ), this ); |
105 | lay-> addWidget ( l, i, 1, AlignLeft | AlignBottom ); | 105 | lay-> addWidget ( l, i, 1, AlignLeft | AlignBottom ); |
106 | l = new QLabel ( tr( "Hold:" ), this ); | 106 | l = new QLabel ( tr( "Hold:" ), this ); |
107 | lay-> addWidget ( l, i + 1, 1, AlignLeft | AlignTop ); | 107 | lay-> addWidget ( l, i + 1, 1, AlignLeft | AlignTop ); |
108 | 108 | ||
109 | l = new QLabel ( this ); | 109 | l = new QLabel ( this ); |
110 | l-> setFixedSize ( 16, 16 ); | 110 | l-> setFixedSize ( 16, 16 ); |
111 | lay-> addWidget ( l, i, 2, AlignLeft | AlignBottom ); | 111 | lay-> addWidget ( l, i, 2, AlignLeft | AlignBottom ); |
112 | bi-> m_picon = l; | 112 | bi-> m_picon = l; |
113 | 113 | ||
114 | l = new QLabel ( this ); | 114 | l = new QLabel ( this ); |
115 | l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); | 115 | l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); |
116 | lay-> addWidget ( l, i, 3, AlignLeft | AlignBottom ); | 116 | lay-> addWidget ( l, i, 3, AlignLeft | AlignBottom ); |
117 | bi-> m_plabel = l; | 117 | bi-> m_plabel = l; |
118 | 118 | ||
119 | l = new QLabel ( this ); | 119 | l = new QLabel ( this ); |
120 | l-> setFixedSize ( 16, 16 ); | 120 | l-> setFixedSize ( 16, 16 ); |
121 | lay-> addWidget ( l, i + 1, 2, AlignLeft | AlignTop ); | 121 | lay-> addWidget ( l, i + 1, 2, AlignLeft | AlignTop ); |
122 | bi-> m_hicon = l; | 122 | bi-> m_hicon = l; |
123 | 123 | ||
124 | l = new QLabel ( this ); | 124 | l = new QLabel ( this ); |
125 | l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); | 125 | l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); |
126 | lay-> addWidget ( l, i + 1, 3, AlignLeft | AlignTop ); | 126 | lay-> addWidget ( l, i + 1, 3, AlignLeft | AlignTop ); |
127 | bi-> m_hlabel = l; | 127 | bi-> m_hlabel = l; |
128 | 128 | ||
129 | i += 2; | 129 | i += 2; |
130 | 130 | ||
131 | m_infos. append ( bi ); | 131 | m_infos. append ( bi ); |
132 | } | 132 | } |
133 | 133 | ||
134 | toplay-> addStretch ( 10 ); | 134 | toplay-> addStretch ( 10 ); |
135 | 135 | ||
136 | m_last_button = 0; | 136 | m_last_button = 0; |
137 | m_lock = false; | 137 | m_lock = false; |
138 | 138 | ||
139 | m_timer = new QTimer ( this ); | 139 | m_timer = new QTimer ( this ); |
140 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( keyTimeout ( ))); | 140 | connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( keyTimeout ( ))); |
141 | 141 | ||
142 | updateLabels ( ); | 142 | updateLabels ( ); |
143 | 143 | ||
144 | QPEApplication::grabKeyboard ( ); | 144 | QPEApplication::grabKeyboard ( ); |
145 | } | 145 | } |
146 | 146 | ||
147 | ButtonSettings::~ButtonSettings ( ) | 147 | ButtonSettings::~ButtonSettings ( ) |
148 | { | 148 | { |
149 | QPEApplication::ungrabKeyboard ( ); | 149 | QPEApplication::ungrabKeyboard ( ); |
150 | } | 150 | } |
151 | 151 | ||
152 | void ButtonSettings::updateLabels ( ) | 152 | void ButtonSettings::updateLabels ( ) |
153 | { | 153 | { |
154 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { | 154 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { |
155 | qCopInfo cip = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_pmsg ); | 155 | qCopInfo cip = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_pmsg ); |
156 | 156 | ||
157 | (*it)-> m_picon-> setPixmap ( cip. m_icon ); | 157 | (*it)-> m_picon-> setPixmap ( cip. m_icon ); |
158 | (*it)-> m_plabel-> setText ( cip. m_name ); | 158 | (*it)-> m_plabel-> setText ( cip. m_name ); |
159 | 159 | ||
160 | qCopInfo cih = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_hmsg ); | 160 | qCopInfo cih = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_hmsg ); |
161 | 161 | ||
162 | (*it)-> m_hicon-> setPixmap ( cih. m_icon ); | 162 | (*it)-> m_hicon-> setPixmap ( cih. m_icon ); |
163 | (*it)-> m_hlabel-> setText ( cih. m_name ); | 163 | (*it)-> m_hlabel-> setText ( cih. m_name ); |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key ) | 167 | buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key ) |
168 | { | 168 | { |
169 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { | 169 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { |
170 | if ((*it)-> m_button-> keycode ( ) == key ) | 170 | if ((*it)-> m_button-> keycode ( ) == key ) |
171 | return *it; | 171 | return *it; |
172 | } | 172 | } |
173 | return 0; | 173 | return 0; |
174 | } | 174 | } |
175 | 175 | ||
176 | void ButtonSettings::keyPressEvent ( QKeyEvent *e ) | 176 | void ButtonSettings::keyPressEvent ( QKeyEvent *e ) |
177 | { | 177 | { |
178 | buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); | 178 | buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); |
179 | 179 | ||
180 | if ( bi && !e-> isAutoRepeat ( )) { | 180 | if ( bi && !e-> isAutoRepeat ( )) { |
181 | m_timer-> stop ( ); | 181 | m_timer-> stop ( ); |
182 | m_last_button = bi; | 182 | m_last_button = bi; |
183 | m_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); | 183 | m_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); |
184 | } | 184 | } |
185 | else | 185 | else |
186 | QDialog::keyPressEvent ( e ); | 186 | QDialog::keyPressEvent ( e ); |
187 | } | 187 | } |
188 | 188 | ||
189 | void ButtonSettings::keyReleaseEvent ( QKeyEvent *e ) | 189 | void ButtonSettings::keyReleaseEvent ( QKeyEvent *e ) |
190 | { | 190 | { |
191 | buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); | 191 | buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); |
192 | 192 | ||
193 | if ( bi && !e-> isAutoRepeat ( ) && m_timer-> isActive ( )) { | 193 | if ( bi && !e-> isAutoRepeat ( ) && m_timer-> isActive ( )) { |
194 | m_timer-> stop ( ); | 194 | m_timer-> stop ( ); |
195 | edit ( bi, false ); | 195 | edit ( bi, false ); |
196 | } | 196 | } |
197 | else | 197 | else |
198 | QDialog::keyReleaseEvent ( e ); | 198 | QDialog::keyReleaseEvent ( e ); |
199 | } | 199 | } |
200 | 200 | ||
201 | void ButtonSettings::keyTimeout ( ) | 201 | void ButtonSettings::keyTimeout ( ) |
202 | { | 202 | { |
203 | if ( m_last_button ) { | 203 | if ( m_last_button ) { |
204 | edit ( m_last_button, true ); | 204 | edit ( m_last_button, true ); |
205 | m_last_button = false; | 205 | m_last_button = false; |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | void ButtonSettings::edit ( buttoninfo *bi, bool hold ) | 209 | void ButtonSettings::edit ( buttoninfo *bi, bool hold ) |
210 | { | 210 | { |
211 | qDebug ( "remap %s for %s", hold ? "hold" : "press", bi-> m_button-> userText ( ). latin1 ( )); | 211 | qDebug ( "remap %s for %s", hold ? "hold" : "press", bi-> m_button-> userText ( ). latin1 ( )); |
212 | 212 | ||
213 | if ( m_lock ) | 213 | if ( m_lock ) |
214 | return; | 214 | return; |
215 | m_lock = true; | 215 | m_lock = true; |
216 | 216 | ||
217 | RemapDlg *d = new RemapDlg ( bi-> m_button, hold, this ); | 217 | RemapDlg *d = new RemapDlg ( bi-> m_button, hold, this ); |
218 | 218 | ||
219 | d-> showMaximized ( ); | 219 | d-> showMaximized ( ); |
220 | if ( d-> exec ( ) == QDialog::Accepted ) { | 220 | if ( d-> exec ( ) == QDialog::Accepted ) { |
221 | qDebug ( " -> %s %s", d-> message ( ). channel ( ). data ( ), d-> message ( ). message ( ). data ( )); | 221 | qDebug ( " -> %s %s", d-> message ( ). channel ( ). data ( ), d-> message ( ). message ( ). data ( )); |
222 | 222 | ||
223 | if ( hold ) { | 223 | if ( hold ) { |
224 | bi-> m_hmsg = d-> message ( ); | 224 | bi-> m_hmsg = d-> message ( ); |
225 | bi-> m_hdirty = true; | 225 | bi-> m_hdirty = true; |
226 | } | 226 | } |
227 | else { | 227 | else { |
228 | bi-> m_pmsg = d-> message ( ); | 228 | bi-> m_pmsg = d-> message ( ); |
229 | bi-> m_pdirty = true; | 229 | bi-> m_pdirty = true; |
230 | } | 230 | } |
231 | 231 | ||
232 | updateLabels ( ); | 232 | updateLabels ( ); |
233 | } | 233 | } |
234 | 234 | ||
235 | delete d; | 235 | delete d; |
236 | 236 | ||
237 | m_lock = false; | 237 | m_lock = false; |
238 | } | 238 | } |
239 | 239 | ||
240 | void ButtonSettings::accept ( ) | 240 | void ButtonSettings::accept ( ) |
241 | { | 241 | { |
242 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { | 242 | for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { |
243 | buttoninfo *bi = *it; | 243 | buttoninfo *bi = *it; |
244 | 244 | ||
245 | if ( bi-> m_pdirty ) | 245 | if ( bi-> m_pdirty ) |
246 | ODevice::inst ( )-> remapPressedAction ( bi-> m_index, bi-> m_pmsg ); | 246 | ODevice::inst ( )-> remapPressedAction ( bi-> m_index, bi-> m_pmsg ); |
247 | if ( bi-> m_hdirty ) | 247 | if ( bi-> m_hdirty ) |
248 | ODevice::inst ( )-> remapHeldAction ( bi-> m_index, bi-> m_hmsg ); | 248 | ODevice::inst ( )-> remapHeldAction ( bi-> m_index, bi-> m_hmsg ); |
249 | } | 249 | } |
250 | QDialog::accept ( ); | 250 | QDialog::accept ( ); |
251 | } | 251 | } |
252 | 252 | ||
253 | void ButtonSettings::done ( int r ) | 253 | void ButtonSettings::done ( int r ) |
254 | { | 254 | { |
255 | QDialog::done ( r ); | 255 | QDialog::done ( r ); |
256 | close ( ); | 256 | close ( ); |
257 | } | 257 | } |