deleting works - partially.
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)
54 // FIXME make use of width
57 // Remove all <style...> ...</style>
58 QRegExp rx ("<style.*>.*</style>");
62 // convert all "<br*>" to "\n"
63 rx.setPattern ("<br.*>");
66 // convert all "</p>" to "\n"
67 rx.setPattern ("</p>");
70 // remove all remaining tags
71 rx.setPattern ("<.*>");
74 // If string starts with \n now, remove it.
75 // It would be wrong in an OOo export for example
76 while (r.at(0)=='\n') r.remove (0,1);
78 // convert "&", "<" and ">"
79 rx.setPattern (">");
81 rx.setPattern ("<");
83 rx.setPattern ("&");
85 rx.setPattern (""");
89 rx.setPattern ("^\n");
90 r.replace (rx,indent);
91 r=indent + r; // Don't forget first line
93 /* FIXME wrap text at width
94 if (fonthint !="fixed")
98 r=indent+"\n"+r+indent+"\n\n";
102 QString NoteObj::getNoteOpenDoc()
104 // Evil hack to transform QT Richtext into
105 // something which can be used in OpenDoc format
107 // TODO create clean XML transformation which also
108 // considers fonts, colors, ...
112 // convert all "<br*>"
113 QRegExp re("<br.*>");
115 r.replace (re,"<text:line-break/>");
118 re.setPattern ("<p>");
119 r.replace (re,"<text:line-break/>");
121 // Remove all other tags, e.g. paragraphs will be added in
122 // templates used during export
123 re.setPattern ("</?html.*>");
125 re.setPattern ("</?head.*>");
127 re.setPattern ("</?body.*>");
129 re.setPattern ("</?meta.*>");
131 re.setPattern ("</?span.*>");
133 re.setPattern ("</?p.*>");
136 r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
140 void NoteObj::setFontHint (const QString &s)
142 // only for backward compatibility (pre 1.5 )
146 QString NoteObj::getFontHint()
148 // only for backward compatibility (pre 1.5 )
152 void NoteObj::setFilenameHint (const QString &s)
157 QString NoteObj::getFilenameHint()
162 bool NoteObj::isEmpty ()
164 return note.isEmpty();
167 QString NoteObj::saveToDir ()
171 // Remove the doctype, which will confuse parsing
172 // with XmlReader in Qt >= 4.4
173 QRegExp rx("<!DOCTYPE.*>");
178 // QTextEdit may generate fontnames with unquoted &, like
179 // in "Lucida B&H". This is invalid in XML and thus would crash
182 // More invalid XML is generated with bullet lists:
183 // There are 2 <style> tags in one <li>, so we merge them here
185 bool inbracket=false;
189 while (pos<n.length())
191 if (n.mid(pos,1)=="<")
196 if (n.mid(pos,1)==">")
199 QString s=n.mid(begin_bracket,pos-begin_bracket+1);
201 if (s.count("style=\"")>1)
203 rx.setPattern ("style=\\s*\"(.*)\"\\s*style=\\s*\"(.*)\"");
204 s.replace(rx,"style=\"\\1 \\2\"");
205 n.replace (begin_bracket,sl,s);
206 pos=pos-(sl-s.length());
209 if (n.mid(pos,1)=="\"" && inbracket)
216 if (n.mid(pos,1)=="&" && inquot)
218 // Now we are inside < " " >
219 n.replace(pos,1,"&");
224 return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");