Changeset View
Changeset View
Standalone View
Standalone View
src/renderer/KReportPrintRenderer_p.cpp
Show First 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 70 | if (!context.painter->isActive()) { | |||
---|---|---|---|---|---|
72 | if (!context.painter->begin(context.printer)) | 72 | if (!context.painter->begin(context.printer)) | ||
73 | return false; | 73 | return false; | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | int fromPage = context.printer->fromPage(); | 76 | int fromPage = context.printer->fromPage(); | ||
77 | if (fromPage > 0) | 77 | if (fromPage > 0) | ||
78 | fromPage -= 1; | 78 | fromPage -= 1; | ||
79 | int toPage = context.printer->toPage(); | 79 | int toPage = context.printer->toPage(); | ||
80 | if (toPage == 0 || toPage > document->pages()) | 80 | if (toPage == 0 || toPage > document->pageCount()) | ||
81 | toPage = document->pages(); | 81 | toPage = document->pageCount(); | ||
82 | 82 | | |||
83 | qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX()); | 83 | qreal scaleX = context.printer->resolution() / qreal(KReportDpi::dpiX()); | ||
84 | qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY()); | 84 | qreal scaleY = context.printer->resolution() / qreal(KReportDpi::dpiY()); | ||
85 | 85 | | |||
86 | 86 | | |||
87 | for (int copy = 0; copy < context.printer->numCopies(); copy++) { | 87 | for (int copy = 0; copy < context.printer->numCopies(); copy++) { | ||
88 | for (int page = fromPage; page < toPage; page++) { | 88 | for (int page = fromPage; page < toPage; page++) { | ||
89 | if (page > fromPage) | 89 | if (page > fromPage) | ||
90 | context.printer->newPage(); | 90 | context.printer->newPage(); | ||
91 | 91 | | |||
92 | OROPage * p = document->page(page); | 92 | OROPage * p = document->page(page); | ||
93 | if (context.printer->pageOrder() == QPrinter::LastPageFirst) | 93 | if (context.printer->pageOrder() == QPrinter::LastPageFirst) | ||
94 | p = document->page(toPage - 1 - page); | 94 | p = document->page(toPage - 1 - page); | ||
95 | 95 | | |||
96 | // Render Page Objects | 96 | // Render Page Objects | ||
97 | for (int i = 0; i < p->primitives(); i++) { | 97 | for (int i = 0; i < p->primitiveCount(); i++) { | ||
98 | OROPrimitive * prim = p->primitive(i); | 98 | OROPrimitive * prim = p->primitive(i); | ||
99 | 99 | | |||
100 | 100 | | |||
101 | prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); | 101 | prim->setPosition(QPointF(prim->position().x() * scaleX, prim->position().y() * scaleY)); | ||
102 | prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); | 102 | prim->setSize(QSizeF(prim->size().width() * scaleX, prim->size().height() * scaleY)); | ||
103 | //kreportDebug() << "Rendering object" << i << "type" << prim->type(); | 103 | //kreportDebug() << "Rendering object" << i << "type" << prim->type(); | ||
104 | if (prim->type() == OROTextBox::TextBox) { | 104 | if (dynamic_cast<OROTextBox*>(prim)) { | ||
105 | //kreportDebug() << "Text Box"; | 105 | //kreportDebug() << "Text Box"; | ||
106 | OROTextBox * tb = (OROTextBox*) prim; | 106 | OROTextBox * tb = dynamic_cast<OROTextBox*>(prim); | ||
107 | 107 | | |||
108 | QPointF ps = tb->position(); | 108 | QPointF ps = tb->position(); | ||
109 | QSizeF sz = tb->size(); | 109 | QSizeF sz = tb->size(); | ||
110 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 110 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
111 | 111 | | |||
112 | context.painter->save(); | 112 | context.painter->save(); | ||
113 | //Background | 113 | //Background | ||
114 | 114 | | |||
Show All 11 Lines | |||||
126 | 126 | | |||
127 | //outer line | 127 | //outer line | ||
128 | context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); | 128 | context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width() * scaleX, tb->lineStyle().penStyle())); | ||
129 | context.painter->drawRect(rc); | 129 | context.painter->drawRect(rc); | ||
130 | 130 | | |||
131 | //Reset back to defaults for next element | 131 | //Reset back to defaults for next element | ||
132 | context.painter->restore(); | 132 | context.painter->restore(); | ||
133 | 133 | | |||
134 | } else if (prim->type() == OROLine::Line) { | 134 | } else if (dynamic_cast<OROLine*>(prim)) { | ||
135 | //kreportDebug() << "Line"; | 135 | //kreportDebug() << "Line"; | ||
136 | OROLine * ln = (OROLine*) prim; | 136 | OROLine * ln = dynamic_cast<OROLine*>(prim); | ||
137 | QPointF s = ln->startPoint(); | 137 | QPointF s = ln->startPoint(); | ||
138 | QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); | 138 | QPointF e(ln->endPoint().x() * scaleX, ln->endPoint().y() * scaleY); | ||
139 | //QPen pen ( _painter->pen() ); | 139 | //QPen pen ( _painter->pen() ); | ||
140 | QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, ln->lineStyle().penStyle()); | 140 | QPen pen(ln->lineStyle().color(), ln->lineStyle().width() * scaleX, ln->lineStyle().penStyle()); | ||
141 | 141 | | |||
142 | context.painter->save(); | 142 | context.painter->save(); | ||
143 | context.painter->setRenderHint(QPainter::Antialiasing, true); | 143 | context.painter->setRenderHint(QPainter::Antialiasing, true); | ||
144 | context.painter->setPen(pen); | 144 | context.painter->setPen(pen); | ||
145 | context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); | 145 | context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); | ||
146 | context.painter->setRenderHint(QPainter::Antialiasing, false); | 146 | context.painter->setRenderHint(QPainter::Antialiasing, false); | ||
147 | context.painter->restore(); | 147 | context.painter->restore(); | ||
148 | } else if (prim->type() == OROImage::Image) { | 148 | } else if (dynamic_cast<OROImage*>(prim)) { | ||
149 | //kreportDebug() << "Image"; | 149 | //kreportDebug() << "Image"; | ||
150 | OROImage * im = (OROImage*) prim; | 150 | OROImage * im = dynamic_cast<OROImage*>(prim); | ||
151 | QPointF ps = im->position(); | 151 | QPointF ps = im->position(); | ||
152 | QSizeF sz = im->size(); | 152 | QSizeF sz = im->size(); | ||
153 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 153 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
154 | 154 | | |||
155 | QImage img = im->image(); | 155 | QImage img = im->image(); | ||
156 | if (im->scaled()) | 156 | if (im->isScaled()) | ||
157 | img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); | 157 | img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), (Qt::TransformationMode) im->transformationMode()); | ||
158 | 158 | | |||
159 | QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); | 159 | QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); | ||
160 | context.painter->drawImage(rc.topLeft(), img, sr); | 160 | context.painter->drawImage(rc.topLeft(), img, sr); | ||
161 | } else if (prim->type() == ORORect::Rect) { | 161 | } else if (dynamic_cast<ORORect*>(prim)) { | ||
162 | //kreportDebug() << "Rect"; | 162 | //kreportDebug() << "Rect"; | ||
163 | ORORect * re = (ORORect*) prim; | 163 | ORORect * re = dynamic_cast<ORORect*>(prim); | ||
164 | 164 | | |||
165 | QPointF ps = re->position(); | 165 | QPointF ps = re->position(); | ||
166 | QSizeF sz = re->size(); | 166 | QSizeF sz = re->size(); | ||
167 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 167 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
168 | 168 | | |||
169 | context.painter->save(); | 169 | context.painter->save(); | ||
170 | context.painter->setPen(re->pen()); | 170 | context.painter->setPen(re->pen()); | ||
171 | context.painter->setBrush(re->brush()); | 171 | context.painter->setBrush(re->brush()); | ||
172 | context.painter->drawRect(rc); | 172 | context.painter->drawRect(rc); | ||
173 | context.painter->restore(); | 173 | context.painter->restore(); | ||
174 | } else if (prim->type() == OROEllipse::Ellipse) { | 174 | } else if (dynamic_cast<OROEllipse*>(prim)) { | ||
175 | OROEllipse * re = (OROEllipse*) prim; | 175 | OROEllipse * re = dynamic_cast<OROEllipse*>(prim); | ||
176 | 176 | | |||
177 | QPointF ps = re->position(); | 177 | QPointF ps = re->position(); | ||
178 | QSizeF sz = re->size(); | 178 | QSizeF sz = re->size(); | ||
179 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 179 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
180 | 180 | | |||
181 | context.painter->save(); | 181 | context.painter->save(); | ||
182 | context.painter->setPen(re->pen()); | 182 | context.painter->setPen(re->pen()); | ||
183 | context.painter->setBrush(re->brush()); | 183 | context.painter->setBrush(re->brush()); | ||
184 | context.painter->drawEllipse(rc); | 184 | context.painter->drawEllipse(rc); | ||
185 | context.painter->restore(); | 185 | context.painter->restore(); | ||
186 | } else if (prim->type() == OROPicture::Picture) { | 186 | } else if (dynamic_cast<OROPicture*>(prim)) { | ||
187 | OROPicture * im = (OROPicture*) prim; | 187 | OROPicture * im = dynamic_cast<OROPicture*>(prim); | ||
188 | QPointF ps = im->position(); | 188 | QPointF ps = im->position(); | ||
189 | QSizeF sz = im->size(); | 189 | QSizeF sz = im->size(); | ||
190 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 190 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
191 | context.painter->drawPicture(rc.topLeft(), *(im->picture())); | 191 | context.painter->drawPicture(rc.topLeft(), *(im->picture())); | ||
192 | } else if (prim->type() == OROCheck::Check) { | 192 | } else if (dynamic_cast<OROCheckBox*>(prim)) { | ||
193 | OROCheck * chk = (OROCheck*) prim; | 193 | OROCheckBox * chk = dynamic_cast<OROCheckBox*>(prim); | ||
194 | QPointF ps = chk->position(); | 194 | QPointF ps = chk->position(); | ||
195 | QSizeF sz = chk->size(); | 195 | QSizeF sz = chk->size(); | ||
196 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 196 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
197 | 197 | | |||
198 | context.painter->save(); | 198 | context.painter->save(); | ||
199 | 199 | | |||
200 | context.painter->setBackgroundMode(Qt::OpaqueMode); | 200 | context.painter->setBackgroundMode(Qt::OpaqueMode); | ||
201 | context.painter->setRenderHint(QPainter::Antialiasing); | 201 | context.painter->setRenderHint(QPainter::Antialiasing); | ||
202 | 202 | | |||
203 | context.painter->setPen(chk->foregroundColor()); | 203 | context.painter->setPen(chk->foregroundColor()); | ||
204 | 204 | | |||
205 | if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { | 205 | if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { | ||
206 | context.painter->setPen(QPen(Qt::lightGray)); | 206 | context.painter->setPen(QPen(Qt::lightGray)); | ||
207 | } else { | 207 | } else { | ||
208 | context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); | 208 | context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width() * scaleX, chk->lineStyle().penStyle())); | ||
209 | } | 209 | } | ||
210 | 210 | | |||
211 | qreal ox = sz.width() / 5; | 211 | qreal ox = sz.width() / 5; | ||
212 | qreal oy = sz.height() / 5; | 212 | qreal oy = sz.height() / 5; | ||
213 | 213 | | |||
214 | //Checkbox Style | 214 | //Checkbox Style | ||
215 | if (chk->checkType() == QLatin1String("Cross")) { | 215 | if (chk->checkType() == OROCheckBox::Cross) { | ||
216 | context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | 216 | context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | ||
217 | 217 | | |||
218 | if (chk->value()) { | 218 | if (chk->value()) { | ||
219 | QPen lp; | 219 | QPen lp; | ||
220 | lp.setColor(chk->foregroundColor()); | 220 | lp.setColor(chk->foregroundColor()); | ||
221 | lp.setWidth(ox > oy ? oy : ox); | 221 | lp.setWidth(ox > oy ? oy : ox); | ||
222 | context.painter->setPen(lp); | 222 | context.painter->setPen(lp); | ||
223 | context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); | 223 | context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); | ||
224 | context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); | 224 | context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); | ||
225 | } | 225 | } | ||
226 | } else if (chk->checkType() == QLatin1String("Dot")) { | 226 | } else if (chk->checkType() == OROCheckBox::Dot) { | ||
227 | //Radio Style | 227 | //Radio Style | ||
228 | context.painter->drawEllipse(rc); | 228 | context.painter->drawEllipse(rc); | ||
229 | 229 | | |||
230 | if (chk->value()) { | 230 | if (chk->value()) { | ||
231 | QBrush lb(chk->foregroundColor()); | 231 | QBrush lb(chk->foregroundColor()); | ||
232 | context.painter->setBrush(lb); | 232 | context.painter->setBrush(lb); | ||
233 | context.painter->setPen(Qt::NoPen); | 233 | context.painter->setPen(Qt::NoPen); | ||
234 | context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); | 234 | context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); | ||
Show All 27 Lines |