2 #include <qtextstream.h>
3 #include <qmessagebox.h>
8 /////////////////////////////////////////////////////////////////
10 /////////////////////////////////////////////////////////////////
17 NoteObj::NoteObj(const QString &s)
23 void NoteObj::copy (NoteObj other)
26 fonthint=other.fonthint;
37 void NoteObj::setNote (const QString &s)
42 QString NoteObj::getNote()
47 QString NoteObj::getNoteASCII()
49 return getNoteASCII (QString(""),80);
52 QString NoteObj::getNoteASCII(const QString &indent, const int &width)
56 // Remove all <style...> ...</style>
57 QRegExp rx ("<style.*>.*</style>");
61 // convert all "<br*>" to "\n"
62 rx.setPattern ("<br.*>");
65 // convert all "</p>" to "\n"
66 rx.setPattern ("</p>");
69 // remove all remaining tags
70 rx.setPattern ("<.*>");
73 // If string starts with \n now, remove it.
74 // It would be wrong in an OOo export for example
75 while (r.at(0)=='\n') r.remove (0,1);
77 // convert "&", "<" and ">"
78 rx.setPattern (">");
80 rx.setPattern ("<");
82 rx.setPattern ("&");
84 rx.setPattern (""");
87 /* FIXME wrap text at width
88 if (fonthint !="fixed")
95 QString NoteObj::getNoteOpenDoc()
97 // Evil hack to transform QT Richtext into
98 // something which can be used in OpenDoc format
100 // TODO create clean XML transformation which also
101 // considers fonts, colors, ...
105 // convert all "<br*>"
106 QRegExp re("<br.*>");
108 r.replace (re,"<text:line-break/>");
111 re.setPattern ("<p>");
112 r.replace (re,"<text:line-break/>");
114 // Remove all other tags, e.g. paragraphs will be added in
115 // templates used during export
116 re.setPattern ("</?html.*>");
118 re.setPattern ("</?head.*>");
120 re.setPattern ("</?body.*>");
122 re.setPattern ("</?meta.*>");
124 re.setPattern ("</?span.*>");
126 re.setPattern ("</?p.*>");
129 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
133 void NoteObj::setFontHint (const QString &s)
135 // only for backward compatibility (pre 1.5 )
139 QString NoteObj::getFontHint()
141 // only for backward compatibility (pre 1.5 )
145 void NoteObj::setFilenameHint (const QString &s)
150 QString NoteObj::getFilenameHint()
155 bool NoteObj::isEmpty ()
157 return note.isEmpty();
160 QString NoteObj::saveToDir ()
162 // QTextEdit may generate fontnames with unquoted &, like
163 // in "Lucida B&H". This is invalid in XML and thus would crash
166 // More invalid XML is generated with bullet lists:
167 // There are 2 <style> tags in one <li>, so we merge them here
169 bool inbracket=false;
173 while (pos<n.length())
175 if (n.mid(pos,1)=="<")
180 if (n.mid(pos,1)==">")
183 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
185 if (s.count("style=\"")>1)
187 QRegExp rx("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
188 rx.setMinimal (true);
189 s.replace(rx,"style=\"\\1 \\2\"");
190 n.replace (begin_bracket,sl,s);
191 pos=pos-(sl-s.length());
194 if (n.mid(pos,1)=="\"" && inbracket)
201 if (n.mid(pos,1)=="&" && inquot)
203 // Now we are inside < " " >
204 n.replace(pos,1,"&");
209 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");