summaryrefslogtreecommitdiff
path: root/inputmethods/pickboard/pickboardcfg.h
blob: e0dc0dd015c83e93fe1893c7af948f52f9014a68 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**********************************************************************
** 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 PICKBOARDCFG_H
#define PICKBOARDCFG_H

#include <qpe/qdawg.h>

#include <qpushbutton.h>
#include <qhbuttongroup.h>
#include <qdialog.h>
#include <qlist.h>

// Internal stuff...

class PickboardPicks;

class LetterButton : public QPushButton {
    Q_OBJECT
public:
    LetterButton(const QChar& letter, QWidget* parent);
private slots:
    void toggleCase();
private:
    bool skip;
};

class LetterChoice : public QButtonGroup {
    Q_OBJECT
public:
    LetterChoice(QWidget* parent, const QString& set);

    QChar choice() { return ch; }

signals:
    void changed();

private slots:
    void change();

private:
    QChar ch;
};

class PickboardAdd : public QDialog {
    Q_OBJECT
public:
    PickboardAdd(QWidget* owner, const QStringList& setlist);
    ~PickboardAdd();

    QString word() const;
    bool exec();

private slots:
    void checkAllDone();

private:
    QPushButton *yes;
    LetterChoice **lc;
    int nlc;
};

class PickboardConfig : QObject {
public:
    PickboardConfig(PickboardPicks* p) : parent(p), nrows(2), pressx(-1) { }
    virtual ~PickboardConfig();
    virtual void pickPoint(const QPoint& p, bool press);
    virtual void draw(QPainter*)=0;
    virtual void fillMenu(QPopupMenu&);
    virtual void doMenu(int);

protected:
    void updateRows(int from, int to);
    virtual void updateItem(int r, int i);
    virtual void pickInRow(int r, int xpos, bool press)=0;

    void changeMode(int m);
    virtual void generateText(const QString& s);
    void generateKey( int k );

    virtual void pick(bool press, int row, int item)=0;

protected:
    PickboardPicks* parent;
    int nrows;
private:
    int pressrow, pressx;
};

class StringConfig : public PickboardConfig {
public:
    StringConfig(PickboardPicks* p) : PickboardConfig(p) { }

    void draw(QPainter* p);

protected:
    virtual QString text(int r, int i)=0;
    virtual bool spreadRow(int i)=0;
    virtual QColor rowColor(int) { return Qt::black; }
    virtual void pickInRow(int r, int xpos, bool press);
    virtual void updateItem(int r, int i);
    virtual bool highlight(int,int) const;
};

class CharStringConfig : public StringConfig {
    QString input;
    QStringList chars;
public:
    CharStringConfig(PickboardPicks* p) : StringConfig(p) { }

    void addChar(const QString& s);
    virtual void doMenu(int);

protected:
    QString text(int r, int i);
    bool spreadRow(int i);
    void pick(bool press, int row, int item);
};

class DictFilterConfig : public StringConfig {
    QStringList matches;
    QStringList sets;
    QStringList othermodes;
    int lit0;
    int lit1;
    int shift;
    QString capitalize(const QString& s);
    QStringList capitalize(const QStringList& s);

public:
    QStringList input;
    DictFilterConfig(PickboardPicks* p) : StringConfig(p)
    {
	shift = 0;
	lit0 = -1;
	lit1 = -1;
    }

    void addSet(const QString& s);
    void addMode(const QString& s);

    void fillMenu(QPopupMenu& menu);
    void doMenu(int i);
    
    void add(const QString& set);

protected:
    QString text(int r, int i);

    bool spreadRow(int i);

    void pick(bool press, int row, int item);

    bool scanMatch(const QString& set, const QChar& l) const;
    void scan(const QDawg::Node* n, int ipos, const QString& str, int length, bool extend);
    void scanLengths(const QDawg::Node* n, int ipos, int& bitarray);

    bool highlight(int r,int c) const;
};

class CharConfig : public StringConfig {
    QStringList chars1;
    QStringList chars2;
public:
    CharConfig(PickboardPicks* p) : StringConfig(p) { }
    void addChar(int r, const QString& s);

protected:
    QString text(int r, int i);
    bool spreadRow(int);
    void pick(bool press, int row, int item);
};

class KeycodeConfig : public PickboardConfig {
    QValueList<int> keys1;
    QValueList<int> keys2;
    QValueList<QPixmap> keypm1;
    QValueList<QPixmap> keypm2;
    static const int xw = 8;
    static const int xmarg = 8;

public:
    KeycodeConfig(PickboardPicks* p) : PickboardConfig(p) { }
    void addKey(int r, const QPixmap& pm, int code);
    void addGap(int r, int w);

    void draw(QPainter* p);

protected:
    void pickInRow(int r, int xpos, bool press);
    QValueList<QPixmap> row(int i);

    void pick(bool press, int row, int item);
};


#endif