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