|
|
@ -11,6 +11,8 @@ |
|
|
|
#include <QRegularExpressionMatch> |
|
|
|
#include <QRegularExpressionMatch> |
|
|
|
#include <cassert> |
|
|
|
#include <cassert> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
|
|
class Highlighter: public QSyntaxHighlighter { |
|
|
|
class Highlighter: public QSyntaxHighlighter { |
|
|
|
Q_OBJECT; |
|
|
|
Q_OBJECT; |
|
|
|
Q_SIGNALS: |
|
|
|
Q_SIGNALS: |
|
|
@ -29,8 +31,10 @@ class Highlighter: public QSyntaxHighlighter { |
|
|
|
QTextCharFormat fmt; |
|
|
|
QTextCharFormat fmt; |
|
|
|
if (QFile(m.captured(1)).exists()) { |
|
|
|
if (QFile(m.captured(1)).exists()) { |
|
|
|
fmt.setForeground(Qt::darkGreen); |
|
|
|
fmt.setForeground(Qt::darkGreen); |
|
|
|
|
|
|
|
fmt.setFontWeight(QFont::Bold); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.setForeground(Qt::darkRed); |
|
|
|
fmt.setForeground(Qt::darkRed); |
|
|
|
|
|
|
|
fmt.setFontStrikeOut(true); |
|
|
|
} |
|
|
|
} |
|
|
|
setFormat(m.capturedStart(1), m.capturedLength(1), fmt); |
|
|
|
setFormat(m.capturedStart(1), m.capturedLength(1), fmt); |
|
|
|
include(m.captured(1)); |
|
|
|
include(m.captured(1)); |
|
|
@ -47,6 +51,7 @@ class Highlighter: public QSyntaxHighlighter { |
|
|
|
Expression(QString s): re(s) {} |
|
|
|
Expression(QString s): re(s) {} |
|
|
|
Expression(QString s, QTextCharFormat f): re(s), fmt(f) {} |
|
|
|
Expression(QString s, QTextCharFormat f): re(s), fmt(f) {} |
|
|
|
Expression& weight(int w) {fmt.setFontWeight(w); return *this;} |
|
|
|
Expression& weight(int w) {fmt.setFontWeight(w); return *this;} |
|
|
|
|
|
|
|
Expression& strike(bool s=true) {fmt.setFontStrikeOut(s); return *this;} |
|
|
|
Expression& fg(const QBrush& b) {fmt.setForeground(b); return *this;} |
|
|
|
Expression& fg(const QBrush& b) {fmt.setForeground(b); return *this;} |
|
|
|
QRegularExpression re; |
|
|
|
QRegularExpression re; |
|
|
|
QTextCharFormat fmt; |
|
|
|
QTextCharFormat fmt; |
|
|
@ -70,6 +75,7 @@ class CodeEditor: public QPlainTextEdit { |
|
|
|
Q_OBJECT; |
|
|
|
Q_OBJECT; |
|
|
|
Q_SIGNALS: |
|
|
|
Q_SIGNALS: |
|
|
|
void include(QString); |
|
|
|
void include(QString); |
|
|
|
|
|
|
|
void link(QString); |
|
|
|
public: |
|
|
|
public: |
|
|
|
CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) { |
|
|
|
CodeEditor(QWidget *parent = 0): QPlainTextEdit(parent) { |
|
|
|
Highlighter *highlighter(new Highlighter(document())); |
|
|
|
Highlighter *highlighter(new Highlighter(document())); |
|
|
@ -111,6 +117,23 @@ class CodeEditor: public QPlainTextEdit { |
|
|
|
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; |
|
|
|
int space = 3 + fontMetrics().width(QLatin1Char('9')) * digits; |
|
|
|
return space; |
|
|
|
return space; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void mousePressEvent(QMouseEvent *e) { |
|
|
|
|
|
|
|
clickedAnchor = (e->button() & Qt::LeftButton) |
|
|
|
|
|
|
|
? document()->findBlock(cursorForPosition(e->pos()).position()).text() |
|
|
|
|
|
|
|
: QString(); |
|
|
|
|
|
|
|
QPlainTextEdit::mousePressEvent(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e) { |
|
|
|
|
|
|
|
if (e->button() & Qt::LeftButton && !clickedAnchor.isEmpty() |
|
|
|
|
|
|
|
&& document()->findBlock(cursorForPosition(e->pos()).position()).text() == clickedAnchor) { |
|
|
|
|
|
|
|
static QRegularExpression inc("^ *include +([^ ].*.\\.wt)"); |
|
|
|
|
|
|
|
QRegularExpressionMatch m(inc.match(clickedAnchor)); |
|
|
|
|
|
|
|
if (m.hasMatch() && QFile(m.captured(1)).exists()) { |
|
|
|
|
|
|
|
link(m.captured(1)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QPlainTextEdit::mouseReleaseEvent(e); |
|
|
|
|
|
|
|
} |
|
|
|
protected: |
|
|
|
protected: |
|
|
|
void resizeEvent(QResizeEvent *e) override { |
|
|
|
void resizeEvent(QResizeEvent *e) override { |
|
|
|
QPlainTextEdit::resizeEvent(e); |
|
|
|
QPlainTextEdit::resizeEvent(e); |
|
|
@ -144,6 +167,7 @@ class CodeEditor: public QPlainTextEdit { |
|
|
|
} |
|
|
|
} |
|
|
|
private: |
|
|
|
private: |
|
|
|
QWidget *lineNumberArea; |
|
|
|
QWidget *lineNumberArea; |
|
|
|
|
|
|
|
QString clickedAnchor; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
inline LineNumberArea::LineNumberArea(CodeEditor *editor): QWidget(editor) { |
|
|
|
inline LineNumberArea::LineNumberArea(CodeEditor *editor): QWidget(editor) { |
|
|
|