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 <boost/shared_ptr.hpp>
00016
00017 #include "TextFormatter.h"
00018
00019 namespace srchiliteqt {
00020
00021 class Qt4SyntaxHighlighter;
00022
00023 typedef boost::shared_ptr<QTextCharFormat> QTextCharFormatPtr;
00024
00028 class Qt4TextFormatter: public TextFormatter {
00029 protected:
00034 QTextCharFormatPtr textFormat;
00035
00039 QColor foregroundColor;
00040
00042 QColor backgroundColor;
00043
00051 Qt4SyntaxHighlighter *qSyntaxHighlighter;
00052
00053 public:
00054 Qt4TextFormatter(const std::string &elem_ = "normal");
00055 virtual ~Qt4TextFormatter();
00056
00057 QTextCharFormat &getQTextCharFormat() const {
00058 return *textFormat;
00059 }
00060
00061 virtual void setQSyntaxHighlighter(QSyntaxHighlighter *qSyntaxHighlighter_);
00062
00069 void format(const std::string &s, const srchilite::FormatterParams *params);
00070
00074 const QString toString() const;
00075
00076 bool isBold() const {
00077 return textFormat->fontWeight() == QFont::Bold;
00078 }
00079
00080 void setBold(bool b) {
00081 textFormat->setFontWeight(b ? QFont::Bold : QFont::Normal);
00082 }
00083
00084 bool isItalic() const {
00085 return textFormat->fontItalic();
00086 }
00087
00088 void setItalic(bool i) {
00089 textFormat->setFontItalic(i);
00090 }
00091
00092 bool isUnderline() const {
00093 return textFormat->fontUnderline();
00094 }
00095
00096 void setUnderline(bool u) {
00097 textFormat->setFontUnderline(u);
00098 }
00099
00100 bool isMonospace() const {
00101 return textFormat->fontFamily() == "Monospace";
00102 }
00103
00104 void setMonospace(bool m) {
00105 if (m)
00106 textFormat->setFontFamily("Monospace");
00107 }
00108
00110 const QColor &getForegroundColor() const {
00111 return foregroundColor;
00112 }
00113
00114 void setForegroundColor(const QColor &color);
00115
00117 const QColor &getBackgroundColor() const {
00118 return backgroundColor;
00119 }
00120
00121 void setBackgroundColor(const QColor &color);
00122 };
00123
00124 }
00125
00126 #endif