Diffstat (limited to 'inputmethods/handwriting/qimpenwordpick.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/handwriting/qimpenwordpick.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/inputmethods/handwriting/qimpenwordpick.cpp b/inputmethods/handwriting/qimpenwordpick.cpp index 8ee103d..39745c6 100644 --- a/inputmethods/handwriting/qimpenwordpick.cpp +++ b/inputmethods/handwriting/qimpenwordpick.cpp | |||
@@ -11,103 +11,103 @@ | |||
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 <qpainter.h> | 21 | #include <qpainter.h> |
22 | #include "qimpenwordpick.h" | 22 | #include "qimpenwordpick.h" |
23 | 23 | ||
24 | QIMPenWordPick::QIMPenWordPick( QWidget *parent, const char *name, WFlags f ) | 24 | QIMPenWordPick::QIMPenWordPick( QWidget *parent, const char *name, WFlags f ) |
25 | : QFrame( parent, name, f ) | 25 | : QFrame( parent, name, f ) |
26 | { | 26 | { |
27 | clickWord = -1; | 27 | clickWord = -1; |
28 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) ); | 28 | setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) ); |
29 | } | 29 | } |
30 | 30 | ||
31 | void QIMPenWordPick::clear() | 31 | void QIMPenWordPick::clear() |
32 | { | 32 | { |
33 | words.clear(); | 33 | words.clear(); |
34 | repaint(); | 34 | repaint(); |
35 | } | 35 | } |
36 | 36 | ||
37 | QSize QIMPenWordPick::sizeHint() const | 37 | QSize QIMPenWordPick::sizeHint() const |
38 | { | 38 | { |
39 | return QSize( -1, font().pixelSize()+2 ); | 39 | return QSize( -1, font().pixelSize()+2 ); |
40 | } | 40 | } |
41 | 41 | ||
42 | void QIMPenWordPick::setWords( const QIMPenMatch::MatchWordList &w ) | 42 | void QIMPenWordPick::setWords( const QIMPenMatch::MatchWordList &w ) |
43 | { | 43 | { |
44 | words.clear(); | 44 | words.clear(); |
45 | QListIterator<QIMPenMatch::MatchWord> it( w ); | 45 | QListIterator<QIMPenMatch::MatchWord> it( w ); |
46 | for ( ; it.current(); ++it ) { | 46 | for ( ; it.current(); ++it ) { |
47 | words.append( it.current()->word ); | 47 | words.append( it.current()->word ); |
48 | } | 48 | } |
49 | repaint(); | 49 | repaint(); |
50 | } | 50 | } |
51 | 51 | ||
52 | int QIMPenWordPick::onWord( QPoint p ) | 52 | int QIMPenWordPick::onWord( QPoint p ) |
53 | { | 53 | { |
54 | int x = 2; | 54 | int x = 2; |
55 | int idx = 0; | 55 | int idx = 0; |
56 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { | 56 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { |
57 | QString word = *it; | 57 | QString word = *it; |
58 | int w = fontMetrics().width( word ); | 58 | int w = fontMetrics().width( word ); |
59 | if ( x + w > width() ) | 59 | if ( x + w > width() ) |
60 | break; | 60 | break; |
61 | if ( p.x() > x-2 && p.x() < x + w + 2 ) | 61 | if ( p.x() > x-2 && p.x() < x + w + 2 ) |
62 | return idx; | 62 | return idx; |
63 | x += w + 5; | 63 | x += w + 5; |
64 | if ( !idx ) | 64 | if ( !idx ) |
65 | x += 3; | 65 | x += 3; |
66 | idx++; | 66 | idx++; |
67 | } | 67 | } |
68 | 68 | ||
69 | return -1; | 69 | return -1; |
70 | } | 70 | } |
71 | 71 | ||
72 | void QIMPenWordPick::paintEvent( QPaintEvent * ) | 72 | void QIMPenWordPick::paintEvent( QPaintEvent * ) |
73 | { | 73 | { |
74 | QPainter p(this); | 74 | QPainter p(this); |
75 | int x = 2; | 75 | int x = 2; |
76 | int h = p.fontMetrics().ascent() + 1; | 76 | int h = p.fontMetrics().ascent() + 1; |
77 | int idx = 0; | 77 | int idx = 0; |
78 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { | 78 | for ( QStringList::Iterator it = words.begin(); it != words.end(); ++it ) { |
79 | QString word = *it; | 79 | QString word = *it; |
80 | int w = p.fontMetrics().width( word ); | 80 | int w = p.fontMetrics().width( word ); |
81 | if ( x + w > width() ) | 81 | if ( x + w > width() ) |
82 | break; | 82 | break; |
83 | if ( idx == clickWord ) { | 83 | if ( idx == clickWord ) { |
84 | p.fillRect( x, 0, w, height(), black ); | 84 | p.fillRect( x, 0, w, height(), black ); |
85 | p.setPen( white ); | 85 | p.setPen( white ); |
86 | } else { | 86 | } else { |
87 | p.setPen( colorGroup().text() ); | 87 | p.setPen( colorGroup().text() ); |
88 | } | 88 | } |
89 | p.drawText( x, h, word ); | 89 | p.drawText( x, h, word ); |
90 | x += w + 5; | 90 | x += w + 5; |
91 | if ( !idx ) | 91 | if ( !idx ) |
92 | x += 3; | 92 | x += 3; |
93 | idx++; | 93 | idx++; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | void QIMPenWordPick::mousePressEvent( QMouseEvent *e ) | 97 | void QIMPenWordPick::mousePressEvent( QMouseEvent *e ) |
98 | { | 98 | { |
99 | clickWord = onWord( e->pos() ); | 99 | clickWord = onWord( e->pos() ); |
100 | repaint(); | 100 | repaint(); |
101 | } | 101 | } |
102 | 102 | ||
103 | void QIMPenWordPick::mouseReleaseEvent( QMouseEvent *e ) | 103 | void QIMPenWordPick::mouseReleaseEvent( QMouseEvent *e ) |
104 | { | 104 | { |
105 | int wordIdx = onWord( e->pos() ); | 105 | int wordIdx = onWord( e->pos() ); |
106 | if ( wordIdx >= 0 && wordIdx == clickWord ) { | 106 | if ( wordIdx >= 0 && wordIdx == clickWord ) { |
107 | //qDebug( "Clicked %s", words[wordIdx].latin1() ); | 107 | //odebug << "Clicked " << words[wordIdx].latin1() << oendl; |
108 | emit wordClicked( words[wordIdx] ); | 108 | emit wordClicked( words[wordIdx] ); |
109 | } | 109 | } |
110 | clickWord = -1; | 110 | clickWord = -1; |
111 | repaint(); | 111 | repaint(); |
112 | } | 112 | } |
113 | 113 | ||