summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/button/buttonsettings.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/core/settings/button/buttonsettings.cpp b/core/settings/button/buttonsettings.cpp
index d286369..779f6ef 100644
--- a/core/settings/button/buttonsettings.cpp
+++ b/core/settings/button/buttonsettings.cpp
@@ -1,254 +1,258 @@
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 <opie2/odevice.h>
29
30#include <qpe/applnk.h>
31
28#include <qlayout.h> 32#include <qlayout.h>
29#include <qlabel.h> 33#include <qlabel.h>
30#include <qtimer.h> 34#include <qtimer.h>
31 35
32
33#include <opie2/odevice.h>
34
35#include "buttonsettings.h" 36#include "buttonsettings.h"
36#include "buttonutils.h" 37#include "buttonutils.h"
37#include "remapdlg.h" 38#include "remapdlg.h"
38 39
39using namespace Opie::Core; 40using namespace Opie::Core;
40 41
41struct buttoninfo { 42struct buttoninfo {
42 const ODeviceButton *m_button; 43 const ODeviceButton *m_button;
43 int m_index; 44 int m_index;
44 45
45 OQCopMessage m_pmsg; 46 OQCopMessage m_pmsg;
46 QLabel *m_picon; 47 QLabel *m_picon;
47 QLabel *m_plabel; 48 QLabel *m_plabel;
48 49
49 OQCopMessage m_hmsg; 50 OQCopMessage m_hmsg;
50 QLabel *m_hicon; 51 QLabel *m_hicon;
51 QLabel *m_hlabel; 52 QLabel *m_hlabel;
52 53
53 bool m_pdirty : 1; 54 bool m_pdirty : 1;
54 bool m_hdirty : 1; 55 bool m_hdirty : 1;
55}; 56};
56 57
57 58
58ButtonSettings::ButtonSettings ( QWidget *parent , const char *, bool, WFlags ) 59ButtonSettings::ButtonSettings ( QWidget *parent , const char *, bool, WFlags )
59 : QDialog ( parent, "ButtonSettings", false, WStyle_ContextHelp ) 60 : QDialog ( parent, "ButtonSettings", false, WStyle_ContextHelp )
60{ 61{
61 const QValueList <ODeviceButton> &buttons = ODevice::inst ( )-> buttons ( ); 62 const QValueList <ODeviceButton> &buttons = ODevice::inst ( )-> buttons ( );
62 (void) ButtonUtils::inst ( ); // initialise 63 (void) ButtonUtils::inst ( ); // initialise
63 64
64 setCaption ( tr( "Button Settings" )); 65 setCaption ( tr( "Button Settings" ));
65 66
66 QVBoxLayout *toplay = new QVBoxLayout ( this, 3, 3 ); 67 QVBoxLayout *toplay = new QVBoxLayout ( this, 3, 3 );
67 68
68 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 );
69 toplay-> addWidget ( l ); 70 toplay-> addWidget ( l );
70 71
71 QGridLayout *lay = new QGridLayout ( toplay ); 72 QGridLayout *lay = new QGridLayout ( toplay );
72 lay-> setMargin ( 0 ); 73 lay-> setMargin ( 0 );
73 lay-> setColStretch ( 0, 0 ); 74 lay-> setColStretch ( 0, 0 );
74 lay-> setColStretch ( 1, 0 ); 75 lay-> setColStretch ( 1, 0 );
75 lay-> setColStretch ( 2, 0 ); 76 lay-> setColStretch ( 2, 0 );
76 lay-> setColStretch ( 3, 10 ); 77 lay-> setColStretch ( 3, 10 );
77 78
78 m_infos. setAutoDelete ( true ); 79 m_infos. setAutoDelete ( true );
79 80
80 int i = 1; 81 int i = 1;
81 int index = 0; 82 int index = 0;
82 for ( QValueList<ODeviceButton>::ConstIterator it = buttons. begin ( ); it != buttons. end ( ); it++ ) { 83 for ( QValueList<ODeviceButton>::ConstIterator it = buttons. begin ( ); it != buttons. end ( ); it++ ) {
83 if ( it != buttons. begin ( )) { 84 if ( it != buttons. begin ( )) {
84 QFrame *f = new QFrame ( this ); 85 QFrame *f = new QFrame ( this );
85 f-> setFrameStyle ( QFrame::Sunken | QFrame::VLine ); 86 f-> setFrameStyle ( QFrame::Sunken | QFrame::VLine );
86 lay-> addMultiCellWidget ( f, i, i, 0, 3 ); 87 lay-> addMultiCellWidget ( f, i, i, 0, 3 );
87 i++; 88 i++;
88 } 89 }
89 90
90 buttoninfo *bi = new buttoninfo ( ); 91 buttoninfo *bi = new buttoninfo ( );
91 bi-> m_button = &(*it); 92 bi-> m_button = &(*it);
92 bi-> m_index = index++; 93 bi-> m_index = index++;
93 bi-> m_pmsg = (*it). pressedAction ( ); 94 bi-> m_pmsg = (*it). pressedAction ( );
94 bi-> m_hmsg = (*it). heldAction ( ); 95 bi-> m_hmsg = (*it). heldAction ( );
95 bi-> m_pdirty = false; 96 bi-> m_pdirty = false;
96 bi-> m_hdirty = false; 97 bi-> m_hdirty = false;
97 98
98 l = new QLabel ( this ); 99 l = new QLabel ( this );
99 l-> setPixmap (( *it ). pixmap ( )); 100 l-> setPixmap (( *it ). pixmap ( ));
100 101
101 lay-> addMultiCellWidget ( l, i, i + 1, 0, 0 ); 102 lay-> addMultiCellWidget ( l, i, i + 1, 0, 0 );
102 103
103 l = new QLabel ( tr( "Press:" ), this ); 104 l = new QLabel ( tr( "Press:" ), this );
104 lay-> addWidget ( l, i, 1, AlignLeft | AlignBottom ); 105 lay-> addWidget ( l, i, 1, AlignLeft | AlignBottom );
105 l = new QLabel ( tr( "Hold:" ), this ); 106 l = new QLabel ( tr( "Hold:" ), this );
106 lay-> addWidget ( l, i + 1, 1, AlignLeft | AlignTop ); 107 lay-> addWidget ( l, i + 1, 1, AlignLeft | AlignTop );
107 108
108 l = new QLabel ( this ); 109 l = new QLabel ( this );
109 l-> setFixedSize ( 16, 16 ); 110 l-> setFixedSize ( 16, 16 );
110 lay-> addWidget ( l, i, 2, AlignLeft | AlignBottom ); 111 lay-> addWidget ( l, i, 2, AlignLeft | AlignBottom );
111 bi-> m_picon = l; 112 bi-> m_picon = l;
112 113
113 l = new QLabel ( this ); 114 l = new QLabel ( this );
114 l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); 115 l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine );
115 lay-> addWidget ( l, i, 3, AlignLeft | AlignBottom ); 116 lay-> addWidget ( l, i, 3, AlignLeft | AlignBottom );
116 bi-> m_plabel = l; 117 bi-> m_plabel = l;
117 118
118 l = new QLabel ( this ); 119 l = new QLabel ( this );
119 l-> setFixedSize ( 16, 16 ); 120 l-> setFixedSize ( 16, 16 );
120 lay-> addWidget ( l, i + 1, 2, AlignLeft | AlignTop ); 121 lay-> addWidget ( l, i + 1, 2, AlignLeft | AlignTop );
121 bi-> m_hicon = l; 122 bi-> m_hicon = l;
122 123
123 l = new QLabel ( this ); 124 l = new QLabel ( this );
124 l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine ); 125 l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine );
125 lay-> addWidget ( l, i + 1, 3, AlignLeft | AlignTop ); 126 lay-> addWidget ( l, i + 1, 3, AlignLeft | AlignTop );
126 bi-> m_hlabel = l; 127 bi-> m_hlabel = l;
127 128
128 i += 2; 129 i += 2;
129 130
130 m_infos. append ( bi ); 131 m_infos. append ( bi );
131 } 132 }
132 133
133 toplay-> addStretch ( 10 ); 134 toplay-> addStretch ( 10 );
134 135
135 m_last_button = 0; 136 m_last_button = 0;
136 m_lock = false; 137 m_lock = false;
137 138
138 m_timer = new QTimer ( this ); 139 m_timer = new QTimer ( this );
139 connect ( m_timer, SIGNAL( timeout()), this, SLOT( keyTimeout())); 140 connect ( m_timer, SIGNAL( timeout()), this, SLOT( keyTimeout()));
140 141
141 updateLabels ( ); 142 updateLabels ( );
142 143
143 QPEApplication::grabKeyboard ( ); 144 QPEApplication::grabKeyboard ( );
144} 145}
145 146
146ButtonSettings::~ButtonSettings ( ) 147ButtonSettings::~ButtonSettings ( )
147{ 148{
148 QPEApplication::ungrabKeyboard ( ); 149 QPEApplication::ungrabKeyboard ( );
149} 150}
150 151
151void ButtonSettings::updateLabels ( ) 152void ButtonSettings::updateLabels ( )
152{ 153{
153 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { 154 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
154 qCopInfo cip = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_pmsg ); 155 qCopInfo cip = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_pmsg );
155 156
156 (*it)-> m_picon-> setPixmap ( cip. m_icon ); 157 QPixmap pic;
158 pic.convertFromImage( cip.m_icon.convertToImage().smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
159 (*it)-> m_picon-> setPixmap ( pic );
157 (*it)-> m_plabel-> setText ( cip. m_name ); 160 (*it)-> m_plabel-> setText ( cip. m_name );
158 161
159 qCopInfo cih = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_hmsg ); 162 qCopInfo cih = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_hmsg );
160 163
161 (*it)-> m_hicon-> setPixmap ( cih. m_icon ); 164 pic.convertFromImage( cih.m_icon.convertToImage().smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
165 (*it)-> m_hicon-> setPixmap ( pic );
162 (*it)-> m_hlabel-> setText ( cih. m_name ); 166 (*it)-> m_hlabel-> setText ( cih. m_name );
163 } 167 }
164} 168}
165 169
166buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key ) 170buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key )
167{ 171{
168 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { 172 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
169 if ((*it)-> m_button-> keycode ( ) == key ) 173 if ((*it)-> m_button-> keycode ( ) == key )
170 return *it; 174 return *it;
171 } 175 }
172 return 0; 176 return 0;
173} 177}
174 178
175void ButtonSettings::keyPressEvent ( QKeyEvent *e ) 179void ButtonSettings::keyPressEvent ( QKeyEvent *e )
176{ 180{
177 buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); 181 buttoninfo *bi = buttonInfoForKeycode ( e-> key ( ));
178 182
179 if ( bi && !e-> isAutoRepeat ( )) { 183 if ( bi && !e-> isAutoRepeat ( )) {
180 m_timer-> stop ( ); 184 m_timer-> stop ( );
181 m_last_button = bi; 185 m_last_button = bi;
182 m_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true ); 186 m_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true );
183 } 187 }
184 else 188 else
185 QDialog::keyPressEvent ( e ); 189 QDialog::keyPressEvent ( e );
186} 190}
187 191
188void ButtonSettings::keyReleaseEvent ( QKeyEvent *e ) 192void ButtonSettings::keyReleaseEvent ( QKeyEvent *e )
189{ 193{
190 buttoninfo *bi = buttonInfoForKeycode ( e-> key ( )); 194 buttoninfo *bi = buttonInfoForKeycode ( e-> key ( ));
191 195
192 if ( bi && !e-> isAutoRepeat ( ) && m_timer-> isActive ( )) { 196 if ( bi && !e-> isAutoRepeat ( ) && m_timer-> isActive ( )) {
193 m_timer-> stop ( ); 197 m_timer-> stop ( );
194 edit ( bi, false ); 198 edit ( bi, false );
195 } 199 }
196 else 200 else
197 QDialog::keyReleaseEvent ( e ); 201 QDialog::keyReleaseEvent ( e );
198} 202}
199 203
200void ButtonSettings::keyTimeout ( ) 204void ButtonSettings::keyTimeout ( )
201{ 205{
202 if ( m_last_button ) { 206 if ( m_last_button ) {
203 edit ( m_last_button, true ); 207 edit ( m_last_button, true );
204 m_last_button = false; 208 m_last_button = false;
205 } 209 }
206} 210}
207 211
208void ButtonSettings::edit ( buttoninfo *bi, bool hold ) 212void ButtonSettings::edit ( buttoninfo *bi, bool hold )
209{ 213{
210 214
211 if ( m_lock ) 215 if ( m_lock )
212 return; 216 return;
213 m_lock = true; 217 m_lock = true;
214 218
215 RemapDlg *d = new RemapDlg ( bi-> m_button, hold, this ); 219 RemapDlg *d = new RemapDlg ( bi-> m_button, hold, this );
216 220
217 if ( QPEApplication::execDialog ( d ) == QDialog::Accepted ) { 221 if ( QPEApplication::execDialog ( d ) == QDialog::Accepted ) {
218 222
219 223
220 if ( hold ) { 224 if ( hold ) {
221 bi-> m_hmsg = d-> message ( ); 225 bi-> m_hmsg = d-> message ( );
222 bi-> m_hdirty = true; 226 bi-> m_hdirty = true;
223 } 227 }
224 else { 228 else {
225 bi-> m_pmsg = d-> message ( ); 229 bi-> m_pmsg = d-> message ( );
226 bi-> m_pdirty = true; 230 bi-> m_pdirty = true;
227 } 231 }
228 232
229 updateLabels ( ); 233 updateLabels ( );
230 } 234 }
231 235
232 delete d; 236 delete d;
233 237
234 m_lock = false; 238 m_lock = false;
235} 239}
236 240
237void ButtonSettings::accept ( ) 241void ButtonSettings::accept ( )
238{ 242{
239 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) { 243 for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
240 buttoninfo *bi = *it; 244 buttoninfo *bi = *it;
241 245
242 if ( bi-> m_pdirty ) 246 if ( bi-> m_pdirty )
243 ODevice::inst ( )-> remapPressedAction ( bi-> m_index, bi-> m_pmsg ); 247 ODevice::inst ( )-> remapPressedAction ( bi-> m_index, bi-> m_pmsg );
244 if ( bi-> m_hdirty ) 248 if ( bi-> m_hdirty )
245 ODevice::inst ( )-> remapHeldAction ( bi-> m_index, bi-> m_hmsg ); 249 ODevice::inst ( )-> remapHeldAction ( bi-> m_index, bi-> m_hmsg );
246 } 250 }
247 QDialog::accept ( ); 251 QDialog::accept ( );
248} 252}
249 253
250void ButtonSettings::done ( int r ) 254void ButtonSettings::done ( int r )
251{ 255{
252 QDialog::done ( r ); 256 QDialog::done ( r );
253 close ( ); 257 close ( );
254} 258}