insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: #include insilmaril@0: insilmaril@0: #include "noteobj.h" insilmaril@0: insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: // NoteObj insilmaril@0: ///////////////////////////////////////////////////////////////// insilmaril@0: insilmaril@0: NoteObj::NoteObj() insilmaril@0: { insilmaril@0: clear(); insilmaril@0: } insilmaril@0: insilmaril@185: NoteObj::NoteObj(const QString &s) insilmaril@185: { insilmaril@185: clear(); insilmaril@185: note=s; insilmaril@185: } insilmaril@185: insilmaril@0: void NoteObj::copy (NoteObj other) insilmaril@0: { insilmaril@0: note=other.note; insilmaril@0: fonthint=other.fonthint; insilmaril@0: filenamehint=""; insilmaril@0: } insilmaril@0: insilmaril@0: void NoteObj::clear() insilmaril@0: { insilmaril@0: note=""; insilmaril@0: fonthint="undef"; insilmaril@0: filenamehint=""; insilmaril@0: } insilmaril@0: insilmaril@0: void NoteObj::setNote (const QString &s) insilmaril@0: { insilmaril@0: note=s; insilmaril@0: } insilmaril@0: insilmaril@0: QString NoteObj::getNote() insilmaril@0: { insilmaril@0: return note; insilmaril@0: } insilmaril@0: insilmaril@185: QString NoteObj::getNoteASCII() insilmaril@185: { insilmaril@185: QString r=note; insilmaril@185: insilmaril@185: // convert all "" to "\n" insilmaril@185: QRegExp re(""); insilmaril@185: re.setMinimal(true); insilmaril@185: r.replace (re,"\n"); insilmaril@185: insilmaril@185: // convert all "

" to "\n" insilmaril@185: re.setPattern ("

"); insilmaril@185: r.replace (re,"\n"); insilmaril@185: insilmaril@185: // remove all remaining tags insilmaril@185: re.setPattern ("<.*>"); insilmaril@185: r.replace (re,""); insilmaril@185: insilmaril@185: // If string starts with \n now, remove it. insilmaril@185: // It would be wrong in an OOo export for example insilmaril@185: while (r.at(0)=='\n') r.remove (0,1); insilmaril@185: insilmaril@185: // convert "&", "<" and ">" insilmaril@185: re.setPattern (">"); insilmaril@185: r.replace (re,">"); insilmaril@185: re.setPattern ("<"); insilmaril@185: r.replace (re,"<"); insilmaril@185: re.setPattern ("&"); insilmaril@185: r.replace (re,"&"); insilmaril@185: re.setPattern ("""); insilmaril@185: r.replace (re,"\""); insilmaril@185: insilmaril@185: return r; insilmaril@185: } insilmaril@185: insilmaril@185: QString NoteObj::getNoteOpenDoc() insilmaril@185: { insilmaril@185: // Evil hack to transform QT Richtext into insilmaril@185: // something which can be used in OpenDoc format insilmaril@185: // insilmaril@185: // TODO create clean XML transformation which also insilmaril@185: // considers fonts, colors, ... insilmaril@185: insilmaril@185: QString r=note; insilmaril@185: insilmaril@185: // convert all "" insilmaril@185: QRegExp re(""); insilmaril@185: re.setMinimal(true); insilmaril@185: r.replace (re,""); insilmaril@185: insilmaril@185: // convert all "

" insilmaril@185: re.setPattern ("

"); insilmaril@185: r.replace (re,""); insilmaril@185: insilmaril@185: // Remove all other tags, e.g. paragraphs will be added in insilmaril@185: // templates used during export insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: re.setPattern (""); insilmaril@185: r.replace (re,""); insilmaril@185: insilmaril@185: r=""+r+""; insilmaril@185: return r; insilmaril@185: } insilmaril@185: insilmaril@0: void NoteObj::setFontHint (const QString &s) insilmaril@0: { insilmaril@0: // only for backward compatibility (pre 1.5 ) insilmaril@0: fonthint=s; insilmaril@0: } insilmaril@0: insilmaril@0: QString NoteObj::getFontHint() insilmaril@0: { insilmaril@0: // only for backward compatibility (pre 1.5 ) insilmaril@0: return fonthint; insilmaril@0: } insilmaril@0: insilmaril@0: void NoteObj::setFilenameHint (const QString &s) insilmaril@0: { insilmaril@0: filenamehint=s; insilmaril@0: } insilmaril@0: insilmaril@0: QString NoteObj::getFilenameHint() insilmaril@0: { insilmaril@0: return filenamehint; insilmaril@0: } insilmaril@0: insilmaril@0: bool NoteObj::isEmpty () insilmaril@0: { insilmaril@0: return note.isEmpty(); insilmaril@0: } insilmaril@0: insilmaril@0: QString NoteObj::saveToDir () insilmaril@0: { insilmaril@0: // QTextEdit may generate fontnames with unquoted &, like insilmaril@0: // in "Lucida B&H". This is invalid in XML and thus would crash insilmaril@0: // the XML parser insilmaril@0: uint pos=0; insilmaril@0: uint pos2; insilmaril@0: bool inbracket=false; insilmaril@0: bool inquot=false; insilmaril@0: while (pos") inbracket=false; insilmaril@0: if (note.mid(pos,1)=="\"" && inbracket) insilmaril@0: { insilmaril@0: if (!inquot) insilmaril@0: inquot=true; insilmaril@0: else insilmaril@0: inquot=false; insilmaril@0: } insilmaril@0: if (note.mid(pos,1)=="&" && inquot) insilmaril@0: { insilmaril@0: // Now we are inside < " " > insilmaril@0: // look for ending " insilmaril@0: pos2=pos+1; insilmaril@0: while (note.mid(pos2,1)!=";" && note.mid(pos2,1)!="\"") insilmaril@0: pos2++; insilmaril@0: if (note.mid(pos2,1)=="\"") insilmaril@0: { insilmaril@0: note.replace(pos,1,"&"); insilmaril@0: pos=pos2; insilmaril@0: } insilmaril@0: } insilmaril@0: pos++; insilmaril@0: } insilmaril@0: return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ note+ "\n" +endElement ("htmlnote"); insilmaril@0: } insilmaril@0: