noteobj.cpp
changeset 185 6691000c3262
parent 0 7a96bd401351
child 251 795d0eb5700f
     1.1 --- a/noteobj.cpp	Sun Jan 30 12:58:47 2005 +0000
     1.2 +++ b/noteobj.cpp	Tue Jan 24 15:09:48 2006 +0000
     1.3 @@ -14,6 +14,12 @@
     1.4  	clear();
     1.5  }
     1.6  
     1.7 +NoteObj::NoteObj(const QString &s)
     1.8 +{
     1.9 +	clear();
    1.10 +	note=s;
    1.11 +}
    1.12 +
    1.13  void NoteObj::copy (NoteObj other)
    1.14  {
    1.15  	note=other.note;
    1.16 @@ -38,6 +44,78 @@
    1.17  	return note;
    1.18  }
    1.19  
    1.20 +QString NoteObj::getNoteASCII()
    1.21 +{
    1.22 +	QString r=note;
    1.23 +
    1.24 +	// convert all "<br*>" to "\n"
    1.25 +	QRegExp re("<br.*>");
    1.26 +	re.setMinimal(true);
    1.27 +	r.replace (re,"\n");
    1.28 +
    1.29 +	// convert all "</p>" to "\n"
    1.30 +	re.setPattern ("</p>");
    1.31 +	r.replace (re,"\n");
    1.32 +	
    1.33 +	// remove all remaining tags 
    1.34 +	re.setPattern ("<.*>");
    1.35 +	r.replace (re,"");
    1.36 +
    1.37 +	// If string starts with \n now, remove it.
    1.38 +	// It would be wrong in an OOo export for example
    1.39 +	while (r.at(0)=='\n') r.remove (0,1);
    1.40 +	
    1.41 +	// convert "&", "<" and ">"
    1.42 +	re.setPattern ("&gt;");
    1.43 +	r.replace (re,">");
    1.44 +	re.setPattern ("&lt;");
    1.45 +	r.replace (re,"<");
    1.46 +	re.setPattern ("&amp;");
    1.47 +	r.replace (re,"&");
    1.48 +	re.setPattern ("&quot;");
    1.49 +	r.replace (re,"\"");
    1.50 +
    1.51 +	return r;
    1.52 +}
    1.53 +
    1.54 +QString NoteObj::getNoteOpenDoc()
    1.55 +{
    1.56 +	// Evil hack to transform QT Richtext into
    1.57 +	// something which can be used in OpenDoc format
    1.58 +	// 
    1.59 +	// TODO create clean XML transformation which also
    1.60 +	// considers fonts, colors, ...
    1.61 +
    1.62 +	QString r=note;
    1.63 +
    1.64 +	// convert all "<br*>"
    1.65 +	QRegExp re("<br.*>");
    1.66 +	re.setMinimal(true);
    1.67 +	r.replace (re,"<text:line-break/>");
    1.68 +
    1.69 +	// convert all "<p>" 
    1.70 +	re.setPattern ("<p>");
    1.71 +	r.replace (re,"<text:line-break/>");
    1.72 +	
    1.73 +	// Remove all other tags, e.g. paragraphs will be added in 
    1.74 +	// templates used during export
    1.75 +	re.setPattern ("</?html.*>");
    1.76 +	r.replace (re,"");
    1.77 +	re.setPattern ("</?head.*>");
    1.78 +	r.replace (re,"");
    1.79 +	re.setPattern ("</?body.*>");
    1.80 +	r.replace (re,"");
    1.81 +	re.setPattern ("</?meta.*>");
    1.82 +	r.replace (re,"");
    1.83 +	re.setPattern ("</?span.*>");
    1.84 +	r.replace (re,"");
    1.85 +	re.setPattern ("</?p.*>");
    1.86 +	r.replace (re,"");
    1.87 +
    1.88 +	r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
    1.89 +	return r;
    1.90 +}
    1.91 +
    1.92  void NoteObj::setFontHint (const QString &s)
    1.93  {
    1.94  	// only for backward compatibility (pre 1.5 )