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 (""");
88 rx.setPattern ("^\n");
89 r.replace (rx,indent);
90 r=indent + r; // Don't forget first line
92 /* FIXME wrap text at width
93 if (fonthint !="fixed")
100 QString NoteObj::getNoteOpenDoc()
102 // Evil hack to transform QT Richtext into
103 // something which can be used in OpenDoc format
105 // TODO create clean XML transformation which also
106 // considers fonts, colors, ...
110 // convert all "<br*>"
111 QRegExp re("<br.*>");
113 r.replace (re,"<text:line-break/>");
116 re.setPattern ("<p>");
117 r.replace (re,"<text:line-break/>");
119 // Remove all other tags, e.g. paragraphs will be added in
120 // templates used during export
121 re.setPattern ("</?html.*>");
123 re.setPattern ("</?head.*>");
125 re.setPattern ("</?body.*>");
127 re.setPattern ("</?meta.*>");
129 re.setPattern ("</?span.*>");
131 re.setPattern ("</?p.*>");
134 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
138 void NoteObj::setFontHint (const QString &s)
140 // only for backward compatibility (pre 1.5 )
144 QString NoteObj::getFontHint()
146 // only for backward compatibility (pre 1.5 )
150 void NoteObj::setFilenameHint (const QString &s)
155 QString NoteObj::getFilenameHint()
160 bool NoteObj::isEmpty ()
162 return note.isEmpty();
165 QString NoteObj::saveToDir ()
167 // QTextEdit may generate fontnames with unquoted &, like
168 // in "Lucida B&H". This is invalid in XML and thus would crash
171 // More invalid XML is generated with bullet lists:
172 // There are 2 <style> tags in one <li>, so we merge them here
174 bool inbracket=false;
178 while (pos<n.length())
180 if (n.mid(pos,1)=="<")
185 if (n.mid(pos,1)==">")
188 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
190 if (s.count("style=\"")>1)
192 QRegExp rx("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
193 rx.setMinimal (true);
194 s.replace(rx,"style=\"\\1 \\2\"");
195 n.replace (begin_bracket,sl,s);
196 pos=pos-(sl-s.length());
199 if (n.mid(pos,1)=="\"" && inbracket)
206 if (n.mid(pos,1)=="&" && inquot)
208 // Now we are inside < " " >
209 n.replace(pos,1,"&");
214 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");