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.cpp2034
1 files changed, 1733 insertions, 301 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index b356ba5..dfdba28 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -1,427 +1,672 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9*****************************************************************************/ 9*****************************************************************************/
10 10
11const int _SBARHEIGHT = 3;
12
13#include "useqpe.h"
14#include <qpainter.h>
15//#include <qdirectpainter_qws.h>
16#include <qimage.h>
17#include <qtimer.h>
18#include "config.h"
11#include "QTReader.h" 19#include "QTReader.h"
12#include "QTReaderApp.h" 20//#include "QTReaderApp.h"
21#include "CDrawBuffer.h"
13#ifdef USEQPE 22#ifdef USEQPE
14#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
15#endif 24#endif
16#include <math.h> 25#include <math.h>
17#include <ctype.h> 26#include <ctype.h>
18#include <stdio.h> //for sprintf 27#include <stdio.h> //for sprintf
19#ifdef USEQPE 28#ifdef USEQPE
20#include <qpe/config.h> 29#include <qpe/config.h>
21#include <qpe/applnk.h> 30#include <qpe/applnk.h>
22#include <qpe/global.h> 31#include <qpe/global.h>
23#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
24#endif 33#endif
34#include <qfileinfo.h>
35#include <qdir.h>
25 36
26#ifdef _UNICODE 37#ifdef _UNICODE
27const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 38const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
28#else 39#else
29const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 40const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
30#endif 41#endif
31//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 42//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
32 43
33//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 44//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
34//const int QTReader::fontsizes[] = {10,16,17,22,0}; 45//const int QTReader::fontsizes[] = {10,16,17,22,0};
35//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 46//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}; 47//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 48
38tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; 49tchar QTReader::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 };
39tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 50tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
40//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 51//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
41 52
53
42QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 54QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
43 QWidget(parent, name, f), 55 QWidget(parent, name, f),
56 m_default_fg(0,0,0),
57 m_default_bg(255,255,255),
58 m_bg(255,255,255),
44 m_delay(100), 59 m_delay(100),
45 m_scrolldy1(0), 60 m_scrolldy1(0),
46 m_scrolldy2(0), 61 m_scrolldy2(0),
62 m_totalscroll(0),
47 m_autoScroll(false), 63 m_autoScroll(false),
48 //textarray(NULL), 64 //textarray(NULL),
49 //locnarray(NULL), 65 //locnarray(NULL),
50 numlines(0), 66 numlines(0),
51 m_fontname("unifont"), 67 m_fontname("unifont"),
52 m_fm(NULL), 68 m_fm(NULL),
53 mouseUpOn(true), 69 mouseUpOn(true),
54 m_twotouch(true), 70 m_twotouch(true),
55 m_touchone(true), 71 m_touchone(true),
56 bDoUpdates(false), 72 bDoUpdates(false),
57#ifdef _SCROLLPIPE 73#ifdef _SCROLLPIPE
58 m_pipeout(NULL), 74 m_pipeout(NULL),
59#endif 75#endif
60 m_border(2) 76 m_left_border(2),
77 m_right_border(2),
78 m_rotated(true),
79 pBkmklist(NULL),
80 m_scrollpos(0),
81 // bNegative(false),
82 bInverse(false),
83 m_highlightfilter(NULL),
84 m_bgIsScaled(false),
85 m_scrollstep(2),
86 m_topmargin(5),
87 m_bottommargin(5),
88 m_reparastring("{\\n[\\n ]}"),
89 m_currentlinkstyle(NULL),
90 m_currentlinkoffset(-1),
91 m_currentlink(-1)
61{ 92{
62 m_overlap = 1; 93 m_overlap = 1;
63 setKeyCompression ( true ); 94 setKeyCompression ( true );
95#ifdef DOUBLEBUFFER
96 dbuff = new QPixmap();
97 dbp = new QPainter();
98 // if (painter->isActive()) painter->end();
99 // painter->begin(frame);
100#endif
64// init(); 101// init();
102
65} 103}
66 104
67/* 105/*
68QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 106QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
69 QWidget(parent, name, f), 107 QWidget(parent, name, f),
70 m_textfont(0), 108 m_textfont(0),
71 m_textsize(1), 109 m_textsize(1),
72 textarray(NULL), 110 textarray(NULL),
73 numlines(0), 111 numlines(0),
74 bstripcr(true), 112 bstripcr(true),
75 bunindent(false), 113 bunindent(false),
76 brepara(false), 114 brepara(false),
77 bdblspce(false), 115 bdblspce(false),
78 btight(false), 116 btight(false),
79 bindenter(0), 117 bindenter(0),
80 m_fm(NULL) 118 m_fm(NULL)
81{ 119{
82 init(); 120 init();
83// // odebug << "Load_file(1)" << oendl; 121// // qDebug("Load_file(1)");
84 load_file((const tchar*)filename); 122 load_file((const tchar*)filename);
85} 123}
86*/ 124*/
87 125
88/* 126/*
89void QTReader::mouseMoveEvent(QMouseEvent* _e) 127void QTReader::mouseMoveEvent(QMouseEvent* _e)
90{ 128{
91 129
92 mouseUpOn = !(_e->pos().x() == -1); 130 mouseUpOn = !(_e->pos().x() == -1);
93 131
94 odebug << "MouseMove:[" << _e->pos().x() << ", " << _e->pos().y() << "]" << oendl; 132 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
95} 133}
96*/ 134*/
97long QTReader::real_delay() 135long QTReader::real_delay()
98{ 136{
99 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 137 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
100} 138}
101 139
102void QTReader::mousePressEvent( QMouseEvent* _e ) 140void QTReader::mousePressEvent( QMouseEvent* _e )
103{ 141{
104 buffdoc.unsuspend(); 142 buffdoc.unsuspend();
143 int x, y, ht, wh;
144 if (m_rotated)
145 {
146 x = _e->y();
147 y = width()-_e->x();
148 ht = width();
149 wh = height();
150 }
151 else
152 {
153 x = _e->x();
154 y = _e->y();
155 ht = height();
156 wh = width();
157 }
105 if (_e->button() == RightButton) 158 if (_e->button() == RightButton)
106 { 159 {
107 //odebug << "MousePress" << oendl; 160 //qDebug("MousePress");
108 mouseUpOn = false; 161 mouseUpOn = false;
109 if (m_swapmouse) 162 if (m_swapmouse)
110 { 163 {
111 int lineno = 0; 164 int lineno = 0;
112 int ht = textarray[0]->lineSpacing(); 165 /*
113 while ((ht < _e->y()) && (lineno < numlines)) 166 int hgt = textarray[0]->lineSpacing();
167 while ((hgt < y) && (lineno < numlines))
114 { 168 {
115 ht += textarray[++lineno]->lineSpacing(); 169 hgt += textarray[++lineno]->lineSpacing();
116 } 170 }
117 size_t startpos, startoffset, tgt; 171 */
118 getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt); 172 size_t startpos, startoffset, tgt, tgtoffset, pictgt;
173 QImage* img;
174 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img);
119 processmousewordevent(startpos, startoffset, _e, lineno); 175 processmousewordevent(startpos, startoffset, _e, lineno);
120 } 176 }
121 else 177 else
122 processmousepositionevent(_e); 178 processmousepositionevent(_e);
123 } 179 }
124} 180}
125 181
126void QTReader::processmousepositionevent( QMouseEvent* _e ) 182void QTReader::processmousepositionevent( QMouseEvent* _e )
127{ 183{
184 int x, y, ht, wh;
185 if (m_rotated)
186 {
187 x = _e->y();
188 y = width()-_e->x();
189 ht = width();
190 wh = height();
191 }
192 else
193 {
194 x = _e->x();
195 y = _e->y();
196 ht = height();
197 wh = width();
198 }
128 if (buffdoc.hasnavigation()) 199 if (buffdoc.hasnavigation())
129 { 200 {
130 if (_e->y() > (2*height())/3) 201 if (y > (2*ht)/3)
131 { 202 {
132 goDown(); 203 goDown();
133 } 204 }
134 else if (_e->y() < height()/3) 205 else if (y < ht/3)
135 { 206 {
136 goUp(); 207 goUp();
137 } 208 }
138 else 209 else
139 { 210 {
140 if (_e->x() < width()/3) 211 if (x < wh/3)
141 { 212 {
142 goBack(); 213 goBack();
143 } 214 }
144 else if (_e->x() > (2*width())/3) 215 else if (x > (2*wh)/3)
145 { 216 {
146 goForward(); 217 goForward();
147 } 218 }
148 else 219 else
149 { 220 {
150 goHome(); 221 goHome();
151 } 222 }
152 } 223 }
153 } 224 }
154 else 225 else
155 { 226 {
156 if (_e->y() > height()/2) 227 if (y > ht/2)
157 { 228 {
158 goDown(); 229 goDown();
159 } 230 }
160 else 231 else
161 { 232 {
162 goUp(); 233 goUp();
163 } 234 }
164 } 235 }
165} 236}
166 237
167void QTReader::goHome() 238void QTReader::goHome()
168{ 239{
169 if (buffdoc.hasnavigation()) 240 if (buffdoc.hasnavigation())
170 { 241 {
171 size_t current=pagelocate(); 242 size_t current=pagelocate();
172 size_t home=buffdoc.getHome(); 243 size_t home=buffdoc.getHome();
173 if (current!=home) 244 if (current!=home)
174 { 245 {
175 buffdoc.saveposn(current); 246 buffdoc.saveposn(m_lastfile, current);
176 locate(home); 247 locate(home);
177 } 248 }
178 } 249 }
250 else
251 locate(0);
179} 252}
180 253
181void QTReader::goBack() 254void QTReader::goBack()
182{ 255{
183 if (buffdoc.hasnavigation()) 256 if (buffdoc.hasnavigation())
184 { 257 {
185 size_t target = pagelocate(); 258 size_t target = pagelocate();
186 buffdoc.writeposn(target); 259 QString nxt = m_lastfile;
187 if (buffdoc.back(target)) 260 buffdoc.writeposn(m_lastfile, target);
261 linkType lt = buffdoc.back(nxt, target);
262 if ((lt & eFile) != 0)
188 { 263 {
189 locate(target); 264 if (nxt != m_lastfile)
265 {
266 emit NewFileRequest(nxt);
267 }
268 locate(target);
269 }
270 else if ((lt & eLink) != 0)
271 {
272 locate(target);
190 } 273 }
191 } 274 }
192} 275}
193 276
194void QTReader::goForward() 277void QTReader::goForward()
195{ 278{
196 if (buffdoc.hasnavigation()) 279 if (buffdoc.hasnavigation())
197 { 280 {
198 size_t target = pagelocate(); 281 size_t target = pagelocate();
199 if (buffdoc.forward(target)) 282 QString nxt = m_lastfile;
283 linkType lt = buffdoc.forward(nxt, target);
284 if ((lt & eFile) != 0)
200 { 285 {
201 locate(target); 286 if (nxt != m_lastfile)
287 {
288 emit NewFileRequest(nxt);
289 }
290 locate(target);
291 }
292 else if ((lt & eLink) != 0)
293 {
294 locate(target);
202 } 295 }
203 } 296 }
204} 297}
205 298
206linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) 299linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img)
207{ 300{
208 int lineno = 0; 301 int ht;
209 int ht = textarray[0]->lineSpacing(); 302 if (m_scrolldy == m_topmargin)
210 while ((ht < y) && (lineno < numlines))
211 { 303 {
212 ht += textarray[++lineno]->lineSpacing(); 304 lineno = 0;
305 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
213 } 306 }
214 start = locnarray[lineno]; 307 else
215 if (m_bMonoSpaced) 308 {
309 if (y >= m_scrolldy)
310 {
311 lineno = 0;
312 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin;
313 }
314 else
315 {
316 lineno = 0;
317 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin;
318 while ((ht < h) && (lineno < numlines-1))
319 {
320 ht += textarray[++lineno]->lineSpacing();
321 }
322 ht = textarray[lineno]->lineSpacing();
323 }
324 }
325 while ((ht < y) && (lineno < numlines-1))
216 { 326 {
217 offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; 327 ht += textarray[++lineno]->lineSpacing();
218 } 328 }
219 else 329 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines;
330 start = locnarray[lineno];
331 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
332 if (m_bMonoSpaced)
220 { 333 {
221 int i; 334 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth;
222 CDrawBuffer* t = textarray[lineno];
223 x = x - t->offset(width(), m_border);
224 for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--);
225 offset = i;
226 } 335 }
227 return textarray[lineno]->getLinkType(offset, tgt); 336 else
337 {
338 int i;
339 CDrawBuffer* t = textarray[lineno];
340 x = x - t->offset(width(), m_left_border, m_right_border, availht);
341 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--);
342 offset = i;
343 }
344 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img);
228} 345}
229 346
230void QTReader::suspend() 347void QTReader::suspend()
231{ 348{
232#ifdef OPIE 349 buffdoc.suspend();
350 /*#ifdef OPIE
233 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); 351 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
234#else 352#else
235 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); 353 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
236#endif 354#endif
355 */
237} 356}
238 357
239void QTReader::setTwoTouch(bool _b) 358void QTReader::setTwoTouch(bool _b)
240{ 359{
241 setBackgroundColor( white ); 360 setBackgroundColor( m_bg );
242 m_twotouch = m_touchone = _b; 361 m_twotouch = m_touchone = _b;
243} 362}
244 363
245void QTReader::setContinuous(bool _b) 364void QTReader::setContinuous(bool _b)
246{ 365{
247 buffdoc.unsuspend(); 366 buffdoc.unsuspend();
248 buffdoc.setContinuous(m_continuousDocument = _b); 367 buffdoc.setContinuous(m_continuousDocument = _b);
249} 368}
250 369
251void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) 370void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
252{ 371{
372 unsigned long wrdstart, wrdend;
253 QString wrd; 373 QString wrd;
374 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
254 if (m_twotouch) 375 if (m_twotouch)
255 { 376 {
256 if (m_touchone) 377 if (m_touchone)
257 { 378 {
258 m_touchone = false; 379 m_touchone = false;
259 m_startpos = startpos; 380 m_startpos = startpos;
260 m_startoffset = startoffset; 381 m_startoffset = startoffset;
261 setBackgroundColor( lightGray ); 382 setBackgroundColor( lightGray );
262 } 383 }
263 else 384 else
264 { 385 {
265 m_touchone = true; 386 m_touchone = true;
266 setBackgroundColor( white ); 387 setBackgroundColor( m_bg );
267 size_t endpos, endoffset; 388 size_t endpos, endoffset;
268 endpos = startpos; 389 endpos = startpos;
269 endoffset = startoffset; 390 endoffset = startoffset;
270 size_t currentpos = locate(); 391 size_t currentpos = locate();
271 if (endpos >= m_startpos) 392 if (endpos >= m_startpos)
272 { 393 {
273 jumpto(m_startpos); 394 jumpto(m_startpos);
274 for (int i = 0; i < m_startoffset; i++) 395 for (int i = 0; i < m_startoffset; i++)
275 { 396 {
276 getch(); 397 getch();
277 } 398 }
399 wrdstart = buffdoc.explocate();
278 if (m_startpos == endpos) 400 if (m_startpos == endpos)
279 { 401 {
280 for (int i = m_startoffset; i <= endoffset; i++) 402 for (int i = m_startoffset; i <= endoffset; i++)
281 { 403 {
282 wrd += QChar(getch()); 404 wrd += QChar(getch());
283 } 405 }
284 } 406 }
285 else 407 else
286 { 408 {
287 while (buffdoc.explocate() <= endpos) 409 while (buffdoc.explocate() <= endpos)
288 { 410 {
289 wrd += QChar(getch()); 411 wrd += QChar(getch());
290 } 412 }
291 for (int i = 0; i < endoffset; i++) 413 for (int i = 0; i < endoffset; i++)
292 { 414 {
293 wrd += QChar(getch()); 415 wrd += QChar(getch());
294 } 416 }
295 } 417 }
418 wrdend = buffdoc.explocate();
296 jumpto(currentpos); 419 jumpto(currentpos);
297 } 420 }
298 } 421 }
299 } 422 }
300 else if (m_bMonoSpaced) 423 else if (m_bMonoSpaced)
301 { 424 {
302 int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth; 425 int chno = (m_rotated) ?
426 (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth
427 :
428 (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth;
303 if (chno < ustrlen(textarray[lineno]->data())) 429 if (chno < ustrlen(textarray[lineno]->data()))
304 { 430 {
305 wrd[0] = textarray[lineno]->data()[chno]; 431 wrd[0] = textarray[lineno]->data()[chno];
306 } 432 }
307 } 433 }
308 else 434 else
309 { 435 {
310 CDrawBuffer* t = textarray[lineno]; 436 CDrawBuffer* t = textarray[lineno];
311 int first = 0; 437 int first = 0;
312 int tgt = _e->x() - t->offset(width(), m_border); 438 int tgt = (m_rotated) ?
439 _e->y() - t->offset(height(), m_left_border, m_right_border, availht) :
440 _e->x() - t->offset(width(), m_left_border, m_right_border, availht);
313 while (1) 441 while (1)
314 { 442 {
315 int i = first+1; 443 int i = first+1;
444 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
316 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 445 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
317 if (t->width(i, true, width(), m_border) > tgt) 446 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt)
318 { 447 {
319 wrd = toQString(t->data()+first, i - first); 448 wrd = toQString(t->data()+first, i - first);
320 // odebug << "Got " << (const char *)wrd << "" << oendl; 449 // qDebug("Got %s", (const char *)wrd);
321 break; 450 break;
322 } 451 }
323 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 452 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
324 if ((*t)[i] == 0) break; 453 if ((*t)[i] == 0) break;
325 first = i; 454 first = i;
326 } 455 }
327 } 456 }
328 if (!wrd.isEmpty()) 457 if (!wrd.isEmpty())
329 { 458 {
330 //odebug << "Selected:" << wrd << "" << oendl; 459 qDebug("Selecteed:%s", (const char*)wrd);
331 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); 460 if (m_twotouch)
461 {
462 emit OnWordSelected(wrd, wrdstart, wrdend, wrd);
463 }
464 else
465 {
466 QString line = toQString(textarray[lineno]->data());
467 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line);
468 }
332 } 469 }
333} 470}
334 471
335void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 472void QTReader::mouseReleaseEvent( QMouseEvent* _e )
336{ 473{
337 buffdoc.unsuspend(); 474 buffdoc.unsuspend();
475 int x, y, ht, wh;
476 if (m_rotated)
477 {
478 x = _e->y();
479 y = width()-_e->x();
480 ht = width();
481 wh = height();
482 }
483 else
484 {
485 x = _e->x();
486 y = _e->y();
487 ht = height();
488 wh = width();
489 }
338 if (_e->button() == LeftButton) 490 if (_e->button() == LeftButton)
339 { 491 {
340 if (mouseUpOn) 492 if (mouseUpOn)
341 { 493 {
342 // odebug << "MouseRelease" << oendl; 494 // qDebug("MouseRelease");
343 if (_e->x() > width() - m_border) 495 switch(m_scrollpos)
344 { 496 {
345 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height()); 497 case 1: // Bottom
346 return; 498 if (y > ht - 5)
499 {
500 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
501 return;
502 }
503 break;
504 case 2: // right
505 if (x > wh - m_right_border)
506 {
507 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
508 return;
509 }
510 break;
511 case 3: // left
512 if (x < m_left_border)
513 {
514 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
515 return;
516 }
517 break;
518 case 0:
519 default:
520 break;
347 } 521 }
348 if (textarray[0] != NULL) 522 if (textarray[0] != NULL)
349 { 523 {
350 QString line; 524 QString line;
351 // int lineno = _e->y()/m_linespacing; 525 // int lineno = _e->y()/m_linespacing;
352 int lineno = 0; 526 int lineno = 0;
527 /*
353 int ht = textarray[0]->lineSpacing(); 528 int ht = textarray[0]->lineSpacing();
354 while ((ht < _e->y()) && (lineno < numlines)) 529 while ((ht < y) && (lineno < numlines))
355 { 530 {
356 ht += textarray[++lineno]->lineSpacing(); 531 ht += textarray[++lineno]->lineSpacing();
357 } 532 }
358 size_t startpos, startoffset, tgt; 533 */
359 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) 534 size_t startpos, startoffset, tgt, tgtoffset, pictgt;
360 { 535 QImage* img;
361 case eLink: 536 if (m_currentlinkstyle != NULL)
362 { 537 {
363 size_t saveposn = pagelocate(); 538 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
364 QString href; 539 m_currentlinkstyle = NULL;
365 linkType lt = buffdoc.hyperlink(tgt, href); 540 m_currentlink = -1;
366 if (lt == eLink) 541 m_currentlinkoffset = -1;
542 }
543 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img);
544 if ((glt & eLink) != 0)
545 {
546 if ((glt & ePicture) != 0)
547 {
548 qDebug("Big Picture:%x", pictgt);
549 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
550 {
551 QImage* pm = buffdoc.getPicture(pictgt);
552 if (pm != NULL)
553 {
554 emit OnShowPicture(*pm);
555 delete pm;
556 return;
557 }
558 }
559 }
560 else if (img != NULL)
561 {
562 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
563 {
564 emit OnShowPicture(*img);
565 return;
566 }
567 }
568 size_t saveposn = pagelocate();
569 QString href, nm;
570 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
571 qDebug("URL(1):%s", (const char*)href);
572 if ((lt & eFile) != 0)
573 {
574 buffdoc.saveposn(m_lastfile, saveposn);
575#ifdef USEQPE
367 { 576 {
368 buffdoc.saveposn(saveposn); 577 QCopEnvelope e("QPE/System", "busy()");
369 fillbuffer();
370 update();
371 } 578 }
372 else 579#endif
373 { 580 ResetScroll();
374 if (lt == ePicture) 581 if (!href.isEmpty())
375 { 582 {
376 QImage* pm = buffdoc.getPicture(tgt); 583 if (!buffdoc.getFile(href))
377 if (pm != NULL) 584 {
378 { 585 emit NewFileRequest(href);
379 emit OnShowPicture(*pm); 586 }
380 delete pm;
381 }
382 }
383 else 587 else
384 { 588 {
385 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 589 ResetScroll();
386 if (!href.isEmpty()) 590 fillbuffer();
387 { 591 update();
388 emit OnURLSelected(href); 592 }
389 } 593 }
390 } 594 if (!nm.isEmpty())
391 locate(pagelocate()); 595 {
392 } 596 qDebug("QTReader:Finding %s", (const char*)nm);
393 return; 597 if (buffdoc.findanchor(nm))
394 } 598 {
395 case ePicture: 599 fillbuffer();
396 { 600 update();
397 // odebug << "Picture:" << tgt << "" << oendl; 601 }
398 QImage* pm = buffdoc.getPicture(tgt); 602 }
399 if (pm != NULL) 603 //fillbuffer();
604 //update();
605#ifdef USEQPE
400 { 606 {
401 emit OnShowPicture(*pm); 607 QCopEnvelope e("QPE/System", "notBusy()");
402 delete pm;
403 } 608 }
609#endif
610 }
611 else if ((lt & eLink) != 0)
612 {
613 buffdoc.saveposn(m_lastfile, saveposn);
614 ResetScroll();
615 fillbuffer();
616 update();
617 }
618 else
619 {
620 if ((lt & ePicture) != 0)
621 {
622 QImage* pm = buffdoc.getPicture(tgt);
623 if (pm != NULL)
624 {
625 emit OnShowPicture(*pm);
626 delete pm;
627 }
628 }
404 else 629 else
405 { 630 {
406 locate(pagelocate()); 631 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
407 } 632 if (!href.isEmpty())
408 return; 633 {
409 } 634 emit OnURLSelected(href, tgt);
410 case eNone: 635 }
411 break; 636 }
412 default: 637 locate(pagelocate());
413 // odebug << "Unknown linktype" << oendl; 638 }
414 return; 639 return;
415 } 640 }
641 else if ((glt & ePicture) != 0)
642 {
643 qDebug("Big Picture:%x", pictgt);
644 QImage* pm = buffdoc.getPicture(pictgt);
645 if (pm != NULL)
646 {
647 emit OnShowPicture(*pm);
648 delete pm;
649 }
650 else
651 {
652 locate(pagelocate());
653 }
654 return;
655 }
656 else if (img != NULL)
657 {
658 emit OnShowPicture(*img);
659 return;
660 }
416 if (m_swapmouse) 661 if (m_swapmouse)
417 processmousepositionevent(_e); 662 processmousepositionevent(_e);
418 else 663 else
419 processmousewordevent(startpos, startoffset, _e, lineno); 664 processmousewordevent(startpos, startoffset, _e, lineno);
420 } 665 }
421 } 666 }
422 else 667 else
423 { 668 {
424 mouseUpOn = true; 669 mouseUpOn = true;
425 } 670 }
426 } 671 }
427} 672}
@@ -432,24 +677,26 @@ void QTReader::focusInEvent(QFocusEvent* e)
432 update(); 677 update();
433} 678}
434 679
435void QTReader::focusOutEvent(QFocusEvent* e) 680void QTReader::focusOutEvent(QFocusEvent* e)
436{ 681{
437 if (m_autoScroll) 682 if (m_autoScroll)
438 { 683 {
439 timer->stop(); 684 timer->stop();
440 //m_scrolldy1 = m_scrolldy2 = 0; 685 //m_scrolldy1 = m_scrolldy2 = 0;
441 } 686 }
442} 687}
443 688
689#include <qapplication.h>
690#include <qdrawutil.h>
444#ifndef _WINDOWS 691#ifndef _WINDOWS
445#include <unistd.h> 692#include <unistd.h>
446#endif 693#endif
447 694
448void QTReader::goDown() 695void QTReader::goDown()
449{ 696{
450 if (m_bpagemode) 697 if (m_bpagemode)
451 { 698 {
452 dopagedn(); 699 dopagedn();
453 } 700 }
454 else 701 else
455 { 702 {
@@ -505,412 +752,1153 @@ void QTReader::NavDown()
505 } 752 }
506 else 753 else
507 { 754 {
508 goDown(); 755 goDown();
509 } 756 }
510} 757}
511 758
512void QTReader::zoomin() 759void QTReader::zoomin()
513{ 760{
514 if (m_fontControl.increasesize()) 761 if (m_fontControl.increasesize())
515 { 762 {
516 bool sc = m_autoScroll; 763 bool sc = m_autoScroll;
764 setautoscroll(false);
517 setfont(); 765 setfont();
518 m_autoScroll = false;
519 locate(pagelocate()); 766 locate(pagelocate());
520 update(); 767 repaint();
521 m_autoScroll = sc; 768 setautoscroll(sc);
522 if (m_autoScroll) autoscroll();
523 } 769 }
524} 770}
525 771
526void QTReader::zoomout() 772void QTReader::zoomout()
527{ 773{
528 if (m_fontControl.decreasesize()) 774 if (m_fontControl.decreasesize())
529 { 775 {
530 bool sc = m_autoScroll; 776 bool sc = m_autoScroll;
531 m_autoScroll = false; 777 setautoscroll(false);
532 setfont(); 778 setfont();
533 locate(pagelocate()); 779 locate(pagelocate());
534 update(); 780 repaint();
535 m_autoScroll = sc; 781 setautoscroll(sc);
536 if (m_autoScroll) autoscroll();
537 } 782 }
538} 783}
539 784
540void QTReader::reduceScroll() 785void QTReader::reduceScroll()
541{ 786{
542 if (m_delay < 59049) 787 if (m_delay < 59049)
543 { 788 {
544 m_delay = (3*m_delay)/2; 789 m_delay = (3*m_delay)/2;
545 timer->changeInterval(real_delay()); 790 timer->changeInterval(real_delay());
546 } 791 }
547 else 792 else
548 { 793 {
549 m_delay = 59049; 794 m_delay = 59049;
550 } 795 }
551} 796}
552 797
553void QTReader::increaseScroll() 798void QTReader::increaseScroll()
554{ 799{
555 if (m_delay > 1024) 800 if (m_delay > 454)
556 { 801 {
557 m_delay = (2*m_delay)/3; 802 m_delay = (2*m_delay)/3;
558 timer->changeInterval(real_delay()); 803 timer->changeInterval(real_delay());
559 } 804 }
560 else 805 else
561 { 806 {
562 m_delay = 1024; 807 m_delay = 454;
563 } 808 }
564} 809}
565 810
566void QTReader::keyPressEvent(QKeyEvent* e) 811void QTReader::keyPressEvent(QKeyEvent* e)
567{ 812{
568 buffdoc.unsuspend(); 813 buffdoc.unsuspend();
569 ((QTReaderApp*)parent()->parent())->handlekey(e); 814
815 //((QTReaderApp*)parent()->parent())->handlekey(e);
816 emit HandleKeyRequest(e);
570// e->ignore(); 817// e->ignore();
571 return; 818 return;
572#ifdef _SCROLLPIPE 819#ifdef _SCROLLPIPE
573 if (m_isPaused) 820 if (m_isPaused)
574 { 821 {
575 m_isPaused = false; 822 m_isPaused = false;
576 if (e->key() != Key_Space) 823 if (e->key() != Key_Space)
577 { 824 {
578 m_autoScroll = false; 825 m_autoScroll = false;
579 if (m_pipeout != NULL) 826 if (m_pipeout != NULL)
580 { 827 {
581 pclose(m_pipeout); 828 pclose(m_pipeout);
582 m_pipeout = NULL; 829 m_pipeout = NULL;
583 } 830 }
584 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 831 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
832 emit SetScrollState(m_autoScroll);
585 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 833 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
586 } 834 }
587 else 835 else
588 { 836 {
589 timer->start(real_delay(), false); 837 timer->start(real_delay(), false);
590 } 838 }
591 e->accept(); 839 e->accept();
592 return; 840 return;
593 } 841 }
594#endif 842#endif
595/* 843}
596 switch (e->key()) 844
845void QTReader::CalculateScrollParameters()
846{
847 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
848 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
849 switch (m_scrolltype)
597 { 850 {
598 case Key_Down: 851 case 0:
599 { 852 {
600 e->accept(); 853 if (m_scrolldy == m_topmargin)
601 if (m_autoScroll)
602 { 854 {
603 if (m_delay < 59049) 855 m_scrolldy1 = 0;
604 { 856 m_scrolldy2 = 0;
605 m_delay = (3*m_delay)/2; 857 m_totalscroll = 0;
606 timer->changeInterval(real_delay()); 858 return;
607 }
608 else
609 {
610 m_delay = 59049;
611 }
612 } 859 }
613 else 860 if (m_scrolldy < textarray[0]->lineSpacing())
614 { 861 {
615 goDown(); 862 m_scrolldy2 = m_scrolldy;
863 return;
616 } 864 }
617 } 865 int ht = m_scrolldy - m_scrolldy1;
618 break; 866 int i;
619 case Key_Up: 867 for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++)
620 {
621 e->accept();
622 if (m_autoScroll)
623 { 868 {
624 if (m_delay > 1024) 869 ht += textarray[i]->lineSpacing();
625 {
626 m_delay = (2*m_delay)/3;
627 timer->changeInterval(real_delay());
628 }
629 else
630 {
631 m_delay = 1024;
632 }
633 } 870 }
634 else 871 ht = 0;
872 int j;
873 i--;
874 for (j = i; j < numlines; j++)
635 { 875 {
636 goUp(); 876 ht += textarray[j]->lineSpacing();
637 } 877 }
638 } 878 ht -= (
879 textarray[i]->lineExtraSpacing()
880 +
881 (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0
882 )/2-2;
883
884 m_scrolldy2 = m_scrolldy-ht;
885 }
886 break;
887 case 1:
888 case 2:
889 case 3:
890 {
891 int ypos = m_topmargin;
892 for (int i = 0; i < numlines; i++)
893 {
894 ypos += textarray[i]->lineSpacing();
895 }
896 ypos -= (
897 textarray[0]->lineExtraSpacing()
898 +
899 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0)
900 )/2 +
901 m_scrolldy1 - 2;
902 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin;
903 }
639 break; 904 break;
640 case Key_Right:
641 {
642 e->accept();
643 if (m_navkeys && buffdoc.hasnavigation())
644 {
645 size_t target = pagelocate();
646 if (buffdoc.forward(target))
647 {
648 locate(target);
649 }
650 }
651 else zoomin();
652 }
653 break;
654 case Key_Left:
655 {
656 e->accept();
657 if (m_navkeys && buffdoc.hasnavigation())
658 {
659 size_t target = pagelocate();
660 if (buffdoc.back(target))
661 {
662 locate(target);
663 }
664 }
665 else zoomout();
666 }
667 break;
668 default:
669 e->ignore();
670 } 905 }
671*/
672} 906}
673 907
674void QTReader::setautoscroll(bool _sc) 908void QTReader::setautoscroll(bool _sc)
675{ 909{
676 if (_sc == m_autoScroll) return; 910 if (_sc == m_autoScroll) return;
677 if (m_autoScroll) 911 if (m_autoScroll)
678 { 912 {
679 m_autoScroll = false; 913 m_autoScroll = false;
680#ifdef USEQPE 914#ifdef USEQPE
681 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 915 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
682#endif 916#endif
683#ifdef _SCROLLPIPE 917#ifdef _SCROLLPIPE
684 if (m_pipeout != NULL) 918 if (m_pipeout != NULL)
685 { 919 {
686 pclose(m_pipeout); 920 pclose(m_pipeout);
687 m_pipeout = NULL; 921 m_pipeout = NULL;
688 } 922 }
689#endif 923#endif
924 //m_scrolldy1 = 0;
925 //refresh();
690 } 926 }
691 else 927 else
692 { 928 {
693 CDrawBuffer* reusebuffer = textarray[numlines]; 929 CDrawBuffer* reusebuffer = textarray[numlines];
694 if (reusebuffer == NULL || reusebuffer->eof()) return; 930 if (reusebuffer == NULL || reusebuffer->eof()) return;
695 m_autoScroll = true; 931 m_autoScroll = true;
932 CalculateScrollParameters();
933
696#ifdef _SCROLLPIPE 934#ifdef _SCROLLPIPE
697 if (!m_pipetarget.isEmpty()) 935 if (!m_pipetarget.isEmpty())
698 { 936 {
699 // odebug << "Opening pipe to " << m_pipetarget << "" << oendl; 937 // qDebug("Opening pipe to %s", (const char*)m_pipetarget);
700 m_pipeout = popen((const char*)m_pipetarget, "w"); 938 m_pipeout = popen((const char*)m_pipetarget, "w");
701 m_isPaused = false; 939 m_isPaused = false;
702 } 940 }
703#endif 941#endif
704 autoscroll(); 942 autoscroll();
705#ifdef USEQPE 943#ifdef USEQPE
706 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed 944 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
707#endif 945#endif
708 } 946 }
709} 947}
710 948
711bool QTReader::getline(CDrawBuffer *buff) 949bool QTReader::getline(CDrawBuffer *buff)
712{ 950{
713 buffdoc.unsuspend(); 951 buffdoc.unsuspend();
952 bool bRet;
953 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
714 if (m_bMonoSpaced) 954 if (m_bMonoSpaced)
715 { 955 {
716 return buffdoc.getline(buff ,width(), m_charWidth, m_border); 956 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
717 } 957 }
718 else 958 else
719 { 959 {
720 return buffdoc.getline(buff, width(), m_border); 960 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht);
721 } 961 }
962 buff->resize(availht);
963 return bRet;
722} 964}
723 965
724void QTReader::doscroll() 966void QTReader::doscroll()
725{ 967{
726 if (!m_autoScroll) 968 if (!m_autoScroll)
727 { 969 {
728 timer->stop(); 970 timer->stop();
729 return; 971 return;
730 } 972 }
731// timer->changeInterval(real_delay()); 973 switch (m_scrolltype)
974 {
975 case 0:
976 doinplacescroll();
977 break;
978 case 1:
979 dorollingscroll(false);
980 break;
981 case 2:
982 dorollingscroll(true);
983 break;
984 case 3:
985 dostaticscroll();
986 break;
987 }
988}
989
990void QTReader::doinplacescroll()
991{
992 QPainter p( this );
993 // p.setBackgroundMode(OpaqueMode);
994 int wh, ht;
995 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
996 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
997 if (m_rotated)
998 {
999 ht = width()-bmargin;
1000 wh = height();
1001 }
1002 else
1003 {
1004 ht = height()-bmargin;
1005 wh = width();
1006 }
1007 int lastdy = m_scrolldy;
1008 m_scrolldy += m_scrollstep;
1009 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1010 {
1011 int ht = textarray[0]->lineSpacing();
1012#ifdef _SCROLLPIPE
1013 if (m_pipeout != NULL)
1014 {
1015 QString outstr = toQString(textarray[0]->data());
1016 if (!outstr.isEmpty())
1017 {
1018 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1019 fflush(m_pipeout);
1020 }
1021 else if (m_pauseAfterEachPara)
1022 {
1023 m_isPaused = true;
1024 timer->stop();
1025 }
1026 }
1027#endif
1028 CDrawBuffer* buff = textarray[0];
1029 for (int i = 1; i <= numlines; i++)
1030 {
1031 textarray[i-1] = textarray[i];
1032 locnarray[i-1] = locnarray[i];
1033 }
1034 textarray[numlines] = buff;
1035 --numlines;
1036 m_scrolldy1 -= ht;
1037 }
1038 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
1039 {
1040 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1041 numlines++;
1042
1043 if (textarray[numlines] == NULL)
1044 {
1045 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1046 }
1047 locnarray[numlines] = locate();
1048 int ch = getline(textarray[numlines]);
1049 if (m_rotated)
1050 {
1051 blitRot(width()-m_scrolldy, 0, height(), -1, textarray[numlines-1]);
1052 }
1053 else
1054 {
1055 if (m_bgpm.isNull())
1056 {
1057 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg);
1058 }
1059 else
1060 {
1061 int h_tmp = textarray[numlines-1]->lineSpacing();
1062 bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp);
1063 }
1064 textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1065 }
1066 mylastpos = locate();
1067 if (!ch)
1068 {
1069 /*
1070 if (m_rotated)
1071 {
1072 blitRot2(0,0,height(),width()-m_scrolldy,NULL);
1073 // blitRot2(0,0,0,height(),width()-m_scrolldy,NULL);
1074 }
1075 else
1076 {
1077 if (m_bgpm.isNull())
1078 {
1079 p.fillRect(0,m_scrolldy,width(),height()-m_scrolldy,m_bg);
1080 }
1081 else
1082 {
1083 bitBlt(this, 0, m_scrolldy, dbuff, 0, m_scrolldy, width(), height()-m_scrolldy);
1084 }
1085 }
1086 */
1087 m_scrolldy = m_topmargin;
1088 m_autoScroll = false;
1089#ifdef _SCROLLPIPE
1090 for (int i = 0; i < numlines; i++)
1091 {
1092 if (m_pipeout != NULL)
1093 {
1094 QString outstr = toQString(textarray[i]->data());
1095 if (!outstr.isEmpty())
1096 {
1097 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1098 fflush(m_pipeout);
1099 }
1100 }
1101 }
1102#endif
1103 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
1104 emit SetScrollState(m_autoScroll);
1105#ifdef USEQPE
1106 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1107#endif
1108 }
1109 if (m_scrolldy > ht-textarray[numlines]->lineSpacing())
1110 {
1111 if (m_rotated)
1112 {
1113 if (m_bgpm.isNull())
1114 {
1115 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg);
1116 }
1117 else
1118 {
1119 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL);
1120 }
1121 }
1122 else
1123 if (m_bgpm.isNull())
1124 {
1125 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),height()-m_scrolldy,m_bg);
1126 }
1127 else
1128 {
1129 bitBlt(this,m_left_border,m_scrolldy,dbuff,m_left_border,m_scrolldy,width()-(m_left_border+m_right_border), height()-m_scrolldy);
1130 }
1131 m_scrolldy = m_topmargin;
1132 m_scrolldy2 = 0;
1133 }
1134 redrawScroll(&p);
1135 emitRedraw();
1136 lastdy = -1;
1137 }
1138 // else
1139 {
1140 if (m_rotated)
1141 {
1142 if (lastdy >= 0)
1143 {
1144 if (m_bgpm.isNull())
1145 {
1146 p.fillRect(width()-lastdy, m_left_border, m_scrollstep, wh-(m_left_border+m_right_border),m_bg);
1147 }
1148 else
1149 {
1150 blitRot(width()-lastdy,m_left_border,wh-(m_left_border+m_right_border), m_scrollstep, NULL);
1151 }
1152 }
1153 p.fillRect(width()-m_scrolldy, m_left_border, 1,wh-(m_left_border+m_right_border),m_scrollcolor);
1154 }
1155 else
1156 {
1157 if (lastdy >= 0)
1158 {
1159 if (m_bgpm.isNull())
1160 {
1161 p.fillRect(m_left_border,lastdy,width()-(m_left_border+m_right_border),m_scrollstep,m_bg);
1162 }
1163 else
1164 {
1165 bitBlt(this, m_left_border, lastdy, dbuff, m_left_border, lastdy, width()-(m_left_border+m_right_border), m_scrollstep);
1166 }
1167 }
1168 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),1,m_scrollcolor);
1169 }
1170 }
1171}
1172
1173void QTReader::dorollingscroll(bool _statbord)
1174{
1175 bool bredrawscroll = false;
732 QPainter p( this ); 1176 QPainter p( this );
733 QBrush b( white); 1177 // 2 = right, 3 = left
734 bitBlt(this,0,0,this,0,1,width(),-1); 1178 int tmargin = (_statbord) ? m_topmargin : 0;
735 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); 1179 int lmargin = (m_scrollpos == 3 || _statbord) ? m_left_border : 0;
1180 int rmargin = (m_scrollpos == 2 || _statbord) ? m_right_border : 0;
1181 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1182 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1183 if (m_rotated)
1184 {
1185 m_totalscroll = (m_totalscroll+m_scrollstep) % width();
1186 bitBlt(this, m_scrollstep+hmargin, lmargin, this, hmargin, lmargin, width()-tmargin-hmargin, height()-(lmargin+rmargin));
1187 if (!m_bgpm.isNull())
1188 {
1189 blitRot(hmargin, tmargin, height(), m_scrollstep, NULL);
1190 }
1191 else
1192 {
1193 p.fillRect(hmargin, rmargin, m_scrollstep, height()-lmargin-rmargin, m_bg);
1194 }
1195 }
1196 else
1197 {
1198 m_totalscroll = (m_totalscroll+m_scrollstep) % height();
1199 bitBlt(this,lmargin,tmargin,this,lmargin,tmargin+m_scrollstep,width()-(lmargin+rmargin),height() - tmargin - hmargin - m_scrollstep);
1200 if (m_bgpm.isNull())
1201 {
1202 p.fillRect(0, height() - (m_scrollstep+1) - hmargin, width(), (m_scrollstep+1), m_bg);
1203 }
1204 else
1205 {
1206 int loff = (_statbord) ? 0 : m_totalscroll;
1207 bitBlt(this,0,height() - (m_scrollstep+1) - hmargin, dbuff, 0, (loff+height() - (m_scrollstep+1) - hmargin) % height(), width(), (m_scrollstep+1));
1208 }
1209 }
736 1210
737 if (++m_scrolldy1 == textarray[0]->lineSpacing()) 1211 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
738 { 1212 {
1213 int ht = textarray[0]->lineSpacing();
1214 bredrawscroll = true;
739#ifdef _SCROLLPIPE 1215#ifdef _SCROLLPIPE
740 if (m_pipeout != NULL) 1216 if (m_pipeout != NULL)
741 { 1217 {
742 QString outstr = toQString(textarray[0]->data()); 1218 QString outstr = toQString(textarray[0]->data());
743 if (!outstr.isEmpty()) 1219 if (!outstr.isEmpty())
744 { 1220 {
745 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1221 fprintf(m_pipeout, "%s\n", (const char*)outstr);
746 fflush(m_pipeout); 1222 fflush(m_pipeout);
747 } 1223 }
748 else if (m_pauseAfterEachPara) 1224 else if (m_pauseAfterEachPara)
749 { 1225 {
750 m_isPaused = true; 1226 m_isPaused = true;
751 timer->stop(); 1227 timer->stop();
752 } 1228 }
753 // write(m_pipeout, (const char*)outstr, outstr.length());
754 // write(m_pipeout, "\n", 1);
755 // fputc(10, m_pipeout);
756 } 1229 }
757#endif 1230#endif
758 CDrawBuffer* buff = textarray[0]; 1231 CDrawBuffer* buff = textarray[0];
759 for (int i = 1; i <= numlines; i++) 1232 for (int i = 1; i <= numlines; i++)
760 { 1233 {
761 textarray[i-1] = textarray[i]; 1234 textarray[i-1] = textarray[i];
762 locnarray[i-1] = locnarray[i]; 1235 locnarray[i-1] = locnarray[i];
763 } 1236 }
764 textarray[numlines] = buff; 1237 textarray[numlines] = buff;
765 --numlines; 1238 --numlines;
766 m_scrolldy1 = 0; 1239 m_scrolldy1 -= ht;
767 } 1240 }
768 if (++m_scrolldy2 == textarray[numlines]->lineSpacing()) 1241 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
769 { 1242 {
770 m_scrolldy2 = 0; 1243 bredrawscroll = true;
1244 m_scrolldy2 -= textarray[numlines]->lineSpacing();
771 numlines++; 1245 numlines++;
772 1246
773 if (textarray[numlines] == NULL) 1247 if (textarray[numlines] == NULL)
774 { 1248 {
775 textarray[numlines] = new CDrawBuffer(&m_fontControl); 1249 textarray[numlines] = new CDrawBuffer(&m_fontControl);
776 } 1250 }
777 locnarray[numlines] = locate(); 1251 locnarray[numlines] = locate();
778 int ch = getline(textarray[numlines]); 1252 int ch = getline(textarray[numlines]);
779 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border); 1253 if (m_rotated)
1254 {
1255 blitRot(hmargin, 0, height(), -1, textarray[numlines-1]);
1256 }
1257 else
1258 {
1259 // textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg);
1260 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - textarray[numlines-1]->lineExtraSpacing() - 1 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1261
1262 }
780 mylastpos = locate(); 1263 mylastpos = locate();
781 if (!ch) 1264 if (!ch)
782 { 1265 {
1266 redrawScroll(&p);
1267 emitRedraw();
783 m_autoScroll = false; 1268 m_autoScroll = false;
784#ifdef _SCROLLPIPE 1269#ifdef _SCROLLPIPE
785 for (int i = 0; i < numlines; i++) 1270 for (int i = 0; i < numlines; i++)
786 { 1271 {
787 if (m_pipeout != NULL) 1272 if (m_pipeout != NULL)
788 { 1273 {
789 QString outstr = toQString(textarray[i]->data()); 1274 QString outstr = toQString(textarray[i]->data());
790 if (!outstr.isEmpty()) 1275 if (!outstr.isEmpty())
791 { 1276 {
792 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1277 fprintf(m_pipeout, "%s\n", (const char*)outstr);
793 fflush(m_pipeout); 1278 fflush(m_pipeout);
794 } 1279 }
795 } 1280 }
796 } 1281 }
797#endif 1282#endif
798 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 1283 emit SetScrollState(m_autoScroll);
799#ifdef USEQPE 1284#ifdef USEQPE
800 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1285 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
801#endif 1286#endif
1287 return;
802 } 1288 }
803 emit OnRedraw();
804 } 1289 }
1290 if (!bredrawscroll && ((m_scrolldy2/m_scrollstep) % 10 == 5) && textarray[numlines]->showPartial())
1291 {
1292 if (m_rotated)
1293 {
1294 blitRot(hmargin + m_scrolldy2 - textarray[numlines]->lineSpacing(), 0, height(), -1, textarray[numlines]);
1295 }
1296 else
1297 {
1298 textarray[numlines]->render( &p, height() + textarray[numlines]->lineSpacing() - textarray[numlines]->descent() - 2 - hmargin-m_scrolldy2, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1299 }
1300 }
1301 if (m_scrollpos != 0)
1302 {
1303 redrawScroll(&p);
1304 }
1305 if (bredrawscroll) emitRedraw();
1306}
1307
1308void QTReader::dostaticscroll()
1309{
1310 redrawall();
1311 bool bredraw = false;
1312 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1313 {
1314 int ht = textarray[0]->lineSpacing();
1315 bredraw = true;
1316#ifdef _SCROLLPIPE
1317 if (m_pipeout != NULL)
1318 {
1319 QString outstr = toQString(textarray[0]->data());
1320 if (!outstr.isEmpty())
1321 {
1322 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1323 fflush(m_pipeout);
1324 }
1325 else if (m_pauseAfterEachPara)
1326 {
1327 m_isPaused = true;
1328 timer->stop();
1329 }
1330 }
1331#endif
1332 CDrawBuffer* buff = textarray[0];
1333 for (int i = 1; i <= numlines; i++)
1334 {
1335 textarray[i-1] = textarray[i];
1336 locnarray[i-1] = locnarray[i];
1337 }
1338 textarray[numlines] = buff;
1339 --numlines;
1340 m_scrolldy1 -= ht;
1341 }
1342 if ((m_scrolldy2 = m_scrolldy2 + m_scrollstep) >= textarray[numlines]->lineSpacing())
1343 {
1344 bredraw = true;
1345 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1346 numlines++;
1347
1348 if (textarray[numlines] == NULL)
1349 {
1350 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1351 }
1352 locnarray[numlines] = locate();
1353 int ch = getline(textarray[numlines]);
1354 mylastpos = locate();
1355 if (!ch)
1356 {
1357 redrawall();
1358 emitRedraw();
1359 m_autoScroll = false;
1360#ifdef _SCROLLPIPE
1361 for (int i = 0; i < numlines; i++)
1362 {
1363 if (m_pipeout != NULL)
1364 {
1365 QString outstr = toQString(textarray[i]->data());
1366 if (!outstr.isEmpty())
1367 {
1368 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1369 fflush(m_pipeout);
1370 }
1371 }
1372 }
1373#endif
1374 emit SetScrollState(m_autoScroll);
1375#ifdef USEQPE
1376 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1377#endif
1378 return;
1379 }
1380 }
1381 if (bredraw) emitRedraw();
1382}
1383
1384void QTReader::redrawScroll(QPainter* p)
1385{
1386 int offset = (m_scrolltype == 1) ? m_totalscroll : 0;
1387 switch (m_scrollpos)
1388 {
1389 case 1:
1390 {
1391 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1392 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1393 if (m_rotated)
1394 {
1395 if (m_bgpm.isNull())
1396 {
1397 p->fillRect(0,0,hmargin,height(),m_bg);
1398 }
1399 else
1400 {
1401 blitRot(0,0, height(), hmargin, NULL);
1402 }
1403 }
1404 else
1405 {
1406 if (m_bgpm.isNull())
1407 {
1408 p->fillRect(0,height() - hmargin,width(),hmargin,m_bg);
1409 }
1410 else
1411 {
1412 int toffset = (offset+height()-hmargin) % height();
1413 if (toffset+hmargin > height())
1414 {
1415 int fp = height()-toffset;
1416 bitBlt(this,
1417 0,height() - hmargin,
1418 dbuff,
1419 0, toffset, width(), fp);
1420 bitBlt(this,
1421 0,height()-hmargin+fp,
1422 dbuff,
1423 0, 0, width(), hmargin-fp);
1424 }
1425 else
1426 {
1427 bitBlt(this,
1428 0,height() - hmargin,
1429 dbuff,
1430 0, toffset, width(), hmargin);
1431 }
1432 }
1433 }
1434 }
1435 break;
1436 case 2: //right
1437 if (m_rotated)
1438 {
1439 if (m_bgpm.isNull())
1440 {
1441 p->fillRect(0,height()-m_right_border,width(),m_right_border,m_bg);
1442 }
1443 else
1444 {
1445 blitRot(0,height()-m_right_border, m_right_border, width(), NULL);
1446 }
1447 }
1448 else
1449 {
1450 if (m_bgpm.isNull())
1451 {
1452 p->fillRect(width()-m_right_border,0,m_right_border,height(),m_bg);
1453 }
1454 else
1455 {
1456 int x = width() - m_right_border;
1457 int fp = height()-offset;
1458 bitBlt(this, x, 0, dbuff, x, offset, m_right_border, fp);
1459 bitBlt(this, x, fp, dbuff, x, 0, m_right_border, height()-fp);
1460 }
1461 }
1462 break;
1463 case 3: //left
1464 if (m_rotated)
1465 {
1466 if (m_bgpm.isNull())
1467 {
1468 p->fillRect(0,0,width(),m_left_border,m_bg);
1469 }
1470 else
1471 {
1472 blitRot(0,0, m_left_border, width(), NULL);
1473 }
1474 }
1475 else
1476 {
1477 if (m_bgpm.isNull())
1478 {
1479 p->fillRect(0,0,m_left_border,height(),m_bg);
1480 }
1481 else
1482 {
1483 int fp = height()-offset;
1484 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp);
1485 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp);
1486 }
1487 }
1488 break;
1489 case 0:
1490 default:
1491 break;
1492 }
1493 if (m_scrollpos != 0) DrawScroll(p, width(), height());
805} 1494}
806 1495
807void QTReader::autoscroll() 1496void QTReader::autoscroll()
808{ 1497{
809 timer->start(real_delay(), false); 1498 drawBackground();
1499 dbp->end();
1500 timer->start(real_delay(), false);
810} 1501}
811 1502
812void QTReader::setfont() 1503void QTReader::setfont()
813{ 1504{
814// m_fontControl.Change 1505// m_fontControl.Change
815 m_charWidth = (m_charpc*m_fontControl.currentsize())/100; 1506 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
816 if (m_charWidth <= 0) m_charWidth = 1; 1507 if (m_charWidth <= 0) m_charWidth = 1;
817 m_ascent = m_fontControl.ascent(); 1508 m_ascent = m_fontControl.ascent();
818 m_descent = m_fontControl.descent(); 1509 m_descent = m_fontControl.descent();
819 m_linespacing = m_fontControl.lineSpacing(); 1510 m_linespacing = m_fontControl.lineSpacing();
820} 1511}
821 1512
822void QTReader::drawFonts( QPainter *p ) 1513void QTReader::DrawStraight(QPainter* p, int w, int h)
1514{
1515 if (m_scrolldy == m_topmargin)
1516 {
1517 int ypos = textarray[0]->ascent()-m_scrolldy1+m_topmargin;
1518 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1519 int i;
1520 for (i = 1; i < numlines; i++)
1521 {
1522 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1523 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1524 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1525 }
1526 if (textarray[i]->showPartial())
1527 {
1528 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1529 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1530 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1531 }
1532 }
1533 else
1534 {
1535 int ypos = textarray[0]->ascent()-m_scrolldy1+m_scrolldy+m_topmargin;
1536 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1537 // p->fillRect(m_border, 0, w-2*m_border, m_scrolldy, m_bg);
1538 for (int i = 1; i < numlines; i++)
1539 {
1540 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1541 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1542 if (ypos+textarray[i]->descent() > h)
1543 {
1544 ypos = textarray[i]->ascent();
1545 }
1546 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1547 }
1548 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor);
1549 }
1550 bool wasrotated = m_rotated;
1551 m_rotated = false;
1552 DrawScroll(p, w, h);
1553 m_rotated = wasrotated;
1554
1555}
1556
1557void QTReader::redrawall()
1558{
1559 if (m_rotated)
1560 {
1561#ifdef DOUBLEBUFFER
1562 drawBackground();
1563 DrawStraight(dbp, height(), width());
1564 dbp->end();
1565
1566 QWMatrix m;
1567 m.rotate(90);
1568 QPixmap rp = dbuff->xForm(m);
1569 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1570#else
1571 QPixmap dbuff(height(), width());
1572 QPainter dbp(&dbuff);
1573 // dbp.setBackgroundMode(OpaqueMode);
1574 dbp.fillRect(dbuff.rect(), m_bg);
1575
1576 DrawStraight(&dbp, height(), width());
1577
1578 QWMatrix m;
1579 m.rotate(90);
1580 QPixmap rp = dbuff.xForm(m);
1581 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1582#endif
1583 }
1584 else
1585 {
1586#ifdef DOUBLEBUFFER
1587 drawBackground();
1588 DrawStraight(dbp, width(), height());
1589 dbp->end();
1590 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1591#else
1592 DrawStraight(p, width(), height());
1593#endif
1594 }
1595}
1596
1597void QTReader::drawFonts()
823{ 1598{
824 if (bDoUpdates) 1599 if (bDoUpdates)
825 { 1600 {
826 //odebug << "How refreshing..." << oendl; 1601 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1602 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1603 //qDebug("How refreshing...");
827 if (buffdoc.empty()) return; 1604 if (buffdoc.empty()) return;
828 setfont(); 1605 setfont();
1606 //if (!m_autoScroll) m_scrolldy1 = 0;
1607#ifdef ROTATION_ENABLED
1608 if (m_lastwidth != ((m_rotated) ? height() : width()))
1609 {
1610 m_scrolldy = m_topmargin;
1611 // qDebug("Not Optimised %d", m_lastwidth);
1612 m_lastwidth = ((m_rotated) ? height() : width());
1613 m_lastheight = ((m_rotated) ? width() : height());
1614 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1615 locate(pagelocate());
1616 // qDebug("Not Optimised %d", m_lastwidth);
1617 }
1618 else
1619 {
1620 int newht = ((m_rotated) ? width() : height());
1621 if (m_lastheight > newht)
1622 {
1623 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1624 m_scrolldy = m_topmargin;
1625 int ypos = m_scrolldy1+m_topmargin;
1626 for (int i = 0; i < numlines; i++)
1627 {
1628 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1629 {
1630 numlines = i;
1631 jumpto(mylastpos = locnarray[i+1]);
1632 break;
1633 }
1634 }
1635 // qDebug("Optimised < %d", numlines);
1636 m_lastheight = newht;
1637 }
1638 else if (m_lastheight < newht)
1639 {
1640 m_scrolldy = m_topmargin;
1641 // qDebug("Optimised > %d", numlines);
1642 int ypos = m_scrolldy1+m_topmargin;
1643 for (int i = 0; i <= numlines; i++)
1644 {
1645 ypos += textarray[i]->lineSpacing();
1646 }
1647 fillbuffer(numlines+1, ypos, newht);
1648 // qDebug("Optimised > %d", numlines);
1649 }
1650 if (numlines > 0)
1651 {
1652 redrawall();
1653 }
1654 }
1655#else
829 if (m_lastwidth != width()) 1656 if (m_lastwidth != width())
830 { 1657 {
831 // odebug << "Not Optimised " << m_lastwidth << "" << oendl; 1658 // qDebug("Not Optimised %d", m_lastwidth);
832 m_lastwidth = width(); 1659 m_lastwidth = width();
833 m_lastheight = height(); 1660 m_lastheight = height();
834 buffdoc.setwidth(m_lastwidth-2*m_border); 1661 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
835 locate(pagelocate()); 1662 locate(pagelocate());
836 // odebug << "Not Optimised " << m_lastwidth << "" << oendl; 1663 // qDebug("Not Optimised %d", m_lastwidth);
837 } 1664 }
838 else 1665 else
839 { 1666 {
840 int newht = height(); 1667 int newht = height();
841 if (m_lastheight > newht) 1668 if (m_lastheight > newht)
842 { 1669 {
843 // odebug << "Optimised < " << numlines << " " << m_lastheight << " " << newht << "" << oendl; 1670 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
844 int ypos = 0; 1671 int ypos = m_topmargin;
845 for (int i = 0; i < numlines; i++) 1672 for (int i = 0; i < numlines; i++)
846 { 1673 {
847 if ((ypos += textarray[i]->lineSpacing()) > newht) 1674 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
848 { 1675 {
849 numlines = i; 1676 numlines = i;
850 jumpto(mylastpos = locnarray[i+1]); 1677 jumpto(mylastpos = locnarray[i+1]);
851 break; 1678 break;
852 } 1679 }
853 } 1680 }
854 // odebug << "Optimised < " << numlines << "" << oendl; 1681 // qDebug("Optimised < %d", numlines);
855 m_lastheight = newht; 1682 m_lastheight = newht;
856 } 1683 }
857 else if (m_lastheight < newht) 1684 else if (m_lastheight < newht)
858 { 1685 {
859 // odebug << "Optimised > " << numlines << "" << oendl; 1686 // qDebug("Optimised > %d", numlines);
860 int ypos = 0; 1687 int ypos = m_topmargin;
861 for (int i = 0; i <= numlines; i++) 1688 for (int i = 0; i <= numlines; i++)
862 { 1689 {
863 ypos += textarray[i]->lineSpacing(); 1690 ypos += textarray[i]->lineSpacing();
864 } 1691 }
865 fillbuffer(numlines+1, ypos, newht); 1692 fillbuffer(numlines+1, ypos, newht);
866 // odebug << "Optimised > " << numlines << "" << oendl; 1693 // qDebug("Optimised > %d", numlines);
867 } 1694 }
868 if (numlines > 0) 1695 if (numlines > 0)
869 { 1696 {
870 int ypos = textarray[0]->ascent(); 1697 int ypos = textarray[0]->ascent()+m_topmargin;
871 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); 1698 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
872 // int last = (m_showlast) ? numlines : numlines-1; 1699 // int last = (m_showlast) ? numlines : numlines-1;
873 // for (int i = 1; i <= last; i++) 1700 // for (int i = 1; i <= last; i++)
874 for (int i = 1; i < numlines; i++) 1701 for (int i = 1; i < numlines; i++)
875 { 1702 {
876 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; 1703 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
877 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ 1704 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
878 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 1705 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
879 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); 1706 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
880 } 1707 }
881// mylastpos = locate(); 1708// mylastpos = locate();
882 } 1709 }
883 } 1710 }
1711#endif
1712 emitRedraw();
1713 }
1714/*
1715 else
1716 {
1717 qDebug("Not so refreshing...");
1718 }
1719*/
1720}
884 1721
885 m_scrolldy1 = m_scrolldy2 = m_scrollpart; 1722void QTReader::DrawScroll( QPainter *p, int _w, int _h )
886 if (m_border > 5 && !buffdoc.empty()) 1723{
1724 if (!buffdoc.empty())
1725 {
1726 QBrush checkered = QBrush( Dense4Pattern );
1727 checkered.setColor(m_scrollbarcolor);
1728 switch (m_scrollpos)
1729 {
1730 case 1:
1731 if (m_rotated)
1732 {
1733 p->fillRect(0, 0, 2, _h, checkered);
1734 }
1735 else
1736 {
1737 p->fillRect(0, _h-2, _w, 2, checkered);
1738 }
1739 break;
1740 case 2:
1741 if (m_rotated)
1742 {
1743 p->fillRect(0, _h-2, _w, 2, checkered);
1744 }
1745 else
1746 {
1747 p->fillRect(_w-2, 0, 2, _h, checkered);
1748 }
1749 break;
1750 case 3:
1751 if (m_rotated)
1752 {
1753 p->fillRect(0, 0, _w, 2, checkered);
1754 }
1755 else
1756 {
1757 p->fillRect(0, 0, 2, _h, checkered);
1758 }
1759 break;
1760 case 0:
1761 default:
1762 break;
1763 }
1764 switch (m_scrollpos)
887 { 1765 {
888 p->fillRect(width()-2, 0, 2, height(), cyan); 1766 case 1:
1767 {
1768 int ht;
1769 if (m_rotated)
1770 {
1771 ht = _h;
1772 }
1773 else
1774 {
1775 ht = _w;
1776 }
1777 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
1778 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
1779 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
1780 int sliderpos;
1781 if (sliderheight < 10)
1782 {
1783 sliderheight = 10;
1784 sliderpos = mid-5;
1785 }
1786 else
1787 {
1788 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
1789 }
1790 if (m_rotated)
1791 {
1792 p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor);
1793 }
1794 else
1795 {
1796 p->fillRect(sliderpos, _h-3, sliderheight, 3, m_scrollbarcolor);
1797 }
1798 }
1799 break;
1800 case 2:
1801 case 3:
1802 {
1803 int ht;
1804 if (m_rotated)
1805 {
1806 ht = _w;
1807 }
1808 else
1809 {
1810 ht = _h;
1811 }
889 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 1812 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
890 int mid = (height()*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); 1813 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
891 p->fillRect(width()-2, mid-5, 2, 10, yellow); 1814 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
892 p->fillRect(width()-2, (height()*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*height()+sectionsize/2)/sectionsize, magenta); 1815 int sliderpos;
1816 if (sliderheight < 10)
1817 {
1818 sliderheight = 10;
1819 sliderpos = mid-5;
1820 }
1821 else
1822 {
1823 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
1824 }
1825 if (m_rotated)
1826 {
1827 int hoff;
1828 if (m_scrollpos == 2) //right
1829 {
1830 hoff = _h-3;
1831 }
1832 else
1833 {
1834 hoff = 0;
1835 }
1836 p->fillRect(ht-sliderpos-sliderheight, hoff, sliderheight, 3, m_scrollbarcolor);
1837 }
1838 else
1839 {
1840 int hoff;
1841 if (m_scrollpos == 2) //right
1842 {
1843 hoff = _w-3;
1844 }
1845 else
1846 {
1847 hoff = 0;
1848 }
1849 p->fillRect(hoff, sliderpos, 3, sliderheight, m_scrollbarcolor);
1850 }
1851 }
1852 break;
1853 case 0:
1854 default:
1855 break;
893 } 1856 }
894
895 emit OnRedraw();
896 } 1857 }
1858}
1859
897/* 1860/*
898 else 1861void QTReader::DrawScroll( QPainter *p )
1862{
1863 if (m_border > 5 && !buffdoc.empty())
899 { 1864 {
900 odebug << "Not so refreshing..." << oendl; 1865 int ht, wh;
1866 if (m_rotated)
1867 {
1868 ht = width();
1869 wh = height()g;
1870 p->fillRect(0, wh-2, ht, 2, cyan);
1871 }
1872 else
1873 {
1874 ht = height();
1875 wh = width();
1876 p->fillRect(wh-2, 0, 2, ht, cyan);
1877 }
1878 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
1879 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
1880 if (m_rotated)
1881 {
1882 p->fillRect(ht-mid-5, wh-2, 10, 2, yellow);
1883 p->fillRect(ht-(ht*(locnarray[numlines]-buffdoc.startSection())+sectionsize/2)/sectionsize, wh-2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, 2, magenta);
1884 }
1885 else
1886 {
1887 p->fillRect(wh-2, mid-5, 2, 10, yellow);
1888 p->fillRect(wh-2, (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, magenta);
1889 }
901 } 1890 }
902*/
903} 1891}
904 1892*/
905QString QTReader::firstword() 1893QString QTReader::firstword()
906{ 1894{
907 if (m_bMonoSpaced) 1895 if (m_bMonoSpaced)
908 { 1896 {
909 return toQString(textarray[0]->data()); 1897 return toQString(textarray[0]->data());
910 } 1898 }
911 else 1899 else
912 { 1900 {
913 int start, end, len, j; 1901 int start, end, len, j;
914 for (j = 0; j < numlines; j++) 1902 for (j = 0; j < numlines; j++)
915 { 1903 {
916 len = textarray[j]->length(); 1904 len = textarray[j]->length();
@@ -932,262 +1920,267 @@ QString QTReader::firstword()
932 1920
933// 1921//
934// Construct the QTReader with buttons. 1922// Construct the QTReader with buttons.
935// 1923//
936 1924
937bool QTReader::ChangeFont(int tgt) 1925bool QTReader::ChangeFont(int tgt)
938{ 1926{
939 return m_fontControl.ChangeFont(m_fontname, tgt); 1927 return m_fontControl.ChangeFont(m_fontname, tgt);
940} 1928}
941 1929
942void QTReader::init() 1930void QTReader::init()
943{ 1931{
944// m_showlast = true; 1932 buffdoc.unsuspend();
945 // setCaption( "Qt Draw Demo Application" ); 1933 setBackgroundColor( m_bg );
946
947 buffdoc.unsuspend();
948 setBackgroundColor( white );
949// QPainter p(this);
950// p.setBackgroundMode( Qt::OpaqueMode );
951 buffdoc.setfilter(getfilter()); 1934 buffdoc.setfilter(getfilter());
952 ChangeFont(m_textsize); 1935 ChangeFont(m_textsize);
953 setFocusPolicy(QWidget::StrongFocus); 1936 setFocusPolicy(QWidget::StrongFocus);
954 // resize( 240, 320 ); 1937 timer = new QTimer(this);
955 //setFocus(); 1938 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
956 timer = new QTimer(this); 1939 // QMessageBox::information(this, "init", m_lastfile, 1);
957 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 1940 setfont();
958// QMessageBox::information(this, "init", m_lastfile, 1);
959 setfont();
960/*
961 if (!m_lastfile.isEmpty())
962 {
963 m_string = DocLnk(m_lastfile).name();
964 load_file(m_lastfile);
965 }
966*/
967} 1941}
968 1942
969// 1943//
970// Clean up 1944// Clean up
971// 1945//
972QTReader::~QTReader() 1946QTReader::~QTReader()
973{ 1947{
1948#ifdef DOUBLEBUFFER
1949 delete dbuff;
1950 delete dbp;
1951#endif
974#ifdef USEQPE 1952#ifdef USEQPE
975 if (m_autoScroll) 1953 if (m_autoScroll)
976 { 1954 {
977 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1955 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
978 } 1956 }
979#endif 1957#endif
980#ifdef _SCROLLPIPE 1958#ifdef _SCROLLPIPE
981 if (m_pipeout != NULL) 1959 if (m_pipeout != NULL)
982 { 1960 {
983 fclose(m_pipeout); 1961 fclose(m_pipeout);
984 } 1962 }
985#endif 1963#endif
986} 1964}
987 1965
988// 1966//
989// Calls the drawing function as specified by the radio buttons.
990//
991
992void QTReader::drawIt( QPainter *p )
993{
994 drawFonts(p);
995}
996
997//
998// Called when the print button is clicked. 1967// Called when the print button is clicked.
999// 1968//
1000/* 1969/*
1001void QTReader::printIt() 1970void QTReader::printIt()
1002{ 1971{
1003#ifndef QT_NO_PRINTER 1972#ifndef QT_NO_PRINTER
1004 if ( printer->setup( this ) ) { 1973 if ( printer->setup( this ) ) {
1005 QPainter paint; 1974 QPainter paint;
1006 if ( !paint.begin( printer ) ) 1975 if ( !paint.begin( printer ) )
1007 return; 1976 return;
1008 drawIt( &paint ); 1977 drawIt( &paint );
1009 } 1978 }
1010#endif 1979#endif
1011} 1980}
1012*/ 1981*/
1013// 1982//
1014// Called when the widget needs to be updated. 1983// Called when the widget needs to be updated.
1015// 1984//
1016 1985
1017void QTReader::paintEvent( QPaintEvent * ) 1986void QTReader::paintEvent( QPaintEvent * )
1018{ 1987{
1019 QPainter paint( this ); 1988 drawFonts();
1020 drawIt( &paint );
1021} 1989}
1022 1990
1023// 1991//
1024// Called when the widget has been resized. 1992// Called when the widget has been resized.
1025// Moves the button group to the upper right corner 1993// Moves the button group to the upper right corner
1026// of the widget. 1994// of the widget.
1027 1995
1028/* 1996/*
1029void QTReader::resizeEvent( QResizeEvent * ) 1997void QTReader::resizeEvent( QResizeEvent * )
1030{ 1998{
1031// // odebug << "resize:(" << width() << "," << height() << ")" << oendl; 1999// // qDebug("resize:(%u,%u)", width(), height());
1032 // bgroup->move( width()-bgroup->width(), 0 ); 2000 // bgroup->move( width()-bgroup->width(), 0 );
1033} 2001}
1034*/ 2002*/
1035 2003
1036// 2004//
1037// Create and display our widget. 2005// Create and display our widget.
1038// 2006//
1039/* 2007/*
1040int main( int argc, tchar **argv ) 2008int main( int argc, tchar **argv )
1041{ 2009{
1042 QApplication app( argc, argv ); 2010 QApplication app( argc, argv );
1043 QTReader draw; 2011 QTReader draw;
1044 app.setMainWidget( &draw ); 2012 app.setMainWidget( &draw );
1045 draw.setCaption("Qt Example - Drawdemo"); 2013 draw.setCaption("Qt Example - Drawdemo");
1046 draw.show(); 2014 draw.show();
1047 return app.exec(); 2015 return app.exec();
1048} 2016}
1049*/ 2017*/
1050 2018
1051 2019
1052bool QTReader::locate(unsigned long n) { 2020bool QTReader::locate(unsigned long n) {
1053 //printf("Locate\n"); 2021 //printf("Locate\n");
1054 buffdoc.unsuspend(); 2022 buffdoc.unsuspend();
1055 buffdoc.locate(n); 2023 buffdoc.locate(n);
1056// // odebug << "&buffdoc.located" << oendl; 2024// // qDebug("&buffdoc.located");
2025 ResetScroll();
1057 fillbuffer(); 2026 fillbuffer();
1058// // odebug << "&Buffer filled" << oendl; 2027// // qDebug("&Buffer filled");
1059 update(); 2028 update();
1060// // odebug << "&Located" << oendl; 2029// // qDebug("&Located");
2030 emitRedraw();
1061 return true; 2031 return true;
1062} 2032}
1063 2033
1064unsigned int QTReader::screenlines() 2034unsigned int QTReader::screenlines()
1065{ 2035{
1066 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 2036 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
1067 // return (height()-m_descent)/(m_linespacing); 2037 // return (height()-m_descent)/(m_linespacing);
1068 return (height()-2)/(m_linespacing); 2038 return (height()-2)/(m_linespacing);
1069}; 2039};
1070 2040
1071bool QTReader::fillbuffer(int reuse, int ht, int newht) 2041bool QTReader::fillbuffer(int reuse, int ht, int newht)
1072{ 2042{
1073 buffdoc.unsuspend(); 2043 buffdoc.unsuspend();
2044 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
2045 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
2046 if (ht < 0) ht = m_topmargin;
1074 if (buffdoc.empty()) return false; 2047 if (buffdoc.empty()) return false;
1075 if (newht < 0) 2048 if (newht < 0)
1076 m_lastheight = height(); 2049 m_lastheight = (m_rotated) ? width() : height();
1077 else 2050 else
1078 m_lastheight = newht; 2051 m_lastheight = newht;
1079 int ch; 2052 int ch;
1080 bool ret = false; 2053 bool ret = false;
1081 unsigned int oldpagepos = locnarray[reuse]; 2054 unsigned int oldpagepos = locnarray[reuse];
1082 int lastypos = ht, ypos = ht; 2055 int lastypos = ht, ypos = ht;
1083 numlines = reuse; 2056 numlines = reuse;
1084 while (ypos < m_lastheight || numlines < 2) 2057 while (ypos < m_lastheight - hmargin || numlines < 2)
1085 { 2058 {
1086 lastypos = ypos; 2059 lastypos = ypos;
1087 if (textarray[numlines] == NULL) 2060 if (textarray[numlines] == NULL)
1088 { 2061 {
1089 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2062 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1090 } 2063 }
1091 locnarray[numlines] = locate(); 2064 locnarray[numlines] = locate();
1092 int ch = getline(textarray[numlines]); 2065 int ch = getline(textarray[numlines]);
1093 ypos += textarray[numlines]->lineSpacing(); 2066 ypos += textarray[numlines]->lineSpacing();
1094 numlines++; 2067 numlines++;
1095 if (!ch) 2068 if (!ch)
1096 { 2069 {
1097 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) 2070 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
1098 { 2071 {
2072 qDebug("FALSE");
1099 locate(oldpagepos); 2073 locate(oldpagepos);
1100 return false; 2074 return false;
1101 } 2075 }
1102 else 2076 else
1103 { 2077 {
2078 qDebug("TRUE");
1104 --numlines; 2079 --numlines;
1105 mylastpos = locate(); 2080 mylastpos = locate();
1106 return true; 2081 return true;
1107 } 2082 }
1108 } 2083 }
2084 if (numlines > 1 && textarray[numlines-2]->isBop())
2085 {
2086 --numlines;
2087 mylastpos = locate();
2088 return true;
2089 }
1109 } 2090 }
1110 2091
1111 --numlines; 2092 --numlines;
1112 mylastpos = locate(); 2093 mylastpos = locate();
1113 m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; 2094 m_scrollpart = m_lastheight - lastypos - hmargin;
1114 2095 if (m_autoScroll)
2096 {
2097 CalculateScrollParameters();
2098 }
1115 return true; 2099 return true;
1116} 2100}
1117 2101
1118void QTReader::dopagedn() 2102void QTReader::dopagedn()
1119{ 2103{
1120// odebug << "HEIGHT(2):" << m_lastheight << "" << oendl; 2104// qDebug("HEIGHT(2):%d", m_lastheight);
1121 buffdoc.unsuspend(); 2105 buffdoc.unsuspend();
1122 int skip = 0, ypos = 0; 2106 ResetScroll();
2107 int skip = 0, ypos = m_topmargin;
1123 if (locate() != mylastpos) 2108 if (locate() != mylastpos)
1124 { 2109 {
1125 ////odebug << "Jumping to " << mylastpos << "" << oendl;
1126 jumpto(mylastpos); 2110 jumpto(mylastpos);
1127 } 2111 }
1128 CDrawBuffer* reusebuffer = textarray[numlines]; 2112 CDrawBuffer* reusebuffer = textarray[numlines];
1129 if (reusebuffer != NULL && reusebuffer->eof()) return;
1130 if (reusebuffer != NULL) 2113 if (reusebuffer != NULL)
1131 { 2114 {
2115 if (reusebuffer->eof()) return;
1132 for (int i = 0; i <= m_overlap; i++) 2116 for (int i = 0; i <= m_overlap; i++)
1133 { 2117 {
1134 int offset = numlines - m_overlap + i; 2118 int offset = numlines - m_overlap + i;
1135 reusebuffer = textarray[offset]; 2119 reusebuffer = textarray[offset];
1136 size_t reuselocn = locnarray[offset]; 2120 size_t reuselocn = locnarray[offset];
1137 textarray[offset] = textarray[i]; 2121 textarray[offset] = textarray[i];
1138 textarray[i] = reusebuffer; 2122 textarray[i] = reusebuffer;
1139 // reusebuffer->empty(); 2123 // reusebuffer->empty();
1140 locnarray[offset] = locnarray[i]; 2124 locnarray[offset] = locnarray[i];
1141 locnarray[i] = reuselocn; 2125 locnarray[i] = reuselocn;
1142 ypos += textarray[i]->lineSpacing(); 2126 ypos += textarray[i]->lineSpacing();
1143 skip++; 2127 skip++;
1144 } 2128 }
1145 } 2129 }
2130 if (numlines <= 1)
2131 {
2132 skip = 0;
2133 ypos = 0;
2134 qDebug("Doing extra skip");
2135 }
1146 if (fillbuffer(skip, ypos)) 2136 if (fillbuffer(skip, ypos))
1147 { 2137 {
1148 update(); 2138 drawFonts();
1149 } 2139 }
1150} 2140}
1151 2141
1152void QTReader::dopageup() 2142void QTReader::dopageup()
1153{ 2143{
1154 buffdoc.unsuspend();
1155 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); 2144 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
1156} 2145}
1157 2146
1158bool QTReader::synch(size_t start, size_t end) 2147bool QTReader::synch(size_t start, size_t end)
1159{ 2148{
1160 jumpto(start); 2149 jumpto(start);
1161 while (start++ < end) 2150 while (start++ < end)
1162 { 2151 {
1163 tchar ch = getch(); 2152 tchar ch = getch();
1164 if (ch == 10) return true; 2153 if (ch == 10) return true;
1165 if (ch == UEOF) return false; 2154 if (ch == UEOF) return false;
2155 if (ch == 6) return false;
1166 } 2156 }
1167 return false; 2157 return false;
1168} 2158}
1169 2159
1170void QTReader::dopageup(unsigned int target) 2160void QTReader::dopageup(unsigned int target)
1171{ 2161{
1172 buffdoc.unsuspend(); 2162 buffdoc.unsuspend();
2163 ResetScroll();
1173 CBufferFace<CDrawBuffer*> buff; 2164 CBufferFace<CDrawBuffer*> buff;
1174 CBufferFace<size_t> loc; 2165 CBufferFace<size_t> loc;
1175 2166
1176 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; 2167 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0;
1177 bool ch = true; 2168 bool ch = true;
1178 int nbfl, ypos = 0; 2169 int nbfl, ypos = m_topmargin;
1179 if (guess < 128) guess = 128; 2170 if (guess < 128) guess = 128;
1180 while (1) 2171 while (1)
1181 { 2172 {
2173 // qDebug("Guess:%u", guess);
2174
1182 ch = true; 2175 ch = true;
1183 if (target < guess) 2176 if (target < guess)
1184 { 2177 {
1185 delta = 0; // 0 is a flag to say don't guess any more 2178 delta = 0; // 0 is a flag to say don't guess any more
1186 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); 2179 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
1187 } 2180 }
1188 else if (!m_continuousDocument && (target - guess < buffdoc.startSection())) 2181 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
1189 { 2182 {
1190 delta = 0; // 0 is a flag to say don't guess any more 2183 delta = 0; // 0 is a flag to say don't guess any more
1191 jumpto(buffdoc.startSection()); 2184 jumpto(buffdoc.startSection());
1192 } 2185 }
1193 else 2186 else
@@ -1200,36 +2193,36 @@ void QTReader::dopageup(unsigned int target)
1200 { 2193 {
1201 guess <<= 1; 2194 guess <<= 1;
1202 continue; 2195 continue;
1203 } 2196 }
1204 else 2197 else
1205 { 2198 {
1206 jumpto(target-delta); 2199 jumpto(target-delta);
1207 } 2200 }
1208 } 2201 }
1209 } 2202 }
1210 2203
1211 nbfl = 0; 2204 nbfl = 0;
1212 ypos = 0; 2205 ypos = m_topmargin;
1213 2206
1214 while (locate() < target) 2207 while (locate() < target)
1215 { 2208 {
1216 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); 2209 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
1217 loc[nbfl] = locate(); 2210 loc[nbfl] = locate();
1218 ch = getline(buff[nbfl]); 2211 ch = getline(buff[nbfl]);
1219 ypos += buff[nbfl]->lineSpacing(); 2212 ypos += buff[nbfl]->lineSpacing();
1220 nbfl++; 2213 nbfl++;
1221 if (!ch) break; 2214 if (!ch) break;
1222 } 2215 }
1223 if (guess < 4000 && ypos < height() && (delta != 0)) 2216 if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0))
1224 { 2217 {
1225 for (int i = 0; i < nbfl; i++) 2218 for (int i = 0; i < nbfl; i++)
1226 { 2219 {
1227 delete buff[i]; 2220 delete buff[i];
1228 buff[i] = NULL; 2221 buff[i] = NULL;
1229 } 2222 }
1230 guess <<= 1; 2223 guess <<= 1;
1231 continue; 2224 continue;
1232 } 2225 }
1233 break; 2226 break;
1234 } 2227 }
1235 if (ch) 2228 if (ch)
@@ -1241,105 +2234,115 @@ void QTReader::dopageup(unsigned int target)
1241 } 2234 }
1242/* 2235/*
1243 ypos = 0; 2236 ypos = 0;
1244 numlines = 0; 2237 numlines = 0;
1245 while (ypos < height() && numlines <= nbfl-1) 2238 while (ypos < height() && numlines <= nbfl-1)
1246 { 2239 {
1247 ypos += buff[nbfl - numlines - 1]->lineSpacing(); 2240 ypos += buff[nbfl - numlines - 1]->lineSpacing();
1248 numlines++; 2241 numlines++;
1249 } 2242 }
1250 --numlines; 2243 --numlines;
1251*/ 2244*/
1252 2245
1253 ypos = 0; 2246 ypos = m_topmargin;
1254 numlines = 0; 2247 numlines = 0;
1255 while (ypos < height() && numlines+2 <= nbfl) 2248 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl)
1256 { 2249 {
1257 ypos += buff[nbfl - numlines - 2]->lineSpacing(); 2250 ypos += buff[nbfl - numlines - 2]->lineSpacing();
1258 numlines++; 2251 numlines++;
1259 } 2252 }
1260 if (numlines > 0) --numlines; 2253 if (numlines > 0) --numlines;
1261 if (numlines == 0 && nbfl > 1) numlines = 1; 2254 if (numlines == 0 && nbfl > 1) numlines = 1;
1262 2255
1263 int offset = nbfl-1; 2256 int offset = nbfl-1;
1264 offset -= numlines; 2257 offset -= numlines;
1265 ypos = 0; 2258 ypos = m_topmargin;
1266 for (int i = 0; i <= numlines; i++) 2259 for (int i = 0; i <= numlines; i++)
1267 { 2260 {
1268 delete textarray[i]; 2261 delete textarray[i];
1269 textarray[i] = buff[offset+i]; 2262 textarray[i] = buff[offset+i];
1270 locnarray[i] = loc[offset + i]; 2263 locnarray[i] = loc[offset + i];
1271 ypos += textarray[i]->lineSpacing(); 2264 ypos += textarray[i]->lineSpacing();
1272 } 2265 }
1273#ifdef _WINDOWS 2266#ifdef _WINDOWS
1274 for (i = 0; i < nbfl - numlines - 1; i++) 2267 for (i = 0; i < nbfl - numlines - 1; i++)
1275#else 2268#else
1276 for (int i = 0; i < nbfl - numlines - 1; i++) 2269 for (int i = 0; i < nbfl - numlines - 1; i++)
1277#endif 2270#endif
1278 { 2271 {
1279 delete buff[i]; 2272 delete buff[i];
1280 } 2273 }
1281 2274
1282 while (ypos < height()) 2275 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin)
1283 { 2276 {
1284 numlines++; 2277 numlines++;
1285 locnarray[numlines] = locate(); 2278 locnarray[numlines] = locate();
1286 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl); 2279 if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
1287 if (!getline(textarray[numlines])) break; 2280 if (!getline(textarray[numlines])) break;
1288 ypos += textarray[numlines]->lineSpacing(); 2281 ypos += textarray[numlines]->lineSpacing();
1289 } 2282 }
1290 2283
1291 mylastpos = locate(); 2284 mylastpos = locate();
1292 2285 CalculateScrollParameters();
1293 update(); 2286 drawFonts();
2287 // repaint();
1294} 2288}
1295 2289
1296bool QTReader::load_file(const char *newfile, unsigned int _lcn) 2290bool QTReader::load_file(const char *newfile, unsigned int _lcn)
1297{ 2291{
1298// QMessageBox::information(this, "Name", name, 1); 2292// QMessageBox::information(this, "Name", name, 1);
1299// QMessageBox::information(this, "load_file", newfile, 1); 2293// QMessageBox::information(this, "load_file", newfile, 1);
1300 2294 int prog = 0;
1301 bool bRC = false; 2295 bool bRC = false;
1302 unsigned int lcn = _lcn; 2296 unsigned int lcn = _lcn;
2297 ResetScroll();
1303 if (m_lastfile == newfile) 2298 if (m_lastfile == newfile)
1304 { 2299 {
1305 lcn = m_lastposn; 2300 lcn = m_lastposn;
1306 } 2301 }
1307 // QMessageBox::information(0, "Opening...", newfile); 2302 // QMessageBox::information(0, "Opening...", newfile);
1308 m_lastwidth = width(); 2303 if (m_rotated)
1309 m_lastheight = height(); 2304 {
2305 m_lastwidth = height();
2306 m_lastheight = width();
2307 }
2308 else
2309 {
2310 m_lastwidth = width();
2311 m_lastheight = height();
2312 }
1310 if (buffdoc.openfile(this,newfile) == 0) 2313 if (buffdoc.openfile(this,newfile) == 0)
1311 { 2314 {
1312 m_lastfile = newfile; 2315 m_lastfile = newfile;
1313 buffdoc.setwidth(m_lastwidth-2*m_border); 2316 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1314 bRC = true; 2317 bRC = true;
1315 buffdoc.setContinuous(m_continuousDocument); 2318 buffdoc.setContinuous(m_continuousDocument);
1316// // odebug << "buffdoc.openfile done" << oendl; 2319 qDebug("buffdoc.openfile done");
1317 locate(lcn); 2320 locate(lcn);
1318// // odebug << "buffdoc.locate done" << oendl; 2321 qDebug("buffdoc.locate done");
1319 } 2322 }
1320 setfilter(getfilter()); 2323 setfilter(getfilter());
1321 update(); 2324 qDebug("Updated");
1322// // odebug << "Updated" << oendl;
1323 return bRC; 2325 return bRC;
1324} 2326}
1325 2327
1326void QTReader::lineDown() 2328void QTReader::lineDown()
1327{ 2329{
1328 int ypos = 0; 2330 int ypos = m_topmargin;
2331 ResetScroll();
1329 int offset = numlines; 2332 int offset = numlines;
1330 2333
1331 for (int i = 0; i <= numlines; i++) 2334 for (int i = 0; i <= numlines; i++)
1332 { 2335 {
1333 if ((ypos += textarray[numlines-i]->lineSpacing()) > height()) 2336 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height()))
1334 { 2337 {
1335 offset = i-1; 2338 offset = i-1;
1336 break; 2339 break;
1337 } 2340 }
1338 } 2341 }
1339 offset = numlines - offset; 2342 offset = numlines - offset;
1340#ifdef _WINDOWS 2343#ifdef _WINDOWS
1341 for (i = offset; i <= numlines; i++) 2344 for (i = offset; i <= numlines; i++)
1342#else 2345#else
1343 for (int i = offset; i <= numlines; i++) 2346 for (int i = offset; i <= numlines; i++)
1344#endif 2347#endif
1345 { 2348 {
@@ -1432,27 +2435,44 @@ void QTReader::lineUp()
1432 for (int i = 0; i < numlines; i++) 2435 for (int i = 0; i < numlines; i++)
1433 { 2436 {
1434 int j = (cbptr+i)%numlines; 2437 int j = (cbptr+i)%numlines;
1435 textarray[i] = buff[j]; 2438 textarray[i] = buff[j];
1436 locnarray[i] = loc[j]; 2439 locnarray[i] = loc[j];
1437 } 2440 }
1438 delete [] buff; 2441 delete [] buff;
1439 delete [] loc; 2442 delete [] loc;
1440 mylastpos = locate(); 2443 mylastpos = locate();
1441 update(); 2444 update();
1442} 2445}
1443*/ 2446*/
2447
2448void QTReader::ResetScroll()
2449{
2450 m_totalscroll = 0;
2451 m_scrolldy1 = 0;
2452 m_scrolldy = m_topmargin;
2453 if (m_autoScroll && ((m_scrolltype == 0) || !m_bgpm.isNull()))
2454 {
2455 setautoscroll(false);
2456 }
2457}
2458
1444void QTReader::lineUp() 2459void QTReader::lineUp()
1445{ 2460{
1446 buffdoc.unsuspend(); 2461 dopageup(locnarray[numlines-1]);
2462
2463 /*
2464 buffdoc.unsuspend();
2465 ResetScroll();
2466
1447 CDrawBuffer* buff = textarray[numlines]; 2467 CDrawBuffer* buff = textarray[numlines];
1448 unsigned int loc; 2468 unsigned int loc;
1449 unsigned int end = locnarray[numlines]; 2469 unsigned int end = locnarray[numlines];
1450 int cbptr = 0; 2470 int cbptr = 0;
1451 if (locate() != mylastpos) jumpto(mylastpos); 2471 if (locate() != mylastpos) jumpto(mylastpos);
1452 unsigned int target = locnarray[0]; 2472 unsigned int target = locnarray[0];
1453 if (target == 0) return; 2473 if (target == 0) return;
1454 if (!m_continuousDocument && (target == buffdoc.startSection())) return; 2474 if (!m_continuousDocument && (target == buffdoc.startSection())) return;
1455 if (buffdoc.hasrandomaccess()) 2475 if (buffdoc.hasrandomaccess())
1456 { 2476 {
1457 unsigned int delta = locate()-pagelocate(); 2477 unsigned int delta = locate()-pagelocate();
1458 if (delta < 64) delta = 64; 2478 if (delta < 64) delta = 64;
@@ -1501,54 +2521,466 @@ void QTReader::lineUp()
1501 { 2521 {
1502 loc = locate(); 2522 loc = locate();
1503 getline(buff); 2523 getline(buff);
1504 } 2524 }
1505 for (int i = numlines; i > 0; i--) 2525 for (int i = numlines; i > 0; i--)
1506 { 2526 {
1507 textarray[i] = textarray[i-1]; 2527 textarray[i] = textarray[i-1];
1508 locnarray[i] = locnarray[i-1]; 2528 locnarray[i] = locnarray[i-1];
1509 } 2529 }
1510 textarray[0] = buff; 2530 textarray[0] = buff;
1511 locnarray[0] = loc; 2531 locnarray[0] = loc;
1512 int start = numlines; 2532 int start = numlines;
1513 int ypos = 0; 2533 int ypos = m_topmargin;
1514#ifdef _WINDOWS 2534#ifdef _WINDOWS
1515 for (i = 0; i <= numlines; i++) 2535 for (i = 0; i <= numlines; i++)
1516#else 2536#else
1517 for (int i = 0; i <= numlines; i++) 2537 for (int i = 0; i <= numlines; i++)
1518#endif 2538#endif
1519 { 2539 {
1520 ypos += textarray[i]->lineSpacing(); 2540 ypos += textarray[i]->lineSpacing();
1521 if (ypos > height()) 2541 if (ypos > ((m_rotated) ? width() : height()))
1522 { 2542 {
1523 start = i; 2543 start = i;
1524 ypos -= textarray[i]->lineSpacing(); 2544 ypos -= textarray[i]->lineSpacing();
1525 break; 2545 break;
1526 } 2546 }
1527 } 2547 }
1528 jumpto(locnarray[start]); 2548 jumpto(locnarray[start]);
1529 fillbuffer(start, ypos); 2549 fillbuffer(start, ypos);
1530 update(); 2550 repaint();
2551 */
1531} 2552}
1532 2553
1533bool QTReader::empty() 2554bool QTReader::empty()
1534{ 2555{
1535 return buffdoc.empty(); 2556 return buffdoc.empty();
1536} 2557}
1537 2558
1538MarkupType QTReader::PreferredMarkup() 2559MarkupType QTReader::PreferredMarkup()
1539{ 2560{
1540 MarkupType m = buffdoc.PreferredMarkup(); 2561 MarkupType m = buffdoc.PreferredMarkup();
1541 if (m == cTEXT) 2562 if (m == cTEXT)
1542 { 2563 {
1543 int ext = m_lastfile.findRev('.'); 2564 int ext = m_lastfile.findRev('.');
1544 if (ext >= 0) 2565 if (ext >= 0)
1545 { 2566 {
1546 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper(); 2567 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
1547 if (ft.left(3) == "HTM") 2568 if (ft.left(3) == "HTM")
1548 { 2569 {
1549 m = cHTML; 2570 m = cHTML;
1550 } 2571 }
1551 } 2572 }
1552 } 2573 }
1553 return m; 2574 return m;
1554} 2575}
2576#ifdef DOUBLEBUFFER
2577void QTReader::resizeEvent( QResizeEvent * p )
2578{
2579 if (m_rotated)
2580 {
2581 dbuff->resize(p->size().height(),p->size().width());
2582 }
2583 else
2584 {
2585 dbuff->resize(p->size());
2586 }
2587 m_bgIsScaled = false;
2588 if (m_bgtype == bgStretched)
2589 {
2590 emit RefreshBitmap();
2591 }
2592
2593 {
2594 int h, w;
2595 if (m_rotated)
2596 {
2597 h = p->size().width();
2598 w = p->size().height();
2599 }
2600 else
2601 {
2602 w = p->size().width();
2603 h = p->size().height();
2604 }
2605 m_topmargin = (h*m_abstopmargin+500)/1000;
2606 m_bottommargin = (h*m_absbottommargin+500)/1000;
2607 m_left_border = (w*m_absleft_border+500)/1000;
2608 m_right_border = (w*m_absright_border+500)/1000;
2609
2610 qDebug("Top margin:%u", m_topmargin );
2611 qDebug("Bottom margin:%u", m_bottommargin );
2612 qDebug("Left margin:%u", m_left_border );
2613 qDebug("Right margin:%u", m_right_border );
2614 }
2615}
2616#endif
2617
2618void QTReader::setrotated(bool sfs)
2619{
2620 m_rotated = sfs;
2621#ifdef DOUBLEBUFFER
2622 if (m_rotated)
2623 {
2624 dbuff->resize(height(), width());
2625 }
2626 else
2627 {
2628 dbuff->resize(width(), height());
2629 }
2630 m_bgIsScaled = false;
2631#endif
2632 int h, w;
2633 if (m_rotated)
2634 {
2635 h = width();
2636 w = height();
2637 }
2638 else
2639 {
2640 w = width();
2641 h = height();
2642 }
2643 m_topmargin = (h*m_abstopmargin+500)/1000;
2644 m_bottommargin = (h*m_absbottommargin+500)/1000;
2645 m_left_border = (w*m_absleft_border+500)/1000;
2646 m_right_border = (w*m_absright_border+500)/1000;
2647
2648 qDebug("Top margin:%u", m_topmargin );
2649 qDebug("Bottom margin:%u", m_bottommargin );
2650 qDebug("Left margin:%u", m_left_border );
2651 qDebug("Right margin:%u", m_right_border );
2652}
2653
2654void QTReader::drawBackground()
2655{
2656 dbp->begin(dbuff);
2657 // dbp->setBackgroundMode(OpaqueMode);
2658 dbp->setBackgroundColor(m_bg);
2659 dbp->eraseRect(dbuff->rect());
2660 if (!m_bgpm.isNull())
2661 {
2662 // dbp->setBackgroundMode(TransparentMode);
2663 switch (m_bgtype)
2664 {
2665 case bgCentred:
2666 {
2667 int w = (dbuff->rect().width()-m_bgpm.width())/2;
2668 int h = (dbuff->rect().height()-m_bgpm.height())/2;
2669 dbp->drawPixmap(w,h,m_bgpm);
2670 }
2671 break;
2672 case bgTiled:
2673 {
2674 dbp->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm);
2675 /*
2676 for (int h = 0; h < dbuff->rect().height(); h += m_bgpm.height())
2677 {
2678 for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width())
2679 {
2680 dbp->drawPixmap(w,h,m_bgpm);
2681 }
2682 }
2683 */
2684 }
2685 break;
2686 case bgStretched:
2687 {
2688 if (!m_bgIsScaled)
2689 {
2690 m_bgIsScaled = true;
2691 QImage im = m_bgpm.convertToImage();
2692 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
2693 }
2694 dbp->drawPixmap(0,0,m_bgpm);
2695 }
2696 break;
2697 default:
2698 qDebug("Unknown background type");
2699 }
2700 // dbp->setBackgroundMode(OpaqueMode);
2701 }
2702}
2703
2704void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2705{
2706 if (txt != NULL)
2707 {
2708 sh = txt->lineSpacing();
2709 }
2710 int sy = width()-dx-sh;
2711 if (m_autoScroll && !(m_scrolltype == 0))
2712 {
2713 sy = (sy+m_totalscroll+1)%width();
2714 }
2715
2716 QPixmap pm(sw, sh);
2717
2718 QPainter pd(&pm, this);
2719 if (m_bgpm.isNull())
2720 {
2721 pd.eraseRect(pm.rect());
2722 }
2723 else
2724 {
2725 if (sy+pm.height() > dbuff->height())
2726 {
2727 // pd.eraseRect(pm.rect());
2728 int fh = dbuff->height() - sy;
2729 if (sy+fh > dbuff->height())
2730 {
2731 qDebug("Oh no!");
2732 }
2733
2734 if (fh > pm.height())
2735 {
2736 qDebug("Oh no! - 2");
2737 }
2738
2739 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),fh);
2740 bitBlt(&pm,0,fh,dbuff,dy,0,pm.width(),pm.height()-fh);
2741 }
2742 else
2743 {
2744 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),pm.height());
2745 }
2746 }
2747 if (txt != NULL)
2748 {
2749 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg);
2750 txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin);
2751 }
2752 QWMatrix m;
2753 m.rotate(90);
2754 QPixmap rp = pm.xForm(m);
2755 /*
2756 p.drawPixmap(QPoint(dx, dy), rp);
2757 */
2758 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP);
2759}
2760
2761QString QTReader::about()
2762{
2763 return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka";
2764}
2765
2766void QTReader::getNextLink()
2767{
2768 if (m_scrolldy != 0)
2769 {
2770 setautoscroll(false);
2771 ResetScroll();
2772 redrawall();
2773 }
2774 bool redraw = false;
2775 bool found = false;
2776 if (m_currentlink >= 0)
2777 {
2778 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2779 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL)
2780 {
2781 qDebug("Found a link at %u", m_currentlinkoffset);
2782 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2783 qDebug("Finishes at %u", offset);
2784 found = true;
2785 }
2786 redraw = true;
2787 drawSingleLine(m_currentlink);
2788 // if (found) return;
2789 }
2790 if (!found)
2791 {
2792 m_currentlinkoffset = -1;
2793 for (int i = m_currentlink+1; i < numlines; ++i)
2794 {
2795 if ((m_currentlinkstyle = textarray[i]->getNextLink(m_currentlinkoffset)) != NULL)
2796 {
2797 m_currentlink = i;
2798 qDebug("Found a link at %u", m_currentlinkoffset);
2799 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2800 qDebug("Finishes at %u", offset);
2801 //drawSingleLine(i);
2802 redraw = true;
2803 found = true;
2804 drawSingleLine(m_currentlink);
2805 break;
2806 }
2807 }
2808 }
2809 if (redraw)
2810 {
2811 // redrawall();
2812 }
2813 if (!found)
2814 {
2815 m_currentlink = -1;
2816 m_currentlinkstyle = NULL;
2817 m_currentlinkoffset = -1;
2818 dopagedn();
2819 }
2820}
2821
2822void QTReader::emitRedraw()
2823{
2824 m_currentlinkstyle = NULL;
2825 m_currentlink = -1;
2826 m_currentlinkoffset = -1;
2827 emit OnRedraw();
2828};
2829
2830void QTReader::drawSingleLine(int lineno)
2831{
2832 QPainter p( this );
2833 int ypos = textarray[0]->ascent()+m_topmargin;
2834 if (lineno == 0)
2835 {
2836 if (m_rotated)
2837 {
2838 blitRot(width()-(ypos+textarray[lineno]->descent()+textarray[lineno]->lineExtraSpacing()), 0, height(), -1, textarray[lineno]);
2839 }
2840 else
2841 {
2842 if (m_bgpm.isNull())
2843 {
2844 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
2845 }
2846 else
2847 {
2848 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing());
2849 }
2850 textarray[lineno]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
2851 }
2852 }
2853 for (int i = 1; i < numlines; i++)
2854 {
2855 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
2856 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
2857 if (i == lineno)
2858 {
2859 if (m_rotated)
2860 {
2861 blitRot(width()-(ypos+textarray[i]->descent()+textarray[i]->lineExtraSpacing()), 0, height(), -1, textarray[i]);
2862 }
2863 else
2864 {
2865 if (m_bgpm.isNull())
2866 {
2867 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
2868 }
2869 else
2870 {
2871 bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing());
2872 }
2873 textarray[i]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
2874 }
2875 }
2876 }
2877}
2878
2879
2880void QTReader::gotoLink()
2881{
2882 if (m_currentlinkstyle == NULL) return;
2883 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2884 size_t saveposn = pagelocate();
2885 QString href, nm;
2886 unsigned long tgt = m_currentlinkstyle->getData();
2887 unsigned long tgtoffset = m_currentlinkstyle->getOffset();
2888 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
2889 qDebug("URL(1):%s", (const char*)href);
2890 if ((lt & eFile) != 0)
2891 {
2892 buffdoc.saveposn(m_lastfile, saveposn);
2893#ifdef USEQPE
2894 {
2895 QCopEnvelope e("QPE/System", "busy()");
2896 }
2897#endif
2898 ResetScroll();
2899 if (!href.isEmpty())
2900 {
2901 if (!buffdoc.getFile(href))
2902 {
2903 emit NewFileRequest(href);
2904 }
2905 else
2906 {
2907 ResetScroll();
2908 fillbuffer();
2909 update();
2910 }
2911 }
2912 if (!nm.isEmpty())
2913 {
2914 qDebug("QTReader:Finding %s", (const char*)nm);
2915 if (buffdoc.findanchor(nm))
2916 {
2917 fillbuffer();
2918 update();
2919 }
2920 }
2921 //fillbuffer();
2922 //update();
2923#ifdef USEQPE
2924 {
2925 QCopEnvelope e("QPE/System", "notBusy()");
2926 }
2927#endif
2928 }
2929 else if ((lt & eLink) != 0)
2930 {
2931 buffdoc.saveposn(m_lastfile, saveposn);
2932 ResetScroll();
2933 fillbuffer();
2934 update();
2935 }
2936 else
2937 {
2938 if ((lt & ePicture) != 0)
2939 {
2940 QImage* pm = buffdoc.getPicture(tgt);
2941 if (pm != NULL)
2942 {
2943 emit OnShowPicture(*pm);
2944 delete pm;
2945 }
2946 }
2947 else
2948 {
2949 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
2950 if (!href.isEmpty())
2951 {
2952 emit OnURLSelected(href, tgt);
2953 }
2954 }
2955 locate(pagelocate());
2956 }
2957 m_currentlinkstyle = NULL;
2958 m_currentlink = -1;
2959 m_currentlinkoffset = -1;
2960}
2961
2962void QTReader::refresh(bool full)
2963{
2964 int h, w;
2965 if (m_rotated)
2966 {
2967 h = width();
2968 w = height();
2969 }
2970 else
2971 {
2972 w = width();
2973 h = height();
2974 }
2975 m_topmargin = (h*m_abstopmargin+500)/1000;
2976 m_bottommargin = (h*m_absbottommargin+500)/1000;
2977 m_left_border = (w*m_absleft_border+500)/1000;
2978 m_right_border = (w*m_absright_border+500)/1000;
2979
2980 qDebug("Top margin:%u", m_topmargin );
2981 qDebug("Bottom margin:%u", m_bottommargin );
2982 qDebug("Left margin:%u", m_left_border );
2983 qDebug("Right margin:%u", m_right_border );
2984 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate());
2985 locate(pagelocate());
2986}