* add QSynEdit
This commit is contained in:
parent
789e503e4d
commit
9e51cf2f06
|
@ -17,6 +17,11 @@ SOURCES += \
|
|||
editorlist.cpp \
|
||||
main.cpp \
|
||||
mainwindow.cpp \
|
||||
qsynedit/CodeFolding.cpp \
|
||||
qsynedit/Constants.cpp \
|
||||
qsynedit/MiscClasses.cpp \
|
||||
qsynedit/highlighter/base.cpp \
|
||||
qsynedit/highlighter/cpp.cpp \
|
||||
settingsdialog/compilersetdirectorieswidget.cpp \
|
||||
settingsdialog/compilersetoptionwidget.cpp \
|
||||
settings.cpp \
|
||||
|
@ -34,6 +39,11 @@ HEADERS += \
|
|||
editor.h \
|
||||
editorlist.h \
|
||||
mainwindow.h \
|
||||
qsynedit/CodeFolding.h \
|
||||
qsynedit/Constants.h \
|
||||
qsynedit/MiscClasses.h \
|
||||
qsynedit/highlighter/base.h \
|
||||
qsynedit/highlighter/cpp.h \
|
||||
settingsdialog/compilersetdirectorieswidget.h \
|
||||
settingsdialog/compilersetoptionwidget.h \
|
||||
settings.h \
|
||||
|
@ -61,9 +71,3 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
|
|||
RESOURCES += \
|
||||
icons.qrc
|
||||
|
||||
win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/release/ -lqscintilla2_qt5d
|
||||
else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../../QScintilla/src/debug/ -lqscintilla2_qt5d
|
||||
else:unix: LIBS += -L$$OUT_PWD/../../QScintilla/src/ -lqscintilla2_qt5d
|
||||
|
||||
INCLUDEPATH += $$PWD/../../QScintilla/src
|
||||
DEPENDPATH += $$PWD/../../QScintilla/src
|
||||
|
|
|
@ -60,7 +60,7 @@ QString Compiler::getFileNameFromOutputLine(QString &line) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (QFile(temp).fileName() == "ld.exe") { // skip ld.exe
|
||||
if (QFile(temp).fileName() == QLatin1String("ld.exe")) { // skip ld.exe
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
|
|
|
@ -65,7 +65,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
|||
lexer->setDefaultFont(QFont("Consolas",12));
|
||||
this->setLexer(lexer);
|
||||
this->setAutoIndent(pSettings->editor().autoIndent());
|
||||
this->setFolding(FoldStyle::BoxedTreeFoldStyle,3);
|
||||
this->setFolding(FoldStyle::BoxedTreeFoldStyle,FoldMargin);
|
||||
this->setTabWidth(4);
|
||||
|
||||
this->setCaretLineVisible(true);
|
||||
|
@ -75,34 +75,24 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
|||
|
||||
this->setBraceMatching(BraceMatch::SloppyBraceMatch);
|
||||
//行号显示区域
|
||||
setMarginType(0, QsciScintilla::NumberMargin);
|
||||
setMarginLineNumbers(0, true);
|
||||
setMarginWidth(0,"10");
|
||||
setMarginType(LineNumberMargin, QsciScintilla::NumberMargin);
|
||||
setMarginLineNumbers(LineNumberMargin, true);
|
||||
setMarginWidth(LineNumberMargin,10);
|
||||
this->onLinesChanged(0,0);
|
||||
//断点设置区域
|
||||
setMarginType(1, QsciScintilla::SymbolMargin);
|
||||
setMarginLineNumbers(1, false);
|
||||
setMarginWidth(1,20);
|
||||
setMarginSensitivity(1, true); //设置是否可以显示断点
|
||||
setMarginsBackgroundColor(QColor("#bbfaae"));
|
||||
setMarginMarkerMask(1, 0x02);
|
||||
setMarginType(MarkerMargin, QsciScintilla::SymbolMargin);
|
||||
setMarginLineNumbers(MarkerMargin, false);
|
||||
setMarginWidth(MarkerMargin,20);
|
||||
setMarginSensitivity(MarkerMargin, true); //set the margin as a selection margin, which is clickable
|
||||
|
||||
// connect(textEdit, SIGNAL(marginClicked(int, int, Qt::KeyboardModifiers)),this,
|
||||
// SLOT(on_margin_clicked(int, int, Qt::KeyboardModifiers)));
|
||||
markerDefine(QsciScintilla::Circle, 1);
|
||||
setMarkerBackgroundColor(QColor("#ee1111"), 1);
|
||||
//单步执行显示区域
|
||||
setMarginType(2, QsciScintilla::SymbolMargin);
|
||||
setMarginLineNumbers(2, false);
|
||||
setMarginWidth(2, 20);
|
||||
setMarginSensitivity(2, false);
|
||||
setMarginMarkerMask(2, 0x04);
|
||||
markerDefine(QsciScintilla::RightArrow, 2);
|
||||
setMarkerBackgroundColor(QColor("#eaf593"), 2);
|
||||
//自动折叠区域
|
||||
setMarginType(3, QsciScintilla::SymbolMargin);
|
||||
setMarginLineNumbers(3, false);
|
||||
setMarginWidth(3, 15);
|
||||
setMarginSensitivity(3, true);
|
||||
|
||||
//markers
|
||||
markerDefine(QsciScintilla::CircledPlus, ErrorMarker);
|
||||
setMarkerForegroundColor(QColor("BLACK"),ErrorMarker);
|
||||
setMarkerBackgroundColor(QColor("RED"),ErrorMarker);
|
||||
markerAdd(1,ErrorMarker);
|
||||
|
||||
// connect will fail if use new function pointer syntax
|
||||
// connect(this, &QsciScintilla::modificationChanged,
|
||||
|
@ -254,6 +244,7 @@ bool Editor::saveAs(){
|
|||
void Editor::activate()
|
||||
{
|
||||
this->mParentPageControl->setCurrentWidget(this);
|
||||
this->setFocus();
|
||||
}
|
||||
|
||||
const QByteArray& Editor::encodingOption() const noexcept{
|
||||
|
@ -296,6 +287,11 @@ void Editor::onModificationChanged(bool) {
|
|||
|
||||
void Editor::onCursorPositionChanged(int line, int index) {
|
||||
pMainWindow->updateStatusBarForEditingInfo(line,index+1,lines(),text().length());
|
||||
long pos = getCursorPosition();
|
||||
long start = SendScintilla(SCI_WORDSTARTPOSITION,pos,false);
|
||||
long end = SendScintilla(SCI_WORDENDPOSITION,pos,false);
|
||||
|
||||
qDebug()<<start<<end<<text(start,end);
|
||||
}
|
||||
|
||||
void Editor::onLinesChanged(int startLine, int count) {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <QObject>
|
||||
#include <utils.h>
|
||||
#include <QTabWidget>
|
||||
#include <Qsci/qsciscintilla.h>
|
||||
|
||||
class SaveException: public std::exception {
|
||||
|
||||
|
@ -23,6 +22,18 @@ class Editor : public QsciScintilla
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum MarginNumber {
|
||||
LineNumberMargin = 0,
|
||||
MarkerMargin = 1,
|
||||
FoldMargin = 2,
|
||||
};
|
||||
|
||||
enum MarkerNumber {
|
||||
BreakpointMarker,
|
||||
ErrorMarker,
|
||||
WarningMarker
|
||||
};
|
||||
|
||||
explicit Editor(QWidget *parent, const QString& filename,
|
||||
const QByteArray& encoding,
|
||||
bool inProject, bool isNew,QTabWidget* parentPageControl);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <QVariant>
|
||||
#include <mainwindow.h>
|
||||
#include <iconv.h>
|
||||
#include <QDebug>
|
||||
|
||||
EditorList::EditorList(QTabWidget* leftPageWidget,
|
||||
QTabWidget* rightPageWidget,
|
||||
|
@ -122,7 +123,7 @@ bool EditorList::closeAll(bool force) {
|
|||
return true;
|
||||
}
|
||||
|
||||
Editor* EditorList::findOpenedEditor(const QString &filename)
|
||||
Editor* EditorList::getOpenedEditorByFilename(const QString &filename)
|
||||
{
|
||||
for (int i=0;i<mLeftPageWidget->count();i++) {
|
||||
Editor* e = static_cast<Editor*>(mLeftPageWidget->widget(i));
|
||||
|
@ -138,3 +139,15 @@ Editor* EditorList::findOpenedEditor(const QString &filename)
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Editor *EditorList::getEditorByFilename(const QString &filename)
|
||||
{
|
||||
//check if an editor is already openned
|
||||
Editor* e=getOpenedEditorByFilename(filename);
|
||||
if (e!=nullptr)
|
||||
return e;
|
||||
//Todo: check if is in the project
|
||||
|
||||
//Create a new editor
|
||||
return newEditor(filename,ENCODING_AUTO_DETECT,false,false);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@ public:
|
|||
|
||||
bool closeAll(bool force = false);
|
||||
|
||||
Editor* findOpenedEditor(const QString& filename);
|
||||
Editor* getOpenedEditorByFilename(const QString& filename);
|
||||
|
||||
Editor* getEditorByFilename(const QString& filename);
|
||||
|
||||
void beginUpdate();
|
||||
void endUpdate();
|
||||
|
|
|
@ -86,7 +86,7 @@ void MainWindow::openFiles(const QStringList &files)
|
|||
|
||||
void MainWindow::openFile(const QString &filename)
|
||||
{
|
||||
Editor* editor = mEditorList->findOpenedEditor(filename);
|
||||
Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
|
||||
if (editor!=nullptr) {
|
||||
editor->activate();
|
||||
return;
|
||||
|
@ -294,3 +294,17 @@ void MainWindow::on_actionFoldAll_triggered()
|
|||
editor->foldAll();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_tableIssues_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
PCompileIssue issue = ui->tableIssues->issue(index);
|
||||
if (!issue)
|
||||
return;
|
||||
|
||||
Editor * editor = mEditorList->getEditorByFilename(issue->filename);
|
||||
if (editor == nullptr)
|
||||
return;
|
||||
|
||||
editor->setCursorPosition(issue->line-1,issue->column-1);
|
||||
editor->activate();
|
||||
}
|
||||
|
|
|
@ -70,6 +70,8 @@ private slots:
|
|||
|
||||
void on_actionFoldAll_triggered();
|
||||
|
||||
void on_tableIssues_doubleClicked(const QModelIndex &index);
|
||||
|
||||
public slots:
|
||||
void onCompileLog(const QString& msg);
|
||||
void onCompileIssue(PCompileIssue issue);
|
||||
|
|
|
@ -191,6 +191,9 @@
|
|||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
#include "CodeFolding.h"
|
||||
|
||||
int QSynFoldRegions::count()
|
||||
{
|
||||
return fRegions.size();
|
||||
}
|
||||
|
||||
int QSynFoldRegions::add(bool addEnding, const QChar &openSymbol, const QChar &closeSymbol, const QString &highlight)
|
||||
{
|
||||
PSynFoldRegion region = std::make_shared<QSynFoldRegion>();
|
||||
region->addEnding = addEnding;
|
||||
region->openSymbol = openSymbol;
|
||||
region->closeSymbol = closeSymbol;
|
||||
region->highlight = highlight;
|
||||
fRegions.push_back(region);
|
||||
}
|
||||
|
||||
PSynFoldRegion QSynFoldRegions::get(int index)
|
||||
{
|
||||
return fRegions.at(index);
|
||||
}
|
||||
|
||||
QSynCodeFolding::QSynCodeFolding():
|
||||
indentGuides(true),
|
||||
showCollapsedLine(true),
|
||||
collapsedLineColor(QColor("black")),
|
||||
folderBarLinesColor(QColor("black")),
|
||||
indentGuidesColor("gray")
|
||||
{
|
||||
foldRegions.add(true,'{','}',"Symbol");
|
||||
}
|
||||
|
||||
|
||||
bool QSynEditFoldRange::parentCollapsed()
|
||||
{
|
||||
PSynEditFoldRange parentFold = parent;
|
||||
// Find first parent that is collapsed
|
||||
while (parentFold) {
|
||||
if (parentFold->collapsed) {
|
||||
return true;
|
||||
}
|
||||
parentFold = parentFold->parent;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void QSynEditFoldRange::move(int count)
|
||||
{
|
||||
fromLine += count;
|
||||
toLine += count;
|
||||
}
|
||||
|
||||
QSynEditFoldRange::QSynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynFoldRegion aFoldRegion, int aToLine):
|
||||
fromLine(aFromLine),
|
||||
toLine(aToLine),
|
||||
linesCollapsed(0),
|
||||
collapsed(false),
|
||||
allFoldRanges(aAllFold),
|
||||
foldRegion(aFoldRegion),
|
||||
hintMarkLeft(0),
|
||||
parent(aParent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
PSynEditFoldRange QSynEditFoldRanges::foldRange(int index)
|
||||
{
|
||||
return ranges[index];
|
||||
}
|
||||
|
||||
int QSynEditFoldRanges::count()
|
||||
{
|
||||
return ranges.size();
|
||||
}
|
||||
|
||||
QSynEditFoldRanges::QSynEditFoldRanges()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PSynEditFoldRange QSynEditFoldRanges::addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynFoldRegion aFoldRegion, int aToLine)
|
||||
{
|
||||
PSynEditFoldRange range=std::make_shared<QSynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
|
||||
return range;
|
||||
}
|
||||
|
||||
int QSynEditFoldRanges::remove(int index)
|
||||
{
|
||||
ranges.erase(ranges.begin()+index);
|
||||
}
|
||||
|
||||
void QSynEditFoldRanges::addObject(PSynEditFoldRange foldRange)
|
||||
{
|
||||
ranges.push_back(foldRange);
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
#ifndef CODEFOLDING_H
|
||||
#define CODEFOLDING_H
|
||||
#include <QColor>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
struct QSynFoldRegion;
|
||||
typedef std::shared_ptr<QSynFoldRegion> PSynFoldRegion;
|
||||
|
||||
class QSynFoldRegions {
|
||||
private:
|
||||
std::vector<PSynFoldRegion> fRegions;
|
||||
public:
|
||||
int count();
|
||||
int add(bool addEnding, const QChar& openSymbol, const QChar& closeSymbol, const QString& highlight);
|
||||
PSynFoldRegion get(int index);
|
||||
};
|
||||
typedef std::shared_ptr<QSynFoldRegions> PSynFoldRegions;
|
||||
|
||||
|
||||
struct QSynFoldRegion {
|
||||
bool addEnding;
|
||||
QSynFoldRegions subFoldRegions;
|
||||
QChar openSymbol;
|
||||
QChar closeSymbol;
|
||||
QString highlight;
|
||||
};
|
||||
|
||||
struct QSynCodeFolding {
|
||||
bool indentGuides;
|
||||
bool showCollapsedLine;
|
||||
QColor collapsedLineColor;
|
||||
QColor folderBarLinesColor;
|
||||
QColor indentGuidesColor;
|
||||
QSynFoldRegions foldRegions;
|
||||
QSynCodeFolding();
|
||||
};
|
||||
|
||||
class QSynEditFoldRange;
|
||||
typedef std::shared_ptr<QSynEditFoldRange> PSynEditFoldRange;
|
||||
class QSynEditFoldRanges;
|
||||
typedef std::shared_ptr<QSynEditFoldRanges> PSynEditFoldRanges;
|
||||
|
||||
class QSynEditFoldRanges{
|
||||
public:
|
||||
std::vector<PSynEditFoldRange> ranges;
|
||||
PSynEditFoldRange foldRange(int index);
|
||||
int count();
|
||||
QSynEditFoldRanges();
|
||||
PSynEditFoldRange addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold,
|
||||
int aFromLine, PSynFoldRegion aFoldRegion, int aToLine);
|
||||
|
||||
int remove(int index);
|
||||
void addObject(PSynEditFoldRange foldRange);
|
||||
};
|
||||
|
||||
// A single fold
|
||||
class QSynEditFoldRange {
|
||||
public:
|
||||
int fromLine; // Beginning line
|
||||
int toLine; // End line
|
||||
int linesCollapsed; // Number of collapsed lines
|
||||
QSynEditFoldRanges subFoldRanges; // Sub fold ranges
|
||||
bool collapsed; // Is collapsed?
|
||||
PSynEditFoldRanges allFoldRanges;// TAllFoldRanges pointer
|
||||
PSynFoldRegion foldRegion; // FoldRegion
|
||||
int hintMarkLeft;
|
||||
PSynEditFoldRange parent;
|
||||
bool parentCollapsed();
|
||||
void move(int count);
|
||||
explicit QSynEditFoldRange(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold,
|
||||
int aFromLine, PSynFoldRegion aFoldRegion, int aToLine);
|
||||
};
|
||||
|
||||
#endif // CODEFOLDING_H
|
|
@ -0,0 +1,5 @@
|
|||
#include "Constants.h"
|
||||
const std::set<QChar> SynWordBreakChars{'.', ',', ';', ':',
|
||||
'"', '\'', '!', '?', '[', ']', '(', ')', '{', '}', '^', '-', '=', '+',
|
||||
'-', '*', '/', '\\', '|'};
|
||||
const QChar SynTabChar('\t');
|
|
@ -0,0 +1,160 @@
|
|||
#ifndef CONSTANTS_H
|
||||
#define CONSTANTS_H
|
||||
#include <set>
|
||||
#include <QChar>
|
||||
|
||||
extern const std::set<QChar> SynWordBreakChars;
|
||||
extern const QChar SynTabChar;
|
||||
|
||||
#define SYN_ATTR_COMMENT 0
|
||||
#define SYN_ATTR_IDENTIFIER 1
|
||||
#define SYN_ATTR_KEYWORD 2
|
||||
#define SYN_ATTR_STRING 3
|
||||
#define SYN_ATTR_WHITESPACE 4
|
||||
#define SYN_ATTR_SYMBOL 5
|
||||
|
||||
// names for highlighter attributes
|
||||
#define SYNS_AttrAreaAIdentifier "Area A Identifier"
|
||||
#define SYNS_AttrArrowHead "ArrowHead"
|
||||
#define SYNS_AttrAsm "Asm"
|
||||
#define SYNS_AttrAsmComment "Asm Comment"
|
||||
#define SYNS_AttrAsmKey "Asm Key"
|
||||
#define SYNS_AttrAssembler "Assembler"
|
||||
#define SYNS_AttrAttribute "Attribute"
|
||||
#define SYNS_AttrAttributeName "Attribute Name"
|
||||
#define SYNS_AttrAttributeValue "Attribute Value"
|
||||
#define SYNS_AttrBasicTypes "Basic Types"
|
||||
#define SYNS_AttrBlock "Block"
|
||||
#define SYNS_AttrBoolean "Boolean value"
|
||||
#define SYNS_AttrBrackets "Brackets"
|
||||
#define SYNS_AttrCDATASection "CDATA Section"
|
||||
#define SYNS_AttrCharacter "Character"
|
||||
#define SYNS_AttrClass "Class"
|
||||
#define SYNS_AttrColor "Color Value"
|
||||
#define SYNS_AttrComment "Comment"
|
||||
#define SYNS_AttrCondition "Condition"
|
||||
#define SYNS_AttrConditionalComment "Conditional Comment"
|
||||
#define SYNS_AttrDataType "Data Type"
|
||||
#define SYNS_AttrDebugLines "Debugging Lines"
|
||||
#define SYNS_AttrDefaultPackage "Default Packages"
|
||||
#define SYNS_AttrDelimitedIdentifier "Delimited Identifier"
|
||||
#define SYNS_AttrDir "Direction"
|
||||
#define SYNS_AttrDirections "Directions"
|
||||
#define SYNS_AttrDirective "Directive"
|
||||
#define SYNS_AttrDOCTYPESection "DOCTYPE Section"
|
||||
#define SYNS_AttrDocumentation "Documentation"
|
||||
#define SYNS_AttrElementName "Element Name"
|
||||
#define SYNS_AttrEmbedSQL "Embedded SQL"
|
||||
#define SYNS_AttrEmbedText "Embedded Text"
|
||||
#define SYNS_AttrEntityReference "Entity Reference"
|
||||
#define SYNS_AttrEscapeAmpersand "Escape Ampersand"
|
||||
#define SYNS_AttrEvent "Event"
|
||||
#define SYNS_AttrException "Exception"
|
||||
#define SYNS_AttrFirstTri "FirstTri"
|
||||
#define SYNS_AttrFloat "Float"
|
||||
#define SYNS_AttrForm "Form"
|
||||
#define SYNS_AttrFourthTri "FourthTri"
|
||||
#define SYNS_AttrFunction "Function"
|
||||
#define SYNS_AttrFunctionParameter "Function Parameter"
|
||||
#define SYNS_AttrGlobalVariable "Global variable"
|
||||
#define SYNS_AttrHexadecimal "Hexadecimal"
|
||||
#define SYNS_AttrIcon "Icon Reference"
|
||||
#define SYNS_AttrIdentifier "Identifier"
|
||||
#define SYNS_AttrIllegalChar "Illegal Char"
|
||||
#define SYNS_AttrInclude "Include"
|
||||
#define SYNS_AttrIndicator "Indicator Area"
|
||||
#define SYNS_AttrIndirect "Indirect"
|
||||
#define SYNS_AttrInvalidSymbol "Invalid Symbol"
|
||||
#define SYNS_AttrInternalFunction "Internal Function"
|
||||
#define SYNS_AttrKey "Key"
|
||||
#define SYNS_AttrLabel "Label"
|
||||
#define SYNS_AttrLace "Lace"
|
||||
#define SYNS_AttrLocalVariable "Local Variable"
|
||||
#define SYNS_AttrLine "Line"
|
||||
#define SYNS_AttrMacro "Macro"
|
||||
#define SYNS_AttrMarker "Marker"
|
||||
#define SYNS_AttrMathMode "Math Mode"
|
||||
#define SYNS_AttrMessage "Message"
|
||||
#define SYNS_AttrMiscellaneous "Miscellaneous"
|
||||
#define SYNS_AttrNamespaceAttrName "Namespace Attribute Name"
|
||||
#define SYNS_AttrNamespaceAttrValue "Namespace Attribute Value"
|
||||
#define SYNS_AttrNonReservedKeyword "Non-reserved Keyword"
|
||||
#define SYNS_AttrNull "Null"
|
||||
#define SYNS_AttrNumber "Number"
|
||||
#define SYNS_AttrOctal "Octal"
|
||||
#define SYNS_AttrOperator "Operator"
|
||||
#define SYNS_AttrOperatorAndSymbols "Operator And Symbols"
|
||||
#define SYNS_AttrOpLine "OpLine"
|
||||
#define SYNS_AttrPLSQL "PL/SQL Reserved Word"
|
||||
#define SYNS_AttrPragma "Pragma"
|
||||
#define SYNS_AttrPredefined "Predefined"
|
||||
#define SYNS_AttrPreprocessor "Preprocessor"
|
||||
#define SYNS_AttrProcessingInstr "Processing Instruction"
|
||||
#define SYNS_AttrQuad "Quad"
|
||||
#define SYNS_AttrQualifier "Qualifier"
|
||||
#define SYNS_AttrRegister "Register"
|
||||
#define SYNS_AttrReservedWord "Reserved Word"
|
||||
#define SYNS_AttrResultValue "Result Value"
|
||||
#define SYNS_AttrRoundBracket "Round Bracket"
|
||||
#define SYNS_AttrRpl "Rpl"
|
||||
#define SYNS_AttrRplKey "Rpl Key"
|
||||
#define SYNS_AttrRplComment "Rpl Comment"
|
||||
#define SYNS_AttrSASM "SASM"
|
||||
#define SYNS_AttrSASMComment "SASM Comment"
|
||||
#define SYNS_AttrSASMKey "SASM Key"
|
||||
#define SYNS_AttrSecondReservedWord "Second Reserved Word"
|
||||
#define SYNS_AttrSecondTri "SecondTri"
|
||||
#define SYNS_AttrSection "Section"
|
||||
#define SYNS_AttrSequence "Sequence Number Area"
|
||||
#define SYNS_AttrShape "Shape"
|
||||
#define SYNS_AttrSingleString "Single Quoted String"
|
||||
#define SYNS_AttrSpace "Space"
|
||||
#define SYNS_AttrSpecialVariable "Special Variable"
|
||||
#define SYNS_AttrSQLKey "SQL Keyword"
|
||||
#define SYNS_AttrSQLPlus "SQL*Plus Command"
|
||||
#define SYNS_AttrSquareBracket "Square Bracket"
|
||||
#define SYNS_AttrString "String"
|
||||
#define SYNS_AttrStringEscapeSequences "Escape sequences"
|
||||
#define SYNS_AttrSymbol "Symbol"
|
||||
#define SYNS_AttrSyntaxError "Syntax Error"
|
||||
#define SYNS_AttrSystem "System Functions and Variables"
|
||||
#define SYNS_AttrSystemValue "System Value"
|
||||
#define SYNS_AttrTagArea "Tag Area"
|
||||
#define SYNS_AttrTableName "Table Name"
|
||||
#define SYNS_AttrTerminator "Terminator"
|
||||
#define SYNS_AttrTeXCommand "TeX Command"
|
||||
#define SYNS_AttrText "Text"
|
||||
#define SYNS_AttrTextMathMode "Text in Math Mode"
|
||||
#define SYNS_AttrThirdTri "ThirdTri"
|
||||
#define SYNS_AttrTriangle "Triangle"
|
||||
#define SYNS_AttrUnknownWord "Unknown Word"
|
||||
#define SYNS_AttrURI "URI"
|
||||
#define SYNS_AttrUser "User Functions and Variables"
|
||||
#define SYNS_AttrUserFunction "User Functions"
|
||||
#define SYNS_AttrValue "Value"
|
||||
#define SYNS_AttrVariable "Variable"
|
||||
#define SYNS_AttrVisitedURI "Visited URI"
|
||||
#define SYNS_AttrVrmlAppearance "Vrml_Appearance"
|
||||
#define SYNS_AttrVrmlAttribute "Vrml_Attribute"
|
||||
#define SYNS_AttrVrmlDefinition "Vrml_Definition"
|
||||
#define SYNS_AttrVrmlEvent "Vrml_Event"
|
||||
#define SYNS_AttrVrmlGrouping "Vrml_Grouping"
|
||||
#define SYNS_AttrVrmlInterpolator "Vrml_Interpolator"
|
||||
#define SYNS_AttrVrmlLight "Vrml_Light"
|
||||
#define SYNS_AttrVrmlNode "Vrml_Node"
|
||||
#define SYNS_AttrVrmlParameter "Vrml_Parameter"
|
||||
#define SYNS_AttrVrmlProto "Vrml_Proto"
|
||||
#define SYNS_AttrVrmlSensor "Vrml_Sensor"
|
||||
#define SYNS_AttrVrmlShape "Vrml_Shape"
|
||||
#define SYNS_AttrVrmlShape_Hint "Vrml_Shape_Hint"
|
||||
#define SYNS_AttrVrmlTime_dependent "Vrml_Time_dependent"
|
||||
#define SYNS_AttrVrmlViewpoint "Vrml_Viewpoint"
|
||||
#define SYNS_AttrVrmlWorldInfo "Vrml_WorldInfo"
|
||||
#define SYNS_AttrWhitespace "Whitespace"
|
||||
#define SYNS_AttrX3DDocType "X3DDocType"
|
||||
#define SYNS_AttrX3DHeader "X3DHeader"
|
||||
// names of exporter output formats
|
||||
#define SYNS_ExporterFormatHTML "HTML"
|
||||
#define SYNS_ExporterFormatRTF "RTF"
|
||||
#define SYNS_ExporterFormatTeX "TeX"
|
||||
#endif // CONSTANTS_H
|
|
@ -0,0 +1,306 @@
|
|||
#include "MiscClasses.h"
|
||||
#include "algorithm"
|
||||
|
||||
SynGutter::SynGutter(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
mFont = QFont("Courier New",9);
|
||||
mColor= QColorConstants::Svg::lightgray;
|
||||
mBorderColor = QColorConstants::Transparent;
|
||||
mWidth = 30;
|
||||
mShowLineNumbers = true;
|
||||
mDigitCount = 4;
|
||||
mLeadingZeros = false;
|
||||
mLeftOffset = 16;
|
||||
mRightOffset = 2;
|
||||
mVisible = true;
|
||||
mUseFontStyle = false;
|
||||
mAutoSize = true;
|
||||
mAutoSizeDigitCount = mDigitCount;
|
||||
mBorderStyle = SynGutterBorderStyle::Middle;
|
||||
mLineNumberStart = 1;
|
||||
mGradient = false;
|
||||
mGradientStartColor = QColorConstants::Transparent;
|
||||
mGradientEndColor = QColorConstants::Transparent;
|
||||
mGradientSteps = 48;
|
||||
}
|
||||
|
||||
QFont SynGutter::font() const
|
||||
{
|
||||
return mFont;
|
||||
}
|
||||
|
||||
void SynGutter::setFont(const QFont &font)
|
||||
{
|
||||
if (mFont != font) {
|
||||
mFont = font;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::autoSize() const
|
||||
{
|
||||
return mAutoSize;
|
||||
}
|
||||
|
||||
void SynGutter::setAutoSize(bool value)
|
||||
{
|
||||
if (mAutoSize != value) {
|
||||
mAutoSize = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void SynGutter::setChanged()
|
||||
{
|
||||
emit changed();
|
||||
}
|
||||
|
||||
int SynGutter::width() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
void SynGutter::setWidth(int width)
|
||||
{
|
||||
if (mWidth != width ) {
|
||||
mWidth = width;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void SynGutter::autoSizeDigitCount(int linesCount)
|
||||
{
|
||||
if (mVisible && mAutoSize && mShowLineNumbers) {
|
||||
linesCount += (mLineNumberStart - 1);
|
||||
}
|
||||
int nDigits = std::max(QString::number(linesCount).length(), mDigitCount);
|
||||
if (mAutoSizeDigitCount!=nDigits) {
|
||||
mAutoSizeDigitCount = nDigits;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString SynGutter::formatLineNumber(int line)
|
||||
{
|
||||
line += (mLineNumberStart - 1);
|
||||
QString result = QString::number(line);
|
||||
return QString(mAutoSizeDigitCount - result.length(),'0') + result;
|
||||
}
|
||||
|
||||
int SynGutter::realGutterWidth(int charWidth)
|
||||
{
|
||||
if (!mVisible) {
|
||||
return 0;
|
||||
}
|
||||
if (mShowLineNumbers) {
|
||||
return mLeftOffset + mRightOffset + mAutoSizeDigitCount * charWidth + 2;
|
||||
}
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
bool SynGutter::visible() const
|
||||
{
|
||||
return mVisible;
|
||||
}
|
||||
|
||||
void SynGutter::setVisible(bool visible)
|
||||
{
|
||||
if (mVisible!=visible) {
|
||||
mVisible = visible;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::useFontStyle() const
|
||||
{
|
||||
return mUseFontStyle;
|
||||
}
|
||||
|
||||
void SynGutter::setUseFontStyle(bool useFontStyle)
|
||||
{
|
||||
if (mUseFontStyle!=useFontStyle) {
|
||||
mUseFontStyle = useFontStyle;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::showLineNumbers() const
|
||||
{
|
||||
return mShowLineNumbers;
|
||||
}
|
||||
|
||||
void SynGutter::setShowLineNumbers(bool showLineNumbers)
|
||||
{
|
||||
if (mShowLineNumbers!=showLineNumbers) {
|
||||
mShowLineNumbers = showLineNumbers;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int SynGutter::rightOffset() const
|
||||
{
|
||||
return mRightOffset;
|
||||
}
|
||||
|
||||
void SynGutter::setRightOffset(int rightOffset)
|
||||
{
|
||||
int value = std::max(0, rightOffset);
|
||||
if (mRightOffset != value) {
|
||||
mRightOffset = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int SynGutter::lineNumberStart() const
|
||||
{
|
||||
return mLineNumberStart;
|
||||
}
|
||||
|
||||
void SynGutter::setLineNumberStart(int lineNumberStart)
|
||||
{
|
||||
int value = std::max(0,lineNumberStart);
|
||||
if (mLineNumberStart!=value) {
|
||||
mLineNumberStart = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::zeroStart()
|
||||
{
|
||||
return mLineNumberStart == 0;
|
||||
}
|
||||
|
||||
int SynGutter::leftOffset() const
|
||||
{
|
||||
return mLeftOffset;
|
||||
}
|
||||
|
||||
void SynGutter::setLeftOffset(int leftOffset)
|
||||
{
|
||||
int value = std::max(0,leftOffset);
|
||||
if (mLeftOffset != value) {
|
||||
mLeftOffset = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::leadingZeros() const
|
||||
{
|
||||
return mLeadingZeros;
|
||||
}
|
||||
|
||||
void SynGutter::setLeadingZeros(bool value)
|
||||
{
|
||||
if (mLeadingZeros!=value) {
|
||||
mLeadingZeros = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int SynGutter::gradientSteps() const
|
||||
{
|
||||
return mGradientSteps;
|
||||
}
|
||||
|
||||
void SynGutter::setGradientSteps(int value)
|
||||
{
|
||||
if (mGradientSteps!=value) {
|
||||
mGradientSteps = value;
|
||||
if (mGradientSteps<2)
|
||||
mGradientSteps = 2;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QColor SynGutter::gradientEndColor() const
|
||||
{
|
||||
return mGradientEndColor;
|
||||
}
|
||||
|
||||
void SynGutter::setGradientEndColor(const QColor &value)
|
||||
{
|
||||
if (mGradientEndColor!=value) {
|
||||
mGradientEndColor = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QColor SynGutter::gradientStartColor() const
|
||||
{
|
||||
return mGradientStartColor;
|
||||
}
|
||||
|
||||
void SynGutter::setGradientStartColor(const QColor &value)
|
||||
{
|
||||
if (mGradientStartColor!=value) {
|
||||
mGradientStartColor = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynGutter::gradient() const
|
||||
{
|
||||
return mGradient;
|
||||
}
|
||||
|
||||
void SynGutter::setGradient(bool value)
|
||||
{
|
||||
if (mGradient!=value){
|
||||
mGradient = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
SynGutterBorderStyle SynGutter::borderStyle() const
|
||||
{
|
||||
return mBorderStyle;
|
||||
}
|
||||
|
||||
void SynGutter::setBorderStyle(const SynGutterBorderStyle &value)
|
||||
{
|
||||
if (mBorderStyle!=value) {
|
||||
mBorderStyle = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int SynGutter::digitCount() const
|
||||
{
|
||||
return mDigitCount;
|
||||
}
|
||||
|
||||
void SynGutter::setDigitCount(int value)
|
||||
{
|
||||
if (mDigitCount != value ) {
|
||||
mDigitCount = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QColor SynGutter::color() const
|
||||
{
|
||||
return mColor;
|
||||
}
|
||||
|
||||
void SynGutter::setColor(const QColor &value)
|
||||
{
|
||||
if (mColor!=value) {
|
||||
mColor = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QColor SynGutter::borderColor() const
|
||||
{
|
||||
return mBorderColor;
|
||||
}
|
||||
|
||||
void SynGutter::setBorderColor(const QColor &value)
|
||||
{
|
||||
if (mBorderColor!=value) {
|
||||
mBorderColor = value;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
#ifndef MISCCLASSES_H
|
||||
#define MISCCLASSES_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QFont>
|
||||
#include <QObject>
|
||||
|
||||
enum class SynGutterBorderStyle {
|
||||
None,
|
||||
Middle,
|
||||
Right
|
||||
};
|
||||
|
||||
class SynGutter : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SynGutter(QObject* parent = nullptr);
|
||||
QFont font() const;
|
||||
void setFont(const QFont &value);
|
||||
|
||||
bool autoSize() const;
|
||||
void setAutoSize(bool value);
|
||||
|
||||
QColor borderColor() const;
|
||||
void setBorderColor(const QColor &value);
|
||||
|
||||
QColor color() const;
|
||||
void setColor(const QColor &value);
|
||||
|
||||
int digitCount() const;
|
||||
void setDigitCount(int value);
|
||||
|
||||
SynGutterBorderStyle borderStyle() const;
|
||||
void setBorderStyle(const SynGutterBorderStyle &value);
|
||||
|
||||
bool gradient() const;
|
||||
void setGradient(bool value);
|
||||
|
||||
QColor gradientStartColor() const;
|
||||
void setGradientStartColor(const QColor &value);
|
||||
|
||||
QColor gradientEndColor() const;
|
||||
void setGradientEndColor(const QColor &value);
|
||||
|
||||
int gradientSteps() const;
|
||||
void setGradientSteps(int value);
|
||||
|
||||
bool leadingZeros() const;
|
||||
void setLeadingZeros(bool value);
|
||||
|
||||
|
||||
int leftOffset() const;
|
||||
void setLeftOffset(int leftOffset);
|
||||
|
||||
int lineNumberStart() const;
|
||||
void setLineNumberStart(int lineNumberStart);
|
||||
|
||||
bool zeroStart();
|
||||
int rightOffset() const;
|
||||
void setRightOffset(int rightOffset);
|
||||
|
||||
bool showLineNumbers() const;
|
||||
void setShowLineNumbers(bool showLineNumbers);
|
||||
|
||||
bool useFontStyle() const;
|
||||
void setUseFontStyle(bool useFontStyle);
|
||||
|
||||
bool visible() const;
|
||||
void setVisible(bool visible);
|
||||
|
||||
int width() const;
|
||||
void setWidth(int width);
|
||||
|
||||
void autoSizeDigitCount(int linesCount);
|
||||
QString formatLineNumber(int line);
|
||||
int realGutterWidth(int charWidth);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
private:
|
||||
void setChanged();
|
||||
private:
|
||||
bool mAutoSize;
|
||||
QColor mBorderColor;
|
||||
QColor mColor;
|
||||
int mDigitCount;
|
||||
QFont mFont;
|
||||
bool mGradient;
|
||||
QColor mGradientStartColor;
|
||||
QColor mGradientEndColor;
|
||||
int mGradientSteps;
|
||||
bool mLeadingZeros;
|
||||
int mLeftOffset;
|
||||
int mLineNumberStart;
|
||||
int mRightOffset;
|
||||
bool mShowLineNumbers;
|
||||
SynGutterBorderStyle mBorderStyle;
|
||||
bool mUseFontStyle;
|
||||
bool mVisible;
|
||||
int mWidth;
|
||||
int mAutoSizeDigitCount;
|
||||
|
||||
};
|
||||
|
||||
#endif // MISCCLASSES_H
|
|
@ -0,0 +1,261 @@
|
|||
#include "base.h"
|
||||
#include "../Constants.h"
|
||||
|
||||
SynHighligterBase::SynHighligterBase(QObject *parent) : QObject(parent),
|
||||
mWordBreakChars{ SynWordBreakChars},
|
||||
mEnabled(true),
|
||||
mUpdateCount(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::map<QString, PSynHighlighterAttribute> SynHighligterBase::attributes() const
|
||||
{
|
||||
return mAttributes;
|
||||
}
|
||||
|
||||
std::set<QChar> SynHighligterBase::wordBreakChars() const
|
||||
{
|
||||
return mWordBreakChars;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::commentAttribute() const
|
||||
{
|
||||
return mCommentAttribute;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::identifierAttribute() const
|
||||
{
|
||||
return mIdentifierAttribute;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::keywordAttribute() const
|
||||
{
|
||||
return mKeywordAttribute;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::stringAttribute() const
|
||||
{
|
||||
return mStringAttribute;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::whitespaceAttribute() const
|
||||
{
|
||||
return mWhitespaceAttribute;
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::symbolAttribute() const
|
||||
{
|
||||
return mSymbolAttribute;
|
||||
}
|
||||
|
||||
void SynHighligterBase::onAttributeChanged()
|
||||
{
|
||||
setAttributesChanged();
|
||||
}
|
||||
|
||||
void SynHighligterBase::setAttributesChanged()
|
||||
{
|
||||
if (mUpdateCount == 0) {
|
||||
emit attributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void SynHighligterBase::beginUpdate()
|
||||
{
|
||||
mUpdateCount++;
|
||||
}
|
||||
|
||||
void SynHighligterBase::endUpdate()
|
||||
{
|
||||
mUpdateCount--;
|
||||
if (mUpdateCount == 0) {
|
||||
setAttributesChanged();
|
||||
}
|
||||
if (mUpdateCount<0) {
|
||||
throw new std::out_of_range("mUpdateCount in SynHighlighterBase < 0");
|
||||
}
|
||||
}
|
||||
|
||||
SynRangeState SynHighligterBase::getRangeState() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SynRangeState SynHighligterBase::getSpaceRangeState() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int SynHighligterBase::getBraceLevel() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SynHighligterBase::getBracketLevel() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SynHighligterBase::getParenthesisLevel() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
SynHighlighterTokenType SynHighligterBase::getTokenType()
|
||||
{
|
||||
return SynHighlighterTokenType::httDefault;
|
||||
}
|
||||
|
||||
bool SynHighligterBase::isKeyword(const QString &)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SynHighligterBase::isSpaceChar(const QChar &ch)
|
||||
{
|
||||
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
|
||||
}
|
||||
|
||||
bool SynHighligterBase::isIdentChar(const QChar &ch) const
|
||||
{
|
||||
if (ch == '_') {
|
||||
return true;
|
||||
}
|
||||
if (ch>='0' && ch <= '9') {
|
||||
return true;
|
||||
}
|
||||
if (ch>='a' && ch <= 'z') {
|
||||
return true;
|
||||
}
|
||||
if (ch>='A' && ch <= 'A') {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SynHighligterBase::addAttribute(PSynHighlighterAttribute attribute)
|
||||
{
|
||||
mAttributes[attribute->name()]=attribute;
|
||||
}
|
||||
|
||||
void SynHighligterBase::clearAttributes()
|
||||
{
|
||||
mAttributes.clear();
|
||||
}
|
||||
|
||||
int SynHighligterBase::attributesCount() const
|
||||
{
|
||||
return mAttributes.size();
|
||||
}
|
||||
|
||||
PSynHighlighterAttribute SynHighligterBase::getAttribute(const QString &name) const
|
||||
{
|
||||
auto search = mAttributes.find(name);
|
||||
if (search!=mAttributes.end()) {
|
||||
return search->second;
|
||||
}
|
||||
return PSynHighlighterAttribute();
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setChanged()
|
||||
{
|
||||
emit changed();
|
||||
}
|
||||
|
||||
bool SynHighlighterAttribute::strikeOut() const
|
||||
{
|
||||
return mStrikeOut;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setStrikeOut(bool strikeOut)
|
||||
{
|
||||
if (mStrikeOut!=strikeOut) {
|
||||
mStrikeOut = strikeOut;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynHighlighterAttribute::underline() const
|
||||
{
|
||||
return mUnderline;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setUnderline(bool underline)
|
||||
{
|
||||
mUnderline = underline;
|
||||
}
|
||||
|
||||
bool SynHighlighterAttribute::italic() const
|
||||
{
|
||||
return mItalic;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setItalic(bool italic)
|
||||
{
|
||||
if (mItalic!=italic) {
|
||||
mItalic = italic;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
bool SynHighlighterAttribute::bold() const
|
||||
{
|
||||
return mBold;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setBold(bool bold)
|
||||
{
|
||||
if (mBold!=bold) {
|
||||
mBold = bold;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString SynHighlighterAttribute::name() const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setName(const QString &name)
|
||||
{
|
||||
if (mName!=name) {
|
||||
mName = name;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QColor SynHighlighterAttribute::foreground() const
|
||||
{
|
||||
return mForeground;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setForeground(const QColor &foreground)
|
||||
{
|
||||
if (mForeground!=foreground) {
|
||||
mForeground = foreground;
|
||||
setChanged();
|
||||
}
|
||||
}
|
||||
|
||||
SynHighlighterAttribute::SynHighlighterAttribute(const QString &name, QObject *parent):
|
||||
QObject(parent),
|
||||
mName(name),
|
||||
mForeground(QColorConstants::Black),
|
||||
mBackground(QColorConstants::White)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QColor SynHighlighterAttribute::background() const
|
||||
{
|
||||
return mBackground;
|
||||
}
|
||||
|
||||
void SynHighlighterAttribute::setBackground(const QColor &background)
|
||||
{
|
||||
if (mBackground!=background) {
|
||||
mBackground = background;
|
||||
setChanged();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
#ifndef SYNHIGHLIGTERBASE_H
|
||||
#define SYNHIGHLIGTERBASE_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
typedef struct {
|
||||
int state;
|
||||
int spaceState;
|
||||
} SynRangeState;
|
||||
typedef int SynTokenKind;
|
||||
|
||||
enum class SynHighlighterTokenType {
|
||||
Default, Space, Comment,
|
||||
PreprocessDirective, String, StringEscapeSequence,
|
||||
Identifier, Symbol,
|
||||
Character, Keyword, Number};
|
||||
|
||||
class SynHighlighterAttribute : public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SynHighlighterAttribute(const QString& name, QObject* parent = nullptr);
|
||||
QColor background() const;
|
||||
void setBackground(const QColor &background);
|
||||
|
||||
QColor foreground() const;
|
||||
void setForeground(const QColor &foreground);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
bool bold() const;
|
||||
void setBold(bool bold);
|
||||
|
||||
bool italic() const;
|
||||
void setItalic(bool italic);
|
||||
|
||||
bool underline() const;
|
||||
void setUnderline(bool underline);
|
||||
|
||||
bool strikeOut() const;
|
||||
void setStrikeOut(bool strikeOut);
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
private:
|
||||
void setChanged();
|
||||
private:
|
||||
QColor mBackground;
|
||||
QColor mForeground;
|
||||
QString mName;
|
||||
bool mBold;
|
||||
bool mItalic;
|
||||
bool mUnderline;
|
||||
bool mStrikeOut;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<SynHighlighterAttribute> PSynHighlighterAttribute;
|
||||
|
||||
class SynHighligterBase : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SynHighligterBase(QObject *parent = nullptr);
|
||||
|
||||
const std::map<QString, PSynHighlighterAttribute> attributes() const;
|
||||
|
||||
std::set<QChar> wordBreakChars() const;
|
||||
|
||||
|
||||
|
||||
PSynHighlighterAttribute commentAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute identifierAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute keywordAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute stringAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute whitespaceAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute symbolAttribute() const;
|
||||
|
||||
virtual bool isIdentChar(const QChar& ch) const;
|
||||
|
||||
void beginUpdate();
|
||||
void endUpdate();
|
||||
virtual bool getTokenFinished() const = 0;
|
||||
virtual bool isLastLineCommentNotFinished(int state) const = 0;
|
||||
virtual bool isLastLineStringNotFinished(int state) const = 0;
|
||||
virtual bool eol() const = 0;
|
||||
virtual SynRangeState getRangeState() const;
|
||||
virtual int getBraceLevel() const;
|
||||
virtual int getBracketLevel() const;
|
||||
virtual int getParenthesisLevel() const;
|
||||
virtual QString getToken() const=0;
|
||||
virtual PSynHighlighterAttribute getTokenAttribute() const=0;
|
||||
virtual SynHighlighterTokenType getTokenType();
|
||||
virtual SynTokenKind getTokenKind() = 0;
|
||||
virtual int getTokenPos() = 0;
|
||||
virtual bool isKeyword(const QString& word);
|
||||
virtual void next() = 0;
|
||||
virtual void nextToEol();
|
||||
virtual void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) = 0;
|
||||
virtual void setLine(const QString& newLine, int lineNumber) = 0;
|
||||
virtual void resetState() = 0;
|
||||
|
||||
virtual QString languageName();
|
||||
|
||||
static bool isSpaceChar(const QChar& ch);
|
||||
signals:
|
||||
void attributesChanged();
|
||||
|
||||
protected:
|
||||
void onAttributeChanged();
|
||||
void setAttributesChanged();
|
||||
|
||||
protected:
|
||||
PSynHighlighterAttribute mCommentAttribute;
|
||||
PSynHighlighterAttribute mIdentifierAttribute;
|
||||
PSynHighlighterAttribute mKeywordAttribute;
|
||||
PSynHighlighterAttribute mStringAttribute;
|
||||
PSynHighlighterAttribute mWhitespaceAttribute;
|
||||
PSynHighlighterAttribute mSymbolAttribute;
|
||||
|
||||
void addAttribute(PSynHighlighterAttribute attribute);
|
||||
void clearAttributes();
|
||||
virtual int attributesCount() const;
|
||||
|
||||
virtual PSynHighlighterAttribute getAttribute(const QString& name) const;
|
||||
|
||||
private:
|
||||
std::map<QString,PSynHighlighterAttribute> mAttributes;
|
||||
int mUpdateCount;
|
||||
bool mEnabled;
|
||||
std::set<QChar> mWordBreakChars;
|
||||
};
|
||||
|
||||
#endif // SYNHIGHLIGTERBASE_H
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,204 @@
|
|||
#ifndef SYNEDITCPPHIGHLIGHTER_H
|
||||
#define SYNEDITCPPHIGHLIGHTER_H
|
||||
#include "base.h"
|
||||
#include <QSet>
|
||||
|
||||
class SynEditCppHighlighter: public SynHighligterBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum TokenKind {
|
||||
Asm = 1,
|
||||
Comment,
|
||||
Directive,
|
||||
Identifier,
|
||||
Key,
|
||||
Null,
|
||||
Number,
|
||||
Space,
|
||||
String,
|
||||
StringEscapeSeq,
|
||||
Symbol,
|
||||
Unknown,
|
||||
Char,
|
||||
Float,
|
||||
Hex,
|
||||
HexFloat,
|
||||
Octal,
|
||||
RawString
|
||||
};
|
||||
|
||||
enum class ExtTokenKind {
|
||||
Add, AddAssign, And, AndAssign, Arrow, Assign,
|
||||
BitComplement, BraceClose, BraceOpen, Colon, Comma,
|
||||
Decrement, Divide, DivideAssign, Ellipse, GreaterThan,
|
||||
GreaterThanEqual, IncOr, IncOrAssign, Increment, LessThan,
|
||||
LessThanEqual, LogAnd, LogComplement, LogEqual, LogOr,
|
||||
Mod, ModAssign, MultiplyAssign, NotEqual, Point, Question,
|
||||
RoundClose, RoundOpen, ScopeResolution, SemiColon, ShiftLeft,
|
||||
ShiftLeftAssign, ShiftRight, ShiftRightAssign, SquareClose,
|
||||
SquareOpen, Star, Subtract, SubtractAssign, Xor,
|
||||
XorAssign
|
||||
};
|
||||
|
||||
enum RangeState {
|
||||
rsUnknown, rsAnsiC, rsAnsiCAsm, rsAnsiCAsmBlock, rsAsm,
|
||||
rsAsmBlock, rsDirective, rsDirectiveComment, rsString,
|
||||
rsMultiLineString, rsMultiLineDirective, rsCppComment,
|
||||
rsStringEscapeSeq, rsMultiLineStringEscapeSeq,
|
||||
rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar
|
||||
};
|
||||
|
||||
public:
|
||||
explicit SynEditCppHighlighter(QObject* parent = nullptr);
|
||||
|
||||
PSynHighlighterAttribute asmAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute direcAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute invalidAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute keyAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute numberAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute floatAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute hexAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute octAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute stringEscapeSequenceAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute charAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute variableAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute functionAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute classAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute globalVarAttribute() const;
|
||||
|
||||
PSynHighlighterAttribute localVarAttribute() const;
|
||||
|
||||
static const QSet<QString> Keywords;
|
||||
|
||||
ExtTokenKind getExtTokenId();
|
||||
SynTokenKind getTokenId();
|
||||
private:
|
||||
void andSymbolProc();
|
||||
void ansiCppProc();
|
||||
void ansiCProc();
|
||||
void asciiCharProc();
|
||||
void atSymbolProc();
|
||||
void braceCloseProc();
|
||||
void braceOpenProc();
|
||||
void colonProc();
|
||||
void commaProc();
|
||||
void directiveProc();
|
||||
void directiveEndProc();
|
||||
void equalProc();
|
||||
void greaterProc();
|
||||
void identProc();
|
||||
void lowerProc();
|
||||
void minusProc();
|
||||
void modSymbolProc();
|
||||
void notSymbolProc();
|
||||
void nullProc();
|
||||
void numberProc();
|
||||
void orSymbolProc();
|
||||
void plusProc();
|
||||
void pointProc();
|
||||
void questionProc();
|
||||
void rawStringProc();
|
||||
void roundCloseProc();
|
||||
void roundOpenProc();
|
||||
void semiColonProc();
|
||||
void slashProc();
|
||||
void spaceProc();
|
||||
void squareCloseProc();
|
||||
void squareOpenProc();
|
||||
void starProc();
|
||||
void stringEndProc();
|
||||
void stringEscapeSeqProc();
|
||||
void stringProc();
|
||||
void stringStartProc();
|
||||
void tildeProc();
|
||||
void unknownProc();
|
||||
void xorSymbolProc();
|
||||
void processChar();
|
||||
|
||||
private:
|
||||
bool mAsmStart;
|
||||
SynRangeState mRange;
|
||||
// SynRangeState mSpaceRange;
|
||||
int mParenthesisLevel;
|
||||
int mBracketLevel;
|
||||
int mBraceLevel;
|
||||
QString mLineString;
|
||||
QChar* mLine;
|
||||
int mLineSize;
|
||||
int mRun;
|
||||
int mStringLen;
|
||||
int mToIdent;
|
||||
int mTokenPos;
|
||||
int mTokenId;
|
||||
ExtTokenKind mExtTokenId;
|
||||
int mLineNumber;
|
||||
|
||||
PSynHighlighterAttribute mAsmAttribute;
|
||||
PSynHighlighterAttribute mDirecAttribute;
|
||||
PSynHighlighterAttribute mInvalidAttribute;
|
||||
PSynHighlighterAttribute mKeyAttribute;
|
||||
PSynHighlighterAttribute mNumberAttribute;
|
||||
PSynHighlighterAttribute mFloatAttribute;
|
||||
PSynHighlighterAttribute mHexAttribute;
|
||||
PSynHighlighterAttribute mOctAttribute;
|
||||
PSynHighlighterAttribute mStringEscapeSequenceAttribute;
|
||||
PSynHighlighterAttribute mCharAttribute;
|
||||
PSynHighlighterAttribute mVariableAttribute;
|
||||
PSynHighlighterAttribute mFunctionAttribute;
|
||||
PSynHighlighterAttribute mClassAttribute;
|
||||
PSynHighlighterAttribute mGlobalVarAttribute;
|
||||
PSynHighlighterAttribute mLocalVarAttribute;
|
||||
|
||||
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
bool getTokenFinished() const override;
|
||||
bool isLastLineCommentNotFinished(int state) const override;
|
||||
bool isLastLineStringNotFinished(int state) const override;
|
||||
bool eol() const override;
|
||||
QString getToken() const override;
|
||||
PSynHighlighterAttribute getTokenAttribute() const override;
|
||||
SynTokenKind getTokenKind() override;
|
||||
int getTokenPos() override;
|
||||
void next() override;
|
||||
void setLine(const QString &newLine, int lineNumber) override;
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
int getBraceLevel() const override;
|
||||
int getBracketLevel() const override;
|
||||
int getParenthesisLevel() const override;
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
bool isKeyword(const QString &word) override;
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
SynHighlighterTokenType getTokenType() override;
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override;
|
||||
|
||||
// SynHighligterBase interface
|
||||
public:
|
||||
void resetState() override;
|
||||
};
|
||||
|
||||
#endif // SYNEDITCPPHIGHLIGHTER_H
|
|
@ -40,7 +40,7 @@ Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &
|
|||
Qt::ItemFlags flags = Qt::NoItemFlags;
|
||||
if (index.isValid()) {
|
||||
flags = Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable ;
|
||||
} else if (index.row() ==-1) {
|
||||
} else if (index.row() == -1) {
|
||||
// -1 means it's a drop target?
|
||||
flags = Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
|
|
@ -7,11 +7,10 @@ IssuesTable::IssuesTable(QWidget *parent):
|
|||
{
|
||||
mModel = new IssuesModel(this);
|
||||
this->setModel(mModel);
|
||||
this->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||
this->horizontalHeader()->setSectionResizeMode(3,QHeaderView::Stretch);
|
||||
this->setColumnWidth(0,200);
|
||||
this->setColumnWidth(1,60);
|
||||
this->setColumnWidth(2,60);
|
||||
this->setColumnWidth(1,45);
|
||||
this->setColumnWidth(2,45);
|
||||
|
||||
}
|
||||
|
||||
|
@ -62,11 +61,30 @@ void IssuesModel::setWarningColor(QColor color)
|
|||
mWarningColor = color;
|
||||
}
|
||||
|
||||
PCompileIssue IssuesModel::issue(int row)
|
||||
{
|
||||
if (row<0 || row>=static_cast<int>(mIssues.size())) {
|
||||
return PCompileIssue();
|
||||
}
|
||||
|
||||
return mIssues[row];
|
||||
}
|
||||
|
||||
void IssuesTable::addIssue(PCompileIssue issue)
|
||||
{
|
||||
mModel->addIssue(issue);
|
||||
}
|
||||
|
||||
PCompileIssue IssuesTable::issue(const QModelIndex &index)
|
||||
{
|
||||
return issue(index.row());
|
||||
}
|
||||
|
||||
PCompileIssue IssuesTable::issue(const int row)
|
||||
{
|
||||
return mModel->issue(row);
|
||||
}
|
||||
|
||||
void IssuesTable::clearIssues()
|
||||
{
|
||||
mModel->clearIssues();
|
||||
|
|
|
@ -18,6 +18,7 @@ public slots:
|
|||
|
||||
void setErrorColor(QColor color);
|
||||
void setWarningColor(QColor color);
|
||||
PCompileIssue issue(int row);
|
||||
private:
|
||||
std::vector<PCompileIssue> mIssues;
|
||||
QColor mErrorColor;
|
||||
|
@ -48,6 +49,9 @@ public:
|
|||
public slots:
|
||||
void addIssue(PCompileIssue issue);
|
||||
|
||||
PCompileIssue issue(const QModelIndex& index);
|
||||
PCompileIssue issue(const int row);
|
||||
|
||||
void clearIssues();
|
||||
|
||||
private:
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
../QScintilla/src/qscintilla.pro \
|
||||
RedPandaIDE
|
||||
|
|
Loading…
Reference in New Issue