00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef INSTIGATE_TOOLKIT_QT_SYNTAX_HIGHLIGHTER
00011 #define INSTIGATE_TOOLKIT_QT_SYNTAX_HIGHLIGHTER
00012
00023
00024
00025
00026
00027
00028 #include <vector>
00029 #include <QSyntaxHighlighter>
00030 #include <QTextCharFormat>
00031 #include <QTextDocument>
00032
00033
00034
00035 namespace instigate {
00036 namespace toolkit {
00037 class qt_syntax_highlighter;
00038 }
00039 }
00040
00052 class instigate::toolkit::qt_syntax_highlighter
00053 : public QSyntaxHighlighter
00054 {
00056 public:
00065 void set_language(const std::string& s) throw();
00066
00067 private:
00068 void highlightBlock(const QString& s) throw();
00069
00070 private:
00071 typedef std::vector<QString> keywords;
00072
00073 void set_tcl_keyword_patterns(keywords&) throw();
00074 void set_verilog_keyword_patterns(keywords&) throw();
00075 void set_vhdl_keyword_patterns(keywords&) throw();
00076 void set_cpp_keyword_patterns(keywords&) throw();
00077 void set_python_keyword_patterns(keywords&) throw();
00078 void set_language_for_cpp() throw();
00079 void set_language_for_vhdl() throw();
00080 void set_language_for_tcl() throw();
00081 void set_language_for_verilog() throw();
00082 void set_language_for_python() throw();
00083
00085 private:
00086 struct highlighting_rule
00087 {
00088 QRegExp m_pattern;
00089 QTextCharFormat m_format;
00090
00091 highlighting_rule(QRegExp p, QTextCharFormat f) throw()
00092 : m_pattern(p)
00093 , m_format(f)
00094 {}
00095 };
00096
00097 typedef std::vector<highlighting_rule> highlighting_rules;
00098 highlighting_rules m_highlighting_rules;
00099
00100 QStringList m_keyword_patterns;
00101 QTextCharFormat m_keyword_format;
00102
00104 public:
00110 qt_syntax_highlighter(QTextDocument* p) throw();
00111
00113 ~qt_syntax_highlighter() throw();
00114
00116 private:
00118 qt_syntax_highlighter() throw();
00119
00121 qt_syntax_highlighter(const qt_syntax_highlighter&) throw();
00122
00124 qt_syntax_highlighter& operator=(const qt_syntax_highlighter&) throw();
00125 };
00126
00127
00128
00129 #endif // INSTIGATE_TOOLKIT_QT_SYNTAX_HIGHLIGHTER