RedPanda-CPP/RedPandaIDE/qsynedit/highlighter/base.cpp

229 lines
4.2 KiB
C++
Raw Normal View History

2021-04-29 20:54:44 +08:00
#include "base.h"
#include "../Constants.h"
2021-05-01 23:42:37 +08:00
SynHighlighter::SynHighlighter(QObject *parent) : QObject(parent),
2021-05-01 10:57:41 +08:00
mWordBreakChars{ SynWordBreakChars },
2021-04-29 20:54:44 +08:00
mEnabled(true),
mUpdateCount(0)
{
}
2021-05-01 23:42:37 +08:00
const QMap<QString, PSynHighlighterAttribute>& SynHighlighter::attributes() const
2021-04-29 20:54:44 +08:00
{
return mAttributes;
}
2021-05-01 23:42:37 +08:00
const QSet<QChar>& SynHighlighter::wordBreakChars() const
2021-04-29 20:54:44 +08:00
{
return mWordBreakChars;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::commentAttribute() const
2021-04-29 20:54:44 +08:00
{
return mCommentAttribute;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::identifierAttribute() const
2021-04-29 20:54:44 +08:00
{
return mIdentifierAttribute;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::keywordAttribute() const
2021-04-29 20:54:44 +08:00
{
return mKeywordAttribute;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::stringAttribute() const
2021-04-29 20:54:44 +08:00
{
return mStringAttribute;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::whitespaceAttribute() const
2021-04-29 20:54:44 +08:00
{
return mWhitespaceAttribute;
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::symbolAttribute() const
2021-04-29 20:54:44 +08:00
{
return mSymbolAttribute;
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::onAttributeChanged()
2021-04-29 20:54:44 +08:00
{
setAttributesChanged();
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::setAttributesChanged()
2021-04-29 20:54:44 +08:00
{
if (mUpdateCount == 0) {
emit attributesChanged();
}
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::beginUpdate()
2021-04-29 20:54:44 +08:00
{
mUpdateCount++;
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::endUpdate()
2021-04-29 20:54:44 +08:00
{
mUpdateCount--;
if (mUpdateCount == 0) {
setAttributesChanged();
}
if (mUpdateCount<0) {
throw new std::out_of_range("mUpdateCount in SynHighlighterBase < 0");
}
}
2021-05-01 23:42:37 +08:00
SynRangeState SynHighlighter::getRangeState() const
2021-04-29 20:54:44 +08:00
{
2021-05-01 10:57:41 +08:00
return {0,0};
2021-04-29 20:54:44 +08:00
}
2021-05-01 23:42:37 +08:00
int SynHighlighter::getBraceLevel() const
2021-04-29 20:54:44 +08:00
{
return 0;
}
2021-05-01 23:42:37 +08:00
int SynHighlighter::getBracketLevel() const
2021-04-29 20:54:44 +08:00
{
return 0;
}
2021-05-01 23:42:37 +08:00
int SynHighlighter::getParenthesisLevel() const
2021-04-29 20:54:44 +08:00
{
return 0;
}
2021-05-01 23:42:37 +08:00
SynHighlighterTokenType SynHighlighter::getTokenType()
2021-04-29 20:54:44 +08:00
{
2021-05-01 10:57:41 +08:00
return SynHighlighterTokenType::Default;
2021-04-29 20:54:44 +08:00
}
2021-05-01 23:42:37 +08:00
bool SynHighlighter::isKeyword(const QString &)
2021-04-29 20:54:44 +08:00
{
return false;
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::nextToEol()
2021-05-01 10:57:41 +08:00
{
while (!eol())
next();
}
2021-05-01 23:42:37 +08:00
bool SynHighlighter::isSpaceChar(const QChar &ch)
2021-04-29 20:54:44 +08:00
{
return ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n';
}
2021-05-01 23:42:37 +08:00
bool SynHighlighter::isIdentChar(const QChar &ch) const
2021-04-29 20:54:44 +08:00
{
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;
}
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::addAttribute(PSynHighlighterAttribute attribute)
2021-04-29 20:54:44 +08:00
{
mAttributes[attribute->name()]=attribute;
2021-05-01 10:57:41 +08:00
connect(attribute.get(), &SynHighlighterAttribute::changed,
2021-05-01 23:42:37 +08:00
this, &SynHighlighter::setAttributesChanged);
2021-04-29 20:54:44 +08:00
}
2021-05-01 23:42:37 +08:00
void SynHighlighter::clearAttributes()
2021-04-29 20:54:44 +08:00
{
mAttributes.clear();
}
2021-05-01 23:42:37 +08:00
int SynHighlighter::attributesCount() const
2021-04-29 20:54:44 +08:00
{
return mAttributes.size();
}
2021-05-01 23:42:37 +08:00
PSynHighlighterAttribute SynHighlighter::getAttribute(const QString &name) const
2021-04-29 20:54:44 +08:00
{
auto search = mAttributes.find(name);
if (search!=mAttributes.end()) {
2021-05-01 10:57:41 +08:00
return search.value();
2021-04-29 20:54:44 +08:00
}
return PSynHighlighterAttribute();
}
void SynHighlighterAttribute::setChanged()
{
emit changed();
}
2021-05-06 20:55:55 +08:00
SynFontStyles SynHighlighterAttribute::styles() const
2021-04-29 20:54:44 +08:00
{
2021-05-06 20:55:55 +08:00
return mStyles;
2021-04-29 20:54:44 +08:00
}
2021-05-06 20:55:55 +08:00
void SynHighlighterAttribute::setStyles(const SynFontStyles &styles)
2021-04-29 20:54:44 +08:00
{
2021-05-06 20:55:55 +08:00
if (mStyles!=styles) {
mStyles = styles;
2021-04-29 20:54:44 +08:00
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();
}
}