summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.h
blob: 3d5f57d448815044e610d793bd4ea5316883a968 (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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
#ifndef __QTREADER_H
#define __QTREADER_H

#include <qwidget.h>
//#include <qpainter.h>
#include "my_list.h"
#include "BuffDoc.h"
#include "FontControl.h"

//#include <qtimer.h>

class CDrawBuffer;
//class CBuffer;
class QPainter;
class QTimer;
class QPixmap;
class statedata;

class QTReader : public QWidget
{
    Q_OBJECT

      friend class QTReaderApp;
    void suspend() { buffdoc.suspend(); }
    void drawText(QPainter& p, int x, int y, tchar* text);
    int m_delay;
    unsigned int m_overlap;
    bool m_autoScroll;
    void autoscroll();
    QTimer* timer;
    int m_scrolldy1, m_scrolldy2, m_encd;
    void focusInEvent(QFocusEvent*);
    void focusOutEvent(QFocusEvent*);
    bool ChangeFont(int);
    bool getline(CDrawBuffer*);
    int m_charWidth;
    int m_charpc;
    FontControl m_fontControl;
public:
    QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
    //    QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
    ~QTReader();
    void zoomin();
    void zoomout();
    void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
	{
	    buffdoc.setSaveData(data, len, src, srclen);
	}
    void putSaveData(unsigned char*& src, unsigned short& srclen)
	{
	    buffdoc.putSaveData(src, srclen);
	}
    bool empty();
    void setContinuous(bool _b);
    void toggle_autoscroll();
    void setautoscroll(bool);
    void disableAutoscroll() { m_autoScroll = false; }
    void copy()
      {
/*
        size_t nd = locate();
	jumpto(m_mark);
        QString text;
        while (m_mark < nd)
          {
            text += buffdoc.getch();
            m_mark++;
          }
        QApplication::clipboard()->setText(text);
        jumpto(nd);
*/
      };
    void clear() {};
    void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
    /*
    void setText(bool oldfile)
      {
	if (oldfile)
	  {
	    m_string = m_lastfile;
	    load_file((const tchar*)m_string);
	  }
	else
	  {
	    m_string = QString::null;
	  }
      };
    */
    void setpeanut(bool _b)
      {
	bpeanut = _b;
	setfilter(getfilter());
      }
    void setremap(bool _b)
      {
	bremap = _b;
	setfilter(getfilter());
      }
    void setmakebold(bool _b)
      {
	bmakebold = _b;
	setfilter(getfilter());
      }
    void setautofmt(bool _b)
      {
	bautofmt = _b;
	if (bautofmt)
	{
	    btextfmt = false;
	    bstriphtml = false;;
	    bpeanut = false;
	}
	setfilter(getfilter());
      }
    void settextfmt(bool _b)
      {
	btextfmt = _b;
	setfilter(getfilter());
      }
    void setstripcr(bool _b)
      {
	bstripcr = _b;
	setfilter(getfilter());
      }
    void setonespace(bool _b)
      {
	bonespace = _b;
	setfilter(getfilter());
      }
#ifdef REPALM
    void setrepalm(bool _b)
      {
	brepalm = _b;
	setfilter(getfilter());
      }
#endif
    void setstriphtml(bool _b)
      {
	bstriphtml = _b;
	setfilter(getfilter());
      }
    void setdehyphen(bool _b)
      {
	bdehyphen = _b;
	setfilter(getfilter());
      }
    void setunindent(bool _b)
      {
	bunindent = _b;
	setfilter(getfilter());
      }
    void setrepara(bool _b)
      {
	brepara = _b;
	setfilter(getfilter());
      }
    void setdblspce(bool _b)
      {
	bdblspce = _b;
	setfilter(getfilter());
      }
    void indentplus()
      {
	if (bindenter < 15) bindenter += 2;
	setfilter(getfilter());
      }
    void indentminus()
      {
	if (bindenter > 1) bindenter -= 2;
	setfilter(getfilter());
      }
    void setpagemode(bool _b)
      {
	m_bpagemode = _b;
      }
    void setmono(bool _b)
      {
	m_bMonoSpaced = _b;
	ChangeFont(m_fontControl.currentsize());
	locate(pagelocate());
      }
    void setencoding(int _f)
	{
	    m_encd = _f;
	    setfilter(getfilter());
	}
    MarkupType PreferredMarkup();
    CEncoding* getencoding()
	{
	    switch (m_encd)
	    {
		case 5:
		    return new Ccp1252;
		case 4:
		    return new CPalm;
		case 1:
		    return new CUtf8;
		case 2:
		    return new CUcs16be;
		case 3:
		    return new CUcs16le;
		case 0:
		default:
		    return new CAscii;
	    }
	}
  CFilterChain* getfilter()
  {
    CFilterChain * filt = new CFilterChain(getencoding());
    if (bstripcr) filt->addfilter(new stripcr);

    if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
    if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
    if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml);

    if (bdehyphen) filt->addfilter(new dehyphen);
    if (bunindent) filt->addfilter(new unindent);
    if (brepara) filt->addfilter(new repara);
    if (bonespace) filt->addfilter(new OnePara);
    if (bindenter) filt->addfilter(new indenter(bindenter));
    if (bdblspce) filt->addfilter(new dblspce);
#ifdef REPALM
    if (brepalm) filt->addfilter(new repalm);
#endif
    if (bremap) filt->addfilter(new remap);
    if (bmakebold) filt->addfilter(new embolden);
    return filt;
  }


private slots:
	void doscroll();
    void   drawIt( QPainter * );
    void   paintEvent( QPaintEvent * );
//    void   resizeEvent( QResizeEvent * p ) { update(); }
  void keyPressEvent(QKeyEvent*);
  void drawFonts(QPainter*);
 private:
  void setTwoTouch(bool _b);
  void init();
  void mousePressEvent( QMouseEvent* );
  void mouseReleaseEvent( QMouseEvent* );
//  void mouseDoubleClickEvent( QMouseEvent* );
  QString m_string, m_fontname;
  void setfont();
  //myoutput stuff
 private:
  bool mouseUpOn;
  linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt);
  bool m_twotouch, m_touchone;
  size_t m_startpos, m_startoffset;
  void dopageup(unsigned int);
  void dopageup();
  void lineDown();
  void lineUp();
  void dopagedn();
  long real_delay();
  int m_textsize;
  int m_lastwidth, m_lastheight;
  CBufferFace<CDrawBuffer*> textarray;
  CBufferFace<size_t>   locnarray;
  unsigned int numlines;
  bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace;
