-rw-r--r-- | inputmethods/handwriting/qimpenwidget.cpp | 2 | ||||
-rw-r--r-- | inputmethods/handwriting/qimpenwidget.h | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/inputmethods/handwriting/qimpenwidget.cpp b/inputmethods/handwriting/qimpenwidget.cpp index 8f8f582..7223e1a 100644 --- a/inputmethods/handwriting/qimpenwidget.cpp +++ b/inputmethods/handwriting/qimpenwidget.cpp | |||
@@ -1,446 +1,446 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qapplication.h> | 21 | #include <qapplication.h> |
22 | #include <qinputdialog.h> | 22 | #include <qinputdialog.h> |
23 | #include <qpainter.h> | 23 | #include <qpainter.h> |
24 | #include <qfile.h> | 24 | #include <qfile.h> |
25 | #include <qdatastream.h> | 25 | #include <qdatastream.h> |
26 | #include <qtimer.h> | 26 | #include <qtimer.h> |
27 | #include "qimpenchar.h" | 27 | #include "qimpenchar.h" |
28 | #include "qimpenwidget.h" | 28 | #include "qimpenwidget.h" |
29 | 29 | ||
30 | #define TITLE_WIDTH30 // ### magic | 30 | #define TITLE_WIDTH30 // ### magic |
31 | 31 | ||
32 | /*! | 32 | /*! |
33 | \class QIMPenWidget qimpenwidget.h | 33 | \class QIMPenWidget qimpenwidget.h |
34 | 34 | ||
35 | Draws characters and allows input of characters. | 35 | Draws characters and allows input of characters. |
36 | */ | 36 | */ |
37 | 37 | ||
38 | QIMPenWidget::QIMPenWidget( QWidget *parent ) | 38 | QIMPenWidget::QIMPenWidget( QWidget *parent ) |
39 | : QWidget( parent ) | 39 | : QWidget( parent ) |
40 | { | 40 | { |
41 | charSets.setAutoDelete( TRUE ); | 41 | charSets.setAutoDelete( TRUE ); |
42 | inputStroke = 0; | 42 | inputStroke = 0; |
43 | outputChar = 0; | 43 | outputChar = 0; |
44 | outputStroke = 0; | 44 | outputStroke = 0; |
45 | mode = Waiting; | 45 | mode = Waiting; |
46 | currCharSet = 0; | 46 | currCharSet = 0; |
47 | readOnly = FALSE; | 47 | readOnly = FALSE; |
48 | strokes.setAutoDelete( TRUE ); | 48 | strokes.setAutoDelete( TRUE ); |
49 | 49 | ||
50 | timer = new QTimer(this); | 50 | timer = new QTimer(this); |
51 | connect( timer, SIGNAL(timeout()), SLOT(timeout())); | 51 | connect( timer, SIGNAL(timeout()), SLOT(timeout())); |
52 | 52 | ||
53 | setBackgroundColor( qApp->palette().color( QPalette::Active, | 53 | setBackgroundColor( qApp->palette().color( QPalette::Active, |
54 | QColorGroup::Base ) ); | 54 | QColorGroup::Base ) ); |
55 | strokeColor = black; | 55 | strokeColor = black; |
56 | setFixedHeight( 75 ); | 56 | setFixedHeight( 75 ); |
57 | } | 57 | } |
58 | 58 | ||
59 | void QIMPenWidget::clear() | 59 | void QIMPenWidget::clear() |
60 | { | 60 | { |
61 | timer->stop(); | 61 | timer->stop(); |
62 | mode = Waiting; | 62 | mode = Waiting; |
63 | QRect r( dirtyRect ); | 63 | QRect r( dirtyRect ); |
64 | QIMPenStrokeIterator it( strokes ); | 64 | QIMPenStrokeIterator it( strokes ); |
65 | while ( it.current() ) { | 65 | while ( it.current() ) { |
66 | r |= it.current()->boundingRect(); | 66 | r |= it.current()->boundingRect(); |
67 | ++it; | 67 | ++it; |
68 | } | 68 | } |
69 | outputChar = 0; | 69 | outputChar = 0; |
70 | outputStroke = 0; | 70 | outputStroke = 0; |
71 | strokes.clear(); | 71 | strokes.clear(); |
72 | if ( !r.isNull() ) { | 72 | if ( !r.isNull() ) { |
73 | r.moveBy( -2, -2 ); | 73 | r.moveBy( -2, -2 ); |
74 | r.setSize( r.size() + QSize( 4, 4 ) ); | 74 | r.setSize( r.size() + QSize( 4, 4 ) ); |
75 | repaint( r ); | 75 | repaint( r ); |
76 | } else { | 76 | } else { |
77 | repaint(); | 77 | repaint(); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | void QIMPenWidget::removeStroke() | 81 | void QIMPenWidget::removeStroke() |
82 | { | 82 | { |
83 | QRect r( dirtyRect ); | 83 | QRect r( dirtyRect ); |
84 | QIMPenStroke *st = strokes.getFirst(); | 84 | QIMPenStroke *st = strokes.getFirst(); |
85 | QRect strokeRect; | 85 | QRect strokeRect; |
86 | if ( st ) | 86 | if ( st ) |
87 | strokeRect = st->boundingRect(); | 87 | strokeRect = st->boundingRect(); |
88 | r |= strokeRect; | 88 | r |= strokeRect; |
89 | strokes.removeFirst(); | 89 | strokes.removeFirst(); |
90 | if ( !r.isNull() ) { | 90 | if ( !r.isNull() ) { |
91 | r.moveBy( -2, -2 ); | 91 | r.moveBy( -2, -2 ); |
92 | r.setSize( r.size() + QSize( 4, 4 ) ); | 92 | r.setSize( r.size() + QSize( 4, 4 ) ); |
93 | repaint( r ); | 93 | repaint( r ); |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | void QIMPenWidget::greyStroke() | 97 | void QIMPenWidget::greyStroke() |
98 | { | 98 | { |
99 | QRect r( dirtyRect ); | 99 | QRect r( dirtyRect ); |
100 | QIMPenStroke *st = strokes.getLast(); | 100 | QIMPenStroke *st = strokes.getLast(); |
101 | QRect strokeRect; | 101 | QRect strokeRect; |
102 | if ( st ) | 102 | if ( st ) |
103 | strokeRect = st->boundingRect(); | 103 | strokeRect = st->boundingRect(); |
104 | r |= strokeRect; | 104 | r |= strokeRect; |
105 | QColor oldCol = strokeColor; | 105 | QColor oldCol = strokeColor; |
106 | strokeColor = gray; | 106 | strokeColor = gray; |
107 | if ( !r.isNull() ) { | 107 | if ( !r.isNull() ) { |
108 | r.moveBy( -2, -2 ); | 108 | r.moveBy( -2, -2 ); |
109 | r.setSize( r.size() + QSize( 4, 4 ) ); | 109 | r.setSize( r.size() + QSize( 4, 4 ) ); |
110 | repaint( r ); | 110 | repaint( r ); |
111 | } | 111 | } |
112 | strokeColor = oldCol; | 112 | strokeColor = oldCol; |
113 | } | 113 | } |
114 | 114 | ||
115 | /*! | 115 | /*! |
116 | Insert a character set into the list. | 116 | Insert a character set into the list. |
117 | */ | 117 | */ |
118 | void QIMPenWidget::insertCharSet( QIMPenCharSet *cs, int stretch, int pos ) | 118 | void QIMPenWidget::insertCharSet( QIMPenCharSet *cs, int stretch, int pos ) |
119 | { | 119 | { |
120 | CharSetEntry *e = new CharSetEntry; | 120 | CharSetEntry *e = new CharSetEntry; |
121 | e->cs = cs; | 121 | e->cs = cs; |
122 | e->stretch = stretch; | 122 | e->stretch = stretch; |
123 | if ( pos < 0 ) | 123 | if ( pos < 0 ) |
124 | pos = charSets.count(); | 124 | pos = charSets.count(); |
125 | charSets.insert( pos, e ); | 125 | charSets.insert( pos, e ); |
126 | currCharSet = 0; | 126 | currCharSet = 0; |
127 | emit changeCharSet( currCharSet ); | 127 | emit changeCharSet( currCharSet ); |
128 | emit changeCharSet( charSets.at(currCharSet)->cs ); | 128 | emit changeCharSet( charSets.at(currCharSet)->cs ); |
129 | totalStretch = 0; | 129 | totalStretch = 0; |
130 | CharSetEntryIterator it( charSets ); | 130 | CharSetEntryIterator it( charSets ); |
131 | for ( ; it.current(); ++it ) | 131 | for ( ; it.current(); ++it ) |
132 | totalStretch += it.current()->stretch; | 132 | totalStretch += it.current()->stretch; |
133 | update(); | 133 | update(); |
134 | } | 134 | } |
135 | 135 | ||
136 | /*! | 136 | /*! |
137 | Remove a character set from the list. | 137 | Remove a character set from the list. |
138 | */ | 138 | */ |
139 | void QIMPenWidget::removeCharSet( int pos ) | 139 | void QIMPenWidget::removeCharSet( int pos ) |
140 | { | 140 | { |
141 | if ( pos >= 0 && pos < (int)charSets.count() ) { | 141 | if ( pos >= 0 && pos < (int)charSets.count() ) { |
142 | charSets.remove( pos ); | 142 | charSets.remove( pos ); |
143 | currCharSet = 0; | 143 | currCharSet = 0; |
144 | if ( charSets.count() ) { | 144 | if ( charSets.count() ) { |
145 | emit changeCharSet( currCharSet ); | 145 | emit changeCharSet( currCharSet ); |
146 | emit changeCharSet( charSets.at(currCharSet)->cs ); | 146 | emit changeCharSet( charSets.at(currCharSet)->cs ); |
147 | } | 147 | } |
148 | totalStretch = 0; | 148 | totalStretch = 0; |
149 | CharSetEntryIterator it( charSets ); | 149 | CharSetEntryIterator it( charSets ); |
150 | for ( ; it.current(); ++it ) | 150 | for ( ; it.current(); ++it ) |
151 | totalStretch += it.current()->stretch; | 151 | totalStretch += it.current()->stretch; |
152 | update(); | 152 | update(); |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | void QIMPenWidget::changeCharSet( QIMPenCharSet *cs, int pos ) | 156 | void QIMPenWidget::changeCharSet( QIMPenCharSet *cs, int pos ) |
157 | { | 157 | { |
158 | if ( pos >= 0 && pos < (int)charSets.count() ) { | 158 | if ( pos >= 0 && pos < (int)charSets.count() ) { |
159 | CharSetEntry *e = new CharSetEntry; | 159 | CharSetEntry *e = new CharSetEntry; |
160 | e->cs = cs; | 160 | e->cs = cs; |
161 | e->stretch = charSets.at(pos)->stretch; | 161 | e->stretch = charSets.at(pos)->stretch; |
162 | charSets.remove( pos ); | 162 | charSets.remove( pos ); |
163 | charSets.insert( pos, e ); | 163 | charSets.insert( pos, e ); |
164 | if ( pos == currCharSet ) { | 164 | if ( pos == currCharSet ) { |
165 | emit changeCharSet( charSets.at(currCharSet)->cs ); | 165 | emit changeCharSet( charSets.at(currCharSet)->cs ); |
166 | } | 166 | } |
167 | update(); | 167 | update(); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | 170 | ||
171 | void QIMPenWidget::clearCharSets() | 171 | void QIMPenWidget::clearCharSets() |
172 | { | 172 | { |
173 | charSets.clear(); | 173 | charSets.clear(); |
174 | currCharSet = 0; | 174 | currCharSet = 0; |
175 | update(); | 175 | update(); |
176 | } | 176 | } |
177 | 177 | ||
178 | /*! | 178 | /*! |
179 | Display a character. \a speed determines how quickly the character is | 179 | Display a character. \a speed determines how quickly the character is |
180 | drawn. | 180 | drawn. |
181 | */ | 181 | */ |
182 | void QIMPenWidget::showCharacter( QIMPenChar *ch, int speed ) | 182 | void QIMPenWidget::showCharacter( QIMPenChar *ch, int speed ) |
183 | { | 183 | { |
184 | outputChar = 0; | 184 | outputChar = 0; |
185 | outputStroke = 0; | 185 | outputStroke = 0; |
186 | strokes.clear(); | 186 | strokes.clear(); |
187 | mode = Output; | 187 | mode = Output; |
188 | repaint(); | 188 | repaint(); |
189 | if ( !ch || ch->isEmpty() ) { | 189 | if ( !ch || ch->isEmpty() ) { |
190 | mode = Waiting; | 190 | mode = Waiting; |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | 193 | ||
194 | outputChar = ch; | 194 | outputChar = ch; |
195 | outputStroke = outputChar->penStrokes().getFirst(); | 195 | outputStroke = outputChar->penStrokes().getFirst(); |
196 | if ( speed < 0 ) speed = 0; | 196 | if ( speed < 0 ) speed = 0; |
197 | if ( speed > 20 ) speed = 20; | 197 | if ( speed > 20 ) speed = 20; |
198 | speed = 50 - speed; | 198 | speed = 50 - speed; |
199 | pointIndex = 0; | 199 | pointIndex = 0; |
200 | strokeIndex = 0; | 200 | strokeIndex = 0; |
201 | lastPoint = outputStroke->startingPoint(); | 201 | lastPoint = outputStroke->startingPoint(); |
202 | QRect br( outputChar->boundingRect() ); | 202 | QRect br( outputChar->boundingRect() ); |
203 | lastPoint.setX( (width() - br.width()) / 2 + (lastPoint.x () - br.left()) ); | 203 | lastPoint.setX( (width() - br.width()) / 2 + (lastPoint.x () - br.left()) ); |
204 | QPoint offset = lastPoint - outputStroke->startingPoint(); | 204 | QPoint offset = lastPoint - outputStroke->startingPoint(); |
205 | br.moveBy( offset.x(), offset.y() ); | 205 | br.moveBy( offset.x(), offset.y() ); |
206 | dirtyRect |= br; | 206 | dirtyRect |= br; |
207 | timer->start( speed ); | 207 | timer->start( speed ); |
208 | } | 208 | } |
209 | 209 | ||
210 | /*! | 210 | /*! |
211 | Handle drawing/clearing of characters. | 211 | Handle drawing/clearing of characters. |
212 | */ | 212 | */ |
213 | void QIMPenWidget::timeout() | 213 | void QIMPenWidget::timeout() |
214 | { | 214 | { |
215 | if ( mode == Output ) { | 215 | if ( mode == Output ) { |
216 | const QArray<QIMPenGlyphLink> &chain = outputStroke->chain(); | 216 | const QArray<QIMPenGlyphLink> &chain = outputStroke->chain(); |
217 | if ( pointIndex < chain.count() ) { | 217 | if ( pointIndex < chain.count() ) { |
218 | QPainter paint( this ); | 218 | QPainter paint( this ); |
219 | paint.setBrush( Qt::black ); | 219 | paint.setBrush( Qt::black ); |
220 | for ( unsigned i = 0; i < 3 && pointIndex < chain.count(); i++ ) { | 220 | for ( unsigned i = 0; i < 3 && pointIndex < chain.count(); i++ ) { |
221 | lastPoint.rx() += chain[pointIndex].dx; | 221 | lastPoint.rx() += chain[pointIndex].dx; |
222 | lastPoint.ry() += chain[pointIndex].dy; | 222 | lastPoint.ry() += chain[pointIndex].dy; |
223 | pointIndex++; | 223 | pointIndex++; |
224 | paint.drawRect( lastPoint.x()-1, lastPoint.y()-1, 2, 2 ); | 224 | paint.drawRect( lastPoint.x()-1, lastPoint.y()-1, 2, 2 ); |
225 | } | 225 | } |
226 | } | 226 | } |
227 | if ( pointIndex >= chain.count() ) { | 227 | if ( pointIndex >= chain.count() ) { |
228 | QIMPenStrokeList strokes = outputChar->penStrokes(); | 228 | QIMPenStrokeList strokes = outputChar->penStrokes(); |
229 | if ( strokeIndex < (int)strokes.count() - 1 ) { | 229 | if ( strokeIndex < (int)strokes.count() - 1 ) { |
230 | pointIndex = 0; | 230 | pointIndex = 0; |
231 | strokeIndex++; | 231 | strokeIndex++; |
232 | outputStroke = strokes.at( strokeIndex ); | 232 | outputStroke = strokes.at( strokeIndex ); |
233 | lastPoint = outputChar->startingPoint(); | 233 | lastPoint = outputChar->startingPoint(); |
234 | QRect br( outputChar->boundingRect() ); | 234 | QRect br( outputChar->boundingRect() ); |
235 | lastPoint.setX( (width() - br.width()) / 2 | 235 | lastPoint.setX( (width() - br.width()) / 2 |
236 | + (lastPoint.x () - br.left()) ); | 236 | + (lastPoint.x () - br.left()) ); |
237 | QPoint off = lastPoint - outputChar->startingPoint(); | 237 | QPoint off = lastPoint - outputChar->startingPoint(); |
238 | lastPoint = outputStroke->startingPoint() + off; | 238 | lastPoint = outputStroke->startingPoint() + off; |
239 | } else { | 239 | } else { |
240 | timer->stop(); | 240 | timer->stop(); |
241 | mode = Waiting; | 241 | mode = Waiting; |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } else if ( mode == Waiting ) { | 244 | } else if ( mode == Waiting ) { |
245 | QRect r( dirtyRect ); | 245 | QRect r( dirtyRect ); |
246 | if ( !r.isNull() ) { | 246 | if ( !r.isNull() ) { |
247 | r.moveBy( -2, -2 ); | 247 | r.moveBy( -2, -2 ); |
248 | r.setSize( r.size() + QSize( 4, 4 ) ); | 248 | r.setSize( r.size() + QSize( 4, 4 ) ); |
249 | repaint( r ); | 249 | repaint( r ); |
250 | } | 250 | } |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
254 | /*! | 254 | /*! |
255 | If the point \a p is over one of the character set titles, switch | 255 | If the point \a p is over one of the character set titles, switch |
256 | to the set and return TRUE. | 256 | to the set and return TRUE. |
257 | */ | 257 | */ |
258 | bool QIMPenWidget::selectSet( QPoint p ) | 258 | bool QIMPenWidget::selectSet( QPoint p ) |
259 | { | 259 | { |
260 | if ( charSets.count() ) { | 260 | if ( charSets.count() ) { |
261 | CharSetEntryIterator it( charSets ); | 261 | CharSetEntryIterator it( charSets ); |
262 | int spos = 0; | 262 | int spos = 0; |
263 | int idx = 0; | 263 | int idx = 0; |
264 | for ( ; it.current(); ++it, idx++ ) { | 264 | for ( ; it.current(); ++it, idx++ ) { |
265 | int setWidth = width() * it.current()->stretch / totalStretch; | 265 | int setWidth = width() * it.current()->stretch / totalStretch; |
266 | spos += setWidth; | 266 | spos += setWidth; |
267 | if ( p.x() < spos ) { | 267 | if ( p.x() < spos ) { |
268 | if ( idx != currCharSet ) { | 268 | if ( idx != currCharSet ) { |
269 | currCharSet = idx; | 269 | currCharSet = idx; |
270 | update( 0, 0, width(), 12 ); | 270 | update( 0, 0, width(), 12 ); |
271 | emit changeCharSet( currCharSet ); | 271 | emit changeCharSet( currCharSet ); |
272 | emit changeCharSet( charSets.at(currCharSet)->cs ); | 272 | emit changeCharSet( charSets.at(currCharSet)->cs ); |
273 | } | 273 | } |
274 | break; | 274 | break; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | } | 277 | } |
278 | 278 | ||
279 | return FALSE; | 279 | return FALSE; |
280 | } | 280 | } |
281 | 281 | ||
282 | /*! | 282 | /*! |
283 | Hopefully returns a sensible size. | 283 | Hopefully returns a sensible size. |
284 | */ | 284 | */ |
285 | QSize QIMPenWidget::sizeHint() | 285 | QSize QIMPenWidget::sizeHint() const |
286 | { | 286 | { |
287 | return QSize( TITLE_WIDTH * charSets.count(), 75 ); | 287 | return QSize( TITLE_WIDTH * charSets.count(), 75 ); |
288 | } | 288 | } |
289 | 289 | ||
290 | void QIMPenWidget::mousePressEvent( QMouseEvent *e ) | 290 | void QIMPenWidget::mousePressEvent( QMouseEvent *e ) |
291 | { | 291 | { |
292 | if ( !readOnly && e->button() == LeftButton && mode == Waiting ) { | 292 | if ( !readOnly && e->button() == LeftButton && mode == Waiting ) { |
293 | // if selectSet returns false the click was not over the | 293 | // if selectSet returns false the click was not over the |
294 | // char set selectors. | 294 | // char set selectors. |
295 | if ( !selectSet( e->pos() ) ) { | 295 | if ( !selectSet( e->pos() ) ) { |
296 | // start of character input | 296 | // start of character input |
297 | timer->stop(); | 297 | timer->stop(); |
298 | if ( outputChar ) { | 298 | if ( outputChar ) { |
299 | outputChar = 0; | 299 | outputChar = 0; |
300 | outputStroke = 0; | 300 | outputStroke = 0; |
301 | repaint(); | 301 | repaint(); |
302 | } | 302 | } |
303 | mode = Input; | 303 | mode = Input; |
304 | lastPoint = e->pos(); | 304 | lastPoint = e->pos(); |
305 | emit beginStroke(); | 305 | emit beginStroke(); |
306 | inputStroke = new QIMPenStroke; | 306 | inputStroke = new QIMPenStroke; |
307 | strokes.append( inputStroke ); | 307 | strokes.append( inputStroke ); |
308 | inputStroke->beginInput( e->pos() ); | 308 | inputStroke->beginInput( e->pos() ); |
309 | QPainter paint( this ); | 309 | QPainter paint( this ); |
310 | paint.setBrush( Qt::black ); | 310 | paint.setBrush( Qt::black ); |
311 | paint.drawRect( lastPoint.x()-1, lastPoint.y()-1, 2, 2 ); | 311 | paint.drawRect( lastPoint.x()-1, lastPoint.y()-1, 2, 2 ); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | } | 314 | } |
315 | 315 | ||
316 | void QIMPenWidget::mouseReleaseEvent( QMouseEvent *e ) | 316 | void QIMPenWidget::mouseReleaseEvent( QMouseEvent *e ) |
317 | { | 317 | { |
318 | if ( !readOnly && e->button() == LeftButton && mode == Input ) { | 318 | if ( !readOnly && e->button() == LeftButton && mode == Input ) { |
319 | mode = Waiting; | 319 | mode = Waiting; |
320 | inputStroke->endInput(); | 320 | inputStroke->endInput(); |
321 | if ( charSets.count() ) | 321 | if ( charSets.count() ) |
322 | emit stroke( inputStroke ); | 322 | emit stroke( inputStroke ); |
323 | inputStroke = 0; | 323 | inputStroke = 0; |
324 | } | 324 | } |
325 | } | 325 | } |
326 | 326 | ||
327 | void QIMPenWidget::mouseMoveEvent( QMouseEvent *e ) | 327 | void QIMPenWidget::mouseMoveEvent( QMouseEvent *e ) |
328 | { | 328 | { |
329 | if ( !readOnly && mode == Input ) { | 329 | if ( !readOnly && mode == Input ) { |
330 | int dx = QABS( e->pos().x() - lastPoint.x() ); | 330 | int dx = QABS( e->pos().x() - lastPoint.x() ); |
331 | int dy = QABS( e->pos().y() - lastPoint.y() ); | 331 | int dy = QABS( e->pos().y() - lastPoint.y() ); |
332 | if ( dx + dy > 1 ) { | 332 | if ( dx + dy > 1 ) { |
333 | if ( inputStroke->addPoint( e->pos() ) ) { | 333 | if ( inputStroke->addPoint( e->pos() ) ) { |
334 | QPainter paint( this ); | 334 | QPainter paint( this ); |
335 | paint.setPen( Qt::black ); | 335 | paint.setPen( Qt::black ); |
336 | paint.setBrush( Qt::black ); | 336 | paint.setBrush( Qt::black ); |
337 | const QArray<QIMPenGlyphLink> &chain = inputStroke->chain(); | 337 | const QArray<QIMPenGlyphLink> &chain = inputStroke->chain(); |
338 | QPoint p( e->pos() ); | 338 | QPoint p( e->pos() ); |
339 | for ( int i = (int)chain.count()-1; i >= 0; i-- ) { | 339 | for ( int i = (int)chain.count()-1; i >= 0; i-- ) { |
340 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); | 340 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); |
341 | p.rx() -= chain[i].dx; | 341 | p.rx() -= chain[i].dx; |
342 | p.ry() -= chain[i].dy; | 342 | p.ry() -= chain[i].dy; |
343 | if ( p == lastPoint ) | 343 | if ( p == lastPoint ) |
344 | break; | 344 | break; |
345 | } | 345 | } |
346 | 346 | ||
347 | /* ### use this when thick lines work properly on all devices | 347 | /* ### use this when thick lines work properly on all devices |
348 | paint.setPen( QPen( Qt::black, 2 ) ); | 348 | paint.setPen( QPen( Qt::black, 2 ) ); |
349 | paint.drawLine( lastPoint, e->pos() ); | 349 | paint.drawLine( lastPoint, e->pos() ); |
350 | */ | 350 | */ |
351 | } | 351 | } |
352 | lastPoint = e->pos(); | 352 | lastPoint = e->pos(); |
353 | } | 353 | } |
354 | } | 354 | } |
355 | } | 355 | } |
356 | 356 | ||
357 | void QIMPenWidget::paintEvent( QPaintEvent * ) | 357 | void QIMPenWidget::paintEvent( QPaintEvent * ) |
358 | { | 358 | { |
359 | QPainter paint( this ); | 359 | QPainter paint( this ); |
360 | 360 | ||
361 | // draw guidelines | 361 | // draw guidelines |
362 | paint.setPen( Qt::gray ); | 362 | paint.setPen( Qt::gray ); |
363 | paint.drawLine( 0, 0, width(), 0 ); | 363 | paint.drawLine( 0, 0, width(), 0 ); |
364 | int y = height() / 3; | 364 | int y = height() / 3; |
365 | paint.drawLine( 0, y, width(), y ); | 365 | paint.drawLine( 0, y, width(), y ); |
366 | y *= 2; | 366 | y *= 2; |
367 | paint.setPen( blue ); | 367 | paint.setPen( blue ); |
368 | paint.drawLine( 0, y, width(), y ); | 368 | paint.drawLine( 0, y, width(), y ); |
369 | paint.setPen( Qt::gray ); | 369 | paint.setPen( Qt::gray ); |
370 | 370 | ||
371 | if ( !charSets.count() ) | 371 | if ( !charSets.count() ) |
372 | return; | 372 | return; |
373 | 373 | ||
374 | // draw the character set titles | 374 | // draw the character set titles |
375 | QFont selFont( "helvetica", 8, QFont::Bold ); | 375 | QFont selFont( "helvetica", 8, QFont::Bold ); |
376 | QFont font( "helvetica", 8 ); | 376 | QFont font( "helvetica", 8 ); |
377 | CharSetEntryIterator it( charSets ); | 377 | CharSetEntryIterator it( charSets ); |
378 | int spos = 0; | 378 | int spos = 0; |
379 | for ( ; it.current(); ++it ) { | 379 | for ( ; it.current(); ++it ) { |
380 | int setWidth = width() * it.current()->stretch / totalStretch; | 380 | int setWidth = width() * it.current()->stretch / totalStretch; |
381 | spos += setWidth; | 381 | spos += setWidth; |
382 | if ( it.current() != charSets.getLast() ) { | 382 | if ( it.current() != charSets.getLast() ) { |
383 | paint.drawLine( spos, 0, spos, 5 ); | 383 | paint.drawLine( spos, 0, spos, 5 ); |
384 | paint.drawLine( spos, height()-1, spos, height()-6 ); | 384 | paint.drawLine( spos, height()-1, spos, height()-6 ); |
385 | } | 385 | } |
386 | paint.setFont( font ); | 386 | paint.setFont( font ); |
387 | int w = paint.fontMetrics().width( it.current()->cs->title() ); | 387 | int w = paint.fontMetrics().width( it.current()->cs->title() ); |
388 | int tpos = spos - setWidth / 2; | 388 | int tpos = spos - setWidth / 2; |
389 | paint.drawText( tpos - w/2, 0, w, 12, QPainter::AlignCenter, | 389 | paint.drawText( tpos - w/2, 0, w, 12, QPainter::AlignCenter, |
390 | it.current()->cs->title() ); | 390 | it.current()->cs->title() ); |
391 | } | 391 | } |
392 | 392 | ||
393 | // draw any character that should be displayed when repainted. | 393 | // draw any character that should be displayed when repainted. |
394 | QPoint off; | 394 | QPoint off; |
395 | const QIMPenStrokeList *stk = 0; | 395 | const QIMPenStrokeList *stk = 0; |
396 | if ( outputChar && mode == Waiting ) { | 396 | if ( outputChar && mode == Waiting ) { |
397 | stk = &outputChar->penStrokes(); | 397 | stk = &outputChar->penStrokes(); |
398 | QPoint p( outputChar->startingPoint() ); | 398 | QPoint p( outputChar->startingPoint() ); |
399 | QRect br( outputChar->boundingRect() ); | 399 | QRect br( outputChar->boundingRect() ); |
400 | p.setX( (width() - br.width()) / 2 + (p.x () - br.left()) ); | 400 | p.setX( (width() - br.width()) / 2 + (p.x () - br.left()) ); |
401 | off = p - outputChar->startingPoint(); | 401 | off = p - outputChar->startingPoint(); |
402 | } else if ( mode == Waiting ) { | 402 | } else if ( mode == Waiting ) { |
403 | stk = &strokes; | 403 | stk = &strokes; |
404 | strokeColor = gray; | 404 | strokeColor = gray; |
405 | } | 405 | } |
406 | 406 | ||
407 | if ( stk && !stk->isEmpty() ) { | 407 | if ( stk && !stk->isEmpty() ) { |
408 | paint.setPen( strokeColor ); | 408 | paint.setPen( strokeColor ); |
409 | paint.setBrush( strokeColor ); | 409 | paint.setBrush( strokeColor ); |
410 | QIMPenStrokeIterator it( *stk ); | 410 | QIMPenStrokeIterator it( *stk ); |
411 | while ( it.current() ) { | 411 | while ( it.current() ) { |
412 | QPoint p = it.current()->startingPoint() + off; | 412 | QPoint p = it.current()->startingPoint() + off; |
413 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); | 413 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); |
414 | const QArray<QIMPenGlyphLink> &chain = it.current()->chain(); | 414 | const QArray<QIMPenGlyphLink> &chain = it.current()->chain(); |
415 | for ( unsigned i = 0; i < chain.count(); i++ ) { | 415 | for ( unsigned i = 0; i < chain.count(); i++ ) { |
416 | p.rx() += chain[i].dx; | 416 | p.rx() += chain[i].dx; |
417 | p.ry() += chain[i].dy; | 417 | p.ry() += chain[i].dy; |
418 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); | 418 | paint.drawRect( p.x()-1, p.y()-1, 2, 2 ); |
419 | } | 419 | } |
420 | ++it; | 420 | ++it; |
421 | if ( it.atLast() && mode == Waiting ) | 421 | if ( it.atLast() && mode == Waiting ) |
422 | strokeColor = black; | 422 | strokeColor = black; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | 425 | ||
426 | dirtyRect = QRect(); | 426 | dirtyRect = QRect(); |
427 | 427 | ||
428 | // debug | 428 | // debug |
429 | /* | 429 | /* |
430 | if ( input ) { | 430 | if ( input ) { |
431 | QArray<int> sig = input->sig(); | 431 | QArray<int> sig = input->sig(); |
432 | for ( unsigned i = 0; i < sig.count(); i++ ) { | 432 | for ( unsigned i = 0; i < sig.count(); i++ ) { |
433 | paint.drawPoint( 200 + i, height()/2 - sig[i] / 8 ); | 433 | paint.drawPoint( 200 + i, height()/2 - sig[i] / 8 ); |
434 | } | 434 | } |
435 | } | 435 | } |
436 | */ | 436 | */ |
437 | } | 437 | } |
438 | 438 | ||
439 | void QIMPenWidget::resizeEvent( QResizeEvent *e ) | 439 | void QIMPenWidget::resizeEvent( QResizeEvent *e ) |
440 | { | 440 | { |
441 | if ( mode == Output ) | 441 | if ( mode == Output ) |
442 | showCharacter( outputChar, 0 ); | 442 | showCharacter( outputChar, 0 ); |
443 | 443 | ||
444 | QWidget::resizeEvent( e ); | 444 | QWidget::resizeEvent( e ); |
445 | } | 445 | } |
446 | 446 | ||
diff --git a/inputmethods/handwriting/qimpenwidget.h b/inputmethods/handwriting/qimpenwidget.h index 98d7f5c..d156554 100644 --- a/inputmethods/handwriting/qimpenwidget.h +++ b/inputmethods/handwriting/qimpenwidget.h | |||
@@ -1,88 +1,88 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include <qwidget.h> | 21 | #include <qwidget.h> |
22 | #include <qlist.h> | 22 | #include <qlist.h> |
23 | #include "qimpenchar.h" | 23 | #include "qimpenchar.h" |
24 | 24 | ||
25 | class QIMPenWidget : public QWidget | 25 | class QIMPenWidget : public QWidget |
26 | { | 26 | { |
27 | Q_OBJECT | 27 | Q_OBJECT |
28 | public: | 28 | public: |
29 | QIMPenWidget( QWidget *parent ); | 29 | QIMPenWidget( QWidget *parent ); |
30 | 30 | ||
31 | void clear(); | 31 | void clear(); |
32 | void greyStroke(); | 32 | void greyStroke(); |
33 | void setReadOnly( bool r ) { readOnly = r; } | 33 | void setReadOnly( bool r ) { readOnly = r; } |
34 | 34 | ||
35 | void insertCharSet( QIMPenCharSet *cs, int stretch=1, int pos=-1 ); | 35 | void insertCharSet( QIMPenCharSet *cs, int stretch=1, int pos=-1 ); |
36 | void removeCharSet( int ); | 36 | void removeCharSet( int ); |
37 | void changeCharSet( QIMPenCharSet *cs, int pos ); | 37 | void changeCharSet( QIMPenCharSet *cs, int pos ); |
38 | void clearCharSets(); | 38 | void clearCharSets(); |
39 | void showCharacter( QIMPenChar *, int speed = 10 ); | 39 | void showCharacter( QIMPenChar *, int speed = 10 ); |
40 | virtual QSize sizeHint(); | 40 | virtual QSize sizeHint() const; |
41 | 41 | ||
42 | public slots: | 42 | public slots: |
43 | void removeStroke(); | 43 | void removeStroke(); |
44 | 44 | ||
45 | signals: | 45 | signals: |
46 | void changeCharSet( QIMPenCharSet *cs ); | 46 | void changeCharSet( QIMPenCharSet *cs ); |
47 | void changeCharSet( int ); | 47 | void changeCharSet( int ); |
48 | void beginStroke(); | 48 | void beginStroke(); |
49 | void stroke( QIMPenStroke *ch ); | 49 | void stroke( QIMPenStroke *ch ); |
50 | 50 | ||
51 | protected slots: | 51 | protected slots: |
52 | void timeout(); | 52 | void timeout(); |
53 | 53 | ||
54 | protected: | 54 | protected: |
55 | enum Mode { Waiting, Input, Output }; | 55 | enum Mode { Waiting, Input, Output }; |
56 | bool selectSet( QPoint ); | 56 | bool selectSet( QPoint ); |
57 | virtual void mousePressEvent( QMouseEvent *e ); | 57 | virtual void mousePressEvent( QMouseEvent *e ); |
58 | virtual void mouseReleaseEvent( QMouseEvent *e ); | 58 | virtual void mouseReleaseEvent( QMouseEvent *e ); |
59 | virtual void mouseMoveEvent( QMouseEvent *e ); | 59 | virtual void mouseMoveEvent( QMouseEvent *e ); |
60 | virtual void paintEvent( QPaintEvent *e ); | 60 | virtual void paintEvent( QPaintEvent *e ); |
61 | virtual void resizeEvent( QResizeEvent *e ); | 61 | virtual void resizeEvent( QResizeEvent *e ); |
62 | 62 | ||
63 | struct CharSetEntry { | 63 | struct CharSetEntry { |
64 | QIMPenCharSet *cs; | 64 | QIMPenCharSet *cs; |
65 | int stretch; | 65 | int stretch; |
66 | }; | 66 | }; |
67 | typedef QList<CharSetEntry> CharSetEntryList; | 67 | typedef QList<CharSetEntry> CharSetEntryList; |
68 | typedef QListIterator<CharSetEntry> CharSetEntryIterator; | 68 | typedef QListIterator<CharSetEntry> CharSetEntryIterator; |
69 | 69 | ||
70 | protected: | 70 | protected: |
71 | Mode mode; | 71 | Mode mode; |
72 | bool autoHide; | 72 | bool autoHide; |
73 | bool readOnly; | 73 | bool readOnly; |
74 | QPoint lastPoint; | 74 | QPoint lastPoint; |
75 | unsigned pointIndex; | 75 | unsigned pointIndex; |
76 | int strokeIndex; | 76 | int strokeIndex; |
77 | int currCharSet; | 77 | int currCharSet; |
78 | QTimer *timer; | 78 | QTimer *timer; |
79 | QColor strokeColor; | 79 | QColor strokeColor; |
80 | QRect dirtyRect; | 80 | QRect dirtyRect; |
81 | QIMPenChar *outputChar; | 81 | QIMPenChar *outputChar; |
82 | QIMPenStroke *outputStroke; | 82 | QIMPenStroke *outputStroke; |
83 | QIMPenStroke *inputStroke; | 83 | QIMPenStroke *inputStroke; |
84 | QIMPenStrokeList strokes; | 84 | QIMPenStrokeList strokes; |
85 | CharSetEntryList charSets; | 85 | CharSetEntryList charSets; |
86 | int totalStretch; | 86 | int totalStretch; |
87 | }; | 87 | }; |
88 | 88 | ||