author | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
---|---|---|
committer | pohly <pohly> | 2004-08-24 20:52:45 (UTC) |
commit | 73253e93327cf4ef0932de1b4afb56af22a0f37e (patch) (unidiff) | |
tree | 1c9a7a6dd3341e036a894d348a3372525d29acec /noncore/apps/opie-reader/CDrawBuffer.cpp | |
parent | e90847c784c48bd21bf8768cb38edb853b832697 (diff) | |
download | opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.zip opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.gz opie-73253e93327cf4ef0932de1b4afb56af22a0f37e.tar.bz2 |
updated source to opie-reader 0.7g
Diffstat (limited to 'noncore/apps/opie-reader/CDrawBuffer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CDrawBuffer.cpp | 400 |
1 files changed, 359 insertions, 41 deletions
diff --git a/noncore/apps/opie-reader/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp index b137ac3..cd79fec 100644 --- a/noncore/apps/opie-reader/CDrawBuffer.cpp +++ b/noncore/apps/opie-reader/CDrawBuffer.cpp | |||
@@ -2,4 +2,8 @@ | |||
2 | #include "FontControl.h" | 2 | #include "FontControl.h" |
3 | #include <qfontmetrics.h> | ||
3 | #include <qpainter.h> | 4 | #include <qpainter.h> |
5 | #include <qpixmap.h> | ||
4 | #include <qimage.h> | 6 | #include <qimage.h> |
7 | #include "useqpe.h" | ||
8 | #include "opie.h" | ||
5 | 9 | ||
@@ -15,3 +19,3 @@ void CDrawBuffer::setright(CDrawBuffer& rhs, int f) | |||
15 | fc = rhs.fc; | 19 | fc = rhs.fc; |
16 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; | 20 | m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; |
17 | while (!segs.isEmpty()) | 21 | while (!segs.isEmpty()) |
@@ -30,3 +34,2 @@ void CDrawBuffer::setright(CDrawBuffer& rhs, int f) | |||
30 | CStyle _style = next->style; | 34 | CStyle _style = next->style; |
31 | |||
32 | segs.push_back(textsegment(st,next->style)); | 35 | segs.push_back(textsegment(st,next->style)); |
@@ -42,5 +45,4 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
42 | int i; | 45 | int i; |
43 | // //odebug << "Trying 2" << oendl; | 46 | // //qDebug("Trying 2"); |
44 | len = rhs.len; | 47 | len = rhs.len; |
45 | m_maxstyle = rhs.m_maxstyle; | ||
46 | m_ascent = rhs.m_ascent; | 48 | m_ascent = rhs.m_ascent; |
@@ -49,2 +51,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
49 | m_lineExtraSpacing = rhs.m_lineExtraSpacing; | 51 | m_lineExtraSpacing = rhs.m_lineExtraSpacing; |
52 | m_showPartial = rhs.m_showPartial; | ||
50 | while (!segs.isEmpty()) | 53 | while (!segs.isEmpty()) |
@@ -60,3 +63,3 @@ CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) | |||
60 | len = i; | 63 | len = i; |
61 | // //odebug << "Tried 2" << oendl; | 64 | // //qDebug("Tried 2"); |
62 | return *this; | 65 | return *this; |
@@ -82,2 +85,3 @@ void CDrawBuffer::empty() | |||
82 | m_bEop = false; | 85 | m_bEop = false; |
86 | m_bBop = false; | ||
83 | len = 0; | 87 | len = 0; |
@@ -89,3 +93,3 @@ void CDrawBuffer::empty() | |||
89 | segs.push_back(textsegment(0,CStyle())); | 93 | segs.push_back(textsegment(0,CStyle())); |
90 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; | 94 | m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; |
91 | m_bEof = false; | 95 | m_bEof = false; |
@@ -93,2 +97,12 @@ void CDrawBuffer::empty() | |||
93 | 97 | ||
98 | void CDrawBuffer::setendpara(const CStyle& _style/* = ucFontBase*/) | ||
99 | { | ||
100 | m_bEop = true; | ||
101 | if (len == 0) | ||
102 | { | ||
103 | segs.first().start = 0; | ||
104 | segs.first().style = _style; | ||
105 | } | ||
106 | } | ||
107 | |||
94 | void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) | 108 | void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) |
@@ -113,3 +127,3 @@ void CDrawBuffer::truncate(int n) | |||
113 | 127 | ||
114 | int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _border) | 128 | int CDrawBuffer::width(int availht, int numchars, bool onscreen, int scwidth, unsigned short _lborder, unsigned short _rborder) |
115 | { | 129 | { |
@@ -152,3 +166,3 @@ int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _ | |||
152 | { | 166 | { |
153 | extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width()); | 167 | extraspace = (scwidth - (_lborder+_rborder) - rightMargin() - leftMargin() - width(availht)); |
154 | if (extraspace == 0) just = false; | 168 | if (extraspace == 0) just = false; |
@@ -170,3 +184,9 @@ int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _ | |||
170 | { | 184 | { |
171 | currentx += (gzoom*currentstyle.getPicture()->width())/100; | 185 | int ht = (gzoom*currentstyle.getPicture()->height())/100; |
186 | int wt = (gzoom*currentstyle.getPicture()->width())/100; | ||
187 | if (ht > availht) | ||
188 | { | ||
189 | wt = (wt*availht)/ht; | ||
190 | } | ||
191 | currentx += wt; | ||
172 | } | 192 | } |
@@ -210,3 +230,3 @@ int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _ | |||
210 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | 230 | QString nstr = str.mid(lastspace+1, nsp-lastspace); |
211 | // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl; | 231 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); |
212 | int lw = fm.width(nstr); | 232 | int lw = fm.width(nstr); |
@@ -232,2 +252,88 @@ int CDrawBuffer::width(int numchars, bool onscreen, int scwidth, unsigned char _ | |||
232 | 252 | ||
253 | int CDrawBuffer::charwidth(int numchars, CStyle& currentstyle) | ||
254 | { | ||
255 | if (currentstyle.isPicture()) | ||
256 | { | ||
257 | int gzoom = fc->gzoom(); | ||
258 | if (currentstyle.canScale()) | ||
259 | { | ||
260 | return (gzoom*currentstyle.getPicture()->width())/100; | ||
261 | } | ||
262 | else | ||
263 | { | ||
264 | return currentstyle.getPicture()->width(); | ||
265 | } | ||
266 | } | ||
267 | else | ||
268 | { | ||
269 | if (currentstyle.isMono() && !fc->hasCourier()) | ||
270 | { | ||
271 | return (7*fc->getsize(currentstyle))/10; | ||
272 | } | ||
273 | else | ||
274 | { | ||
275 | QString text = QChar((data())[numchars]); | ||
276 | QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); | ||
277 | // f.setUnderline(currentstyle.isUnderline()); | ||
278 | QFontMetrics fm(f); | ||
279 | return fm.width(text); | ||
280 | } | ||
281 | } | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | int CDrawBuffer::charwidth(int numchars) | ||
286 | { | ||
287 | int gzoom = fc->gzoom(); | ||
288 | int end = 0; | ||
289 | QString text = QChar((data())[numchars]); | ||
290 | CList<textsegment>::iterator textstart = segs.begin(); | ||
291 | CList<textsegment>::iterator textend = textstart; | ||
292 | do | ||
293 | { | ||
294 | textend++; | ||
295 | end = (textend != segs.end()) ? textend->start : len; | ||
296 | if (end <= numchars) | ||
297 | { | ||
298 | textstart = textend; | ||
299 | continue; | ||
300 | } | ||
301 | if (numchars >= 0 && end > numchars) | ||
302 | { | ||
303 | end = numchars; | ||
304 | } | ||
305 | CStyle currentstyle = textstart->style; | ||
306 | if (currentstyle.isPicture()) | ||
307 | { | ||
308 | if (currentstyle.canScale()) | ||
309 | { | ||
310 | return (gzoom*currentstyle.getPicture()->width())/100; | ||
311 | } | ||
312 | else | ||
313 | { | ||
314 | return currentstyle.getPicture()->width(); | ||
315 | } | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | if (currentstyle.isMono() && !fc->hasCourier()) | ||
320 | { | ||
321 | return (7*fc->getsize(currentstyle))/10; | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | QFont f(currentstyle.isMono() ? QString(fc->fixedfontname()) : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); | ||
326 | // f.setUnderline(currentstyle.isUnderline()); | ||
327 | QFontMetrics fm(f); | ||
328 | return fm.width(text); | ||
329 | } | ||
330 | } | ||
331 | textstart = textend; | ||
332 | } | ||
333 | while (textend != segs.end() /* && end != numchars*/ && textstart->start < len); | ||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | |||
338 | |||
233 | int CDrawBuffer::leftMargin() | 339 | int CDrawBuffer::leftMargin() |
@@ -242,5 +348,5 @@ int CDrawBuffer::rightMargin() | |||
242 | 348 | ||
243 | int CDrawBuffer::offset(int scwidth, unsigned char _border) | 349 | int CDrawBuffer::offset(int scwidth, unsigned short _lborder, unsigned short _rborder, int availht) |
244 | { | 350 | { |
245 | int currentx = _border; | 351 | int currentx = _lborder; |
246 | switch(segs.begin()->style.getJustify()) | 352 | switch(segs.begin()->style.getJustify()) |
@@ -249,3 +355,3 @@ int CDrawBuffer::offset(int scwidth, unsigned char _border) | |||
249 | { | 355 | { |
250 | currentx = scwidth - _border - rightMargin() - width(); | 356 | currentx = scwidth - _rborder - rightMargin() - width(availht); |
251 | } | 357 | } |
@@ -255,5 +361,5 @@ int CDrawBuffer::offset(int scwidth, unsigned char _border) | |||
255 | currentx = ( | 361 | currentx = ( |
256 | scwidth + | 362 | scwidth - _lborder -_rborder + |
257 | leftMargin() - rightMargin() | 363 | leftMargin() - rightMargin() |
258 | - width())/2; | 364 | - width(availht))/2 + _lborder; |
259 | } | 365 | } |
@@ -262,3 +368,3 @@ int CDrawBuffer::offset(int scwidth, unsigned char _border) | |||
262 | case m_AlignLeft: | 368 | case m_AlignLeft: |
263 | currentx = _border + leftMargin(); | 369 | currentx = _lborder + leftMargin(); |
264 | break; | 370 | break; |
@@ -268,8 +374,49 @@ int CDrawBuffer::offset(int scwidth, unsigned char _border) | |||
268 | 374 | ||
269 | void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned char _border) | 375 | void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth, unsigned short _lborder, unsigned short _rborder, const QColor& _bg, int availht) |
270 | { | 376 | { |
377 | CList<textsegment>::iterator textstart = segs.begin(); | ||
378 | QColor paperColour = QColor(qRgb(textstart->style.pRed(), | ||
379 | textstart->style.pGreen(), | ||
380 | textstart->style.pBlue())); | ||
381 | |||
382 | Highlight(_p, !(paperColour == _bg), _lborder, _y, scwidth-(_lborder+_rborder), paperColour); | ||
383 | // Highlight(_p, true, _lborder, _y, scwidth-(_lborder+_rborder), paperColour); | ||
271 | int gzoom = fc->gzoom(); | 384 | int gzoom = fc->gzoom(); |
272 | int currentx = offset(scwidth, _border); | 385 | int currentx = offset(scwidth, _lborder, _rborder, availht); |
386 | if (!m_hastext) | ||
387 | { | ||
388 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++) | ||
389 | { | ||
390 | CStyle currentstyle = iter->style; | ||
391 | if (currentstyle.isPicture()) | ||
392 | { | ||
393 | CStyle currentstyle = segs.begin()->style; | ||
394 | int ht = (gzoom*currentstyle.getPicture()->height())/100; | ||
395 | int wt = (gzoom*currentstyle.getPicture()->width())/100; | ||
396 | bool willscale = false; | ||
397 | if (ht > availht) | ||
398 | { | ||
399 | wt = (wt*availht)/ht; | ||
400 | ht = availht; | ||
401 | willscale = true; | ||
402 | } | ||
403 | |||
404 | QPixmap pc; | ||
405 | if ((willscale || gzoom != 100) && currentstyle.canScale()) | ||
406 | { | ||
407 | QImage im = currentstyle.getPicture()->smoothScale(wt,ht); | ||
408 | pc.convertFromImage(im); | ||
409 | } | ||
410 | else | ||
411 | { | ||
412 | pc.convertFromImage(*currentstyle.getPicture()); | ||
413 | } | ||
414 | int yoffset = pc.height()/2; | ||
415 | _p->drawPixmap( currentx, _y-yoffset, pc ); | ||
416 | currentx += pc.width(); | ||
417 | } | ||
418 | } | ||
419 | return; | ||
420 | } | ||
273 | QString text = toQString(data()); | 421 | QString text = toQString(data()); |
274 | CList<textsegment>::iterator textstart = segs.begin(); | ||
275 | int extraspace = 0; | 422 | int extraspace = 0; |
@@ -307,3 +454,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
307 | { | 454 | { |
308 | extraspace = (scwidth - 2*_border - rightMargin() - leftMargin() - width()); | 455 | extraspace = (scwidth - (_lborder+_rborder) - rightMargin() - leftMargin() - width(availht)); |
309 | if (extraspace == 0) just = false; | 456 | if (extraspace == 0) just = false; |
@@ -312,2 +459,4 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
312 | CList<textsegment>::iterator textend = textstart; | 459 | CList<textsegment>::iterator textend = textstart; |
460 | |||
461 | bool drawBackground = false; | ||
313 | do | 462 | do |
@@ -317,5 +466,21 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
317 | CStyle currentstyle = textstart->style; | 466 | CStyle currentstyle = textstart->style; |
467 | /* | ||
468 | bool drawBackground = ( | ||
469 | currentstyle.bRed() != 255 | ||
470 | || | ||
471 | currentstyle.bGreen() != 255 | ||
472 | || | ||
473 | currentstyle.bBlue() != 255 | ||
474 | ); | ||
475 | */ | ||
476 | QColor bgColour = QColor(qRgb(currentstyle.bRed(), | ||
477 | currentstyle.bGreen(), | ||
478 | currentstyle.bBlue())); | ||
479 | drawBackground = !(bgColour == _bg); | ||
480 | |||
481 | // if (drawBackground) qDebug("Drawing background"); | ||
482 | |||
318 | QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); | 483 | QFont f((currentstyle.isMono() && fc->hasCourier()) ? fc->fixedfontname() : fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); |
319 | //f.setUnderline(currentstyle.isUnderline()); | 484 | //f.setUnderline(currentstyle.isUnderline()); |
320 | //if (currentstyle.isUnderline()) odebug << "UNDERLINE" << oendl; | 485 | //if (currentstyle.isUnderline()) qDebug("UNDERLINE"); |
321 | _p->setFont(f); | 486 | _p->setFont(f); |
@@ -328,4 +493,7 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
328 | int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; | 493 | int voffset = currentstyle.getVOffset()*fc->getsize(currentstyle)/2; |
494 | |||
329 | if (_bMono) | 495 | if (_bMono) |
330 | { | 496 | { |
497 | |||
498 | Highlight(_p, drawBackground, currentx, _y, str.length()*_charWidth, bgColour); | ||
331 | if (currentstyle.isUnderline()) | 499 | if (currentstyle.isUnderline()) |
@@ -351,2 +519,9 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
351 | int wt = (gzoom*currentstyle.getPicture()->width())/100; | 519 | int wt = (gzoom*currentstyle.getPicture()->width())/100; |
520 | bool willscale = false; | ||
521 | if (ht > availht) | ||
522 | { | ||
523 | wt = (wt*availht)/ht; | ||
524 | ht = availht; | ||
525 | willscale = true; | ||
526 | } | ||
352 | int ascent = fc->ascent(currentstyle)/2; | 527 | int ascent = fc->ascent(currentstyle)/2; |
@@ -355,3 +530,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
355 | QPixmap pc; | 530 | QPixmap pc; |
356 | if (gzoom != 100 && currentstyle.canScale()) | 531 | if ((willscale || gzoom != 100) && currentstyle.canScale()) |
357 | { | 532 | { |
@@ -373,2 +548,3 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
373 | int w = cw*(end-textstart->start); | 548 | int w = cw*(end-textstart->start); |
549 | Highlight(_p, drawBackground, currentx, _y, w, bgColour); | ||
374 | if (currentstyle.isUnderline()) | 550 | if (currentstyle.isUnderline()) |
@@ -410,5 +586,7 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
410 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | 586 | QString nstr = str.mid(lastspace+1, nsp-lastspace); |
411 | // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl; | 587 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); |
412 | int lw = fm.width(nstr); | 588 | int lw = fm.width(nstr); |
589 | Highlight(_p, drawBackground, cx, _y, lw, bgColour); | ||
413 | _p->drawText( cx, _y+voffset, nstr); | 590 | _p->drawText( cx, _y+voffset, nstr); |
591 | Highlight(_p, drawBackground, cx+lw, _y, nexttoadd, bgColour); | ||
414 | cx += lw+nexttoadd; | 592 | cx += lw+nexttoadd; |
@@ -420,4 +598,5 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
420 | QString nstr = str.mid(lastspace+1, nsp-lastspace); | 598 | QString nstr = str.mid(lastspace+1, nsp-lastspace); |
421 | // odebug << "str:" << str << ": last:" << lastspace << " new:" << nsp << " nstr:" << nstr << ":" << oendl; | 599 | // qDebug("str:%s: last:%d new:%d nstr:%s:", (const char*)str, lastspace, nsp, (const char*)nstr); |
422 | int lw = fm.width(nstr); | 600 | int lw = fm.width(nstr); |
601 | Highlight(_p, drawBackground, cx, _y, lw, bgColour); | ||
423 | _p->drawText( cx, _y+voffset, nstr); | 602 | _p->drawText( cx, _y+voffset, nstr); |
@@ -428,4 +607,6 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
428 | QString nstr = str.right(str.length()-1-lastspace); | 607 | QString nstr = str.right(str.length()-1-lastspace); |
608 | int lw = fm.width(nstr); | ||
609 | Highlight(_p, drawBackground, cx, _y, lw, bgColour); | ||
429 | _p->drawText( cx, _y+voffset, nstr); | 610 | _p->drawText( cx, _y+voffset, nstr); |
430 | cx += fm.width(nstr); | 611 | cx += lw; |
431 | w = cx - currentx; | 612 | w = cx - currentx; |
@@ -434,4 +615,6 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
434 | { | 615 | { |
616 | int lw = fm.width(str); | ||
617 | Highlight(_p, drawBackground, currentx, _y, lw, bgColour); | ||
435 | _p->drawText( currentx, _y+voffset, str); | 618 | _p->drawText( currentx, _y+voffset, str); |
436 | w = fm.width(str); | 619 | w = lw; |
437 | } | 620 | } |
@@ -453,2 +636,16 @@ void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int | |||
453 | while (textend != segs.end() && textstart->start < len); | 636 | while (textend != segs.end() && textstart->start < len); |
637 | /* | ||
638 | if (firstColour == bgColour) | ||
639 | { | ||
640 | Highlight(_p, drawBackground, currentx, _y, scwidth - (currentx + _lborder + _rborder), bgColour); | ||
641 | } | ||
642 | */ | ||
643 | } | ||
644 | |||
645 | void CDrawBuffer::Highlight(QPainter* _p, bool drawBackground, int _x, int _y, int w, QColor bgColour) | ||
646 | { | ||
647 | if (drawBackground) | ||
648 | { | ||
649 | _p->fillRect(_x, _y-m_ascent, w, m_lineSpacing, bgColour); | ||
650 | } | ||
454 | } | 651 | } |
@@ -460,4 +657,10 @@ CStyle CDrawBuffer::laststyle() | |||
460 | 657 | ||
461 | linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | 658 | CStyle CDrawBuffer::firststyle() |
659 | { | ||
660 | return segs.first().style; | ||
661 | } | ||
662 | |||
663 | linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt, size_t& offset, size_t& pictgt, QImage*& img) | ||
462 | { | 664 | { |
665 | linkType ret = eNone; | ||
463 | int end = 0; | 666 | int end = 0; |
@@ -472,5 +675,5 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | |||
472 | /* | 675 | /* |
473 | if (currentstyle.isPicture()) odebug << "Passed thru picture" << oendl; | 676 | if (currentstyle.isPicture()) qDebug("Passed thru picture"); |
474 | if (currentstyle.getLink()) odebug << "Passed thru link" << oendl; | 677 | if (currentstyle.getLink()) qDebug("Passed thru link"); |
475 | //odebug << "islink:" << numchars << " - " << end << "" << oendl; | 678 | //qDebug("islink:%d - %d", numchars, end); |
476 | */ | 679 | */ |
@@ -479,7 +682,7 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | |||
479 | while (textend != segs.end() && end <= numchars); | 682 | while (textend != segs.end() && end <= numchars); |
480 | // if (currentstyle.isPicture()) odebug << "Clicked on picture" << oendl; | 683 | img = currentstyle.getPicture(); |
481 | if (currentstyle.getPictureLink()) | 684 | if (currentstyle.getPictureLink()) |
482 | { | 685 | { |
483 | tgt = currentstyle.getPictureLinkData(); | 686 | pictgt = currentstyle.getPictureLinkData(); |
484 | return ePicture; | 687 | ret |= ePicture; |
485 | } | 688 | } |
@@ -488,11 +691,32 @@ linkType CDrawBuffer::getLinkType(int numchars, size_t& tgt) | |||
488 | tgt = currentstyle.getData(); | 691 | tgt = currentstyle.getData(); |
489 | return eLink; | 692 | offset = currentstyle.getOffset(); |
693 | ret |= eLink; | ||
490 | } | 694 | } |
491 | return eNone; | 695 | return ret; |
492 | } | 696 | } |
493 | 697 | ||
494 | void CDrawBuffer::resize() | 698 | void CDrawBuffer::resize(int availht) |
495 | { | 699 | { |
496 | int gzoom = fc->gzoom(); | 700 | int gzoom = fc->gzoom(); |
497 | m_maxstyle = m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; | 701 | m_ascent = m_descent = m_lineSpacing = m_lineExtraSpacing = 0; |
702 | /* | ||
703 | int t_ascent = 0; | ||
704 | int t_descent = 0; | ||
705 | int t_lineExtraSpacing = 0; | ||
706 | */ | ||
707 | int t_lineSpacing = 0; | ||
708 | m_hastext = false; | ||
709 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) | ||
710 | { | ||
711 | CStyle _style = iter->style; | ||
712 | if (!_style.isPicture()) | ||
713 | { | ||
714 | m_hastext = true; | ||
715 | break; | ||
716 | } | ||
717 | iter++; | ||
718 | } | ||
719 | if (m_hastext) | ||
720 | { | ||
721 | |||
498 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) | 722 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end() && iter->start <= len; ) |
@@ -512,3 +736,22 @@ void CDrawBuffer::resize() | |||
512 | extra = linespacing - ascent - descent; | 736 | extra = linespacing - ascent - descent; |
513 | if (_style.isPicture() && _style.canScale()) | 737 | /* |
738 | if (ascent > t_ascent) t_ascent = ascent; | ||
739 | if (descent > t_descent) t_descent = descent; | ||
740 | if (extra > t_lineExtraSpacing) t_lineExtraSpacing = extra; | ||
741 | t_lineSpacing = t_ascent+t_descent+t_lineExtraSpacing; | ||
742 | */ | ||
743 | if (linespacing > t_lineSpacing) t_lineSpacing = linespacing; | ||
744 | if (_style.isPicture()) | ||
745 | { | ||
746 | int ht = (gzoom*_style.getPicture()->height())/100; | ||
747 | int wt = (gzoom*_style.getPicture()->width())/100; | ||
748 | |||
749 | bool willscale = false; | ||
750 | if (ht > availht) | ||
751 | { | ||
752 | wt = (wt*availht)/ht; | ||
753 | ht = availht; | ||
754 | willscale = true; | ||
755 | } | ||
756 | if (willscale || _style.canScale()) | ||
514 | { | 757 | { |
@@ -517,2 +760,4 @@ void CDrawBuffer::resize() | |||
517 | } | 760 | } |
761 | } | ||
762 | |||
518 | /* | 763 | /* |
@@ -531,2 +776,3 @@ void CDrawBuffer::resize() | |||
531 | } | 776 | } |
777 | m_showPartial = (m_lineSpacing > t_lineSpacing); | ||
532 | int lead = fc->getlead(); | 778 | int lead = fc->getlead(); |
@@ -534,4 +780,4 @@ void CDrawBuffer::resize() | |||
534 | { | 780 | { |
535 | int xt = (lead*m_lineSpacing+5)/10; | 781 | int xt = (lead*t_lineSpacing+5)/10; |
536 | m_descent += xt; | 782 | m_lineExtraSpacing += xt; |
537 | m_lineSpacing += xt; | 783 | m_lineSpacing += xt; |
@@ -541,3 +787,3 @@ void CDrawBuffer::resize() | |||
541 | int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10; | 787 | int xt = ((segs.begin()->style.getExtraSpace()+fc->getextraspace())*fc->getsize(segs.begin()->style)+5)/10; |
542 | //odebug << "ExtraSpace:" << xt << "" << oendl; | 788 | //qDebug("ExtraSpace:%d", xt); |
543 | m_ascent += xt; | 789 | m_ascent += xt; |
@@ -546 +792,73 @@ void CDrawBuffer::resize() | |||
546 | } | 792 | } |
793 | else | ||
794 | { | ||
795 | m_showPartial = true; | ||
796 | int maxheight = 0; | ||
797 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); iter++) | ||
798 | { | ||
799 | CStyle _style = iter->style; | ||
800 | if (_style.isPicture()) | ||
801 | { | ||
802 | int ht = 0; | ||
803 | if (_style.canScale()) | ||
804 | { | ||
805 | ht = ((gzoom*_style.getPicture()->height())/100); | ||
806 | } | ||
807 | else | ||
808 | { | ||
809 | ht = _style.getPicture()->height(); | ||
810 | } | ||
811 | if (ht > availht) | ||
812 | { | ||
813 | ht = availht; | ||
814 | } | ||
815 | if (ht > maxheight) maxheight = ht; | ||
816 | } | ||
817 | } | ||
818 | m_ascent = maxheight/2; | ||
819 | m_descent = maxheight-m_ascent; | ||
820 | m_lineExtraSpacing = 0; | ||
821 | m_lineSpacing = m_ascent+m_descent; | ||
822 | } | ||
823 | } | ||
824 | |||
825 | CStyle* CDrawBuffer::getNextLink(int& offset) | ||
826 | { | ||
827 | CStyle* ret = NULL; | ||
828 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); ++iter) | ||
829 | { | ||
830 | if (offset < iter->start && iter->style.getLink()) | ||
831 | { | ||
832 | ret = &(iter->style); | ||
833 | offset = iter->start; | ||
834 | qDebug("Found a link at offset %d!", offset); | ||
835 | break; | ||
836 | } | ||
837 | } | ||
838 | return ret; | ||
839 | } | ||
840 | |||
841 | int CDrawBuffer::invertLink(int offset) | ||
842 | { | ||
843 | for (CList<textsegment>::iterator iter = segs.begin(); iter != segs.end(); ++iter) | ||
844 | { | ||
845 | if (offset <= iter->start && iter->style.getLink()) | ||
846 | { | ||
847 | iter->style.invert(); | ||
848 | unsigned long currentvalue = iter->style.getData(); | ||
849 | qDebug("Link data %u", currentvalue); | ||
850 | CList<textsegment>::iterator next = iter; | ||
851 | ++next; | ||
852 | while (next != segs.end() && (currentvalue == next->style.getData()) && next->style.getLink()) | ||
853 | { | ||
854 | next->style.invert(); | ||
855 | offset = next->start; | ||
856 | iter++; | ||
857 | next++; | ||
858 | } | ||
859 | return offset; | ||
860 | } | ||
861 | } | ||
862 | qDebug("Failed to invert"); | ||
863 | return offset; | ||
864 | } | ||