#ifdef REPALM
  bool brepalm;
#endif
  bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
  unsigned char bindenter;
  QString m_lastfile;
  size_t m_lastposn;
 public:
  bool bDoUpdates;
  bool m_navkeys;
  void NavUp();
  void NavDown();
  int getch() { return buffdoc.getch(); }
  bool tight;
  bool load_file(const char *newfile, unsigned int lcn=0);
  BuffDoc buffdoc;
  CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
  bool locate(unsigned long n);
  void jumpto(unsigned long n) { buffdoc.unsuspend(); buffdoc.locate(n); }
  unsigned long locate() { buffdoc.unsuspend(); return buffdoc.locate(); }
  unsigned long explocate() { buffdoc.unsuspend(); return buffdoc.explocate(); }
  unsigned long pagelocate() { return locnarray[0]; }
  unsigned long mylastpos;
  void setfilter(CFilterChain *f) { buffdoc.unsuspend(); buffdoc.setfilter(f); locate(pagelocate()); }
  void restore() { jumpto(mylastpos); }
  void goUp();
  void refresh() { locate(pagelocate()); }
  void goDown();
  //  bool bold;
  int textsize() { return m_textsize; }
  void textsize(int ts) { m_textsize = ts; }
  bool fillbuffer(int ru = 0, int ht = 0);
  unsigned int screenlines();
  void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.unsuspend(); buffdoc.sizes(fs,ts); }
  static const char *fonts[];
//  unsigned int   *fontsizes;
  int m_ascent, m_descent, m_linespacing;
  QFontMetrics* m_fm;
  QString firstword();
  void setstate(const statedata& sd);

 signals:
  void OnRedraw();
  void OnWordSelected(const QString&, size_t, const QString&);
  void OnActionPressed();
  void OnShowPicture(QPixmap&);
};

#endif