1 | /* |
2 | This file is part of the Grantlee template system. |
3 | |
4 | Copyright (c) 2008 Stephen Kelly <steveire@gmail.com> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Lesser General Public |
8 | License as published by the Free Software Foundation; either version |
9 | 2.1 of the Licence, or (at your option) any later version. |
10 | |
11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Lesser General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU Lesser General Public |
17 | License along with this library. If not, see <http://www.gnu.org/licenses/>. |
18 | |
19 | */ |
20 | |
21 | #ifndef GRANTLEE_PLAINTEXTMARKUPBUILDER_H |
22 | #define GRANTLEE_PLAINTEXTMARKUPBUILDER_H |
23 | |
24 | |
25 | #ifdef Q_OS_WIN |
26 | #pragma warning( disable : 4250 ) |
27 | #endif |
28 | |
29 | #define LETTERSINALPHABET 26 |
30 | #define DIGITSOFFSET 10 |
31 | |
32 | #include "abstractmarkupbuilder.h" |
33 | #include "grantlee_gui_export.h" |
34 | #include "markupdirector.h" |
35 | |
36 | class QBrush; |
37 | |
38 | namespace Grantlee |
39 | { |
40 | |
41 | class PlainTextMarkupBuilderPrivate; |
42 | |
43 | /// @headerfile plaintextmarkupbuilder.h grantlee/plaintextmarkupbuilder.h |
44 | |
45 | /** |
46 | @brief The PlainTextHTMLMarkupBuilder creates a simple marked up plain text document. |
47 | |
48 | This class creates a simple plain text markup. |
49 | |
50 | Text that may be represented as |
51 | |
52 | @code |
53 | A paragraph with <b>bold</b> text, <i>italic</i> text, and <u>underlined</u> text. |
54 | @endcode |
55 | |
56 | would be output as |
57 | |
58 | @code |
59 | A paragraph with *bold* text /italic/ text, and _underlined_ text. |
60 | @endcode |
61 | |
62 | The markup is intended to be simple, plain and easily human readable. No markup is created for different font-familiy, font-size, foreground or background colors. |
63 | |
64 | Lists are marked up by preceding the list element with '*' for disc, 'o' for circle, 'X' for square, or a letter or number. Lists are also indented if nested. |
65 | eg: |
66 | |
67 | @code |
68 | A. One |
69 | B. Two |
70 | o Three |
71 | o Four |
72 | \* Five |
73 | \* Six |
74 | C. Seven |
75 | @endcode |
76 | |
77 | External references such as external urls and images are represented in the body text as a reference, and references are maintained at the bottom of the output. |
78 | |
79 | Eg, |
80 | @code |
81 | Here is a link to <a href="http://www.kde.org">KDE</a> and the <a href="http://pim.kde.org">KDEPIM project</a>. |
82 | @endcode |
83 | |
84 | becomes: |
85 | |
86 | @code |
87 | Here is a link to KDE[1], and the KDEPIM project[2]. |
88 | |
89 | ---- References ---- |
90 | [1] http://www.kde.org |
91 | [2] http://pim.kde.org |
92 | @endcode |
93 | |
94 | @author Stephen Kelly <steveire@gmail.com> |
95 | */ |
96 | class GRANTLEE_GUI_EXPORT PlainTextMarkupBuilder : virtual public AbstractMarkupBuilder |
97 | { |
98 | public: |
99 | /** Construct a new PlainTextHTMLMarkupBuilder. */ |
100 | PlainTextMarkupBuilder(); |
101 | |
102 | virtual ~PlainTextMarkupBuilder(); |
103 | |
104 | /* reimp */ void beginStrong(); |
105 | /* reimp */ void endStrong(); |
106 | /* reimp */ void beginEmph(); |
107 | /* reimp */ void endEmph(); |
108 | /* reimp */ void beginUnderline(); |
109 | /* reimp */ void endUnderline(); |
110 | /* reimp */ void beginStrikeout(); |
111 | /* reimp */ void endStrikeout(); |
112 | |
113 | /* reimp */ void beginAnchor( const QString &href = QString(), const QString &name = QString() ); |
114 | |
115 | /* reimp */ void endAnchor(); |
116 | |
117 | /* reimp */ void beginForeground( const QBrush &brush ); |
118 | |
119 | /* reimp */ void endForeground(); |
120 | |
121 | /* reimp */ void beginBackground( const QBrush &brush ); |
122 | |
123 | /* reimp */ void endBackground(); |
124 | |
125 | /* reimp */ void beginFontFamily( const QString &family ); |
126 | |
127 | /* reimp */ void endFontFamily(); |
128 | |
129 | /* reimp */ void beginFontPointSize( int size ); |
130 | |
131 | /* reimp */ void endFontPointSize(); |
132 | |
133 | /* reimp */ void beginParagraph( Qt::Alignment a = Qt::AlignLeft, qreal top = 0.0, qreal bottom = 0.0, qreal left = 0.0, qreal right = 0.0 ); |
134 | |
135 | /* reimp */ void endParagraph(); |
136 | /* reimp */ void addNewline(); |
137 | |
138 | /* reimp */ void insertHorizontalRule( int width = -1 ); |
139 | |
140 | /* reimp */ void insertImage( const QString &src, qreal width, qreal height ); |
141 | |
142 | /* reimp */ void beginList( QTextListFormat::Style style ); |
143 | |
144 | /* reimp */ void endList(); |
145 | |
146 | /* reimp */ void beginListItem(); |
147 | |
148 | /* reimp */ void endListItem(); |
149 | |
150 | /* reimp */ void beginSuperscript(); |
151 | |
152 | /* reimp */ void endSuperscript(); |
153 | |
154 | /* reimp */ void beginSubscript(); |
155 | |
156 | /* reimp */ void endSubscript(); |
157 | |
158 | /* reimp */ void beginTable( qreal cellpadding, qreal cellspacing, const QString &width ); |
159 | |
160 | /* reimp */ void beginTableRow(); |
161 | |
162 | /* reimp */ void ( const QString &width, int colSpan, int rowSpan ); |
163 | |
164 | /* reimp */ void beginTableCell( const QString &width, int colSpan, int rowSpan ); |
165 | |
166 | /* reimp */ void endTable(); |
167 | |
168 | /* reimp */ void endTableRow(); |
169 | |
170 | /* reimp */ void (); |
171 | |
172 | /* reimp */ void endTableCell(); |
173 | |
174 | /* reimp */ void ( int level ); |
175 | |
176 | /* reimp */ void ( int level ); |
177 | |
178 | /* reimp */ void appendLiteralText( const QString &text ); |
179 | |
180 | /* reimp */ void appendRawText( const QString &text ); |
181 | |
182 | /** |
183 | Adds a reference to @p reference to the internal list of references in the document. |
184 | */ |
185 | int addReference( const QString &reference ); |
186 | |
187 | /** |
188 | Returns the finalised plain text markup, including references at the end. |
189 | */ |
190 | /* reimp */ QString getResult(); |
191 | |
192 | private: |
193 | PlainTextMarkupBuilderPrivate * const d_ptr; |
194 | Q_DECLARE_PRIVATE( PlainTextMarkupBuilder ) |
195 | |
196 | }; |
197 | |
198 | } |
199 | |
200 | #endif |
201 | |