6 /////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////
15 NoteObj::NoteObj(const QString &s)
21 void NoteObj::operator= (const NoteObj &other)
26 void NoteObj::copy (NoteObj other)
29 fonthint=other.fonthint;
30 filenamehint=other.filenamehint;
40 void NoteObj::setNote (const QString &s)
45 QString NoteObj::getNote() const
50 QString NoteObj::getNoteASCII()
52 return getNoteASCII ("",80);
55 QString NoteObj::getNoteASCII(QString indent, const int &) //FIXME-3 use width
57 if (note.isEmpty()) return note;
60 // Remove all <style...> ...</style>
61 QRegExp rx ("<style.*>.*</style>");
65 // convert all "<br*>" to "\n"
66 rx.setPattern ("<br.*>");
69 // convert all "</p>" to "\n"
70 rx.setPattern ("</p>");
73 // remove all remaining tags
74 rx.setPattern ("<.*>");
77 // If string starts with \n now, remove it.
78 // It would be wrong in an OOo export for example
79 while (r.at(0)=='\n') r.remove (0,1);
81 // convert "&", "<" and ">"
82 rx.setPattern (">");
84 rx.setPattern ("<");
86 rx.setPattern ("&");
88 rx.setPattern (""");
92 rx.setPattern ("^\n");
93 r.replace (rx,indent);
94 r=indent + r; // Don't forget first line
96 /* FIXME-3 wrap text at width
97 if (fonthint !="fixed")
101 r=indent+"\n"+r+indent+"\n\n";
105 QString NoteObj::getNoteOpenDoc()
107 // Evil hack to transform QT Richtext into
108 // something which can be used in OpenDoc format
110 // TODO create clean XML transformation which also
111 // considers fonts, colors, ...
115 // convert all "<br*>"
116 QRegExp re("<br.*>");
118 r.replace (re,"<text:line-break/>");
121 re.setPattern ("<p>");
122 r.replace (re,"<text:line-break/>");
124 // Remove all other tags, e.g. paragraphs will be added in
125 // templates used during export
126 re.setPattern ("</?html.*>");
128 re.setPattern ("</?head.*>");
130 re.setPattern ("</?body.*>");
132 re.setPattern ("</?meta.*>");
134 re.setPattern ("</?span.*>");
136 re.setPattern ("</?p.*>");
139 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
143 void NoteObj::setFontHint (const QString &s)
145 // only for backward compatibility (pre 1.5 )
149 QString NoteObj::getFontHint() const
151 // only for backward compatibility (pre 1.5 )
155 void NoteObj::setFilenameHint (const QString &s)
160 QString NoteObj::getFilenameHint() const
165 bool NoteObj::isEmpty ()
167 return note.isEmpty();
170 QString NoteObj::saveToDir ()
174 // Remove the doctype, which will confuse parsing
175 // with XmlReader in Qt >= 4.4
176 QRegExp rx("<!DOCTYPE.*>");
181 // QTextEdit may generate fontnames with unquoted &, like
182 // in "Lucida B&H". This is invalid in XML and thus would crash
185 // More invalid XML is generated with bullet lists:
186 // There are 2 <style> tags in one <li>, so we merge them here
188 bool inbracket=false;
192 while (pos<n.length())
194 if (n.mid(pos,1)=="<")
199 if (n.mid(pos,1)==">")
202 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
204 if (s.count("style=\"")>1)
206 rx.setPattern ("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
207 s.replace(rx,"style=\"\\1 \\2\"");
208 n.replace (begin_bracket,sl,s);
209 pos=pos-(sl-s.length());
212 if (n.mid(pos,1)=="\"" && inbracket)
219 if (n.mid(pos,1)=="&" && inquot)
221 // Now we are inside < " " >
222 n.replace(pos,1,"&");
227 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");