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 #include <QIcon>
29 #include <QMenu>
30 #include <QPainter>
31 #include <QScrollBar>
32 #include <QContextMenuEvent>
33 
34 /*!
35 	\ingroup widgets
36 	@{
37 */
38 
39 /*!
40 	\class QLineMarkPanel
41 	\brief A specific panel in charge of drawing line numbers of an editor
42 
43 	\see QEditorInterface
44 */
45 
QCE_AUTO_REGISTER(QLineChangePanel)46 QCE_AUTO_REGISTER(QLineChangePanel)
47 
48 /*!
49 	\brief Constructor
50 */
51 QLineChangePanel::QLineChangePanel(QWidget *p)
52  : QPanel(p)
53 {
54 	setFixedWidth(4);
55 }
56 
57 /*!
58 	\brief Empty destructor
59 */
~QLineChangePanel()60 QLineChangePanel::~QLineChangePanel()
61 {
62 
63 }
64 
65 /*!
66 
67 */
type() const68 QString QLineChangePanel::type() const
69 {
70 	return "Line changes";
71 }
72 
73 /*!
74 	\internal
75 */
paint(QPainter * p,QEditor * e)76 bool QLineChangePanel::paint(QPainter *p, QEditor *e)
77 {
78 	if ( !e || !e->document() )
79 		return true;
80 
81 	const QFontMetrics fm( e->document()->font() );
82 
83 	int n, posY,
84 		as = fm.ascent(),
85 		ls = fm.lineSpacing(),
86 		pageBottom = e->viewport()->height(),
87 		contentsY = e->verticalOffset();
88 
89 	QString txt;
90 
91 	QDocument *d = e->document();
92 	n = d->lineNumber(contentsY);
93 	posY = 2 + d->y(n) - contentsY;
94 
95 	for ( ; ; ++n )
96 	{
97 		//qDebug("n = %i; pos = %i", n, posY);
98 		QDocumentLine line = d->line(n);
99 
100 		if ( line.isNull() || ((posY - as) > pageBottom) )
101 			break;
102 
103 		if ( line.isHidden() )
104 			continue;
105 
106 		int span = line.lineSpan();
107 
108 		if ( d->isLineModified(line) )
109 		{
110 			p->fillRect(1, posY, 2, ls * span, Qt::red);
111 		} else if ( d->hasLineEverBeenModified(line) ) {
112 			p->fillRect(1, posY, 2, ls * span, Qt::green);
113 		}
114 
115 		posY += ls * span;
116 	}
117 
118 	return true;
119 }
120 
121 /*! @} */
122