1 /****************************************************************************
2 **
3 ** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
4 **
5 ** This file is part of the Edyuk project <http://edyuk.org>
6 **
7 ** This file may be used under the terms of the GNU General Public License
8 ** version 3 as published by the Free Software Foundation and appearing in the
9 ** file GPL.txt included in the packaging of this file.
10 **
11 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 **
14 ****************************************************************************/
15 
16 #include "qlinechangepanel.h"
17 
18 /*!
19 	\file qlinechangepanel.cpp
20 	\brief Implementation of the QLineChangePanel class.
21 */
22 
23 #include "qeditor.h"
24 
25 #include "qdocument.h"
26 #include "qdocumentline.h"
27 
28 /*!
29 	\ingroup widgets
30 	@{
31 */
32 
33 /*!
34 	\class QLineMarkPanel
35 	\brief A specific panel in charge of drawing line numbers of an editor
36 
37 	\see QEditorInterface
38 */
39 
QCE_AUTO_REGISTER(QLineChangePanel)40 QCE_AUTO_REGISTER(QLineChangePanel)
41 
42 /*!
43 	\brief Constructor
44 */
45 QLineChangePanel::QLineChangePanel(QWidget *p)
46  : QPanel(p)
47 {
48 	setFixedWidth(4);
49 	setObjectName("lineChangePanel");
50 }
51 
52 /*!
53 	\brief Empty destructor
54 */
~QLineChangePanel()55 QLineChangePanel::~QLineChangePanel()
56 {
57 
58 }
59 
60 /*!
61 
62 */
type() const63 QString QLineChangePanel::type() const
64 {
65 	return "Line changes";
66 }
67 
68 /*!
69 	\internal
70 */
paint(QPainter * p,QEditor * e)71 bool QLineChangePanel::paint(QPainter *p, QEditor *e)
72 {
73 	if ( !e || !e->document() )
74 		return true;
75 
76     int n;
77     qreal posY,
78         as = QFontMetricsF(e->document()->font()).ascent(),
79 		ls = e->document()->getLineSpacing(),
80 		pageBottom = e->viewport()->height(),
81 		contentsY = e->verticalOffset();
82 
83 	QDocument *d = e->document();
84 	n = d->lineNumber(contentsY);
85     posY = d->y(n) - contentsY;
86 
87 	for ( ; ; ++n )
88 	{
89 		//qDebug("n = %i; pos = %i", n, posY);
90 		QDocumentLine line = d->line(n);
91 
92 		if ( line.isNull() || ((posY - as) > pageBottom) )
93 			break;
94 
95 		if ( line.isHidden() )
96 			continue;
97 
98 		int span = line.lineSpan();
99 
100 		if ( d->isLineModified(line) )
101 		{
102             p->fillRect(QRectF(1, posY, 2, ls * span), QColor(255, 216, 0)); // yellow
103 		} else if ( d->hasLineEverBeenModified(line) ) {
104             p->fillRect(QRectF(1, posY, 2, ls * span), QColor(70, 191, 0)); // green
105 		}
106 
107 		posY += ls * span;
108 	}
109 
110 	return true;
111 }
112 
113 /*! @} */
114