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