| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <QTextCharFormat> |
| |
|
| |
|
| | #include "AbaqusHighlighter.h" |
| |
|
| |
|
| | using namespace FemGui; |
| |
|
| | |
| | |
| | |
| | AbaqusHighlighter::AbaqusHighlighter(QObject* parent) |
| | : SyntaxHighlighter(parent) |
| | {} |
| |
|
| | |
| | AbaqusHighlighter::~AbaqusHighlighter() = default; |
| |
|
| | void AbaqusHighlighter::highlightBlock(const QString& text) |
| | { |
| | |
| | |
| | |
| | enum |
| | { |
| | NormalState = -1, |
| | Definition, |
| | BeforeKey, |
| | InideKey, |
| | BeforeValue, |
| | InsideValue, |
| | Text, |
| | Number |
| | }; |
| |
|
| | int state = NormalState; |
| | int start = 0; |
| |
|
| | QColor keywordColor(102, 0, 227); |
| | QColor defnameColor(0, 119, 255); |
| | QColor operateColor(153, 0, 102); |
| | QColor valueColor(0, 0, 0); |
| | QColor numberColor(0, 127, 127); |
| | QColor commentColor = this->colorByType(SyntaxHighlighter::Comment); |
| |
|
| | for (int i = 0; i < text.length(); ++i) { |
| | |
| | if (text[i] == QLatin1Char(',') || text[i] == QLatin1Char('=')) { |
| | setFormat(i, 1, operateColor); |
| | } |
| |
|
| | if (state == Definition) { |
| | if (!text[i].isLetterOrNumber() && !text[i].isSpace()) { |
| | QTextCharFormat keywordFormat; |
| | keywordFormat.setForeground(keywordColor); |
| | keywordFormat.setFontWeight(QFont::Bold); |
| | setFormat(start, i - start, keywordFormat); |
| |
|
| | start = i; |
| | state = BeforeKey; |
| | } |
| | } |
| | else if (state == BeforeKey) { |
| | if (text[i].isLetterOrNumber()) { |
| | start = i; |
| | state = InideKey; |
| | } |
| | } |
| | else if (state == InideKey) { |
| | if (!text[i].isLetterOrNumber() && !text[i].isSpace()) { |
| | QTextCharFormat keyFormat; |
| | keyFormat.setForeground(defnameColor); |
| | setFormat(start, i - start, keyFormat); |
| |
|
| | start = i; |
| | state = BeforeValue; |
| | } |
| | } |
| | else if (state == BeforeValue) { |
| | if (text[i].isLetterOrNumber()) { |
| | start = i; |
| | state = InsideValue; |
| | } |
| | } |
| | else if (state == InsideValue) { |
| | if (!text[i].isLetterOrNumber() && !text[i].isSpace()) { |
| | QTextCharFormat valueFormat; |
| | valueFormat.setForeground(valueColor); |
| | setFormat(start, i - start, valueFormat); |
| |
|
| | start = i; |
| | state = BeforeKey; |
| | } |
| | } |
| | |
| | else if (state == Number) { |
| | if (!text[i].isNumber() && text[i] != QLatin1Char('.')) { |
| | QTextCharFormat numberFormat; |
| | numberFormat.setForeground(numberColor); |
| | setFormat(start, i - start, numberFormat); |
| |
|
| | start = i; |
| | state = NormalState; |
| | } |
| | } |
| | else if (text[i].isNumber() || text[i] == QLatin1Char('-')) { |
| | if (state == NormalState) { |
| | start = i; |
| | state = Number; |
| | } |
| | } |
| | |
| | else if (text.mid(i, 2) == QLatin1String("**")) { |
| | QTextCharFormat commentFormat; |
| | commentFormat.setForeground(commentColor); |
| | commentFormat.setFontItalic(true); |
| | setFormat(i, text.length() - i, commentFormat); |
| | break; |
| | } |
| | |
| | else if (text[i] == QLatin1Char('*')) { |
| | start = i; |
| | state = Definition; |
| | } |
| | else if (text[i].isLetterOrNumber()) { |
| | if (state == NormalState) { |
| | start = i; |
| | state = Text; |
| | } |
| | } |
| | else { |
| | state = NormalState; |
| | } |
| | } |
| |
|
| | if (state == Definition) { |
| | QTextCharFormat keywordFormat; |
| | keywordFormat.setForeground(keywordColor); |
| | keywordFormat.setFontWeight(QFont::Bold); |
| | setFormat(start, text.length() - start, keywordFormat); |
| | } |
| | else if (state == InideKey) { |
| | QTextCharFormat keyFormat; |
| | keyFormat.setForeground(defnameColor); |
| | setFormat(start, text.length() - start, keyFormat); |
| | } |
| | else if (state == InsideValue) { |
| | QTextCharFormat valueFormat; |
| | valueFormat.setForeground(valueColor); |
| | setFormat(start, text.length() - start, valueFormat); |
| | } |
| | else if (state == Number) { |
| | QTextCharFormat numberFormat; |
| | numberFormat.setForeground(numberColor); |
| | setFormat(start, text.length() - start, numberFormat); |
| | } |
| | } |
| |
|