Source-highlight Qt Library
Qt4TextFormatter.h
1 /*
2  * Copyright (C) 2008-2010 Lorenzo Bettini, http://www.lorenzobettini.it
3  * License: See COPYING file that comes with this distribution
4  */
5 
6 #ifndef QT4TEXTFORMATTER_H_
7 #define QT4TEXTFORMATTER_H_
8 
9 #include <QTextCharFormat>
10 #include <QSyntaxHighlighter>
11 
12 #include "TextFormatter.h"
13 
14 namespace srchiliteqt {
15 
16 class Qt4SyntaxHighlighter;
17 
22 protected:
26  QTextCharFormat textFormat;
27 
32 
35 
44 
45 public:
46  Qt4TextFormatter(const std::string &elem_ = "normal");
47  virtual ~Qt4TextFormatter();
48 
49  const QTextCharFormat &getQTextCharFormat() const {
50  return textFormat;
51  }
52 
53  virtual void setQSyntaxHighlighter(QSyntaxHighlighter *qSyntaxHighlighter_);
54 
61  void format(const std::string &s, const srchilite::FormatterParams *params);
62 
66  const QString toString() const;
67 
75  const QString toSourceHighlightStyleString() const;
76 
77  bool isBold() const {
78  return textFormat.fontWeight() == QFont::Bold;
79  }
80 
81  void setBold(bool b) {
82  textFormat.setFontWeight(b ? QFont::Bold : QFont::Normal);
83  }
84 
85  bool isItalic() const {
86  return textFormat.fontItalic();
87  }
88 
89  void setItalic(bool i) {
90  textFormat.setFontItalic(i);
91  }
92 
93  bool isUnderline() const {
94  return textFormat.fontUnderline();
95  }
96 
97  void setUnderline(bool u) {
98  textFormat.setFontUnderline(u);
99  }
100 
101  bool isMonospace() const {
102  return textFormat.fontFamily() == "Monospace";
103  }
104 
105  void setMonospace(bool m) {
106  if (m)
107  textFormat.setFontFamily("Monospace");
108  }
109 
111  const QColor &getForegroundColor() const {
112  return foregroundColor;
113  }
114 
115  void setForegroundColor(const QColor &color);
116 
118  const QColor &getBackgroundColor() const {
119  return backgroundColor;
120  }
121 
122  void setBackgroundColor(const QColor &color);
123 };
124 
125 }
126 
127 #endif /* QT4TEXTFORMATTER_H_ */