summaryrefslogtreecommitdiff
path: root/inputmethods/handwriting/qimpenchar.cpp
Side-by-side diff
Diffstat (limited to 'inputmethods/handwriting/qimpenchar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/handwriting/qimpenchar.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/inputmethods/handwriting/qimpenchar.cpp b/inputmethods/handwriting/qimpenchar.cpp
index 929f370..db5d135 100644
--- a/inputmethods/handwriting/qimpenchar.cpp
+++ b/inputmethods/handwriting/qimpenchar.cpp
@@ -5,48 +5,49 @@
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qfile.h>
#include <qtl.h>
#include <math.h>
#include <limits.h>
#include <errno.h>
#include <qdatastream.h>
#include "qimpencombining.h"
#include "qimpenchar.h"
+#include "opie2/odebug.h"
#define QIMPEN_MATCH_THRESHOLD 200000
const QIMPenSpecialKeys qimpen_specialKeys[] = {
{ Qt::Key_Escape, "[Esc]" },
{ Qt::Key_Tab, "[Tab]" },
{ Qt::Key_Backspace, "[BackSpace]" },
{ Qt::Key_Return, "[Return]" },
{ QIMPenChar::Caps, "[Uppercase]" },
{ QIMPenChar::CapsLock, "[Caps Lock]" },
{ QIMPenChar::Shortcut, "[Shortcut]" },
{ QIMPenChar::Punctuation, "[Punctuation]" },
{ QIMPenChar::Symbol, "[Symbol]" },
{ QIMPenChar::Extended, "[Extended]" },
{ Qt::Key_unknown, 0 } };
/*!
\class QIMPenChar qimpenchar.h
Handles a single character. Can calculate closeness of match to
another character.
*/
@@ -146,64 +147,64 @@ int QIMPenChar::match( QIMPenChar *pen )
*/
int err = 0;
int maxErr = 0;
int diff = 0;
QIMPenStrokeIterator it1( strokes );
QIMPenStrokeIterator it2( pen->strokes );
err = it1.current()->match( it2.current() );
if ( err > maxErr )
maxErr = err;
++it1;
++it2;
while ( err < 400000 && it1.current() && it2.current() ) {
QPoint p1 = it1.current()->boundingRect().center() -
strokes.getFirst()->boundingRect().center();
QPoint p2 = it2.current()->boundingRect().center() -
pen->strokes.getFirst()->boundingRect().center();
int xdiff = QABS( p1.x() - p2.x() ) - 6;
int ydiff = QABS( p1.y() - p2.y() ) - 5;
if ( xdiff < 0 )
xdiff = 0;
if ( ydiff < 0 )
ydiff = 0;
if ( xdiff > 10 || ydiff > 10 ) { // not a chance
#ifdef DEBUG_QIMPEN
- qDebug( "char %c, stroke starting pt diff excessive", pen->ch );
+ odebug << "char " << pen->ch <<", stroke starting pt diff excessive" << oendl;
#endif
return INT_MAX;
}
diff += xdiff*xdiff + ydiff*ydiff;
err = it1.current()->match( it2.current() );
if ( err > maxErr )
maxErr = err;
++it1;
++it2;
}
maxErr += diff * diff * 6; // magic weighting :)
#ifdef DEBUG_QIMPEN
- qDebug( "char: %c, maxErr %d, diff %d, (%d)", pen->ch, maxErr, diff, strokes.count() );
+ odebug << "char: " << pen->ch << ", maxErr " << maxErr << ", diff " << diff << ", " << strokes.count() << oendl;
#endif
return maxErr;
}
/*!
Return the bounding rect of this character. It may have sides with
negative coords since its origin is where the user started drawing
the character.
*/
QRect QIMPenChar::boundingRect()
{
QRect br;
QIMPenStroke *st = strokes.first();
while ( st ) {
br |= st->boundingRect();
st = strokes.next();
}
return br;
}
/*!
Write the character's data to the stream.
@@ -437,50 +438,50 @@ QIMPenCharMatchList QIMPenCharSet::match( QIMPenChar *ch )
if (tmplChar->penStrokes().count() != ch->penStrokes().count())
err = QMIN(err*3, QIMPEN_MATCH_THRESHOLD);
QIMPenCharMatchList::Iterator it;
for ( it = matches.begin(); it != matches.end(); ++it ) {
if ( (*it).penChar->character() == tmplChar->character() &&
(*it).penChar->penStrokes().count() == tmplChar->penStrokes().count() ) {
if ( (*it).error > err )
(*it).error = err;
break;
}
}
if ( it == matches.end() ) {
QIMPenCharMatch m;
m.error = err;
m.penChar = tmplChar;
matches.append( m );
}
}
}
}
qHeapSort( matches );
/*
QIMPenCharMatchList::Iterator it;
for ( it = matches.begin(); it != matches.end(); ++it ) {
- qDebug( "Match: \'%c\', error %d, strokes %d", (*it).penChar->character(),
- (*it).error, (*it).penChar->penStrokes().count() );
+
+ odebug << "Match: \'" << (*it).penChar->character() "\', error " << (*it).error ", strokes " <<(*it).penChar->penStrokes().count() << oendl;
}
*/
return matches;
}
/*!
Add a character \a ch to this set.
QIMPenCharSet will delete this character when it is no longer needed.
*/
void QIMPenCharSet::addChar( QIMPenChar *ch )
{
if ( ch->penStrokes().count() > maxStrokes )
maxStrokes = ch->penStrokes().count();
chars.append( ch );
}
/*!
Remove a character by reference \a ch from this set.
QIMPenCharSet will delete this character.
*/
void QIMPenCharSet::removeChar( QIMPenChar *ch )
{
chars.remove( ch );
}