summaryrefslogtreecommitdiff
path: root/inputmethods/handwriting/qimpenchar.h
blob: 92ee2c17c2c91b4e7cdfcf7a22e16dcb1ec566e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/**********************************************************************
** Copyright (C) 2000 Trolltech AS.  All rights reserved.
**
** This file is part of Qtopia Environment.
**
** 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.
**
**********************************************************************/

#ifndef QIMPENCHAR_H_
#define QIMPENCHAR_H_

#include <qlist.h>
#include <qvaluelist.h>
#include <qcstring.h>
#include "qimpenstroke.h"

struct QIMPenSpecialKeys {
    int code;
    char *name;
};

extern const QIMPenSpecialKeys qimpen_specialKeys[];


class QIMPenChar
{
public:
    QIMPenChar();
    QIMPenChar( const QIMPenChar & );

    unsigned int character() const { return ch; }
    void setCharacter( unsigned int c ) { ch = c; }

    const QString &data() const { return d; }
    void setData( const QString &ba ) { d = ba; }

    QString name() const;
    bool isEmpty() const { return strokes.isEmpty(); }
    unsigned int strokeCount() const { return strokes.count(); }
    unsigned int strokeLength( int s ) const;
    void clear();
    int match( QIMPenChar *ch );
    const QIMPenStrokeList &penStrokes() { return strokes; }
    QPoint startingPoint() const { return strokes.getFirst()->startingPoint(); }
    QRect boundingRect();

    void setFlag( int f ) { flags |= f; }
    void clearFlag( int f ) { flags &= ~f; }
    bool testFlag( int f ) { return flags & f; }

    enum Flags { System=0x01, Deleted=0x02, CombineRight=0x04, Data=0x08, Combined=0x10 };
    // Correspond to codes in template files.  Do not change values.
    enum Mode { ModeBase=0x4000, Caps=0x4001, Shortcut=0x4002, CapsLock=0x4003,
		 Punctuation=0x4004, Symbol=0x4005, Extended=0x4006 };

    QIMPenChar &operator=( const QIMPenChar &s );

    void addStroke( QIMPenStroke * );

protected:
    unsigned int ch;
    QString d;
    Q_UINT8 flags;
    QIMPenStrokeList strokes;

    friend QDataStream &operator<< (QDataStream &, const QIMPenChar &);
    friend QDataStream &operator>> (QDataStream &, QIMPenChar &);
};

typedef QList<QIMPenChar> QIMPenCharList;
typedef QListIterator<QIMPenChar> QIMPenCharIterator;

QDataStream & operator<< (QDataStream & s, const QIMPenChar &ws);
QDataStream & operator>> (QDataStream & s, QIMPenChar &ws);

struct QIMPenCharMatch
{
    int error;
    QIMPenChar *penChar;

    bool operator>( const QIMPenCharMatch &m );
    bool operator<( const QIMPenCharMatch &m );
    bool operator<=( const QIMPenCharMatch &m );
};

typedef QValueList<QIMPenCharMatch> QIMPenCharMatchList;


class QIMPenCharSet
{
public:
    QIMPenCharSet();
    QIMPenCharSet( const QString &fn );

    bool isEmpty() const { return chars.isEmpty(); }
    unsigned int count() const { return chars.count(); }
    void clear() { chars.clear(); }

    void setDescription( const QString &d ) { desc = d; }
    QString description() const { return desc; }
    void setTitle( const QString &t ) { csTitle = t; }
    QString title() const { return csTitle; }

    QIMPenCharMatchList match( QIMPenChar *ch );
    void addChar( QIMPenChar *ch );
    void removeChar( QIMPenChar *ch );
    QIMPenChar *at( int i );
    void setHidden ( const bool &b ) { phidden = b; }
    bool hidden() const { return phidden; }

    unsigned maximumStrokes() const { return maxStrokes; }

    void up( QIMPenChar *ch );
    void down( QIMPenChar *ch );

    enum Domain { System, User };
    enum Type { Unknown=0x00, Lower=0x01, Upper=0x02, Combining=0x04,
		Numeric=0x08, Punctuation=0x10, Symbol=0x20, Shortcut=0x40 };

    const QIMPenCharList &characters() const { return chars; }

    void setType( Type t ) { csType = t; }
    Type type() const { return csType; }

    const QString &filename( Domain d ) const;
    void setFilename( const QString &fn, Domain d=System );
    bool load( const QString &fn, Domain d=System );
    bool save( Domain d=System );

protected:
    void markDeleted( uint ch );

protected:
    QString csTitle;
    QString desc;
    QString sysFilename;
    QString userFilename;
    Type csType;
    unsigned maxStrokes;
    QIMPenCharList chars;
    QIMPenCharMatchList matches;
    bool phidden : 1;
};

typedef QList<QIMPenCharSet> QIMPenCharSetList;
typedef QListIterator<QIMPenCharSet> QIMPenCharSetIterator;

#endif