2014-06-07 19:22:14 +04:00
|
|
|
#include <iostream>
|
2014-06-07 17:29:40 +04:00
|
|
|
#include <QString>
|
|
|
|
#include <QChar>
|
2014-06-11 14:29:05 +04:00
|
|
|
#include <Qsci/qscilexercpp.h>
|
2014-06-07 19:19:38 +04:00
|
|
|
#include "scintillaeditor.h"
|
2014-06-12 12:01:28 +04:00
|
|
|
#include "parsersettings.h"
|
2014-06-07 19:19:38 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
ScintillaEditor::ScintillaEditor(QWidget *parent) : EditorInterface(parent)
|
2014-06-07 19:19:38 +04:00
|
|
|
{
|
2014-06-07 19:22:14 +04:00
|
|
|
scintillaLayout = new QVBoxLayout(this);
|
|
|
|
qsci = new QsciScintilla(this);
|
2014-06-13 04:40:47 +04:00
|
|
|
scintillaLayout->setContentsMargins(0, 0, 0, 0);
|
2014-06-07 19:22:14 +04:00
|
|
|
scintillaLayout->addWidget(qsci);
|
2014-06-11 14:29:05 +04:00
|
|
|
qsci->setBraceMatching (QsciScintilla::SloppyBraceMatch);
|
|
|
|
qsci->setWrapMode(QsciScintilla::WrapWord);
|
2014-06-12 12:01:28 +04:00
|
|
|
qsci->setWrapVisualFlags(QsciScintilla::WrapFlagByText, QsciScintilla::WrapFlagByText, 0);
|
|
|
|
qsci->setAutoIndent(true);
|
2014-06-12 18:56:18 +04:00
|
|
|
qsci->indicatorDefine(QsciScintilla::RoundBoxIndicator, indicatorNumber);
|
|
|
|
qsci->markerDefine(QsciScintilla::Circle, markerNumber);
|
|
|
|
qsci->setMarkerBackgroundColor(QColor(255, 0, 0, 100), markerNumber);
|
2014-06-11 14:29:05 +04:00
|
|
|
initFont();
|
|
|
|
initMargin();
|
|
|
|
initLexer();
|
|
|
|
|
2014-06-07 19:19:38 +04:00
|
|
|
}
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::indentSelection()
|
|
|
|
{
|
2014-06-12 12:01:28 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
}
|
|
|
|
void ScintillaEditor::unindentSelection()
|
2014-06-07 17:29:40 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::commentSelection()
|
2014-06-11 14:29:05 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::uncommentSelection()
|
2014-06-11 14:29:05 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::setPlainText(const QString &text)
|
2014-06-07 17:29:40 +04:00
|
|
|
{
|
|
|
|
qsci->setText(text);
|
|
|
|
}
|
2014-06-13 04:40:47 +04:00
|
|
|
|
2014-06-07 17:29:40 +04:00
|
|
|
QString ScintillaEditor::toPlainText()
|
|
|
|
{
|
|
|
|
return qsci->text();
|
|
|
|
}
|
2014-06-13 04:40:47 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::highlightError(int error_pos)
|
2014-06-11 14:29:05 +04:00
|
|
|
{
|
2014-06-12 12:01:28 +04:00
|
|
|
int line, index;
|
|
|
|
qsci->lineIndexFromPosition(error_pos, &line, &index);
|
2014-06-12 18:56:18 +04:00
|
|
|
qsci->fillIndicatorRange(line, index, line, index+1, indicatorNumber);
|
2014-06-12 12:01:28 +04:00
|
|
|
qsci->setIndicatorForegroundColor(QColor(255,0,0,100));
|
2014-06-12 18:56:18 +04:00
|
|
|
qsci->markerAdd(line, markerNumber);
|
2014-06-11 14:29:05 +04:00
|
|
|
}
|
2014-06-13 04:40:47 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::unhighlightLastError()
|
2014-06-11 14:29:05 +04:00
|
|
|
{
|
2014-06-12 18:56:18 +04:00
|
|
|
int totalLength = qsci->text().length();
|
2014-06-12 12:01:28 +04:00
|
|
|
int line, index;
|
2014-06-12 18:56:18 +04:00
|
|
|
qsci->lineIndexFromPosition(totalLength, &line, &index);
|
|
|
|
qsci->clearIndicatorRange(0, 0, line, index, indicatorNumber);
|
|
|
|
qsci->markerDeleteAll(markerNumber);
|
2014-06-11 14:29:05 +04:00
|
|
|
}
|
2014-06-13 04:40:47 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::setHighlightScheme(const QString &name)
|
2014-06-11 14:29:05 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-06-13 04:40:47 +04:00
|
|
|
|
2014-06-07 19:22:14 +04:00
|
|
|
void ScintillaEditor::insertPlainText(const QString &text)
|
2014-06-07 17:29:40 +04:00
|
|
|
{
|
|
|
|
qsci->setText(text);
|
|
|
|
}
|
2014-06-07 19:22:14 +04:00
|
|
|
|
|
|
|
void ScintillaEditor::undo()
|
|
|
|
{
|
|
|
|
qsci->undo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::redo()
|
|
|
|
{
|
|
|
|
qsci->redo();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::cut()
|
|
|
|
{
|
|
|
|
qsci->cut();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::copy()
|
|
|
|
{
|
|
|
|
qsci->copy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::paste()
|
|
|
|
{
|
|
|
|
qsci->paste();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::zoomIn()
|
|
|
|
{
|
|
|
|
qsci->zoomIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::zoomOut()
|
|
|
|
{
|
|
|
|
qsci->zoomOut();
|
|
|
|
}
|
|
|
|
|
2014-06-11 14:29:05 +04:00
|
|
|
void ScintillaEditor::initFont()
|
|
|
|
{
|
|
|
|
QFont font("Courier", 12);
|
|
|
|
font.setFixedPitch(true);
|
|
|
|
qsci->setFont(font);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::initMargin()
|
|
|
|
{
|
|
|
|
QFontMetrics fontmetrics = QFontMetrics(qsci->font());
|
|
|
|
qsci->setMarginsFont(qsci->font());
|
|
|
|
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6);
|
|
|
|
qsci->setMarginLineNumbers(0, true);
|
|
|
|
qsci->setMarginsBackgroundColor(QColor("#cccccc"));
|
|
|
|
|
|
|
|
connect(qsci, SIGNAL(textChanged()), this, SLOT(onTextChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::onTextChanged()
|
|
|
|
{
|
|
|
|
QFontMetrics fontmetrics = qsci->fontMetrics();
|
|
|
|
qsci->setMarginWidth(0, fontmetrics.width(QString::number(qsci->lines())) + 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScintillaEditor::initLexer()
|
|
|
|
{
|
|
|
|
QsciLexerCPP *lexer = new QsciLexerCPP();
|
|
|
|
lexer->setDefaultFont(qsci->font());
|
|
|
|
lexer->setFoldComments(true);
|
|
|
|
qsci->setLexer(lexer);
|
|
|
|
}
|