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 | |||
@@ -10,3 +10,6 @@ | |||
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" |
@@ -15,3 +18,5 @@ | |||
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> |
@@ -19,8 +24,9 @@ | |||
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 | ||
@@ -38,2 +44,6 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 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) : |
@@ -53,9 +63,14 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : | |||
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), |
@@ -74,3 +89,3 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, | |||
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); |
@@ -79,2 +94,11 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, | |||
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() |
@@ -89,37 +113,32 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) | |||
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 | } |
@@ -127,5 +146,9 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) | |||
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 | } |
@@ -133,3 +156,3 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) | |||
133 | { | 156 | { |
134 | goUp(); | 157 | goHome(); |
135 | } | 158 | } |
@@ -137,2 +160,52 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) | |||
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 | } |
@@ -150,3 +223,3 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si | |||
150 | { | 223 | { |
151 | offset = x/m_charWidth; | 224 | offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; |
152 | } | 225 | } |
@@ -156,4 +229,4 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si | |||
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; |
@@ -163,2 +236,11 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si | |||
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) |
@@ -175,2 +257,86 @@ void QTReader::setContinuous(bool _b) | |||
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 ) |
@@ -182,5 +348,11 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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; |
@@ -198,3 +370,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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 | { |
@@ -206,2 +380,19 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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()); |
@@ -212,4 +403,4 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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) |
@@ -228,82 +419,9 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) | |||
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 | } |
@@ -328,3 +446,3 @@ void QTReader::focusOutEvent(QFocusEvent* e) | |||
328 | timer->stop(); | 446 | timer->stop(); |
329 | m_scrolldy1 = m_scrolldy2 = 0; | 447 | //m_scrolldy1 = m_scrolldy2 = 0; |
330 | } | 448 | } |
@@ -334,3 +452,5 @@ void QTReader::focusOutEvent(QFocusEvent* e) | |||
334 | #include <qdrawutil.h> | 452 | #include <qdrawutil.h> |
453 | #ifndef _WINDOWS | ||
335 | #include <unistd.h> | 454 | #include <unistd.h> |
455 | #endif | ||
336 | 456 | ||
@@ -428,2 +548,28 @@ void QTReader::zoomout() | |||
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) |
@@ -431,2 +577,29 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
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()) |
@@ -475,31 +648,2 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
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: |
@@ -532,9 +676,2 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
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: |
@@ -542,2 +679,3 @@ void QTReader::keyPressEvent(QKeyEvent* e) | |||
542 | } | 679 | } |
680 | */ | ||
543 | } | 681 | } |
@@ -550,3 +688,12 @@ void QTReader::setautoscroll(bool _sc) | |||
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 | } |
@@ -557,4 +704,14 @@ void QTReader::setautoscroll(bool _sc) | |||
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 | } |
@@ -567,3 +724,3 @@ bool QTReader::getline(CDrawBuffer *buff) | |||
567 | { | 724 | { |
568 | return buffdoc.getline(buff ,width(), m_charWidth); | 725 | return buffdoc.getline(buff ,width(), m_charWidth, m_border); |
569 | } | 726 | } |
@@ -571,3 +728,3 @@ bool QTReader::getline(CDrawBuffer *buff) | |||
571 | { | 728 | { |
572 | return buffdoc.getline(buff, width()); | 729 | return buffdoc.getline(buff, width(), m_border); |
573 | } | 730 | } |
@@ -590,2 +747,21 @@ void QTReader::doscroll() | |||
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]; |
@@ -611,3 +787,3 @@ void QTReader::doscroll() | |||
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(); |
@@ -616,3 +792,20 @@ void QTReader::doscroll() | |||
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 | } |
@@ -641,3 +834,3 @@ void QTReader::drawFonts( QPainter *p ) | |||
641 | { | 834 | { |
642 | qDebug("How refreshing..."); | 835 | //qDebug("How refreshing..."); |
643 | if (buffdoc.empty()) return; | 836 | if (buffdoc.empty()) return; |
@@ -646,7 +839,8 @@ void QTReader::drawFonts( QPainter *p ) | |||
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 | } |
@@ -654,5 +848,6 @@ void QTReader::drawFonts( QPainter *p ) | |||
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; |
@@ -660,6 +855,6 @@ void QTReader::drawFonts( QPainter *p ) | |||
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; |
@@ -667,8 +862,8 @@ void QTReader::drawFonts( QPainter *p ) | |||
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; |
@@ -678,5 +873,4 @@ void QTReader::drawFonts( QPainter *p ) | |||
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 | } |
@@ -685,3 +879,5 @@ void QTReader::drawFonts( QPainter *p ) | |||
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++) |
@@ -691,3 +887,3 @@ void QTReader::drawFonts( QPainter *p ) | |||
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 | } |
@@ -696,5 +892,16 @@ void QTReader::drawFonts( QPainter *p ) | |||
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 |
@@ -703,2 +910,3 @@ void QTReader::drawFonts( QPainter *p ) | |||
703 | } | 910 | } |
911 | */ | ||
704 | } | 912 | } |
@@ -744,2 +952,3 @@ void QTReader::init() | |||
744 | { | 952 | { |
953 | // m_showlast = true; | ||
745 | // setCaption( "Qt Draw Demo Application" ); | 954 | // setCaption( "Qt Draw Demo Application" ); |
@@ -773,2 +982,14 @@ 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 | } |
@@ -818,3 +1039,3 @@ 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 ); |
@@ -843,7 +1064,7 @@ bool QTReader::locate(unsigned long n) { | |||
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; |
@@ -858,3 +1079,3 @@ unsigned int QTReader::screenlines() | |||
858 | 1079 | ||
859 | bool QTReader::fillbuffer(int reuse, int ht) | 1080 | bool QTReader::fillbuffer(int reuse, int ht, int newht) |
860 | { | 1081 | { |
@@ -862,3 +1083,6 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
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; |
@@ -866,6 +1090,7 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
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) |
@@ -896,2 +1121,3 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
896 | mylastpos = locate(); | 1121 | mylastpos = locate(); |
1122 | m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; | ||
897 | 1123 | ||
@@ -900,5 +1126,5 @@ bool QTReader::fillbuffer(int reuse, int ht) | |||
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(); |
@@ -907,3 +1133,3 @@ void QTReader::dopagedn() | |||
907 | { | 1133 | { |
908 | //qDebug("Jumping to %u", mylastpos); | 1134 | ////qDebug("Jumping to %u", mylastpos); |
909 | jumpto(mylastpos); | 1135 | jumpto(mylastpos); |
@@ -940,2 +1166,14 @@ void QTReader::dopageup() | |||
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) |
@@ -946,6 +1184,6 @@ void QTReader::dopageup(unsigned int target) | |||
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) |
@@ -953,3 +1191,2 @@ void QTReader::dopageup(unsigned int target) | |||
953 | ch = true; | 1191 | ch = true; |
954 | nbfl = 0; | ||
955 | if (target < guess) | 1192 | if (target < guess) |
@@ -967,18 +1204,20 @@ void QTReader::dopageup(unsigned int target) | |||
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) |
@@ -992,3 +1231,3 @@ void QTReader::dopageup(unsigned int target) | |||
992 | } | 1231 | } |
993 | if (ypos < height() && (delta != 0)) | 1232 | if (guess < 4000 && ypos < height() && (delta != 0)) |
994 | { | 1233 | { |
@@ -1011,2 +1250,3 @@ void QTReader::dopageup(unsigned int target) | |||
1011 | } | 1250 | } |
1251 | /* | ||
1012 | ypos = 0; | 1252 | ypos = 0; |
@@ -1019,2 +1259,14 @@ void QTReader::dopageup(unsigned int target) | |||
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; |
@@ -1029,3 +1281,7 @@ void QTReader::dopageup(unsigned int target) | |||
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 | { |
@@ -1059,3 +1315,2 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
1059 | } | 1315 | } |
1060 | m_lastfile = newfile; | ||
1061 | // QMessageBox::information(0, "Opening...", newfile); | 1316 | // QMessageBox::information(0, "Opening...", newfile); |
@@ -1064,8 +1319,10 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
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 | } |
@@ -1073,3 +1330,3 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) | |||
1073 | update(); | 1330 | update(); |
1074 | // qDebug("Updated"); | 1331 | // // qDebug("Updated"); |
1075 | return bRC; | 1332 | return bRC; |
@@ -1091,3 +1348,7 @@ void QTReader::lineDown() | |||
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 | { |
@@ -1261,3 +1522,7 @@ void QTReader::lineUp() | |||
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 | { |
@@ -1298,30 +1563 @@ MarkupType QTReader::PreferredMarkup() | |||
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 | } | ||