Example #1
0
/*!
	\internal
*/
bool QLineMarkPanel::event(QEvent *e) {
     if (e->type() == QEvent::ToolTip) {
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(e);
        int linen=editor()->document()->lineNumber(editor()->verticalOffset()+helpEvent->y());
        markToolTip="";
        if (linen>-1 && linen<editor()->document()->lines()) {
            QDocumentLine line = editor()->document()->line(linen);
			QList<int> lm = line.marks();
			int count = 1;
			int bestMark = -1;
			QLineMarksInfoCenter *mic = QLineMarksInfoCenter::instance();
			foreach ( int id, lm )
			{
			    if (mic->markType(id).icon.isNull())
                    continue;
                if (helpEvent->x()>count && helpEvent->x()<count+16)
                    bestMark = id; //no break do to overdraw
				if (count < 16*(maxMarksPerLine-1)) {
                    count += 16;
                    if (bestMark!=-1) break;
				}
			}
			if (bestMark!=-1)
                emit toolTipRequested(linen,bestMark);
        }
/*!
	\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();
	}