File: qgotolinepanel.cpp

package info (click to toggle)
texstudio 2.8.4%2Bdebian-3
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 39,108 kB
  • ctags: 13,390
  • sloc: cpp: 84,770; xml: 10,109; ansic: 6,865; sh: 150; makefile: 82
file content (170 lines) | stat: -rw-r--r-- 3,659 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/****************************************************************************
**
** Copyright (C) 2006-2009 fullmetalcoder <fullmetalcoder@hotmail.fr>
**
** This file is part of the Edyuk project <http://edyuk.org>
** 
** This file may be used under the terms of the GNU General Public License
** version 3 as published by the Free Software Foundation and appearing in the
** file GPL.txt included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/

#include "qgotolinepanel.h"
#include "utilsSystem.h"

/*!
	\file qgotolinepanel.cpp
	\brief Implementation of the QGotoLinePanel class.
	
	\see QGotoLinePanel
*/

#include "qeditor.h"

#include "qdocument.h"
#include "qdocumentline.h"
#include "qdocumentcursor.h"

/*!
	\ingroup widgets
	@{
*/

/*!
	\class QGotoLinePanel
	\brief A panel that provide inline goto line functionalities
*/

QCE_AUTO_REGISTER(QGotoLinePanel)

/*!
	\brief Constructor
*/
QGotoLinePanel::QGotoLinePanel(QWidget *p)
 : QPanel(p)
{
	setupUi(this);
	setDefaultVisibility(false);
	
	setObjectName("gotoLinePanel");
	
    bClose->setIcon(getRealIconCached("fileclose"));
}

/*!
	\brief Empty destructor
*/
QGotoLinePanel::~QGotoLinePanel()
{
	
}

/*!

*/
QString QGotoLinePanel::type() const
{
	return "Goto";
}

/*!
	\brief 
*/
void QGotoLinePanel::editorChange(QEditor *e)
{
	if ( editor() )
	{
		disconnect(	editor(), SIGNAL( cursorPositionChanged() ),
					this	, SLOT  ( cursorPositionChanged() ) );
		
		disconnect(	editor()->document(), SIGNAL( lineCountChanged(int) ),
					this				, SLOT  ( lineCountChanged(int) ) );
	}
	
	if ( e )
	{
		connect(e	, SIGNAL( cursorPositionChanged() ),
				this, SLOT  ( cursorPositionChanged() ) );
		
		connect(e->document()	, SIGNAL( lineCountChanged(int) ),
				this			, SLOT  ( lineCountChanged(int) ) );
		
		lineCountChanged(e->document()->lineCount());
		spLine->setValue(e->cursor().lineNumber() + 1);
		slLine->setValue(e->cursor().lineNumber() + 1);
	}
}

bool QGotoLinePanel::forward(QMouseEvent *e)
{
	Q_UNUSED(e)
	
	/*
		This panel does not need mouse events to be forwarded to the editor.
		Even more, it requires them not to be forwarded...
	*/
	return false;
}

void QGotoLinePanel::showEvent(QShowEvent *e)
{
	Q_UNUSED(e)
	
	spLine->setFocus();
	spLine->selectAll();
}

void QGotoLinePanel::keyPressEvent(QKeyEvent *e)
{
	if ( e->key() == Qt::Key_Escape )
	{
		on_bClose_clicked();
	} else if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) {
		on_bGo_clicked();
		on_bClose_clicked();
	} else {
		QPanel::keyPressEvent(e);
	}
}

void QGotoLinePanel::on_bClose_clicked()
{
	hide();
	editor()->setFocus();
}

void QGotoLinePanel::on_bGo_clicked()
{
	editor()->setCursor(QDocumentCursor(editor()->document(), spLine->value() - 1), false);
	editor()->ensureCursorVisible(QEditor::Navigation);
}

void QGotoLinePanel::on_spLine_valueChanged(int v)
{
	if ( slLine->value() != v )
		slLine->setValue(v);
}

void QGotoLinePanel::on_slLine_valueChanged(int v)
{
	if ( spLine->value() != v )
		spLine->setValue(v);
}

void QGotoLinePanel::lineCountChanged(int n)
{
	spLine->setMaximum(n);
	slLine->setMaximum(n);
}

void QGotoLinePanel::cursorPositionChanged()
{
	spLine->setValue(editor()->cursor().lineNumber() + 1);
	slLine->setValue(editor()->cursor().lineNumber() + 1);
}

/*! @} */