-rw-r--r-- | core/settings/button/buttonsettings.cpp | 14 |
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,66 +1,67 @@ | |||
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 | ||
39 | using namespace Opie::Core; | 40 | using namespace Opie::Core; |
40 | 41 | ||
41 | struct buttoninfo { | 42 | struct 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 | ||
58 | ButtonSettings::ButtonSettings ( QWidget *parent , const char *, bool, WFlags ) | 59 | ButtonSettings::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 ); |
@@ -124,70 +125,73 @@ ButtonSettings::ButtonSettings ( QWidget *parent , const char *, bool, WFlags | |||
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 | ||
146 | ButtonSettings::~ButtonSettings ( ) | 147 | ButtonSettings::~ButtonSettings ( ) |
147 | { | 148 | { |
148 | QPEApplication::ungrabKeyboard ( ); | 149 | QPEApplication::ungrabKeyboard ( ); |
149 | } | 150 | } |
150 | 151 | ||
151 | void ButtonSettings::updateLabels ( ) | 152 | void 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 | ||
166 | buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key ) | 170 | buttoninfo *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 | ||
175 | void ButtonSettings::keyPressEvent ( QKeyEvent *e ) | 179 | void 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 | ||
188 | void ButtonSettings::keyReleaseEvent ( QKeyEvent *e ) | 192 | void 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 ( ); |