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.cpp1186
1 files changed, 630 insertions, 556 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 6335ea2..e7bfc28 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -1,25 +1,27 @@
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
11#include <qpainter.h>
11#include "config.h" 12#include "config.h"
12#include "QTReader.h" 13#include "QTReader.h"
13#include "QTReaderApp.h" 14#include "QTReaderApp.h"
15#include "CDrawBuffer.h"
14#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
15#include <math.h> 17#include <math.h>
16#include <ctype.h> 18#include <ctype.h>
17#include <stdio.h> //for sprintf 19#include <stdio.h> //for sprintf
18#include <qpe/config.h> 20#include <qpe/config.h>
19#include <qpe/applnk.h> 21#include <qpe/applnk.h>
20#include <qfontdatabase.h> 22#include <qfontdatabase.h>
21#include <qpe/global.h> 23#include <qpe/global.h>
22#include <qpe/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
23 25
24#ifdef _UNICODE 26#ifdef _UNICODE
25const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 27const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
@@ -27,34 +29,37 @@ const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
27const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 29const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
28#endif 30#endif
29//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 31//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
30 32
31//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 33//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
32//const int QTReader::fontsizes[] = {10,16,17,22,0}; 34//const int QTReader::fontsizes[] = {10,16,17,22,0};
33//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 35//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
34//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}; 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};
35 37
36QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) : 38QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
37 QWidget(parent, name, f), 39 QWidget(parent, name, f),
38 m_delay(100), 40 m_delay(100),
39 m_scrolldy(0), 41 m_scrolldy1(0),
42 m_scrolldy2(0),
40 m_autoScroll(false), 43 m_autoScroll(false),
41 textarray(NULL), 44 //textarray(NULL),
42 locnarray(NULL), 45 //locnarray(NULL),
43 numlines(0), 46 numlines(0),
44 m_fontname("unifont"), 47 m_fontname("unifont"),
45 m_fm(NULL) 48 m_fm(NULL),
49 mouseUpOn(true),
50 m_twotouch(true),
51 m_touchone(true)
46{ 52{
47 m_overlap = 1; 53 m_overlap = 1;
48 fontsizes = NULL;
49// init(); 54// init();
50} 55}
51/* 56/*
52QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 57QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
53 QWidget(parent, name, f), 58 QWidget(parent, name, f),
54 m_textfont(0), 59 m_textfont(0),
55 m_textsize(1), 60 m_textsize(1),
56 textarray(NULL), 61 textarray(NULL),
57 numlines(0), 62 numlines(0),
58 bstripcr(true), 63 bstripcr(true),
59 bunindent(false), 64 bunindent(false),
60 brepara(false), 65 brepara(false),
@@ -65,538 +70,578 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
65{ 70{
66 init(); 71 init();
67 // qDebug("Load_file(1)"); 72 // qDebug("Load_file(1)");
68 load_file((const tchar*)filename); 73 load_file((const tchar*)filename);
69} 74}
70*/ 75*/
71 76
72long QTReader::real_delay() 77long QTReader::real_delay()
73{ 78{
74 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 79 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
75} 80}
76 81
77void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 82void QTReader::mousePressEvent( QMouseEvent* _e )
78//void QTReader::mouseDoubleClickEvent( QMouseEvent* _e )
79{ 83{
80 if (textarray != NULL) 84 if (_e->button() == RightButton)
81 { 85 {
82// printf("(%u, %u)\n", _e->x(), _e->y()); 86 mouseUpOn = false;
83 QString wrd = QString::null; 87 if (_e->y() > height()/2)
84 int lineno = _e->y()/m_linespacing; 88 {
85 if (m_bMonoSpaced) 89 goDown();
86 { 90 }
87 int chno = _e->x()/m_charWidth; 91 else
88 if (chno < ustrlen(textarray[lineno]->data())) 92 {
89 { 93 goUp();
90 wrd[0] = textarray[lineno]->data()[chno]; 94 }
91 } 95 }
92 } 96}
93 else 97
94 { 98bool QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
95 CBuffer* t = textarray[lineno]; 99{
96 int first = 0; 100 int lineno = 0;
97 while (1) 101 int ht = textarray[0]->lineSpacing();
98 { 102 while ((ht < y) && (lineno < numlines))
99 int i = first+1;
100// while ((*t)[i] != ' ' && (*t)[i] != 0) i++;
101 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
102 if (m_fm->width(toQString(t->data()), i) > _e->x())
103 { 103 {
104 wrd = toQString(t->data()+first, i - first); 104 ht += textarray[++lineno]->lineSpacing();
105 break;
106 } 105 }
107// while ((*t)[i] == ' ' && (*t)[i] != 0) i++; 106 start = locnarray[lineno];
108 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 107 if (m_bMonoSpaced)
109 if ((*t)[i] == 0) break; 108 {
110 first = i; 109 offset = x/m_charWidth;
111 } 110 }
112 } 111 else
113 if (!wrd.isEmpty()) 112 {
114 { 113 int i;
115 QClipboard* cb = QApplication::clipboard(); 114 CDrawBuffer* t = textarray[lineno];
116 cb->setText(wrd); 115 for (i = t->length(); t->width(i) > x; i--);
117 Global::statusMessage(wrd); 116 offset = i;
118 if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty()) 117 }
119 { 118 return textarray[lineno]->isLink(offset, tgt);
120 QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8()); 119}
121 e << wrd; 120
122 } 121void QTReader::setTwoTouch(bool _b)
123 } 122{
123 setBackgroundColor( white );
124 m_twotouch = m_touchone = _b;
125}
126
127void QTReader::mouseReleaseEvent( QMouseEvent* _e )
128{
129 if (_e->button() == LeftButton)
130 {
131 if (mouseUpOn)
132 {
133 if (textarray[0] != NULL)
134 {
135 QString wrd, line;
136 // int lineno = _e->y()/m_linespacing;
137 int lineno = 0;
138 int ht = textarray[0]->lineSpacing();
139 while ((ht < _e->y()) && (lineno < numlines))
140 {
141 ht += textarray[++lineno]->lineSpacing();
142 }
143 size_t startpos, startoffset, tgt;
144 if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
145 {
146 if (buffdoc.hyperlink(tgt))
147 {
148 fillbuffer();
149 update();
150 }
151 else
152 {
153 locate(pagelocate());
154 }
155 return;
156 }
157 if (m_twotouch)
158 {
159 if (m_touchone)
160 {
161 m_touchone = false;
162 m_startpos = startpos;
163 m_startoffset = startoffset;
164 setBackgroundColor( lightGray );
165 }
166 else
167 {
168 m_touchone = true;
169 setBackgroundColor( white );
170 size_t endpos, endoffset;
171 endpos = startpos;
172 endoffset = startoffset;
173 size_t currentpos = locate();
174 if (endpos >= m_startpos)
175 {
176 jumpto(m_startpos);
177 for (int i = 0; i < m_startoffset; i++)
178 {
179 getch();
180 }
181 if (m_startpos == endpos)
182 {
183 for (int i = m_startoffset; i <= endoffset; i++)
184 {
185 wrd += QChar(getch());
186 }
187 }
188 else
189 {
190 while (buffdoc.explocate() <= endpos)
191 {
192 wrd += QChar(getch());
193 }
194 for (int i = 0; i < endoffset; i++)
195 {
196 wrd += QChar(getch());
197 }
198 }
199 jumpto(currentpos);
200 }
201 }
202 }
203 else if (m_bMonoSpaced)
204 {
205 int chno = _e->x()/m_charWidth;
206 if (chno < ustrlen(textarray[lineno]->data()))
207 {
208 wrd[0] = textarray[lineno]->data()[chno];
209 }
210 }
211 else
212 {
213 CDrawBuffer* t = textarray[lineno];
214 int first = 0;
215 while (1)
216 {
217 int i = first+1;
218 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
219 if (t->width(i) > _e->x())
220 {
221 wrd = toQString(t->data()+first, i - first);
222 break;
223 }
224 while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
225 if ((*t)[i] == 0) break;
226 first = i;
227 }
228 }
229 if (!wrd.isEmpty())
230 {
231 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
232 }
233 }
234 }
235 else
236 {
237 mouseUpOn = true;
238 }
124 } 239 }
125} 240}
126 241
127void QTReader::focusInEvent(QFocusEvent* e) 242void QTReader::focusInEvent(QFocusEvent* e)
128{ 243{
129 if (m_autoScroll) timer->start(real_delay(), false); 244 if (m_autoScroll) timer->start(real_delay(), false);
130 update(); 245 update();
131} 246}
132 247
133void QTReader::focusOutEvent(QFocusEvent* e) 248void QTReader::focusOutEvent(QFocusEvent* e)
134{ 249{
135 if (m_autoScroll) 250 if (m_autoScroll)
136 { 251 {
137 timer->stop(); 252 timer->stop();
138 m_scrolldy = 0; 253 m_scrolldy1 = m_scrolldy2 = 0;
139 } 254 }
140} 255}
141 256
142#include <qapplication.h> 257#include <qapplication.h>
143#include <qdrawutil.h> 258#include <qdrawutil.h>
144#include <unistd.h> 259#include <unistd.h>
145 260
146void QTReader::goDown() 261void QTReader::goDown()
147{ 262{
148 if (m_bpagemode) 263 if (m_bpagemode)
149 { 264 {
150 dopagedn(); 265 dopagedn();
151 } 266 }
152 else 267 else
153 { 268 {
154 lineDown(); 269 lineDown();
155 } 270 }
156} 271}
157 272
158void QTReader::goUp() 273void QTReader::goUp()
159{ 274{
160 if (m_bpagemode) 275 if (m_bpagemode)
161 { 276 {
162 dopageup(); 277 dopageup();
163 } 278 }
164 else 279 else
165 { 280 {
166 lineUp(); 281 lineUp();
167 } 282 }
168} 283}
169 284
170void QTReader::keyPressEvent(QKeyEvent* e) 285void QTReader::keyPressEvent(QKeyEvent* e)
171{ 286{
172 switch (e->key()) 287 switch (e->key())
173 { 288 {
174 case Key_Down: 289 case Key_Down:
175 { 290 {
176 e->accept(); 291 e->accept();
177 if (m_autoScroll) 292 if (m_autoScroll)
178 { 293 {
179 if (m_delay < 59049) 294 if (m_delay < 59049)
180 { 295 {
181 m_delay = (3*m_delay)/2; 296 m_delay = (3*m_delay)/2;
182 timer->changeInterval(real_delay()); 297 timer->changeInterval(real_delay());
183 } 298 }
184 else 299 else
185 { 300 {
186 m_delay = 59049; 301 m_delay = 59049;
187 } 302 }
188 } 303 }
189 else 304 else
190 { 305 {
191 goDown(); 306 goDown();
192 } 307 }
193 } 308 }
194 break; 309 break;
195 case Key_Up: 310 case Key_Up:
196 { 311 {
197 e->accept(); 312 e->accept();
198 if (m_autoScroll) 313 if (m_autoScroll)
199 { 314 {
200 if (m_delay > 1024) 315 if (m_delay > 1024)
201 { 316 {
202 m_delay = (2*m_delay)/3; 317 m_delay = (2*m_delay)/3;
203 timer->changeInterval(real_delay()); 318 timer->changeInterval(real_delay());
204 } 319 }
205 else 320 else
206 { 321 {
207 m_delay = 1024; 322 m_delay = 1024;
208 } 323 }
209 } 324 }
210 else 325 else
211 { 326 {
212 goUp(); 327 goUp();
213 } 328 }
214 } 329 }
215 break; 330 break;
216 /* 331 /*
217 case Key_Left: 332 case Key_Left:
218 { 333 {
219 e->accept(); 334 e->accept();
220 if (m_textfont > 0) 335 if (m_textfont > 0)
221 { 336 {
222 m_textfont--; 337 m_textfont--;
223 setfont(NULL); 338 setfont(NULL);
224 locate(pagelocate()); 339 locate(pagelocate());
225 update(); 340 update();
226 } 341 }
227 } 342 }
228 break; 343 break;
229 case Key_Right: 344 case Key_Right:
230 { 345 {
231 e->accept(); 346 e->accept();
232 if (fonts[++m_textfont] == 0) 347 if (fonts[++m_textfont] == 0)
233 { 348 {
234 m_textfont--; 349 m_textfont--;
235 } 350 }
236 else 351 else
237 { 352 {
238 setfont(NULL); 353 setfont(NULL);
239 locate(pagelocate()); 354 locate(pagelocate());
240 update(); 355 update();
241 } 356 }
242 } 357 }
243 break; 358 break;
244 */ 359 */
245 case Key_Right: 360 case Key_Right:
246 { 361 {
247 e->accept(); 362 e->accept();
248 if (fontsizes[++m_textsize] == 0) 363 if (m_fontControl.increasesize())
249 { 364 {
250 m_textsize--; 365 bool sc = m_autoScroll;
251 } 366 setfont();
252 else 367 m_autoScroll = false;
253 { 368 locate(pagelocate());
254 bool sc = m_autoScroll; 369 update();
255 m_autoScroll = false; 370 m_autoScroll = sc;
256 setfont(NULL); 371 if (m_autoScroll) autoscroll();
257 locate(pagelocate()); 372 }
258 update(); 373 }
259 m_autoScroll = sc;
260 if (m_autoScroll) autoscroll();
261 }
262 }
263 break; 374 break;
264 case Key_Left: 375 case Key_Left:
265 { 376 {
266 e->accept(); 377 e->accept();
267 if (m_textsize > 0) 378 if (m_fontControl.decreasesize())
268 { 379 {
269 bool sc = m_autoScroll; 380 bool sc = m_autoScroll;
270 m_autoScroll = false; 381 m_autoScroll = false;
271 m_textsize--; 382 setfont();
272 setfont(NULL); 383 locate(pagelocate());
273 locate(pagelocate()); 384 update();
274 update(); 385 m_autoScroll = sc;
275 m_autoScroll = sc; 386 if (m_autoScroll) autoscroll();
276 if (m_autoScroll) autoscroll(); 387 }
277 } 388 }
278 }
279 break; 389 break;
280 case Key_Space: 390 case Key_Space:
281// case Key_Enter: 391 case Key_Return:
282 case Key_Return: 392 {
283 { 393 e->accept();
284 e->accept(); 394 emit OnActionPressed();
285 setautoscroll(!m_autoScroll); 395 }
286 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 396 break;
287 } 397 default:
288 break; 398 e->ignore();
289 default:
290 e->ignore();
291 } 399 }
292} 400}
293 401
294void QTReader::setautoscroll(bool _sc) 402void QTReader::setautoscroll(bool _sc)
295{ 403{
296 if (_sc == m_autoScroll) return; 404 if (_sc == m_autoScroll) return;
297 if (m_autoScroll) 405 if (m_autoScroll)
298 { 406 {
299 m_autoScroll = false; 407 m_autoScroll = false;
300 } 408 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
409 }
301 else 410 else
302 { 411 {
303 m_autoScroll = true; 412 m_autoScroll = true;
304 autoscroll(); 413 autoscroll();
414 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
305 } 415 }
306} 416}
307 417
308bool QTReader::getline(CBuffer *buff) 418bool QTReader::getline(CDrawBuffer *buff)
309{ 419{
310 if (m_bMonoSpaced) 420 if (m_bMonoSpaced)
311 { 421 {
312 return buffdoc.getline(buff ,width(), m_charWidth); 422 return buffdoc.getline(buff ,width(), m_charWidth);
313 } 423 }
314 else 424 else
315 { 425 {
316 return buffdoc.getline(buff, width()); 426 return buffdoc.getline(buff, width());
317 } 427 }
318} 428}
319 429
320void QTReader::doscroll() 430void QTReader::doscroll()
321{ 431{
322 if (!m_autoScroll) 432 if (!m_autoScroll)
323 { 433 {
324 timer->stop(); 434 timer->stop();
325 return; 435 return;
326 } 436 }
327// timer->changeInterval(real_delay()); 437// timer->changeInterval(real_delay());
328 QPainter p( this ); 438 QPainter p( this );
329 QBrush b( white); 439 QBrush b( white);
330 bitBlt(this,0,0,this,0,1,width(),-1); 440 bitBlt(this,0,0,this,0,1,width(),-1);
331 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); 441 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
332 442
333 if (++m_scrolldy == m_linespacing) 443 if (++m_scrolldy1 == textarray[0]->lineSpacing())
334 {
335 setfont(&p);
336 m_scrolldy = 0;
337// qDrawPlainRect(&p,0,height() - m_linespacing,width(),m_linespacing,white,1,&b);
338 pagepos = locnarray[1];
339 CBuffer* buff = textarray[0];
340 for (int i = 1; i < numlines; i++)
341 {
342 textarray[i-1] = textarray[i];
343 locnarray[i-1] = locnarray[i];
344 }
345 locnarray[numlines-1] = locate();
346 if (getline(buff))
347 {
348 textarray[numlines-1] = buff;
349 drawText( p, 0, height() - m_descent - 2, buff->data());
350 mylastpos = locate();
351 }
352 else
353 {
354// (*buff)[0] = '\0';
355 textarray[numlines-1] = buff;
356 m_autoScroll = false;
357 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
358 }
359 }
360}
361
362void QTReader::drawText(QPainter& p, int x, int y, tchar* _text)
363{
364 QString text = toQString(_text);
365 if (m_bMonoSpaced)
366 { 444 {
367 for (int i = 0; i < text.length(); i++) 445 CDrawBuffer* buff = textarray[0];
368 { 446 for (int i = 1; i <= numlines; i++)
369 p.drawText( x+i*m_charWidth, y, QString(text[i]) ); 447 {
370 } 448 textarray[i-1] = textarray[i];
449 locnarray[i-1] = locnarray[i];
450 }
451 textarray[numlines] = buff;
452 --numlines;
453 m_scrolldy1 = 0;
371 } 454 }
372 else 455 if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
373 { 456 {
374 p.drawText( x, y, text ); 457 m_scrolldy2 = 0;
458 numlines++;
459
460 if (textarray[numlines] == NULL)
461 {
462 textarray[numlines] = new CDrawBuffer;
463 }
464 locnarray[numlines] = locate();
465 int ch = getline(textarray[numlines]);
466 textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
467 mylastpos = locate();
468 if (!ch)
469 {
470 m_autoScroll = false;
471 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
472 emit OnRedraw();
473 }
474 emit OnRedraw();
375 } 475 }
376} 476}
377 477
378void QTReader::autoscroll() 478void QTReader::autoscroll()
379{ 479{
380 timer->start(real_delay(), false); 480 timer->start(real_delay(), false);
381} 481}
382 482
383void QTReader::setfont(QPainter* p) 483void QTReader::setfont()
384{ 484{
385 // qDebug("Fontsize = %u",fontsizes[m_textsize]); 485// m_fontControl.Change
386 // qDebug("SetFont %x",p); 486 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
387 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
388 m_charWidth = (m_charpc*fontsizes[m_textsize])/100;
389 if (m_charWidth <= 0) m_charWidth = 1; 487 if (m_charWidth <= 0) m_charWidth = 1;
390// font.setFixedPitch(m_bMonoSpaced); 488 m_ascent = m_fontControl.ascent();
391// qDebug("Raw name = %s", (const char*)font.rawName()); 489 m_descent = m_fontControl.descent();
392 if (p != NULL) p->setFont( font ); 490 m_linespacing = m_fontControl.lineSpacing();
393 if (m_fm == NULL)
394 {
395 m_fm = new QFontMetrics(font);
396 buffdoc.setfm(m_fm);
397 }
398 else
399 {
400 *m_fm = QFontMetrics(font);
401 }
402 m_ascent = m_fm->ascent();
403 m_descent = m_fm->descent();
404 m_linespacing = m_fm->lineSpacing();
405} 491}
406 492
407void QTReader::drawFonts( QPainter *p ) 493void QTReader::drawFonts( QPainter *p )
408{ 494{
409 setfont(p); 495 setfont();
410 if (m_lastwidth != width()) 496 if (m_lastwidth != width() || m_lastheight != height())
411 { 497 {
412 m_lastwidth = width(); 498 m_lastwidth = width();
413 locate(pagepos); 499 m_lastheight = height();
500 locate(pagelocate());
414 } 501 }
415 else 502 else
416 { 503 {
504
505/*
417 int sl = screenlines(); 506 int sl = screenlines();
418 if (sl < numlines) 507 if (sl < numlines)
419 { 508 {
420// qDebug("df:<%u,%u>",sl,numlines); 509 //qDebug("df:<%u,%u>",sl,numlines);
421 510
422 size_t newpos = locnarray[sl]; 511 size_t newpos = locnarray[sl];
423 CBuffer** nta = new CBuffer*[sl]; 512 CDrawBuffer** nta = new CDrawBuffer*[sl];
424 size_t* nla = new size_t[sl]; 513 size_t* nla = new size_t[sl];
425 for (int i = 0; i < sl; i++) 514 for (int i = 0; i < sl; i++)
426 { 515 {
427 nta[i] = textarray[i]; 516 nta[i] = textarray[i];
428 nla[i] = locnarray[i]; 517 nla[i] = locnarray[i];
429 } 518 }
430 for (int i = sl; i < numlines; i++) delete textarray[i]; 519 for (int i = sl; i < numlines; i++) delete textarray[i];
431 delete [] textarray; 520 delete [] locnarray;
432 delete [] locnarray; 521 delete [] textarray;
433 textarray = nta; 522 textarray = nta;
434 locnarray = nla; 523 locnarray = nla;
435 numlines = sl; 524 numlines = sl;
436 jumpto(mylastpos = newpos); 525 jumpto(mylastpos = newpos);
437// locate(pagepos);
438 } 526 }
439 if (sl > numlines) 527 if (sl > numlines)
440 { 528 {
441// qDebug("df:<%u,%u>",sl,numlines); 529 //qDebug("df:<%u,%u>",sl,numlines);
442 CBuffer** nta = new CBuffer*[sl]; 530 CDrawBuffer** nta = new CDrawBuffer*[sl];
443 size_t* nla = new size_t[sl]; 531 size_t* nla = new size_t[sl];
444 for (int i = 0; i < numlines; i++) 532 for (int i = 0; i < numlines; i++)
445 { 533 {
446 nta[i] = textarray[i]; 534 nta[i] = textarray[i];
447 nla[i] = locnarray[i]; 535 nla[i] = locnarray[i];
448 } 536 }
449 if (locate() != mylastpos) jumpto(mylastpos); 537 if (locate() != mylastpos) jumpto(mylastpos);
450 for (int i = numlines; i < sl; i++) 538 for (int i = numlines; i < sl; i++)
451 { 539 {
452 nta[i] = new CBuffer; 540 nta[i] = new CDrawBuffer(&m_fontControl);
453 nla[i] = locate(); 541 nla[i] = locate();
454 getline(nta[i]); 542 getline(nta[i]);
455 } 543 }
456 mylastpos = locate(); 544 mylastpos = locate();
457 delete [] textarray; 545 delete [] locnarray;
458 delete [] locnarray; 546 delete [] textarray;
459 textarray = nta; 547 textarray = nta;
460 locnarray = nla; 548 locnarray = nla;
461 numlines = sl; 549 numlines = sl;
462 } 550 }
463 int ypos = (btight) ? 0 : m_ascent-m_linespacing; 551*/
464 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 552 if (numlines > 0)
465 for (int i = 0; i < numlines; i++) 553 {
554 int ypos = textarray[0]->ascent();
555 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
556 for (int i = 1; i < numlines; i++)
466 { 557 {
467 drawText( *p, 0, ypos += m_linespacing, textarray[i]->data()); 558 ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
559 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
560
561 }
562// mylastpos = locate();
468 } 563 }
469 /*
470
471
472
473 int nlines = height()/(fontmetric.ascent()+fontmetric.descent());
474 tchar buffer[1024];
475 for (int i = 0; i < nlines; i++)
476 {
477 y += fontmetric.ascent();
478 sprintf(buffer, "%d:%d:%s[%d]:Lines %d:%s", i+1, m_textfont, fonts[m_textfont], m_fs, nlines, (const tchar*)m_string);
479 drawText( *p, 0, y, buffer );
480 y += fontmetric.descent();
481 }
482 */
483 } 564 }
484 m_scrolldy = 0; 565 m_scrolldy1 = m_scrolldy2 = 0;
566 emit OnRedraw();
485} 567}
486 568
487QString QTReader::firstword() 569QString QTReader::firstword()
488{ 570{
489 if (m_bMonoSpaced) 571 if (m_bMonoSpaced)
490 { 572 {
491 return toQString(textarray[0]->data()); 573 return toQString(textarray[0]->data());
492 } 574 }
493 else 575 else
494 { 576 {
495 int start, end, len, j; 577 int start, end, len, j;
496 for (j = 0; j < numlines; j++) 578 for (j = 0; j < numlines; j++)
497 { 579 {
498 len = textarray[j]->length(); 580 len = textarray[j]->length();
499 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++); 581 for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
500 if (start < len) break; 582 if (start < len) break;
501 } 583 }
502 if (j < numlines) 584 if (j < numlines)
503 { 585 {
504 QString ret = ""; 586 QString ret = "";
505 for (end = start; end < len && isalpha((*textarray[j])[end]); end++) 587 for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
506 ret += (*textarray[j])[end]; 588 ret += (*textarray[j])[end];
507 if (ret.isEmpty()) ret = "Current position"; 589 if (ret.isEmpty()) ret = "Current position";
508 return ret; 590 return ret;
509 } 591 }
510 else 592 else
511 return "Current position"; 593 return "Current position";
512 } 594 }
513} 595}
514 596
515// 597//
516// Construct the QTReader with buttons. 598// Construct the QTReader with buttons.
517// 599//
518 600
519void QTReader::ChangeFont(int tgt) 601bool QTReader::ChangeFont(int tgt)
520{ 602{
521 603 return m_fontControl.ChangeFont(m_fontname, tgt);
522 QValueList<int>::Iterator it;
523
524// QValueList<int> sizes = QFontDatabase::pointSizes(m_fontname, (m_bBold) ? QFont::Bold : QFont::Normal);
525 QFontDatabase fdb;
526/*
527 QStringList styles = fdb.styles(m_fontname);
528 for ( QStringList::Iterator it = styles.begin(); it != styles.end(); ++it )
529 {
530 printf( "%s \n", (*it).latin1() );
531 }
532*/
533 QValueList<int> sizes = fdb.pointSizes(m_fontname, (m_bBold) ? QString("Bold") : QString::null);
534 uint n = sizes.count();
535 if (fontsizes != NULL) delete [] fontsizes;
536 fontsizes = new unsigned int[n+1];
537 uint i = 0;
538 uint best = 0;
539 for (it = sizes.begin(); it != sizes.end(); it++)
540 {
541 fontsizes[i] = (*it)/10;
542 if (abs(tgt-fontsizes[i]) < abs(tgt-fontsizes[best]))
543 {
544 best = i;
545 }
546 i++;
547 }
548 m_textsize = best;
549 fontsizes[i] = 0;
550 setfont(NULL);
551 QFont font(m_fontname, fontsizes[m_textsize], (m_bBold) ? QFont::Bold : QFont::Normal );
552 if (m_fm == NULL)
553 {
554 m_fm = new QFontMetrics(font);
555 buffdoc.setfm(m_fm);
556 }
557} 604}
558 605
559void QTReader::init() 606void QTReader::init()
560{ 607{
561 // setCaption( "Qt Draw Demo Application" ); 608 // setCaption( "Qt Draw Demo Application" );
562 609
563 setBackgroundColor( white ); 610 setBackgroundColor( white );
564// QPainter p(this); 611// QPainter p(this);
565// p.setBackgroundMode( Qt::OpaqueMode ); 612// p.setBackgroundMode( Qt::OpaqueMode );
566 buffdoc.setfilter(getfilter()); 613 buffdoc.setfilter(getfilter());
567 ChangeFont(m_textsize); 614 ChangeFont(m_textsize);
568 // setFocusPolicy(QWidget::StrongFocus); 615 setFocusPolicy(QWidget::StrongFocus);
569 // resize( 240, 320 ); 616 // resize( 240, 320 );
570 //setFocus(); 617 //setFocus();
571 timer = new QTimer(this); 618 timer = new QTimer(this);
572 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 619 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
573// QMessageBox::information(this, "init", m_lastfile, 1); 620// QMessageBox::information(this, "init", m_lastfile, 1);
574 m_lastwidth = width(); 621 m_lastwidth = width();
622 m_lastheight = height();
623 setfont();
575 if (!m_lastfile.isEmpty()) 624 if (!m_lastfile.isEmpty())
576 { 625 {
577 m_string = DocLnk(m_lastfile).name(); 626 m_string = DocLnk(m_lastfile).name();
578 load_file(m_lastfile); 627 load_file(m_lastfile);
579 } 628 }
580} 629}
581 630
582// 631//
583// Clean up 632// Clean up
584// 633//
585QTReader::~QTReader() 634QTReader::~QTReader()
586{ 635{
587 if (fontsizes != NULL) delete [] fontsizes;
588#ifndef QT_NO_PRINTER
589 // delete printer;
590#endif
591} 636}
592 637
593// 638//
594// Calls the drawing function as specified by the radio buttons. 639// Calls the drawing function as specified by the radio buttons.
595// 640//
596 641
597void QTReader::drawIt( QPainter *p ) 642void QTReader::drawIt( QPainter *p )
598{ 643{
599 drawFonts(p); 644 drawFonts(p);
600} 645}
601 646
602// 647//
@@ -663,288 +708,292 @@ bool QTReader::locate(unsigned long n) {
663 update(); 708 update();
664 // qDebug("&Located"); 709 // qDebug("&Located");
665 return true; 710 return true;
666} 711}
667 712
668unsigned int QTReader::screenlines() 713unsigned int QTReader::screenlines()
669{ 714{
670 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 715 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
671 // return (height()-m_descent)/(m_linespacing); 716 // return (height()-m_descent)/(m_linespacing);
672 return (height()-2)/(m_linespacing); 717 return (height()-2)/(m_linespacing);
673}; 718};
674 719
675bool QTReader::fillbuffer() { 720bool QTReader::fillbuffer(int reuse, int ht)
676 if (buffdoc.empty()) return false; 721{
677 //printf("Fillbuffer\n"); 722 if (buffdoc.empty()) return false;
678 m_scrolldy = 0; 723 m_scrolldy1 = m_scrolldy2 = 0;
679 int ch; 724 int ch;
680 bool ret = false; 725 bool ret = false;
681 int delta = screenlines(); 726 unsigned int oldpagepos = locnarray[reuse];
682 // qDebug("fillbuffer:%u-%u",delta,numlines); 727 int ypos = ht;
683 if (delta != numlines) 728 numlines = reuse;
684 { 729 while (ypos < height())
685 if (textarray != NULL)
686 {
687 for (int i = 0; i < numlines; i++) delete textarray[i];
688 delete [] textarray;
689 delete [] locnarray;
690 }
691 numlines = delta;
692 textarray = new CBuffer*[numlines];
693 locnarray = new size_t[numlines];
694 for (int i = 0; i < numlines; i++) textarray[i] = new CBuffer;
695 }
696 // qDebug("fillbuffer:pagepos:%u",pagepos);
697 unsigned int oldpagepos = pagepos;
698// if (textarray != NULL)
699// pagepos = locnarray[0];
700// else
701 pagepos = locate();
702 for (int i = 0; i < delta; i++)
703 { 730 {
704 locnarray[i] = locate(); 731 if (textarray[numlines] == NULL)
705 ch = getline(textarray[i]); 732 {
706 // if (ch == EOF) { 733 textarray[numlines] = new CDrawBuffer(&m_fontControl);
707 if (!ch) 734 }
708 { 735 locnarray[numlines] = locate();
709 if (i == 0) 736 int ch = getline(textarray[numlines]);
710 { 737 ypos += textarray[numlines]->lineSpacing();
711 locate(oldpagepos); 738 numlines++;
712 return false; 739 if (!ch)
713 } 740 {
714 else 741 if (numlines - reuse == 1/* && locnarray[0] == buffdoc.locate()*/)
715 { 742 {
716 ret = true; 743 locate(oldpagepos);
717 for (int j = i+1; j < delta; j++) 744 return false;
718 { 745 }
719 locnarray[j] = locnarray[j-1]; 746 else
720 (*(textarray[j]))[0] = '\0'; 747 {
721 } 748 --numlines;
722 break; 749 mylastpos = locate();
723 } 750 return true;
724 } 751 }
725 if (ch == '\012') ret = true; 752 }
726 } 753 }
727 mylastpos = locate(); 754
728 // qDebug("fillbuffer:lastpos:%u",mylastpos); 755 --numlines;
729 return true; 756 mylastpos = locate();
757
758 return true;
730} 759}
731 760
732 761
733void QTReader::dopagedn() 762void QTReader::dopagedn()
734{ 763{
735 if (m_overlap == 0) 764 int skip = 0, ypos = 0;
765 if (locate() != mylastpos)
736 { 766 {
737 if (locate() != mylastpos) jumpto(mylastpos); 767 //qDebug("Jumping to %u", mylastpos);
768 jumpto(mylastpos);
738 } 769 }
739 else 770 CDrawBuffer* reusebuffer = textarray[numlines];
771 if (reusebuffer != NULL)
740 { 772 {
741 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 773 for (int i = 0; i <= m_overlap; i++)
742 jumpto(locnarray[screenlines()-m_overlap]); 774 {
775 int offset = numlines - m_overlap + i;
776 reusebuffer = textarray[offset];
777 size_t reuselocn = locnarray[offset];
778 textarray[offset] = textarray[i];
779 textarray[i] = reusebuffer;
780 locnarray[offset] = locnarray[i];
781 locnarray[i] = reuselocn;
782 ypos += textarray[i]->lineSpacing();
783 skip++;
784 }
743 } 785 }
744 if (fillbuffer()) 786 if (fillbuffer(skip, ypos))
745 { 787 {
746 update(); 788 update();
747 } 789 }
748} 790}
749 791
750void QTReader::dopageup() 792void QTReader::dopageup()
751{ 793{
752 CBuffer** buff = textarray; 794 CBufferFace<CDrawBuffer*> buff;
753 unsigned int *loc = new unsigned int[numlines]; 795 CBufferFace<size_t> loc;
754 int cbptr = 0; 796 unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2];
755 if (locate() != mylastpos) jumpto(mylastpos); 797
756 if (m_overlap >= screenlines()) m_overlap = screenlines()/2; 798 size_t delta;
757 unsigned int target = locnarray[m_overlap]; 799 if (target < 2048)
758 if (buffdoc.hasrandomaccess())
759 {
760 unsigned int delta = locate()-pagelocate();
761 if (delta < 64) delta = 64;
762 if (delta % 2 != 0) delta++;
763 if (target % 2 != 0) target++;
764 do
765 { 800 {
766 delta <<= 1; 801 delta = target;
767 if (delta >= target) 802 jumpto(0);
768 { 803 }
769 delta = target; 804 else
770 jumpto(0); 805 {
771 for (int i = 0; i < numlines; i++) 806 delta = 2048;
772 { 807
773 loc[i] = locate(); 808 jumpto(target - delta);
774 getline(buff[i]); 809
775 } 810 buff[0] = new CDrawBuffer(&m_fontControl);
776 break; 811
777 } 812 do
778 jumpto(target-delta);
779 do
780 {
781 getline(buff[0]);
782#ifdef WS
783 //printf("Trying:%s\n",buff[0]);
784#endif
785 if (locate() > target) continue;
786 }
787 while (!buffdoc.iseol());
788 for (int i = 0; i < numlines; i++)
789 { 813 {
790 loc[i] = locate(); 814
791 getline(buff[i]); 815 if (!getline(buff[0])) break;
792#ifdef WS 816
793 //printf("Filling:%s\n",buff[i]); 817 if (locate() > target) continue;
794#endif
795 } 818 }
819 while (!buffdoc.iseol());
796 } 820 }
797 while (locate() >= target && delta < 4096); 821 int nbfl = 0;
798#ifdef WS 822
799 //printf("Delta:%u\n",delta); 823 bool ch = true;
800#endif 824 int ypos = 0;
801 } 825 while (locate() < target)
802 else
803 {
804 jumpto(0);
805 for (int i = 0; i < numlines; i++)
806 { 826 {
807 loc[i] = locate(); 827 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
808 getline(buff[i]); 828 loc[nbfl] = locate();
829 ch = getline(buff[nbfl]);
830 ypos += buff[nbfl]->lineSpacing();
831 nbfl++;
832 if (!ch) break;
809 } 833 }
810 } 834 if (ypos < height())
811 cbptr = 0; 835 {
812 while (locate() < target) 836 locate(0);
813 { 837 return;
814 loc[cbptr] = locate(); 838 }
815 getline(buff[cbptr]); 839 if (ch)
816#ifdef WS 840 {
817 //printf("Adding:%s\n",buff[cbptr]->data()); 841 if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
818#endif 842 loc[nbfl] = locate();
819 cbptr = (cbptr+1) % numlines; 843 int ch = getline(buff[nbfl]);
820 } 844 nbfl++;
821 pagepos = loc[cbptr]; 845 }
822 textarray = new CBuffer*[numlines]; 846 ypos = 0;
823 for (int i = 0; i < numlines; i++) 847 numlines = 0;
824 { 848 while (ypos < height() && numlines <= nbfl-2)
825 int j = (cbptr+i)%numlines; 849 {
826 textarray[i] = buff[j]; 850 ypos += buff[nbfl - numlines - 2]->lineSpacing();
827 locnarray[i] = loc[j]; 851 numlines++;
828 } 852 }
829 delete [] buff; 853 --numlines;
830 delete [] loc; 854 int offset = nbfl;
855 offset -= numlines+1;
856 for (int i = 0; i <= numlines; i++)
857 {
858 delete textarray[i];
859 textarray[i] = buff[offset+i];
860 locnarray[i] = loc[offset + i];
861 }
862 for (int i = 0; i < nbfl - numlines - 1; i++)
863 {
864 delete buff[i];
865 }
866
867// --numlines;
831 mylastpos = locate(); 868 mylastpos = locate();
869
832 update(); 870 update();
833} 871}
834 872
835bool QTReader::load_file(const char *newfile, unsigned int _lcn) 873bool QTReader::load_file(const char *newfile, unsigned int _lcn)
836{ 874{
837// QMessageBox::information(this, "Name", name, 1); 875// QMessageBox::information(this, "Name", name, 1);
838// QMessageBox::information(this, "load_file", newfile, 1); 876// QMessageBox::information(this, "load_file", newfile, 1);
839 877
840 bool bRC = false; 878 bool bRC = false;
841 unsigned int lcn = _lcn; 879 unsigned int lcn = _lcn;
842 if (m_lastfile == newfile) 880 if (m_lastfile == newfile)
843 { 881 {
844 lcn = m_lastposn; 882 lcn = m_lastposn;
845 } 883 }
846 m_lastfile = newfile; 884 m_lastfile = newfile;
847 // QMessageBox::information(0, "Opening...", newfile); 885 // QMessageBox::information(0, "Opening...", newfile);
848 if (buffdoc.openfile(this,newfile) == 0) 886 if (buffdoc.openfile(this,newfile) == 0)
849 { 887 {
850 bRC = true; 888 bRC = true;
851 // qDebug("buffdoc.openfile done"); 889 // qDebug("buffdoc.openfile done");
852 locate(lcn); 890 locate(lcn);
853 // qDebug("buffdoc.locate done"); 891 // qDebug("buffdoc.locate done");
854 } 892 }
893 setfilter(getfilter());
855 update(); 894 update();
856 // qDebug("Updated"); 895 // qDebug("Updated");
857 return bRC; 896 return bRC;
858} 897}
859 898
860void QTReader::lineDown() 899void QTReader::lineDown()
861{ 900{
862 pagepos = locnarray[1]; 901 int ypos = 0;
863 CBuffer* buff = textarray[0]; 902 int offset = numlines;
864 for (int i = 1; i < numlines; i++) 903
904 for (int i = 0; i <= numlines; i++)
865 { 905 {
866 textarray[i-1] = textarray[i]; 906 if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
867 locnarray[i-1] = locnarray[i]; 907 {
908 offset = i-1;
909 break;
910 }
868 } 911 }
869 locnarray[numlines-1] = locate(); 912 offset = numlines - offset;
870 if (getline(buff)) 913 for (int i = offset; i <= numlines; i++)
871 { 914 {
872 textarray[numlines-1] = buff; 915 CDrawBuffer* buff = textarray[i-offset];
873 mylastpos = locate(); 916 textarray[i-offset] = textarray[i];
917 locnarray[i-offset] = locnarray[i];
918 textarray[i] = buff;
874 } 919 }
875 else 920 numlines = numlines - offset + 1;
921 locnarray[numlines] = locate();
922 if (textarray[numlines] == NULL)
876 { 923 {
877 textarray[numlines-1] = buff; 924 textarray[numlines] = new CDrawBuffer(&m_fontControl);
878 } 925 }
926 getline(textarray[numlines]);
927 mylastpos = locate();
879 update(); 928 update();
880} 929}
881/* 930/*
882void QTReader::lineUp() 931void QTReader::lineUp()
883{ 932{
884 CBuffer** buff = textarray; 933 CBuffer** buff = textarray;
885 unsigned int *loc = new unsigned int[numlines]; 934 unsigned int *loc = new unsigned int[numlines];
886 int cbptr = 0; 935 int cbptr = 0;
887 if (locate() != mylastpos) jumpto(mylastpos); 936 if (locate() != mylastpos) jumpto(mylastpos);
888 unsigned int target = locnarray[numlines-1]; 937 unsigned int target = locnarray[numlines-1];
889 if (buffdoc.hasrandomaccess()) 938 if (buffdoc.hasrandomaccess())
890 { 939 {
891 unsigned int delta = locate()-pagelocate(); 940 unsigned int delta = locate()-pagelocate();
892 if (delta < 64) delta = 64; 941 if (delta < 64) delta = 64;
893 do 942 do
894 { 943 {
895 delta <<= 1; 944 delta <<= 1;
896 if (delta >= target) 945 if (delta >= target)
897 { 946 {
898 delta = target; 947 delta = target;
899 jumpto(0); 948 jumpto(0);
900 for (int i = 0; i < numlines; i++) 949 for (int i = 0; i < numlines; i++)
901 { 950 {
902 loc[i] = locate(); 951 loc[i] = locate();
903 getline(buff[i]); 952 getline(buff[i]);
904 } 953 }
905 break; 954 break;
906 } 955 }
907 jumpto(target-delta); 956 jumpto(target-delta);
908 do 957 do
909 { 958 {
910 buffdoc.getline(buff[0],width()); 959 buffdoc.getline(buff[0],width());
911#ifdef WS 960#ifdef WS
912 //printf("Trying:%s\n",buff[0]); 961 //printf("Trying:%s\n",buff[0]);
913#endif 962#endif
914 if (locate() > target) continue; 963 if (locate() > target) continue;
915 } 964 }
916 while (!buffdoc.iseol()); 965 while (!buffdoc.iseol());
917 for (int i = 0; i < numlines; i++) 966 for (int i = 0; i < numlines; i++)
918 { 967 {
919 loc[i] = locate(); 968 loc[i] = locate();
920 buffdoc.getline(buff[i],width()); 969 buffdoc.getline(buff[i],width());
921#ifdef WS 970#ifdef WS
922 //printf("Filling:%s\n",buff[i]); 971 //printf("Filling:%s\n",buff[i]);
923#endif 972#endif
924 } 973 }
925 } 974 }
926 while (locate() >= target && delta < 4096); 975 while (locate() >= target && delta < 4096);
927#ifdef WS 976#ifdef WS
928 //printf("Delta:%u\n",delta); 977 //printf("Delta:%u\n",delta);
929#endif 978#endif
930 } 979 }
931 else 980 else
932 { 981 {
933 jumpto(0); 982 jumpto(0);
934 for (int i = 0; i < numlines; i++) 983 for (int i = 0; i < numlines; i++)
935 { 984 {
936 loc[i] = locate(); 985 loc[i] = locate();
937 buffdoc.getline(buff[i],width()); 986 buffdoc.getline(buff[i],width());
938 } 987 }
939 } 988 }
940 cbptr = 0; 989 cbptr = 0;
941 while (locate() < target) 990 while (locate() < target)
942 { 991 {
943 loc[cbptr] = locate(); 992 loc[cbptr] = locate();
944 buffdoc.getline(buff[cbptr], width()); 993 buffdoc.getline(buff[cbptr], width());
945#ifdef WS 994#ifdef WS
946 //printf("Adding:%s\n",buff[cbptr]->data()); 995 //printf("Adding:%s\n",buff[cbptr]->data());
947#endif 996#endif
948 cbptr = (cbptr+1) % numlines; 997 cbptr = (cbptr+1) % numlines;
949 } 998 }
950 pagepos = loc[cbptr]; 999 pagepos = loc[cbptr];
@@ -954,82 +1003,107 @@ void QTReader::lineUp()
954 int j = (cbptr+i)%numlines; 1003 int j = (cbptr+i)%numlines;
955 textarray[i] = buff[j]; 1004 textarray[i] = buff[j];
956 locnarray[i] = loc[j]; 1005 locnarray[i] = loc[j];
957 } 1006 }
958 delete [] buff; 1007 delete [] buff;
959 delete [] loc; 1008 delete [] loc;
960 mylastpos = locate(); 1009 mylastpos = locate();
961 update(); 1010 update();
962} 1011}
963*/ 1012*/
964void QTReader::lineUp() 1013void QTReader::lineUp()
965{ 1014{
966 CBuffer* buff = textarray[numlines-1]; 1015 CDrawBuffer* buff = textarray[numlines];
967 unsigned int loc; 1016 unsigned int loc;
968 unsigned int end = locnarray[numlines-1]; 1017 unsigned int end = locnarray[numlines];
969 int cbptr = 0; 1018 int cbptr = 0;
970 if (locate() != mylastpos) jumpto(mylastpos); 1019 if (locate() != mylastpos) jumpto(mylastpos);
971 unsigned int target = locnarray[0]; 1020 unsigned int target = locnarray[0];
1021 if (target == 0) return;
972 if (buffdoc.hasrandomaccess()) 1022 if (buffdoc.hasrandomaccess())
973 { 1023 {
974 unsigned int delta = locate()-pagelocate(); 1024 unsigned int delta = locate()-pagelocate();
975 if (delta < 64) delta = 64; 1025 if (delta < 64) delta = 64;
976 do 1026 do
977 { 1027 {
978 delta <<= 1; 1028 delta <<= 1;
979 if (delta >= target) 1029 if (delta >= target)
980 { 1030 {
981 delta = target; 1031 delta = target;
982 jumpto(0); 1032 jumpto(0);
983 for (int i = 0; i < numlines; i++) 1033 loc = locate();
984 { 1034 getline(buff);
985 loc = locate(); 1035 break;
986 getline(buff); 1036 }
987 } 1037 jumpto(target-delta);
988 break; 1038 do
989 } 1039 {
990 jumpto(target-delta); 1040 getline(buff);
991 do
992 {
993 getline(buff);
994#ifdef WS 1041#ifdef WS
995 //printf("Trying:%s\n",buff[0]); 1042 //printf("Trying:%s\n",buff[0]);
996#endif 1043#endif
997 if (locate() > target) continue; 1044 if (locate() > target) continue;
998 } 1045 }
999 while (!buffdoc.iseol()); 1046 while (!buffdoc.iseol());
1000 loc = locate(); 1047 loc = locate();
1001 getline(buff); 1048 getline(buff);
1002 } 1049 }
1003 while (locate() >= target && delta < 4096); 1050 while (locate() >= target && delta < 4096);
1004 } 1051 }
1005 else 1052 else
1006 { 1053 {
1007 jumpto(0); 1054 jumpto(0);
1008 loc = locate(); 1055 loc = locate();
1009 getline(buff); 1056 getline(buff);
1010 } 1057 }
1011 cbptr = 0; 1058 cbptr = 0;
1012 while (locate() < target) 1059 while (locate() < target)
1013 { 1060 {
1014 loc = locate(); 1061 loc = locate();
1015 getline(buff); 1062 getline(buff);
1016 } 1063 }
1017 pagepos = loc; 1064 for (int i = numlines; i > 0; i--)
1018 for (int i = numlines-1; i > 0; i--)
1019 { 1065 {
1020 textarray[i] = textarray[i-1]; 1066 textarray[i] = textarray[i-1];
1021 locnarray[i] = locnarray[i-1]; 1067 locnarray[i] = locnarray[i-1];
1022 } 1068 }
1023 textarray[0] = buff; 1069 textarray[0] = buff;
1024 locnarray[0] = loc; 1070 locnarray[0] = loc;
1025// delete [] buff; 1071 int start = numlines;
1026// delete [] loc; 1072 int ypos = 0;
1027 mylastpos = locate(); 1073 for (int i = 0; i <= numlines; i++)
1028 jumpto(end); 1074 {
1075 ypos += textarray[i]->lineSpacing();
1076 if (ypos > height())
1077 {
1078 start = i;
1079 ypos -= textarray[i]->lineSpacing();
1080 break;
1081 }
1082 }
1083 jumpto(locnarray[start]);
1084 fillbuffer(start, ypos);
1029 update(); 1085 update();
1030} 1086}
1031 1087
1032bool QTReader::empty() 1088bool QTReader::empty()
1033{ 1089{
1034 return buffdoc.empty(); 1090 return buffdoc.empty();
1035} 1091}
1092
1093MarkupType QTReader::PreferredMarkup()
1094{
1095 MarkupType m = buffdoc.PreferredMarkup();
1096 if (m == cTEXT)
1097 {
1098 int ext = m_lastfile.findRev('.');
1099 if (ext >= 0)
1100 {
1101 QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
1102 if (ft.left(3) == "HTM")
1103 {
1104 m = cHTML;
1105 }
1106 }
1107 }
1108 return m;
1109}