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_ */
QTextCharFormat textFormat
The format represented by this formatter.
Definition: Qt4TextFormatter.h:26
Definition: ColorDialog.cpp:12
const QColor & getForegroundColor() const
Definition: Qt4TextFormatter.h:111
Qt4SyntaxHighlighter * qSyntaxHighlighter
The reference to QSyntaxHighlighter object.
Definition: Qt4TextFormatter.h:43
QColor foregroundColor
the (possibly invalid) foreground color.
Definition: Qt4TextFormatter.h:31
QColor backgroundColor
the (possibly invalid) background color
Definition: Qt4TextFormatter.h:34
The implementation of TextFormatter for Qt4, relying on QTextCharFormat.
Definition: Qt4TextFormatter.h:21
const QString toSourceHighlightStyleString() const
Starting from this formatter, it builds a string representation using the syntax of source-highlight ...
Definition: Qt4TextFormatter.cpp:79
A specialization of srchilite::Formatter in order to format parts of a document, instead of outputtin...
Definition: TextFormatter.h:30
const QColor & getBackgroundColor() const
Definition: Qt4TextFormatter.h:118
const QString toString() const
Definition: Qt4TextFormatter.cpp:57
void format(const std::string &s, const srchilite::FormatterParams *params)
Formats the passed string.
Definition: Qt4TextFormatter.cpp:39
An implementation of QSyntaxHighlighter using GNU Source-highlight library (by relying on GNUSyntaxHi...
Definition: Qt4SyntaxHighlighter.h:38