Diffstat (limited to 'noncore/apps/opie-reader/QTReader.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/QTReader.h | 99 |
1 files changed, 77 insertions, 22 deletions
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h index 2efb988..78230b4 100644 --- a/noncore/apps/opie-reader/QTReader.h +++ b/noncore/apps/opie-reader/QTReader.h | |||
@@ -1,41 +1,47 @@ | |||
1 | #ifndef __QTREADER_H | 1 | #ifndef __QTREADER_H |
2 | #define __QTREADER_H | 2 | #define __QTREADER_H |
3 | 3 | ||
4 | #include <qwidget.h> | 4 | #include <qwidget.h> |
5 | #include <qpainter.h> | 5 | //#include <qpainter.h> |
6 | #include <qclipboard.h> | ||
7 | #include "CBuffer.h" | ||
8 | #include "my_list.h" | 6 | #include "my_list.h" |
9 | #include "BuffDoc.h" | 7 | #include "BuffDoc.h" |
10 | #include <qtimer.h> | 8 | #include "FontControl.h" |
9 | |||
10 | //#include <qtimer.h> | ||
11 | |||
12 | class CDrawBuffer; | ||
13 | //class CBuffer; | ||
14 | class QPainter; | ||
15 | class QTimer; | ||
11 | 16 | ||
12 | class QTReader : public QWidget | 17 | class QTReader : public QWidget |
13 | { | 18 | { |
14 | Q_OBJECT | 19 | Q_OBJECT |
15 | 20 | ||
16 | friend class QTReaderApp; | 21 | friend class QTReaderApp; |
17 | void drawText(QPainter& p, int x, int y, tchar* text); | 22 | void drawText(QPainter& p, int x, int y, tchar* text); |
18 | int m_delay; | 23 | int m_delay; |
19 | unsigned int m_overlap; | 24 | unsigned int m_overlap; |
20 | bool m_autoScroll; | 25 | bool m_autoScroll; |
21 | void autoscroll(); | 26 | void autoscroll(); |
22 | QTimer* timer; | 27 | QTimer* timer; |
23 | int m_scrolldy, m_encd; | 28 | int m_scrolldy1, m_scrolldy2, m_encd; |
24 | void focusInEvent(QFocusEvent*); | 29 | void focusInEvent(QFocusEvent*); |
25 | void focusOutEvent(QFocusEvent*); | 30 | void focusOutEvent(QFocusEvent*); |
26 | void ChangeFont(int); | 31 | bool ChangeFont(int); |
27 | bool getline(CBuffer*); | 32 | bool getline(CDrawBuffer*); |
28 | int m_charWidth; | 33 | int m_charWidth; |
29 | int m_charpc; | 34 | int m_charpc; |
35 | FontControl m_fontControl; | ||
30 | public: | 36 | public: |
31 | QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0); | 37 | 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); | 38 | // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); |
33 | ~QTReader(); | 39 | ~QTReader(); |
34 | bool empty(); | 40 | bool empty(); |
35 | void toggle_autoscroll(); | 41 | void toggle_autoscroll(); |
36 | void setautoscroll(bool); | 42 | void setautoscroll(bool); |
37 | void disableAutoscroll() { m_autoScroll = false; } | 43 | void disableAutoscroll() { m_autoScroll = false; } |
38 | void copy() | 44 | void copy() |
39 | { | 45 | { |
40 | /* | 46 | /* |
41 | size_t nd = locate(); | 47 | size_t nd = locate(); |
@@ -57,24 +63,55 @@ public: | |||
57 | { | 63 | { |
58 | if (oldfile) | 64 | if (oldfile) |
59 | { | 65 | { |
60 | m_string = m_lastfile; | 66 | m_string = m_lastfile; |
61 | load_file((const tchar*)m_string); | 67 | load_file((const tchar*)m_string); |
62 | } | 68 | } |
63 | else | 69 | else |
64 | { | 70 | { |
65 | m_string = QString::null; | 71 | m_string = QString::null; |
66 | } | 72 | } |
67 | }; | 73 | }; |
68 | */ | 74 | */ |
75 | void setpeanut(bool _b) | ||
76 | { | ||
77 | bpeanut = _b; | ||
78 | setfilter(getfilter()); | ||
79 | } | ||
80 | void setremap(bool _b) | ||
81 | { | ||
82 | bremap = _b; | ||
83 | setfilter(getfilter()); | ||
84 | } | ||
85 | void setmakebold(bool _b) | ||
86 | { | ||
87 | bmakebold = _b; | ||
88 | setfilter(getfilter()); | ||
89 | } | ||
90 | void setautofmt(bool _b) | ||
91 | { | ||
92 | bautofmt = _b; | ||
93 | if (bautofmt) | ||
94 | { | ||
95 | btextfmt = false; | ||
96 | bstriphtml = false;; | ||
97 | bpeanut = false; | ||
98 | } | ||
99 | setfilter(getfilter()); | ||
100 | } | ||
101 | void settextfmt(bool _b) | ||
102 | { | ||
103 | btextfmt = _b; | ||
104 | setfilter(getfilter()); | ||
105 | } | ||
69 | void setstripcr(bool _b) | 106 | void setstripcr(bool _b) |
70 | { | 107 | { |
71 | bstripcr = _b; | 108 | bstripcr = _b; |
72 | setfilter(getfilter()); | 109 | setfilter(getfilter()); |
73 | } | 110 | } |
74 | void setstriphtml(bool _b) | 111 | void setstriphtml(bool _b) |
75 | { | 112 | { |
76 | bstriphtml = _b; | 113 | bstriphtml = _b; |
77 | setfilter(getfilter()); | 114 | setfilter(getfilter()); |
78 | } | 115 | } |
79 | void setdehyphen(bool _b) | 116 | void setdehyphen(bool _b) |
80 | { | 117 | { |
@@ -104,114 +141,132 @@ public: | |||
104 | void indentminus() | 141 | void indentminus() |
105 | { | 142 | { |
106 | if (bindenter > 1) bindenter -= 2; | 143 | if (bindenter > 1) bindenter -= 2; |
107 | setfilter(getfilter()); | 144 | setfilter(getfilter()); |
108 | } | 145 | } |
109 | void setpagemode(bool _b) | 146 | void setpagemode(bool _b) |
110 | { | 147 | { |
111 | m_bpagemode = _b; | 148 | m_bpagemode = _b; |
112 | } | 149 | } |
113 | void setmono(bool _b) | 150 | void setmono(bool _b) |
114 | { | 151 | { |
115 | m_bMonoSpaced = _b; | 152 | m_bMonoSpaced = _b; |
116 | ChangeFont(fontsizes[m_textsize]); | 153 | ChangeFont(m_fontControl.currentsize()); |
117 | locate(pagepos); | 154 | locate(pagelocate()); |
118 | } | 155 | } |
119 | void setencoding(int _f) | 156 | void setencoding(int _f) |
120 | { | 157 | { |
121 | m_encd = _f; | 158 | m_encd = _f; |
122 | setfilter(getfilter()); | 159 | setfilter(getfilter()); |
123 | } | 160 | } |
161 | MarkupType PreferredMarkup(); | ||
124 | CEncoding* getencoding() | 162 | CEncoding* getencoding() |
125 | { | 163 | { |
126 | switch (m_encd) | 164 | switch (m_encd) |
127 | { | 165 | { |
128 | case 5: | 166 | case 5: |
129 | return new Ccp1252; | 167 | return new Ccp1252; |
130 | case 4: | 168 | case 4: |
131 | return new CPalm; | 169 | return new CPalm; |
132 | case 1: | 170 | case 1: |
133 | return new CUtf8; | 171 | return new CUtf8; |
134 | case 2: | 172 | case 2: |
135 | return new CUcs16be; | 173 | return new CUcs16be; |
136 | case 3: | 174 | case 3: |
137 | return new CUcs16le; | 175 | return new CUcs16le; |
138 | case 0: | 176 | case 0: |
139 | default: | 177 | default: |
140 | return new CAscii; | 178 | return new CAscii; |
141 | } | 179 | } |
142 | } | 180 | } |
143 | CFilterChain* getfilter() | 181 | CFilterChain* getfilter() |
144 | { | 182 | { |
145 | CFilterChain * filt = new CFilterChain(getencoding()); | 183 | CFilterChain * filt = new CFilterChain(getencoding()); |
146 | if (bstripcr) filt->addfilter(new stripcr); | 184 | if (bstripcr) filt->addfilter(new stripcr); |
147 | if (bstriphtml) filt->addfilter(new striphtml); | 185 | |
186 | if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); | ||
187 | if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); | ||
188 | if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml); | ||
189 | |||
148 | if (bdehyphen) filt->addfilter(new dehyphen); | 190 | if (bdehyphen) filt->addfilter(new dehyphen); |
149 | if (bunindent) filt->addfilter(new unindent); | 191 | if (bunindent) filt->addfilter(new unindent); |
150 | if (brepara) filt->addfilter(new repara); | 192 | if (brepara) filt->addfilter(new repara); |
151 | if (bindenter) filt->addfilter(new indenter(bindenter)); | 193 | if (bindenter) filt->addfilter(new indenter(bindenter)); |
152 | if (bdblspce) filt->addfilter(new dblspce); | 194 | if (bdblspce) filt->addfilter(new dblspce); |
195 | if (bremap) filt->addfilter(new remap); | ||
196 | if (bmakebold) filt->addfilter(new embolden); | ||
153 | return filt; | 197 | return filt; |
154 | } | 198 | } |
155 | 199 | ||
156 | 200 | ||
157 | private slots: | 201 | private slots: |
158 | void doscroll(); | 202 | void doscroll(); |
159 | void drawIt( QPainter * ); | 203 | void drawIt( QPainter * ); |
160 | void paintEvent( QPaintEvent * ); | 204 | void paintEvent( QPaintEvent * ); |
161 | // void resizeEvent( QResizeEvent * p ) { update(); } | 205 | // void resizeEvent( QResizeEvent * p ) { update(); } |
162 | void keyPressEvent(QKeyEvent*); | 206 | void keyPressEvent(QKeyEvent*); |
163 | void drawFonts(QPainter*); | 207 | void drawFonts(QPainter*); |
164 | private: | 208 | private: |
209 | void setTwoTouch(bool _b); | ||
165 | void init(); | 210 | void init(); |
211 | void mousePressEvent( QMouseEvent* ); | ||
166 | void mouseReleaseEvent( QMouseEvent* ); | 212 | void mouseReleaseEvent( QMouseEvent* ); |
167 | // void mouseDoubleClickEvent( QMouseEvent* ); | 213 | // void mouseDoubleClickEvent( QMouseEvent* ); |
168 | QString m_string, m_fontname; | 214 | QString m_string, m_fontname; |
169 | void setfont(QPainter*); | 215 | void setfont(); |
170 | //myoutput stuff | 216 | //myoutput stuff |
171 | private: | 217 | private: |
218 | bool mouseUpOn; | ||
219 | bool getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt); | ||
220 | bool m_twotouch, m_touchone; | ||
221 | size_t m_startpos, m_startoffset; | ||
172 | void dopageup(); | 222 | void dopageup(); |
173 | void lineDown(); | 223 | void lineDown(); |
174 | void lineUp(); | 224 | void lineUp(); |
175 | void dopagedn(); | 225 | void dopagedn(); |
176 | long real_delay(); | 226 | long real_delay(); |
177 | int m_textsize; | 227 | int m_textsize; |
178 | int m_lastwidth; | 228 | int m_lastwidth, m_lastheight; |
179 | CBuffer** textarray; | 229 | CBufferFace<CDrawBuffer*> textarray; |
180 | size_t* locnarray; | 230 | CBufferFace<size_t> locnarray; |
181 | unsigned int numlines; | 231 | unsigned int numlines; |
182 | bool bstripcr, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, m_bBold; | 232 | bool bstripcr, btextfmt, bstriphtml, bdehyphen, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt; |
183 | bool m_bpagemode, m_bMonoSpaced; | 233 | bool m_bpagemode, m_bMonoSpaced; |
184 | QString m_targetapp, m_targetmsg; | ||
185 | unsigned char bindenter; | 234 | unsigned char bindenter; |
186 | QString m_lastfile; | 235 | QString m_lastfile; |
187 | size_t m_lastposn; | 236 | size_t m_lastposn; |
188 | public: | 237 | public: |
189 | int getch() { return buffdoc.getch(); } | 238 | int getch() { return buffdoc.getch(); } |
190 | bool tight; | 239 | bool tight; |
191 | bool load_file(const char *newfile, unsigned int lcn=0); | 240 | bool load_file(const char *newfile, unsigned int lcn=0); |
192 | BuffDoc buffdoc; | 241 | BuffDoc buffdoc; |
193 | CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } | 242 | CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } |
194 | bool locate(unsigned long n); | 243 | bool locate(unsigned long n); |
195 | void jumpto(unsigned long n) { buffdoc.locate(n); } | 244 | void jumpto(unsigned long n) { buffdoc.locate(n); } |
196 | unsigned long locate() { return buffdoc.locate(); } | 245 | unsigned long locate() { return buffdoc.locate(); } |
197 | unsigned long pagelocate() { return pagepos; } | 246 | unsigned long explocate() { return buffdoc.explocate(); } |
198 | unsigned long pagepos, mylastpos; | 247 | unsigned long pagelocate() { return locnarray[0]; } |
199 | void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagepos); } | 248 | unsigned long mylastpos; |
249 | void setfilter(CFilterChain *f) { buffdoc.setfilter(f); locate(pagelocate()); } | ||
200 | void restore() { jumpto(mylastpos); } | 250 | void restore() { jumpto(mylastpos); } |
201 | void goUp(); | 251 | void goUp(); |
202 | void refresh() { locate(pagepos); } | 252 | void refresh() { locate(pagelocate()); } |
203 | void goDown(); | 253 | void goDown(); |
204 | // bool bold; | 254 | // bool bold; |
205 | int textsize() { return m_textsize; } | 255 | int textsize() { return m_textsize; } |
206 | void textsize(int ts) { m_textsize = ts; } | 256 | void textsize(int ts) { m_textsize = ts; } |
207 | bool fillbuffer(); | 257 | bool fillbuffer(int ru = 0, int ht = 0); |
208 | unsigned int screenlines(); | 258 | unsigned int screenlines(); |
209 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } | 259 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } |
210 | static const char *fonts[]; | 260 | static const char *fonts[]; |
211 | unsigned int *fontsizes; | 261 | // unsigned int *fontsizes; |
212 | int m_ascent, m_descent, m_linespacing; | 262 | int m_ascent, m_descent, m_linespacing; |
213 | QFontMetrics* m_fm; | 263 | QFontMetrics* m_fm; |
214 | QString firstword(); | 264 | QString firstword(); |
265 | |||
266 | signals: | ||
267 | void OnRedraw(); | ||
268 | void OnWordSelected(const QString&, size_t, const QString&); | ||
269 | void OnActionPressed(); | ||
215 | }; | 270 | }; |
216 | 271 | ||
217 | #endif | 272 | #endif |