Changeset View
Changeset View
Standalone View
Standalone View
src/renderer/KReportHTMLCSSRenderer_p.cpp
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | 85 | { | |||
---|---|---|---|---|---|
88 | QString style; | 88 | QString style; | ||
89 | QStringList styles; | 89 | QStringList styles; | ||
90 | int styleindex; | 90 | int styleindex; | ||
91 | bool renderedPageHead = false; | 91 | bool renderedPageHead = false; | ||
92 | bool renderedPageFoot = false; | 92 | bool renderedPageFoot = false; | ||
93 | 93 | | |||
94 | QDir d(m_tempDirName); | 94 | QDir d(m_tempDirName); | ||
95 | // Render Each Section | 95 | // Render Each Section | ||
96 | for (long s = 0; s < document->sections(); s++) { | 96 | for (long s = 0; s < document->sectionCount(); s++) { | ||
staniek: long -> int | |||||
staniek: TODO | |||||
97 | OROSection *section = document->section(s); | 97 | OROSection *section = document->section(s); | ||
98 | 98 | | |||
99 | if (section->type() == KReportSectionData::GroupHeader || | 99 | if (section->type() == KReportSectionData::GroupHeader || | ||
100 | section->type() == KReportSectionData::GroupFooter || | 100 | section->type() == KReportSectionData::GroupFooter || | ||
101 | section->type() == KReportSectionData::Detail || | 101 | section->type() == KReportSectionData::Detail || | ||
102 | section->type() == KReportSectionData::ReportHeader || | 102 | section->type() == KReportSectionData::ReportHeader || | ||
103 | section->type() == KReportSectionData::ReportFooter || | 103 | section->type() == KReportSectionData::ReportFooter || | ||
104 | (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHead) || | 104 | (section->type() == KReportSectionData::PageHeaderAny && !renderedPageHead) || | ||
105 | (section->type() == KReportSectionData::PageFooterAny && !renderedPageFoot && s > document->sections() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer | 105 | (section->type() == KReportSectionData::PageFooterAny && !renderedPageFoot && s > document->sectionCount() - 2)) { //render the page foot right at the end, it will either be the last or second last section if there is a report footer | ||
106 | if (section->type() == KReportSectionData::PageHeaderAny) | 106 | if (section->type() == KReportSectionData::PageHeaderAny) | ||
107 | renderedPageHead = true; | 107 | renderedPageHead = true; | ||
108 | 108 | | |||
109 | if (section->type() == KReportSectionData::PageFooterAny) | 109 | if (section->type() == KReportSectionData::PageFooterAny) | ||
110 | renderedPageFoot = true; | 110 | renderedPageFoot = true; | ||
111 | 111 | | |||
112 | style = QLatin1String("position: relative; top: 0pt; left: 0pt; background-color: ") + section->backgroundColor().name() + QLatin1String("; height: ") + QString::number(section->height()) + QLatin1String("pt;"); | 112 | style = QLatin1String("position: relative; top: 0pt; left: 0pt; background-color: ") + section->backgroundColor().name() + QLatin1String("; height: ") + QString::number(section->height()) + QLatin1String("pt;"); | ||
113 | 113 | | |||
114 | if (!styles.contains(style)) { | 114 | if (!styles.contains(style)) { | ||
115 | styles << style; | 115 | styles << style; | ||
116 | } | 116 | } | ||
117 | styleindex = styles.indexOf(style); | 117 | styleindex = styles.indexOf(style); | ||
118 | 118 | | |||
119 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">\n"); | 119 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">\n"); | ||
120 | //Render the objects in each section | 120 | //Render the objects in each section | ||
121 | for (int i = 0; i < section->primitives(); i++) { | 121 | for (int i = 0; i < section->primitiveCount(); i++) { | ||
122 | OROPrimitive * prim = section->primitive(i); | 122 | OROPrimitive * prim = section->primitive(i); | ||
123 | //kreportDebug() << "Got object type" << prim->type(); | 123 | //kreportDebug() << "Got object type" << prim->type(); | ||
124 | if (prim->type() == OROTextBox::TextBox) { | 124 | if (dynamic_cast<OROTextBox*>(prim)) { | ||
125 | OROTextBox * tb = (OROTextBox*) prim; | 125 | OROTextBox * tb = dynamic_cast<OROTextBox*>(prim); | ||
126 | 126 | | |||
127 | QColor bg = tb->textStyle().backgroundColor; | 127 | QColor bg = tb->textStyle().backgroundColor; | ||
128 | style = QLatin1String("position: absolute; ") + | 128 | style = QLatin1String("position: absolute; ") + | ||
129 | QLatin1String("background-color: ") + QString::fromLatin1("rgba(%1,%2,%3,%4)") | 129 | QLatin1String("background-color: ") + QString::fromLatin1("rgba(%1,%2,%3,%4)") | ||
130 | .arg(bg.red()) | 130 | .arg(bg.red()) | ||
131 | .arg(bg.green()) | 131 | .arg(bg.green()) | ||
132 | .arg(bg.blue()) | 132 | .arg(bg.blue()) | ||
133 | .arg(0.01 * tb->textStyle().backgroundOpacity) +QLatin1String( "; ") + | 133 | .arg(0.01 * tb->textStyle().backgroundOpacity) +QLatin1String( "; ") + | ||
Show All 12 Lines | |||||
146 | if (!styles.contains(style)) { | 146 | if (!styles.contains(style)) { | ||
147 | styles << style; | 147 | styles << style; | ||
148 | } | 148 | } | ||
149 | styleindex = styles.indexOf(style); | 149 | styleindex = styles.indexOf(style); | ||
150 | 150 | | |||
151 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | 151 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | ||
152 | tb->text() + | 152 | tb->text() + | ||
153 | QLatin1String("</div>\n"); | 153 | QLatin1String("</div>\n"); | ||
154 | } else if (prim->type() == OROImage::Image) { | 154 | } else if (dynamic_cast<OROImage*>(prim)) { | ||
155 | //kreportDebug() << "Saving an image"; | 155 | //kreportDebug() << "Saving an image"; | ||
156 | OROImage * im = (OROImage*) prim; | 156 | OROImage * im = dynamic_cast<OROImage*>(prim); | ||
157 | style = QLatin1String("position: absolute; ") + | 157 | style = QLatin1String("position: absolute; ") + | ||
158 | QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + | 158 | QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + | ||
159 | QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); | 159 | QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); | ||
160 | if (!styles.contains(style)) { | 160 | if (!styles.contains(style)) { | ||
161 | styles << style; | 161 | styles << style; | ||
162 | } | 162 | } | ||
163 | styleindex = styles.indexOf(style); | 163 | styleindex = styles.indexOf(style); | ||
164 | 164 | | |||
165 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | 165 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | ||
166 | QLatin1String("<img width=\"") + QString::number(im->size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\"></img>") + | 166 | QLatin1String("<img width=\"") + QString::number(im->size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\"></img>") + | ||
167 | QLatin1String("</div>\n"); | 167 | QLatin1String("</div>\n"); | ||
168 | 168 | | |||
169 | 169 | | |||
170 | im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); | 170 | im->image().save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); | ||
171 | } else if (prim->type() == OROPicture::Picture) { | 171 | } else if (dynamic_cast<OROPicture*>(prim)) { | ||
172 | //kreportDebug() << "Saving a picture"; | 172 | //kreportDebug() << "Saving a picture"; | ||
173 | OROPicture * im = (OROPicture*) prim; | 173 | OROPicture * im = dynamic_cast<OROPicture*>(prim); | ||
174 | style = QLatin1String("position: absolute; ") + | 174 | style = QLatin1String("position: absolute; ") + | ||
175 | QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + | 175 | QLatin1String("top: ") + QString::number(im->position().y()) + QLatin1String("pt; ") + | ||
176 | QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); | 176 | QLatin1String("left: ") + QString::number(im->position().x()) + QLatin1String("pt; "); | ||
177 | if (!styles.contains(style)) { | 177 | if (!styles.contains(style)) { | ||
178 | styles << style; | 178 | styles << style; | ||
179 | } | 179 | } | ||
180 | styleindex = styles.indexOf(style); | 180 | styleindex = styles.indexOf(style); | ||
181 | 181 | | |||
182 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | 182 | body += QLatin1String("<div class=\"style") + QString::number(styleindex) + QLatin1String("\">") + | ||
183 | QLatin1String("<img width=\"") + QString::number(im->size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\"></img>") + | 183 | QLatin1String("<img width=\"") + QString::number(im->size().width()) + QLatin1String("px") + QLatin1String("\" height=\"") + QString::number(im->size().height()) + QLatin1String("px") + QLatin1String("\" src=\"./") + m_actualDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png\"></img>") + | ||
184 | QLatin1String("</div>\n"); | 184 | QLatin1String("</div>\n"); | ||
185 | 185 | | |||
186 | QImage image(im->size().toSize(), QImage::Format_RGB32); | 186 | QImage image(im->size().toSize(), QImage::Format_RGB32); | ||
187 | QPainter painter(&image); | 187 | QPainter painter(&image); | ||
188 | im->picture()->play(&painter); | 188 | im->picture()->play(&painter); | ||
189 | image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); | 189 | image.save(m_tempDirName + QLatin1String("/object") + QString::number(s) + QString::number(i) + QLatin1String(".png")); | ||
190 | } else { | 190 | } else { | ||
191 | kreportWarning() << "unrecognized primitive type" << prim->type(); | 191 | kreportWarning() << "unrecognized primitive type"; | ||
192 | } | 192 | } | ||
193 | } | 193 | } | ||
194 | body += QLatin1String("</div>\n"); | 194 | body += QLatin1String("</div>\n"); | ||
195 | } | 195 | } | ||
196 | } | 196 | } | ||
197 | 197 | | |||
198 | //! @todo add option for creating separate css file | 198 | //! @todo add option for creating separate css file | ||
199 | html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" | 199 | html = QLatin1String("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" | ||
Show All 23 Lines |
long -> int