Diffstat (limited to 'noncore/apps/opie-reader/QTReader.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/QTReader.h | 230 |
1 files changed, 187 insertions, 43 deletions
diff --git a/noncore/apps/opie-reader/QTReader.h b/noncore/apps/opie-reader/QTReader.h index f89de63..7b0ebc8 100644 --- a/noncore/apps/opie-reader/QTReader.h +++ b/noncore/apps/opie-reader/QTReader.h | |||
@@ -3,5 +3,5 @@ | |||
3 | 3 | ||
4 | //#define _SCROLLPIPE | 4 | //#define _SCROLLPIPE |
5 | 5 | #include "static.h" | |
6 | #include <qwidget.h> | 6 | #include <qwidget.h> |
7 | //#include <qpainter.h> | 7 | //#include <qpainter.h> |
@@ -14,25 +14,74 @@ | |||
14 | class CDrawBuffer; | 14 | class CDrawBuffer; |
15 | //class CBuffer; | 15 | //class CBuffer; |
16 | #include <qpixmap.h> | ||
16 | class QPainter; | 17 | class QPainter; |
17 | class QTimer; | 18 | class QTimer; |
18 | class QPixmap; | 19 | class QImage; |
20 | |||
21 | #include "BGType.h" | ||
22 | #include "striphtml.h" | ||
23 | |||
24 | #define ROTATION_ENABLED | ||
25 | #define SPECIALSCROLL | ||
26 | #define DOUBLEBUFFER | ||
27 | #ifdef DOUBLEBUFFER | ||
28 | class QPainter; | ||
29 | #endif | ||
30 | |||
31 | class CStyle; | ||
19 | 32 | ||
20 | class QTReader : public QWidget | 33 | class QTReader : public QWidget |
21 | { | 34 | { |
22 | Q_OBJECT | 35 | Q_OBJECT |
36 | friend class QTReaderApp; | ||
37 | #ifdef DOUBLEBUFFER | ||
38 | QPixmap *dbuff; | ||
39 | QPainter* dbp; | ||
40 | #endif | ||
41 | void drawSingleLine(int lineno); | ||
42 | void gotoLink(); | ||
43 | void emitRedraw(); | ||
44 | CStyle* m_currentlinkstyle; | ||
45 | int m_currentlink; | ||
46 | int m_currentlinkoffset; | ||
47 | QPixmap m_bgpm; | ||
48 | bool m_bgIsScaled; | ||
49 | bground m_bgtype; | ||
50 | int m_scrollpos; | ||
51 | unsigned short m_scrollstep; | ||
52 | void blitRot(int dx, int sx, int sw, int sh, CDrawBuffer* txt); | ||
53 | void setBackgroundBitmap(const QPixmap& _pm, bground bg) | ||
54 | { | ||
55 | m_bgpm = _pm; | ||
56 | m_bgtype = bg; | ||
57 | m_bgIsScaled = false; | ||
58 | } | ||
23 | 59 | ||
60 | QColor m_bg, m_default_bg, m_default_fg, m_negative_fg; | ||
24 | static tchar pluckernextpart[]; | 61 | static tchar pluckernextpart[]; |
25 | static tchar jplucknextpart[]; | 62 | static tchar jplucknextpart[]; |
26 | friend class QTReaderApp; | 63 | CList<Bkmk>* pBkmklist; |
27 | void suspend(); | 64 | void setHyphenThreshold(int _v) { buffdoc.setHyphenThreshold(_v); } |
65 | void ResetScroll(); | ||
28 | void increaseScroll(); | 66 | void increaseScroll(); |
29 | void reduceScroll(); | 67 | void reduceScroll(); |
30 | void drawText(QPainter& p, int x, int y, tchar* text); | 68 | void drawText(QPainter& p, int x, int y, tchar* text); |
31 | int m_delay; | 69 | void DrawScroll( QPainter *p, int w, int h ); |
70 | void dorollingscroll(bool); | ||
71 | void doinplacescroll(); | ||
72 | void dostaticscroll(); | ||
73 | void suspend(); | ||
74 | void redrawScroll(QPainter* p); | ||
75 | int m_delay, m_scrolltype; | ||
32 | unsigned int m_overlap; | 76 | unsigned int m_overlap; |
33 | bool m_autoScroll, m_swapmouse; | 77 | bool m_autoScroll, m_swapmouse; |
78 | void drawBackground(); | ||
79 | #ifdef ROTATION_ENABLED | ||
80 | bool m_rotated; | ||
81 | void setrotated(bool); | ||
82 | #endif | ||
34 | void autoscroll(); | 83 | void autoscroll(); |
35 | QTimer* timer; | 84 | QTimer* timer; |
36 | int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart; | 85 | int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart, m_totalscroll; |
37 | void focusInEvent(QFocusEvent*); | 86 | void focusInEvent(QFocusEvent*); |
38 | void focusOutEvent(QFocusEvent*); | 87 | void focusOutEvent(QFocusEvent*); |
@@ -43,5 +92,6 @@ class QTReader : public QWidget | |||
43 | int m_charWidth; | 92 | int m_charWidth; |
44 | int m_charpc; | 93 | int m_charpc; |
45 | unsigned char m_border; | 94 | unsigned short m_absleft_border, m_absright_border; |
95 | unsigned short m_left_border, m_right_border; | ||
46 | FontControl m_fontControl; | 96 | FontControl m_fontControl; |
47 | void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); } | 97 | void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); } |
@@ -57,4 +107,21 @@ public: | |||
57 | // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); | 107 | // QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0); |
58 | ~QTReader(); | 108 | ~QTReader(); |
109 | QString about(); | ||
110 | CList<Bkmk>* Bkmklist() { return pBkmklist; } | ||
111 | void setBackground(const QColor& _c) | ||
112 | { | ||
113 | m_default_bg = _c; | ||
114 | reset_bg(); | ||
115 | } | ||
116 | void setForeground(const QColor& _c) | ||
117 | { | ||
118 | m_default_fg = _c; | ||
119 | int r,g,b; | ||
120 | m_default_fg.rgb(&r, &g, &b); | ||
121 | r = 255-r; | ||
122 | g = 255-g; | ||
123 | b = 255-b; | ||
124 | m_negative_fg.setRgb(r,g,b); | ||
125 | } | ||
59 | void zoomin(); | 126 | void zoomin(); |
60 | void zoomout(); | 127 | void zoomout(); |
@@ -137,21 +204,21 @@ public: | |||
137 | CEncoding* getencoding() | 204 | CEncoding* getencoding() |
138 | { | 205 | { |
139 | // odebug << "m_encd:" << m_encd << oendl; | 206 | // qDebug("m_encd:%d", m_encd); |
140 | switch (m_encd) | 207 | switch (m_encd) |
141 | { | 208 | { |
142 | case 4: | 209 | case 4: |
143 | // odebug << "palm" << oendl; | 210 | // qDebug("palm"); |
144 | return new CPalm; | 211 | return new CPalm; |
145 | case 1: | 212 | case 1: |
146 | // odebug << "utf8" << oendl; | 213 | // qDebug("utf8"); |
147 | return new CUtf8; | 214 | return new CUtf8; |
148 | case 2: | 215 | case 2: |
149 | // odebug << "ucs16be" << oendl; | 216 | // qDebug("ucs16be"); |
150 | return new CUcs16be; | 217 | return new CUcs16be; |
151 | case 3: | 218 | case 3: |
152 | // odebug << "ucs16le" << oendl; | 219 | // qDebug("ucs16le"); |
153 | return new CUcs16le; | 220 | return new CUcs16le; |
154 | case 0: | 221 | case 0: |
155 | // odebug << "ascii" << oendl; | 222 | // qDebug("ascii"); |
156 | return new CAscii; | 223 | return new CAscii; |
157 | default: | 224 | default: |
@@ -159,4 +226,5 @@ public: | |||
159 | } | 226 | } |
160 | } | 227 | } |
228 | HighlightFilter* m_highlightfilter; | ||
161 | CFilterChain* getfilter() | 229 | CFilterChain* getfilter() |
162 | { | 230 | { |
@@ -166,20 +234,46 @@ public: | |||
166 | if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); | 234 | if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); |
167 | if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); | 235 | if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); |
168 | if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml); | 236 | // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); |
237 | |||
238 | #ifdef __STATIC | ||
239 | if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); | ||
240 | if (bautofmt && (PreferredMarkup() == cCHM)) | ||
241 | { | ||
242 | filt->addfilter(new striphtml(m_lastfile)); | ||
243 | } | ||
244 | #else | ||
245 | if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile)); | ||
246 | if (bautofmt && (PreferredMarkup() == cCHM)) | ||
247 | { | ||
248 | ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile); | ||
249 | ((striphtml*)f->filter())->setchm(true); | ||
250 | filt->addfilter(f); | ||
251 | } | ||
252 | #endif | ||
253 | m_highlightfilter = new HighlightFilter(this); | ||
254 | filt->addfilter(m_highlightfilter); | ||
169 | 255 | ||
170 | if (bdehyphen) filt->addfilter(new dehyphen); | 256 | if (bdehyphen) filt->addfilter(new dehyphen); |
171 | if (bunindent) filt->addfilter(new unindent); | 257 | if (bunindent) filt->addfilter(new unindent); |
172 | if (brepara) filt->addfilter(new repara); | 258 | if (brepara) filt->addfilter(new repara(m_reparastring)); |
173 | if (bonespace) filt->addfilter(new OnePara); | 259 | if (bonespace) filt->addfilter(new OnePara); |
174 | if (bindenter) filt->addfilter(new indenter(bindenter)); | 260 | if (bindenter) filt->addfilter(new indenter(bindenter)); |
175 | if (bdblspce) filt->addfilter(new dblspce); | 261 | if (bdblspce) filt->addfilter(new dblspce); |
176 | #ifdef REPALM | ||
177 | if (brepalm) filt->addfilter(new repalm); | ||
178 | #endif | ||
179 | if (bremap) filt->addfilter(new remap); | ||
180 | if (bdepluck) filt->addfilter(new DePluck(pluckernextpart)); | 262 | if (bdepluck) filt->addfilter(new DePluck(pluckernextpart)); |
181 | if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart)); | 263 | if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart)); |
264 | if (brepalm) filt->addfilter(new repalm); | ||
265 | if (bkern) filt->addfilter(new kern); | ||
266 | if (bremap) filt->addfilter(new remap); | ||
182 | if (bmakebold) filt->addfilter(new embolden); | 267 | if (bmakebold) filt->addfilter(new embolden); |
183 | if (bfulljust) filt->addfilter(new FullJust); | 268 | if (bfulljust) filt->addfilter(new FullJust); |
269 | int r,g,b; | ||
270 | m_default_bg.rgb(&r, &g, &b); | ||
271 | if (r != 255 || g != 255 || b != 255) | ||
272 | filt->addfilter(new setbg(r,g,b)); | ||
273 | m_default_fg.rgb(&r, &g, &b); | ||
274 | if (r != 0 || g != 0 || b != 0) | ||
275 | filt->addfilter(new setfg(r,g,b)); | ||
276 | // if (bNegative) filt->addfilter(new makeNegative); | ||
277 | if (bInverse) filt->addfilter(new makeInverse); | ||
184 | return filt; | 278 | return filt; |
185 | } | 279 | } |
@@ -187,14 +281,23 @@ public: | |||
187 | 281 | ||
188 | private slots: | 282 | private slots: |
283 | void dopageup(); | ||
284 | void lineDown(); | ||
285 | void lineUp(); | ||
286 | void dopagedn(); | ||
189 | void goHome(); | 287 | void goHome(); |
190 | void goBack(); | 288 | void goBack(); |
191 | void goForward(); | 289 | void goForward(); |
192 | void doscroll(); | 290 | void doscroll(); |
193 | void drawIt( QPainter * ); | ||
194 | void paintEvent( QPaintEvent * ); | 291 | void paintEvent( QPaintEvent * ); |
195 | // void resizeEvent( QResizeEvent * p ) { update(); } | 292 | #ifdef DOUBLEBUFFER |
293 | void resizeEvent( QResizeEvent * p ); | ||
294 | #endif | ||
196 | void keyPressEvent(QKeyEvent*); | 295 | void keyPressEvent(QKeyEvent*); |
197 | void drawFonts(QPainter*); | ||
198 | private: | 296 | private: |
297 | // void drawIt( QPainter * ); | ||
298 | void redrawall(); | ||
299 | void drawFonts(); | ||
300 | void DrawStraight(QPainter* p, int w, int h); | ||
301 | QColor m_scrollcolor, m_scrollbarcolor; | ||
199 | void setTwoTouch(bool _b); | 302 | void setTwoTouch(bool _b); |
200 | void init(); | 303 | void init(); |
@@ -202,17 +305,16 @@ private slots: | |||
202 | void mouseReleaseEvent( QMouseEvent* ); | 305 | void mouseReleaseEvent( QMouseEvent* ); |
203 | // void mouseDoubleClickEvent( QMouseEvent* ); | 306 | // void mouseDoubleClickEvent( QMouseEvent* ); |
204 | QString m_string, m_fontname; | 307 | QString m_string, m_fontname, m_reparastring; |
205 | void setfont(); | 308 | void setfont(); |
206 | //myoutput stuff | 309 | //myoutput stuff |
207 | private: | 310 | private: |
311 | #ifdef SPECIALSCROLL | ||
312 | int m_scrolldy; | ||
313 | #endif | ||
208 | bool mouseUpOn; | 314 | bool mouseUpOn; |
209 | linkType getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt); | 315 | linkType getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*&); |
210 | bool m_twotouch, m_touchone; | 316 | bool m_twotouch, m_touchone; |
211 | size_t m_startpos, m_startoffset; | 317 | size_t m_startpos, m_startoffset; |
212 | void dopageup(unsigned int); | 318 | void dopageup(unsigned int); |
213 | void dopageup(); | ||
214 | void lineDown(); | ||
215 | void lineUp(); | ||
216 | void dopagedn(); | ||
217 | long real_delay(); | 319 | long real_delay(); |
218 | int m_textsize; | 320 | int m_textsize; |
@@ -222,14 +324,14 @@ private slots: | |||
222 | unsigned int numlines; | 324 | unsigned int numlines; |
223 | // bool m_showlast; | 325 | // bool m_showlast; |
224 | bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust; | 326 | bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust, /*bNegative,*/ bInverse; |
225 | #ifdef REPALM | 327 | bool bkern, brepalm; |
226 | bool brepalm; | ||
227 | #endif | ||
228 | bool m_bpagemode, m_bMonoSpaced, m_continuousDocument; | 328 | bool m_bpagemode, m_bMonoSpaced, m_continuousDocument; |
229 | unsigned char bindenter; | 329 | unsigned char bindenter; |
230 | QString m_lastfile; | 330 | QString m_lastfile; |
231 | size_t m_lastposn; | 331 | size_t m_lastposn; |
232 | public: | ||
233 | bool bDoUpdates; | 332 | bool bDoUpdates; |
333 | public: | ||
334 | void setDoUpdates(bool b) { bDoUpdates = b; } | ||
335 | void setStripCR(bool b) { bstripcr = b; } | ||
234 | void NavUp(); | 336 | void NavUp(); |
235 | void NavDown(); | 337 | void NavDown(); |
@@ -241,31 +343,73 @@ private slots: | |||
241 | CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } | 343 | CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); } |
242 | bool locate(unsigned long n); | 344 | bool locate(unsigned long n); |
243 | void jumpto(unsigned long n) { buffdoc.unsuspend(); buffdoc.locate(n); } | 345 | void jumpto(unsigned long n) { buffdoc.locate(n); } |
244 | unsigned long locate() { buffdoc.unsuspend(); return buffdoc.locate(); } | 346 | unsigned long locate() { return buffdoc.locate(); } |
245 | unsigned long explocate() { buffdoc.unsuspend(); return buffdoc.explocate(); } | 347 | unsigned long explocate() { return buffdoc.explocate(); } |
246 | unsigned long pagelocate() { return locnarray[0]; } | 348 | unsigned long pagelocate() { return locnarray[0]; } |
247 | unsigned long mylastpos; | 349 | unsigned long mylastpos; |
248 | void setfilter(CFilterChain *f) { buffdoc.unsuspend(); buffdoc.setfilter(f); locate(pagelocate()); } | 350 | void getNextLink(); |
351 | void setfilter(CFilterChain *f) { buffdoc.setfilter(f); if (bDoUpdates) locate(pagelocate()); } | ||
249 | void restore() { jumpto(mylastpos); } | 352 | void restore() { jumpto(mylastpos); } |
250 | void goUp(); | 353 | void goUp(); |
251 | void refresh() { locate(pagelocate()); } | 354 | void refresh(bool full = false); |
252 | void goDown(); | 355 | void goDown(); |
253 | // bool bold; | 356 | // bool bold; |
254 | int textsize() { return m_textsize; } | 357 | int textsize() { return m_textsize; } |
255 | void textsize(int ts) { m_textsize = ts; } | 358 | void textsize(int ts) { m_textsize = ts; } |
256 | bool fillbuffer(int ru = 0, int ht = 0, int newht = -1); | 359 | bool fillbuffer(int ru = 0, int ht = -1, int newht = -1); |
360 | void CalculateScrollParameters(); | ||
257 | unsigned int screenlines(); | 361 | unsigned int screenlines(); |
258 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.unsuspend(); buffdoc.sizes(fs,ts); } | 362 | void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); } |
259 | static const char *fonts[]; | 363 | static const char *fonts[]; |
260 | // unsigned int *fontsizes; | 364 | // unsigned int *fontsizes; |
261 | int m_ascent, m_descent, m_linespacing; | 365 | int m_ascent, m_descent, m_linespacing; |
366 | int m_topmargin, m_bottommargin; | ||
367 | int m_abstopmargin, m_absbottommargin; | ||
262 | QFontMetrics* m_fm; | 368 | QFontMetrics* m_fm; |
263 | QString firstword(); | 369 | QString firstword(); |
264 | 370 | bool hyphenate; | |
371 | void reset_bg() | ||
372 | { | ||
373 | int r,g,b; | ||
374 | m_default_bg.rgb(&r, &g, &b); | ||
375 | if (bInverse) | ||
376 | { | ||
377 | r = 255-r; | ||
378 | g = 255-g; | ||
379 | b = 255-b; | ||
380 | } | ||
381 | m_bg.setRgb(r,g,b); | ||
382 | /* | ||
383 | int h,s,v; | ||
384 | m_bg.hsv(&h, &s, &v); | ||
385 | if (bNegative) | ||
386 | { | ||
387 | v = 255-v; | ||
388 | m_bg.setHsv(h,s,v); | ||
389 | } | ||
390 | */ | ||
391 | setBackgroundColor( m_bg ); | ||
392 | } | ||
393 | void setInverse(bool b) | ||
394 | { | ||
395 | bInverse = b; | ||
396 | reset_bg(); | ||
397 | } | ||
398 | /* | ||
399 | void setNegative() | ||
400 | { | ||
401 | bNegative = !bNegative; | ||
402 | reset_bg(); | ||
403 | } | ||
404 | */ | ||
265 | signals: | 405 | signals: |
266 | void OnRedraw(); | 406 | void OnRedraw(); |
267 | void OnWordSelected(const QString&, size_t, const QString&); | 407 | void OnWordSelected(const QString&, size_t, size_t, const QString&); |
268 | void OnShowPicture(QImage&); | 408 | void OnShowPicture(QImage&); |
269 | void OnURLSelected(const QString&); | 409 | void OnURLSelected(const QString&, const size_t); |
410 | void NewFileRequest(const QString&); | ||
411 | void HandleKeyRequest(QKeyEvent*); | ||
412 | void SetScrollState(bool); | ||
413 | void RefreshBitmap(); | ||
270 | }; | 414 | }; |
271 | 415 | ||