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.cpp716
1 files changed, 476 insertions, 240 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
@@ -9,19 +9,25 @@
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
@@ -37,4 +43,8 @@ const char *QTReader::fonts[] = { "Helvetica", "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),
@@ -52,11 +62,16 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
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),
@@ -73,9 +88,18 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name,
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{
@@ -88,52 +112,101 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
88 if (_e->button() == RightButton) 112 if (_e->button() == RightButton)
89 { 113 {
114 //qDebug("MousePress");
90 mouseUpOn = false; 115 mouseUpOn = false;
91 if (buffdoc.hasnavigation()) 116 if (m_swapmouse)
92 { 117 {
93 if (_e->y() > (2*height())/3) 118 int lineno = 0;
94 { 119 int ht = textarray[0]->lineSpacing();
95 goDown(); 120 while ((ht < _e->y()) && (lineno < numlines))
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 {
121 buffdoc.saveposn(pagelocate()); 122 ht += textarray[++lineno]->lineSpacing();
122 locate(buffdoc.getHome());
123 } 123 }
124 } 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{
135 if (buffdoc.hasnavigation())
136 {
137 if (_e->y() > (2*height())/3)
138 {
139 goDown();
140 }
141 else if (_e->y() < height()/3)
142 {
143 goUp();
125 } 144 }
126 else 145 else
127 { 146 {
128 if (_e->y() > height()/2) 147 if (_e->x() < width()/3)
129 { 148 {
130 goDown(); 149 goBack();
150 }
151 else if (_e->x() > (2*width())/3)
152 {
153 goForward();
131 } 154 }
132 else 155 else
133 { 156 {
134 goUp(); 157 goHome();
135 } 158 }
136 } 159 }
137 } 160 }
161 else
162 {
163 if (_e->y() > height()/2)
164 {
165 goDown();
166 }
167 else
168 {
169 goUp();
170 }
171 }
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
@@ -149,5 +222,5 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
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
@@ -155,6 +228,6 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
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 }
@@ -162,4 +235,13 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
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{
@@ -174,4 +256,88 @@ void QTReader::setContinuous(bool _b)
174} 256}
175 257
258void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
259{
260 QString wrd;
261 if (m_twotouch)
262 {
263 if (m_touchone)
264 {
265 m_touchone = false;
266 m_startpos = startpos;
267 m_startoffset = startoffset;
268 setBackgroundColor( lightGray );
269 }
270 else
271 {
272 m_touchone = true;
273 setBackgroundColor( white );
274 size_t endpos, endoffset;
275 endpos = startpos;
276 endoffset = startoffset;
277 size_t currentpos = locate();
278 if (endpos >= m_startpos)
279 {
280 jumpto(m_startpos);
281 for (int i = 0; i < m_startoffset; i++)
282 {
283 getch();
284 }
285 if (m_startpos == endpos)
286 {
287 for (int i = m_startoffset; i <= endoffset; i++)
288 {
289 wrd += QChar(getch());
290 }
291 }
292 else
293 {
294 while (buffdoc.explocate() <= endpos)
295 {
296 wrd += QChar(getch());
297 }
298 for (int i = 0; i < endoffset; i++)
299 {
300 wrd += QChar(getch());
301 }
302 }
303 jumpto(currentpos);
304 }
305 }
306 }
307 else if (m_bMonoSpaced)
308 {
309 int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth;
310 if (chno < ustrlen(textarray[lineno]->data()))
311 {
312 wrd[0] = textarray[lineno]->data()[chno];
313 }
314 }
315 else
316 {
317 CDrawBuffer* t = textarray[lineno];
318 int first = 0;
319 int tgt = _e->x() - t->offset(width(), m_border);
320 while (1)
321 {
322 int i = first+1;
323 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
324 if (t->width(i, true, width(), m_border) > tgt)
325 {
326 wrd = toQString(t->data()+first, i - first);
327 // qDebug("Got %s", (const char *)wrd);
328 break;
329 }
330 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
331 if ((*t)[i] == 0) break;
332 first = i;
333 }
334 }
335 if (!wrd.isEmpty())
336 {
337 //qDebug("Selected:%s", (const char*)wrd);
338 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
339 }
340}
341
176void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 342void QTReader::mouseReleaseEvent( QMouseEvent* _e )
177{ 343{
@@ -181,7 +347,13 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
181 if (mouseUpOn) 347 if (mouseUpOn)
182 { 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 }
183 if (textarray[0] != NULL) 355 if (textarray[0] != NULL)
184 { 356 {
185 QString wrd, line; 357 QString line;
186 // int lineno = _e->y()/m_linespacing; 358 // int lineno = _e->y()/m_linespacing;
187 int lineno = 0; 359 int lineno = 0;
@@ -197,5 +369,7 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
197 { 369 {
198 size_t saveposn = pagelocate(); 370 size_t saveposn = pagelocate();
199 if (buffdoc.hyperlink(tgt)) 371 QString href;
372 linkType lt = buffdoc.hyperlink(tgt, href);
373 if (lt == eLink)
200 { 374 {
201 buffdoc.saveposn(saveposn); 375 buffdoc.saveposn(saveposn);
@@ -205,4 +379,21 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
205 else 379 else
206 { 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 }
207 locate(pagelocate()); 398 locate(pagelocate());
208 } 399 }
@@ -211,6 +402,6 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
211 case ePicture: 402 case ePicture:
212 { 403 {
213 qDebug("Picture:%x", tgt); 404 // qDebug("Picture:%x", tgt);
214 QPixmap* pm = buffdoc.getPicture(tgt); 405 QImage* pm = buffdoc.getPicture(tgt);
215 if (pm != NULL) 406 if (pm != NULL)
216 { 407 {
@@ -227,84 +418,11 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
227 break; 418 break;
228 default: 419 default:
229 qDebug("Unknown linktype"); 420 // qDebug("Unknown linktype");
230 return; 421 return;
231 } 422 }
232 if (m_twotouch) 423 if (m_swapmouse)
233 { 424 processmousepositionevent(_e);
234 if (m_touchone)
235 {
236 m_touchone = false;
237 m_startpos = startpos;
238 m_startoffset = startoffset;
239 setBackgroundColor( lightGray );
240 }
241 else
242 {
243 m_touchone = true;
244 setBackgroundColor( white );
245 size_t endpos, endoffset;
246 endpos = startpos;
247 endoffset = startoffset;
248 size_t currentpos = locate();
249 if (endpos >= m_startpos)
250 {
251 jumpto(m_startpos);
252 for (int i = 0; i < m_startoffset; i++)
253 {
254 getch();
255 }
256 if (m_startpos == endpos)
257 {
258 for (int i = m_startoffset; i <= endoffset; i++)
259 {
260 wrd += QChar(getch());
261 }
262 }
263 else
264 {
265 while (buffdoc.explocate() <= endpos)
266 {
267 wrd += QChar(getch());
268 }
269 for (int i = 0; i < endoffset; i++)
270 {
271 wrd += QChar(getch());
272 }
273 }
274 jumpto(currentpos);
275 }
276 }
277 }
278 else if (m_bMonoSpaced)
279 {
280 int chno = _e->x()/m_charWidth;
281 if (chno < ustrlen(textarray[lineno]->data()))
282 {
283 wrd[0] = textarray[lineno]->data()[chno];
284 }
285 }
286 else 425 else
287 { 426 processmousewordevent(startpos, startoffset, _e, lineno);
288 CDrawBuffer* t = textarray[lineno];
289 int first = 0;
290 int tgt = _e->x() - t->offset(width());
291 while (1)
292 {
293 int i = first+1;
294 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
295 if (t->width(i) > tgt)
296 {
297 wrd = toQString(t->data()+first, i - first);
298 break;
299 }
300 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
301 if ((*t)[i] == 0) break;
302 first = i;
303 }
304 }
305 if (!wrd.isEmpty())
306 {
307 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
308 }
309 } 427 }
310 } 428 }
@@ -327,5 +445,5 @@ void QTReader::focusOutEvent(QFocusEvent* e)
327 { 445 {
328 timer->stop(); 446 timer->stop();
329 m_scrolldy1 = m_scrolldy2 = 0; 447 //m_scrolldy1 = m_scrolldy2 = 0;
330 } 448 }
331} 449}
@@ -333,5 +451,7 @@ void QTReader::focusOutEvent(QFocusEvent* e)
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()
@@ -427,7 +547,60 @@ void QTReader::zoomout()
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 {
@@ -474,33 +647,4 @@ void QTReader::keyPressEvent(QKeyEvent* e)
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 {
@@ -531,14 +675,8 @@ void QTReader::keyPressEvent(QKeyEvent* e)
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
@@ -549,5 +687,14 @@ void QTReader::setautoscroll(bool _sc)
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
@@ -556,6 +703,16 @@ void QTReader::setautoscroll(bool _sc)
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}
@@ -566,9 +723,9 @@ bool QTReader::getline(CDrawBuffer *buff)
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}
@@ -589,4 +746,23 @@ void QTReader::doscroll()
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++)
@@ -610,10 +786,27 @@ void QTReader::doscroll()
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();
@@ -640,36 +833,38 @@ void QTReader::drawFonts( QPainter *p )
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++)
@@ -677,12 +872,13 @@ void QTReader::drawFonts( QPainter *p )
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 {
@@ -690,16 +886,28 @@ void QTReader::drawFonts( QPainter *p )
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
@@ -743,4 +951,5 @@ bool QTReader::ChangeFont(int tgt)
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
@@ -772,4 +981,16 @@ void QTReader::init()
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
@@ -817,5 +1038,5 @@ void QTReader::paintEvent( QPaintEvent * )
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}
@@ -842,9 +1063,9 @@ bool QTReader::locate(unsigned long 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}
@@ -857,16 +1078,20 @@ unsigned int QTReader::screenlines()
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 {
@@ -895,16 +1120,17 @@ bool QTReader::fillbuffer(int reuse, int ht)
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 }
@@ -939,4 +1165,16 @@ void QTReader::dopageup()
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{
@@ -945,12 +1183,11 @@ void QTReader::dopageup(unsigned int target)
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 {
@@ -966,20 +1203,22 @@ void QTReader::dopageup(unsigned int target)
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 {
@@ -991,5 +1230,5 @@ void QTReader::dopageup(unsigned int target)
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++)
@@ -1010,4 +1249,5 @@ void QTReader::dopageup(unsigned int target)
1010 nbfl++; 1249 nbfl++;
1011 } 1250 }
1251/*
1012 ypos = 0; 1252 ypos = 0;
1013 numlines = 0; 1253 numlines = 0;
@@ -1018,4 +1258,16 @@ void QTReader::dopageup(unsigned int target)
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;
@@ -1028,5 +1280,9 @@ void QTReader::dopageup(unsigned int target)
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];
@@ -1058,19 +1314,20 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
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}
@@ -1090,5 +1347,9 @@ void QTReader::lineDown()
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];
@@ -1260,5 +1521,9 @@ void QTReader::lineUp()
1260 int start = numlines; 1521 int start = numlines;
1261 int ypos = 0; 1522 int ypos = 0;
1262 for (int i = 0; i <= numlines; i++) 1523#ifdef _WINDOWS
1524 for (i = 0; i <= numlines; i++)
1525#else
1526 for (int i = 0; i <= numlines; i++)
1527#endif
1263 { 1528 {
1264 ypos += textarray[i]->lineSpacing(); 1529 ypos += textarray[i]->lineSpacing();
@@ -1297,31 +1562,2 @@ MarkupType QTReader::PreferredMarkup()
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}