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.cpp632
1 files changed, 353 insertions, 279 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 6335ea2..e7bfc28 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -10,2 +10,3 @@
10 10
11#include <qpainter.h>
11#include "config.h" 12#include "config.h"
@@ -13,2 +14,3 @@
13#include "QTReaderApp.h" 14#include "QTReaderApp.h"
15#include "CDrawBuffer.h"
14#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
@@ -38,12 +40,15 @@ QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
38 m_delay(100), 40 m_delay(100),
39 m_scrolldy(0), 41 m_scrolldy1(0),
42 m_scrolldy2(0),
40 m_autoScroll(false), 43 m_autoScroll(false),
41 textarray(NULL), 44 //textarray(NULL),
42 locnarray(NULL), 45 //locnarray(NULL),
43 numlines(0), 46 numlines(0),
44 m_fontname("unifont"), 47 m_fontname("unifont"),
45 m_fm(NULL) 48 m_fm(NULL),
49 mouseUpOn(true),
50 m_twotouch(true),
51 m_touchone(true)
46{ 52{
47 m_overlap = 1; 53 m_overlap = 1;
48 fontsizes = NULL;
49// init(); 54// init();
@@ -76,12 +81,125 @@ long QTReader::real_delay()
76 81
77void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 82void QTReader::mousePressEvent( QMouseEvent* _e )
78//void QTReader::mouseDoubleClickEvent( QMouseEvent* _e ) 83{
84 if (_e->button() == RightButton)
85 {
86 mouseUpOn = false;
87 if (_e->y() > height()/2)
88 {
89 goDown();
90 }
91 else
92 {
93 goUp();
94 }
95 }
96}
97
98bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
79{ 99{
80 if (textarray != NULL) 100 int lineno = 0;
101 int ht = textarray[0]->lineSpacing();
102 while ((ht < y) && (lineno < numlines))
81 { 103 {
82// printf("(%u, %u)\n", _e->x(), _e->y()); 104 ht += textarray[++lineno]->lineSpacing();
83 QString wrd = QString::null; 105 }
84 int lineno = _e->y()/m_linespacing; 106 start = locnarray[lineno];
85 if (m_bMonoSpaced) 107 if (m_bMonoSpaced)
86 { 108 {
109 offset = x/m_charWidth;
110 }
111 else
112 {
113 int i;
114 CDrawBuffer* t = textarray[lineno];
115 for (i = t->length(); t->width(i) > x; i--);
116 offset = i;
117 }
118 return textarray[lineno]->isLink(offset, tgt);
119}
120
121void QTReader::setTwoTouch(bool _b)
122{
123 setBackgroundColor( white );
124 m_twotouch = m_touchone = _b;
125}
126
127void QTReader::mouseReleaseEvent( QMouseEvent* _e )
128{
129 if (_e->button() == LeftButton)
130 {
131 if (mouseUpOn)
132 {
133 if (textarray[0] != NULL)
134 {
135 QString wrd, line;
136 // int lineno = _e->y()/m_linespacing;
137 int lineno = 0;
138 int ht = textarray[0]->lineSpacing();
139 while ((ht < _e->y()) && (lineno < numlines))
140 {
141 ht += textarray[++lineno]->lineSpacing();
142 }
143 size_t startpos, startoffset, tgt;
144 if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
145 {
146 if (buffdoc.hyperlink(tgt))
147 {
148 fillbuffer();
149 update();
150 }
151 else
152 {
153 locate(pagelocate());
154 }
155 return;
156 }
157 if (m_twotouch)
158 {
159 if (m_touchone)
160 {
161 m_touchone = false;
162 m_startpos = startpos;
163 m_startoffset = startoffset;
164 setBackgroundColor( lightGray );
165 }
166 else
167 {
168 m_touchone = true;
169 setBackgroundColor( white );
170 size_t endpos, endoffset;
171 endpos = startpos;
172 endoffset = startoffset;
173 size_t currentpos = locate();
174 if (endpos >= m_startpos)
175 {
176 jumpto(m_startpos);
177 for (int i = 0; i < m_startoffset; i++)
178 {
179 getch();
180 }
181 if (m_startpos == endpos)
182 {
183 for (int i = m_startoffset; i <= endoffset; i++)
184 {
185 wrd += QChar(getch());
186 }
187 }
188 else
189 {
190 while (buffdoc.explocate() <= endpos)
191 {
192 wrd += QChar(getch());
193 }
194 for (int i = 0; i < endoffset; i++)
195 {
196 wrd += QChar(getch());
197 }
198 }
199 jumpto(currentpos);
200 }
201 }
202 }
203 else if (m_bMonoSpaced)
204 {
87 int chno = _e->x()/m_charWidth; 205 int chno = _e->x()/m_charWidth;
@@ -94,3 +212,3 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
94 { 212 {
95 CBuffer* t = textarray[lineno]; 213 CDrawBuffer* t = textarray[lineno];
96 int first = 0; 214 int first = 0;
@@ -99,5 +217,4 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
99 int i = first+1; 217 int i = first+1;
100// while ((*t)[i] != ' ' && (*t)[i] != 0) i++;
101 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 218 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
102 if (m_fm->width(toQString(t->data()), i) > _e->x()) 219 if (t->width(i) > _e->x())
103 { 220 {
@@ -106,3 +223,2 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
106 } 223 }
107// while ((*t)[i] == ' ' && (*t)[i] != 0) i++;
108 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 224 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
@@ -114,10 +230,9 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
114 { 230 {
115 QClipboard* cb = QApplication::clipboard(); 231 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
116 cb->setText(wrd); 232 }
117 Global::statusMessage(wrd); 233 }
118 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
119 {
120 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
121 e << wrd;
122 } 234 }
235 else
236 {
237 mouseUpOn = true;
123 } 238 }
@@ -137,3 +252,3 @@ void QTReader::focusOutEvent(QFocusEvent* e)
137 timer->stop(); 252 timer->stop();
138 m_scrolldy = 0; 253 m_scrolldy1 = m_scrolldy2 = 0;
139 } 254 }
@@ -247,11 +362,7 @@ void QTReader::keyPressEvent(QKeyEvent* e)
247 e->accept(); 362 e->accept();
248 if (fontsizes[++m_textsize] == 0) 363 if (m_fontControl.increasesize())
249 {
250 m_textsize--;
251 }
252 else
253 { 364 {
254 bool sc = m_autoScroll; 365 bool sc = m_autoScroll;
366 setfont();
255 m_autoScroll = false; 367 m_autoScroll = false;
256 setfont(NULL);
257 locate(pagelocate()); 368 locate(pagelocate());
@@ -266,3 +377,3 @@ void QTReader::keyPressEvent(QKeyEvent* e)
266 e->accept(); 377 e->accept();
267 if (m_textsize > 0) 378 if (m_fontControl.decreasesize())
268 { 379 {
@@ -270,4 +381,3 @@ void QTReader::keyPressEvent(QKeyEvent* e)
270 m_autoScroll = false; 381 m_autoScroll = false;
271 m_textsize--; 382 setfont();
272 setfont(NULL);
273 locate(pagelocate()); 383 locate(pagelocate());
@@ -280,3 +390,2 @@ void QTReader::keyPressEvent(QKeyEvent* e)
280 case Key_Space: 390 case Key_Space:
281// case Key_Enter:
282 case Key_Return: 391 case Key_Return:
@@ -284,4 +393,3 @@ void QTReader::keyPressEvent(QKeyEvent* e)
284 e->accept(); 393 e->accept();
285 setautoscroll(!m_autoScroll); 394 emit OnActionPressed();
286 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
287 } 395 }
@@ -299,2 +407,3 @@ void QTReader::setautoscroll(bool _sc)
299 m_autoScroll = false; 407 m_autoScroll = false;
408 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
300 } 409 }
@@ -304,2 +413,3 @@ void QTReader::setautoscroll(bool _sc)
304 autoscroll(); 413 autoscroll();
414 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
305 } 415 }
@@ -307,3 +417,3 @@ void QTReader::setautoscroll(bool _sc)
307 417
308bool QTReader::getline(CBuffer *buff) 418bool QTReader::getline(CDrawBuffer *buff)
309{ 419{
@@ -332,10 +442,6 @@ void QTReader::doscroll()
332 442
333 if (++m_scrolldy == m_linespacing) 443 if (++m_scrolldy1 == textarray[0]->lineSpacing())
334 { 444 {
335 setfont(&p); 445 CDrawBuffer* buff = textarray[0];
336 m_scrolldy = 0; 446 for (int i = 1; i <= numlines; i++)
337// qDrawPlainRect(&p,0,height() - m_linespacing,width(),m_linespacing,white,1,&b);
338 pagepos = locnarray[1];
339 CBuffer* buff = textarray[0];
340 for (int i = 1; i < numlines; i++)
341 { 447 {
@@ -344,32 +450,26 @@ void QTReader::doscroll()
344 } 450 }
345 locnarray[numlines-1] = locate(); 451 textarray[numlines] = buff;
346 if (getline(buff)) 452 --numlines;
347 { 453 m_scrolldy1 = 0;
348 textarray[numlines-1] = buff;
349 drawText( p, 0, height() - m_descent - 2, buff->data());
350 mylastpos = locate();
351 } 454 }
352 else 455 if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
353 { 456 {
354// (*buff)[0] = '\0'; 457 m_scrolldy2 = 0;
355 textarray[numlines-1] = buff; 458 numlines++;
356 m_autoScroll = false;
357 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
358 }
359 }
360}
361 459
362void QTReader::drawText(QPainter& p, int x, int y, tchar* _text) 460 if (textarray[numlines] == NULL)
363{
364 QString text = toQString(_text);
365 if (m_bMonoSpaced)
366 {
367 for (int i = 0; i < text.length(); i++)
368 { 461 {
369 p.drawText( x+i*m_charWidth, y, QString(text[i]) ); 462 textarray[numlines] = new CDrawBuffer;
370 } 463 }
371 } 464 locnarray[numlines] = locate();
372 else 465 int ch = getline(textarray[numlines]);
466 textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
467 mylastpos = locate();
468 if (!ch)
373 { 469 {
374 p.drawText( x, y, text ); 470 m_autoScroll = false;
471 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
472 emit OnRedraw();
473 }
474 emit OnRedraw();
375 } 475 }
@@ -382,24 +482,10 @@ void QTReader::autoscroll()
382 482
383void QTReader::setfont(QPainter* p) 483void QTReader::setfont()
384{ 484{
385 // qDebug("Fontsize = %u",fontsizes[m_textsize]); 485// m_fontControl.Change
386 // qDebug("SetFont %x",p); 486 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
387 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
388 m_charWidth = (m_charpc*fontsizes[m_textsize])/100;
389 if (m_charWidth <= 0) m_charWidth = 1; 487 if (m_charWidth <= 0) m_charWidth = 1;
390// font.setFixedPitch(m_bMonoSpaced); 488 m_ascent = m_fontControl.ascent();
391// qDebug("Raw name = %s", (const char*)font.rawName()); 489 m_descent = m_fontControl.descent();
392 if (p != NULL) p->setFont( font ); 490 m_linespacing = m_fontControl.lineSpacing();
393 if (m_fm == NULL)
394 {
395 m_fm = new QFontMetrics(font);
396 buffdoc.setfm(m_fm);
397 }
398 else
399 {
400 *m_fm = QFontMetrics(font);
401 }
402 m_ascent = m_fm->ascent();
403 m_descent = m_fm->descent();
404 m_linespacing = m_fm->lineSpacing();
405} 491}
@@ -408,7 +494,8 @@ void QTReader::drawFonts( QPainter *p )
408{ 494{
409 setfont(p); 495 setfont();
410 if (m_lastwidth != width()) 496 if (m_lastwidth != width() || m_lastheight != height())
411 { 497 {
412 m_lastwidth = width(); 498 m_lastwidth = width();
413 locate(pagepos); 499 m_lastheight = height();
500 locate(pagelocate());
414 } 501 }
@@ -416,2 +503,4 @@ void QTReader::drawFonts( QPainter *p )
416 { 503 {
504
505/*
417 int sl = screenlines(); 506 int sl = screenlines();
@@ -422,3 +511,3 @@ void QTReader::drawFonts( QPainter *p )
422 size_t newpos = locnarray[sl]; 511 size_t newpos = locnarray[sl];
423 CBuffer** nta = new CBuffer*[sl]; 512 CDrawBuffer** nta = new CDrawBuffer*[sl];
424 size_t* nla = new size_t[sl]; 513 size_t* nla = new size_t[sl];
@@ -430,4 +519,4 @@ void QTReader::drawFonts( QPainter *p )
430 for (int i = sl; i < numlines; i++) delete textarray[i]; 519 for (int i = sl; i < numlines; i++) delete textarray[i];
431 delete [] textarray;
432 delete [] locnarray; 520 delete [] locnarray;
521 delete [] textarray;
433 textarray = nta; 522 textarray = nta;
@@ -436,3 +525,2 @@ void QTReader::drawFonts( QPainter *p )
436 jumpto(mylastpos = newpos); 525 jumpto(mylastpos = newpos);
437// locate(pagepos);
438 } 526 }
@@ -441,3 +529,3 @@ void QTReader::drawFonts( QPainter *p )
441// qDebug("df:<%u,%u>",sl,numlines); 529// qDebug("df:<%u,%u>",sl,numlines);
442 CBuffer** nta = new CBuffer*[sl]; 530 CDrawBuffer** nta = new CDrawBuffer*[sl];
443 size_t* nla = new size_t[sl]; 531 size_t* nla = new size_t[sl];
@@ -451,3 +539,3 @@ void QTReader::drawFonts( QPainter *p )
451 { 539 {
452 nta[i] = new CBuffer; 540 nta[i] = new CDrawBuffer(&m_fontControl);
453 nla[i] = locate(); 541 nla[i] = locate();
@@ -456,4 +544,4 @@ void QTReader::drawFonts( QPainter *p )
456 mylastpos = locate(); 544 mylastpos = locate();
457 delete [] textarray;
458 delete [] locnarray; 545 delete [] locnarray;
546 delete [] textarray;
459 textarray = nta; 547 textarray = nta;
@@ -462,24 +550,18 @@ void QTReader::drawFonts( QPainter *p )
462 } 550 }
463 int ypos = (btight) ? 0 : m_ascent-m_linespacing; 551*/
464 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 552 if (numlines > 0)
465 for (int i = 0; i < numlines; i++)
466 { 553 {
467 drawText( *p, 0, ypos += m_linespacing, textarray[i]->data()); 554 int ypos = textarray[0]->ascent();
468 } 555 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
469 /* 556 for (int i = 1; i < numlines; i++)
470
471
472
473 int nlines = height()/(fontmetric.ascent()+fontmetric.descent());
474 tchar buffer[1024];
475 for (int i = 0; i < nlines; i++)
476 { 557 {
477 y += fontmetric.ascent(); 558 ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
478 sprintf(buffer, "%d:%d:%s[%d]:Lines %d:%s", i+1, m_textfont, fonts[m_textfont], m_fs, nlines, (const tchar*)m_string); 559 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
479 drawText( *p, 0, y, buffer ); 560
480 y += fontmetric.descent(); 561 }
562// mylastpos = locate();
481 } 563 }
482 */
483 } 564 }
484 m_scrolldy = 0; 565 m_scrolldy1 = m_scrolldy2 = 0;
566 emit OnRedraw();
485} 567}
@@ -518,40 +600,5 @@ QString QTReader::firstword()
518 600
519void QTReader::ChangeFont(int tgt) 601bool QTReader::ChangeFont(int tgt)
520{ 602{
521 603 return m_fontControl.ChangeFont(m_fontname, tgt);
522 QValueList<int>::Iterator it;
523
524// QValueList<int> sizes = QFontDatabase::pointSizes(m_fontname, (m_bBold) ? QFont::Bold : QFont::Normal);
525 QFontDatabase fdb;
526/*
527 QStringList styles = fdb.styles(m_fontname);
528 for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it )
529 {
530 printf( "%s \n", (*it).latin1() );
531 }
532*/
533 QValueList<int> sizes = fdb.pointSizes(m_fontname, (m_bBold) ? QString("Bold") : QString::null);
534 uint n = sizes.count();
535 if (fontsizes != NULL) delete [] fontsizes;
536 fontsizes = new unsigned int[n+1];
537 uint i = 0;
538 uint best = 0;
539 for (it = sizes.begin(); it != sizes.end(); it++)
540 {
541 fontsizes[i] = (*it)/10;
542 if (abs(tgt-fontsizes[i]) < abs(tgt-fontsizes[best]))
543 {
544 best = i;
545 }
546 i++;
547 }
548 m_textsize = best;
549 fontsizes[i] = 0;
550 setfont(NULL);
551 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
552 if (m_fm == NULL)
553 {
554 m_fm = new QFontMetrics(font);
555 buffdoc.setfm(m_fm);
556 }
557} 604}
@@ -567,3 +614,3 @@ void QTReader::init()
567 ChangeFont(m_textsize); 614 ChangeFont(m_textsize);
568 // setFocusPolicy(QWidget::StrongFocus); 615 setFocusPolicy(QWidget::StrongFocus);
569 // resize( 240, 320 ); 616 // resize( 240, 320 );
@@ -574,2 +621,4 @@ void QTReader::init()
574 m_lastwidth = width(); 621 m_lastwidth = width();
622 m_lastheight = height();
623 setfont();
575 if (!m_lastfile.isEmpty()) 624 if (!m_lastfile.isEmpty())
@@ -586,6 +635,2 @@ QTReader::~QTReader()
586{ 635{
587 if (fontsizes != NULL) delete [] fontsizes;
588#ifndef QT_NO_PRINTER
589 // delete printer;
590#endif
591} 636}
@@ -674,37 +719,24 @@ unsigned int QTReader::screenlines()
674 719
675bool QTReader::fillbuffer() { 720bool QTReader::fillbuffer(int reuse, int ht)
721{
676 if (buffdoc.empty()) return false; 722 if (buffdoc.empty()) return false;
677 //printf("Fillbuffer\n"); 723 m_scrolldy1 = m_scrolldy2 = 0;
678 m_scrolldy = 0;
679 int ch; 724 int ch;
680 bool ret = false; 725 bool ret = false;
681 int delta = screenlines(); 726 unsigned int oldpagepos = locnarray[reuse];
682 // qDebug("fillbuffer:%u-%u",delta,numlines); 727 int ypos = ht;
683 if (delta != numlines) 728 numlines = reuse;
729 while (ypos < height())
684 { 730 {
685 if (textarray != NULL) 731 if (textarray[numlines] == NULL)
686 { 732 {
687 for (int i = 0; i < numlines; i++) delete textarray[i]; 733 textarray[numlines] = new CDrawBuffer(&m_fontControl);
688 delete [] textarray;
689 delete [] locnarray;
690 } 734 }
691 numlines = delta; 735 locnarray[numlines] = locate();
692 textarray = new CBuffer*[numlines]; 736 int ch = getline(textarray[numlines]);
693 locnarray = new size_t[numlines]; 737 ypos += textarray[numlines]->lineSpacing();
694 for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer; 738 numlines++;
695 }
696 // qDebug("fillbuffer:pagepos:%u",pagepos);
697 unsigned int oldpagepos = pagepos;
698// if (textarray != NULL)
699// pagepos = locnarray[0];
700// else
701 pagepos = locate();
702 for (int i = 0; i < delta; i++)
703 {
704 locnarray[i] = locate();
705 ch = getline(textarray[i]);
706 // if (ch == EOF) {
707 if (!ch) 739 if (!ch)
708 { 740 {
709 if (i == 0) 741 if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/)
710 { 742 {
@@ -715,15 +747,12 @@ bool QTReader::fillbuffer() {
715 { 747 {
716 ret = true; 748 --numlines;
717 for (int j = i+1; j < delta; j++) 749 mylastpos = locate();
718 { 750 return true;
719 locnarray[j] = locnarray[j-1];
720 (*(textarray[j]))[0] = '\0';
721 }
722 break;
723 } 751 }
724 } 752 }
725 if (ch == '\012') ret = true;
726 } 753 }
754
755 --numlines;
727 mylastpos = locate(); 756 mylastpos = locate();
728 // qDebug("fillbuffer:lastpos:%u",mylastpos); 757
729 return true; 758 return true;
@@ -734,12 +763,25 @@ void QTReader::dopagedn()
734{ 763{
735 if (m_overlap == 0) 764 int skip = 0, ypos = 0;
765 if (locate() != mylastpos)
736 { 766 {
737 if (locate() != mylastpos) jumpto(mylastpos); 767 //qDebug("Jumping to %u", mylastpos);
768 jumpto(mylastpos);
738 } 769 }
739 else 770 CDrawBuffer* reusebuffer = textarray[numlines];
771 if (reusebuffer != NULL)
772 {
773 for (int i = 0; i <= m_overlap; i++)
740 { 774 {
741 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 775 int offset = numlines - m_overlap + i;
742 jumpto(locnarray[screenlines()-m_overlap]); 776 reusebuffer = textarray[offset];
777 size_t reuselocn = locnarray[offset];
778 textarray[offset] = textarray[i];
779 textarray[i] = reusebuffer;
780 locnarray[offset] = locnarray[i];
781 locnarray[i] = reuselocn;
782 ypos += textarray[i]->lineSpacing();
783 skip++;
743 } 784 }
744 if (fillbuffer()) 785 }
786 if (fillbuffer(skip, ypos))
745 { 787 {
@@ -751,18 +793,8 @@ void QTReader::dopageup()
751{ 793{
752 CBuffer** buff = textarray; 794 CBufferFace<CDrawBuffer*> buff;
753 unsigned int *loc = new unsigned int[numlines]; 795 CBufferFace<size_t> loc;
754 int cbptr = 0; 796 unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
755 if (locate() != mylastpos) jumpto(mylastpos); 797
756 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 798 size_t delta;
757 unsigned int target = locnarray[m_overlap]; 799 if (target < 2048)
758 if (buffdoc.hasrandomaccess())
759 {
760 unsigned int delta = locate()-pagelocate();
761 if (delta < 64) delta = 64;
762 if (delta % 2 != 0) delta++;
763 if (target % 2 != 0) target++;
764 do
765 {
766 delta <<= 1;
767 if (delta >= target)
768 { 800 {
@@ -770,16 +802,16 @@ void QTReader::dopageup()
770 jumpto(0); 802 jumpto(0);
771 for (int i = 0; i < numlines; i++)
772 {
773 loc[i] = locate();
774 getline(buff[i]);
775 }
776 break;
777 } 803 }
804 else
805 {
806 delta = 2048;
807
778 jumpto(target-delta); 808 jumpto(target-delta);
809
810 buff[0] = new CDrawBuffer(&m_fontControl);
811
779 do 812 do
780 { 813 {
781 getline(buff[0]); 814
782#ifdef WS 815 if (!getline(buff[0])) break;
783 //printf("Trying:%s\n",buff[0]); 816
784#endif
785 if (locate() > target) continue; 817 if (locate() > target) continue;
@@ -787,46 +819,52 @@ void QTReader::dopageup()
787 while (!buffdoc.iseol()); 819 while (!buffdoc.iseol());
788 for (int i = 0; i < numlines; i++)
789 {
790 loc[i] = locate();
791 getline(buff[i]);
792#ifdef WS
793 //printf("Filling:%s\n",buff[i]);
794#endif
795 }
796 } 820 }
797 while (locate() >= target && delta < 4096); 821 int nbfl = 0;
798#ifdef WS 822
799 //printf("Delta:%u\n",delta); 823 bool ch = true;
800#endif 824 int ypos = 0;
825 while (locate() < target)
826 {
827 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
828 loc[nbfl] = locate();
829 ch = getline(buff[nbfl]);
830 ypos += buff[nbfl]->lineSpacing();
831 nbfl++;
832 if (!ch) break;
801 } 833 }
802 else 834 if (ypos < height())
803 { 835 {
804 jumpto(0); 836 locate(0);
805 for (int i = 0; i < numlines; i++) 837 return;
838 }
839 if (ch)
806 { 840 {
807 loc[i] = locate(); 841 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
808 getline(buff[i]); 842 loc[nbfl] = locate();
843 int ch = getline(buff[nbfl]);
844 nbfl++;
809 } 845 }
846 ypos = 0;
847 numlines = 0;
848 while (ypos < height() && numlines <= nbfl-2)
849 {
850 ypos += buff[nbfl - numlines - 2]->lineSpacing();
851 numlines++;
810 } 852 }
811 cbptr = 0; 853 --numlines;
812 while (locate() < target) 854 int offset = nbfl;
855 offset -= numlines+1;
856 for (int i = 0; i <= numlines; i++)
813 { 857 {
814 loc[cbptr] = locate(); 858 delete textarray[i];
815 getline(buff[cbptr]); 859 textarray[i] = buff[offset+i];
816#ifdef WS 860 locnarray[i] = loc[offset + i];
817 //printf("Adding:%s\n",buff[cbptr]->data());
818#endif
819 cbptr = (cbptr+1) % numlines;
820 } 861 }
821 pagepos = loc[cbptr]; 862 for (int i = 0; i < nbfl - numlines - 1; i++)
822 textarray = new CBuffer*[numlines];
823 for (int i = 0; i < numlines; i++)
824 { 863 {
825 int j = (cbptr+i)%numlines; 864 delete buff[i];
826 textarray[i] = buff[j];
827 locnarray[i] = loc[j];
828 } 865 }
829 delete [] buff; 866
830 delete [] loc; 867// --numlines;
831 mylastpos = locate(); 868 mylastpos = locate();
869
832 update(); 870 update();
@@ -854,2 +892,3 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
854 } 892 }
893 setfilter(getfilter());
855 update(); 894 update();
@@ -861,19 +900,29 @@ void QTReader::lineDown()
861{ 900{
862 pagepos = locnarray[1]; 901 int ypos = 0;
863 CBuffer* buff = textarray[0]; 902 int offset = numlines;
864 for (int i = 1; i < numlines; i++) 903
904 for (int i = 0; i <= numlines; i++)
865 { 905 {
866 textarray[i-1] = textarray[i]; 906 if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
867 locnarray[i-1] = locnarray[i]; 907 {
908 offset = i-1;
909 break;
910 }
868 } 911 }
869 locnarray[numlines-1] = locate(); 912 offset = numlines - offset;
870 if (getline(buff)) 913 for (int i = offset; i <= numlines; i++)
871 { 914 {
872 textarray[numlines-1] = buff; 915 CDrawBuffer* buff = textarray[i-offset];
873 mylastpos = locate(); 916 textarray[i-offset] = textarray[i];
917 locnarray[i-offset] = locnarray[i];
918 textarray[i] = buff;
874 } 919 }
875 else 920 numlines = numlines - offset + 1;
921 locnarray[numlines] = locate();
922 if (textarray[numlines] == NULL)
876 { 923 {
877 textarray[numlines-1] = buff; 924 textarray[numlines] = new CDrawBuffer(&m_fontControl);
878 } 925 }
926 getline(textarray[numlines]);
927 mylastpos = locate();
879 update(); 928 update();
@@ -965,5 +1014,5 @@ void QTReader::lineUp()
965{ 1014{
966 CBuffer* buff = textarray[numlines-1]; 1015 CDrawBuffer* buff = textarray[numlines];
967 unsigned int loc; 1016 unsigned int loc;
968 unsigned int end = locnarray[numlines-1]; 1017 unsigned int end = locnarray[numlines];
969 int cbptr = 0; 1018 int cbptr = 0;
@@ -971,2 +1020,3 @@ void QTReader::lineUp()
971 unsigned int target = locnarray[0]; 1020 unsigned int target = locnarray[0];
1021 if (target == 0) return;
972 if (buffdoc.hasrandomaccess()) 1022 if (buffdoc.hasrandomaccess())
@@ -982,7 +1032,4 @@ void QTReader::lineUp()
982 jumpto(0); 1032 jumpto(0);
983 for (int i = 0; i < numlines; i++)
984 {
985 loc = locate(); 1033 loc = locate();
986 getline(buff); 1034 getline(buff);
987 }
988 break; 1035 break;
@@ -1016,4 +1063,3 @@ void QTReader::lineUp()
1016 } 1063 }
1017 pagepos = loc; 1064 for (int i = numlines; i > 0; i--)
1018 for (int i = numlines-1; i > 0; i--)
1019 { 1065 {
@@ -1024,6 +1070,16 @@ void QTReader::lineUp()
1024 locnarray[0] = loc; 1070 locnarray[0] = loc;
1025// delete [] buff; 1071 int start = numlines;
1026// delete [] loc; 1072 int ypos = 0;
1027 mylastpos = locate(); 1073 for (int i = 0; i <= numlines; i++)
1028 jumpto(end); 1074 {
1075 ypos += textarray[i]->lineSpacing();
1076 if (ypos > height())
1077 {
1078 start = i;
1079 ypos -= textarray[i]->lineSpacing();
1080 break;
1081 }
1082 }
1083 jumpto(locnarray[start]);
1084 fillbuffer(start, ypos);
1029 update(); 1085 update();
@@ -1035 +1091,19 @@ bool QTReader::empty()
1035} 1091}
1092
1093MarkupType QTReader::PreferredMarkup()
1094{
1095 MarkupType m = buffdoc.PreferredMarkup();
1096 if (m == cTEXT)
1097 {
1098 int ext = m_lastfile.findRev('.');
1099 if (ext >= 0)
1100 {
1101 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
1102 if (ft.left(3) == "HTM")
1103 {
1104 m = cHTML;
1105 }
1106 }
1107 }
1108 return m;
1109}