/*! */ void QFoldPanel::paint(QPainter *p, QEditor *e) { QDocument *doc = editor()->document(); QLanguageDefinition *def = e->languageDefinition(); if ( !def || !doc ) { return; } m_rects.clear(); m_lines.clear(); bool bVisible = false; //, // inCursorBlock = false; QDocumentLine block; const QFontMetrics fm(doc->font()); int n, pos, depth = 0, max = doc->lines(), h = fm.height(), ls = fm.lineSpacing(), pageBottom = e->viewport()->height(), contentsY = e->verticalOffset(); pos = - contentsY; //qDebug("beg pos : %i", pos); for ( n = 0; n < max; ++n ) { if ( pos > pageBottom ) break; block = doc->line(n); if ( block.isHidden() ) { continue; } int len = ls * block.lineSpan(); int flags = def->blockFlags(doc, n, depth); short open = QCE_FOLD_OPEN_COUNT(flags); short close = QCE_FOLD_CLOSE_COUNT(flags); bVisible = ((pos + len) >= 0); int oldDepth = depth; depth -= close; if ( depth < 0 ) depth = 0; depth += open; if ( open ) { if ( flags & QLanguageDefinition::Collapsed ) { int bound = (ls - 8) / 2; int mid = pos + len - ls / 6; // outermost block folded : none of the opening is actually opened depth -= open; if ( bVisible ) { // draw icon if ( bound > 0 && oldDepth > 0 ) { p->drawLine(7, pos, 7, pos + bound); } if ( close ) { p->drawLine(7, pos + 8 + bound, 7, mid); p->drawLine(7, mid, 12, mid); } m_lines << n; m_rects << drawIcon(p, e, 3, pos + bound, true); } int sub = open; //qDebug("%i : +%i", n, open); while ( sub > 0 && ((n + 1) < max) ) { ++n; block = doc->line(n); if ( !block.isHidden() ) { if ( bVisible ) p->drawLine(7, pos + 8 + bound, 7, pos + len); --n; break; } int sflags = def->blockFlags(doc, n, depth + 1); short sopen = QCE_FOLD_OPEN_COUNT(sflags); short sclose = QCE_FOLD_CLOSE_COUNT(sflags); sub -= sclose; if ( sub <= 0 ) break; sub += sopen; } depth += sub; if ( bVisible && depth > 0 ) { if ( close ) p->drawLine(7, mid, 7, pos + len); else p->drawLine(7, pos + 8 + bound, 7, pos + len); } } else { if ( bVisible ) { int bound = (ls - 8) / 2; if ( oldDepth > 0 && bound > 0 ) p->drawLine(7, pos, 7, pos + bound); m_lines << n; m_rects << drawIcon(p, e, 3, pos + bound, false); int mid = pos + len - ls / 6; if ( close ) p->drawLine(7, mid, 12, mid); if ( bound > 0 ) p->drawLine(7, pos + 8 + bound, 7, pos + len); } } } else if ( (oldDepth > 0) && bVisible ) { if ( close ) { int mid = pos + len - ls / 6; p->drawLine(7, pos, 7, mid); p->drawLine(7, mid, 12, mid); if ( depth > 0 ) p->drawLine(7, pos, 7, pos + len); } else { p->drawLine(7, pos, 7, pos + len); } } pos += len; } }
/*! \internal */ void QLineMarkPanel::paint(QPainter *p, QEditor *e) { if ( !e || !e->document() ) return; m_rects.clear(); m_lines.clear(); QDocument *d = e->document(); int maxMarksPerLine = d->maxMarksPerLine(); setFixedWidth(maxMarksPerLine ? maxMarksPerLine * 16 + 2 : 18); const QFontMetrics fm( d->font() ); int n, posY, maxCount = 0, as = fm.ascent(), ls = fm.lineSpacing(), pageBottom = e->viewport()->height(), contentsY = e->verticalOffset(); QString txt; const QFontMetrics sfm(fontMetrics()); QLineMarksInfoCenter *mic = QLineMarksInfoCenter::instance(); n = d->lineNumber(contentsY); posY = 2 + d->y(n) - contentsY; //qDebug("first = %i; last = %i", first, last); //qDebug("beg pos : %i", posY); //qDebug("<session>"); for ( ; ; ++n ) { //qDebug("n = %i; pos = %i", n, posY); QDocumentLine line = d->line(n); if ( line.isNull() || ((posY - as) > pageBottom) ) break; if ( line.isHidden() ) continue; m_lines << n; m_rects << QRect(0, posY, width(), ls); if ( maxMarksPerLine ) { int count = 1; QList<int> lm = line.marks(); foreach ( int id, lm ) { QPixmap pix = mic->markType(id).icon; if ( pix.isNull() ) continue; int h = qMin(pix.height(), ls), w = qMin(pix.width(), 16), x = count, y = posY + ( (ls - h) >> 1 ); p->drawPixmap(x, y, w, h, pix); count += 16; } } posY += ls * line.lineSpan(); }