-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtextedit.cpp
51 lines (41 loc) · 1.17 KB
/
textedit.cpp
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
#include "textedit.h"
TextEdit::TextEdit(QWidget *parent) :
QTextEdit(parent)
{
defaultFormat.setForeground(QBrush::QBrush(Qt::black));
setAcceptRichText(false);
}
void TextEdit::setColors(QStringList colorList)
{
colors = colorList;
}
void TextEdit::exactMatch(QRegExp *regExp, QString *result)
{
if(regExp->exactMatch(toPlainText()))
*result = "true";
else
*result = "false";
int captureCount = regExp->captureCount();
blockSignals(true);
QTextCursor tempCursor = textCursor();
selectAll();
setTextColor(QColor("black")); // reset formating
moveCursor(QTextCursor::Start, QTextCursor::MoveAnchor);
QString cap;
for(int i=0; i < captureCount && i < colors.length(); i++)
{
cap = regExp->cap(i+1);
if(find(cap))
{
setTextColor(QColor(colors.at(i)));
}
}
blockSignals(false);
setTextCursor(tempCursor);
}
void TextEdit::keyPressEvent(QKeyEvent *e)
{
if(e->key() > Qt::Key_QuoteDbl && e->key() < Qt::Key_AsciiTilde)
setCurrentCharFormat(defaultFormat);
QTextEdit::keyPressEvent(e);
}