author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /inputmethods/handwriting/qimpenwordpick.cpp | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'inputmethods/handwriting/qimpenwordpick.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/handwriting/qimpenwordpick.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/inputmethods/handwriting/qimpenwordpick.cpp b/inputmethods/handwriting/qimpenwordpick.cpp new file mode 100644 index 0000000..8ee103d --- a/dev/null +++ b/inputmethods/handwriting/qimpenwordpick.cpp | |||
@@ -0,0 +1,113 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
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 | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
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. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qpainter.h> | ||
22 | #include "qimpenwordpick.h" | ||
23 | |||
24 | QIMPenWordPick::QIMPenWordPick( QWidget *parent, const char *name, WFlags f ) | ||
25 | : QFrame( parent, name, f ) | ||
26 | { | ||
27 | clickWord = -1; | ||
28 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) ); | ||
29 | } | ||
30 | |||
31 | void QIMPenWordPick::clear() | ||
32 | { | ||
33 | words.clear(); | ||
34 | repaint(); | ||
35 | } | ||
36 | |||
37 | QSize QIMPenWordPick::sizeHint() const | ||
38 | { | ||
39 | return QSize( -1, font().pixelSize()+2 ); | ||
40 | } | ||
41 | |||
42 | void QIMPenWordPick::setWords( const QIMPenMatch::MatchWordList &w ) | ||
43 | { | ||
44 | words.clear(); | ||
45 | QListIterator<QIMPenMatch::MatchWord> it( w ); | ||
46 | for ( ; it.current(); ++it ) { | ||
47 | words.append( it.current()->word ); | ||
48 | } | ||
49 | repaint(); | ||
50 | } | ||
51 | |||
52 | int QIMPenWordPick::onWord( QPoint p ) | ||
53 | { | ||
54 | int x = 2; | ||
55 | int idx = 0; | ||
56 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { | ||
57 | QString word = *it; | ||
58 | int w = fontMetrics().width( word ); | ||
59 | if ( x + w > width() ) | ||
60 | break; | ||
61 | if ( p.x() > x-2 && p.x() < x + w + 2 ) | ||
62 | return idx; | ||
63 | x += w + 5; | ||
64 | if ( !idx ) | ||
65 | x += 3; | ||
66 | idx++; | ||
67 | } | ||
68 | |||
69 | return -1; | ||
70 | } | ||
71 | |||
72 | void QIMPenWordPick::paintEvent( QPaintEvent * ) | ||
73 | { | ||
74 | QPainter p(this); | ||
75 | int x = 2; | ||
76 | int h = p.fontMetrics().ascent() + 1; | ||
77 | int idx = 0; | ||
78 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { | ||
79 | QString word = *it; | ||
80 | int w = p.fontMetrics().width( word ); | ||
81 | if ( x + w > width() ) | ||
82 | break; | ||
83 | if ( idx == clickWord ) { | ||
84 | p.fillRect( x, 0, w, height(), black ); | ||
85 | p.setPen( white ); | ||
86 | } else { | ||
87 | p.setPen( colorGroup().text() ); | ||
88 | } | ||
89 | p.drawText( x, h, word ); | ||
90 | x += w + 5; | ||
91 | if ( !idx ) | ||
92 | x += 3; | ||
93 | idx++; | ||
94 | } | ||
95 | } | ||
96 | |||
97 | void QIMPenWordPick::mousePressEvent( QMouseEvent *e ) | ||
98 | { | ||
99 | clickWord = onWord( e->pos() ); | ||
100 | repaint(); | ||
101 | } | ||
102 | |||
103 | void QIMPenWordPick::mouseReleaseEvent( QMouseEvent *e ) | ||
104 | { | ||
105 | int wordIdx = onWord( e->pos() ); | ||
106 | if ( wordIdx >= 0 && wordIdx == clickWord ) { | ||
107 | //qDebug( "Clicked %s", words[wordIdx].latin1() ); | ||
108 | emit wordClicked( words[wordIdx] ); | ||
109 | } | ||
110 | clickWord = -1; | ||
111 | repaint(); | ||
112 | } | ||
113 | |||