2 #include <qtextstream.h>
3 #include <qmessagebox.h>
8 /////////////////////////////////////////////////////////////////
10 /////////////////////////////////////////////////////////////////
17 NoteObj::NoteObj(const QString &s)
23 void NoteObj::operator= (const NoteObj &other)
28 void NoteObj::copy (NoteObj other)
31 fonthint=other.fonthint;
32 filenamehint=other.filenamehint;
42 void NoteObj::setNote (const QString &s)
47 QString NoteObj::getNote() const
52 QString NoteObj::getNoteASCII()
54 return getNoteASCII (QString(""),80);
57 QString NoteObj::getNoteASCII(const QString &indent, const int &width)
59 // FIXME-3 make use of width
62 // Remove all <style...> ...</style>
63 QRegExp rx ("<style.*>.*</style>");
67 // convert all "<br*>" to "\n"
68 rx.setPattern ("<br.*>");
71 // convert all "</p>" to "\n"
72 rx.setPattern ("</p>");
75 // remove all remaining tags
76 rx.setPattern ("<.*>");
79 // If string starts with \n now, remove it.
80 // It would be wrong in an OOo export for example
81 while (r.at(0)=='\n') r.remove (0,1);
83 // convert "&", "<" and ">"
84 rx.setPattern (">");
86 rx.setPattern ("<");
88 rx.setPattern ("&");
90 rx.setPattern (""");
94 rx.setPattern ("^\n");
95 r.replace (rx,indent);
96 r=indent + r; // Don't forget first line
98 /* FIXME-2 wrap text at width
99 if (fonthint !="fixed")
103 r=indent+"\n"+r+indent+"\n\n";
107 QString NoteObj::getNoteOpenDoc()
109 // Evil hack to transform QT Richtext into
110 // something which can be used in OpenDoc format
112 // TODO create clean XML transformation which also
113 // considers fonts, colors, ...
117 // convert all "<br*>"
118 QRegExp re("<br.*>");
120 r.replace (re,"<text:line-break/>");
123 re.setPattern ("<p>");
124 r.replace (re,"<text:line-break/>");
126 // Remove all other tags, e.g. paragraphs will be added in
127 // templates used during export
128 re.setPattern ("</?html.*>");
130 re.setPattern ("</?head.*>");
132 re.setPattern ("</?body.*>");
134 re.setPattern ("</?meta.*>");
136 re.setPattern ("</?span.*>");
138 re.setPattern ("</?p.*>");
141 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
145 void NoteObj::setFontHint (const QString &s)
147 // only for backward compatibility (pre 1.5 )
151 QString NoteObj::getFontHint() const
153 // only for backward compatibility (pre 1.5 )
157 void NoteObj::setFilenameHint (const QString &s)
162 QString NoteObj::getFilenameHint() const
167 bool NoteObj::isEmpty ()
169 return note.isEmpty();
172 QString NoteObj::saveToDir ()
176 // Remove the doctype, which will confuse parsing
177 // with XmlReader in Qt >= 4.4
178 QRegExp rx("<!DOCTYPE.*>");
183 // QTextEdit may generate fontnames with unquoted &, like
184 // in "Lucida B&H". This is invalid in XML and thus would crash
187 // More invalid XML is generated with bullet lists:
188 // There are 2 <style> tags in one <li>, so we merge them here
190 bool inbracket=false;
194 while (pos<n.length())
196 if (n.mid(pos,1)=="<")
201 if (n.mid(pos,1)==">")
204 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
206 if (s.count("style=\"")>1)
208 rx.setPattern ("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
209 s.replace(rx,"style=\"\\1 \\2\"");
210 n.replace (begin_bracket,sl,s);
211 pos=pos-(sl-s.length());
214 if (n.mid(pos,1)=="\"" && inbracket)
221 if (n.mid(pos,1)=="&" && inquot)
223 // Now we are inside < " " >
224 n.replace(pos,1,"&");
229 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");