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()
51 // Remove all <style...> ...</style>
52 QRegExp rx ("<style.*>.*</style>");
56 // convert all "<br*>" to "\n"
57 rx.setPattern ("<br.*>");
60 // convert all "</p>" to "\n"
61 rx.setPattern ("</p>");
64 // remove all remaining tags
65 rx.setPattern ("<.*>");
68 // If string starts with \n now, remove it.
69 // It would be wrong in an OOo export for example
70 while (r.at(0)=='\n') r.remove (0,1);
72 // convert "&", "<" and ">"
73 rx.setPattern (">");
75 rx.setPattern ("<");
77 rx.setPattern ("&");
79 rx.setPattern (""");
85 QString NoteObj::getNoteOpenDoc()
87 // Evil hack to transform QT Richtext into
88 // something which can be used in OpenDoc format
90 // TODO create clean XML transformation which also
91 // considers fonts, colors, ...
95 // convert all "<br*>"
98 r.replace (re,"<text:line-break/>");
101 re.setPattern ("<p>");
102 r.replace (re,"<text:line-break/>");
104 // Remove all other tags, e.g. paragraphs will be added in
105 // templates used during export
106 re.setPattern ("</?html.*>");
108 re.setPattern ("</?head.*>");
110 re.setPattern ("</?body.*>");
112 re.setPattern ("</?meta.*>");
114 re.setPattern ("</?span.*>");
116 re.setPattern ("</?p.*>");
119 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
123 void NoteObj::setFontHint (const QString &s)
125 // only for backward compatibility (pre 1.5 )
129 QString NoteObj::getFontHint()
131 // only for backward compatibility (pre 1.5 )
135 void NoteObj::setFilenameHint (const QString &s)
140 QString NoteObj::getFilenameHint()
145 bool NoteObj::isEmpty ()
147 return note.isEmpty();
150 QString NoteObj::saveToDir ()
152 // QTextEdit may generate fontnames with unquoted &, like
153 // in "Lucida B&H". This is invalid in XML and thus would crash
156 // More invalid XML is generated with bullet lists:
157 // There are 2 <style> tags in one <li>, so we merge them here
159 bool inbracket=false;
163 while (pos<n.length())
165 if (n.mid(pos,1)=="<")
170 if (n.mid(pos,1)==">")
173 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
175 if (s.count("style=\"")>1)
177 QRegExp rx("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
178 rx.setMinimal (true);
179 s.replace(rx,"style=\"\\1 \\2\"");
180 n.replace (begin_bracket,sl,s);
181 pos=pos-(sl-s.length());
184 if (n.mid(pos,1)=="\"" && inbracket)
191 if (n.mid(pos,1)=="&" && inquot)
193 // Now we are inside < " " >
194 n.replace(pos,1,"&");
199 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");