6 #include <QTextDocument>
8 /////////////////////////////////////////////////////////////////
9 // VymText Base class for Vymnotes and Headings
10 /////////////////////////////////////////////////////////////////
16 VymText::VymText(const VymText &other)
23 VymText::VymText(const QString &s)
29 bool VymText::operator== (const VymText &other)
31 if ( text == other.text &&
32 fonthint == other.fonthint &&
33 textmode == other.textmode &&
34 filenamehint == other.filenamehint
41 void VymText::operator= (const VymText &other)
46 void VymText::copy (const VymText &other)
49 fonthint = other.fonthint;
50 filenamehint = other.filenamehint;
51 textmode = other.textmode;
64 void VymText::setRichText(bool b)
72 bool VymText::isRichText()const
74 if (textmode == RichText)
80 void VymText::setText (const QString &s)
85 void VymText::setRichText (const QString &s)
91 void VymText::setPlainText (const QString &s)
97 void VymText::setAutoText (const QString &s)
100 if (Qt::mightBeRichText (s))
106 QString VymText::getText() const
111 QString VymText::getTextASCII() const
113 return getTextASCII ("",80);
116 QString VymText::getTextASCII(QString indent, const int &) const //FIXME-3 use width
118 if (text.isEmpty()) return text;
129 if ( fonthint == "fixed")
139 while ( (int)n < text.length() )
141 curline = curline + text.at(n);
142 if ( text.at(n) == '\n' )
148 if (curline.length() > width)
150 // Try to find last previous whitespace in curline
151 uint i = curline.length() - 1;
154 if ( curline.at(i) == ' ' )
156 s = s + curline.left(i) + '\n';
157 curline = curline.right( curline.length() - i - 1 );
163 // Cannot break this line into smaller parts
176 s = s.replace (rx,indent);
178 s = s.replace (rx, "\n" + indent) + "\n";
183 // Remove all <style...> ...</style>
184 rx.setPattern("<style.*>.*</style>");
187 // convert all "<br*>" to "\n"
188 rx.setPattern ("<br.*>");
191 // convert all "</p>" to "\n"
192 rx.setPattern ("</p>");
195 // remove all remaining tags
196 rx.setPattern ("<.*>");
199 // If string starts with \n now, remove it.
200 // It would be wrong in an OOo export for example
201 while ( s.at(0) == '\n' ) s.remove (0,1);
203 // convert "&", "<" and ">"
204 rx.setPattern (">");
206 rx.setPattern ("<");
208 rx.setPattern ("&");
210 rx.setPattern (""");
214 rx.setPattern ("^\n");
215 s.replace (rx,indent);
216 s = indent + s; // Don't forget first line
218 /* FIXME-3 wrap text at width
219 if (fonthint !="fixed")
226 void VymText::setFontHint (const QString &s)
228 // only for backward compatibility (pre 1.5 )
232 QString VymText::getFontHint() const
234 // only for backward compatibility (pre 1.5 )
238 void VymText::setFilenameHint (const QString &s)
243 QString VymText::getFilenameHint() const
248 bool VymText::isEmpty ()
250 return text.isEmpty();
253 void VymText::setColor(QColor col)
258 QColor VymText::getColor()
263 QString VymText::getAttributes()
266 if (textmode == RichText)
267 ret += attribut("textMode","richText");
270 ret += attribut("textMode","plainText");
271 ret += " " + attribut("fonthint", fonthint);
273 ret += " " + attribut("textColor", color.name() );
277 QString VymText::saveToDir ()
279 return getCDATA( text );