-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHtmlExport.cpp
98 lines (84 loc) · 3.68 KB
/
HtmlExport.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "HtmlExport.h"
#include "Note.h"
#include "ImageNote.h"
#include "Article.h"
#include "VideoNote.h"
#include "AudioNote.h"
#include "Document.h"
#include "ExportStrategy.h"
#include <QString>
//Html Export
QString HtmlExport::header() const
{
return "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd\">"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">"
"p, li { white-space: pre-wrap; }"
"</style></head><body style=\" font-family:'Lucida Grande'; font-size:13pt; font-weight:400; font-style:normal;\">";
}
QString HtmlExport::footer() const
{
return "</body></html>";
}
QString HtmlExport::exportNote(const ImageNote *note, unsigned int level) const
{
QString str;
// Shoud implement a limit on margin...TODO
int margin = level * 10;
int titleSize = (level > 5) ? 5 : level;
str+= "<div style=\"margin-left:"+QString::number(margin)+"px\";>";
str+="<h"+QString::number(titleSize+1)+">"+note->getTitle()+ \
"</h"+QString::number(titleSize+1)+"><p><img style=\"width: 100% margin:\" src=\"file://"+note->getMediaPath()+"\"></p><p>"\
+note->getDescription()+"</p></div>";
return str;
}
QString HtmlExport::exportNote(const Article *note, unsigned int level) const
{
QString str;
QString text = note->getText();
text.replace(QString("\n"), QString("<br>"));
// Shoud implement a limit on margin...TODO
int margin = level * 10;
int titleSize = (level > 5) ? 5 : level;
str+= "<div style=\"margin-left:"+QString::number(margin)+"px\";>";
str+="<h"+QString::number(titleSize+1)+">"+note->getTitle()+ \
"</h"+QString::number(titleSize+1)+"><p>"+text+"</p></div>";
return str;
}
QString HtmlExport::exportNote(const AudioNote *note, unsigned int level) const
{
QString str;
// Shoud implement a limit on margin...TODO
int margin = level * 10;
int titleSize = (level > 5) ? 5 : level;
str+= "<div style=\"margin-left:"+QString::number(margin)+"px\";>";
str+="<h"+QString::number(titleSize+1)+">"+note->getTitle()+ \
"</h"+QString::number(titleSize+1)+"><p>"+"<audio controls><source src=\"file:///"+note->getMediaPath()+"\" type=\"audio/ogg\"><source src=\"file:///"+note->getMediaPath()+"\" type=\"audio/mp3\">Your browser does not support the audio element.</audio><p>"+note->getDescription()+"</p></p></div>";
return str;
}
QString HtmlExport::exportNote(const VideoNote *note, unsigned int level) const
{
QString str;
// Shoud implement a limit on margin...TODO
int margin = level * 10;
int titleSize = (level > 5) ? 5 : level;
str+= "<div style=\"margin-left:"+QString::number(margin)+"px\";>";
str+="<h"+QString::number(titleSize+1)+">"+note->getTitle()+ \
"</h"+QString::number(titleSize+1)+"><p>"+"<video width=\"640\" height=\"480\" controls><source src=\"file:///"+note->getMediaPath()+"\" type=\"video/mp4\"><source src=\"file:///"+note->getMediaPath()+"\" type=\"video/avi\">Your browser does not support the video tag.</video><p>"+note->getDescription()+"</p></p></div>";
return str;
}
QString HtmlExport::exportNote(const Document *doc, unsigned int level) const
{
QString str;
int margin = level * 10;
int titleSize = (level > 5) ? 5 : level;
str+= "<div style=\"margin-left:"+QString::number(margin)+"px\";>";
str+="<h"+QString::number(titleSize+1)+">"+doc->getTitle()+ \
"</h"+QString::number(titleSize+1)+"><p>";
++level;
for(QList<Note *>::const_iterator it = doc->begin(); it!=doc->end(); it++)
{
str+=(*it)->exportNote(this, level);
}
str+="</p></div>";
return str;
}