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