1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/noteobj.cpp Sun Jan 30 12:59:03 2005 +0000
1.3 @@ -0,0 +1,105 @@
1.4 +#include <qfile.h>
1.5 +#include <qtextstream.h>
1.6 +#include <qmessagebox.h>
1.7 +#include <qregexp.h>
1.8 +
1.9 +#include "noteobj.h"
1.10 +
1.11 +/////////////////////////////////////////////////////////////////
1.12 +// NoteObj
1.13 +/////////////////////////////////////////////////////////////////
1.14 +
1.15 +NoteObj::NoteObj()
1.16 +{
1.17 + clear();
1.18 +}
1.19 +
1.20 +void NoteObj::copy (NoteObj other)
1.21 +{
1.22 + note=other.note;
1.23 + fonthint=other.fonthint;
1.24 + filenamehint="";
1.25 +}
1.26 +
1.27 +void NoteObj::clear()
1.28 +{
1.29 + note="";
1.30 + fonthint="undef";
1.31 + filenamehint="";
1.32 +}
1.33 +
1.34 +void NoteObj::setNote (const QString &s)
1.35 +{
1.36 + note=s;
1.37 +}
1.38 +
1.39 +QString NoteObj::getNote()
1.40 +{
1.41 + return note;
1.42 +}
1.43 +
1.44 +void NoteObj::setFontHint (const QString &s)
1.45 +{
1.46 + // only for backward compatibility (pre 1.5 )
1.47 + fonthint=s;
1.48 +}
1.49 +
1.50 +QString NoteObj::getFontHint()
1.51 +{
1.52 + // only for backward compatibility (pre 1.5 )
1.53 + return fonthint;
1.54 +}
1.55 +
1.56 +void NoteObj::setFilenameHint (const QString &s)
1.57 +{
1.58 + filenamehint=s;
1.59 +}
1.60 +
1.61 +QString NoteObj::getFilenameHint()
1.62 +{
1.63 + return filenamehint;
1.64 +}
1.65 +
1.66 +bool NoteObj::isEmpty ()
1.67 +{
1.68 + return note.isEmpty();
1.69 +}
1.70 +
1.71 +QString NoteObj::saveToDir ()
1.72 +{
1.73 + // QTextEdit may generate fontnames with unquoted &, like
1.74 + // in "Lucida B&H". This is invalid in XML and thus would crash
1.75 + // the XML parser
1.76 + uint pos=0;
1.77 + uint pos2;
1.78 + bool inbracket=false;
1.79 + bool inquot=false;
1.80 + while (pos<note.length())
1.81 + {
1.82 + if (note.mid(pos,1)=="<") inbracket=true;
1.83 + if (note.mid(pos,1)==">") inbracket=false;
1.84 + if (note.mid(pos,1)=="\"" && inbracket)
1.85 + {
1.86 + if (!inquot)
1.87 + inquot=true;
1.88 + else
1.89 + inquot=false;
1.90 + }
1.91 + if (note.mid(pos,1)=="&" && inquot)
1.92 + {
1.93 + // Now we are inside < " " >
1.94 + // look for ending "
1.95 + pos2=pos+1;
1.96 + while (note.mid(pos2,1)!=";" && note.mid(pos2,1)!="\"")
1.97 + pos2++;
1.98 + if (note.mid(pos2,1)=="\"")
1.99 + {
1.100 + note.replace(pos,1,"&");
1.101 + pos=pos2;
1.102 + }
1.103 + }
1.104 + pos++;
1.105 + }
1.106 + return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ note+ "\n" +endElement ("htmlnote");
1.107 +}
1.108 +