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.cpp400
1 files changed, 309 insertions, 91 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 7cf08e5..3995ee7 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -22,6 +22,7 @@
22#include <qfontdatabase.h> 22#include <qfontdatabase.h>
23#include <qpe/global.h> 23#include <qpe/global.h>
24#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include "StateData.h"
25 26
26#ifdef _UNICODE 27#ifdef _UNICODE
27const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 28const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
@@ -35,7 +36,7 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
35//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 36//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
36//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}; 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};
37 38
38QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 39QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
39 QWidget(parent, name, f), 40 QWidget(parent, name, f),
40 m_delay(100), 41 m_delay(100),
41 m_scrolldy1(0), 42 m_scrolldy1(0),
@@ -48,7 +49,9 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
48 m_fm(NULL), 49 m_fm(NULL),
49 mouseUpOn(true), 50 mouseUpOn(true),
50 m_twotouch(true), 51 m_twotouch(true),
51 m_touchone(true) 52 m_touchone(true),
53 bDoUpdates(false),
54 m_navkeys(true)
52{ 55{
53 m_overlap = 1; 56 m_overlap = 1;
54// init(); 57// init();
@@ -81,9 +84,47 @@ long QTReader::real_delay()
81 84
82void QTReader::mousePressEvent( QMouseEvent* _e ) 85void QTReader::mousePressEvent( QMouseEvent* _e )
83{ 86{
87 buffdoc.unsuspend();
84 if (_e->button() == RightButton) 88 if (_e->button() == RightButton)
85 { 89 {
86 mouseUpOn = false; 90 mouseUpOn = false;
91 if (buffdoc.hasnavigation())
92 {
93 if (_e->y() > (2*height())/3)
94 {
95 goDown();
96 }
97 else if (_e->y() < height()/3)
98 {
99 goUp();
100 }
101 else
102 {
103 if (_e->x() < width()/3)
104 {
105 size_t target = pagelocate();
106 if (buffdoc.back(target))
107 {
108 locate(target);
109 }
110 }
111 else if (_e->x() > (2*width())/3)
112 {
113 size_t target = pagelocate();
114 if (buffdoc.forward(target))
115 {
116 locate(target);
117 }
118 }
119 else
120 {
121 buffdoc.saveposn(pagelocate());
122 locate(buffdoc.getHome());
123 }
124 }
125 }
126 else
127 {
87 if (_e->y() > height()/2) 128 if (_e->y() > height()/2)
88 { 129 {
89 goDown(); 130 goDown();
@@ -94,8 +135,9 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
94 } 135 }
95 } 136 }
96} 137}
138}
97 139
98bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) 140linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
99{ 141{
100 int lineno = 0; 142 int lineno = 0;
101 int ht = textarray[0]->lineSpacing(); 143 int ht = textarray[0]->lineSpacing();
@@ -112,10 +154,11 @@ bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t
112 { 154 {
113 int i; 155 int i;
114 CDrawBuffer* t = textarray[lineno]; 156 CDrawBuffer* t = textarray[lineno];
115 for (i = t->length(); t->width(i) > x; i--); 157 x = x - t->offset(width());
158 for (i = t->length(); i >= 0 && t->width(i) > x; i--);
116 offset = i; 159 offset = i;
117 } 160 }
118 return textarray[lineno]->isLink(offset, tgt); 161 return textarray[lineno]->getLinkType(offset, tgt);
119} 162}
120 163
121void QTReader::setTwoTouch(bool _b) 164void QTReader::setTwoTouch(bool _b)
@@ -124,8 +167,15 @@ void QTReader::setTwoTouch(bool _b)
124 m_twotouch = m_touchone = _b; 167 m_twotouch = m_touchone = _b;
125} 168}
126 169
170void QTReader::setContinuous(bool _b)
171{
172 buffdoc.unsuspend();
173 buffdoc.setContinuous(m_continuousDocument = _b);
174}
175
127void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 176void QTReader::mouseReleaseEvent( QMouseEvent* _e )
128{ 177{
178 buffdoc.unsuspend();
129 if (_e->button() == LeftButton) 179 if (_e->button() == LeftButton)
130 { 180 {
131 if (mouseUpOn) 181 if (mouseUpOn)
@@ -141,10 +191,14 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
141 ht += textarray[++lineno]->lineSpacing(); 191 ht += textarray[++lineno]->lineSpacing();
142 } 192 }
143 size_t startpos, startoffset, tgt; 193 size_t startpos, startoffset, tgt;
144 if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) 194 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
195 {
196 case eLink:
145 { 197 {
198 size_t saveposn = pagelocate();
146 if (buffdoc.hyperlink(tgt)) 199 if (buffdoc.hyperlink(tgt))
147 { 200 {
201 buffdoc.saveposn(saveposn);
148 fillbuffer(); 202 fillbuffer();
149 update(); 203 update();
150 } 204 }
@@ -154,6 +208,27 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
154 } 208 }
155 return; 209 return;
156 } 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 {
222 locate(pagelocate());
223 }
224 return;
225 }
226 case eNone:
227 break;
228 default:
229 qDebug("Unknown linktype");
230 return;
231 }
157 if (m_twotouch) 232 if (m_twotouch)
158 { 233 {
159 if (m_touchone) 234 if (m_touchone)
@@ -212,11 +287,12 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
212 { 287 {
213 CDrawBuffer* t = textarray[lineno]; 288 CDrawBuffer* t = textarray[lineno];
214 int first = 0; 289 int first = 0;
290 int tgt = _e->x() - t->offset(width());
215 while (1) 291 while (1)
216 { 292 {
217 int i = first+1; 293 int i = first+1;
218 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 294 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
219 if (t->width(i) > _e->x()) 295 if (t->width(i) > tgt)
220 { 296 {
221 wrd = toQString(t->data()+first, i - first); 297 wrd = toQString(t->data()+first, i - first);
222 break; 298 break;
@@ -282,8 +358,77 @@ void QTReader::goUp()
282 } 358 }
283} 359}
284 360
361void QTReader::NavUp()
362{
363 buffdoc.unsuspend();
364 if (buffdoc.hasnavigation())
365 {
366/*
367 size_t target = pagelocate();
368 if (buffdoc.back(target))
369 {
370 locate(target);
371 }
372*/
373 locate(buffdoc.startSection());
374 }
375 else
376 {
377 goUp();
378 }
379}
380
381void QTReader::NavDown()
382{
383 buffdoc.unsuspend();
384 if (buffdoc.hasnavigation())
385 {
386/*
387 size_t target = pagelocate();
388 if (buffdoc.forward(target))
389 {
390 locate(target);
391 }
392*/
393 dopageup(buffdoc.endSection());
394 }
395 else
396 {
397 goDown();
398 }
399}
400
401void QTReader::zoomin()
402{
403 if (m_fontControl.increasesize())
404 {
405 bool sc = m_autoScroll;
406 setfont();
407 m_autoScroll = false;
408 locate(pagelocate());
409 update();
410 m_autoScroll = sc;
411 if (m_autoScroll) autoscroll();
412 }
413}
414
415void QTReader::zoomout()
416{
417 if (m_fontControl.decreasesize())
418 {
419 bool sc = m_autoScroll;
420 m_autoScroll = false;
421 setfont();
422 locate(pagelocate());
423 update();
424 m_autoScroll = sc;
425 if (m_autoScroll) autoscroll();
426 }
427}
428
285void QTReader::keyPressEvent(QKeyEvent* e) 429void QTReader::keyPressEvent(QKeyEvent* e)
286{ 430{
431 buffdoc.unsuspend();
287 switch (e->key()) 432 switch (e->key())
288 { 433 {
289 case Key_Down: 434 case Key_Down:
@@ -360,31 +505,29 @@ void QTReader::keyPressEvent(QKeyEvent* e)
360 case Key_Right: 505 case Key_Right:
361 { 506 {
362 e->accept(); 507 e->accept();
363 if (m_fontControl.increasesize()) 508 if (m_navkeys && buffdoc.hasnavigation())
364 { 509 {
365 bool sc = m_autoScroll; 510 size_t target = pagelocate();
366 setfont(); 511 if (buffdoc.forward(target))
367 m_autoScroll = false; 512 {
368 locate(pagelocate()); 513 locate(target);
369 update();
370 m_autoScroll = sc;
371 if (m_autoScroll) autoscroll();
372 } 514 }
373 } 515 }
516 else zoomin();
517 }
374 break; 518 break;
375 case Key_Left: 519 case Key_Left:
376 { 520 {
377 e->accept(); 521 e->accept();
378 if (m_fontControl.decreasesize()) 522 if (m_navkeys && buffdoc.hasnavigation())
379 { 523 {
380 bool sc = m_autoScroll; 524 size_t target = pagelocate();
381 m_autoScroll = false; 525 if (buffdoc.back(target))
382 setfont(); 526 {
383 locate(pagelocate()); 527 locate(target);
384 update(); 528 }
385 m_autoScroll = sc;
386 if (m_autoScroll) autoscroll();
387 } 529 }
530 else zoomout();
388 } 531 }
389 break; 532 break;
390 case Key_Space: 533 case Key_Space:
@@ -409,6 +552,8 @@ void QTReader::setautoscroll(bool _sc)
409 } 552 }
410 else 553 else
411 { 554 {
555 CDrawBuffer* reusebuffer = textarray[numlines];
556 if (reusebuffer == NULL || reusebuffer->eof()) return;
412 m_autoScroll = true; 557 m_autoScroll = true;
413 autoscroll(); 558 autoscroll();
414 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 559 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
@@ -417,6 +562,7 @@ void QTReader::setautoscroll(bool _sc)
417 562
418bool QTReader::getline(CDrawBuffer *buff) 563bool QTReader::getline(CDrawBuffer *buff)
419{ 564{
565 buffdoc.unsuspend();
420 if (m_bMonoSpaced) 566 if (m_bMonoSpaced)
421 { 567 {
422 return buffdoc.getline(buff ,width(), m_charWidth); 568 return buffdoc.getline(buff ,width(), m_charWidth);
@@ -459,17 +605,16 @@ void QTReader::doscroll()
459 605
460 if (textarray[numlines] == NULL) 606 if (textarray[numlines] == NULL)
461 { 607 {
462 textarray[numlines] = new CDrawBuffer; 608 textarray[numlines] = new CDrawBuffer(&m_fontControl);
463 } 609 }
464 locnarray[numlines] = locate(); 610 locnarray[numlines] = locate();
465 int ch = getline(textarray[numlines]); 611 int ch = getline(textarray[numlines]);
466 textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); 612 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
467 mylastpos = locate(); 613 mylastpos = locate();
468 if (!ch) 614 if (!ch)
469 { 615 {
470 m_autoScroll = false; 616 m_autoScroll = false;
471 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 617 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
472 emit OnRedraw();
473 } 618 }
474 emit OnRedraw(); 619 emit OnRedraw();
475 } 620 }
@@ -492,72 +637,59 @@ void QTReader::setfont()
492 637
493void QTReader::drawFonts( QPainter *p ) 638void QTReader::drawFonts( QPainter *p )
494{ 639{
640 if (bDoUpdates)
641 {
642 qDebug("How refreshing...");
643 if (buffdoc.empty()) return;
495 setfont(); 644 setfont();
496 if (m_lastwidth != width() || m_lastheight != height()) 645 if (m_lastwidth != width())
497 { 646 {
647 qDebug("Not Optimised %d", m_lastwidth);
498 m_lastwidth = width(); 648 m_lastwidth = width();
499 m_lastheight = height(); 649 m_lastheight = height();
500 locate(pagelocate()); 650 locate(pagelocate());
651 qDebug("Not Optimised %d", m_lastwidth);
501 } 652 }
502 else 653 else
503 { 654 {
504 655 if (m_lastheight > height())
505/*
506 int sl = screenlines();
507 if (sl < numlines)
508 { 656 {
509 //qDebug("df:<%u,%u>",sl,numlines); 657 qDebug("Optimised < %d", numlines);
510 658 int ypos = 0;
511 size_t newpos = locnarray[sl]; 659 for (int i = 0; i < numlines; i++)
512 CDrawBuffer** nta = new CDrawBuffer*[sl]; 660 {
513 size_t* nla = new size_t[sl]; 661 if ((ypos += textarray[i]->lineSpacing()) > height())
514 for (int i = 0; i < sl; i++)
515 { 662 {
516 nta[i] = textarray[i]; 663 numlines = i;
517 nla[i] = locnarray[i]; 664 jumpto(locnarray[i+1]);
665 break;
518 } 666 }
519 for (int i = sl; i < numlines; i++) delete textarray[i];
520 delete [] locnarray;
521 delete [] textarray;
522 textarray = nta;
523 locnarray = nla;
524 numlines = sl;
525 jumpto(mylastpos = newpos);
526 } 667 }
527 if (sl > numlines) 668 qDebug("Optimised < %d", numlines);
528 { 669 m_lastheight = height();
529 //qDebug("df:<%u,%u>",sl,numlines);
530 CDrawBuffer** nta = new CDrawBuffer*[sl];
531 size_t* nla = new size_t[sl];
532 for (int i = 0; i < numlines; i++)
533 {
534 nta[i] = textarray[i];
535 nla[i] = locnarray[i];
536 } 670 }
537 if (locate() != mylastpos) jumpto(mylastpos); 671 else if (m_lastheight < height())
538 for (int i = numlines; i < sl; i++)
539 { 672 {
540 nta[i] = new CDrawBuffer(&m_fontControl); 673 qDebug("Optimised > %d", numlines);
541 nla[i] = locate(); 674 int ypos = 0;
542 getline(nta[i]); 675 for (int i = 0; i <= numlines; i++)
676 {
677 ypos += textarray[i]->lineSpacing();
543 } 678 }
544 mylastpos = locate(); 679 fillbuffer(numlines+1, ypos);
545 delete [] locnarray; 680 qDebug("Optimised > %d", numlines);
546 delete [] textarray; 681 m_lastheight = height();
547 textarray = nta;
548 locnarray = nla;
549 numlines = sl;
550 } 682 }
551*/
552 if (numlines > 0) 683 if (numlines > 0)
553 { 684 {
554 int ypos = textarray[0]->ascent(); 685 int ypos = textarray[0]->ascent();
555 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); 686 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
556 for (int i = 1; i < numlines; i++) 687 for (int i = 1; i < numlines; i++)
557 { 688 {
558 ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; 689 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
690 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
691 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
559 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); 692 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
560
561 } 693 }
562// mylastpos = locate(); 694// mylastpos = locate();
563 } 695 }
@@ -565,6 +697,11 @@ void QTReader::drawFonts( QPainter *p )
565 m_scrolldy1 = m_scrolldy2 = 0; 697 m_scrolldy1 = m_scrolldy2 = 0;
566 emit OnRedraw(); 698 emit OnRedraw();
567} 699}
700 else
701 {
702 qDebug("Not so refreshing...");
703 }
704}
568 705
569QString QTReader::firstword() 706QString QTReader::firstword()
570{ 707{
@@ -607,6 +744,7 @@ void QTReader::init()
607{ 744{
608 // setCaption( "Qt Draw Demo Application" ); 745 // setCaption( "Qt Draw Demo Application" );
609 746
747 buffdoc.unsuspend();
610 setBackgroundColor( white ); 748 setBackgroundColor( white );
611// QPainter p(this); 749// QPainter p(this);
612// p.setBackgroundMode( Qt::OpaqueMode ); 750// p.setBackgroundMode( Qt::OpaqueMode );
@@ -618,14 +756,14 @@ void QTReader::init()
618 timer = new QTimer(this); 756 timer = new QTimer(this);
619 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 757 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
620// QMessageBox::information(this, "init", m_lastfile, 1); 758// QMessageBox::information(this, "init", m_lastfile, 1);
621 m_lastwidth = width();
622 m_lastheight = height();
623 setfont(); 759 setfont();
760/*
624 if (!m_lastfile.isEmpty()) 761 if (!m_lastfile.isEmpty())
625 { 762 {
626 m_string = DocLnk(m_lastfile).name(); 763 m_string = DocLnk(m_lastfile).name();
627 load_file(m_lastfile); 764 load_file(m_lastfile);
628 } 765 }
766*/
629} 767}
630 768
631// 769//
@@ -701,6 +839,7 @@ int main( int argc, tchar **argv )
701 839
702bool QTReader::locate(unsigned long n) { 840bool QTReader::locate(unsigned long n) {
703 //printf("Locate\n"); 841 //printf("Locate\n");
842 buffdoc.unsuspend();
704 buffdoc.locate(n); 843 buffdoc.locate(n);
705 // qDebug("&buffdoc.located"); 844 // qDebug("&buffdoc.located");
706 fillbuffer(); 845 fillbuffer();
@@ -719,6 +858,7 @@ unsigned int QTReader::screenlines()
719 858
720bool QTReader::fillbuffer(int reuse, int ht) 859bool QTReader::fillbuffer(int reuse, int ht)
721{ 860{
861 buffdoc.unsuspend();
722 if (buffdoc.empty()) return false; 862 if (buffdoc.empty()) return false;
723 m_scrolldy1 = m_scrolldy2 = 0; 863 m_scrolldy1 = m_scrolldy2 = 0;
724 int ch; 864 int ch;
@@ -726,7 +866,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
726 unsigned int oldpagepos = locnarray[reuse]; 866 unsigned int oldpagepos = locnarray[reuse];
727 int ypos = ht; 867 int ypos = ht;
728 numlines = reuse; 868 numlines = reuse;
729 while (ypos < height()) 869 while (ypos < height() || numlines < 2)
730 { 870 {
731 if (textarray[numlines] == NULL) 871 if (textarray[numlines] == NULL)
732 { 872 {
@@ -738,7 +878,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
738 numlines++; 878 numlines++;
739 if (!ch) 879 if (!ch)
740 { 880 {
741 if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/) 881 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
742 { 882 {
743 locate(oldpagepos); 883 locate(oldpagepos);
744 return false; 884 return false;
@@ -761,6 +901,7 @@ bool QTReader::fillbuffer(int reuse, int ht)
761 901
762void QTReader::dopagedn() 902void QTReader::dopagedn()
763{ 903{
904 buffdoc.unsuspend();
764 int skip = 0, ypos = 0; 905 int skip = 0, ypos = 0;
765 if (locate() != mylastpos) 906 if (locate() != mylastpos)
766 { 907 {
@@ -768,6 +909,7 @@ void QTReader::dopagedn()
768 jumpto(mylastpos); 909 jumpto(mylastpos);
769 } 910 }
770 CDrawBuffer* reusebuffer = textarray[numlines]; 911 CDrawBuffer* reusebuffer = textarray[numlines];
912 if (reusebuffer != NULL && reusebuffer->eof()) return;
771 if (reusebuffer != NULL) 913 if (reusebuffer != NULL)
772 { 914 {
773 for (int i = 0; i <= m_overlap; i++) 915 for (int i = 0; i <= m_overlap; i++)
@@ -777,6 +919,7 @@ void QTReader::dopagedn()
777 size_t reuselocn = locnarray[offset]; 919 size_t reuselocn = locnarray[offset];
778 textarray[offset] = textarray[i]; 920 textarray[offset] = textarray[i];
779 textarray[i] = reusebuffer; 921 textarray[i] = reusebuffer;
922 // reusebuffer->empty();
780 locnarray[offset] = locnarray[i]; 923 locnarray[offset] = locnarray[i];
781 locnarray[i] = reuselocn; 924 locnarray[i] = reuselocn;
782 ypos += textarray[i]->lineSpacing(); 925 ypos += textarray[i]->lineSpacing();
@@ -791,19 +934,37 @@ void QTReader::dopagedn()
791 934
792void QTReader::dopageup() 935void QTReader::dopageup()
793{ 936{
937 buffdoc.unsuspend();
938 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
939}
940
941void QTReader::dopageup(unsigned int target)
942{
943 buffdoc.unsuspend();
794 CBufferFace<CDrawBuffer*> buff; 944 CBufferFace<CDrawBuffer*> buff;
795 CBufferFace<size_t> loc; 945 CBufferFace<size_t> loc;
796 unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
797 946
798 size_t delta; 947 size_t delta, guess = 2048;
799 if (target < 2048) 948 bool ch = true;
949 int nbfl, ypos = 0;
950
951 while (1)
800 { 952 {
801 delta = target; 953 ch = true;
802 jumpto(0); 954 nbfl = 0;
955 if (target < guess)
956 {
957 delta = 0; // 0 is a flag to say don't guess any more
958 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
959 }
960 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
961 {
962 delta = 0; // 0 is a flag to say don't guess any more
963 jumpto(buffdoc.startSection());
803 } 964 }
804 else 965 else
805 { 966 {
806 delta = 2048; 967 delta = guess;
807 968
808 jumpto(target - delta); 969 jumpto(target - delta);
809 970
@@ -814,14 +975,12 @@ void QTReader::dopageup()
814 975
815 if (!getline(buff[0])) break; 976 if (!getline(buff[0])) break;
816 977
817 if (locate() > target) continue; 978 if (locate() > target) break;
818 } 979 }
819 while (!buffdoc.iseol()); 980 while (!buffdoc.iseol());
820 } 981 }
821 int nbfl = 0;
822 982
823 bool ch = true; 983 ypos = 0;
824 int ypos = 0;
825 while (locate() < target) 984 while (locate() < target)
826 { 985 {
827 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 986 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
@@ -831,10 +990,17 @@ void QTReader::dopageup()
831 nbfl++; 990 nbfl++;
832 if (!ch) break; 991 if (!ch) break;
833 } 992 }
834 if (ypos < height()) 993 if (ypos < height() && (delta != 0))
835 { 994 {
836 locate(0); 995 for (int i = 0; i < nbfl; i++)
837 return; 996 {
997 delete buff[i];
998 buff[i] = NULL;
999 }
1000 guess <<= 1;
1001 continue;
1002 }
1003 break;
838 } 1004 }
839 if (ch) 1005 if (ch)
840 { 1006 {
@@ -845,26 +1011,36 @@ void QTReader::dopageup()
845 } 1011 }
846 ypos = 0; 1012 ypos = 0;
847 numlines = 0; 1013 numlines = 0;
848 while (ypos < height() && numlines <= nbfl-2) 1014 while (ypos < height() && numlines <= nbfl-1)
849 { 1015 {
850 ypos += buff[nbfl - numlines - 2]->lineSpacing(); 1016 ypos += buff[nbfl - numlines - 1]->lineSpacing();
851 numlines++; 1017 numlines++;
852 } 1018 }
853 --numlines; 1019 --numlines;
854 int offset = nbfl; 1020 int offset = nbfl-1;
855 offset -= numlines+1; 1021 offset -= numlines;
1022 ypos = 0;
856 for (int i = 0; i <= numlines; i++) 1023 for (int i = 0; i <= numlines; i++)
857 { 1024 {
858 delete textarray[i]; 1025 delete textarray[i];
859 textarray[i] = buff[offset+i]; 1026 textarray[i] = buff[offset+i];
860 locnarray[i] = loc[offset + i]; 1027 locnarray[i] = loc[offset + i];
1028 ypos += textarray[i]->lineSpacing();
861 } 1029 }
862 for (int i = 0; i < nbfl - numlines - 1; i++) 1030 for (int i = 0; i < nbfl - numlines - 1; i++)
863 { 1031 {
864 delete buff[i]; 1032 delete buff[i];
865 } 1033 }
866 1034
867// --numlines; 1035 while (ypos < height())
1036 {
1037 numlines++;
1038 locnarray[numlines] = locate();
1039 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
1040 if (!getline(textarray[numlines])) break;
1041 ypos += textarray[numlines]->lineSpacing();
1042 }
1043
868 mylastpos = locate(); 1044 mylastpos = locate();
869 1045
870 update(); 1046 update();
@@ -883,9 +1059,12 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
883 } 1059 }
884 m_lastfile = newfile; 1060 m_lastfile = newfile;
885 // QMessageBox::information(0, "Opening...", newfile); 1061 // QMessageBox::information(0, "Opening...", newfile);
1062 m_lastwidth = width();
1063 m_lastheight = height();
886 if (buffdoc.openfile(this,newfile) == 0) 1064 if (buffdoc.openfile(this,newfile) == 0)
887 { 1065 {
888 bRC = true; 1066 bRC = true;
1067 buffdoc.setContinuous(m_continuousDocument);
889 // qDebug("buffdoc.openfile done"); 1068 // qDebug("buffdoc.openfile done");
890 locate(lcn); 1069 locate(lcn);
891 // qDebug("buffdoc.locate done"); 1070 // qDebug("buffdoc.locate done");
@@ -1012,6 +1191,7 @@ void QTReader::lineUp()
1012*/ 1191*/
1013void QTReader::lineUp() 1192void QTReader::lineUp()
1014{ 1193{
1194 buffdoc.unsuspend();
1015 CDrawBuffer* buff = textarray[numlines]; 1195 CDrawBuffer* buff = textarray[numlines];
1016 unsigned int loc; 1196 unsigned int loc;
1017 unsigned int end = locnarray[numlines]; 1197 unsigned int end = locnarray[numlines];
@@ -1019,6 +1199,7 @@ void QTReader::lineUp()
1019 if (locate() != mylastpos) jumpto(mylastpos); 1199 if (locate() != mylastpos) jumpto(mylastpos);
1020 unsigned int target = locnarray[0]; 1200 unsigned int target = locnarray[0];
1021 if (target == 0) return; 1201 if (target == 0) return;
1202 if (!m_continuousDocument && (target == buffdoc.startSection())) return;
1022 if (buffdoc.hasrandomaccess()) 1203 if (buffdoc.hasrandomaccess())
1023 { 1204 {
1024 unsigned int delta = locate()-pagelocate(); 1205 unsigned int delta = locate()-pagelocate();
@@ -1034,6 +1215,14 @@ void QTReader::lineUp()
1034 getline(buff); 1215 getline(buff);
1035 break; 1216 break;
1036 } 1217 }
1218 else if (!m_continuousDocument && (target - delta < buffdoc.startSection()))
1219 {
1220 delta = target-buffdoc.startSection();
1221 jumpto(buffdoc.startSection());
1222 loc = locate();
1223 getline(buff);
1224 break;
1225 }
1037 jumpto(target-delta); 1226 jumpto(target-delta);
1038 do 1227 do
1039 { 1228 {
@@ -1107,3 +1296,32 @@ MarkupType QTReader::PreferredMarkup()
1107 } 1296 }
1108 return m; 1297 return m;
1109} 1298}
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}