insilmaril@0
|
1 |
#include <qfile.h>
|
insilmaril@0
|
2 |
#include <qtextstream.h>
|
insilmaril@0
|
3 |
#include <qmessagebox.h>
|
insilmaril@0
|
4 |
#include <qregexp.h>
|
insilmaril@0
|
5 |
|
insilmaril@0
|
6 |
#include "noteobj.h"
|
insilmaril@0
|
7 |
|
insilmaril@0
|
8 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
9 |
// NoteObj
|
insilmaril@0
|
10 |
/////////////////////////////////////////////////////////////////
|
insilmaril@0
|
11 |
|
insilmaril@0
|
12 |
NoteObj::NoteObj()
|
insilmaril@0
|
13 |
{
|
insilmaril@0
|
14 |
clear();
|
insilmaril@0
|
15 |
}
|
insilmaril@0
|
16 |
|
insilmaril@185
|
17 |
NoteObj::NoteObj(const QString &s)
|
insilmaril@185
|
18 |
{
|
insilmaril@185
|
19 |
clear();
|
insilmaril@185
|
20 |
note=s;
|
insilmaril@185
|
21 |
}
|
insilmaril@185
|
22 |
|
insilmaril@0
|
23 |
void NoteObj::copy (NoteObj other)
|
insilmaril@0
|
24 |
{
|
insilmaril@0
|
25 |
note=other.note;
|
insilmaril@0
|
26 |
fonthint=other.fonthint;
|
insilmaril@0
|
27 |
filenamehint="";
|
insilmaril@0
|
28 |
}
|
insilmaril@0
|
29 |
|
insilmaril@0
|
30 |
void NoteObj::clear()
|
insilmaril@0
|
31 |
{
|
insilmaril@0
|
32 |
note="";
|
insilmaril@0
|
33 |
fonthint="undef";
|
insilmaril@0
|
34 |
filenamehint="";
|
insilmaril@0
|
35 |
}
|
insilmaril@0
|
36 |
|
insilmaril@0
|
37 |
void NoteObj::setNote (const QString &s)
|
insilmaril@0
|
38 |
{
|
insilmaril@0
|
39 |
note=s;
|
insilmaril@0
|
40 |
}
|
insilmaril@0
|
41 |
|
insilmaril@0
|
42 |
QString NoteObj::getNote()
|
insilmaril@0
|
43 |
{
|
insilmaril@0
|
44 |
return note;
|
insilmaril@0
|
45 |
}
|
insilmaril@0
|
46 |
|
insilmaril@185
|
47 |
QString NoteObj::getNoteASCII()
|
insilmaril@185
|
48 |
{
|
insilmaril@185
|
49 |
QString r=note;
|
insilmaril@185
|
50 |
|
insilmaril@185
|
51 |
// convert all "<br*>" to "\n"
|
insilmaril@185
|
52 |
QRegExp re("<br.*>");
|
insilmaril@185
|
53 |
re.setMinimal(true);
|
insilmaril@185
|
54 |
r.replace (re,"\n");
|
insilmaril@185
|
55 |
|
insilmaril@185
|
56 |
// convert all "</p>" to "\n"
|
insilmaril@185
|
57 |
re.setPattern ("</p>");
|
insilmaril@185
|
58 |
r.replace (re,"\n");
|
insilmaril@185
|
59 |
|
insilmaril@185
|
60 |
// remove all remaining tags
|
insilmaril@185
|
61 |
re.setPattern ("<.*>");
|
insilmaril@185
|
62 |
r.replace (re,"");
|
insilmaril@185
|
63 |
|
insilmaril@185
|
64 |
// If string starts with \n now, remove it.
|
insilmaril@185
|
65 |
// It would be wrong in an OOo export for example
|
insilmaril@185
|
66 |
while (r.at(0)=='\n') r.remove (0,1);
|
insilmaril@185
|
67 |
|
insilmaril@185
|
68 |
// convert "&", "<" and ">"
|
insilmaril@185
|
69 |
re.setPattern (">");
|
insilmaril@185
|
70 |
r.replace (re,">");
|
insilmaril@185
|
71 |
re.setPattern ("<");
|
insilmaril@185
|
72 |
r.replace (re,"<");
|
insilmaril@185
|
73 |
re.setPattern ("&");
|
insilmaril@185
|
74 |
r.replace (re,"&");
|
insilmaril@185
|
75 |
re.setPattern (""");
|
insilmaril@185
|
76 |
r.replace (re,"\"");
|
insilmaril@185
|
77 |
|
insilmaril@185
|
78 |
return r;
|
insilmaril@185
|
79 |
}
|
insilmaril@185
|
80 |
|
insilmaril@185
|
81 |
QString NoteObj::getNoteOpenDoc()
|
insilmaril@185
|
82 |
{
|
insilmaril@185
|
83 |
// Evil hack to transform QT Richtext into
|
insilmaril@185
|
84 |
// something which can be used in OpenDoc format
|
insilmaril@185
|
85 |
//
|
insilmaril@185
|
86 |
// TODO create clean XML transformation which also
|
insilmaril@185
|
87 |
// considers fonts, colors, ...
|
insilmaril@185
|
88 |
|
insilmaril@185
|
89 |
QString r=note;
|
insilmaril@185
|
90 |
|
insilmaril@185
|
91 |
// convert all "<br*>"
|
insilmaril@185
|
92 |
QRegExp re("<br.*>");
|
insilmaril@185
|
93 |
re.setMinimal(true);
|
insilmaril@185
|
94 |
r.replace (re,"<text:line-break/>");
|
insilmaril@185
|
95 |
|
insilmaril@185
|
96 |
// convert all "<p>"
|
insilmaril@185
|
97 |
re.setPattern ("<p>");
|
insilmaril@185
|
98 |
r.replace (re,"<text:line-break/>");
|
insilmaril@185
|
99 |
|
insilmaril@185
|
100 |
// Remove all other tags, e.g. paragraphs will be added in
|
insilmaril@185
|
101 |
// templates used during export
|
insilmaril@185
|
102 |
re.setPattern ("</?html.*>");
|
insilmaril@185
|
103 |
r.replace (re,"");
|
insilmaril@185
|
104 |
re.setPattern ("</?head.*>");
|
insilmaril@185
|
105 |
r.replace (re,"");
|
insilmaril@185
|
106 |
re.setPattern ("</?body.*>");
|
insilmaril@185
|
107 |
r.replace (re,"");
|
insilmaril@185
|
108 |
re.setPattern ("</?meta.*>");
|
insilmaril@185
|
109 |
r.replace (re,"");
|
insilmaril@185
|
110 |
re.setPattern ("</?span.*>");
|
insilmaril@185
|
111 |
r.replace (re,"");
|
insilmaril@185
|
112 |
re.setPattern ("</?p.*>");
|
insilmaril@185
|
113 |
r.replace (re,"");
|
insilmaril@185
|
114 |
|
insilmaril@185
|
115 |
r="<text:span text:style-name=\"vym-notestyle\">"+r+"</text:span>";
|
insilmaril@185
|
116 |
return r;
|
insilmaril@185
|
117 |
}
|
insilmaril@185
|
118 |
|
insilmaril@0
|
119 |
void NoteObj::setFontHint (const QString &s)
|
insilmaril@0
|
120 |
{
|
insilmaril@0
|
121 |
// only for backward compatibility (pre 1.5 )
|
insilmaril@0
|
122 |
fonthint=s;
|
insilmaril@0
|
123 |
}
|
insilmaril@0
|
124 |
|
insilmaril@0
|
125 |
QString NoteObj::getFontHint()
|
insilmaril@0
|
126 |
{
|
insilmaril@0
|
127 |
// only for backward compatibility (pre 1.5 )
|
insilmaril@0
|
128 |
return fonthint;
|
insilmaril@0
|
129 |
}
|
insilmaril@0
|
130 |
|
insilmaril@0
|
131 |
void NoteObj::setFilenameHint (const QString &s)
|
insilmaril@0
|
132 |
{
|
insilmaril@0
|
133 |
filenamehint=s;
|
insilmaril@0
|
134 |
}
|
insilmaril@0
|
135 |
|
insilmaril@0
|
136 |
QString NoteObj::getFilenameHint()
|
insilmaril@0
|
137 |
{
|
insilmaril@0
|
138 |
return filenamehint;
|
insilmaril@0
|
139 |
}
|
insilmaril@0
|
140 |
|
insilmaril@0
|
141 |
bool NoteObj::isEmpty ()
|
insilmaril@0
|
142 |
{
|
insilmaril@0
|
143 |
return note.isEmpty();
|
insilmaril@0
|
144 |
}
|
insilmaril@0
|
145 |
|
insilmaril@0
|
146 |
QString NoteObj::saveToDir ()
|
insilmaril@0
|
147 |
{
|
insilmaril@0
|
148 |
// QTextEdit may generate fontnames with unquoted &, like
|
insilmaril@0
|
149 |
// in "Lucida B&H". This is invalid in XML and thus would crash
|
insilmaril@0
|
150 |
// the XML parser
|
insilmaril@0
|
151 |
uint pos=0;
|
insilmaril@0
|
152 |
bool inbracket=false;
|
insilmaril@0
|
153 |
bool inquot=false;
|
insilmaril@251
|
154 |
QString n=note;
|
insilmaril@251
|
155 |
while (pos<n.length())
|
insilmaril@0
|
156 |
{
|
insilmaril@251
|
157 |
if (n.mid(pos,1)=="<") inbracket=true;
|
insilmaril@251
|
158 |
if (n.mid(pos,1)==">") inbracket=false;
|
insilmaril@251
|
159 |
if (n.mid(pos,1)=="\"" && inbracket)
|
insilmaril@0
|
160 |
{
|
insilmaril@0
|
161 |
if (!inquot)
|
insilmaril@0
|
162 |
inquot=true;
|
insilmaril@0
|
163 |
else
|
insilmaril@0
|
164 |
inquot=false;
|
insilmaril@0
|
165 |
}
|
insilmaril@251
|
166 |
if (n.mid(pos,1)=="&" && inquot)
|
insilmaril@0
|
167 |
{
|
insilmaril@0
|
168 |
// Now we are inside < " " >
|
insilmaril@251
|
169 |
n.replace(pos,1,"&");
|
insilmaril@251
|
170 |
pos=pos+3;
|
insilmaril@0
|
171 |
}
|
insilmaril@0
|
172 |
pos++;
|
insilmaril@0
|
173 |
}
|
insilmaril@251
|
174 |
return beginElement ("htmlnote",attribut("fonthint",fonthint)) + "\n"+ n+ "\n" +endElement ("htmlnote");
|
insilmaril@0
|
175 |
}
|
insilmaril@0
|
176 |
|