2021-05-26 00:04:20 +08:00
|
|
|
#include "HighlighterManager.h"
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QObject>
|
|
|
|
#include "qsynedit/highlighter/cpp.h"
|
2021-07-02 10:32:29 +08:00
|
|
|
#include "qsynedit/highlighter/asm.h"
|
2021-06-20 22:54:16 +08:00
|
|
|
#include "qsynedit/Constants.h"
|
|
|
|
#include "colorscheme.h"
|
2021-05-26 00:04:20 +08:00
|
|
|
|
|
|
|
HighlighterManager highlighterManager;
|
|
|
|
|
|
|
|
HighlighterManager::HighlighterManager()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-07 11:02:03 +08:00
|
|
|
PSynHighlighter HighlighterManager::getHighlighter(const QString &filename)
|
2021-05-26 00:04:20 +08:00
|
|
|
{
|
|
|
|
if (filename.isEmpty() || filename.startsWith(QObject::tr("untitled"))) {
|
2021-06-07 11:02:03 +08:00
|
|
|
return getCppHighlighter();
|
2021-05-26 00:04:20 +08:00
|
|
|
} else {
|
|
|
|
QFileInfo info(filename);
|
|
|
|
QString suffix = info.suffix();
|
|
|
|
if (suffix.isEmpty() || suffix == "c" || suffix == "cpp" || suffix == "cxx"
|
|
|
|
|| suffix == "cc" || suffix == "h" || suffix == "hpp"
|
2021-11-27 10:25:27 +08:00
|
|
|
|| suffix == "hxx" || suffix == "hh" || suffix == "C"
|
|
|
|
|| suffix == "CPP" || suffix =="H" || suffix == "c++"
|
|
|
|
|| suffix == "h++") {
|
2021-06-07 11:02:03 +08:00
|
|
|
return getCppHighlighter();
|
2021-05-26 00:04:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return PSynHighlighter();
|
|
|
|
}
|
|
|
|
|
2021-06-20 22:54:16 +08:00
|
|
|
PSynHighlighter HighlighterManager::copyHighlighter(PSynHighlighter highlighter)
|
|
|
|
{
|
|
|
|
if (!highlighter)
|
|
|
|
return PSynHighlighter();
|
|
|
|
if (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
|
|
|
|
return getCppHighlighter();
|
2021-06-24 20:43:09 +08:00
|
|
|
//todo
|
|
|
|
return PSynHighlighter();
|
2021-06-20 22:54:16 +08:00
|
|
|
}
|
|
|
|
|
2021-06-07 11:02:03 +08:00
|
|
|
PSynHighlighter HighlighterManager::getCppHighlighter()
|
2021-05-26 00:04:20 +08:00
|
|
|
{
|
|
|
|
SynEditCppHighlighter* highlighter = new SynEditCppHighlighter();
|
|
|
|
PSynHighlighter pHighlighter(highlighter);
|
|
|
|
highlighter->asmAttribute()->setForeground(QColorConstants::Blue);
|
|
|
|
highlighter->charAttribute()->setForeground(QColorConstants::Black);
|
|
|
|
highlighter->commentAttribute()->setForeground(0x8C8C8C);
|
|
|
|
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
|
|
|
|
highlighter->classAttribute()->setForeground(0x008080);
|
|
|
|
highlighter->floatAttribute()->setForeground(QColorConstants::Svg::purple);
|
|
|
|
highlighter->functionAttribute()->setForeground(0x00627A);
|
|
|
|
highlighter->globalVarAttribute()->setForeground(0x660E7A);
|
|
|
|
highlighter->hexAttribute()->setForeground(QColorConstants::Svg::purple);
|
|
|
|
highlighter->identifierAttribute()->setForeground(0x080808);
|
|
|
|
highlighter->invalidAttribute()->setForeground(QColorConstants::Svg::red);
|
|
|
|
highlighter->localVarAttribute()->setForeground(QColorConstants::Black);
|
|
|
|
highlighter->numberAttribute()->setForeground(0x1750EB);
|
|
|
|
highlighter->octAttribute()->setForeground(QColorConstants::Svg::purple);
|
2021-10-12 09:47:58 +08:00
|
|
|
highlighter->preprocessorAttribute()->setForeground(0x1f542e);
|
2021-07-02 10:32:29 +08:00
|
|
|
highlighter->keywordAttribute()->setForeground(0x0033b3);
|
2021-05-26 00:04:20 +08:00
|
|
|
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
|
|
|
|
highlighter->stringAttribute()->setForeground(0x007d17);
|
|
|
|
highlighter->stringEscapeSequenceAttribute()->setForeground(QColorConstants::Svg::red);
|
|
|
|
highlighter->symbolAttribute()->setForeground(0xc10000);
|
|
|
|
highlighter->variableAttribute()->setForeground(0x400080);
|
|
|
|
return pHighlighter;
|
|
|
|
}
|
2021-06-20 22:54:16 +08:00
|
|
|
|
2021-07-02 10:32:29 +08:00
|
|
|
PSynHighlighter HighlighterManager::getAsmHighlighter()
|
|
|
|
{
|
|
|
|
SynEditASMHighlighter* highlighter = new SynEditASMHighlighter();
|
|
|
|
PSynHighlighter pHighlighter(highlighter);
|
|
|
|
highlighter->commentAttribute()->setForeground(0x8C8C8C);
|
|
|
|
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
|
|
|
|
highlighter->identifierAttribute()->setForeground(0x080808);
|
|
|
|
highlighter->keywordAttribute()->setForeground(0x0033b3);
|
|
|
|
highlighter->numberAttribute()->setForeground(0x1750EB);
|
|
|
|
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
|
|
|
|
highlighter->stringAttribute()->setForeground(0x007d17);
|
|
|
|
highlighter->symbolAttribute()->setForeground(0xc10000);
|
|
|
|
return pHighlighter;
|
|
|
|
}
|
|
|
|
|
2021-06-20 22:54:16 +08:00
|
|
|
void HighlighterManager::applyColorScheme(PSynHighlighter highlighter, const QString &schemeName)
|
|
|
|
{
|
|
|
|
if (!highlighter)
|
|
|
|
return;
|
2021-07-02 10:32:29 +08:00
|
|
|
if ( (highlighter->getName() == SYN_HIGHLIGHTER_CPP)
|
|
|
|
|| (highlighter->getName() == SYN_HIGHLIGHTER_ASM)
|
|
|
|
) {
|
2021-06-20 22:54:16 +08:00
|
|
|
for (QString name: highlighter->attributes().keys()) {
|
|
|
|
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
|
|
|
|
if (item) {
|
|
|
|
PSynHighlighterAttribute attr = highlighter->attributes()[name];
|
|
|
|
attr->setBackground(item->background());
|
|
|
|
attr->setForeground(item->foreground());
|
|
|
|
SynFontStyles styles = SynFontStyle::fsNone;
|
2021-10-10 21:23:25 +08:00
|
|
|
styles.setFlag(SynFontStyle::fsBold, item->bold());
|
|
|
|
styles.setFlag(SynFontStyle::fsItalic, item->italic());
|
|
|
|
styles.setFlag(SynFontStyle::fsUnderline, item->underlined());
|
|
|
|
styles.setFlag(SynFontStyle::fsStrikeOut, item->strikeout());
|
|
|
|
attr->setStyles(styles);
|
2021-06-20 22:54:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|