summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp622
1 files changed, 429 insertions, 193 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index f2ee027..03c8fbe 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -8,21 +8,27 @@
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11#include "useqpe.h"
11#include <qpainter.h> 12#include <qpainter.h>
13#include <qimage.h>
14#include <qtimer.h>
12#include "config.h" 15#include "config.h"
13#include "QTReader.h" 16#include "QTReader.h"
14#include "QTReaderApp.h" 17#include "QTReaderApp.h"
15#include "CDrawBuffer.h" 18#include "CDrawBuffer.h"
19#ifdef USEQPE
16#include <qpe/qpeapplication.h> 20#include <qpe/qpeapplication.h>
21#endif
17#include <math.h> 22#include <math.h>
18#include <ctype.h> 23#include <ctype.h>
19#include <stdio.h> //for sprintf 24#include <stdio.h> //for sprintf
25#ifdef USEQPE
20#include <qpe/config.h> 26#include <qpe/config.h>
21#include <qpe/applnk.h> 27#include <qpe/applnk.h>
22#include <qfontdatabase.h>
23#include <qpe/global.h> 28#include <qpe/global.h>
24#include <qpe/qcopenvelope_qws.h> 29#include <qpe/qcopenvelope_qws.h>
25#include "StateData.h" 30#endif
31#include <qfontdatabase.h>
26 32
27#ifdef _UNICODE 33#ifdef _UNICODE
28const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 34const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
@@ -36,6 +42,10 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
36//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 42//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
37//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}; 43//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};
38 44
45tchar 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 };
46tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
47//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
48
39QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 49QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
40 QWidget(parent, name, f), 50 QWidget(parent, name, f),
41 m_delay(100), 51 m_delay(100),
@@ -51,13 +61,18 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
51 m_twotouch(true), 61 m_twotouch(true),
52 m_touchone(true), 62 m_touchone(true),
53 bDoUpdates(false), 63 bDoUpdates(false),
54 m_navkeys(true) 64#ifdef _SCROLLPIPE
65 m_pipeout(NULL),
66#endif
67 m_border(2)
55{ 68{
56 m_overlap = 1; 69 m_overlap = 1;
70 setKeyCompression ( true );
57// init(); 71// init();
58} 72}
73
59/* 74/*
60QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, WFlags f ) : 75QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
61 QWidget(parent, name, f), 76 QWidget(parent, name, f),
62 m_textfont(0), 77 m_textfont(0),
63 m_textsize(1), 78 m_textsize(1),
@@ -72,11 +87,20 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name,
72 m_fm(NULL) 87 m_fm(NULL)
73{ 88{
74 init(); 89 init();
75 // qDebug("Load_file(1)"); 90// // qDebug("Load_file(1)");
76 load_file((const tchar*)filename); 91 load_file((const tchar*)filename);
77} 92}
78*/ 93*/
79 94
95/*
96void QTReader::mouseMoveEvent(QMouseEvent* _e)
97{
98
99 mouseUpOn = !(_e->pos().x() == -1);
100
101 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
102}
103*/
80long QTReader::real_delay() 104long QTReader::real_delay()
81{ 105{
82 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 106 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
@@ -87,7 +111,27 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
87 buffdoc.unsuspend(); 111 buffdoc.unsuspend();
88 if (_e->button() == RightButton) 112 if (_e->button() == RightButton)
89 { 113 {
114 //qDebug("MousePress");
90 mouseUpOn = false; 115 mouseUpOn = false;
116 if (m_swapmouse)
117 {
118 int lineno = 0;
119 int ht = textarray[0]->lineSpacing();
120 while ((ht < _e->y()) && (lineno < numlines))
121 {
122 ht += textarray[++lineno]->lineSpacing();
123 }
124 size_t startpos, startoffset, tgt;
125 getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt);
126 processmousewordevent(startpos, startoffset, _e, lineno);
127 }
128 else
129 processmousepositionevent(_e);
130 }
131}
132
133void QTReader::processmousepositionevent( QMouseEvent* _e )
134{
91 if (buffdoc.hasnavigation()) 135 if (buffdoc.hasnavigation())
92 { 136 {
93 if (_e->y() > (2*height())/3) 137 if (_e->y() > (2*height())/3)
@@ -102,24 +146,15 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
102 { 146 {
103 if (_e->x() < width()/3) 147 if (_e->x() < width()/3)
104 { 148 {
105 size_t target = pagelocate(); 149 goBack();
106 if (buffdoc.back(target))
107 {
108 locate(target);
109 }
110 } 150 }
111 else if (_e->x() > (2*width())/3) 151 else if (_e->x() > (2*width())/3)
112 { 152 {
113 size_t target = pagelocate(); 153 goForward();
114 if (buffdoc.forward(target))
115 {
116 locate(target);
117 }
118 } 154 }
119 else 155 else
120 { 156 {
121 buffdoc.saveposn(pagelocate()); 157 goHome();
122 locate(buffdoc.getHome());
123 } 158 }
124 } 159 }
125 } 160 }
@@ -135,6 +170,44 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
135 } 170 }
136 } 171 }
137 } 172 }
173
174void QTReader::goHome()
175{
176 if (buffdoc.hasnavigation())
177 {
178 size_t current=pagelocate();
179 size_t home=buffdoc.getHome();
180 if (current!=home)
181 {
182 buffdoc.saveposn(current);
183 locate(home);
184 }
185 }
186}
187
188void QTReader::goBack()
189{
190 if (buffdoc.hasnavigation())
191 {
192 size_t target = pagelocate();
193 buffdoc.writeposn(target);
194 if (buffdoc.back(target))
195 {
196 locate(target);
197 }
198 }
199}
200
201void QTReader::goForward()
202{
203 if (buffdoc.hasnavigation())
204 {
205 size_t target = pagelocate();
206 if (buffdoc.forward(target))
207 {
208 locate(target);
209 }
210 }
138} 211}
139 212
140linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) 213linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
@@ -148,19 +221,28 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
148 start = locnarray[lineno]; 221 start = locnarray[lineno];
149 if (m_bMonoSpaced) 222 if (m_bMonoSpaced)
150 { 223 {
151 offset = x/m_charWidth; 224 offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth;
152 } 225 }
153 else 226 else
154 { 227 {
155 int i; 228 int i;
156 CDrawBuffer* t = textarray[lineno]; 229 CDrawBuffer* t = textarray[lineno];
157 x = x - t->offset(width()); 230 x = x - t->offset(width(), m_border);
158 for (i = t->length(); i >= 0 && t->width(i) > x; i--); 231 for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--);
159 offset = i; 232 offset = i;
160 } 233 }
161 return textarray[lineno]->getLinkType(offset, tgt); 234 return textarray[lineno]->getLinkType(offset, tgt);
162} 235}
163 236
237void QTReader::suspend()
238{
239#ifdef OPIE
240 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
241#else
242 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
243#endif
244}
245
164void QTReader::setTwoTouch(bool _b) 246void QTReader::setTwoTouch(bool _b)
165{ 247{
166 setBackgroundColor( white ); 248 setBackgroundColor( white );
@@ -173,62 +255,9 @@ void QTReader::setContinuous(bool _b)
173 buffdoc.setContinuous(m_continuousDocument = _b); 255 buffdoc.setContinuous(m_continuousDocument = _b);
174} 256}
175 257
176void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 258void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
177{
178 buffdoc.unsuspend();
179 if (_e->button() == LeftButton)
180 {
181 if (mouseUpOn)
182 {
183 if (textarray[0] != NULL)
184 {
185 QString wrd, line;
186 // int lineno = _e->y()/m_linespacing;
187 int lineno = 0;
188 int ht = textarray[0]->lineSpacing();
189 while ((ht < _e->y()) && (lineno < numlines))
190 {
191 ht += textarray[++lineno]->lineSpacing();
192 }
193 size_t startpos, startoffset, tgt;
194 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
195 {
196 case eLink:
197 {
198 size_t saveposn = pagelocate();
199 if (buffdoc.hyperlink(tgt))
200 {
201 buffdoc.saveposn(saveposn);
202 fillbuffer();
203 update();
204 }
205 else
206 {
207 locate(pagelocate());
208 }
209 return;
210 }
211 case ePicture:
212 {
213 qDebug("Picture:%x", tgt);
214 QPixmap* pm = buffdoc.getPicture(tgt);
215 if (pm != NULL)
216 {
217 emit OnShowPicture(*pm);
218 delete pm;
219 }
220 else
221 { 259 {
222 locate(pagelocate()); 260 QString wrd;
223 }
224 return;
225 }
226 case eNone:
227 break;
228 default:
229 qDebug("Unknown linktype");
230 return;
231 }
232 if (m_twotouch) 261 if (m_twotouch)
233 { 262 {
234 if (m_touchone) 263 if (m_touchone)
@@ -277,7 +306,7 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
277 } 306 }
278 else if (m_bMonoSpaced) 307 else if (m_bMonoSpaced)
279 { 308 {
280 int chno = _e->x()/m_charWidth; 309 int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth;
281 if (chno < ustrlen(textarray[lineno]->data())) 310 if (chno < ustrlen(textarray[lineno]->data()))
282 { 311 {
283 wrd[0] = textarray[lineno]->data()[chno]; 312 wrd[0] = textarray[lineno]->data()[chno];
@@ -287,14 +316,15 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
287 { 316 {
288 CDrawBuffer* t = textarray[lineno]; 317 CDrawBuffer* t = textarray[lineno];
289 int first = 0; 318 int first = 0;
290 int tgt = _e->x() - t->offset(width()); 319 int tgt = _e->x() - t->offset(width(), m_border);
291 while (1) 320 while (1)
292 { 321 {
293 int i = first+1; 322 int i = first+1;
294 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 323 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
295 if (t->width(i) > tgt) 324 if (t->width(i, true, width(), m_border) > tgt)
296 { 325 {
297 wrd = toQString(t->data()+first, i - first); 326 wrd = toQString(t->data()+first, i - first);
327 // qDebug("Got %s", (const char *)wrd);
298 break; 328 break;
299 } 329 }
300 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 330 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
@@ -304,9 +334,97 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
304 } 334 }
305 if (!wrd.isEmpty()) 335 if (!wrd.isEmpty())
306 { 336 {
337 //qDebug("Selected:%s", (const char*)wrd);
307 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); 338 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
308 } 339 }
309 } 340 }
341
342void QTReader::mouseReleaseEvent( QMouseEvent* _e )
343{
344 buffdoc.unsuspend();
345 if (_e->button() == LeftButton)
346 {
347 if (mouseUpOn)
348 {
349 // qDebug("MouseRelease");
350 if (_e->x() > width() - m_border)
351 {
352 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height());
353 return;
354 }
355 if (textarray[0] != NULL)
356 {
357 QString line;
358 // int lineno = _e->y()/m_linespacing;
359 int lineno = 0;
360 int ht = textarray[0]->lineSpacing();
361 while ((ht < _e->y()) && (lineno < numlines))
362 {
363 ht += textarray[++lineno]->lineSpacing();
364 }
365 size_t startpos, startoffset, tgt;
366 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
367 {
368 case eLink:
369 {
370 size_t saveposn = pagelocate();
371 QString href;
372 linkType lt = buffdoc.hyperlink(tgt, href);
373 if (lt == eLink)
374 {
375 buffdoc.saveposn(saveposn);
376 fillbuffer();
377 update();
378 }
379 else
380 {
381 if (lt == ePicture)
382 {
383 QImage* pm = buffdoc.getPicture(tgt);
384 if (pm != NULL)
385 {
386 emit OnShowPicture(*pm);
387 delete pm;
388 }
389 }
390 else
391 {
392 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
393 if (!href.isEmpty())
394 {
395 emit OnURLSelected(href);
396 }
397 }
398 locate(pagelocate());
399 }
400 return;
401 }
402 case ePicture:
403 {
404 // qDebug("Picture:%x", tgt);
405 QImage* pm = buffdoc.getPicture(tgt);
406 if (pm != NULL)
407 {
408 emit OnShowPicture(*pm);
409 delete pm;
410 }
411 else
412 {
413 locate(pagelocate());
414 }
415 return;
416 }
417 case eNone:
418 break;
419 default:
420 // qDebug("Unknown linktype");
421 return;
422 }
423 if (m_swapmouse)
424 processmousepositionevent(_e);
425 else
426 processmousewordevent(startpos, startoffset, _e, lineno);
427 }
310 } 428 }
311 else 429 else
312 { 430 {
@@ -326,13 +444,15 @@ void QTReader::focusOutEvent(QFocusEvent* e)
326 if (m_autoScroll) 444 if (m_autoScroll)
327 { 445 {
328 timer->stop(); 446 timer->stop();
329 m_scrolldy1 = m_scrolldy2 = 0; 447 //m_scrolldy1 = m_scrolldy2 = 0;
330 } 448 }
331} 449}
332 450
333#include <qapplication.h> 451#include <qapplication.h>
334#include <qdrawutil.h> 452#include <qdrawutil.h>
453#ifndef _WINDOWS
335#include <unistd.h> 454#include <unistd.h>
455#endif
336 456
337void QTReader::goDown() 457void QTReader::goDown()
338{ 458{
@@ -426,9 +546,62 @@ void QTReader::zoomout()
426 } 546 }
427} 547}
428 548
549void QTReader::reduceScroll()
550{
551 if (m_delay < 59049)
552 {
553 m_delay = (3*m_delay)/2;
554 timer->changeInterval(real_delay());
555 }
556 else
557 {
558 m_delay = 59049;
559 }
560}
561
562void QTReader::increaseScroll()
563{
564 if (m_delay > 1024)
565 {
566 m_delay = (2*m_delay)/3;
567 timer->changeInterval(real_delay());
568 }
569 else
570 {
571 m_delay = 1024;
572 }
573}
574
429void QTReader::keyPressEvent(QKeyEvent* e) 575void QTReader::keyPressEvent(QKeyEvent* e)
430{ 576{
431 buffdoc.unsuspend(); 577 buffdoc.unsuspend();
578 ((QTReaderApp*)parent()->parent())->handlekey(e);
579// e->ignore();
580 return;
581#ifdef _SCROLLPIPE
582 if (m_isPaused)
583 {
584 m_isPaused = false;
585 if (e->key() != Key_Space)
586 {
587 m_autoScroll = false;
588 if (m_pipeout != NULL)
589 {
590 pclose(m_pipeout);
591 m_pipeout = NULL;
592 }
593 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
594 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
595 }
596 else
597 {
598 timer->start(real_delay(), false);
599 }
600 e->accept();
601 return;
602 }
603#endif
604/*
432 switch (e->key()) 605 switch (e->key())
433 { 606 {
434 case Key_Down: 607 case Key_Down:
@@ -473,35 +646,6 @@ void QTReader::keyPressEvent(QKeyEvent* e)
473 } 646 }
474 } 647 }
475 break; 648 break;
476 /*
477 case Key_Left:
478 {
479 e->accept();
480 if (m_textfont > 0)
481 {
482 m_textfont--;
483 setfont(NULL);
484 locate(pagelocate());
485 update();
486 }
487 }
488 break;
489 case Key_Right:
490 {
491 e->accept();
492 if (fonts[++m_textfont] == 0)
493 {
494 m_textfont--;
495 }
496 else
497 {
498 setfont(NULL);
499 locate(pagelocate());
500 update();
501 }
502 }
503 break;
504 */
505 case Key_Right: 649 case Key_Right:
506 { 650 {
507 e->accept(); 651 e->accept();
@@ -530,16 +674,10 @@ void QTReader::keyPressEvent(QKeyEvent* e)
530 else zoomout(); 674 else zoomout();
531 } 675 }
532 break; 676 break;
533 case Key_Space:
534 case Key_Return:
535 {
536 e->accept();
537 emit OnActionPressed();
538 }
539 break;
540 default: 677 default:
541 e->ignore(); 678 e->ignore();
542 } 679 }
680*/
543} 681}
544 682
545void QTReader::setautoscroll(bool _sc) 683void QTReader::setautoscroll(bool _sc)
@@ -548,15 +686,34 @@ void QTReader::setautoscroll(bool _sc)
548 if (m_autoScroll) 686 if (m_autoScroll)
549 { 687 {
550 m_autoScroll = false; 688 m_autoScroll = false;
689#ifdef USEQPE
551 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 690 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
691#endif
692#ifdef _SCROLLPIPE
693 if (m_pipeout != NULL)
694 {
695 pclose(m_pipeout);
696 m_pipeout = NULL;
697 }
698#endif
552 } 699 }
553 else 700 else
554 { 701 {
555 CDrawBuffer* reusebuffer = textarray[numlines]; 702 CDrawBuffer* reusebuffer = textarray[numlines];
556 if (reusebuffer == NULL || reusebuffer->eof()) return; 703 if (reusebuffer == NULL || reusebuffer->eof()) return;
557 m_autoScroll = true; 704 m_autoScroll = true;
705#ifdef _SCROLLPIPE
706 if (!m_pipetarget.isEmpty())
707 {
708 // qDebug("Opening pipe to %s", (const char*)m_pipetarget);
709 m_pipeout = popen((const char*)m_pipetarget, "w");
710 m_isPaused = false;
711 }
712#endif
558 autoscroll(); 713 autoscroll();
714#ifdef USEQPE
559 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 715 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
716#endif
560 } 717 }
561} 718}
562 719
@@ -565,11 +722,11 @@ bool QTReader::getline(CDrawBuffer *buff)
565 buffdoc.unsuspend(); 722 buffdoc.unsuspend();
566 if (m_bMonoSpaced) 723 if (m_bMonoSpaced)
567 { 724 {
568 return buffdoc.getline(buff ,width(), m_charWidth); 725 return buffdoc.getline(buff ,width(), m_charWidth, m_border);
569 } 726 }
570 else 727 else
571 { 728 {
572 return buffdoc.getline(buff, width()); 729 return buffdoc.getline(buff, width(), m_border);
573 } 730 }
574} 731}
575 732
@@ -588,6 +745,25 @@ void QTReader::doscroll()
588 745
589 if (++m_scrolldy1 == textarray[0]->lineSpacing()) 746 if (++m_scrolldy1 == textarray[0]->lineSpacing())
590 { 747 {
748#ifdef _SCROLLPIPE
749 if (m_pipeout != NULL)
750 {
751 QString outstr = toQString(textarray[0]->data());
752 if (!outstr.isEmpty())
753 {
754 fprintf(m_pipeout, "%s\n", (const char*)outstr);
755 fflush(m_pipeout);
756 }
757 else if (m_pauseAfterEachPara)
758 {
759 m_isPaused = true;
760 timer->stop();
761 }
762 // write(m_pipeout, (const char*)outstr, outstr.length());
763 // write(m_pipeout, "\n", 1);
764 // fputc(10, m_pipeout);
765 }
766#endif
591 CDrawBuffer* buff = textarray[0]; 767 CDrawBuffer* buff = textarray[0];
592 for (int i = 1; i <= numlines; i++) 768 for (int i = 1; i <= numlines; i++)
593 { 769 {
@@ -609,12 +785,29 @@ void QTReader::doscroll()
609 } 785 }
610 locnarray[numlines] = locate(); 786 locnarray[numlines] = locate();
611 int ch = getline(textarray[numlines]); 787 int ch = getline(textarray[numlines]);
612 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); 788 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border);
613 mylastpos = locate(); 789 mylastpos = locate();
614 if (!ch) 790 if (!ch)
615 { 791 {
616 m_autoScroll = false; 792 m_autoScroll = false;
793#ifdef _SCROLLPIPE
794 for (int i = 0; i < numlines; i++)
795 {
796 if (m_pipeout != NULL)
797 {
798 QString outstr = toQString(textarray[i]->data());
799 if (!outstr.isEmpty())
800 {
801 fprintf(m_pipeout, "%s\n", (const char*)outstr);
802 fflush(m_pipeout);
803 }
804 }
805 }
806#endif
617 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 807 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
808#ifdef USEQPE
809 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
810#endif
618 } 811 }
619 emit OnRedraw(); 812 emit OnRedraw();
620 } 813 }
@@ -639,68 +832,83 @@ void QTReader::drawFonts( QPainter *p )
639{ 832{
640 if (bDoUpdates) 833 if (bDoUpdates)
641 { 834 {
642 qDebug("How refreshing..."); 835 //qDebug("How refreshing...");
643 if (buffdoc.empty()) return; 836 if (buffdoc.empty()) return;
644 setfont(); 837 setfont();
645 if (m_lastwidth != width()) 838 if (m_lastwidth != width())
646 { 839 {
647 qDebug("Not Optimised %d", m_lastwidth); 840 // qDebug("Not Optimised %d", m_lastwidth);
648 m_lastwidth = width(); 841 m_lastwidth = width();
649 m_lastheight = height(); 842 m_lastheight = height();
843 buffdoc.setwidth(m_lastwidth-2*m_border);
650 locate(pagelocate()); 844 locate(pagelocate());
651 qDebug("Not Optimised %d", m_lastwidth); 845 // qDebug("Not Optimised %d", m_lastwidth);
652 } 846 }
653 else 847 else
654 { 848 {
655 if (m_lastheight > height()) 849 int newht = height();
850 if (m_lastheight > newht)
656 { 851 {
657 qDebug("Optimised < %d", numlines); 852 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
658 int ypos = 0; 853 int ypos = 0;
659 for (int i = 0; i < numlines; i++) 854 for (int i = 0; i < numlines; i++)
660 { 855 {
661 if ((ypos += textarray[i]->lineSpacing()) > height()) 856 if ((ypos += textarray[i]->lineSpacing()) > newht)
662 { 857 {
663 numlines = i; 858 numlines = i;
664 jumpto(locnarray[i+1]); 859 jumpto(mylastpos = locnarray[i+1]);
665 break; 860 break;
666 } 861 }
667 } 862 }
668 qDebug("Optimised < %d", numlines); 863 // qDebug("Optimised < %d", numlines);
669 m_lastheight = height(); 864 m_lastheight = newht;
670 } 865 }
671 else if (m_lastheight < height()) 866 else if (m_lastheight < newht)
672 { 867 {
673 qDebug("Optimised > %d", numlines); 868 // qDebug("Optimised > %d", numlines);
674 int ypos = 0; 869 int ypos = 0;
675 for (int i = 0; i <= numlines; i++) 870 for (int i = 0; i <= numlines; i++)
676 { 871 {
677 ypos += textarray[i]->lineSpacing(); 872 ypos += textarray[i]->lineSpacing();
678 } 873 }
679 fillbuffer(numlines+1, ypos); 874 fillbuffer(numlines+1, ypos, newht);
680 qDebug("Optimised > %d", numlines); 875 // qDebug("Optimised > %d", numlines);
681 m_lastheight = height();
682 } 876 }
683 if (numlines > 0) 877 if (numlines > 0)
684 { 878 {
685 int ypos = textarray[0]->ascent(); 879 int ypos = textarray[0]->ascent();
686 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); 880 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border);
881 // int last = (m_showlast) ? numlines : numlines-1;
882 // for (int i = 1; i <= last; i++)
687 for (int i = 1; i < numlines; i++) 883 for (int i = 1; i < numlines; i++)
688 { 884 {
689 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; 885 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
690 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 886 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
691 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 887 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
692 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); 888 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border);
693 } 889 }
694// mylastpos = locate(); 890// mylastpos = locate();
695 } 891 }
696 } 892 }
697 m_scrolldy1 = m_scrolldy2 = 0; 893
894 m_scrolldy1 = m_scrolldy2 = m_scrollpart;
895 if (m_border > 5 && !buffdoc.empty())
896 {
897 p->fillRect(width()-2, 0, 2, height(), cyan);
898 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
899 int mid = (height()*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
900 p->fillRect(width()-2, mid-5, 2, 10, yellow);
901 p->fillRect(width()-2, (height()*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*height()+sectionsize/2)/sectionsize, magenta);
902 }
903
698 emit OnRedraw(); 904 emit OnRedraw();
699 } 905 }
906/*
700 else 907 else
701 { 908 {
702 qDebug("Not so refreshing..."); 909 qDebug("Not so refreshing...");
703 } 910 }
911*/
704} 912}
705 913
706QString QTReader::firstword() 914QString QTReader::firstword()
@@ -742,6 +950,7 @@ bool QTReader::ChangeFont(int tgt)
742 950
743void QTReader::init() 951void QTReader::init()
744{ 952{
953// m_showlast = true;
745 // setCaption( "Qt Draw Demo Application" ); 954 // setCaption( "Qt Draw Demo Application" );
746 955
747 buffdoc.unsuspend(); 956 buffdoc.unsuspend();
@@ -771,6 +980,18 @@ void QTReader::init()
771// 980//
772QTReader::~QTReader() 981QTReader::~QTReader()
773{ 982{
983#ifdef USEQPE
984 if (m_autoScroll)
985 {
986 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
987 }
988#endif
989#ifdef _SCROLLPIPE
990 if (m_pipeout != NULL)
991 {
992 fclose(m_pipeout);
993 }
994#endif
774} 995}
775 996
776// 997//
@@ -816,7 +1037,7 @@ void QTReader::paintEvent( QPaintEvent * )
816/* 1037/*
817void QTReader::resizeEvent( QResizeEvent * ) 1038void QTReader::resizeEvent( QResizeEvent * )
818{ 1039{
819 // qDebug("resize:(%u,%u)", width(), height()); 1040// // qDebug("resize:(%u,%u)", width(), height());
820 // bgroup->move( width()-bgroup->width(), 0 ); 1041 // bgroup->move( width()-bgroup->width(), 0 );
821} 1042}
822*/ 1043*/
@@ -841,11 +1062,11 @@ bool QTReader::locate(unsigned long n) {
841 //printf("Locate\n"); 1062 //printf("Locate\n");
842 buffdoc.unsuspend(); 1063 buffdoc.unsuspend();
843 buffdoc.locate(n); 1064 buffdoc.locate(n);
844 // qDebug("&buffdoc.located"); 1065// // qDebug("&buffdoc.located");
845 fillbuffer(); 1066 fillbuffer();
846 // qDebug("&Buffer filled"); 1067// // qDebug("&Buffer filled");
847 update(); 1068 update();
848 // qDebug("&Located"); 1069// // qDebug("&Located");
849 return true; 1070 return true;
850} 1071}
851 1072
@@ -856,18 +1077,22 @@ unsigned int QTReader::screenlines()
856 return (height()-2)/(m_linespacing); 1077 return (height()-2)/(m_linespacing);
857}; 1078};
858 1079
859bool QTReader::fillbuffer(int reuse, int ht) 1080bool QTReader::fillbuffer(int reuse, int ht, int newht)
860{ 1081{
861 buffdoc.unsuspend(); 1082 buffdoc.unsuspend();
862 if (buffdoc.empty()) return false; 1083 if (buffdoc.empty()) return false;
863 m_scrolldy1 = m_scrolldy2 = 0; 1084 if (newht < 0)
1085 m_lastheight = height();
1086 else
1087 m_lastheight = newht;
864 int ch; 1088 int ch;
865 bool ret = false; 1089 bool ret = false;
866 unsigned int oldpagepos = locnarray[reuse]; 1090 unsigned int oldpagepos = locnarray[reuse];
867 int ypos = ht; 1091 int lastypos = ht, ypos = ht;
868 numlines = reuse; 1092 numlines = reuse;
869 while (ypos < height() || numlines < 2) 1093 while (ypos < m_lastheight || numlines < 2)
870 { 1094 {
1095 lastypos = ypos;
871 if (textarray[numlines] == NULL) 1096 if (textarray[numlines] == NULL)
872 { 1097 {
873 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1098 textarray[numlines] = new CDrawBuffer(&m_fontControl);
@@ -894,18 +1119,19 @@ bool QTReader::fillbuffer(int reuse, int ht)
894 1119
895 --numlines; 1120 --numlines;
896 mylastpos = locate(); 1121 mylastpos = locate();
1122 m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos;
897 1123
898 return true; 1124 return true;
899} 1125}
900 1126
901
902void QTReader::dopagedn() 1127void QTReader::dopagedn()
903{ 1128{
1129// qDebug("HEIGHT(2):%d", m_lastheight);
904 buffdoc.unsuspend(); 1130 buffdoc.unsuspend();
905 int skip = 0, ypos = 0; 1131 int skip = 0, ypos = 0;
906 if (locate() != mylastpos) 1132 if (locate() != mylastpos)
907 { 1133 {
908 //qDebug("Jumping to %u", mylastpos); 1134 ////qDebug("Jumping to %u", mylastpos);
909 jumpto(mylastpos); 1135 jumpto(mylastpos);
910 } 1136 }
911 CDrawBuffer* reusebuffer = textarray[numlines]; 1137 CDrawBuffer* reusebuffer = textarray[numlines];
@@ -938,20 +1164,31 @@ void QTReader::dopageup()
938 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); 1164 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
939} 1165}
940 1166
1167bool QTReader::synch(size_t start, size_t end)
1168{
1169 jumpto(start);
1170 while (start++ < end)
1171 {
1172 tchar ch = getch();
1173 if (ch == 10) return true;
1174 if (ch == UEOF) return false;
1175 }
1176 return false;
1177}
1178
941void QTReader::dopageup(unsigned int target) 1179void QTReader::dopageup(unsigned int target)
942{ 1180{
943 buffdoc.unsuspend(); 1181 buffdoc.unsuspend();
944 CBufferFace<CDrawBuffer*> buff; 1182 CBufferFace<CDrawBuffer*> buff;
945 CBufferFace<size_t> loc; 1183 CBufferFace<size_t> loc;
946 1184
947 size_t delta, guess = 2048; 1185 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0;
948 bool ch = true; 1186 bool ch = true;
949 int nbfl, ypos = 0; 1187 int nbfl, ypos = 0;
950 1188 if (guess < 128) guess = 128;
951 while (1) 1189 while (1)
952 { 1190 {
953 ch = true; 1191 ch = true;
954 nbfl = 0;
955 if (target < guess) 1192 if (target < guess)
956 { 1193 {
957 delta = 0; // 0 is a flag to say don't guess any more 1194 delta = 0; // 0 is a flag to say don't guess any more
@@ -965,22 +1202,24 @@ void QTReader::dopageup(unsigned int target)
965 else 1202 else
966 { 1203 {
967 delta = guess; 1204 delta = guess;
968 1205 if (!synch(target-delta, target-lastdelta))
969 jumpto(target - delta);
970
971 buff[0] = new CDrawBuffer(&m_fontControl);
972
973 do
974 { 1206 {
975 1207 lastdelta = delta;
976 if (!getline(buff[0])) break; 1208 if (guess < 4000)
977 1209 {
978 if (locate() > target) break; 1210 guess <<= 1;
1211 continue;
1212 }
1213 else
1214 {
1215 jumpto(target-delta);
1216 }
979 } 1217 }
980 while (!buffdoc.iseol());
981 } 1218 }
982 1219
1220 nbfl = 0;
983 ypos = 0; 1221 ypos = 0;
1222
984 while (locate() < target) 1223 while (locate() < target)
985 { 1224 {
986 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 1225 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
@@ -990,7 +1229,7 @@ void QTReader::dopageup(unsigned int target)
990 nbfl++; 1229 nbfl++;
991 if (!ch) break; 1230 if (!ch) break;
992 } 1231 }
993 if (ypos < height() && (delta != 0)) 1232 if (guess < 4000 && ypos < height() && (delta != 0))
994 { 1233 {
995 for (int i = 0; i < nbfl; i++) 1234 for (int i = 0; i < nbfl; i++)
996 { 1235 {
@@ -1009,6 +1248,7 @@ void QTReader::dopageup(unsigned int target)
1009 int ch = getline(buff[nbfl]); 1248 int ch = getline(buff[nbfl]);
1010 nbfl++; 1249 nbfl++;
1011 } 1250 }
1251/*
1012 ypos = 0; 1252 ypos = 0;
1013 numlines = 0; 1253 numlines = 0;
1014 while (ypos < height() && numlines <= nbfl-1) 1254 while (ypos < height() && numlines <= nbfl-1)
@@ -1017,6 +1257,18 @@ void QTReader::dopageup(unsigned int target)
1017 numlines++; 1257 numlines++;
1018 } 1258 }
1019 --numlines; 1259 --numlines;
1260*/
1261
1262 ypos = 0;
1263 numlines = 0;
1264 while (ypos < height() && numlines+2 <= nbfl)
1265 {
1266 ypos += buff[nbfl - numlines - 2]->lineSpacing();
1267 numlines++;
1268 }
1269 if (numlines > 0) --numlines;
1270 if (numlines == 0 && nbfl > 1) numlines = 1;
1271
1020 int offset = nbfl-1; 1272 int offset = nbfl-1;
1021 offset -= numlines; 1273 offset -= numlines;
1022 ypos = 0; 1274 ypos = 0;
@@ -1027,7 +1279,11 @@ void QTReader::dopageup(unsigned int target)
1027 locnarray[i] = loc[offset + i]; 1279 locnarray[i] = loc[offset + i];
1028 ypos += textarray[i]->lineSpacing(); 1280 ypos += textarray[i]->lineSpacing();
1029 } 1281 }
1282#ifdef _WINDOWS
1283 for (i = 0; i < nbfl - numlines - 1; i++)
1284#else
1030 for (int i = 0; i < nbfl - numlines - 1; i++) 1285 for (int i = 0; i < nbfl - numlines - 1; i++)
1286#endif
1031 { 1287 {
1032 delete buff[i]; 1288 delete buff[i];
1033 } 1289 }
@@ -1057,21 +1313,22 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
1057 { 1313 {
1058 lcn = m_lastposn; 1314 lcn = m_lastposn;
1059 } 1315 }
1060 m_lastfile = newfile;
1061 // QMessageBox::information(0, "Opening...", newfile); 1316 // QMessageBox::information(0, "Opening...", newfile);
1062 m_lastwidth = width(); 1317 m_lastwidth = width();
1063 m_lastheight = height(); 1318 m_lastheight = height();
1064 if (buffdoc.openfile(this,newfile) == 0) 1319 if (buffdoc.openfile(this,newfile) == 0)
1065 { 1320 {
1321 m_lastfile = newfile;
1322 buffdoc.setwidth(m_lastwidth-2*m_border);
1066 bRC = true; 1323 bRC = true;
1067 buffdoc.setContinuous(m_continuousDocument); 1324 buffdoc.setContinuous(m_continuousDocument);
1068 // qDebug("buffdoc.openfile done"); 1325// // qDebug("buffdoc.openfile done");
1069 locate(lcn); 1326 locate(lcn);
1070 // qDebug("buffdoc.locate done"); 1327// // qDebug("buffdoc.locate done");
1071 } 1328 }
1072 setfilter(getfilter()); 1329 setfilter(getfilter());
1073 update(); 1330 update();
1074 // qDebug("Updated"); 1331// // qDebug("Updated");
1075 return bRC; 1332 return bRC;
1076} 1333}
1077 1334
@@ -1089,7 +1346,11 @@ void QTReader::lineDown()
1089 } 1346 }
1090 } 1347 }
1091 offset = numlines - offset; 1348 offset = numlines - offset;
1349#ifdef _WINDOWS
1350 for (i = offset; i <= numlines; i++)
1351#else
1092 for (int i = offset; i <= numlines; i++) 1352 for (int i = offset; i <= numlines; i++)
1353#endif
1093 { 1354 {
1094 CDrawBuffer* buff = textarray[i-offset]; 1355 CDrawBuffer* buff = textarray[i-offset];
1095 textarray[i-offset] = textarray[i]; 1356 textarray[i-offset] = textarray[i];
@@ -1259,7 +1520,11 @@ void QTReader::lineUp()
1259 locnarray[0] = loc; 1520 locnarray[0] = loc;
1260 int start = numlines; 1521 int start = numlines;
1261 int ypos = 0; 1522 int ypos = 0;
1523#ifdef _WINDOWS
1524 for (i = 0; i <= numlines; i++)
1525#else
1262 for (int i = 0; i <= numlines; i++) 1526 for (int i = 0; i <= numlines; i++)
1527#endif
1263 { 1528 {
1264 ypos += textarray[i]->lineSpacing(); 1529 ypos += textarray[i]->lineSpacing();
1265 if (ypos > height()) 1530 if (ypos > height())
@@ -1296,32 +1561,3 @@ MarkupType QTReader::PreferredMarkup()
1296 } 1561 }
1297 return m; 1562 return m;
1298} 1563}
1299
1300void QTReader::setstate(const statedata& sd)
1301{
1302 bstripcr = sd.bstripcr;
1303 btextfmt = sd.btextfmt;
1304 bautofmt = sd.bautofmt;
1305 bstriphtml = sd.bstriphtml;
1306 bpeanut = sd.bpeanut;
1307 bdehyphen = sd.bdehyphen;
1308 bonespace = sd.bonespace;
1309 bunindent = sd.bunindent;
1310 brepara = sd.brepara;
1311 bdblspce = sd.bdblspce;
1312 m_bpagemode = sd.m_bpagemode;
1313 m_navkeys = sd.m_navkeys;
1314 m_bMonoSpaced = sd.m_bMonoSpaced;
1315 bremap = sd.bremap;
1316 bmakebold = sd.bmakebold;
1317 m_continuousDocument = sd.Continuous;
1318#ifdef REPALM
1319 brepalm = sd.brepalm;
1320#endif
1321 bindenter = sd.bindenter;
1322 m_encd = sd.m_charpc;
1323 m_fontname = sd.m_fontname;
1324 setContinuous(sd.Continuous);
1325 ChangeFont(sd.m_textsize);
1326 refresh();
1327}