summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1301
1 files changed, 904 insertions, 397 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 33884a0..0c56dd4 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -19,52 +19,56 @@ const int _SBARHEIGHT = 3;
19//#include "QTReaderApp.h" 19//#include "QTReaderApp.h"
20#include "CDrawBuffer.h" 20#include "CDrawBuffer.h"
21#ifdef USEQPE 21#ifdef USEQPE
22#include <qpe/qpeapplication.h> 22#include <qpe/qpeapplication.h>
23#endif 23#endif
24#include <math.h> 24#include <math.h>
25#include <ctype.h> 25#include <ctype.h>
26#include <stdio.h> //for sprintf 26#include <stdio.h> //for sprintf
27#ifdef USEQPE 27#ifdef USEQPE
28#include <qpe/config.h> 28#include <qpe/config.h>
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
32#endif 32#endif
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qdir.h> 34#include <qdir.h>
35#include "TableDialog.h"
36#include "outputcodec.h"
35 37
38/*
36#ifdef _UNICODE 39#ifdef _UNICODE
37const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 40const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
38#else 41#else
39const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 42const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
40#endif 43#endif
44*/
41//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 45//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
42 46
43//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 47//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
44//const int QTReader::fontsizes[] = {10,16,17,22,0}; 48//const int QTReader::fontsizes[] = {10,16,17,22,0};
45//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 49//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
46//const int QTReader::fontsizes[] = {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,0}; 50//const int QTReader::fontsizes[] = {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,0};
47 51
48tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; 52tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 };
49tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 53tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
50//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 54//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
51 55
52
53QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 56QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
54 QWidget(parent, name, f), 57 QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
58 m_outofdate(true),
55 m_default_fg(0,0,0), 59 m_default_fg(0,0,0),
56 m_default_bg(255,255,255), 60 m_default_bg(255,255,255),
57 m_bg(255,255,255), 61 m_bg(255,255,255),
58 m_delay(100), 62 m_delay(100),
59 m_scrolldy1(0), 63 m_scrolldy1(0),
60 m_scrolldy2(0), 64 m_scrolldy2(0),
61 m_totalscroll(0), 65 m_totalscroll(0),
62 m_autoScroll(false), 66 m_autoScroll(false),
63 //textarray(NULL), 67 //textarray(NULL),
64 //locnarray(NULL), 68 //locnarray(NULL),
65 numlines(0), 69 numlines(0),
66 m_fontname("unifont"), 70 m_fontname("unifont"),
67 m_fm(NULL), 71 m_fm(NULL),
68 mouseUpOn(true), 72 mouseUpOn(true),
69 m_twotouch(true), 73 m_twotouch(true),
70 m_touchone(true), 74 m_touchone(true),
@@ -76,118 +80,259 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
76 m_right_border(2), 80 m_right_border(2),
77 m_rotated(true), 81 m_rotated(true),
78 pBkmklist(NULL), 82 pBkmklist(NULL),
79 m_scrollpos(0), 83 m_scrollpos(0),
80 // bNegative(false), 84 // bNegative(false),
81 bInverse(false), 85 bInverse(false),
82 m_highlightfilter(NULL), 86 m_highlightfilter(NULL),
83 m_bgIsScaled(false), 87 m_bgIsScaled(false),
84 m_scrollstep(2), 88 m_scrollstep(2),
85 m_topmargin(5), 89 m_topmargin(5),
86 m_bottommargin(5), 90 m_bottommargin(5),
87 m_reparastring("{\\n[\\n ]}"), 91 m_reparastring("{\\n[\\n ]}"),
88 m_currentlinkstyle(NULL), 92 m_currentlinkstyle(NULL),
89 m_currentlinkoffset(-1), 93 m_currentlinkoffset(-1),
90 m_currentlink(-1) 94 m_currentlink(-1)
91{ 95{
96 m_output = NULL;
92 m_overlap = 1; 97 m_overlap = 1;
93 setKeyCompression ( true ); 98 setKeyCompression ( true );
94#ifdef DOUBLEBUFFER
95 dbuff = new QPixmap();
96 dbp = new QPainter();
97 // if (painter->isActive()) painter->end();
98 // painter->begin(frame);
99#endif
100// init();
101 99
100 dbuff = NULL;
101 dbp = NULL;
102} 102}
103 103
104/* 104/*
105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
106 QWidget(parent, name, f), 106 QWidget(parent, name, f),
107 m_textfont(0), 107 m_textfont(0),
108 m_textsize(1), 108 m_textsize(1),
109 textarray(NULL), 109 textarray(NULL),
110 numlines(0), 110 numlines(0),
111 bstripcr(true), 111 bstripcr(true),
112 bunindent(false), 112 bunindent(false),
113 brepara(false), 113 brepara(false),
114 bdblspce(false), 114 bdblspce(false),
115 btight(false), 115 btight(false),
116 bindenter(0), 116 bindenter(0),
117 m_fm(NULL) 117 m_fm(NULL)
118{ 118{
119 init(); 119 init();
120// // qDebug("Load_file(1)"); 120// // qDeb2ug("Load_file(1)");
121 load_file((const tchar*)filename); 121 load_file((const tchar*)filename);
122} 122}
123*/ 123*/
124 124
125/* 125/*
126void QTReader::mouseMoveEvent(QMouseEvent* _e) 126void QTReader::mouseMoveEvent(QMouseEvent* _e)
127{ 127{
128 128
129 mouseUpOn = !(_e->pos().x() == -1); 129 mouseUpOn = !(_e->pos().x() == -1);
130 130
131 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); 131 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
132} 132}
133*/ 133*/
134long QTReader::real_delay() 134long QTReader::real_delay()
135{ 135{
136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
137} 137}
138 138
139void QTReader::mousePressEvent( QMouseEvent* _e ) 139void QTReader::mousePressEvent( QMouseEvent* _e )
140{ 140{
141 buffdoc.unsuspend(); 141 m_drageligible = false;
142 qDebug("Mouse pressed at (%u, %u)", _e->x(), _e->y());
142 int x, y, ht, wh; 143 int x, y, ht, wh;
143 if (m_rotated) 144 if (m_rotated)
144 { 145 {
145 x = _e->y(); 146 x = _e->y();
146 y = width()-_e->x(); 147 y = width()-_e->x();
147 ht = width(); 148 ht = width();
148 wh = height(); 149 wh = height();
149 } 150 }
150 else 151 else
151 { 152 {
152 x = _e->x(); 153 x = _e->x();
153 y = _e->y(); 154 y = _e->y();
154 ht = height(); 155 ht = height();
155 wh = width(); 156 wh = width();
156 } 157 }
157 if (_e->button() == RightButton) 158 if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin)
158 { 159 {
159 //qDebug("MousePress"); 160 if (_e->button() == RightButton)
160 mouseUpOn = false;
161 if (m_swapmouse)
162 { 161 {
163 int lineno = 0; 162 //qDebug("MousePress");
164 /* 163 mouseUpOn = false;
164 if (m_swapmouse)
165 {
166 int lineno = 0;
167 /*
165 int hgt = textarray[0]->lineSpacing(); 168 int hgt = textarray[0]->lineSpacing();
166 while ((hgt < y) && (lineno < numlines)) 169 while ((hgt < y) && (lineno < numlines))
167 { 170 {
168 hgt += textarray[++lineno]->lineSpacing(); 171 hgt += textarray[++lineno]->lineSpacing();
169 } 172 }
170 */ 173 */
171 size_t startpos, startoffset, tgt, tgtoffset, pictgt; 174 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
172 QImage* img; 175 QImage* img;
173 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); 176 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
174 processmousewordevent(startpos, startoffset, _e, lineno); 177 processmousewordevent(startpos, startoffset, _e, lineno);
178 }
179 else
180 {
181 processmousepositionevent(_e);
182 }
183 }
184 }
185 else
186 {
187 int ln = -1;
188 int mp;
189 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
190 switch (m_scrollpos)
191 {
192 case 1:
193 {
194 if (m_rotated)
195 {
196 if (_e->x() < m_bottommargin)
197 {
198 ln = height();
199 mp = _e->y();
200 }
201 }
202 else
203 {
204 if (_e->y() > height()-m_bottommargin)
205 {
206 ln = width();
207 mp = _e->x();
208 }
209 }
210 }
211 break;
212 case 2:
213 {
214 if (m_rotated)
215 {
216 if (_e->y() > height() - m_right_border)
217 {
218 ln = width();
219 mp = width()-_e->x();
220 }
221 }
222 else
223 {
224 if (_e->x() > width() - m_right_border)
225 {
226 ln = height();
227 mp = _e->y();
228 }
229 }
230 }
231 break;
232 case 3:
233 {
234 if (m_rotated)
235 {
236 if (_e->y() < m_left_border)
237 {
238 ln = width();
239 mp = width()-_e->x();
240 }
241 }
242 else
243 {
244 if (_e->x() < m_left_border)
245 {
246 ln = height();
247 mp = _e->y();
248 }
249 }
250 }
251 break;
252 case 0:
253 default:
254 ln = -1;
255 break;
256 }
257 if (ln >= 0)
258 {
259 int dp = (sectionsize*mp+ln/2)/ln + buffdoc.startSection();
260 int winsize = locnarray[numlines]-locnarray[0];
261 int slidersize = 10*(sectionsize+ln/2)/ln;
262 if (slidersize > winsize)
263 {
264 int mid = (locnarray[0] + locnarray[numlines])/2;
265 slidersize /= 2;
266 if (dp < mid-slidersize)
267 {
268 dopageup();
269 }
270 else if (dp > mid+slidersize)
271 {
272 dopagedn();
273 }
274 //if (mid-slidersize < dp && dp < mid+slidersize)
275 else
276 {
277 m_drageligible = true;
278 }
279 }
280 else
281 {
282 if (dp < locnarray[0])
283 {
284 dopageup();
285 }
286 else if (dp > locnarray[numlines])
287 {
288 dopagedn();
289 }
290 //if (locnarray[0] < dp && dp < locnarray[numlines])
291 else
292 {
293 m_drageligible = true;
294 }
295 }
296 qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false");
297 }
298 else
299 {
300 if (m_scrollpos == 1)
301 {
302 if (x < m_left_border)
303 {
304 lineUp();
305 }
306 if (y > ht - m_bottommargin)
307 {
308 lineDown();
309 }
310 }
311 else if (m_scrollpos != 0)
312 {
313 if (y < m_topmargin)
314 {
315 lineUp();
316 }
317 if (y > ht - m_bottommargin)
318 {
319 lineDown();
320 }
321 }
175 } 322 }
176 else
177 processmousepositionevent(_e);
178 } 323 }
179} 324}
180 325
181void QTReader::processmousepositionevent( QMouseEvent* _e ) 326void QTReader::processmousepositionevent( QMouseEvent* _e )
182{ 327{
183 int x, y, ht, wh; 328 int x, y, ht, wh;
184 if (m_rotated) 329 if (m_rotated)
185 { 330 {
186 x = _e->y(); 331 x = _e->y();
187 y = width()-_e->x(); 332 y = width()-_e->x();
188 ht = width(); 333 ht = width();
189 wh = height(); 334 wh = height();
190 } 335 }
191 else 336 else
192 { 337 {
193 x = _e->x(); 338 x = _e->x();
@@ -282,33 +427,33 @@ void QTReader::goForward()
282 linkType lt = buffdoc.forward(nxt, target); 427 linkType lt = buffdoc.forward(nxt, target);
283 if ((lt & eFile) != 0) 428 if ((lt & eFile) != 0)
284 { 429 {
285 if (nxt != m_lastfile) 430 if (nxt != m_lastfile)
286 { 431 {
287 emit NewFileRequest(nxt); 432 emit NewFileRequest(nxt);
288 } 433 }
289 locate(target); 434 locate(target);
290 } 435 }
291 else if ((lt & eLink) != 0) 436 else if ((lt & eLink) != 0)
292 { 437 {
293 locate(target); 438 locate(target);
294 } 439 }
295 } 440 }
296} 441}
297 442
298linkType QTReader::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*& img) 443linkType QTReader::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*& img, size_t& tabtgt)
299{ 444{
300 int ht; 445 int ht;
301 if (m_scrolldy == m_topmargin) 446 if (m_scrolldy == m_topmargin)
302 { 447 {
303 lineno = 0; 448 lineno = 0;
304 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; 449 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
305 } 450 }
306 else 451 else
307 { 452 {
308 if (y >= m_scrolldy) 453 if (y >= m_scrolldy)
309 { 454 {
310 lineno = 0; 455 lineno = 0;
311 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin; 456 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin;
312 } 457 }
313 else 458 else
314 { 459 {
@@ -327,55 +472,86 @@ linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t
327 } 472 }
328 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines; 473 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines;
329 start = locnarray[lineno]; 474 start = locnarray[lineno];
330 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 475 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
331 if (m_bMonoSpaced) 476 if (m_bMonoSpaced)
332 { 477 {
333 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth; 478 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth;
334 } 479 }
335 else 480 else
336 { 481 {
337 int i; 482 int i;
338 CDrawBuffer* t = textarray[lineno]; 483 CDrawBuffer* t = textarray[lineno];
339 x = x - t->offset(width(), m_left_border, m_right_border, availht); 484 x = x - t->offset(width(), m_left_border, m_right_border, availht);
340 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); 485 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--);
341 offset = i; 486 offset = i;
342 } 487 }
343 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img); 488 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt);
344} 489}
345 490
346void QTReader::suspend() 491void QTReader::suspend()
347{ 492{
348 buffdoc.suspend(); 493 buffdoc.suspend();
349 /*#ifdef OPIE 494 /*#ifdef OPIE
350 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); 495 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
351#else 496#else
352 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); 497 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
353#endif 498#endif
354 */ 499 */
355} 500}
356 501
502void QTReader::setDoubleBuffer(bool _b)
503{
504 m_doubleBuffered = _b;
505 if (_b || m_rotated)
506 {
507 if (dbuff == NULL)
508 {
509 dbuff = new QPixmap();
510 dbp = new QPainter();
511 }
512 if (m_rotated)
513 {
514 dbuff->resize(height(), width());
515 }
516 else
517 {
518 dbuff->resize(width(), height());
519 }
520 m_outofdate = true;
521 }
522 else
523 {
524 if (dbuff != NULL)
525 {
526 delete dbuff;
527 delete dbp;
528 }
529 dbuff = NULL;
530 dbp = NULL;
531 }
532}
533
357void QTReader::setTwoTouch(bool _b) 534void QTReader::setTwoTouch(bool _b)
358{ 535{
359 setBackgroundColor( m_bg ); 536 setBackgroundColor( m_bg );
360 m_twotouch = m_touchone = _b; 537 m_twotouch = m_touchone = _b;
361} 538}
362 539
363void QTReader::setContinuous(bool _b) 540void QTReader::setContinuous(bool _b)
364{ 541{
365 buffdoc.unsuspend();
366 buffdoc.setContinuous(m_continuousDocument = _b); 542 buffdoc.setContinuous(m_continuousDocument = _b);
367} 543}
368 544
369void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) 545void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
370{ 546{
371 unsigned long wrdstart, wrdend; 547 unsigned long wrdstart, wrdend;
372 QString wrd; 548 QString wrd;
373 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 549 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
374 if (m_twotouch) 550 if (m_twotouch)
375 { 551 {
376 if (m_touchone) 552 if (m_touchone)
377 { 553 {
378 m_touchone = false; 554 m_touchone = false;
379 m_startpos = startpos; 555 m_startpos = startpos;
380 m_startoffset = startoffset; 556 m_startoffset = startoffset;
381 setBackgroundColor( lightGray ); 557 setBackgroundColor( lightGray );
@@ -442,258 +618,401 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
442 int i = first+1; 618 int i = first+1;
443 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 619 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
444 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 620 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
445 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt) 621 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt)
446 { 622 {
447 wrd = toQString(t->data()+first, i - first); 623 wrd = toQString(t->data()+first, i - first);
448 // qDebug("Got %s", (const char *)wrd); 624 // qDebug("Got %s", (const char *)wrd);
449 break; 625 break;
450 } 626 }
451 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 627 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
452 if ((*t)[i] == 0) break; 628 if ((*t)[i] == 0) break;
453 first = i; 629 first = i;
454 } 630 }
455 } 631 }
456 if (!wrd.isEmpty()) 632 if (!wrd.isEmpty())
457 { 633 {
458 qDebug("Selecteed:%s", (const char*)wrd); 634 qDebug("Selected:%s", (const char*)wrd);
459 if (m_twotouch) 635 if (m_twotouch)
460 { 636 {
461 emit OnWordSelected(wrd, wrdstart, wrdend, wrd); 637 emit OnWordSelected(wrd, wrdstart, wrdend, wrd);
462 } 638 }
463 else 639 else
464 { 640 {
465 QString line = toQString(textarray[lineno]->data()); 641 QString line = toQString(textarray[lineno]->data());
466 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line); 642 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line);
467 } 643 }
468 } 644 }
469} 645}
470 646
471void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 647#ifdef USETIMER
648void QTReader::actionDrag()
472{ 649{
473 buffdoc.unsuspend(); 650 if (m_drageligible)
474 int x, y, ht, wh;
475 if (m_rotated)
476 { 651 {
477 x = _e->y(); 652 int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize);
478 y = width()-_e->x(); 653 if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages)
479 ht = width(); 654 {
480 wh = height(); 655 int tgt = m_dragtarget - fivepages/2;
656 //qDebug("Jumping to %u (%u)", tgt, fivepages);
657 if (tgt < buffdoc.startSection())
658 {
659 tgt = buffdoc.startSection();
660 }
661 locate(tgt);
662 drawFonts();
663 }
664 else if (locnarray[0] > m_dragtarget+fivepages)
665 {
666 int tgt = m_dragtarget + fivepages/2;
667 //qDebug("Jumping to %u (%u)", tgt, fivepages);
668 if (tgt > buffdoc.endSection())
669 {
670 dopageup();
671 }
672 else
673 {
674 locate(tgt);
675 drawFonts();
676 }
677 }
678 else if (locnarray[numlines] <= m_dragtarget)
679 {
680 dopagedn();
681 }
682 else if (locnarray[0] > m_dragtarget)
683 {
684 dopageup();
685 }
481 } 686 }
482 else 687 else
483 { 688 {
484 x = _e->x(); 689 m_dragtimer->stop();
485 y = _e->y();
486 ht = height();
487 wh = width();
488 } 690 }
489 if (_e->button() == LeftButton) 691}
692#endif
693
694void QTReader::mouseMoveEvent( QMouseEvent* _e )
695{
696 if (m_drageligible)
490 { 697 {
491 if (mouseUpOn) 698 int ht;
699 int mp;
700 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
701 //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y());
702 switch (m_scrollpos)
492 { 703 {
493 // qDebug("MouseRelease"); 704 case 1:
494 switch(m_scrollpos) 705 {
706 if (m_rotated)
707 {
708 ht = height();
709 mp = _e->y();
710 }
711 else
712 {
713 ht = width();
714 mp = _e->x();
715 }
716 }
717 break;
718 case 2:
719 case 3:
720 {
721 if (m_rotated)
722 {
723 ht = width();
724 mp = width()-_e->x();
725 }
726 else
727 {
728 ht = height();
729 mp = _e->y();
730 }
731 }
732 break;
733 case 0:
734 default:
735 ht = -1;
736 break;
737 }
738 if (ht >= 0)
739 {
740#ifdef USETIMER
741 m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
742 if (!m_dragtimer->isActive())
495 { 743 {
496 case 1: // Bottom 744 m_dragtimer->start(0, false);
497 if (y > ht - 5)
498 {
499 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
500 return;
501 }
502 break;
503 case 2: // right
504 if (x > wh - m_right_border)
505 {
506 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
507 return;
508 }
509 break;
510 case 3: // left
511 if (x < m_left_border)
512 {
513 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
514 return;
515 }
516 break;
517 case 0:
518 default:
519 break;
520 } 745 }
521 if (textarray[0] != NULL) 746#else
747 int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
748 locate(dp);
749#endif
750 }
751 }
752}
753
754void QTReader::mouseReleaseEvent( QMouseEvent* _e )
755{
756 qDebug("Mouse released at (%u, %u)", _e->x(), _e->y());
757 if (m_drageligible)
758 {
759 m_drageligible = false;
760 }
761 else
762 {
763 int x, y, ht, wh;
764 if (m_rotated)
765 {
766 x = _e->y();
767 y = width()-_e->x();
768 ht = width();
769 wh = height();
770 }
771 else
772 {
773 x = _e->x();
774 y = _e->y();
775 ht = height();
776 wh = width();
777 }
778 if (_e->button() == LeftButton)
779 {
780 if (mouseUpOn)
522 { 781 {
523 QString line; 782 // qDebug("MouseRelease");
524 // int lineno = _e->y()/m_linespacing; 783 /*
525 int lineno = 0; 784 switch(m_scrollpos)
526 /*
527 int ht = textarray[0]->lineSpacing();
528 while ((ht < y) && (lineno < numlines))
529 { 785 {
530 ht += textarray[++lineno]->lineSpacing(); 786 case 1: // Bottom
787 if (y > ht - 5)
788 {
789 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
790 return;
531 } 791 }
532 */ 792 break;
533 size_t startpos, startoffset, tgt, tgtoffset, pictgt; 793 case 2: // right
534 QImage* img; 794 if (x > wh - m_right_border)
535 if (m_currentlinkstyle != NULL) 795 {
536 { 796 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
537 textarray[m_currentlink]->invertLink(m_currentlinkoffset); 797 return;
538 m_currentlinkstyle = NULL; 798 }
539 m_currentlink = -1; 799 break;
540 m_currentlinkoffset = -1; 800 case 3: // left
541 } 801 if (x < m_left_border)
542 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); 802 {
543 if ((glt & eLink) != 0) 803 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
544 { 804 return;
545 if ((glt & ePicture) != 0) 805 }
546 { 806 break;
547 qDebug("Big Picture:%x", pictgt); 807 case 0:
548 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 808 default:
549 { 809 break;
550 QImage* pm = buffdoc.getPicture(pictgt); 810 }
551 if (pm != NULL) 811 */
552 { 812 if (textarray[0] != NULL)
553 emit OnShowPicture(*pm); 813 {
554 delete pm; 814 QString line;
555 return; 815 // int lineno = _e->y()/m_linespacing;
556 } 816 int lineno = 0;
557 } 817 /*
558 } 818 int ht = textarray[0]->lineSpacing();
559 else if (img != NULL) 819 while ((ht < y) && (lineno < numlines))
560 { 820 {
561 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 821 ht += textarray[++lineno]->lineSpacing();
562 { 822 }
563 emit OnShowPicture(*img); 823 */
564 return; 824 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
565 } 825 QImage* img;
566 } 826 if (m_currentlinkstyle != NULL)
567 size_t saveposn = pagelocate(); 827 {
568 QString href, nm; 828 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
569 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); 829 m_currentlinkstyle = NULL;
570 qDebug("URL(1):%s", (const char*)href); 830 m_currentlink = -1;
571 if ((lt & eFile) != 0) 831 m_currentlinkoffset = -1;
572 { 832 }
573 buffdoc.saveposn(m_lastfile, saveposn); 833 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
834 if (bNoInlineTables && ((glt & eTable) != 0))
835 {
836 size_t currentpos = locate();
837 QString tabtext = buffdoc.getTableAsHtml(tabtgt);
838 qDebug("TABLE:%u:%u:%s", currentpos, tabtgt, (const char*)tabtext);
839 QFont f(m_fontname, m_fontControl.currentsize());
574#ifdef USEQPE 840#ifdef USEQPE
841 CTableDialog td(f, tabtext, true, this);
842#else
843 CTableDialog td(f, tabtext, false, this);
844#endif
845 td.exec();
846 jumpto(currentpos);
847 }
848 if ((glt & eLink) != 0)
849 {
850 if ((glt & ePicture) != 0)
575 { 851 {
576 QCopEnvelope e("QPE/System", "busy()"); 852 qDebug("Big Picture:%x", pictgt);
853 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
854 {
855 QImage* pm = buffdoc.getPicture(pictgt);
856 if (pm != NULL)
857 {
858 emit OnShowPicture(*pm);
859 delete pm;
860 return;
861 }
862 }
577 } 863 }
578#endif 864 else if (img != NULL)
579 ResetScroll();
580 if (!href.isEmpty())
581 {
582 if (!buffdoc.getFile(href))
583 {
584 emit NewFileRequest(href);
585 }
586 else
587 {
588 ResetScroll();
589 fillbuffer();
590 update();
591 }
592 }
593 if (!nm.isEmpty())
594 {
595 qDebug("QTReader:Finding %s", (const char*)nm);
596 if (buffdoc.findanchor(nm))
597 {
598 fillbuffer();
599 update();
600 }
601 }
602 //fillbuffer();
603 //update();
604#ifdef USEQPE
605 { 865 {
606 QCopEnvelope e("QPE/System", "notBusy()"); 866 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
867 {
868 emit OnShowPicture(*img);
869 return;
870 }
607 } 871 }
608#endif 872 size_t saveposn = pagelocate();
609 } 873 QString href, nm;
610 else if ((lt & eLink) != 0) 874 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
611 { 875 qDebug("URL(1):%s", (const char*)href);
612 buffdoc.saveposn(m_lastfile, saveposn); 876 if ((lt & eFile) != 0)
613 ResetScroll(); 877 {
614 fillbuffer(); 878 buffdoc.saveposn(m_lastfile, saveposn);
615 update(); 879#ifdef USEQPE
616 }
617 else
618 {
619 if ((lt & ePicture) != 0)
620 { 880 {
621 QImage* pm = buffdoc.getPicture(tgt); 881 QCopEnvelope e("QPE/System", "busy()");
622 if (pm != NULL)
623 {
624 emit OnShowPicture(*pm);
625 delete pm;
626 }
627 } 882 }
628 else 883#endif
884 ResetScroll();
885 if (!href.isEmpty())
886 {
887 if (!buffdoc.getFile(href, nm))
888 {
889 emit NewFileRequest(href);
890 }
891 else
892 {
893 qDebug("BEFORE:%u", pagelocate());
894 buffdoc.resetPos();
895 ResetScroll();
896 fillbuffer();
897 qDebug("AFTER:%u", pagelocate());
898 m_outofdate = true;
899 update();
900 }
901 }
902 if (!nm.isEmpty())
903 {
904 qDebug("QTReader:Finding %s", (const char*)nm);
905 if (buffdoc.findanchor(nm))
906 {
907 buffdoc.resetPos();
908 fillbuffer();
909 m_outofdate = true;
910 update();
911 }
912 }
913 //fillbuffer();
914 //update();
915#ifdef USEQPE
629 { 916 {
630 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 917 QCopEnvelope e("QPE/System", "notBusy()");
631 if (!href.isEmpty())
632 {
633 emit OnURLSelected(href, tgt);
634 }
635 } 918 }
636 locate(pagelocate()); 919#endif
637 } 920 }
638 return; 921 else if ((lt & eLink) != 0)
639 } 922 {
640 else if ((glt & ePicture) != 0) 923 buffdoc.saveposn(m_lastfile, saveposn);
641 { 924 ResetScroll();
642 qDebug("Big Picture:%x", pictgt); 925 fillbuffer();
643 QImage* pm = buffdoc.getPicture(pictgt); 926 m_outofdate = true;
644 if (pm != NULL) 927 update();
645 { 928 }
646 emit OnShowPicture(*pm); 929 else
647 delete pm; 930 {
648 } 931 if ((lt & ePicture) != 0)
649 else 932 {
650 { 933 QImage* pm = buffdoc.getPicture(tgt);
651 locate(pagelocate()); 934 if (pm != NULL)
652 } 935 {
653 return; 936 emit OnShowPicture(*pm);
654 } 937 delete pm;
655 else if (img != NULL) 938 }
656 { 939 }
657 emit OnShowPicture(*img); 940 else
658 return; 941 {
659 } 942 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
660 if (m_swapmouse) 943 if (!href.isEmpty())
944 {
945 emit OnURLSelected(href, tgt);
946 }
947 }
948 }
949 return;
950 }
951 else if ((glt & ePicture) != 0)
952 {
953 qDebug("Big Picture:%x", pictgt);
954 QImage* pm = buffdoc.getPicture(pictgt);
955 if (pm != NULL)
956 {
957 emit OnShowPicture(*pm);
958 delete pm;
959 }
960 else
961 {
962 update();
963 }
964 return;
965 }
966 else if (img != NULL)
967 {
968 emit OnShowPicture(*img);
969 return;
970 }
971 if (m_swapmouse)
661 processmousepositionevent(_e); 972 processmousepositionevent(_e);
662 else 973 else
663 processmousewordevent(startpos, startoffset, _e, lineno); 974 processmousewordevent(startpos, startoffset, _e, lineno);
975 }
976 }
977 else
978 {
979 mouseUpOn = true;
664 } 980 }
665 }
666 else
667 {
668 mouseUpOn = true;
669 } 981 }
670 } 982 }
671} 983}
672 984
673void QTReader::focusInEvent(QFocusEvent* e) 985void QTReader::focusInEvent(QFocusEvent* e)
674{ 986{
675 if (m_autoScroll) timer->start(real_delay(), false); 987 if (m_autoScroll && (m_scrolltype != 4)) timer->start(real_delay(), false);
676 update(); 988 update();
677} 989}
678 990
679void QTReader::focusOutEvent(QFocusEvent* e) 991void QTReader::focusOutEvent(QFocusEvent* e)
680{ 992{
681 if (m_autoScroll) 993 if (m_autoScroll)
682 { 994 {
683 timer->stop(); 995 if (m_scrolltype != 4)
996 {
997 timer->stop();
998 }
999 else
1000 {
1001 m_autoScroll = false;
1002 }
684 //m_scrolldy1 = m_scrolldy2 = 0; 1003 //m_scrolldy1 = m_scrolldy2 = 0;
685 } 1004 }
686} 1005}
687 1006
688#include <qapplication.h> 1007#include <qapplication.h>
689#include <qdrawutil.h> 1008#include <qdrawutil.h>
690#ifndef _WINDOWS 1009#ifndef _WINDOWS
691#include <unistd.h> 1010#include <unistd.h>
692#endif 1011#endif
693 1012
694void QTReader::goDown() 1013void QTReader::goDown()
695{ 1014{
696 if (m_bpagemode) 1015 if (m_bpagemode)
697 { 1016 {
698 dopagedn(); 1017 dopagedn();
699 } 1018 }
@@ -704,126 +1023,121 @@ void QTReader::goDown()
704} 1023}
705 1024
706void QTReader::goUp() 1025void QTReader::goUp()
707{ 1026{
708 if (m_bpagemode) 1027 if (m_bpagemode)
709 { 1028 {
710 dopageup(); 1029 dopageup();
711 } 1030 }
712 else 1031 else
713 { 1032 {
714 lineUp(); 1033 lineUp();
715 } 1034 }
716} 1035}
717 1036
718void QTReader::NavUp() 1037void QTReader::NavUp()
719{ 1038{
720 buffdoc.unsuspend();
721 if (buffdoc.hasnavigation()) 1039 if (buffdoc.hasnavigation())
722 { 1040 {
723/* 1041/*
724 size_t target = pagelocate(); 1042 size_t target = pagelocate();
725 if (buffdoc.back(target)) 1043 if (buffdoc.back(target))
726 { 1044 {
727 locate(target); 1045 locate(target);
728 } 1046 }
729*/ 1047*/
730 locate(buffdoc.startSection()); 1048 locate(buffdoc.startSection());
731 } 1049 }
732 else 1050 else
733 { 1051 {
734 goUp(); 1052 goUp();
735 } 1053 }
736} 1054}
737 1055
738void QTReader::NavDown() 1056void QTReader::NavDown()
739{ 1057{
740 buffdoc.unsuspend();
741 if (buffdoc.hasnavigation()) 1058 if (buffdoc.hasnavigation())
742 { 1059 {
743/* 1060/*
744 size_t target = pagelocate(); 1061 size_t target = pagelocate();
745 if (buffdoc.forward(target)) 1062 if (buffdoc.forward(target))
746 { 1063 {
747 locate(target); 1064 locate(target);
748 } 1065 }
749*/ 1066*/
750 dopageup(buffdoc.endSection()); 1067 dopageup(buffdoc.endSection());
751 } 1068 }
752 else 1069 else
753 { 1070 {
754 goDown(); 1071 goDown();
755 } 1072 }
756} 1073}
757 1074
758void QTReader::zoomin() 1075void QTReader::zoomin()
759{ 1076{
760 if (m_fontControl.increasesize()) 1077 if (m_fontControl.increasesize())
761 { 1078 {
762 bool sc = m_autoScroll; 1079 bool sc = m_autoScroll;
763 setautoscroll(false); 1080 setautoscroll(false);
764 setfont(); 1081 setfont();
765 locate(pagelocate()); 1082 refresh();
766 repaint();
767 setautoscroll(sc); 1083 setautoscroll(sc);
768 } 1084 }
769} 1085}
770 1086
771void QTReader::zoomout() 1087void QTReader::zoomout()
772{ 1088{
773 if (m_fontControl.decreasesize()) 1089 if (m_fontControl.decreasesize())
774 { 1090 {
775 bool sc = m_autoScroll; 1091 bool sc = m_autoScroll;
776 setautoscroll(false); 1092 setautoscroll(false);
777 setfont(); 1093 setfont();
778 locate(pagelocate()); 1094 refresh();
779 repaint();
780 setautoscroll(sc); 1095 setautoscroll(sc);
781 } 1096 }
782} 1097}
783 1098
784void QTReader::reduceScroll() 1099void QTReader::reduceScroll()
785{ 1100{
786 if (m_delay < 59049) 1101 if (m_delay < 59049)
787 { 1102 {
788 m_delay = (3*m_delay)/2; 1103 m_delay = (3*m_delay)/2;
789 timer->changeInterval(real_delay()); 1104 timer->changeInterval(real_delay());
790 } 1105 }
791 else 1106 else
792 { 1107 {
793 m_delay = 59049; 1108 m_delay = 59049;
794 } 1109 }
795} 1110}
796 1111
797void QTReader::increaseScroll() 1112void QTReader::increaseScroll()
798{ 1113{
799 if (m_delay > 454) 1114 if (m_delay > 454)
800 { 1115 {
801 m_delay = (2*m_delay)/3; 1116 m_delay = (2*m_delay)/3;
802 timer->changeInterval(real_delay()); 1117 timer->changeInterval(real_delay());
803 } 1118 }
804 else 1119 else
805 { 1120 {
806 m_delay = 454; 1121 m_delay = 454;
807 } 1122 }
808} 1123}
809 1124
810void QTReader::keyPressEvent(QKeyEvent* e) 1125void QTReader::keyPressEvent(QKeyEvent* e)
811{ 1126{
812 buffdoc.unsuspend(); 1127
813
814 //((QTReaderApp*)parent()->parent())->handlekey(e); 1128 //((QTReaderApp*)parent()->parent())->handlekey(e);
815 emit HandleKeyRequest(e); 1129 emit HandleKeyRequest(e);
816// e->ignore(); 1130// e->ignore();
817 return; 1131 return;
818#ifdef _SCROLLPIPE 1132#ifdef _SCROLLPIPE
819 if (m_isPaused) 1133 if (m_isPaused)
820 { 1134 {
821 m_isPaused = false; 1135 m_isPaused = false;
822 if (e->key() != Key_Space) 1136 if (e->key() != Key_Space)
823 { 1137 {
824 m_autoScroll = false; 1138 m_autoScroll = false;
825 if (m_pipeout != NULL) 1139 if (m_pipeout != NULL)
826 { 1140 {
827 pclose(m_pipeout); 1141 pclose(m_pipeout);
828 m_pipeout = NULL; 1142 m_pipeout = NULL;
829 } 1143 }
@@ -893,74 +1207,77 @@ void QTReader::CalculateScrollParameters()
893 ypos += textarray[i]->lineSpacing(); 1207 ypos += textarray[i]->lineSpacing();
894 } 1208 }
895 ypos -= ( 1209 ypos -= (
896 textarray[0]->lineExtraSpacing() 1210 textarray[0]->lineExtraSpacing()
897 + 1211 +
898 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0) 1212 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0)
899 )/2 + 1213 )/2 +
900 m_scrolldy1 - 2; 1214 m_scrolldy1 - 2;
901 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin; 1215 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin;
902 } 1216 }
903 break; 1217 break;
904 } 1218 }
905} 1219}
906 1220
907void QTReader::setautoscroll(bool _sc) 1221void QTReader::setautoscroll(bool _sc)
908{ 1222{
1223 m_outofdate = true;
909 if (_sc == m_autoScroll) return; 1224 if (_sc == m_autoScroll) return;
910 if (m_autoScroll) 1225 if (m_autoScroll)
911 { 1226 {
912 m_autoScroll = false; 1227 m_autoScroll = false;
913#ifdef USEQPE 1228#ifdef USEQPE
914 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1229 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
915#endif 1230#endif
916#ifdef _SCROLLPIPE 1231#ifdef _SCROLLPIPE
917 if (m_pipeout != NULL) 1232 if (m_pipeout != NULL)
918 { 1233 {
919 pclose(m_pipeout); 1234 pclose(m_pipeout);
920 m_pipeout = NULL; 1235 m_pipeout = NULL;
921 } 1236 }
922#endif 1237#endif
923 //m_scrolldy1 = 0; 1238 //m_scrolldy1 = 0;
924 //refresh(); 1239 //refresh();
925 } 1240 }
926 else 1241 else
927 { 1242 {
928 CDrawBuffer* reusebuffer = textarray[numlines]; 1243 CDrawBuffer* reusebuffer = textarray[numlines];
929 if (reusebuffer == NULL || reusebuffer->eof()) return; 1244 if (reusebuffer == NULL || reusebuffer->eof()) return;
1245#ifndef __STATIC
1246 if ((m_scrolltype == 4) && !checkoutput()) return;
1247#endif
930 m_autoScroll = true; 1248 m_autoScroll = true;
931 CalculateScrollParameters(); 1249 CalculateScrollParameters();
932 1250
933#ifdef _SCROLLPIPE 1251#ifdef _SCROLLPIPE
934 if (!m_pipetarget.isEmpty()) 1252 if (!m_pipetarget.isEmpty())
935 { 1253 {
936 // qDebug("Opening pipe to %s", (const char*)m_pipetarget); 1254 // qDebug("Opening pipe to %s", (const char*)m_pipetarget);
937 m_pipeout = popen((const char*)m_pipetarget, "w"); 1255 m_pipeout = popen((const char*)m_pipetarget, "w");
938 m_isPaused = false; 1256 m_isPaused = false;
939 } 1257 }
940#endif 1258#endif
941 autoscroll(); 1259 autoscroll();
942#ifdef USEQPE 1260#ifdef USEQPE
943 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 1261 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
944#endif 1262#endif
945 } 1263 }
946} 1264}
947 1265
948bool QTReader::getline(CDrawBuffer *buff) 1266bool QTReader::getline(CDrawBuffer *buff)
949{ 1267{
950 buffdoc.unsuspend();
951 bool bRet; 1268 bool bRet;
952 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 1269 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
953 if (m_bMonoSpaced) 1270 if (m_bMonoSpaced)
954 { 1271 {
955 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht); 1272 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
956 } 1273 }
957 else 1274 else
958 { 1275 {
959 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht); 1276 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht);
960 } 1277 }
961 buff->resize(availht); 1278 buff->resize(availht);
962 return bRet; 1279 return bRet;
963} 1280}
964 1281
965void QTReader::doscroll() 1282void QTReader::doscroll()
966{ 1283{
@@ -1052,67 +1369,48 @@ void QTReader::doinplacescroll()
1052 else 1369 else
1053 { 1370 {
1054 if (m_bgpm.isNull()) 1371 if (m_bgpm.isNull())
1055 { 1372 {
1056 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg); 1373 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg);
1057 } 1374 }
1058 else 1375 else
1059 { 1376 {
1060 int h_tmp = textarray[numlines-1]->lineSpacing(); 1377 int h_tmp = textarray[numlines-1]->lineSpacing();
1061 bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp); 1378 bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp);
1062 } 1379 }
1063 textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); 1380 textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1064 } 1381 }
1065 mylastpos = locate(); 1382 mylastpos = locate();
1066 if (!ch) 1383 if (!ch)
1067 { 1384 {
1068 /*
1069 if (m_rotated)
1070 {
1071 blitRot2(0,0,height(),width()-m_scrolldy,NULL);
1072 // blitRot2(0,0,0,height(),width()-m_scrolldy,NULL);
1073 }
1074 else
1075 {
1076 if (m_bgpm.isNull())
1077 {
1078 p.fillRect(0,m_scrolldy,width(),height()-m_scrolldy,m_bg);
1079 }
1080 else
1081 {
1082 bitBlt(this, 0, m_scrolldy, dbuff, 0, m_scrolldy, width(), height()-m_scrolldy);
1083 }
1084 }
1085 */
1086 m_scrolldy = m_topmargin; 1385 m_scrolldy = m_topmargin;
1087 m_autoScroll = false; 1386 m_autoScroll = false;
1088#ifdef _SCROLLPIPE 1387#ifdef _SCROLLPIPE
1089 for (int i = 0; i < numlines; i++) 1388 for (int i = 0; i < numlines; i++)
1090 { 1389 {
1091 if (m_pipeout != NULL) 1390 if (m_pipeout != NULL)
1092 { 1391 {
1093 QString outstr = toQString(textarray[i]->data()); 1392 QString outstr = toQString(textarray[i]->data());
1094 if (!outstr.isEmpty()) 1393 if (!outstr.isEmpty())
1095 { 1394 {
1096 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1395 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1097 fflush(m_pipeout); 1396 fflush(m_pipeout);
1098 } 1397 }
1099 } 1398 }
1100 } 1399 }
1101#endif 1400#endif
1102 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
1103 emit SetScrollState(m_autoScroll); 1401 emit SetScrollState(m_autoScroll);
1104#ifdef USEQPE 1402#ifdef USEQPE
1105 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1403 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1106#endif 1404#endif
1107 } 1405 }
1108 if (m_scrolldy > ht-textarray[numlines]->lineSpacing()) 1406 if (m_scrolldy > ht-textarray[numlines]->lineSpacing())
1109 { 1407 {
1110 if (m_rotated) 1408 if (m_rotated)
1111 { 1409 {
1112 if (m_bgpm.isNull()) 1410 if (m_bgpm.isNull())
1113 { 1411 {
1114 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg); 1412 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg);
1115 } 1413 }
1116 else 1414 else
1117 { 1415 {
1118 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL); 1416 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL);
@@ -1481,35 +1779,46 @@ void QTReader::redrawScroll(QPainter* p)
1481 { 1779 {
1482 int fp = height()-offset; 1780 int fp = height()-offset;
1483 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp); 1781 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp);
1484 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp); 1782 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp);
1485 } 1783 }
1486 } 1784 }
1487 break; 1785 break;
1488 case 0: 1786 case 0:
1489 default: 1787 default:
1490 break; 1788 break;
1491 } 1789 }
1492 if (m_scrollpos != 0) DrawScroll(p, width(), height()); 1790 if (m_scrollpos != 0) DrawScroll(p, width(), height());
1493} 1791}
1494 1792
1495void QTReader::autoscroll() 1793void QTReader::autoscroll()
1496{ 1794{
1497 drawBackground(); 1795 if (m_scrolltype == 4)
1498 dbp->end(); 1796 {
1499 timer->start(real_delay(), false); 1797 readAloud();
1798 }
1799 else
1800 {
1801 if (dbuff != NULL)
1802 {
1803 dbp->begin(dbuff);
1804 drawBackground(dbp);
1805 dbp->end();
1806 }
1807 timer->start(real_delay(), false);
1808 }
1500} 1809}
1501 1810
1502void QTReader::setfont() 1811void QTReader::setfont()
1503{ 1812{
1504// m_fontControl.Change 1813// m_fontControl.Change
1505 m_charWidth = (m_charpc*m_fontControl.currentsize())/100; 1814 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
1506 if (m_charWidth <= 0) m_charWidth = 1; 1815 if (m_charWidth <= 0) m_charWidth = 1;
1507 m_ascent = m_fontControl.ascent(); 1816 m_ascent = m_fontControl.ascent();
1508 m_descent = m_fontControl.descent(); 1817 m_descent = m_fontControl.descent();
1509 m_linespacing = m_fontControl.lineSpacing(); 1818 m_linespacing = m_fontControl.lineSpacing();
1510} 1819}
1511 1820
1512void QTReader::DrawStraight(QPainter* p, int w, int h) 1821void QTReader::DrawStraight(QPainter* p, int w, int h)
1513{ 1822{
1514 if (m_scrolldy == m_topmargin) 1823 if (m_scrolldy == m_topmargin)
1515 { 1824 {
@@ -1544,87 +1853,125 @@ void QTReader::DrawStraight(QPainter* p, int w, int h)
1544 } 1853 }
1545 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); 1854 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1546 } 1855 }
1547 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor); 1856 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor);
1548 } 1857 }
1549 bool wasrotated = m_rotated; 1858 bool wasrotated = m_rotated;
1550 m_rotated = false; 1859 m_rotated = false;
1551 DrawScroll(p, w, h); 1860 DrawScroll(p, w, h);
1552 m_rotated = wasrotated; 1861 m_rotated = wasrotated;
1553 1862
1554} 1863}
1555 1864
1556void QTReader::redrawall() 1865void QTReader::redrawall()
1557{ 1866{
1558 if (m_rotated) 1867 if (m_rotated)
1559 { 1868 {
1560#ifdef DOUBLEBUFFER 1869 if (dbuff != NULL)
1561 drawBackground(); 1870 {
1562 DrawStraight(dbp, height(), width()); 1871 dbp->begin(dbuff);
1563 dbp->end(); 1872 drawBackground(dbp);
1564 1873 DrawStraight(dbp, height(), width());
1565 QWMatrix m; 1874 dbp->end();
1566 m.rotate(90); 1875
1567 QPixmap rp = dbuff->xForm(m); 1876 QWMatrix m;
1568 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1877 m.rotate(90);
1569#else 1878 QPixmap rp = dbuff->xForm(m);
1570 QPixmap dbuff(height(), width()); 1879 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1571 QPainter dbp(&dbuff); 1880 }
1572 // dbp.setBackgroundMode(OpaqueMode); 1881 else
1573 dbp.fillRect(dbuff.rect(), m_bg); 1882 {
1574 1883 qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)");
1575 DrawStraight(&dbp, height(), width()); 1884 QPixmap dbuff(height(), width());
1576 1885 QPainter dbp(&dbuff);
1577 QWMatrix m; 1886
1578 m.rotate(90); 1887 drawBackground(&dbp);
1579 QPixmap rp = dbuff.xForm(m); 1888 DrawStraight(&dbp, height(), width());
1580 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1889
1581#endif 1890 QWMatrix m;
1891 m.rotate(90);
1892 QPixmap rp = dbuff.xForm(m);
1893 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1894 }
1582 } 1895 }
1583 else 1896 else
1584 { 1897 {
1585#ifdef DOUBLEBUFFER 1898 if (dbuff != NULL)
1586 drawBackground(); 1899 {
1587 DrawStraight(dbp, width(), height()); 1900 dbp->begin(dbuff);
1588 dbp->end(); 1901 drawBackground(dbp);
1589 bitBlt(this, 0,0,dbuff,0,0,-1,-1); 1902 DrawStraight(dbp, width(), height());
1590#else 1903 dbp->end();
1591 DrawStraight(p, width(), height()); 1904 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1592#endif 1905 }
1906 else
1907 {
1908 QPainter p(this);
1909 drawBackground(&p);
1910 DrawStraight(&p, width(), height());
1911 }
1593 } 1912 }
1594} 1913}
1595 1914
1596void QTReader::drawFonts() 1915void QTReader::drawFonts()
1597{ 1916{
1598 if (bDoUpdates) 1917 if (bDoUpdates)
1599 { 1918 {
1600 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1919 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1601 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 1920 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1602 //qDebug("How refreshing..."); 1921 //qDebug("How refreshing...");
1603 if (buffdoc.empty()) return; 1922 if (buffdoc.empty())
1923 {
1924 if (dbuff != NULL)
1925 {
1926 dbp->begin(dbuff);
1927 drawBackground(dbp);
1928 dbp->end();
1929 }
1930 else
1931 {
1932 QPainter p(this);
1933 drawBackground(&p);
1934 }
1935 return;
1936 }
1604 setfont(); 1937 setfont();
1605 //if (!m_autoScroll) m_scrolldy1 = 0; 1938 //if (!m_autoScroll) m_scrolldy1 = 0;
1606#ifdef ROTATION_ENABLED 1939 if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height()))
1940 {
1941 qDebug("Oh no! A resize event was missed...");
1942 if (m_rotated)
1943 {
1944 dbuff->resize(height(), width());
1945 }
1946 else
1947 {
1948 dbuff->resize(width(), height());
1949 }
1950 m_lastwidth = 0;
1951 }
1607 if (m_lastwidth != ((m_rotated) ? height() : width())) 1952 if (m_lastwidth != ((m_rotated) ? height() : width()))
1608 { 1953 {
1609 m_scrolldy = m_topmargin; 1954 m_scrolldy = m_topmargin;
1610 // qDebug("Not Optimised %d", m_lastwidth); 1955 // qDebug("Not Optimised %d", m_lastwidth);
1611 m_lastwidth = ((m_rotated) ? height() : width()); 1956 m_lastwidth = ((m_rotated) ? height() : width());
1612 m_lastheight = ((m_rotated) ? width() : height()); 1957 m_lastheight = ((m_rotated) ? width() : height());
1613 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 1958 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1614 locate(pagelocate()); 1959 buffdoc.locate(pagelocate());
1960 fillbuffer();
1961 redrawall();
1615 // qDebug("Not Optimised %d", m_lastwidth); 1962 // qDebug("Not Optimised %d", m_lastwidth);
1616 } 1963 }
1617 else 1964 else
1618 { 1965 {
1619 int newht = ((m_rotated) ? width() : height()); 1966 int newht = ((m_rotated) ? width() : height());
1620 if (m_lastheight > newht) 1967 if (m_lastheight > newht)
1621 { 1968 {
1622 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); 1969 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1623 m_scrolldy = m_topmargin; 1970 m_scrolldy = m_topmargin;
1624 int ypos = m_scrolldy1+m_topmargin; 1971 int ypos = m_scrolldy1+m_topmargin;
1625 for (int i = 0; i < numlines; i++) 1972 for (int i = 0; i < numlines; i++)
1626 { 1973 {
1627 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin) 1974 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1628 { 1975 {
1629 numlines = i; 1976 numlines = i;
1630 jumpto(mylastpos = locnarray[i+1]); 1977 jumpto(mylastpos = locnarray[i+1]);
@@ -1638,89 +1985,32 @@ void QTReader::drawFonts()
1638 { 1985 {
1639 m_scrolldy = m_topmargin; 1986 m_scrolldy = m_topmargin;
1640 // qDebug("Optimised > %d", numlines); 1987 // qDebug("Optimised > %d", numlines);
1641 int ypos = m_scrolldy1+m_topmargin; 1988 int ypos = m_scrolldy1+m_topmargin;
1642 for (int i = 0; i <= numlines; i++) 1989 for (int i = 0; i <= numlines; i++)
1643 { 1990 {
1644 ypos += textarray[i]->lineSpacing(); 1991 ypos += textarray[i]->lineSpacing();
1645 } 1992 }
1646 fillbuffer(numlines+1, ypos, newht); 1993 fillbuffer(numlines+1, ypos, newht);
1647 // qDebug("Optimised > %d", numlines); 1994 // qDebug("Optimised > %d", numlines);
1648 } 1995 }
1649 if (numlines > 0) 1996 if (numlines > 0)
1650 { 1997 {
1651 redrawall(); 1998 redrawall();
1652 } 1999 }
1653 } 2000 }
1654#else
1655 if (m_lastwidth != width())
1656 {
1657 // qDebug("Not Optimised %d", m_lastwidth);
1658 m_lastwidth = width();
1659 m_lastheight = height();
1660 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1661 locate(pagelocate());
1662 // qDebug("Not Optimised %d", m_lastwidth);
1663 }
1664 else
1665 {
1666 int newht = height();
1667 if (m_lastheight > newht)
1668 {
1669 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1670 int ypos = m_topmargin;
1671 for (int i = 0; i < numlines; i++)
1672 {
1673 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1674 {
1675 numlines = i;
1676 jumpto(mylastpos = locnarray[i+1]);
1677 break;
1678 }
1679 }
1680 // qDebug("Optimised < %d", numlines);
1681 m_lastheight = newht;
1682 }
1683 else if (m_lastheight < newht)
1684 {
1685 // qDebug("Optimised > %d", numlines);
1686 int ypos = m_topmargin;
1687 for (int i = 0; i <= numlines; i++)
1688 {
1689 ypos += textarray[i]->lineSpacing();
1690 }
1691 fillbuffer(numlines+1, ypos, newht);
1692 // qDebug("Optimised > %d", numlines);
1693 }
1694 if (numlines > 0)
1695 {
1696 int ypos = textarray[0]->ascent()+m_topmargin;
1697 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1698 // int last = (m_showlast) ? numlines : numlines-1;
1699 // for (int i = 1; i <= last; i++)
1700 for (int i = 1; i < numlines; i++)
1701 {
1702 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
1703 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1704 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1705 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1706 }
1707// mylastpos = locate();
1708 }
1709 }
1710#endif
1711 emitRedraw(); 2001 emitRedraw();
1712 } 2002 }
1713/* 2003/*
1714 else 2004 else
1715 { 2005 {
1716 qDebug("Not so refreshing..."); 2006 qDebug("Not so refreshing...");
1717 } 2007 }
1718*/ 2008*/
1719} 2009}
1720 2010
1721void QTReader::DrawScroll( QPainter *p, int _w, int _h ) 2011void QTReader::DrawScroll( QPainter *p, int _w, int _h )
1722{ 2012{
1723 if (!buffdoc.empty()) 2013 if (!buffdoc.empty())
1724 { 2014 {
1725 QBrush checkered = QBrush( Dense4Pattern ); 2015 QBrush checkered = QBrush( Dense4Pattern );
1726 checkered.setColor(m_scrollbarcolor); 2016 checkered.setColor(m_scrollbarcolor);
@@ -1915,52 +2205,60 @@ QString QTReader::firstword()
1915 else 2205 else
1916 return "Current position"; 2206 return "Current position";
1917 } 2207 }
1918} 2208}
1919 2209
1920// 2210//
1921// Construct the QTReader with buttons. 2211// Construct the QTReader with buttons.
1922// 2212//
1923 2213
1924bool QTReader::ChangeFont(int tgt) 2214bool QTReader::ChangeFont(int tgt)
1925{ 2215{
1926 return m_fontControl.ChangeFont(m_fontname, tgt); 2216 return m_fontControl.ChangeFont(m_fontname, tgt);
1927} 2217}
1928 2218
1929void QTReader::init() 2219void QTReader::init()
1930{ 2220{
1931 buffdoc.unsuspend();
1932 setBackgroundColor( m_bg ); 2221 setBackgroundColor( m_bg );
1933 buffdoc.setfilter(getfilter()); 2222 buffdoc.setfilter(getfilter());
1934 ChangeFont(m_textsize); 2223 ChangeFont(m_textsize);
1935 setFocusPolicy(QWidget::StrongFocus); 2224 setFocusPolicy(QWidget::StrongFocus);
1936 timer = new QTimer(this); 2225 timer = new QTimer(this);
1937 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 2226 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
2227#ifdef USETIMER
2228 m_dragtimer = new QTimer(this);
2229 connect(m_dragtimer, SIGNAL(timeout()), this, SLOT(actionDrag()));
2230#endif
1938 // QMessageBox::information(this, "init", m_lastfile, 1); 2231 // QMessageBox::information(this, "init", m_lastfile, 1);
1939 setfont(); 2232 setfont();
1940} 2233}
1941 2234
1942// 2235//
1943// Clean up 2236// Clean up
1944// 2237//
1945QTReader::~QTReader() 2238QTReader::~QTReader()
1946{ 2239{
1947#ifdef DOUBLEBUFFER 2240 if (m_output != NULL)
1948 delete dbuff; 2241 {
1949 delete dbp; 2242 delete m_output;
1950#endif 2243 }
2244 if (dbuff != NULL)
2245 {
2246 delete dbuff;
2247 delete dbp;
2248 }
1951#ifdef USEQPE 2249#ifdef USEQPE
1952 if (m_autoScroll) 2250 if (m_autoScroll)
1953 { 2251 {
1954 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 2252 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1955 } 2253 }
1956#endif 2254#endif
1957#ifdef _SCROLLPIPE 2255#ifdef _SCROLLPIPE
1958 if (m_pipeout != NULL) 2256 if (m_pipeout != NULL)
1959 { 2257 {
1960 fclose(m_pipeout); 2258 fclose(m_pipeout);
1961 } 2259 }
1962#endif 2260#endif
1963} 2261}
1964 2262
1965// 2263//
1966// Called when the print button is clicked. 2264// Called when the print button is clicked.
@@ -1969,152 +2267,207 @@ QTReader::~QTReader()
1969void QTReader::printIt() 2267void QTReader::printIt()
1970{ 2268{
1971#ifndef QT_NO_PRINTER 2269#ifndef QT_NO_PRINTER
1972 if ( printer->setup( this ) ) { 2270 if ( printer->setup( this ) ) {
1973 QPainter paint; 2271 QPainter paint;
1974 if ( !paint.begin( printer ) ) 2272 if ( !paint.begin( printer ) )
1975 return; 2273 return;
1976 drawIt( &paint ); 2274 drawIt( &paint );
1977 } 2275 }
1978#endif 2276#endif
1979} 2277}
1980*/ 2278*/
1981// 2279//
1982// Called when the widget needs to be updated. 2280// Called when the widget needs to be updated.
1983// 2281//
1984 2282
1985void QTReader::paintEvent( QPaintEvent * ) 2283void QTReader::paintEvent( QPaintEvent * p )
1986{ 2284{
1987 drawFonts(); 2285 if ((dbuff != NULL) && !m_outofdate)
2286 {
2287 if (m_rotated)
2288 {
2289 if ((p->rect().width() != width()) || (p->rect().height() != height()))
2290 {
2291 qDebug("Partial paint");
2292 QRect r;
2293 r.setTop(width()-p->rect().right()-1);
2294 r.setLeft(p->rect().top());
2295 r.setHeight(p->rect().width());
2296 r.setWidth(p->rect().height());
2297 QPixmap p1(r.width(), r.height());
2298 bitBlt(&p1, QPoint(0, 0), dbuff, r);
2299 QWMatrix m;
2300 m.rotate(90);
2301 QPixmap p2 = p1.xForm(m);
2302 bitBlt(this, p->rect().left(), p->rect().top(), &p2, 0, 0, -1, -1);
2303 }
2304 else
2305 {
2306 qDebug("Full paint");
2307 QWMatrix m;
2308 m.rotate(90);
2309 QPixmap rp = dbuff->xForm(m);
2310 bitBlt(this, 0,0,&rp,0,0,-1,-1);
2311 }
2312 }
2313 else
2314 {
2315 //bitBlt(this, 0,0,dbuff,0,0,-1,-1);
2316 bitBlt(this,p->rect().topLeft(),dbuff,p->rect());
2317 }
2318 }
2319 else
2320 {
2321 drawFonts();
2322 }
2323 m_outofdate = false;
1988} 2324}
1989 2325
1990// 2326//
1991// Called when the widget has been resized. 2327// Called when the widget has been resized.
1992// Moves the button group to the upper right corner 2328// Moves the button group to the upper right corner
1993// of the widget. 2329// of the widget.
1994 2330
1995/* 2331/*
1996void QTReader::resizeEvent( QResizeEvent * ) 2332void QTReader::resizeEvent( QResizeEvent * )
1997{ 2333{
1998// // qDebug("resize:(%u,%u)", width(), height()); 2334// // qDebug("resize:(%u,%u)", width(), height());
1999 // bgroup->move( width()-bgroup->width(), 0 ); 2335 // bgroup->move( width()-bgroup->width(), 0 );
2000} 2336}
2001*/ 2337*/
2002 2338
2003// 2339//
2004// Create and display our widget. 2340// Create and display our widget.
2005// 2341//
2006/* 2342/*
2007int main( int argc, tchar **argv ) 2343int main( int argc, tchar **argv )
2008{ 2344{
2009 QApplication app( argc, argv ); 2345 QApplication app( argc, argv );
2010 QTReader draw; 2346 QTReader draw;
2011 app.setMainWidget( &draw ); 2347 app.setMainWidget( &draw );
2012 draw.setCaption("Qt Example - Drawdemo"); 2348 draw.setCaption("Qt Example - Drawdemo");
2013 draw.show(); 2349 draw.show();
2014 return app.exec(); 2350 return app.exec();
2015} 2351}
2016*/ 2352*/
2017 2353
2018 2354
2355bool QTReader::locate(unsigned long n)
2356{
2357 m_outofdate = true;
2358 m_lastwidth = 0;
2359 locnarray[0] = n;
2360 ResetScroll();
2361 update();
2362 return true;
2363}
2364/*
2019bool QTReader::locate(unsigned long n) { 2365bool QTReader::locate(unsigned long n) {
2020 //printf("Locate\n"); 2366 //printf("Locate\n");
2021 buffdoc.unsuspend();
2022 buffdoc.locate(n); 2367 buffdoc.locate(n);
2023// // qDebug("&buffdoc.located"); 2368// // qDebug("&buffdoc.located");
2024 ResetScroll(); 2369 ResetScroll();
2025 fillbuffer(); 2370 fillbuffer();
2371 m_outofdate = true;
2026// // qDebug("&Buffer filled"); 2372// // qDebug("&Buffer filled");
2027 update(); 2373 update();
2028// // qDebug("&Located"); 2374// // qDebug("&Located");
2029 emitRedraw(); 2375 emitRedraw();
2030 return true; 2376 return true;
2031} 2377}
2032 2378*/
2033unsigned int QTReader::screenlines() 2379unsigned int QTReader::screenlines()
2034{ 2380{
2035 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 2381 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
2036 // return (height()-m_descent)/(m_linespacing); 2382 // return (height()-m_descent)/(m_linespacing);
2037 return (height()-2)/(m_linespacing); 2383 return (height()-2)/(m_linespacing);
2038}; 2384};
2039 2385
2040bool QTReader::fillbuffer(int reuse, int ht, int newht) 2386bool QTReader::fillbuffer(int reuse, int ht, int newht)
2041{ 2387{
2042 buffdoc.unsuspend();
2043 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 2388 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
2044 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 2389 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
2045 if (ht < 0) ht = m_topmargin; 2390 if (ht < 0) ht = m_topmargin;
2046 if (buffdoc.empty()) return false; 2391 if (buffdoc.empty()) return false;
2047 if (newht < 0) 2392 if (newht < 0)
2048 m_lastheight = (m_rotated) ? width() : height(); 2393 m_lastheight = (m_rotated) ? width() : height();
2049 else 2394 else
2050 m_lastheight = newht; 2395 m_lastheight = newht;
2051 int ch; 2396 int ch;
2052 bool ret = false; 2397 bool ret = false;
2053 unsigned int oldpagepos = locnarray[reuse]; 2398 unsigned int oldpagepos = locnarray[reuse];
2054 int lastypos = ht, ypos = ht; 2399 int lastypos = ht, ypos = ht;
2055 numlines = reuse; 2400 numlines = reuse;
2056 while (ypos < m_lastheight - hmargin || numlines < 2) 2401 while (ypos < m_lastheight - hmargin || numlines < 2)
2057 { 2402 {
2058 lastypos = ypos; 2403 lastypos = ypos;
2059 if (textarray[numlines] == NULL) 2404 if (textarray[numlines] == NULL)
2060 { 2405 {
2061 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2406 textarray[numlines] = new CDrawBuffer(&m_fontControl);
2062 } 2407 }
2063 locnarray[numlines] = locate(); 2408 locnarray[numlines] = locate();
2064 int ch = getline(textarray[numlines]); 2409 int ch = getline(textarray[numlines]);
2065 ypos += textarray[numlines]->lineSpacing(); 2410 ypos += textarray[numlines]->lineSpacing();
2411 /*
2412 QString tmp = toQString(textarray[numlines]->data());
2413 printf("[%u, %u, %u](%s):%s\n", lastypos, m_lastheight-hmargin, ypos,
2414 ((textarray[numlines]->showPartial()) ? "TRUE" : "FALSE"),
2415 (const char*)tmp);
2416 */
2066 numlines++; 2417 numlines++;
2067 if (!ch) 2418 if (!ch)
2068 { 2419 {
2069 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) 2420 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
2070 { 2421 {
2071 qDebug("FALSE"); 2422 qDebug("FALSE");
2423 if (oldpagepos < buffdoc.endSection())
2072 locate(oldpagepos); 2424 locate(oldpagepos);
2073 return false; 2425 else
2426 dopageup(buffdoc.endSection());
2427 return false;
2074 } 2428 }
2075 else 2429 else
2076 { 2430 {
2077 qDebug("TRUE"); 2431 qDebug("TRUE");
2078 --numlines; 2432 --numlines;
2079 mylastpos = locate(); 2433 mylastpos = locate();
2080 return true; 2434 return true;
2081 } 2435 }
2082 } 2436 }
2083 if (numlines > 1 && textarray[numlines-2]->isBop()) 2437 if (numlines > 1 && textarray[numlines-2]->isBop())
2084 { 2438 {
2085 --numlines; 2439 --numlines;
2086 mylastpos = locate(); 2440 mylastpos = locate();
2087 return true; 2441 return true;
2088 } 2442 }
2089 } 2443 }
2090 2444
2091 --numlines; 2445 --numlines;
2092 mylastpos = locate(); 2446 mylastpos = locate();
2093 m_scrollpart = m_lastheight - lastypos - hmargin; 2447 m_scrollpart = m_lastheight - lastypos - hmargin;
2094 if (m_autoScroll) 2448 if (m_autoScroll)
2095 { 2449 {
2096 CalculateScrollParameters(); 2450 CalculateScrollParameters();
2097 } 2451 }
2098 return true; 2452 return true;
2099} 2453}
2100 2454
2101void QTReader::dopagedn() 2455void QTReader::dopagedn()
2102{ 2456{
2103// qDebug("HEIGHT(2):%d", m_lastheight); 2457// qDebug("HEIGHT(2):%d", m_lastheight);
2104 buffdoc.unsuspend();
2105 ResetScroll(); 2458 ResetScroll();
2106 int skip = 0, ypos = m_topmargin; 2459 int skip = 0, ypos = m_topmargin;
2107 if (locate() != mylastpos) 2460 if (locate() != mylastpos)
2108 { 2461 {
2109 jumpto(mylastpos); 2462 jumpto(mylastpos);
2110 } 2463 }
2111 CDrawBuffer* reusebuffer = textarray[numlines]; 2464 CDrawBuffer* reusebuffer = textarray[numlines];
2112 if (reusebuffer != NULL) 2465 if (reusebuffer != NULL)
2113 { 2466 {
2114 if (reusebuffer->eof()) return; 2467 if (reusebuffer->eof()) return;
2115 for (int i = 0; i <= m_overlap; i++) 2468 for (int i = 0; i <= m_overlap; i++)
2116 { 2469 {
2117 int offset = numlines - m_overlap + i; 2470 int offset = numlines - m_overlap + i;
2118 reusebuffer = textarray[offset]; 2471 reusebuffer = textarray[offset];
2119 size_t reuselocn = locnarray[offset]; 2472 size_t reuselocn = locnarray[offset];
2120 textarray[offset] = textarray[i]; 2473 textarray[offset] = textarray[i];
@@ -2137,78 +2490,80 @@ void QTReader::dopagedn()
2137 drawFonts(); 2490 drawFonts();
2138 } 2491 }
2139} 2492}
2140 2493
2141void QTReader::dopageup() 2494void QTReader::dopageup()
2142{ 2495{
2143 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); 2496 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
2144} 2497}
2145 2498
2146bool QTReader::synch(size_t start, size_t end) 2499bool QTReader::synch(size_t start, size_t end)
2147{ 2500{
2148 jumpto(start); 2501 jumpto(start);
2149 while (start++ < end) 2502 while (start++ < end)
2150 { 2503 {
2151 tchar ch = getch(); 2504 tchar ch = getch();
2152 if (ch == 10) return true; 2505 if (ch == 10) return true;
2153 if (ch == UEOF) return false; 2506 if ((ch == UEOF) || (ch == 6))
2154 if (ch == 6) return false; 2507 {
2508 return false;
2509 }
2155 } 2510 }
2156 return false; 2511 return false;
2157} 2512}
2158 2513
2159void QTReader::dopageup(unsigned int target) 2514void QTReader::dopageup(unsigned int target)
2160{ 2515{
2161 buffdoc.unsuspend();
2162 ResetScroll(); 2516 ResetScroll();
2163 CBufferFace<CDrawBuffer*> buff; 2517 CBufferFace<CDrawBuffer*> buff;
2164 CBufferFace<size_t> loc; 2518 CBufferFace<size_t> loc;
2165
2166 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; 2519 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0;
2520 qDebug("dopageup:: locate():%u pagelocate():%u guess:%u", locate(), pagelocate(), guess);
2167 bool ch = true; 2521 bool ch = true;
2168 int nbfl, ypos = m_topmargin; 2522 int nbfl, ypos = m_topmargin;
2169 if (guess < 128) guess = 128; 2523 if (guess < 128) guess = 128;
2170 while (1) 2524 while (1)
2171 { 2525 {
2172 // qDebug("Guess:%u", guess); 2526 // qDebug("Guess:%u", guess);
2173 2527
2174 ch = true; 2528 ch = true;
2175 if (target < guess) 2529 if (target < guess)
2176 { 2530 {
2177 delta = 0; // 0 is a flag to say don't guess any more 2531 delta = 0; // 0 is a flag to say don't guess any more
2178 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); 2532 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
2179 } 2533 }
2180 else if (!m_continuousDocument && (target - guess < buffdoc.startSection())) 2534 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
2181 { 2535 {
2182 delta = 0; // 0 is a flag to say don't guess any more 2536 delta = 0; // 0 is a flag to say don't guess any more
2537 qDebug("Jumping to startsection:%d", buffdoc.startSection());
2183 jumpto(buffdoc.startSection()); 2538 jumpto(buffdoc.startSection());
2184 } 2539 }
2185 else 2540 else
2186 { 2541 {
2187 delta = guess; 2542 delta = guess;
2188 if (!synch(target-delta, target-lastdelta)) 2543 if (!synch(target-delta, target-lastdelta))
2189 { 2544 {
2190 lastdelta = delta; 2545 lastdelta = delta;
2191 if (guess < 4000) 2546 if (guess < 4000)
2192 { 2547 {
2193 guess <<= 1; 2548 guess <<= 1;
2194 continue; 2549 continue;
2195 } 2550 }
2196 else 2551 else
2197 { 2552 {
2198 jumpto(target-delta); 2553 jumpto(target-delta);
2199 } 2554 }
2200 } 2555 }
2201 } 2556 }
2202 2557
2203 nbfl = 0; 2558 nbfl = 0;
2204 ypos = m_topmargin; 2559 ypos = m_topmargin;
2205 2560
2206 while (locate() < target) 2561 while (locate() < target)
2207 { 2562 {
2208 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 2563 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
2209 loc[nbfl] = locate(); 2564 loc[nbfl] = locate();
2210 ch = getline(buff[nbfl]); 2565 ch = getline(buff[nbfl]);
2211 ypos += buff[nbfl]->lineSpacing(); 2566 ypos += buff[nbfl]->lineSpacing();
2212 nbfl++; 2567 nbfl++;
2213 if (!ch) break; 2568 if (!ch) break;
2214 } 2569 }
@@ -2280,60 +2635,61 @@ void QTReader::dopageup(unsigned int target)
2280 ypos += textarray[numlines]->lineSpacing(); 2635 ypos += textarray[numlines]->lineSpacing();
2281 } 2636 }
2282 2637
2283 mylastpos = locate(); 2638 mylastpos = locate();
2284 CalculateScrollParameters(); 2639 CalculateScrollParameters();
2285 drawFonts(); 2640 drawFonts();
2286 // repaint(); 2641 // repaint();
2287} 2642}
2288 2643
2289bool QTReader::load_file(const char *newfile, unsigned int _lcn) 2644bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2290{ 2645{
2291// QMessageBox::information(this, "Name", name, 1); 2646// QMessageBox::information(this, "Name", name, 1);
2292// QMessageBox::information(this, "load_file", newfile, 1); 2647// QMessageBox::information(this, "load_file", newfile, 1);
2293 int prog = 0; 2648 int prog = 0;
2294 bool bRC = false; 2649 bool bRC = false;
2295 unsigned int lcn = _lcn; 2650 unsigned int lcn = _lcn;
2651 bDoUpdates = false;
2296 ResetScroll(); 2652 ResetScroll();
2297 if (m_lastfile == newfile) 2653 if (m_lastfile == newfile && lcn == 0)
2298 { 2654 {
2299 lcn = m_lastposn; 2655 lcn = m_lastposn;
2300 } 2656 }
2301 // QMessageBox::information(0, "Opening...", newfile); 2657 // QMessageBox::information(0, "Opening...", newfile);
2302 if (m_rotated) 2658 if (m_rotated)
2303 { 2659 {
2304 m_lastwidth = height(); 2660 m_lastwidth = height();
2305 m_lastheight = width(); 2661 m_lastheight = width();
2306 } 2662 }
2307 else 2663 else
2308 { 2664 {
2309 m_lastwidth = width(); 2665 m_lastwidth = width();
2310 m_lastheight = height(); 2666 m_lastheight = height();
2311 } 2667 }
2312 if (buffdoc.openfile(this,newfile) == 0) 2668 if (buffdoc.openfile(this,newfile) == 0)
2313 { 2669 {
2314 m_lastfile = newfile; 2670 m_lastfile = newfile;
2315 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 2671 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
2316 bRC = true; 2672 bRC = true;
2317 buffdoc.setContinuous(m_continuousDocument); 2673 buffdoc.setContinuous(m_continuousDocument);
2318 qDebug("buffdoc.openfile done"); 2674 qDebug("buffdoc.openfile done");
2319 locate(lcn);
2320 qDebug("buffdoc.locate done");
2321 } 2675 }
2322 setfilter(getfilter()); 2676 setfilter(getfilter());
2323 qDebug("Updated"); 2677 qDebug("Updated");
2678 bDoUpdates = true;
2679 locate(lcn);
2324 return bRC; 2680 return bRC;
2325} 2681}
2326 2682
2327void QTReader::lineDown() 2683void QTReader::lineDown()
2328{ 2684{
2329 int ypos = m_topmargin; 2685 int ypos = m_topmargin;
2330 ResetScroll(); 2686 ResetScroll();
2331 int offset = numlines; 2687 int offset = numlines;
2332 2688
2333 for (int i = 0; i <= numlines; i++) 2689 for (int i = 0; i <= numlines; i++)
2334 { 2690 {
2335 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height())) 2691 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height()))
2336 { 2692 {
2337 offset = i-1; 2693 offset = i-1;
2338 break; 2694 break;
2339 } 2695 }
@@ -2345,32 +2701,33 @@ void QTReader::lineDown()
2345 for (int i = offset; i <= numlines; i++) 2701 for (int i = offset; i <= numlines; i++)
2346#endif 2702#endif
2347 { 2703 {
2348 CDrawBuffer* buff = textarray[i-offset]; 2704 CDrawBuffer* buff = textarray[i-offset];
2349 textarray[i-offset] = textarray[i]; 2705 textarray[i-offset] = textarray[i];
2350 locnarray[i-offset] = locnarray[i]; 2706 locnarray[i-offset] = locnarray[i];
2351 textarray[i] = buff; 2707 textarray[i] = buff;
2352 } 2708 }
2353 numlines = numlines - offset + 1; 2709 numlines = numlines - offset + 1;
2354 locnarray[numlines] = locate(); 2710 locnarray[numlines] = locate();
2355 if (textarray[numlines] == NULL) 2711 if (textarray[numlines] == NULL)
2356 { 2712 {
2357 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2713 textarray[numlines] = new CDrawBuffer(&m_fontControl);
2358 } 2714 }
2359 getline(textarray[numlines]); 2715 getline(textarray[numlines]);
2360 mylastpos = locate(); 2716 mylastpos = locate();
2717 m_outofdate = true;
2361 update(); 2718 update();
2362} 2719}
2363/* 2720/*
2364void QTReader::lineUp() 2721void QTReader::lineUp()
2365{ 2722{
2366 CBuffer** buff = textarray; 2723 CBuffer** buff = textarray;
2367 unsigned int *loc = new unsigned int[numlines]; 2724 unsigned int *loc = new unsigned int[numlines];
2368 int cbptr = 0; 2725 int cbptr = 0;
2369 if (locate() != mylastpos) jumpto(mylastpos); 2726 if (locate() != mylastpos) jumpto(mylastpos);
2370 unsigned int target = locnarray[numlines-1]; 2727 unsigned int target = locnarray[numlines-1];
2371 if (buffdoc.hasrandomaccess()) 2728 if (buffdoc.hasrandomaccess())
2372 { 2729 {
2373 unsigned int delta = locate()-pagelocate(); 2730 unsigned int delta = locate()-pagelocate();
2374 if (delta < 64) delta = 64; 2731 if (delta < 64) delta = 64;
2375 do 2732 do
2376 { 2733 {
@@ -2559,157 +2916,182 @@ MarkupType QTReader::PreferredMarkup()
2559{ 2916{
2560 MarkupType m = buffdoc.PreferredMarkup(); 2917 MarkupType m = buffdoc.PreferredMarkup();
2561 if (m == cTEXT) 2918 if (m == cTEXT)
2562 { 2919 {
2563 int ext = m_lastfile.findRev('.'); 2920 int ext = m_lastfile.findRev('.');
2564 if (ext >= 0) 2921 if (ext >= 0)
2565 { 2922 {
2566 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper(); 2923 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
2567 if (ft.left(3) == "HTM") 2924 if (ft.left(3) == "HTM")
2568 { 2925 {
2569 m = cHTML; 2926 m = cHTML;
2570 } 2927 }
2571 } 2928 }
2572 } 2929 }
2573 return m; 2930 return m;
2574} 2931}
2575#ifdef DOUBLEBUFFER 2932
2576void QTReader::resizeEvent( QResizeEvent * p ) 2933void QTReader::resizeEvent( QResizeEvent * p )
2577{ 2934{
2578 if (m_rotated) 2935 qDebug("Resizing");
2579 { 2936 m_outofdate = true;
2580 dbuff->resize(p->size().height(),p->size().width()); 2937 if (dbuff != NULL)
2581 }
2582 else
2583 { 2938 {
2584 dbuff->resize(p->size()); 2939 if (m_rotated)
2940 {
2941 dbuff->resize(p->size().height(),p->size().width());
2942 }
2943 else
2944 {
2945 dbuff->resize(p->size());
2946 }
2585 } 2947 }
2586 m_bgIsScaled = false; 2948 m_bgIsScaled = false;
2587 if (m_bgtype == bgStretched) 2949 if (m_bgtype == bgStretched)
2588 { 2950 {
2589 emit RefreshBitmap(); 2951 emit RefreshBitmap();
2590 } 2952 }
2591 2953
2592 { 2954 {
2593 int h, w; 2955 int h, w;
2594 if (m_rotated) 2956 if (m_rotated)
2595 { 2957 {
2596 h = p->size().width(); 2958 h = p->size().width();
2597 w = p->size().height(); 2959 w = p->size().height();
2598 } 2960 }
2599 else 2961 else
2600 { 2962 {
2601 w = p->size().width(); 2963 w = p->size().width();
2602 h = p->size().height(); 2964 h = p->size().height();
2603 } 2965 }
2604 m_topmargin = (h*m_abstopmargin+500)/1000; 2966 m_topmargin = (h*m_abstopmargin+500)/1000;
2605 m_bottommargin = (h*m_absbottommargin+500)/1000; 2967 m_bottommargin = (h*m_absbottommargin+500)/1000;
2606 m_left_border = (w*m_absleft_border+500)/1000; 2968 m_left_border = (w*m_absleft_border+500)/1000;
2607 m_right_border = (w*m_absright_border+500)/1000; 2969 m_right_border = (w*m_absright_border+500)/1000;
2608
2609 qDebug("Top margin:%u", m_topmargin );
2610 qDebug("Bottom margin:%u", m_bottommargin );
2611 qDebug("Left margin:%u", m_left_border );
2612 qDebug("Right margin:%u", m_right_border );
2613 } 2970 }
2971 if (dbuff != NULL && buffdoc.empty())
2972 {
2973 dbp->begin(dbuff);
2974 drawBackground(dbp);
2975 dbp->end();
2976 }
2614} 2977}
2615#endif
2616 2978
2617void QTReader::setrotated(bool sfs) 2979void QTReader::setrotated(bool sfs)
2618{ 2980{
2981 qDebug("Rotating");
2619 m_rotated = sfs; 2982 m_rotated = sfs;
2620#ifdef DOUBLEBUFFER 2983 setDoubleBuffer(m_doubleBuffered);
2621 if (m_rotated)
2622 {
2623 dbuff->resize(height(), width());
2624 }
2625 else
2626 {
2627 dbuff->resize(width(), height());
2628 }
2629 m_bgIsScaled = false; 2984 m_bgIsScaled = false;
2630#endif 2985 m_outofdate = true;
2986 /*
2631 int h, w; 2987 int h, w;
2632 if (m_rotated) 2988 if (m_rotated)
2633 { 2989 {
2634 h = width(); 2990 h = width();
2635 w = height(); 2991 w = height();
2636 } 2992 }
2637 else 2993 else
2638 { 2994 {
2639 w = width(); 2995 w = width();
2640 h = height(); 2996 h = height();
2641 } 2997 }
2642 m_topmargin = (h*m_abstopmargin+500)/1000; 2998 m_topmargin = (h*m_abstopmargin+500)/1000;
2643 m_bottommargin = (h*m_absbottommargin+500)/1000; 2999 m_bottommargin = (h*m_absbottommargin+500)/1000;
2644 m_left_border = (w*m_absleft_border+500)/1000; 3000 m_left_border = (w*m_absleft_border+500)/1000;
2645 m_right_border = (w*m_absright_border+500)/1000; 3001 m_right_border = (w*m_absright_border+500)/1000;
2646 3002
2647 qDebug("Top margin:%u", m_topmargin ); 3003 qDebug("Top margin:%u", m_topmargin );
2648 qDebug("Bottom margin:%u", m_bottommargin ); 3004 qDebug("Bottom margin:%u", m_bottommargin );
2649 qDebug("Left margin:%u", m_left_border ); 3005 qDebug("Left margin:%u", m_left_border );
2650 qDebug("Right margin:%u", m_right_border ); 3006 qDebug("Right margin:%u", m_right_border );
3007 */
2651} 3008}
2652 3009
2653void QTReader::drawBackground() 3010void QTReader::drawBackground(QPainter *p)
2654{ 3011{
2655 dbp->begin(dbuff); 3012 // p->setBackgroundMode(OpaqueMode);
2656 // dbp->setBackgroundMode(OpaqueMode); 3013 p->setBackgroundColor(m_bg);
2657 dbp->setBackgroundColor(m_bg); 3014 if (dbuff != NULL)
2658 dbp->eraseRect(dbuff->rect()); 3015 {
3016 p->eraseRect(dbuff->rect());
3017 }
3018 else
3019 {
3020 if (m_rotated)
3021 {
3022 p->eraseRect(0,0,height(),width());
3023 }
3024 else
3025 {
3026 p->eraseRect(rect());
3027 }
3028 }
2659 if (!m_bgpm.isNull()) 3029 if (!m_bgpm.isNull())
2660 { 3030 {
2661 // dbp->setBackgroundMode(TransparentMode); 3031 // p->setBackgroundMode(TransparentMode);
2662 switch (m_bgtype) 3032 switch (m_bgtype)
2663 { 3033 {
2664 case bgCentred: 3034 case bgCentred:
2665 { 3035 {
2666 int w = (dbuff->rect().width()-m_bgpm.width())/2; 3036 if (dbuff == NULL)
2667 int h = (dbuff->rect().height()-m_bgpm.height())/2; 3037 {
2668 dbp->drawPixmap(w,h,m_bgpm); 3038 p->drawPixmap(width(),height(),m_bgpm);
3039 }
3040 else
3041 {
3042 int w = (dbuff->rect().width()-m_bgpm.width())/2;
3043 int h = (dbuff->rect().height()-m_bgpm.height())/2;
3044 p->drawPixmap(w,h,m_bgpm);
3045 }
2669 } 3046 }
2670 break; 3047 break;
2671 case bgTiled: 3048 case bgTiled:
2672 { 3049 {
2673 dbp->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm); 3050 if (dbuff == NULL)
2674 /*
2675 for (int h = 0; h < dbuff->rect().height(); h += m_bgpm.height())
2676 { 3051 {
2677 for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width()) 3052 p->drawTiledPixmap(0,0,width(),height(),m_bgpm);
2678 { 3053 }
2679 dbp->drawPixmap(w,h,m_bgpm); 3054 else
2680 } 3055 {
3056 p->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm);
2681 } 3057 }
2682 */
2683 } 3058 }
2684 break; 3059 break;
2685 case bgStretched: 3060 case bgStretched:
2686 { 3061 {
2687 if (!m_bgIsScaled) 3062 if (!m_bgIsScaled)
2688 { 3063 {
2689 m_bgIsScaled = true; 3064 m_bgIsScaled = true;
2690 QImage im = m_bgpm.convertToImage(); 3065 QImage im = m_bgpm.convertToImage();
2691 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); 3066 if (dbuff == NULL)
3067 {
3068 m_bgpm.convertFromImage(im.smoothScale(width(),height()));
3069 }
3070 else
3071 {
3072 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
3073 }
2692 } 3074 }
2693 dbp->drawPixmap(0,0,m_bgpm); 3075 p->drawPixmap(0,0,m_bgpm);
2694 } 3076 }
2695 break; 3077 break;
2696 default: 3078 default:
2697 qDebug("Unknown background type"); 3079 qDebug("Unknown background type");
2698 } 3080 }
2699 // dbp->setBackgroundMode(OpaqueMode); 3081 // p->setBackgroundMode(OpaqueMode);
2700 } 3082 }
2701} 3083}
2702 3084
2703void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt) 3085void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2704{ 3086{
2705 if (txt != NULL) 3087 if (txt != NULL)
2706 { 3088 {
2707 sh = txt->lineSpacing(); 3089 sh = txt->lineSpacing();
2708 } 3090 }
2709 int sy = width()-dx-sh; 3091 int sy = width()-dx-sh;
2710 if (m_autoScroll && !(m_scrolltype == 0)) 3092 if (m_autoScroll && !(m_scrolltype == 0))
2711 { 3093 {
2712 sy = (sy+m_totalscroll+1)%width(); 3094 sy = (sy+m_totalscroll+1)%width();
2713 } 3095 }
2714 3096
2715 QPixmap pm(sw, sh); 3097 QPixmap pm(sw, sh);
@@ -2746,33 +3128,38 @@ void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2746 if (txt != NULL) 3128 if (txt != NULL)
2747 { 3129 {
2748 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg); 3130 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg);
2749 txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin); 3131 txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin);
2750 } 3132 }
2751 QWMatrix m; 3133 QWMatrix m;
2752 m.rotate(90); 3134 m.rotate(90);
2753 QPixmap rp = pm.xForm(m); 3135 QPixmap rp = pm.xForm(m);
2754 /* 3136 /*
2755 p.drawPixmap(QPoint(dx, dy), rp); 3137 p.drawPixmap(QPoint(dx, dy), rp);
2756 */ 3138 */
2757 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP); 3139 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP);
2758} 3140}
2759 3141
2760QString QTReader::about() 3142QString QTReader::about()
2761{ 3143{
2762 return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; 3144 QString ab = QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka";
3145 if (m_output != NULL)
3146 {
3147 ab += QString("\n") + m_output->about();
3148 }
3149 return ab;
2763} 3150}
2764 3151
2765void QTReader::getNextLink() 3152void QTReader::getNextLink()
2766{ 3153{
2767 if (m_scrolldy != 0) 3154 if (m_scrolldy != 0)
2768 { 3155 {
2769 setautoscroll(false); 3156 setautoscroll(false);
2770 ResetScroll(); 3157 ResetScroll();
2771 redrawall(); 3158 redrawall();
2772 } 3159 }
2773 bool redraw = false; 3160 bool redraw = false;
2774 bool found = false; 3161 bool found = false;
2775 if (m_currentlink >= 0) 3162 if (m_currentlink >= 0)
2776 { 3163 {
2777 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); 3164 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2778 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL) 3165 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL)
@@ -2884,102 +3271,222 @@ void QTReader::gotoLink()
2884 QString href, nm; 3271 QString href, nm;
2885 unsigned long tgt = m_currentlinkstyle->getData(); 3272 unsigned long tgt = m_currentlinkstyle->getData();
2886 unsigned long tgtoffset = m_currentlinkstyle->getOffset(); 3273 unsigned long tgtoffset = m_currentlinkstyle->getOffset();
2887 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); 3274 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
2888 qDebug("URL(1):%s", (const char*)href); 3275 qDebug("URL(1):%s", (const char*)href);
2889 if ((lt & eFile) != 0) 3276 if ((lt & eFile) != 0)
2890 { 3277 {
2891 buffdoc.saveposn(m_lastfile, saveposn); 3278 buffdoc.saveposn(m_lastfile, saveposn);
2892#ifdef USEQPE 3279#ifdef USEQPE
2893 { 3280 {
2894 QCopEnvelope e("QPE/System", "busy()"); 3281 QCopEnvelope e("QPE/System", "busy()");
2895 } 3282 }
2896#endif 3283#endif
2897 ResetScroll(); 3284 ResetScroll();
2898 if (!href.isEmpty()) 3285 if (!href.isEmpty())
2899 { 3286 {
2900 if (!buffdoc.getFile(href)) 3287 if (!buffdoc.getFile(href, nm))
2901 { 3288 {
2902 emit NewFileRequest(href); 3289 emit NewFileRequest(href);
2903 } 3290 }
2904 else 3291 else
2905 { 3292 {
2906 ResetScroll(); 3293 ResetScroll();
2907 fillbuffer(); 3294 fillbuffer();
3295 m_outofdate = true;
2908 update(); 3296 update();
2909 } 3297 }
2910 } 3298 }
2911 if (!nm.isEmpty()) 3299 if (!nm.isEmpty())
2912 { 3300 {
2913 qDebug("QTReader:Finding %s", (const char*)nm); 3301 qDebug("QTReader:Finding %s", (const char*)nm);
2914 if (buffdoc.findanchor(nm)) 3302 if (buffdoc.findanchor(nm))
2915 { 3303 {
3304 buffdoc.resetPos();
2916 fillbuffer(); 3305 fillbuffer();
3306 m_outofdate = true;
2917 update(); 3307 update();
2918 } 3308 }
2919 } 3309 }
2920 //fillbuffer(); 3310 //fillbuffer();
2921 //update(); 3311 //update();
2922#ifdef USEQPE 3312#ifdef USEQPE
2923 { 3313 {
2924 QCopEnvelope e("QPE/System", "notBusy()"); 3314 QCopEnvelope e("QPE/System", "notBusy()");
2925 } 3315 }
2926#endif 3316#endif
2927 } 3317 }
2928 else if ((lt & eLink) != 0) 3318 else if ((lt & eLink) != 0)
2929 { 3319 {
2930 buffdoc.saveposn(m_lastfile, saveposn); 3320 buffdoc.saveposn(m_lastfile, saveposn);
2931 ResetScroll(); 3321 ResetScroll();
2932 fillbuffer(); 3322 fillbuffer();
3323 m_outofdate = true;
2933 update(); 3324 update();
2934 } 3325 }
2935 else 3326 else
2936 { 3327 {
2937 if ((lt & ePicture) != 0) 3328 if ((lt & ePicture) != 0)
2938 { 3329 {
2939 QImage* pm = buffdoc.getPicture(tgt); 3330 QImage* pm = buffdoc.getPicture(tgt);
2940 if (pm != NULL) 3331 if (pm != NULL)
2941 { 3332 {
2942 emit OnShowPicture(*pm); 3333 emit OnShowPicture(*pm);
2943 delete pm; 3334 delete pm;
2944 } 3335 }
2945 } 3336 }
2946 else 3337 else
2947 { 3338 {
2948 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 3339 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
2949 if (!href.isEmpty()) 3340 if (!href.isEmpty())
2950 { 3341 {
2951 emit OnURLSelected(href, tgt); 3342 emit OnURLSelected(href, tgt);
3343 refresh();
2952 } 3344 }
2953 } 3345 }
2954 locate(pagelocate());
2955 } 3346 }
2956 m_currentlinkstyle = NULL; 3347 m_currentlinkstyle = NULL;
2957 m_currentlink = -1; 3348 m_currentlink = -1;
2958 m_currentlinkoffset = -1; 3349 m_currentlinkoffset = -1;
2959} 3350}
2960 3351
2961void QTReader::refresh(bool full) 3352void QTReader::refresh(bool full)
2962{ 3353{
3354 qDebug("Refreshing");
2963 int h, w; 3355 int h, w;
2964 if (m_rotated) 3356 if (m_rotated)
2965 { 3357 {
2966 h = width(); 3358 h = width();
2967 w = height(); 3359 w = height();
2968 } 3360 }
2969 else 3361 else
2970 { 3362 {
2971 w = width(); 3363 w = width();
2972 h = height(); 3364 h = height();
2973 } 3365 }
2974 m_topmargin = (h*m_abstopmargin+500)/1000; 3366 m_topmargin = (h*m_abstopmargin+500)/1000;
2975 m_bottommargin = (h*m_absbottommargin+500)/1000; 3367 m_bottommargin = (h*m_absbottommargin+500)/1000;
2976 m_left_border = (w*m_absleft_border+500)/1000; 3368 m_left_border = (w*m_absleft_border+500)/1000;
2977 m_right_border = (w*m_absright_border+500)/1000; 3369 m_right_border = (w*m_absright_border+500)/1000;
2978 3370
2979 qDebug("Top margin:%u", m_topmargin ); 3371 qDebug("Top margin:%u", m_topmargin );
2980 qDebug("Bottom margin:%u", m_bottommargin ); 3372 qDebug("Bottom margin:%u", m_bottommargin );
2981 qDebug("Left margin:%u", m_left_border ); 3373 qDebug("Left margin:%u", m_left_border );
2982 qDebug("Right margin:%u", m_right_border ); 3374 qDebug("Right margin:%u", m_right_border );
2983 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate()); 3375 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate());
3376 m_outofdate = true;
2984 locate(pagelocate()); 3377 locate(pagelocate());
2985} 3378}
3379
3380#include "striphtml.h"
3381
3382CFilterChain* QTReader::getfilter()
3383{
3384 CFilterChain * filt = new CFilterChain(getencoding());
3385 if (bstripcr) filt->addfilter(new stripcr);
3386
3387 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
3388 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
3389 // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3390
3391#ifdef __STATIC
3392 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3393 if (bautofmt && (PreferredMarkup() == cCHM))
3394 {
3395 striphtml* f = new striphtml(m_lastfile);
3396 f->setchm(true);
3397 filt->addfilter(f);
3398 }
3399#else
3400 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile));
3401 if (bautofmt && (PreferredMarkup() == cCHM))
3402 {
3403 ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile);
3404 ((striphtml*)f->filter())->setchm(true);
3405 filt->addfilter(f);
3406 }
3407#endif
3408 m_highlightfilter = new HighlightFilter(this);
3409 filt->addfilter(m_highlightfilter);
3410
3411 if (bdehyphen) filt->addfilter(new dehyphen);
3412 if (bunindent) filt->addfilter(new unindent);
3413 if (brepara) filt->addfilter(new repara(m_reparastring));
3414 if (bonespace) filt->addfilter(new OnePara);
3415 if (bindenter) filt->addfilter(new indenter(bindenter));
3416 if (bdblspce) filt->addfilter(new dblspce);
3417 if (bdepluck) filt->addfilter(new DePluck(pluckernextpart));
3418 if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart));
3419 if (brepalm) filt->addfilter(new repalm);
3420 if (bunderlineLink) filt->addfilter(new underlineLink);
3421 if (bkern) filt->addfilter(new kern);
3422 if (bremap) filt->addfilter(new remap);
3423 if (bmakebold) filt->addfilter(new embolden);
3424 if (bfulljust) filt->addfilter(new FullJust);
3425 int r,g,b;
3426 m_default_bg.rgb(&r, &g, &b);
3427 if (r != 255 || g != 255 || b != 255)
3428 filt->addfilter(new setbg(r,g,b));
3429 m_default_fg.rgb(&r, &g, &b);
3430 if (r != 0 || g != 0 || b != 0)
3431 filt->addfilter(new setfg(r,g,b));
3432 // if (bNegative) filt->addfilter(new makeNegative);
3433 if (bInverse) filt->addfilter(new makeInverse);
3434 if (bNoInlineTables) filt->addfilter(new tableLink);
3435 return filt;
3436}
3437
3438void QTReader::readAloud()
3439{
3440#ifdef __STATIC
3441 return;
3442#else
3443 CBuffer para;
3444 jumpto(pagelocate());
3445 while (m_autoScroll && (buffdoc.getpara(para) != -1))
3446 {
3447 if (para.length() > 0)
3448 {
3449 unsigned long lastpos = buffdoc.explocate();
3450 while (lastpos > mylastpos)
3451 {
3452 dopagedn();
3453 qApp->processEvents();
3454 }
3455 jumpto(lastpos);
3456 QString txt = toQString(para.data());
3457
3458 doOutput(txt);
3459 }
3460 qApp->processEvents();
3461 }
3462#endif
3463}
3464
3465bool QTReader::doOutput(const QString& wrd)
3466{
3467 if (m_output != NULL)
3468 {
3469 m_output->output(wrd);
3470 return true;
3471 }
3472 else
3473 {
3474 return false;
3475 }
3476}
3477
3478bool QTReader::checkoutput()
3479{
3480 if (m_output == NULL)
3481 {
3482 m_output = new outputcodec(m_outputName);
3483 if (reinterpret_cast<outputcodec*>(m_output)->getStatus() != 0)
3484 {
3485 delete m_output;
3486 m_output = NULL;
3487 QMessageBox::warning(this, PROGNAME, QString("Couldn't find output codec\n")+m_outputName);
3488 return false;
3489 }
3490 }
3491 return true;
3492}