-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourcePlainText.cpp
More file actions
54 lines (44 loc) · 1.41 KB
/
SourcePlainText.cpp
File metadata and controls
54 lines (44 loc) · 1.41 KB
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
/*
Written By Pradipna Nepal
www.pradsprojects.com
Copyright (C) 2013 Pradipna Nepal
Please read COPYING.txt included along with this source code for more detail.
If not included, see http://www.gnu.org/licenses/
*/
#include "SourcePlainText.h"
#include "FrmFindAndReplace.h"
SourcePlainText::SourcePlainText(QWidget *parent = 0) : QPlainTextEdit(parent) {
findAndReplaceDialog = new FrmFindAndReplace(this);
findAndReplaceDialog->setModal(false);
}
SourcePlainText::~SourcePlainText() {
delete findAndReplaceDialog;
}
void SourcePlainText::returnKeyIdent() {
QTextCursor cursor = this->textCursor();
int position = cursor.position();
QString sourceCode = this->toPlainText();
QString upper = sourceCode.mid(0, position), tabs = "";
int lineStart;
for (lineStart = position - 2; lineStart >= 0; --lineStart) {
if (sourceCode[lineStart] == '\n') {
++lineStart;
break;
}
}
if (lineStart > 0) {
while(sourceCode[lineStart++] == '\t') {
tabs.push_back('\t');
}
}
this->insertPlainText(tabs);
}
void SourcePlainText::keyPressEvent(QKeyEvent *event) {
QPlainTextEdit::keyPressEvent(event);
if (event->key() == Qt::Key_Return) {
returnKeyIdent();
}
}
void SourcePlainText::findAndReplace() {
findAndReplaceDialog->show();
}