/*!
	\internal
*/
void QLineChangePanel::paint(QPainter *p, QEditor *e)
{
	if ( !e || !e->document() )
		return;

	const QFontMetrics fm( e->document()->font() );

	int n, posY,
//		maxCount = 0,
		as = fm.ascent(),
		ls = fm.lineSpacing(),
		pageBottom = e->viewport()->height(),
		contentsY = e->verticalOffset();

	QString txt;

	QDocument *d = e->document();
	n = d->lineNumber(contentsY);
	posY = 2 + d->y(n) - contentsY;

	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;

		int span = line.lineSpan();

		if ( d->isLineModified(line) )
		{
			p->fillRect(1, posY, 2, ls * span, Qt::yellow);
		} else if ( d->hasLineEverBeenModified(line) ) {
			p->fillRect(1, posY, 2, ls * span, Qt::green);
		}

		posY += ls * span;
	}
}
Beispiel #2
0
/*!
	\internal
*/
bool QLineChangePanel::paint(QPainter *p, QEditor *e)
{
	if ( !e || !e->document() )
		return true;

	int n, posY,
		as = QFontMetrics(e->document()->font()).ascent(),
		ls = e->document()->getLineSpacing(),
		pageBottom = e->viewport()->height(),
		contentsY = e->verticalOffset();

	QString txt;

	QDocument *d = e->document();
	n = d->lineNumber(contentsY);
	posY = 2 + d->y(n) - contentsY;

	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;

		int span = line.lineSpan();

		if ( d->isLineModified(line) )
		{
			p->fillRect(1, posY, 2, ls * span, QColor(255, 216, 0)); // yellow
		} else if ( d->hasLineEverBeenModified(line) ) {
			p->fillRect(1, posY, 2, ls * span, QColor(70, 191, 0)); // green
		}

		posY += ls * span;
	}
	
	return true;
}
/*!
	\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();
	}
Beispiel #4
0
/*!

*/
bool QLineNumberPanel::paint(QPainter *p, QEditor *e)
{
	/*
		possible Unicode caracter for wrapping arrow :
			0x21B3
			0x2937
	*/
	
	QFont f(font());
	f.setWeight(QFont::Bold);
	const QFontMetrics sfm(f);
	
	#ifndef WIN32
	static const QChar wrappingArrow(0x2937);
	const QFontMetrics specialSfm(sfm);
	#else
	// 0xC4 gives a decent wrapping arrow in Wingdings fonts, availables on all windows systems
	// this is a hackish fallback to workaround Windows issues with Unicode...
	static const QChar wrappingArrow(0xC4);
	QFont specialFont(font());
	specialFont.setRawName("Wingdings");
	const QFontMetrics specialSfm(specialFont);
	#endif
	
	const int max = e->document()->lines();
	const int panelWidth = sfm.width(QString::number(max)) + 5;
	setFixedWidth(panelWidth);
	
	const QFontMetrics fm( e->document()->font() );
	
	int n, posY,
		as = fm.ascent(),
		ls = fm.lineSpacing(),
		pageBottom = e->viewport()->height(),
		contentsY = e->verticalOffset();
	
	QString txt;
	QDocument *d = e->document();
	const int cursorLine = e->cursor().lineNumber();
	
	n = d->lineNumber(contentsY);
	posY = as + 2 + d->y(n) - contentsY;
	
	//qDebug("first = %i; last = %i", first, last);
	//qDebug("beg pos : %i", posY);
	
	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;
		
		bool draw = true;
		
		if ( !m_verbose )
		{
			draw = !((n + 1) % 10) || !n || line.marks().count();
		}
		
		txt = QString::number(n + 1);
		
		if ( n == cursorLine )
		{
			draw = true;
			
			p->save();
			QFont f = p->font();
			f.setWeight(QFont::Bold);
			
			p->setFont(f);
		}
		
		if ( draw )
		{
			p->drawText(width() - 2 - sfm.width(txt),
						posY,
						txt);
			
		} else {
			int yOff = posY - (as + 1) + ls / 2;
			
			if ( (n + 1) % 5 )
				p->drawPoint(width() - 5, yOff);
			else
				p->drawLine(width() - 7, yOff, width() - 2, yOff);
		}
		
		if ( line.lineSpan() > 1 )
		{
			#ifdef Q_OS_WIN32
			p->save();
			specialFont.setBold(n == cursorLine); //todo: only get bold on the current wrapped line
			p->setFont(specialFont);
			#endif

			for ( int i = 1; i < line.lineSpan(); ++i )
			{
				// draw line wrapping indicators
				//p->drawText(width() - 2 - sfm.width(wrappingArrow), posY + i * ls, wrappingArrow);
				p->drawText(width() - 1 - specialSfm.width(wrappingArrow), posY + i * ls, wrappingArrow);
			}
			
			#ifdef Q_OS_WIN32
			p->restore();
			#endif
		}
		
		if ( n == cursorLine )
		{
			p->restore();
		}
		
		posY += ls * line.lineSpan();
	}
	
	//p->setPen(Qt::DotLine);
	//p->drawLine(width()-1, 0, width()-1, pageBottom);
	
	//setFixedWidth(sfm.width(txt) + 5);
	return true;
}