author | sandman <sandman> | 2002-10-28 20:27:14 (UTC) |
---|---|---|
committer | sandman <sandman> | 2002-10-28 20:27:14 (UTC) |
commit | b963230163fc8069731374a19390fd0e5cb42532 (patch) (unidiff) | |
tree | a9a46c7d61e9529afee40f39b03ed01dd744e868 /core/settings/light-and-power/calibration.cpp | |
parent | 052303d29fe4a7b16858398f79f667e57ae569c9 (diff) | |
download | opie-b963230163fc8069731374a19390fd0e5cb42532.zip opie-b963230163fc8069731374a19390fd0e5cb42532.tar.gz opie-b963230163fc8069731374a19390fd0e5cb42532.tar.bz2 |
Major update:
- fixed some layout margins in the ui file
- cleanup in light.cpp (removed the old TT code)
- new sensor calibration dialog
- new copyright headers
!! The launcher does not yet use the sensor calibration data !!
Diffstat (limited to 'core/settings/light-and-power/calibration.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/light-and-power/calibration.cpp | 278 |
1 files changed, 278 insertions, 0 deletions
diff --git a/core/settings/light-and-power/calibration.cpp b/core/settings/light-and-power/calibration.cpp new file mode 100644 index 0000000..307de1f --- a/dev/null +++ b/core/settings/light-and-power/calibration.cpp | |||
@@ -0,0 +1,278 @@ | |||
1 | /* | ||
2 | This file is part of the OPIE Project | ||
3 | =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org> | ||
4 | .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> | ||
5 | .>+-= | ||
6 | _;:, .> :=|. This file is free software; you can | ||
7 | .> <`_, > . <= redistribute it and/or modify it under | ||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | ||
9 | .="- .-=="i, .._ License as published by the Free Software | ||
10 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
11 | ._= =} : or (at your option) any later version. | ||
12 | .%`+i> _;_. | ||
13 | .i_,=:_. -<s. This file is distributed in the hope that | ||
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
15 | : .. .:, . . . without even the implied warranty of | ||
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | ||
18 | ..}^=.= = ; Public License for more details. | ||
19 | ++= -. .` .: | ||
20 | : = ...= . :.=- You should have received a copy of the GNU | ||
21 | -. .:....=;==+<; General Public License along with this file; | ||
22 | -_. . . )=. = see the file COPYING. If not, write to the | ||
23 | -- :-=` Free Software Foundation, Inc., | ||
24 | 59 Temple Place - Suite 330, | ||
25 | Boston, MA 02111-1307, USA. | ||
26 | |||
27 | */ | ||
28 | #include "calibration.h" | ||
29 | |||
30 | #include <qpainter.h> | ||
31 | #include <qpalette.h> | ||
32 | |||
33 | #define BRD 2 | ||
34 | |||
35 | Calibration::Calibration ( QWidget *parent, const char *name, WFlags fl ) | ||
36 | : QWidget ( parent, name, fl ) | ||
37 | { | ||
38 | m_scale = QSize ( 256, 256 ); | ||
39 | m_steps = 5; | ||
40 | m_dragged = -1; | ||
41 | m_interval = 5; | ||
42 | |||
43 | m_p [0] = QPoint ( 0, 0 ); | ||
44 | m_p [1] = QPoint ( 255, 255 ); | ||
45 | } | ||
46 | |||
47 | Calibration::~Calibration ( ) | ||
48 | { | ||
49 | } | ||
50 | |||
51 | void Calibration::setScale ( const QSize &s ) | ||
52 | { | ||
53 | if ( s. width ( ) < 1 || s. height ( ) < 1 ) | ||
54 | return; | ||
55 | |||
56 | m_scale = s; | ||
57 | checkPoints ( ); | ||
58 | |||
59 | update ( ); | ||
60 | } | ||
61 | |||
62 | QSize Calibration::scale ( ) const | ||
63 | { | ||
64 | return m_scale; | ||
65 | } | ||
66 | |||
67 | void Calibration::setLineSteps ( int steps ) | ||
68 | { | ||
69 | if ( m_steps < 2 ) | ||
70 | return; | ||
71 | |||
72 | m_steps = steps; | ||
73 | update ( ); | ||
74 | } | ||
75 | |||
76 | int Calibration::lineSteps ( ) const | ||
77 | { | ||
78 | return m_steps; | ||
79 | } | ||
80 | |||
81 | void Calibration::setInterval ( int iv ) | ||
82 | { | ||
83 | if ( iv < 1 ) | ||
84 | return; | ||
85 | |||
86 | m_interval = iv; | ||
87 | //update ( ); | ||
88 | } | ||
89 | |||
90 | int Calibration::interval ( ) const | ||
91 | { | ||
92 | return m_interval; | ||
93 | } | ||
94 | |||
95 | void Calibration::setStartPoint ( const QPoint &p ) | ||
96 | { | ||
97 | m_p [0] = p; | ||
98 | checkPoints ( ); | ||
99 | update ( ); | ||
100 | } | ||
101 | |||
102 | QPoint Calibration::startPoint ( ) const | ||
103 | { | ||
104 | return m_p [0]; | ||
105 | } | ||
106 | |||
107 | void Calibration::setEndPoint ( const QPoint &p ) | ||
108 | { | ||
109 | m_p [1] = p; | ||
110 | checkPoints ( ); | ||
111 | update ( ); | ||
112 | } | ||
113 | |||
114 | QPoint Calibration::endPoint ( ) const | ||
115 | { | ||
116 | return m_p [1]; | ||
117 | } | ||
118 | |||
119 | void Calibration::checkPoints ( ) | ||
120 | { | ||
121 | int dx = m_scale. width ( ); | ||
122 | int dy = m_scale. height ( ); | ||
123 | |||
124 | if ( m_p [1]. x ( ) >= dx ) | ||
125 | m_p [1]. setX ( dx - 1 ); | ||
126 | if ( m_p [0]. x ( ) > m_p [1]. x ( )) | ||
127 | m_p [0]. setX ( m_p [1]. x ( )); | ||
128 | |||
129 | if ( m_p [1]. y ( ) >= dy ) | ||
130 | m_p [1]. setY ( dy - 1 ); | ||
131 | if ( m_p [0]. y ( ) > m_p [1]. y ( )) | ||
132 | m_p [0]. setY ( m_p [1]. y ( )); | ||
133 | } | ||
134 | |||
135 | |||
136 | #define SCALEX(x) (BRD+x*(width()- 2*BRD)/m_scale.width()) | ||
137 | #define SCALEY(y) (BRD+y*(height()-2*BRD)/m_scale.height()) | ||
138 | |||
139 | |||
140 | static QRect around ( int x, int y ) | ||
141 | { | ||
142 | return QRect ( x - BRD, y - BRD, 2 * BRD + 1, 2 * BRD + 1 ); | ||
143 | } | ||
144 | |||
145 | void Calibration::mousePressEvent ( QMouseEvent *e ) | ||
146 | { | ||
147 | if ( e-> button ( ) != LeftButton ) | ||
148 | return QWidget::mousePressEvent ( e ); | ||
149 | |||
150 | int olddragged = m_dragged; | ||
151 | int x [2], y [2]; | ||
152 | |||
153 | m_dragged = -1; | ||
154 | for ( int i = 0; i < 2; i++ ) { | ||
155 | x [i] = SCALEX( m_p [i]. x ( )); | ||
156 | y [i] = SCALEY( m_p [i]. y ( )); | ||
157 | |||
158 | if (( QABS( e-> x ( ) - x [i] ) <= BRD ) && | ||
159 | ( QABS( e-> y ( ) - y [i] ) <= BRD )) { | ||
160 | m_dragged = i; | ||
161 | break; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | if ( m_dragged != olddragged ) { | ||
166 | QRect r; | ||
167 | |||
168 | if ( olddragged >= 0 ) | ||
169 | r |= around ( x [olddragged], y [olddragged] ); | ||
170 | if ( m_dragged >= 0 ) | ||
171 | r |= around ( x [m_dragged], y [m_dragged] ); | ||
172 | repaint ( r ); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | void Calibration::mouseMoveEvent ( QMouseEvent *e ) | ||
177 | { | ||
178 | if ( m_dragged < 0 ) | ||
179 | return; | ||
180 | |||
181 | QPoint n [2]; | ||
182 | |||
183 | n [m_dragged]. setX (( e-> x ( ) - BRD ) * m_scale. width ( ) / ( width ( ) - 2 * BRD )); | ||
184 | n [m_dragged]. setY (( e-> y ( ) - BRD ) * m_scale. height ( ) / ( height ( ) - 2 * BRD )); | ||
185 | n [1 - m_dragged] = m_p [1 - m_dragged]; | ||
186 | |||
187 | if (( n [0]. x ( ) > n [1]. x ( )) || ( n [m_dragged]. x ( ) < 0 ) || ( n [m_dragged]. x ( ) >= m_scale. width ( ))) | ||
188 | n [m_dragged]. setX ( m_p [m_dragged]. x ( )); | ||
189 | if (( n [0]. y ( ) > n [1]. y ( )) || ( n [m_dragged]. y ( ) < 0 ) || ( n [m_dragged]. y ( ) >= m_scale. height ( ))) | ||
190 | n [m_dragged]. setY ( m_p [m_dragged]. y ( )); | ||
191 | |||
192 | QRect r; | ||
193 | int ox [2], oy [2], nx [2], ny [2]; | ||
194 | |||
195 | for ( int i = 0; i < 2; i++ ) { | ||
196 | nx [i] = SCALEX( n [i]. x ( )); | ||
197 | ny [i] = SCALEY( n [i]. y ( )); | ||
198 | ox [i] = SCALEX( m_p [i]. x ( )); | ||
199 | oy [i] = SCALEY( m_p [i]. y ( )); | ||
200 | |||
201 | if ( n [i] != m_p [i] ){ | ||
202 | r |= around ( nx [i], ny [i] ); | ||
203 | r |= around ( ox [i], oy [i] ); | ||
204 | m_p [i] = n [i]; | ||
205 | |||
206 | if ( i == 0 ) { | ||
207 | r |= QRect ( 0, 0, nx [0] - 0 + 1, ny [0] - 0 + 1 ); | ||
208 | r |= QRect ( 0, 0, ox [0] - 0 + 1, oy [0] - 0 + 1 ); | ||
209 | } | ||
210 | else if ( i == 1 ) { | ||
211 | r |= QRect ( nx [1], ny [1], width ( ) - nx [1], height ( ) - ny [1] ); | ||
212 | r |= QRect ( ox [1], oy [1], width ( ) - ox [1], height ( ) - oy [1] ); | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | if ( r. isValid ( )) { | ||
217 | r |= QRect ( nx [0], ny [0], nx [1] - nx [0] + 1, ny [1] - ny [0] + 1 ); | ||
218 | r |= QRect ( ox [0], oy [0], ox [1] - ox [0] + 1, oy [1] - oy [0] + 1 ); | ||
219 | |||
220 | repaint ( r ); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | void Calibration::mouseReleaseEvent ( QMouseEvent *e ) | ||
225 | { | ||
226 | if ( e-> button ( ) != LeftButton ) | ||
227 | return QWidget::mouseReleaseEvent ( e ); | ||
228 | |||
229 | if ( m_dragged < 0 ) | ||
230 | return; | ||
231 | |||
232 | int x = SCALEX( m_p [m_dragged]. x ( )); | ||
233 | int y = SCALEY( m_p [m_dragged]. y ( )); | ||
234 | m_dragged = -1; | ||
235 | |||
236 | repaint ( around ( x, y )); | ||
237 | } | ||
238 | |||
239 | void Calibration::paintEvent ( QPaintEvent * ) | ||
240 | { | ||
241 | QPainter p ( this ); | ||
242 | QColorGroup g = colorGroup ( ); | ||
243 | |||
244 | int x0 = SCALEX( m_p [0]. x ( )); | ||
245 | int y0 = SCALEY( m_p [0]. y ( )); | ||
246 | int x1 = SCALEX( m_p [1]. x ( )); | ||
247 | int y1 = SCALEY( m_p [1]. y ( )); | ||
248 | |||
249 | int dx = x1 - x0; | ||
250 | int dy = y1 - y0; | ||
251 | |||
252 | int ex = x0, ey = y0; | ||
253 | |||
254 | p. setPen ( g. highlight ( )); | ||
255 | |||
256 | p. drawLine ( BRD, BRD, ex, BRD ); | ||
257 | p. drawLine ( ex, BRD, ex, ey ); | ||
258 | |||
259 | for ( int i = 1; i < m_steps; i++ ) { | ||
260 | int fx = x0 + dx * i / m_steps; | ||
261 | int fy = y0 + dy * i / ( m_steps - 1 ); | ||
262 | |||
263 | p. drawLine ( ex, ey, fx, ey ); | ||
264 | p. drawLine ( fx, ey, fx, fy ); | ||
265 | |||
266 | ex = fx; | ||
267 | ey = fy; | ||
268 | } | ||
269 | |||
270 | p. drawLine ( ex, ey, width ( ) - 1 - BRD, ey ); | ||
271 | |||
272 | p. fillRect ( around ( x0, y0 ), m_dragged == 0 ? g. highlightedText ( ) : g. text ( )); | ||
273 | p. fillRect ( around ( x1, y1 ), m_dragged == 1 ? g. highlightedText ( ) : g. text ( )); | ||
274 | |||
275 | p. setPen ( g. text ( )); | ||
276 | p. drawText ( QRect ( BRD, BRD, width ( ) - 2*BRD, height() - 2*BRD ), AlignTop | AlignRight, tr( "%1 Steps" ). arg ( m_steps )); | ||
277 | } | ||
278 | |||