Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/QTReader.cpp | 716 |
1 files changed, 476 insertions, 240 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index f2ee027..03c8fbe 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp | |||
@@ -7,23 +7,29 @@ | |||
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 "useqpe.h" | ||
11 | #include <qpainter.h> | 12 | #include <qpainter.h> |
13 | #include <qimage.h> | ||
14 | #include <qtimer.h> | ||
12 | #include "config.h" | 15 | #include "config.h" |
13 | #include "QTReader.h" | 16 | #include "QTReader.h" |
14 | #include "QTReaderApp.h" | 17 | #include "QTReaderApp.h" |
15 | #include "CDrawBuffer.h" | 18 | #include "CDrawBuffer.h" |
19 | #ifdef USEQPE | ||
16 | #include <qpe/qpeapplication.h> | 20 | #include <qpe/qpeapplication.h> |
21 | #endif | ||
17 | #include <math.h> | 22 | #include <math.h> |
18 | #include <ctype.h> | 23 | #include <ctype.h> |
19 | #include <stdio.h> //for sprintf | 24 | #include <stdio.h> //for sprintf |
25 | #ifdef USEQPE | ||
20 | #include <qpe/config.h> | 26 | #include <qpe/config.h> |
21 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
22 | #include <qfontdatabase.h> | ||
23 | #include <qpe/global.h> | 28 | #include <qpe/global.h> |
24 | #include <qpe/qcopenvelope_qws.h> | 29 | #include <qpe/qcopenvelope_qws.h> |
25 | #include "StateData.h" | 30 | #endif |
31 | #include <qfontdatabase.h> | ||
26 | 32 | ||
27 | #ifdef _UNICODE | 33 | #ifdef _UNICODE |
28 | const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; | 34 | const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; |
29 | #else | 35 | #else |
@@ -35,8 +41,12 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; | |||
35 | //const int QTReader::fontsizes[] = {10,16,17,22,0}; | 41 | //const int QTReader::fontsizes[] = {10,16,17,22,0}; |
36 | //const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; | 42 | //const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; |
37 | //const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; | 43 | //const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; |
38 | 44 | ||
45 | tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; | ||
46 | tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; | ||
47 | //tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; | ||
48 | |||
39 | QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : | 49 | QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : |
40 | QWidget(parent, name, f), | 50 | QWidget(parent, name, f), |
41 | m_delay(100), | 51 | m_delay(100), |
42 | m_scrolldy1(0), | 52 | m_scrolldy1(0), |
@@ -50,15 +60,20 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : | |||
50 | mouseUpOn(true), | 60 | mouseUpOn(true), |
51 | m_twotouch(true), | 61 | m_twotouch(true), |
52 | m_touchone(true), | 62 | m_touchone(true), |
53 | bDoUpdates(false), | 63 | bDoUpdates(false), |
54 | m_navkeys(true) | 64 | #ifdef _SCROLLPIPE |
65 | m_pipeout(NULL), | ||
66 | #endif | ||
67 | m_border(2) | ||
55 | { | 68 | { |
56 | m_overlap = 1; | 69 | m_overlap = 1; |
70 | setKeyCompression ( true ); | ||
57 | // init(); | 71 | // init(); |
58 | } | 72 | } |
73 | |||
59 | /* | 74 | /* |
60 | QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, WFlags f ) : | 75 | QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : |
61 | QWidget(parent, name, f), | 76 | QWidget(parent, name, f), |
62 | m_textfont(0), | 77 | m_textfont(0), |
63 | m_textsize(1), | 78 | m_textsize(1), |
64 | textarray(NULL), | 79 | textarray(NULL), |
@@ -71,13 +86,22 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, | |||
71 | bindenter(0), | 86 | bindenter(0), |
72 | m_fm(NULL) | 87 | m_fm(NULL) |
73 | { | 88 | { |
74 | init(); | 89 | init(); |
75 | // qDebug("Load_file(1)"); | 90 | // // qDebug("Load_file(1)"); |
76 | load_file((const tchar*)filename); | 91 | load_file((const tchar*)filename); |
77 | } | 92 | } |
78 | */ | 93 | */ |
79 | 94 | ||
95 | /* | ||
96 | void QTReader::mouseMoveEvent(QMouseEvent* _e) | ||
97 | { | ||
98 | |||
99 | mouseUpOn = !(_e->pos().x() == -1); | ||
100 | |||
101 | qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); | ||
102 | } | ||
103 | */ | ||
80 | long QTReader::real_delay() | 104 | long QTReader::real_delay() |
81 | { | 105 | { |
82 | return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); | 106 | return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); |
83 | } | 107 | } |
@@ -86,56 +110,105 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) | |||
86 | { | 110 | { |
87 | buffdoc.unsuspend(); | 111 | buffdoc.unsuspend(); |
88 | if (_e->button() == RightButton) | 112 | if (_e->button() == RightButton) |
89 | { | 113 | { |
114 | //qDebug("MousePress"); | ||
90 | mouseUpOn = false; | 115 | mouseUpOn = false; |
91 | if (buffdoc.hasnavigation()) | 116 | if (m_swapmouse) |
92 | { | 117 | { |
93 | if (_e->y() > (2*height())/3) | 118 | int lineno = 0; |
94 | { | 119 | int ht = textarray[0]->lineSpacing(); |
95 | goDown(); | 120 | while ((ht < _e->y()) && (lineno < numlines)) |
96 | } | ||
97 | else if (_e->y() < height()/3) | ||
98 | { | ||
99 | goUp(); | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | if (_e->x() < width()/3) | ||
104 | { | ||
105 | size_t target = pagelocate(); | ||
106 | if (buffdoc.back(target)) | ||
107 | { | ||
108 | locate(target); | ||
109 | } | ||
110 | } | ||
111 | else if (_e->x() > (2*width())/3) | ||
112 | { | ||
113 | size_t target = pagelocate(); | ||
114 | if (buffdoc.forward(target)) | ||
115 | { | ||
116 | locate(target); | ||
117 | } | ||
118 | } | ||
119 | else | ||
120 | { | 121 | { |
121 | buffdoc.saveposn(pagelocate()); | 122 | ht += textarray[++lineno]->lineSpacing(); |
122 | locate(buffdoc.getHome()); | ||
123 | } | 123 | } |
124 | } | 124 | size_t startpos, startoffset, tgt; |
125 | getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt); | ||
126 | processmousewordevent(startpos, startoffset, _e, lineno); | ||
127 | } | ||
128 | else | ||
129 | processmousepositionevent(_e); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | void QTReader::processmousepositionevent( QMouseEvent* _e ) | ||
134 | { | ||
135 | if (buffdoc.hasnavigation()) | ||
136 | { | ||
137 | if (_e->y() > (2*height())/3) | ||
138 | { | ||
139 | goDown(); | ||
140 | } | ||
141 | else if (_e->y() < height()/3) | ||
142 | { | ||
143 | goUp(); | ||
125 | } | 144 | } |
126 | else | 145 | else |
127 | { | 146 | { |
128 | if (_e->y() > height()/2) | 147 | if (_e->x() < width()/3) |
129 | { | 148 | { |
130 | goDown(); | 149 | goBack(); |
150 | } | ||
151 | else if (_e->x() > (2*width())/3) | ||
152 | { | ||
153 | goForward(); | ||
131 | } | 154 | } |
132 | else | 155 | else |
133 | { | 156 | { |
134 | goUp(); | 157 | goHome(); |
135 | } | 158 | } |
136 | } | 159 | } |
137 | } | 160 | } |
161 | else | ||
162 | { | ||
163 | if (_e->y() > height()/2) | ||
164 | { | ||
165 | goDown(); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | goUp(); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | void QTReader::goHome() | ||
175 | { | ||
176 | if (buffdoc.hasnavigation()) | ||
177 | { | ||
178 | size_t current=pagelocate(); | ||
179 | size_t home=buffdoc.getHome(); | ||
180 | if (current!=home) | ||
181 | { | ||
182 | buffdoc.saveposn(current); | ||
183 | locate(home); | ||
184 | } | ||
185 | } | ||
186 | } | ||
187 | |||
188 | void QTReader::goBack() | ||
189 | { | ||
190 | if (buffdoc.hasnavigation()) | ||
191 | { | ||
192 | size_t target = pagelocate(); | ||
193 | buffdoc.writeposn(target); | ||
194 | if (buffdoc.back(target)) | ||
195 | { | ||
196 | locate(target); | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
201 | void QTReader::goForward() | ||
202 | { | ||
203 | if (buffdoc.hasnavigation()) | ||
204 | { | ||
205 | size_t target = pagelocate(); | ||
206 | if (buffdoc.forward(target)) | ||
207 | { | ||
208 | locate(target); | ||
209 | } | ||
210 | } | ||
138 | } | 211 | } |
139 | 212 | ||
140 | linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) | 213 | linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) |
141 | { | 214 | { |
@@ -147,21 +220,30 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si | |||
147 | } | 220 | } |
148 | start = locnarray[lineno]; | 221 | start = locnarray[lineno]; |
149 | if (m_bMonoSpaced) | 222 | if (m_bMonoSpaced) |
150 | { | 223 | { |
151 | offset = x/m_charWidth; | 224 | offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; |
152 | } | 225 | } |
153 | else | 226 | else |
154 | { | 227 | { |
155 | int i; | 228 | int i; |
156 | CDrawBuffer* t = textarray[lineno]; | 229 | CDrawBuffer* t = textarray[lineno]; |
157 | x = x - t->offset(width()); | 230 | x = x - t->offset(width(), m_border); |
158 | for (i = t->length(); i >= 0 && t->width(i) > x; i--); | 231 | for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--); |
159 | offset = i; | 232 | offset = i; |
160 | } | 233 | } |
161 | return textarray[lineno]->getLinkType(offset, tgt); | 234 | return textarray[lineno]->getLinkType(offset, tgt); |
162 | } | 235 | } |
163 | 236 | ||
237 | void QTReader::suspend() | ||
238 | { | ||
239 | #ifdef OPIE | ||
240 | if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); | ||
241 | #else | ||
242 | if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); | ||
243 | #endif | ||
244 | } | ||
245 | |||
164 | void QTReader::setTwoTouch(bool _b) | 246 | void QTReader::setTwoTouch(bool _b) |
165 | { | 247 | { |
166 | setBackgroundColor( white ); | 248 | setBackgroundColor( white ); |
167 | m_twotouch = m_touchone = _b; | 249 | m_twotouch = m_touchone = _b; |
@@ -172,18 +254,108 @@ void QTReader::setContinuous(bool _b) | |||
172 | buffdoc.unsuspend(); | 254 | buffdoc.unsuspend(); |
173 | buffdoc.setContinuous(m_continuousDocument = _b); | 255 | buffdoc.setContinuous(m_continuousDocument = _b); |
174 | } | 256 | } |
175 | 257 | ||
258 | void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) | ||
259 | { | ||
260 | QString wrd; | ||
261 | if (m_twotouch) | ||
262 | { | ||
263 | if (m_touchone) | ||
264 | { | ||
265 | m_touchone = false; | ||
266 | m_startpos = startpos; | ||
267 | m_startoffset = startoffset; | ||
268 | setBackgroundColor( lightGray ); | ||
269 | } | ||
270 | else | ||
271 | { | ||
272 | m_touchone = true; | ||
273 | setBackgroundColor( white ); | ||
274 | size_t endpos, endoffset; | ||
275 | endpos = startpos; | ||
276 | endoffset = startoffset; | ||
277 | size_t currentpos = locate(); | ||
278 | if (endpos >= m_startpos) | ||
279 | { | ||
280 | jumpto(m_startpos); | ||
281 | for (int i = 0; i < m_startoffset; i++) | ||
282 | { | ||
283 | getch(); | ||
284 | } | ||
285 | if (m_startpos == endpos) | ||
286 | { | ||
287 | for (int i = m_startoffset; i <= endoffset; i++) | ||
288 | { | ||
289 | wrd += QChar(getch()); | ||
290 | } | ||
291 | } | ||
292 | else | ||
293 | { | ||
294 | while (buffdoc.explocate() <= endpos) | ||
295 | { | ||
296 | wrd += QChar(getch()); | ||
297 | } | ||
298 | for (int i = 0; i < endoffset; i++) | ||
299 | { | ||
300 | wrd += QChar(getch()); | ||
301 | } | ||
302 | } | ||
303 | jumpto(currentpos); | ||
304 | } | ||
305 | } | ||
306 | } | ||
307 | else if (m_bMonoSpaced) | ||
308 | { | ||
309 | int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth; | ||
310 | if (chno < ustrlen(textarray[lineno]->data())) | ||
311 | { | ||
312 | wrd[0] = textarray[lineno]->data()[chno]; | ||
313 | } | ||
314 | } | ||
315 | else | ||
316 | { | ||
317 | CDrawBuffer* t = textarray[lineno]; | ||
318 | int first = 0; | ||
319 | int tgt = _e->x() - t->offset(width(), m_border); | ||
320 | while (1) | ||
321 | { | ||
322 | int i = first+1; | ||
323 | while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | ||
324 | if (t->width(i, true, width(), m_border) > tgt) | ||
325 | { | ||
326 | wrd = toQString(t->data()+first, i - first); | ||
327 | // qDebug("Got %s", (const char *)wrd); | ||
328 | break; | ||
329 | } | ||
330 | while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | ||
331 | if ((*t)[i] == 0) break; | ||
332 | first = i; | ||
333 | } | ||
334 | } | ||
335 | if (!wrd.isEmpty()) | ||
336 | { | ||
337 | //qDebug("Selected:%s", (const char*)wrd); | ||
338 | emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); | ||
339 | } | ||
340 | } | ||
341 | |||
176 | void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | 342 | void QTReader::mouseReleaseEvent( QMouseEvent* _e ) |
177 | { | 343 | { |
178 | buffdoc.unsuspend(); | 344 | buffdoc.unsuspend(); |
179 | if (_e->button() == LeftButton) | 345 | if (_e->button() == LeftButton) |
180 | { | 346 | { |
181 | if (mouseUpOn) | 347 | if (mouseUpOn) |
182 | { | 348 | { |
349 | // qDebug("MouseRelease"); | ||
350 | if (_e->x() > width() - m_border) | ||
351 | { | ||
352 | locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height()); | ||
353 | return; | ||
354 | } | ||
183 | if (textarray[0] != NULL) | 355 | if (textarray[0] != NULL) |
184 | { | 356 | { |
185 | QString wrd, line; | 357 | QString line; |
186 | // int lineno = _e->y()/m_linespacing; | 358 | // int lineno = _e->y()/m_linespacing; |
187 | int lineno = 0; | 359 | int lineno = 0; |
188 | int ht = textarray[0]->lineSpacing(); | 360 | int ht = textarray[0]->lineSpacing(); |
189 | while ((ht < _e->y()) && (lineno < numlines)) | 361 | while ((ht < _e->y()) && (lineno < numlines)) |
@@ -195,24 +367,43 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
195 | { | 367 | { |
196 | case eLink: | 368 | case eLink: |
197 | { | 369 | { |
198 | size_t saveposn = pagelocate(); | 370 | size_t saveposn = pagelocate(); |
199 | if (buffdoc.hyperlink(tgt)) | 371 | QString href; |
372 | linkType lt = buffdoc.hyperlink(tgt, href); | ||
373 | if (lt == eLink) | ||
200 | { | 374 | { |
201 | buffdoc.saveposn(saveposn); | 375 | buffdoc.saveposn(saveposn); |
202 | fillbuffer(); | 376 | fillbuffer(); |
203 | update(); | 377 | update(); |
204 | } | 378 | } |
205 | else | 379 | else |
206 | { | 380 | { |
381 | if (lt == ePicture) | ||
382 | { | ||
383 | QImage* pm = buffdoc.getPicture(tgt); | ||
384 | if (pm != NULL) | ||
385 | { | ||
386 | emit OnShowPicture(*pm); | ||
387 | delete pm; | ||
388 | } | ||
389 | } | ||
390 | else | ||
391 | { | ||
392 | // QString anchortext = textarray[lineno]->getanchortext(startoffset); | ||
393 | if (!href.isEmpty()) | ||
394 | { | ||
395 | emit OnURLSelected(href); | ||
396 | } | ||
397 | } | ||
207 | locate(pagelocate()); | 398 | locate(pagelocate()); |
208 | } | 399 | } |
209 | return; | 400 | return; |
210 | } | 401 | } |
211 | case ePicture: | 402 | case ePicture: |
212 | { | 403 | { |
213 | qDebug("Picture:%x", tgt); | 404 | // qDebug("Picture:%x", tgt); |
214 | QPixmap* pm = buffdoc.getPicture(tgt); | 405 | QImage* pm = buffdoc.getPicture(tgt); |
215 | if (pm != NULL) | 406 | if (pm != NULL) |
216 | { | 407 | { |
217 | emit OnShowPicture(*pm); | 408 | emit OnShowPicture(*pm); |
218 | delete pm; | 409 | delete pm; |
@@ -225,88 +416,15 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
225 | } | 416 | } |
226 | case eNone: | 417 | case eNone: |
227 | break; | 418 | break; |
228 | default: | 419 | default: |
229 | qDebug("Unknown linktype"); | 420 | // qDebug("Unknown linktype"); |
230 | return; | 421 | return; |
231 | } | 422 | } |
232 | if (m_twotouch) | 423 | if (m_swapmouse) |
233 | { | 424 | processmousepositionevent(_e); |
234 | if (m_touchone) | ||
235 | { | ||
236 | m_touchone = false; | ||
237 | m_startpos = startpos; | ||
238 | m_startoffset = startoffset; | ||
239 | setBackgroundColor( lightGray ); | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | m_touchone = true; | ||
244 | setBackgroundColor( white ); | ||
245 | size_t endpos, endoffset; | ||
246 | endpos = startpos; | ||
247 | endoffset = startoffset; | ||
248 | size_t currentpos = locate(); | ||
249 | if (endpos >= m_startpos) | ||
250 | { | ||
251 | jumpto(m_startpos); | ||
252 | for (int i = 0; i < m_startoffset; i++) | ||
253 | { | ||
254 | getch(); | ||
255 | } | ||
256 | if (m_startpos == endpos) | ||
257 | { | ||
258 | for (int i = m_startoffset; i <= endoffset; i++) | ||
259 | { | ||
260 | wrd += QChar(getch()); | ||
261 | } | ||
262 | } | ||
263 | else | ||
264 | { | ||
265 | while (buffdoc.explocate() <= endpos) | ||
266 | { | ||
267 | wrd += QChar(getch()); | ||
268 | } | ||
269 | for (int i = 0; i < endoffset; i++) | ||
270 | { | ||
271 | wrd += QChar(getch()); | ||
272 | } | ||
273 | } | ||
274 | jumpto(currentpos); | ||
275 | } | ||
276 | } | ||
277 | } | ||
278 | else if (m_bMonoSpaced) | ||
279 | { | ||
280 | int chno = _e->x()/m_charWidth; | ||
281 | if (chno < ustrlen(textarray[lineno]->data())) | ||
282 | { | ||
283 | wrd[0] = textarray[lineno]->data()[chno]; | ||
284 | } | ||
285 | } | ||
286 | else | 425 | else |
287 | { | 426 | processmousewordevent(startpos, startoffset, _e, lineno); |
288 | CDrawBuffer* t = textarray[lineno]; | ||
289 | int first = 0; | ||
290 | int tgt = _e->x() - t->offset(width()); | ||
291 | while (1) | ||
292 | { | ||
293 | int i = first+1; | ||
294 | while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | ||
295 | if (t->width(i) > tgt) | ||
296 | { | ||
297 | wrd = toQString(t->data()+first, i - first); | ||
298 | break; | ||
299 | } | ||
300 | while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; | ||
301 | if ((*t)[i] == 0) break; | ||
302 | first = i; | ||
303 | } | ||
304 | } | ||
305 | if (!wrd.isEmpty()) | ||
306 | { | ||
307 | emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); | ||
308 | } | ||
309 | } | 427 | } |
310 | } | 428 | } |
311 | else | 429 | else |
312 | { | 430 | { |
@@ -325,15 +443,17 @@ void QTReader::focusOutEvent(QFocusEvent* e) | |||
325 | { | 443 | { |
326 | if (m_autoScroll) | 444 | if (m_autoScroll) |
327 | { | 445 | { |
328 | timer->stop(); | 446 | timer->stop(); |
329 | m_scrolldy1 = m_scrolldy2 = 0; | 447 | //m_scrolldy1 = m_scrolldy2 = 0; |
330 | } | 448 | } |
331 | } | 449 | } |
332 | 450 | ||
333 | #include <qapplication.h> | 451 | #include <qapplication.h> |
334 | #include <qdrawutil.h> | 452 | #include <qdrawutil.h> |
453 | #ifndef _WINDOWS | ||
335 | #include <unistd.h> | 454 | #include <unistd.h> |
455 | #endif | ||
336 | 456 | ||
337 | void QTReader::goDown() | 457 | void QTReader::goDown() |
338 | { | 458 | { |
339 | if (m_bpagemode) | 459 | if (m_bpagemode) |
@@ -425,11 +545,64 @@ void QTReader::zoomout() | |||
425 | if (m_autoScroll) autoscroll(); | 545 | if (m_autoScroll) autoscroll(); |
426 | } | 546 | } |
427 | } | 547 | } |
428 | 548 | ||
549 | void QTReader::reduceScroll() | ||
550 | { | ||
551 | if (m_delay < 59049) | ||
552 | { | ||
553 | m_delay = (3*m_delay)/2; | ||
554 | timer->changeInterval(real_delay()); | ||
555 | } | ||
556 | else | ||
557 | { | ||
558 | m_delay = 59049; | ||
559 | } | ||
560 | } | ||
561 | |||
562 | void QTReader::increaseScroll() | ||
563 | { | ||
564 | if (m_delay > 1024) | ||
565 | { | ||
566 | m_delay = (2*m_delay)/3; | ||
567 | timer->changeInterval(real_delay()); | ||
568 | } | ||
569 | else | ||
570 | { | ||
571 | m_delay = 1024; | ||
572 | } | ||
573 | } | ||
574 | |||
429 | void QTReader::keyPressEvent(QKeyEvent* e) | 575 | void QTReader::keyPressEvent(QKeyEvent* e) |
430 | { | 576 | { |
431 | buffdoc.unsuspend(); | 577 | buffdoc.unsuspend(); |
578 | ((QTReaderApp*)parent()->parent())->handlekey(e); | ||
579 | // e->ignore(); | ||
580 | return; | ||
581 | #ifdef _SCROLLPIPE | ||
582 | if (m_isPaused) | ||
583 | { | ||
584 | m_isPaused = false; | ||
585 | if (e->key() != Key_Space) | ||
586 | { | ||
587 | m_autoScroll = false; | ||
588 | if (m_pipeout != NULL) | ||
589 | { | ||
590 | pclose(m_pipeout); | ||
591 | m_pipeout = NULL; | ||
592 | } | ||
593 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); | ||
594 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | ||
595 | } | ||
596 | else | ||
597 | { | ||
598 | timer->start(real_delay(), false); | ||
599 | } | ||
600 | e->accept(); | ||
601 | return; | ||
602 | } | ||
603 | #endif | ||
604 | /* | ||
432 | switch (e->key()) | 605 | switch (e->key()) |
433 | { | 606 | { |
434 | case Key_Down: | 607 | case Key_Down: |
435 | { | 608 | { |
@@ -472,37 +645,8 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
472 | goUp(); | 645 | goUp(); |
473 | } | 646 | } |
474 | } | 647 | } |
475 | break; | 648 | break; |
476 | /* | ||
477 | case Key_Left: | ||
478 | { | ||
479 | e->accept(); | ||
480 | if (m_textfont > 0) | ||
481 | { | ||
482 | m_textfont--; | ||
483 | setfont(NULL); | ||
484 | locate(pagelocate()); | ||
485 | update(); | ||
486 | } | ||
487 | } | ||
488 | break; | ||
489 | case Key_Right: | ||
490 | { | ||
491 | e->accept(); | ||
492 | if (fonts[++m_textfont] == 0) | ||
493 | { | ||
494 | m_textfont--; | ||
495 | } | ||
496 | else | ||
497 | { | ||
498 | setfont(NULL); | ||
499 | locate(pagelocate()); | ||
500 | update(); | ||
501 | } | ||
502 | } | ||
503 | break; | ||
504 | */ | ||
505 | case Key_Right: | 649 | case Key_Right: |
506 | { | 650 | { |
507 | e->accept(); | 651 | e->accept(); |
508 | if (m_navkeys && buffdoc.hasnavigation()) | 652 | if (m_navkeys && buffdoc.hasnavigation()) |
@@ -529,48 +673,61 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
529 | } | 673 | } |
530 | else zoomout(); | 674 | else zoomout(); |
531 | } | 675 | } |
532 | break; | 676 | break; |
533 | case Key_Space: | ||
534 | case Key_Return: | ||
535 | { | ||
536 | e->accept(); | ||
537 | emit OnActionPressed(); | ||
538 | } | ||
539 | break; | ||
540 | default: | 677 | default: |
541 | e->ignore(); | 678 | e->ignore(); |
542 | } | 679 | } |
680 | */ | ||
543 | } | 681 | } |
544 | 682 | ||
545 | void QTReader::setautoscroll(bool _sc) | 683 | void QTReader::setautoscroll(bool _sc) |
546 | { | 684 | { |
547 | if (_sc == m_autoScroll) return; | 685 | if (_sc == m_autoScroll) return; |
548 | if (m_autoScroll) | 686 | if (m_autoScroll) |
549 | { | 687 | { |
550 | m_autoScroll = false; | 688 | m_autoScroll = false; |
689 | #ifdef USEQPE | ||
551 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | 690 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; |
691 | #endif | ||
692 | #ifdef _SCROLLPIPE | ||
693 | if (m_pipeout != NULL) | ||
694 | { | ||
695 | pclose(m_pipeout); | ||
696 | m_pipeout = NULL; | ||
697 | } | ||
698 | #endif | ||
552 | } | 699 | } |
553 | else | 700 | else |
554 | { | 701 | { |
555 | CDrawBuffer* reusebuffer = textarray[numlines]; | 702 | CDrawBuffer* reusebuffer = textarray[numlines]; |
556 | if (reusebuffer == NULL || reusebuffer->eof()) return; | 703 | if (reusebuffer == NULL || reusebuffer->eof()) return; |
557 | m_autoScroll = true; | 704 | m_autoScroll = true; |
705 | #ifdef _SCROLLPIPE | ||
706 | if (!m_pipetarget.isEmpty()) | ||
707 | { | ||
708 | // qDebug("Opening pipe to %s", (const char*)m_pipetarget); | ||
709 | m_pipeout = popen((const char*)m_pipetarget, "w"); | ||
710 | m_isPaused = false; | ||
711 | } | ||
712 | #endif | ||
558 | autoscroll(); | 713 | autoscroll(); |
714 | #ifdef USEQPE | ||
559 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed | 715 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed |
716 | #endif | ||
560 | } | 717 | } |
561 | } | 718 | } |
562 | 719 | ||
563 | bool QTReader::getline(CDrawBuffer *buff) | 720 | bool QTReader::getline(CDrawBuffer *buff) |
564 | { | 721 | { |
565 | buffdoc.unsuspend(); | 722 | buffdoc.unsuspend(); |
566 | if (m_bMonoSpaced) | 723 | if (m_bMonoSpaced) |
567 | { | 724 | { |
568 | return buffdoc.getline(buff ,width(), m_charWidth); | 725 | return buffdoc.getline(buff ,width(), m_charWidth, m_border); |
569 | } | 726 | } |
570 | else | 727 | else |
571 | { | 728 | { |
572 | return buffdoc.getline(buff, width()); | 729 | return buffdoc.getline(buff, width(), m_border); |
573 | } | 730 | } |
574 | } | 731 | } |
575 | 732 | ||
576 | void QTReader::doscroll() | 733 | void QTReader::doscroll() |
@@ -587,8 +744,27 @@ void QTReader::doscroll() | |||
587 | qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); | 744 | qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); |
588 | 745 | ||
589 | if (++m_scrolldy1 == textarray[0]->lineSpacing()) | 746 | if (++m_scrolldy1 == textarray[0]->lineSpacing()) |
590 | { | 747 | { |
748 | #ifdef _SCROLLPIPE | ||
749 | if (m_pipeout != NULL) | ||
750 | { | ||
751 | QString outstr = toQString(textarray[0]->data()); | ||
752 | if (!outstr.isEmpty()) | ||
753 | { | ||
754 | fprintf(m_pipeout, "%s\n", (const char*)outstr); | ||
755 | fflush(m_pipeout); | ||
756 | } | ||
757 | else if (m_pauseAfterEachPara) | ||
758 | { | ||
759 | m_isPaused = true; | ||
760 | timer->stop(); | ||
761 | } | ||
762 | // write(m_pipeout, (const char*)outstr, outstr.length()); | ||
763 | // write(m_pipeout, "\n", 1); | ||
764 | // fputc(10, m_pipeout); | ||
765 | } | ||
766 | #endif | ||
591 | CDrawBuffer* buff = textarray[0]; | 767 | CDrawBuffer* buff = textarray[0]; |
592 | for (int i = 1; i <= numlines; i++) | 768 | for (int i = 1; i <= numlines; i++) |
593 | { | 769 | { |
594 | textarray[i-1] = textarray[i]; | 770 | textarray[i-1] = textarray[i]; |
@@ -608,14 +784,31 @@ void QTReader::doscroll() | |||
608 | textarray[numlines] = new CDrawBuffer(&m_fontControl); | 784 | textarray[numlines] = new CDrawBuffer(&m_fontControl); |
609 | } | 785 | } |
610 | locnarray[numlines] = locate(); | 786 | locnarray[numlines] = locate(); |
611 | int ch = getline(textarray[numlines]); | 787 | int ch = getline(textarray[numlines]); |
612 | textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); | 788 | textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border); |
613 | mylastpos = locate(); | 789 | mylastpos = locate(); |
614 | if (!ch) | 790 | if (!ch) |
615 | { | 791 | { |
616 | m_autoScroll = false; | 792 | m_autoScroll = false; |
793 | #ifdef _SCROLLPIPE | ||
794 | for (int i = 0; i < numlines; i++) | ||
795 | { | ||
796 | if (m_pipeout != NULL) | ||
797 | { | ||
798 | QString outstr = toQString(textarray[i]->data()); | ||
799 | if (!outstr.isEmpty()) | ||
800 | { | ||
801 | fprintf(m_pipeout, "%s\n", (const char*)outstr); | ||
802 | fflush(m_pipeout); | ||
803 | } | ||
804 | } | ||
805 | } | ||
806 | #endif | ||
617 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); | 807 | ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); |
808 | #ifdef USEQPE | ||
809 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | ||
810 | #endif | ||
618 | } | 811 | } |
619 | emit OnRedraw(); | 812 | emit OnRedraw(); |
620 | } | 813 | } |
621 | } | 814 | } |
@@ -638,70 +831,85 @@ void QTReader::setfont() | |||
638 | void QTReader::drawFonts( QPainter *p ) | 831 | void QTReader::drawFonts( QPainter *p ) |
639 | { | 832 | { |
640 | if (bDoUpdates) | 833 | if (bDoUpdates) |
641 | { | 834 | { |
642 | qDebug("How refreshing..."); | 835 | //qDebug("How refreshing..."); |
643 | if (buffdoc.empty()) return; | 836 | if (buffdoc.empty()) return; |
644 | setfont(); | 837 | setfont(); |
645 | if (m_lastwidth != width()) | 838 | if (m_lastwidth != width()) |
646 | { | 839 | { |
647 | qDebug("Not Optimised %d", m_lastwidth); | 840 | // qDebug("Not Optimised %d", m_lastwidth); |
648 | m_lastwidth = width(); | 841 | m_lastwidth = width(); |
649 | m_lastheight = height(); | 842 | m_lastheight = height(); |
843 | buffdoc.setwidth(m_lastwidth-2*m_border); | ||
650 | locate(pagelocate()); | 844 | locate(pagelocate()); |
651 | qDebug("Not Optimised %d", m_lastwidth); | 845 | // qDebug("Not Optimised %d", m_lastwidth); |
652 | } | 846 | } |
653 | else | 847 | else |
654 | { | 848 | { |
655 | if (m_lastheight > height()) | 849 | int newht = height(); |
850 | if (m_lastheight > newht) | ||
656 | { | 851 | { |
657 | qDebug("Optimised < %d", numlines); | 852 | // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); |
658 | int ypos = 0; | 853 | int ypos = 0; |
659 | for (int i = 0; i < numlines; i++) | 854 | for (int i = 0; i < numlines; i++) |
660 | { | 855 | { |
661 | if ((ypos += textarray[i]->lineSpacing()) > height()) | 856 | if ((ypos += textarray[i]->lineSpacing()) > newht) |
662 | { | 857 | { |
663 | numlines = i; | 858 | numlines = i; |
664 | jumpto(locnarray[i+1]); | 859 | jumpto(mylastpos = locnarray[i+1]); |
665 | break; | 860 | break; |
666 | } | 861 | } |
667 | } | 862 | } |
668 | qDebug("Optimised < %d", numlines); | 863 | // qDebug("Optimised < %d", numlines); |
669 | m_lastheight = height(); | 864 | m_lastheight = newht; |
670 | } | 865 | } |
671 | else if (m_lastheight < height()) | 866 | else if (m_lastheight < newht) |
672 | { | 867 | { |
673 | qDebug("Optimised > %d", numlines); | 868 | // qDebug("Optimised > %d", numlines); |
674 | int ypos = 0; | 869 | int ypos = 0; |
675 | for (int i = 0; i <= numlines; i++) | 870 | for (int i = 0; i <= numlines; i++) |
676 | { | 871 | { |
677 | ypos += textarray[i]->lineSpacing(); | 872 | ypos += textarray[i]->lineSpacing(); |
678 | } | 873 | } |
679 | fillbuffer(numlines+1, ypos); | 874 | fillbuffer(numlines+1, ypos, newht); |
680 | qDebug("Optimised > %d", numlines); | 875 | // qDebug("Optimised > %d", numlines); |
681 | m_lastheight = height(); | ||
682 | } | 876 | } |
683 | if (numlines > 0) | 877 | if (numlines > 0) |
684 | { | 878 | { |
685 | int ypos = textarray[0]->ascent(); | 879 | int ypos = textarray[0]->ascent(); |
686 | textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); | 880 | textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); |
881 | // int last = (m_showlast) ? numlines : numlines-1; | ||
882 | // for (int i = 1; i <= last; i++) | ||
687 | for (int i = 1; i < numlines; i++) | 883 | for (int i = 1; i < numlines; i++) |
688 | { | 884 | { |
689 | // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; | 885 | // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2; |
690 | ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ | 886 | ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ |
691 | (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; | 887 | (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; |
692 | textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); | 888 | textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); |
693 | } | 889 | } |
694 | // mylastpos = locate(); | 890 | // mylastpos = locate(); |
695 | } | 891 | } |
696 | } | 892 | } |
697 | m_scrolldy1 = m_scrolldy2 = 0; | 893 | |
894 | m_scrolldy1 = m_scrolldy2 = m_scrollpart; | ||
895 | if (m_border > 5 && !buffdoc.empty()) | ||
896 | { | ||
897 | p->fillRect(width()-2, 0, 2, height(), cyan); | ||
898 | int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); | ||
899 | int mid = (height()*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); | ||
900 | p->fillRect(width()-2, mid-5, 2, 10, yellow); | ||
901 | p->fillRect(width()-2, (height()*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*height()+sectionsize/2)/sectionsize, magenta); | ||
902 | } | ||
903 | |||
698 | emit OnRedraw(); | 904 | emit OnRedraw(); |
699 | } | 905 | } |
906 | /* | ||
700 | else | 907 | else |
701 | { | 908 | { |
702 | qDebug("Not so refreshing..."); | 909 | qDebug("Not so refreshing..."); |
703 | } | 910 | } |
911 | */ | ||
704 | } | 912 | } |
705 | 913 | ||
706 | QString QTReader::firstword() | 914 | QString QTReader::firstword() |
707 | { | 915 | { |
@@ -741,8 +949,9 @@ bool QTReader::ChangeFont(int tgt) | |||
741 | } | 949 | } |
742 | 950 | ||
743 | void QTReader::init() | 951 | void QTReader::init() |
744 | { | 952 | { |
953 | // m_showlast = true; | ||
745 | // setCaption( "Qt Draw Demo Application" ); | 954 | // setCaption( "Qt Draw Demo Application" ); |
746 | 955 | ||
747 | buffdoc.unsuspend(); | 956 | buffdoc.unsuspend(); |
748 | setBackgroundColor( white ); | 957 | setBackgroundColor( white ); |
@@ -770,8 +979,20 @@ void QTReader::init() | |||
770 | // Clean up | 979 | // Clean up |
771 | // | 980 | // |
772 | QTReader::~QTReader() | 981 | QTReader::~QTReader() |
773 | { | 982 | { |
983 | #ifdef USEQPE | ||
984 | if (m_autoScroll) | ||
985 | { | ||
986 | QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; | ||
987 | } | ||
988 | #endif | ||
989 | #ifdef _SCROLLPIPE | ||
990 | if (m_pipeout != NULL) | ||
991 | { | ||
992 | fclose(m_pipeout); | ||
993 | } | ||
994 | #endif | ||
774 | } | 995 | } |
775 | 996 | ||
776 | // | 997 | // |
777 | // Calls the drawing function as specified by the radio buttons. | 998 | // Calls the drawing function as specified by the radio buttons. |
@@ -815,9 +1036,9 @@ void QTReader::paintEvent( QPaintEvent * ) | |||
815 | 1036 | ||
816 | /* | 1037 | /* |
817 | void QTReader::resizeEvent( QResizeEvent * ) | 1038 | void QTReader::resizeEvent( QResizeEvent * ) |
818 | { | 1039 | { |
819 | // qDebug("resize:(%u,%u)", width(), height()); | 1040 | // // qDebug("resize:(%u,%u)", width(), height()); |
820 | // bgroup->move( width()-bgroup->width(), 0 ); | 1041 | // bgroup->move( width()-bgroup->width(), 0 ); |
821 | } | 1042 | } |
822 | */ | 1043 | */ |
823 | 1044 | ||
@@ -840,13 +1061,13 @@ int main( int argc, tchar **argv ) | |||
840 | bool QTReader::locate(unsigned long n) { | 1061 | bool QTReader::locate(unsigned long n) { |
841 | //printf("Locate\n"); | 1062 | //printf("Locate\n"); |
842 | buffdoc.unsuspend(); | 1063 | buffdoc.unsuspend(); |
843 | buffdoc.locate(n); | 1064 | buffdoc.locate(n); |
844 | // qDebug("&buffdoc.located"); | 1065 | // // qDebug("&buffdoc.located"); |
845 | fillbuffer(); | 1066 | fillbuffer(); |
846 | // qDebug("&Buffer filled"); | 1067 | // // qDebug("&Buffer filled"); |
847 | update(); | 1068 | update(); |
848 | // qDebug("&Located"); | 1069 | // // qDebug("&Located"); |
849 | return true; | 1070 | return true; |
850 | } | 1071 | } |
851 | 1072 | ||
852 | unsigned int QTReader::screenlines() | 1073 | unsigned int QTReader::screenlines() |
@@ -855,20 +1076,24 @@ unsigned int QTReader::screenlines() | |||
855 | // return (height()-m_descent)/(m_linespacing); | 1076 | // return (height()-m_descent)/(m_linespacing); |
856 | return (height()-2)/(m_linespacing); | 1077 | return (height()-2)/(m_linespacing); |
857 | }; | 1078 | }; |
858 | 1079 | ||
859 | bool QTReader::fillbuffer(int reuse, int ht) | 1080 | bool QTReader::fillbuffer(int reuse, int ht, int newht) |
860 | { | 1081 | { |
861 | buffdoc.unsuspend(); | 1082 | buffdoc.unsuspend(); |
862 | if (buffdoc.empty()) return false; | 1083 | if (buffdoc.empty()) return false; |
863 | m_scrolldy1 = m_scrolldy2 = 0; | 1084 | if (newht < 0) |
1085 | m_lastheight = height(); | ||
1086 | else | ||
1087 | m_lastheight = newht; | ||
864 | int ch; | 1088 | int ch; |
865 | bool ret = false; | 1089 | bool ret = false; |
866 | unsigned int oldpagepos = locnarray[reuse]; | 1090 | unsigned int oldpagepos = locnarray[reuse]; |
867 | int ypos = ht; | 1091 | int lastypos = ht, ypos = ht; |
868 | numlines = reuse; | 1092 | numlines = reuse; |
869 | while (ypos < height() || numlines < 2) | 1093 | while (ypos < m_lastheight || numlines < 2) |
870 | { | 1094 | { |
1095 | lastypos = ypos; | ||
871 | if (textarray[numlines] == NULL) | 1096 | if (textarray[numlines] == NULL) |
872 | { | 1097 | { |
873 | textarray[numlines] = new CDrawBuffer(&m_fontControl); | 1098 | textarray[numlines] = new CDrawBuffer(&m_fontControl); |
874 | } | 1099 | } |
@@ -893,20 +1118,21 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
893 | } | 1118 | } |
894 | 1119 | ||
895 | --numlines; | 1120 | --numlines; |
896 | mylastpos = locate(); | 1121 | mylastpos = locate(); |
1122 | m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; | ||
897 | 1123 | ||
898 | return true; | 1124 | return true; |
899 | } | 1125 | } |
900 | 1126 | ||
901 | |||
902 | void QTReader::dopagedn() | 1127 | void QTReader::dopagedn() |
903 | { | 1128 | { |
1129 | // qDebug("HEIGHT(2):%d", m_lastheight); | ||
904 | buffdoc.unsuspend(); | 1130 | buffdoc.unsuspend(); |
905 | int skip = 0, ypos = 0; | 1131 | int skip = 0, ypos = 0; |
906 | if (locate() != mylastpos) | 1132 | if (locate() != mylastpos) |
907 | { | 1133 | { |
908 | //qDebug("Jumping to %u", mylastpos); | 1134 | ////qDebug("Jumping to %u", mylastpos); |
909 | jumpto(mylastpos); | 1135 | jumpto(mylastpos); |
910 | } | 1136 | } |
911 | CDrawBuffer* reusebuffer = textarray[numlines]; | 1137 | CDrawBuffer* reusebuffer = textarray[numlines]; |
912 | if (reusebuffer != NULL && reusebuffer->eof()) return; | 1138 | if (reusebuffer != NULL && reusebuffer->eof()) return; |
@@ -937,22 +1163,33 @@ void QTReader::dopageup() | |||
937 | buffdoc.unsuspend(); | 1163 | buffdoc.unsuspend(); |
938 | dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); | 1164 | dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); |
939 | } | 1165 | } |
940 | 1166 | ||
1167 | bool QTReader::synch(size_t start, size_t end) | ||
1168 | { | ||
1169 | jumpto(start); | ||
1170 | while (start++ < end) | ||
1171 | { | ||
1172 | tchar ch = getch(); | ||
1173 | if (ch == 10) return true; | ||
1174 | if (ch == UEOF) return false; | ||
1175 | } | ||
1176 | return false; | ||
1177 | } | ||
1178 | |||
941 | void QTReader::dopageup(unsigned int target) | 1179 | void QTReader::dopageup(unsigned int target) |
942 | { | 1180 | { |
943 | buffdoc.unsuspend(); | 1181 | buffdoc.unsuspend(); |
944 | CBufferFace<CDrawBuffer*> buff; | 1182 | CBufferFace<CDrawBuffer*> buff; |
945 | CBufferFace<size_t> loc; | 1183 | CBufferFace<size_t> loc; |
946 | 1184 | ||
947 | size_t delta, guess = 2048; | 1185 | size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; |
948 | bool ch = true; | 1186 | bool ch = true; |
949 | int nbfl, ypos = 0; | 1187 | int nbfl, ypos = 0; |
950 | 1188 | if (guess < 128) guess = 128; | |
951 | while (1) | 1189 | while (1) |
952 | { | 1190 | { |
953 | ch = true; | 1191 | ch = true; |
954 | nbfl = 0; | ||
955 | if (target < guess) | 1192 | if (target < guess) |
956 | { | 1193 | { |
957 | delta = 0; // 0 is a flag to say don't guess any more | 1194 | delta = 0; // 0 is a flag to say don't guess any more |
958 | jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); | 1195 | jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); |
@@ -964,24 +1201,26 @@ void QTReader::dopageup(unsigned int target) | |||
964 | } | 1201 | } |
965 | else | 1202 | else |
966 | { | 1203 | { |
967 | delta = guess; | 1204 | delta = guess; |
968 | 1205 | if (!synch(target-delta, target-lastdelta)) | |
969 | jumpto(target - delta); | ||
970 | |||
971 | buff[0] = new CDrawBuffer(&m_fontControl); | ||
972 | |||
973 | do | ||
974 | { | 1206 | { |
975 | 1207 | lastdelta = delta; | |
976 | if (!getline(buff[0])) break; | 1208 | if (guess < 4000) |
977 | 1209 | { | |
978 | if (locate() > target) break; | 1210 | guess <<= 1; |
1211 | continue; | ||
1212 | } | ||
1213 | else | ||
1214 | { | ||
1215 | jumpto(target-delta); | ||
1216 | } | ||
979 | } | 1217 | } |
980 | while (!buffdoc.iseol()); | ||
981 | } | 1218 | } |
982 | 1219 | ||
1220 | nbfl = 0; | ||
983 | ypos = 0; | 1221 | ypos = 0; |
1222 | |||
984 | while (locate() < target) | 1223 | while (locate() < target) |
985 | { | 1224 | { |
986 | if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); | 1225 | if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl); |
987 | loc[nbfl] = locate(); | 1226 | loc[nbfl] = locate(); |
@@ -989,9 +1228,9 @@ void QTReader::dopageup(unsigned int target) | |||
989 | ypos += buff[nbfl]->lineSpacing(); | 1228 | ypos += buff[nbfl]->lineSpacing(); |
990 | nbfl++; | 1229 | nbfl++; |
991 | if (!ch) break; | 1230 | if (!ch) break; |
992 | } | 1231 | } |
993 | if (ypos < height() && (delta != 0)) | 1232 | if (guess < 4000 && ypos < height() && (delta != 0)) |
994 | { | 1233 | { |
995 | for (int i = 0; i < nbfl; i++) | 1234 | for (int i = 0; i < nbfl; i++) |
996 | { | 1235 | { |
997 | delete buff[i]; | 1236 | delete buff[i]; |
@@ -1008,16 +1247,29 @@ void QTReader::dopageup(unsigned int target) | |||
1008 | loc[nbfl] = locate(); | 1247 | loc[nbfl] = locate(); |
1009 | int ch = getline(buff[nbfl]); | 1248 | int ch = getline(buff[nbfl]); |
1010 | nbfl++; | 1249 | nbfl++; |
1011 | } | 1250 | } |
1251 | /* | ||
1012 | ypos = 0; | 1252 | ypos = 0; |
1013 | numlines = 0; | 1253 | numlines = 0; |
1014 | while (ypos < height() && numlines <= nbfl-1) | 1254 | while (ypos < height() && numlines <= nbfl-1) |
1015 | { | 1255 | { |
1016 | ypos += buff[nbfl - numlines - 1]->lineSpacing(); | 1256 | ypos += buff[nbfl - numlines - 1]->lineSpacing(); |
1017 | numlines++; | 1257 | numlines++; |
1018 | } | 1258 | } |
1019 | --numlines; | 1259 | --numlines; |
1260 | */ | ||
1261 | |||
1262 | ypos = 0; | ||
1263 | numlines = 0; | ||
1264 | while (ypos < height() && numlines+2 <= nbfl) | ||
1265 | { | ||
1266 | ypos += buff[nbfl - numlines - 2]->lineSpacing(); | ||
1267 | numlines++; | ||
1268 | } | ||
1269 | if (numlines > 0) --numlines; | ||
1270 | if (numlines == 0 && nbfl > 1) numlines = 1; | ||
1271 | |||
1020 | int offset = nbfl-1; | 1272 | int offset = nbfl-1; |
1021 | offset -= numlines; | 1273 | offset -= numlines; |
1022 | ypos = 0; | 1274 | ypos = 0; |
1023 | for (int i = 0; i <= numlines; i++) | 1275 | for (int i = 0; i <= numlines; i++) |
@@ -1026,9 +1278,13 @@ void QTReader::dopageup(unsigned int target) | |||
1026 | textarray[i] = buff[offset+i]; | 1278 | textarray[i] = buff[offset+i]; |
1027 | locnarray[i] = loc[offset + i]; | 1279 | locnarray[i] = loc[offset + i]; |
1028 | ypos += textarray[i]->lineSpacing(); | 1280 | ypos += textarray[i]->lineSpacing(); |
1029 | } | 1281 | } |
1282 | #ifdef _WINDOWS | ||
1283 | for (i = 0; i < nbfl - numlines - 1; i++) | ||
1284 | #else | ||
1030 | for (int i = 0; i < nbfl - numlines - 1; i++) | 1285 | for (int i = 0; i < nbfl - numlines - 1; i++) |
1286 | #endif | ||
1031 | { | 1287 | { |
1032 | delete buff[i]; | 1288 | delete buff[i]; |
1033 | } | 1289 | } |
1034 | 1290 | ||
@@ -1056,23 +1312,24 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
1056 | if (m_lastfile == newfile) | 1312 | if (m_lastfile == newfile) |
1057 | { | 1313 | { |
1058 | lcn = m_lastposn; | 1314 | lcn = m_lastposn; |
1059 | } | 1315 | } |
1060 | m_lastfile = newfile; | ||
1061 | // QMessageBox::information(0, "Opening...", newfile); | 1316 | // QMessageBox::information(0, "Opening...", newfile); |
1062 | m_lastwidth = width(); | 1317 | m_lastwidth = width(); |
1063 | m_lastheight = height(); | 1318 | m_lastheight = height(); |
1064 | if (buffdoc.openfile(this,newfile) == 0) | 1319 | if (buffdoc.openfile(this,newfile) == 0) |
1065 | { | 1320 | { |
1321 | m_lastfile = newfile; | ||
1322 | buffdoc.setwidth(m_lastwidth-2*m_border); | ||
1066 | bRC = true; | 1323 | bRC = true; |
1067 | buffdoc.setContinuous(m_continuousDocument); | 1324 | buffdoc.setContinuous(m_continuousDocument); |
1068 | // qDebug("buffdoc.openfile done"); | 1325 | // // qDebug("buffdoc.openfile done"); |
1069 | locate(lcn); | 1326 | locate(lcn); |
1070 | // qDebug("buffdoc.locate done"); | 1327 | // // qDebug("buffdoc.locate done"); |
1071 | } | 1328 | } |
1072 | setfilter(getfilter()); | 1329 | setfilter(getfilter()); |
1073 | update(); | 1330 | update(); |
1074 | // qDebug("Updated"); | 1331 | // // qDebug("Updated"); |
1075 | return bRC; | 1332 | return bRC; |
1076 | } | 1333 | } |
1077 | 1334 | ||
1078 | void QTReader::lineDown() | 1335 | void QTReader::lineDown() |
@@ -1088,9 +1345,13 @@ void QTReader::lineDown() | |||
1088 | break; | 1345 | break; |
1089 | } | 1346 | } |
1090 | } | 1347 | } |
1091 | offset = numlines - offset; | 1348 | offset = numlines - offset; |
1349 | #ifdef _WINDOWS | ||
1350 | for (i = offset; i <= numlines; i++) | ||
1351 | #else | ||
1092 | for (int i = offset; i <= numlines; i++) | 1352 | for (int i = offset; i <= numlines; i++) |
1353 | #endif | ||
1093 | { | 1354 | { |
1094 | CDrawBuffer* buff = textarray[i-offset]; | 1355 | CDrawBuffer* buff = textarray[i-offset]; |
1095 | textarray[i-offset] = textarray[i]; | 1356 | textarray[i-offset] = textarray[i]; |
1096 | locnarray[i-offset] = locnarray[i]; | 1357 | locnarray[i-offset] = locnarray[i]; |
@@ -1258,9 +1519,13 @@ void QTReader::lineUp() | |||
1258 | textarray[0] = buff; | 1519 | textarray[0] = buff; |
1259 | locnarray[0] = loc; | 1520 | locnarray[0] = loc; |
1260 | int start = numlines; | 1521 | int start = numlines; |
1261 | int ypos = 0; | 1522 | int ypos = 0; |
1262 | for (int i = 0; i <= numlines; i++) | 1523 | #ifdef _WINDOWS |
1524 | for (i = 0; i <= numlines; i++) | ||
1525 | #else | ||
1526 | for (int i = 0; i <= numlines; i++) | ||
1527 | #endif | ||
1263 | { | 1528 | { |
1264 | ypos += textarray[i]->lineSpacing(); | 1529 | ypos += textarray[i]->lineSpacing(); |
1265 | if (ypos > height()) | 1530 | if (ypos > height()) |
1266 | { | 1531 | { |
@@ -1295,33 +1560,4 @@ MarkupType QTReader::PreferredMarkup() | |||
1295 | } | 1560 | } |
1296 | } | 1561 | } |
1297 | return m; | 1562 | return m; |
1298 | } | 1563 | } |
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 | } | ||