-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathExpressTextEdit.cpp
119 lines (103 loc) · 3.64 KB
/
ExpressTextEdit.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
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
/* This file is part of SCView, a STEP-Express viewer based on StepCode
Copyright (C) 2012 Laurent Bauer lahoraent@hotmail.com
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; version 2
of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "ExpressTextEdit.h"
#include "ExpressSyntaxHighlighter.h"
#include <Registry.h>
#include <ExpDict.h>
#include <QMouseEvent>
#include <QApplication>
ExpressTextEdit::ExpressTextEdit(Registry ®istry, QWidget *parent)
: QTextEdit(parent)
, m_Registry(registry)
, m_Highlighter ( new ExpressSyntaxHighlighter(this->document()))
{
setMouseTracking(true);
}
void ExpressTextEdit::fillHighlighterWithTypes(const QStringList &list)
{
m_Highlighter->fillTypes(list);
}
void ExpressTextEdit::fillHighlighterWithEntities(const QStringList &list)
{
m_Highlighter->fillEntities(list);
}
void ExpressTextEdit::mouseMoveEvent(QMouseEvent *e)
{
QTextCursor cursor = cursorForPosition(e->pos());
cursor.select(QTextCursor::WordUnderCursor);
QString wordUnderCursor = cursor.selectedText();
const EntityDescriptor * entityDescriptor = m_Registry.FindEntity(wordUnderCursor.toAscii());
const TypeDescriptor * typeDescriptor = m_Registry.FindType(wordUnderCursor.toAscii());
if (entityDescriptor )
{
std::string str;
setToolTip(entityDescriptor->GenerateExpress(str));
if (QApplication::overrideCursor()==0)
QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
}
else if(typeDescriptor)
{
std::string str;
setToolTip(typeDescriptor->GenerateExpress(str));
if (QApplication::overrideCursor()==0)
QApplication::setOverrideCursor(QCursor(Qt::PointingHandCursor));
}
else
{
setToolTip(QString());
QApplication::restoreOverrideCursor();
}
}
void ExpressTextEdit::mousePressEvent(QMouseEvent *e)
{
if (e->modifiers()==Qt::ControlModifier)
{
QTextEdit::mousePressEvent(e);
navigate(e);
}
}
void ExpressTextEdit::mouseDoubleClickEvent(QMouseEvent *e)
{
navigate(e);
QTextEdit::mouseDoubleClickEvent(e);
}
void ExpressTextEdit::leaveEvent(QEvent *e)
{
QApplication::restoreOverrideCursor();
}
void ExpressTextEdit::setDescriptor(const TypeDescriptor *typeDescriptor)
{
clear();
if (typeDescriptor)
{
std::string str;
QString text(typeDescriptor->GenerateExpress(str));
setPlainText(text);
}
}
void ExpressTextEdit::navigate(QMouseEvent *e)
{
// QTextCursor cursor = textCursor();
QTextCursor cursor = cursorForPosition(e->pos());
cursor.select(QTextCursor::WordUnderCursor);
QString wordUnderCursor = cursor.selectedText();
const EntityDescriptor * entityDescriptor = m_Registry.FindEntity(wordUnderCursor.toAscii());
const TypeDescriptor * typeDescriptor = m_Registry.FindType(wordUnderCursor.toAscii());
if (entityDescriptor )
emit descriptorDoubleClicked(entityDescriptor);
else if(typeDescriptor)
emit descriptorDoubleClicked(typeDescriptor);
}