6 #include <QTextDocument>
8 /////////////////////////////////////////////////////////////////
9 // VymText Base class for Vymnotes and Headings
10 /////////////////////////////////////////////////////////////////
12 VymText::VymText() { clear(); }
14 VymText::VymText(const VymText &other)
21 VymText::VymText(const QString &s)
27 bool VymText::operator==(const VymText &other)
29 if (text == other.text && fonthint == other.fonthint &&
30 textmode == other.textmode && filenamehint == other.filenamehint &&
37 void VymText::operator=(const VymText &other) { copy(other); }
39 void VymText::copy(const VymText &other)
42 fonthint = other.fonthint;
43 filenamehint = other.filenamehint;
44 textmode = other.textmode;
57 void VymText::setRichText(bool b)
65 bool VymText::isRichText() const
67 if (textmode == RichText)
73 void VymText::setText(const QString &s) { text = s; }
75 void VymText::setRichText(const QString &s)
81 void VymText::setPlainText(const QString &s)
87 void VymText::setAutoText(const QString &s)
90 if (Qt::mightBeRichText(s))
96 QString VymText::getText() const { return text; }
98 QString VymText::getTextASCII() const { return getTextASCII("", 0); } // FIXME-2 use setting, see TreeItem::setHeading
100 QString VymText::getTextASCII(QString indent, const int &width) const
112 if (fonthint == "fixed" || width == 0) {
115 // Wordwrap, if width > 0
120 while ((int)n < text.length()) {
121 curline = curline + text.at(n);
122 if (text.at(n) == '\n') {
127 if (curline.length() > width) {
128 // Try to find last previous whitespace in curline
129 uint i = curline.length() - 1;
131 if (curline.at(i) == ' ') {
132 s = s + curline.left(i) + '\n';
133 curline = curline.right(curline.length() - i - 1);
138 // Cannot break this line into smaller parts
151 s = s.replace(rx, indent);
153 s = s.replace(rx, "\n" + indent) + "\n";
158 // Remove all <style...> ...</style>
159 rx.setPattern("<style.*>.*</style>");
162 // convert all "<br*>" to "\n"
163 rx.setPattern("<br.*>");
166 // convert all "</p>" to "\n"
167 rx.setPattern("</p>");
170 // remove all remaining tags
171 rx.setPattern("<.*>");
174 // If string starts with \n now, remove it.
175 // It would be wrong in an OOo export for example
176 while (s.at(0) == '\n')
179 // convert "&", "<" and ">"
180 rx.setPattern(">");
182 rx.setPattern("<");
184 rx.setPattern("&");
186 rx.setPattern(""");
190 rx.setPattern("^\n");
191 s.replace(rx, indent);
192 s = indent + s; // Don't forget first line
194 /* FIXME-3 wrap text at width
195 if (fonthint !="fixed")
202 void VymText::setFontHint(const QString &s)
204 if (s == "undef") return;
206 // only for backward compatibility (pre 1.5 )
210 QString VymText::getFontHint() const
212 // only for backward compatibility (pre 1.5 )
216 void VymText::setFilenameHint(const QString &s) { filenamehint = s; }
218 QString VymText::getFilenameHint() const { return filenamehint; }
220 bool VymText::isEmpty() const
223 return text.isEmpty();
231 void VymText::setColor(QColor col) { color = col; }
233 QColor VymText::getColor() { return color; }
235 QStringList VymText::getAttributes() const
238 if (textmode == RichText)
239 ret << attribut("textMode", "richText");
241 ret << attribut("textMode", "plainText");
242 if (!fonthint.isEmpty())
243 ret << attribut("fonthint", fonthint);
245 ret << attribut("textColor", color.name());
246 ret << attribut("text", quoteQuotes(text));
250 QString VymText::saveToDir() { return ""; }