summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.h
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.h217
1 files changed, 217 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h
new file mode 100644
index 0000000..2efb988
--- a/dev/null
+++ b/noncore/apps/opie-reader/QTReader.h
@@ -0,0 +1,217 @@
1#ifndef __QTREADER_H
2#define __QTREADER_H
3
4#include <qwidget.h>
5#include <qpainter.h>
6#include <qclipboard.h>
7#include "CBuffer.h"
8#include "my_list.h"
9#include "BuffDoc.h"
10#include <qtimer.h>
11
12class QTReader : public QWidget
13{
14 Q_OBJECT
15
16 friend class QTReaderApp;
17 void drawText(QPainter& p, int x, int y, tchar* text);
18 int m_delay;
19 unsigned int m_overlap;
20 bool m_autoScroll;
21 void autoscroll();
22 QTimer* timer;
23 int m_scrolldy, m_encd;
24 void focusInEvent(QFocusEvent*);
25 void focusOutEvent(QFocusEvent*);
26 void ChangeFont(int);
27 bool getline(CBuffer*);
28 int m_charWidth;
29 int m_charpc;
30public:
31 QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
32 // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
33 ~QTReader();
34 bool empty();
35 void toggle_autoscroll();
36 void setautoscroll(bool);
37 void disableAutoscroll() { m_autoScroll = false; }
38 void copy()
39 {
40/*
41 size_t nd = locate();
42 jumpto(m_mark);
43 QString text;
44 while (m_mark < nd)
45 {
46 text += buffdoc.getch();
47 m_mark++;
48 }
49 QApplication::clipboard()->setText(text);
50 jumpto(nd);
51*/
52 };
53 void clear() {};
54 void setText(const QString& n, const QString& s) { m_string = n; load_file((const char*)s); };
55 /*
56 void setText(bool oldfile)
57 {
58 if (oldfile)
59 {
60 m_string = m_lastfile;
61 load_file((const tchar*)m_string);
62 }
63 else
64 {
65 m_string = QString::null;
66 }
67 };
68 */
69 void setstripcr(bool _b)
70 {
71 bstripcr = _b;
72 setfilter(getfilter());
73 }
74 void setstriphtml(bool _b)
75 {
76 bstriphtml = _b;
77 setfilter(getfilter());
78 }
79 void setdehyphen(bool _b)
80 {
81 bdehyphen = _b;
82 setfilter(getfilter());
83 }
84 void setunindent(bool _b)
85 {
86 bunindent = _b;
87 setfilter(getfilter());
88 }
89 void setrepara(bool _b)
90 {
91 brepara = _b;
92 setfilter(getfilter());
93 }
94 void setdblspce(bool _b)
95 {
96 bdblspce = _b;
97 setfilter(getfilter());
98 }
99 void indentplus()
100 {
101 if (bindenter < 15) bindenter += 2;
102 setfilter(getfilter());
103 }
104 void indentminus()
105 {
106 if (bindenter > 1) bindenter -= 2;
107 setfilter(getfilter());
108 }
109 void setpagemode(bool _b)
110 {
111 m_bpagemode = _b;
112 }
113 void setmono(bool _b)
114 {
115 m_bMonoSpaced = _b;
116 ChangeFont(fontsizes[m_textsize]);
117 locate(pagepos);
118 }
119 void setencoding(int _f)
120 {
121 m_encd = _f;
122 setfilter(getfilter());
123 }
124 CEncoding* getencoding()
125 {
126 switch (m_encd)
127 {
128 case 5:
129 return new Ccp1252;
130 case 4:
131 return new CPalm;
132 case 1:
133 return new CUtf8;
134 case 2:
135 return new CUcs16be;
136 case 3:
137 return new CUcs16le;
138 case 0:
139 default:
140 return new CAscii;
141 }
142 }
143 CFilterChain* getfilter()
144 {
145 CFilterChain * filt = new CFilterChain(getencoding());
146 if (bstripcr) filt->addfilter(new stripcr);
147 if (bstriphtml) filt->addfilter(new striphtml);
148 if (bdehyphen) filt->addfilter(new dehyphen);
149 if (bunindent) filt->addfilter(new unindent);
150 if (brepara) filt->addfilter(new repara);
151 if (bindenter) filt->addfilter(new indenter(bindenter));
152 if (bdblspce) filt->addfilter(new dblspce);
153 return filt;
154 }
155
156
157private slots:
158 void doscroll();
159 void drawIt( QPainter * );
160 void paintEvent( QPaintEvent * );
161// void resizeEvent( QResizeEvent * p ) { update(); }
162 void keyPressEvent(QKeyEvent*);
163 void drawFonts(QPainter*);
164 private:
165 void init();
166 void mouseReleaseEvent( QMouseEvent* );
167// void mouseDoubleClickEvent( QMouseEvent* );
168 QString m_string, m_fontname;
169 void setfont(QPainter*);
170 //myoutput stuff
171 private:
172 void dopageup();
173 void lineDown();
174 void lineUp();
175 void dopagedn();
176 long real_delay();
177 int m_textsize;
178 int m_lastwidth;
179 CBuffer** textarray;
180 size_t* locnarray;
181 unsigned int numlines;
182 bool bstripcr, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, m_bBold;
183 bool m_bpagemode, m_bMonoSpaced;
184 QString m_targetapp, m_targetmsg;
185 unsigned char bindenter;
186 QString m_lastfile;
187 size_t m_lastposn;
188 public:
189 int getch() { return buffdoc.getch(); }
190 bool tight;
191 bool load_file(const char *newfile, unsigned int lcn=0);
192 BuffDoc buffdoc;
193 CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
194 bool locate(unsigned long n);
195 void jumpto(unsigned long n) { buffdoc.locate(n); }
196 unsigned long locate() { return buffdoc.locate(); }
197 unsigned long pagelocate() { return pagepos; }
198 unsigned long pagepos, mylastpos;
199 void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagepos); }
200 void restore() { jumpto(mylastpos); }
201 void goUp();
202 void refresh() { locate(pagepos); }
203 void goDown();
204 // bool bold;
205 int textsize() { return m_textsize; }
206 void textsize(int ts) { m_textsize = ts; }
207 bool fillbuffer();
208 unsigned int screenlines();
209 void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); }
210 static const char *fonts[];
211 unsigned int *fontsizes;
212 int m_ascent, m_descent, m_linespacing;
213 QFontMetrics* m_fm;
214 QString firstword();
215};
216
217#endif