insilmaril@842: #include "noteobj.h"
insilmaril@0:
insilmaril@842: #include
insilmaril@842: #include
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@746: void NoteObj::operator= (const NoteObj &other)
insilmaril@746: {
insilmaril@746: copy (other);
insilmaril@746: }
insilmaril@746:
insilmaril@0: void NoteObj::copy (NoteObj other)
insilmaril@0: {
insilmaril@0: note=other.note;
insilmaril@0: fonthint=other.fonthint;
insilmaril@746: filenamehint=other.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@746: QString NoteObj::getNote() const
insilmaril@0: {
insilmaril@0: return note;
insilmaril@0: }
insilmaril@0:
insilmaril@185: QString NoteObj::getNoteASCII()
insilmaril@185: {
insilmaril@842: return getNoteASCII ("",80);
insilmaril@613: }
insilmaril@613:
insilmaril@842: QString NoteObj::getNoteASCII(QString indent, const int &width)
insilmaril@613: {
insilmaril@842: if (note.isEmpty()) return note;
insilmaril@185: QString r=note;
insilmaril@185:
insilmaril@551: // Remove all ...
insilmaril@551: QRegExp rx (".*");
insilmaril@551: rx.setMinimal(true);
insilmaril@551: r.replace (rx,"");
insilmaril@551:
insilmaril@185: // convert all "
" to "\n"
insilmaril@551: rx.setPattern ("");
insilmaril@551: r.replace (rx,"\n");
insilmaril@185:
insilmaril@185: // convert all "
" to "\n"
insilmaril@551: rx.setPattern ("");
insilmaril@551: r.replace (rx,"\n");
insilmaril@185:
insilmaril@185: // remove all remaining tags
insilmaril@551: rx.setPattern ("<.*>");
insilmaril@551: r.replace (rx,"");
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@551: rx.setPattern (">");
insilmaril@551: r.replace (rx,">");
insilmaril@551: rx.setPattern ("<");
insilmaril@551: r.replace (rx,"<");
insilmaril@551: rx.setPattern ("&");
insilmaril@551: r.replace (rx,"&");
insilmaril@551: rx.setPattern (""");
insilmaril@551: r.replace (rx,"\"");
insilmaril@185:
insilmaril@663: // Indent everything
insilmaril@663: rx.setPattern ("^\n");
insilmaril@663: r.replace (rx,indent);
insilmaril@663: r=indent + r; // Don't forget first line
insilmaril@663:
insilmaril@842: /* FIXME-3 wrap text at width
insilmaril@613: if (fonthint !="fixed")
insilmaril@613: {
insilmaril@613: }
insilmaril@613: */
insilmaril@693: r=indent+"\n"+r+indent+"\n\n";
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 ("?html.*>");
insilmaril@185: r.replace (re,"");
insilmaril@185: re.setPattern ("?head.*>");
insilmaril@185: r.replace (re,"");
insilmaril@185: re.setPattern ("?body.*>");
insilmaril@185: r.replace (re,"");
insilmaril@185: re.setPattern ("?meta.*>");
insilmaril@185: r.replace (re,"");
insilmaril@185: re.setPattern ("?span.*>");
insilmaril@185: r.replace (re,"");
insilmaril@185: re.setPattern ("?p.*>");
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@746: QString NoteObj::getFontHint() const
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@746: QString NoteObj::getFilenameHint() const
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@708: QString n=note;
insilmaril@708:
insilmaril@721: // Remove the doctype, which will confuse parsing
insilmaril@708: // with XmlReader in Qt >= 4.4
insilmaril@708: QRegExp rx("");
insilmaril@711: rx.setMinimal(true);
insilmaril@708: n.replace (rx,"");
insilmaril@721:
insilmaril@721:
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@551:
insilmaril@551: // More invalid XML is generated with bullet lists:
insilmaril@551: // There are 2