diff options
author | Ken Moore <moorekou@gmail.com> | 2016-04-14 12:49:55 -0400 |
---|---|---|
committer | Ken Moore <moorekou@gmail.com> | 2016-04-14 12:49:55 -0400 |
commit | 1a1e43c175bcba94d84dbb1368329fe45827bb16 (patch) | |
tree | 64adb89cdb69c5900a783e77ad5e6d057d4e2f78 /desktop-utilities/lumina-textedit/syntaxSupport.h | |
parent | Fix up some selection/cursor handling so the user cannot change the current c... (diff) | |
download | lumina-1a1e43c175bcba94d84dbb1368329fe45827bb16.tar.gz lumina-1a1e43c175bcba94d84dbb1368329fe45827bb16.tar.bz2 lumina-1a1e43c175bcba94d84dbb1368329fe45827bb16.zip |
Add a start for a Qt text editor (mainly for playing around - but it could turn into something useful down the road).
Diffstat (limited to 'desktop-utilities/lumina-textedit/syntaxSupport.h')
-rw-r--r-- | desktop-utilities/lumina-textedit/syntaxSupport.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/desktop-utilities/lumina-textedit/syntaxSupport.h b/desktop-utilities/lumina-textedit/syntaxSupport.h new file mode 100644 index 00000000..e8944aa4 --- /dev/null +++ b/desktop-utilities/lumina-textedit/syntaxSupport.h @@ -0,0 +1,45 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_SYNTAX_HIGHLIGHER_CPP_H +#define _LUMINA_SYNTAX_HIGHLIGHER_CPP_H + +#include <QSyntaxHighlighter> +#include <QTextDocument> +#include <QTextCharFormat> +#include <QString> + +struct SyntaxRule{ + QRegExp pattern; + QTextCharFormat format; +}; + +class Custom_Syntax : public QSyntaxHighlighter{ + Q_OBJECT +private: + QVector<SyntaxRule> rules; +public: + Custom_Syntax(QTextDocument *parent = 0) : QSyntaxHighlighter(parent){ + } + ~Custom_Syntax(){} + + static QStringList availableRules(); + static QString ruleForFile(QString filename); + void loadRules(QString type); +protected: + void highlightBlock(const QString &text){ + for(int i=0; i<rules.length(); i++){ + QRegExp patt(rules[i].pattern); //need a copy of the rule's pattern (will be changing it below) + int index = patt.indexIn(text); + while(index>=0){ + int len = patt.matchedLength(); + setFormat(index, len, rules[i].format); + index = patt.indexIn(text, index+len); //go to the next match + } + } + } +}; +#endif
\ No newline at end of file |