SpeedCrunch
0.11
|
00001 // This file is part of the SpeedCrunch project 00002 // Copyright (C) 2007 Ariya Hidayat <ariya@kde.org> 00003 // Copyright (C) 2007-2009, 2013, 2014 Helder Correia <helder.pereira.correia@gmail.com> 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; see the file COPYING. If not, write to 00017 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 // Boston, MA 02110-1301, USA. 00019 00020 #ifndef GUI_SYNTAXHIGHLIGHTER_H 00021 #define GUI_SYNTAXHIGHLIGHTER_H 00022 00023 #include <QSyntaxHighlighter> 00024 00025 class QPlainTextEdit; 00026 00027 class SyntaxHighlighter : public QSyntaxHighlighter { 00028 public: 00029 enum ColorScheme { 00030 Terminal = 0, 00031 Standard = 1, 00032 Sublime = 2, 00033 SolarizedLight = 3, 00034 SolarizedDark = 4 00035 }; 00036 00037 enum Role { 00038 Cursor, 00039 Number, 00040 Parens, 00041 Result, 00042 Comment, 00043 Matched, 00044 Function, 00045 Operator, 00046 Variable, 00047 ScrollBar, 00048 Separator, 00049 Background, 00050 EditorBackground 00051 }; 00052 00053 explicit SyntaxHighlighter(QPlainTextEdit*); 00054 00055 void setColorScheme(ColorScheme); 00056 QColor colorForRole(Role role) const { return m_colorScheme[role]; } 00057 void setColorForRole(Role role, const QColor& color) { m_colorScheme[role] = color; } 00058 00059 void update(); 00060 00061 virtual void highlightBlock(const QString&); 00062 00063 private: 00064 Q_DISABLE_COPY(SyntaxHighlighter); 00065 SyntaxHighlighter(); 00066 SyntaxHighlighter(QObject*); 00067 SyntaxHighlighter(QTextDocument*); 00068 void groupDigits(const QString& text, int pos, int length); 00069 void formatDigitsGroup(const QString& text, int start, int end, bool invert, int size); 00070 00071 QHash<Role, QColor> m_colorScheme; 00072 }; 00073 00074 #endif