00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef QT4TEXTFORMATTER_H_
00010 #define QT4TEXTFORMATTER_H_
00011
00012 #include <QTextCharFormat>
00013 #include <QSyntaxHighlighter>
00014
00015 #include "TextFormatter.h"
00016
00017 namespace srchiliteqt {
00018
00019 class Qt4SyntaxHighlighter;
00020
00024 class Qt4TextFormatter: public TextFormatter {
00025 protected:
00029 QTextCharFormat textFormat;
00030
00034 QColor foregroundColor;
00035
00037 QColor backgroundColor;
00038
00046 Qt4SyntaxHighlighter *qSyntaxHighlighter;
00047
00048 public:
00049 Qt4TextFormatter(const std::string &elem_ = "normal");
00050 virtual ~Qt4TextFormatter();
00051
00052 const QTextCharFormat &getQTextCharFormat() const {
00053 return textFormat;
00054 }
00055
00056 virtual void setQSyntaxHighlighter(QSyntaxHighlighter *qSyntaxHighlighter_);
00057
00064 void format(const std::string &s, const srchilite::FormatterParams *params);
00065
00069 const QString toString() const;
00070
00078 const QString toSourceHighlightStyleString() const;
00079
00080 bool isBold() const {
00081 return textFormat.fontWeight() == QFont::Bold;
00082 }
00083
00084 void setBold(bool b) {
00085 textFormat.setFontWeight(b ? QFont::Bold : QFont::Normal);
00086 }
00087
00088 bool isItalic() const {
00089 return textFormat.fontItalic();
00090 }
00091
00092 void setItalic(bool i) {
00093 textFormat.setFontItalic(i);
00094 }
00095
00096 bool isUnderline() const {
00097 return textFormat.fontUnderline();
00098 }
00099
00100 void setUnderline(bool u) {
00101 textFormat.setFontUnderline(u);
00102 }
00103
00104 bool isMonospace() const {
00105 return textFormat.fontFamily() == "Monospace";
00106 }
00107
00108 void setMonospace(bool m) {
00109 if (m)
00110 textFormat.setFontFamily("Monospace");
00111 }
00112
00114 const QColor &getForegroundColor() const {
00115 return foregroundColor;
00116 }
00117
00118 void setForegroundColor(const QColor &color);
00119
00121 const QColor &getBackgroundColor() const {
00122 return backgroundColor;
00123 }
00124
00125 void setBackgroundColor(const QColor &color);
00126 };
00127
00128 }
00129
00130 #endif