Changeset View
Changeset View
Standalone View
Standalone View
src/renderer/KReportScreenRenderer_p.cpp
Show All 25 Lines | |||||
26 | ScreenRenderer::ScreenRenderer() | 26 | ScreenRenderer::ScreenRenderer() | ||
27 | { | 27 | { | ||
28 | 28 | | |||
29 | } | 29 | } | ||
30 | 30 | | |||
31 | ScreenRenderer::~ScreenRenderer() | 31 | ScreenRenderer::~ScreenRenderer() | ||
32 | { | 32 | { | ||
33 | } | 33 | } | ||
34 | 34 | | |||
35 | //void KRScreenRender::setPainter(QPainter * pPainter) | | |||
36 | //{ | | |||
37 | // context.painter = pPainter; | | |||
38 | //} | | |||
39 | | ||||
40 | bool ScreenRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) | 35 | bool ScreenRenderer::render(const KReportRendererContext& context, ORODocument *document, int page) | ||
staniek: let's remove? | |||||
41 | { | 36 | { | ||
42 | if (!document) | 37 | if (!document) | ||
43 | return false; | 38 | return false; | ||
44 | 39 | | |||
45 | if (!context.painter) | 40 | if (!context.painter()) | ||
46 | return false; | 41 | return false; | ||
47 | 42 | | |||
48 | OROPage *p = document->page(page); | 43 | OROPage *p = document->page(page); | ||
49 | 44 | | |||
50 | if (!p) { | 45 | if (!p) { | ||
51 | return false; | 46 | return false; | ||
52 | } | 47 | } | ||
53 | 48 | | |||
54 | // Render Page Objects | 49 | // Render Page Objects | ||
55 | for (int i = 0; i < p->primitiveCount(); i++) { | 50 | for (int i = 0; i < p->primitiveCount(); i++) { | ||
56 | OROPrimitive *prim = p->primitive(i); | 51 | OROPrimitive *prim = p->primitive(i); | ||
57 | 52 | | |||
58 | if (dynamic_cast<OROTextBox*>(prim)) { | 53 | if (dynamic_cast<OROTextBox*>(prim)) { | ||
59 | OROTextBox *tb = dynamic_cast<OROTextBox*>(prim); | 54 | OROTextBox *tb = dynamic_cast<OROTextBox*>(prim); | ||
60 | 55 | | |||
61 | QPointF ps = tb->position(); | 56 | QPointF ps = tb->position(); | ||
62 | QSizeF sz = tb->size(); | 57 | QSizeF sz = tb->size(); | ||
63 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 58 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
64 | 59 | | |||
65 | context.painter->save(); | 60 | context.painter()->save(); | ||
66 | //Background | 61 | //Background | ||
67 | 62 | | |||
68 | context.painter->setBackgroundMode(Qt::TransparentMode); | 63 | context.painter()->setBackgroundMode(Qt::TransparentMode); | ||
69 | 64 | | |||
70 | QColor bg = tb->textStyle().backgroundColor; | 65 | QColor bg = tb->textStyle().backgroundColor; | ||
71 | bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); | 66 | bg.setAlphaF(0.01 * tb->textStyle().backgroundOpacity); | ||
72 | 67 | | |||
73 | context.painter->fillRect(rc, bg); | 68 | context.painter()->fillRect(rc, bg); | ||
74 | 69 | | |||
75 | //Text | 70 | //Text | ||
76 | context.painter->setFont(tb->textStyle().font); | 71 | context.painter()->setFont(tb->textStyle().font); | ||
77 | context.painter->setPen(tb->textStyle().foregroundColor); | 72 | context.painter()->setPen(tb->textStyle().foregroundColor); | ||
78 | context.painter->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); | 73 | context.painter()->drawText(rc.adjusted(2, 2, 0, 0), tb->flags(), tb->text()); | ||
79 | 74 | | |||
80 | //outer line | 75 | //outer line | ||
81 | context.painter->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); | 76 | context.painter()->setPen(QPen(tb->lineStyle().color(), tb->lineStyle().width(), tb->lineStyle().penStyle())); | ||
82 | context.painter->drawRect(rc); | 77 | context.painter()->drawRect(rc); | ||
83 | 78 | | |||
84 | //Reset back to defaults for next element | 79 | //Reset back to defaults for next element | ||
85 | context.painter->restore(); | 80 | context.painter()->restore(); | ||
86 | } | 81 | } | ||
87 | else if (dynamic_cast<OROLine*>(prim)) { | 82 | else if (dynamic_cast<OROLine*>(prim)) { | ||
88 | OROLine * ln = dynamic_cast<OROLine*>(prim); | 83 | OROLine * ln = dynamic_cast<OROLine*>(prim); | ||
89 | QPointF s = ln->startPoint(); | 84 | QPointF s = ln->startPoint(); | ||
90 | QPointF e = ln->endPoint(); | 85 | QPointF e = ln->endPoint(); | ||
91 | //QPen pen ( _painter->pen() ); | 86 | //QPen pen ( _painter->pen() ); | ||
92 | QPen pen(ln->lineStyle().color(), ln->lineStyle().width(), ln->lineStyle().penStyle()); | 87 | QPen pen(ln->lineStyle().color(), ln->lineStyle().width(), ln->lineStyle().penStyle()); | ||
93 | 88 | | |||
94 | context.painter->save(); | 89 | context.painter()->save(); | ||
95 | context.painter->setRenderHint(QPainter::Antialiasing, true); | 90 | context.painter()->setRenderHint(QPainter::Antialiasing, true); | ||
96 | context.painter->setPen(pen); | 91 | context.painter()->setPen(pen); | ||
97 | context.painter->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); | 92 | context.painter()->drawLine(QLineF(s.x(), s.y(), e.x(), e.y())); | ||
98 | context.painter->setRenderHint(QPainter::Antialiasing, false); | 93 | context.painter()->setRenderHint(QPainter::Antialiasing, false); | ||
99 | context.painter->restore(); | 94 | context.painter()->restore(); | ||
100 | } | 95 | } | ||
101 | else if (dynamic_cast<ORORect*>(prim)) { | 96 | else if (dynamic_cast<ORORect*>(prim)) { | ||
102 | ORORect * re = dynamic_cast<ORORect*>(prim); | 97 | ORORect * re = dynamic_cast<ORORect*>(prim); | ||
103 | 98 | | |||
104 | QPointF ps = re->position(); | 99 | QPointF ps = re->position(); | ||
105 | QSizeF sz = re->size(); | 100 | QSizeF sz = re->size(); | ||
106 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 101 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
107 | 102 | | |||
108 | context.painter->save(); | 103 | context.painter()->save(); | ||
109 | context.painter->setPen(re->pen()); | 104 | context.painter()->setPen(re->pen()); | ||
110 | context.painter->setBrush(re->brush()); | 105 | context.painter()->setBrush(re->brush()); | ||
111 | context.painter->drawRect(rc); | 106 | context.painter()->drawRect(rc); | ||
112 | context.painter->restore(); | 107 | context.painter()->restore(); | ||
113 | } | 108 | } | ||
114 | else if (dynamic_cast<OROEllipse*>(prim)) { | 109 | else if (dynamic_cast<OROEllipse*>(prim)) { | ||
115 | OROEllipse * re = dynamic_cast<OROEllipse*>(prim); | 110 | OROEllipse * re = dynamic_cast<OROEllipse*>(prim); | ||
116 | 111 | | |||
117 | QPointF ps = re->position(); | 112 | QPointF ps = re->position(); | ||
118 | QSizeF sz = re->size(); | 113 | QSizeF sz = re->size(); | ||
119 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 114 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
120 | 115 | | |||
121 | context.painter->save(); | 116 | context.painter()->save(); | ||
122 | context.painter->setPen(re->pen()); | 117 | context.painter()->setPen(re->pen()); | ||
123 | context.painter->setBrush(re->brush()); | 118 | context.painter()->setBrush(re->brush()); | ||
124 | context.painter->drawEllipse(rc); | 119 | context.painter()->drawEllipse(rc); | ||
125 | context.painter->restore(); | 120 | context.painter()->restore(); | ||
126 | } | 121 | } | ||
127 | else if (dynamic_cast<OROImage*>(prim)) { | 122 | else if (dynamic_cast<OROImage*>(prim)) { | ||
128 | OROImage * im = dynamic_cast<OROImage*>(prim); | 123 | OROImage * im = dynamic_cast<OROImage*>(prim); | ||
129 | QPointF ps = im->position(); | 124 | QPointF ps = im->position(); | ||
130 | QSizeF sz = im->size(); | 125 | QSizeF sz = im->size(); | ||
131 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 126 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
132 | 127 | | |||
133 | QImage img = im->image(); | 128 | QImage img = im->image(); | ||
134 | if (im->isScaled()) | 129 | if (im->isScaled()) | ||
135 | img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), | 130 | img = img.scaled(rc.size().toSize(), (Qt::AspectRatioMode) im->aspectRatioMode(), | ||
136 | (Qt::TransformationMode) im->transformationMode()); | 131 | (Qt::TransformationMode) im->transformationMode()); | ||
137 | 132 | | |||
138 | QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); | 133 | QRectF sr = QRectF(QPointF(0.0, 0.0), rc.size().boundedTo(img.size())); | ||
139 | context.painter->drawImage(rc.topLeft(), img, sr); | 134 | context.painter()->drawImage(rc.topLeft(), img, sr); | ||
140 | } | 135 | } | ||
141 | else if (dynamic_cast<OROPicture*>(prim)) { | 136 | else if (dynamic_cast<OROPicture*>(prim)) { | ||
142 | OROPicture * im = dynamic_cast<OROPicture*>(prim); | 137 | OROPicture * im = dynamic_cast<OROPicture*>(prim); | ||
143 | QPointF ps = im->position(); | 138 | QPointF ps = im->position(); | ||
144 | QSizeF sz = im->size(); | 139 | QSizeF sz = im->size(); | ||
145 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 140 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
146 | context.painter->save(); | 141 | context.painter()->save(); | ||
147 | context.painter->drawPicture(rc.topLeft(), *(im->picture())); | 142 | context.painter()->drawPicture(rc.topLeft(), *(im->picture())); | ||
148 | context.painter->restore(); | 143 | context.painter()->restore(); | ||
149 | } | 144 | } | ||
150 | else if (dynamic_cast<OROCheckBox*>(prim)) { | 145 | else if (dynamic_cast<OROCheckBox*>(prim)) { | ||
151 | OROCheckBox * chk = dynamic_cast<OROCheckBox*>(prim); | 146 | OROCheckBox * chk = dynamic_cast<OROCheckBox*>(prim); | ||
152 | QPointF ps = chk->position(); | 147 | QPointF ps = chk->position(); | ||
153 | QSizeF sz = chk->size(); | 148 | QSizeF sz = chk->size(); | ||
154 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | 149 | QRectF rc = QRectF(ps.x(), ps.y(), sz.width(), sz.height()); | ||
155 | 150 | | |||
156 | context.painter->save(); | 151 | context.painter()->save(); | ||
157 | 152 | | |||
158 | context.painter->setBackgroundMode(Qt::OpaqueMode); | 153 | context.painter()->setBackgroundMode(Qt::OpaqueMode); | ||
159 | context.painter->setRenderHint(QPainter::Antialiasing); | 154 | context.painter()->setRenderHint(QPainter::Antialiasing); | ||
160 | 155 | | |||
161 | context.painter->setPen(chk->foregroundColor()); | 156 | context.painter()->setPen(chk->foregroundColor()); | ||
162 | 157 | | |||
163 | if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { | 158 | if (chk->lineStyle().penStyle() == Qt::NoPen || chk->lineStyle().width() <= 0) { | ||
164 | context.painter->setPen(QPen(Qt::lightGray)); | 159 | context.painter()->setPen(QPen(Qt::lightGray)); | ||
165 | } else { | 160 | } else { | ||
166 | context.painter->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); | 161 | context.painter()->setPen(QPen(chk->lineStyle().color(), chk->lineStyle().width(), chk->lineStyle().penStyle())); | ||
167 | } | 162 | } | ||
168 | 163 | | |||
169 | qreal ox = sz.width() / 5; | 164 | qreal ox = sz.width() / 5; | ||
170 | qreal oy = sz.height() / 5; | 165 | qreal oy = sz.height() / 5; | ||
171 | 166 | | |||
172 | //Checkbox Style | 167 | //Checkbox Style | ||
173 | if (chk->checkType() == OROCheckBox::Cross) { | 168 | if (chk->checkType() == OROCheckBox::Cross) { | ||
174 | context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | 169 | context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | ||
175 | 170 | | |||
176 | if (chk->value()) { | 171 | if (chk->value()) { | ||
177 | QPen lp; | 172 | QPen lp; | ||
178 | lp.setColor(chk->foregroundColor()); | 173 | lp.setColor(chk->foregroundColor()); | ||
179 | lp.setWidth(ox > oy ? oy : ox); | 174 | lp.setWidth(ox > oy ? oy : ox); | ||
180 | context.painter->setPen(lp); | 175 | context.painter()->setPen(lp); | ||
181 | context.painter->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); | 176 | context.painter()->drawLine(QPointF(ox, oy) + ps, QPointF(sz.width() - ox, sz.height() - oy) + ps); | ||
182 | context.painter->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); | 177 | context.painter()->drawLine(QPointF(ox, sz.height() - oy) + ps, QPoint(sz.width() - ox, oy) + ps); | ||
183 | } | 178 | } | ||
184 | } | 179 | } | ||
185 | else if (chk->checkType() == OROCheckBox::Dot) { | 180 | else if (chk->checkType() == OROCheckBox::Dot) { | ||
186 | //Radio Style | 181 | //Radio Style | ||
187 | context.painter->drawEllipse(rc); | 182 | context.painter()->drawEllipse(rc); | ||
188 | 183 | | |||
189 | if (chk->value()) { | 184 | if (chk->value()) { | ||
190 | QBrush lb(chk->foregroundColor()); | 185 | QBrush lb(chk->foregroundColor()); | ||
191 | context.painter->setBrush(lb); | 186 | context.painter()->setBrush(lb); | ||
192 | context.painter->setPen(Qt::NoPen); | 187 | context.painter()->setPen(Qt::NoPen); | ||
193 | context.painter->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); | 188 | context.painter()->drawEllipse(rc.center(), sz.width() / 2 - ox, sz.height() / 2 - oy); | ||
194 | } | 189 | } | ||
195 | } | 190 | } | ||
196 | else { | 191 | else { | ||
197 | //Tickbox Style | 192 | //Tickbox Style | ||
198 | context.painter->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | 193 | context.painter()->drawRoundedRect(rc, sz.width() / 10 , sz.height() / 10); | ||
199 | 194 | | |||
200 | if (chk->value()) { | 195 | if (chk->value()) { | ||
201 | QPen lp; | 196 | QPen lp; | ||
202 | lp.setColor(chk->foregroundColor()); | 197 | lp.setColor(chk->foregroundColor()); | ||
203 | lp.setWidth(ox > oy ? oy : ox); | 198 | lp.setWidth(ox > oy ? oy : ox); | ||
204 | context.painter->setPen(lp); | 199 | context.painter()->setPen(lp); | ||
205 | context.painter->drawLine( | 200 | context.painter()->drawLine( | ||
206 | QPointF(ox, sz.height() / 2) + ps, | 201 | QPointF(ox, sz.height() / 2) + ps, | ||
207 | QPointF(sz.width() / 2, sz.height() - oy) + ps); | 202 | QPointF(sz.width() / 2, sz.height() - oy) + ps); | ||
208 | context.painter->drawLine( | 203 | context.painter()->drawLine( | ||
209 | QPointF(sz.width() / 2, sz.height() - oy) + ps, | 204 | QPointF(sz.width() / 2, sz.height() - oy) + ps, | ||
210 | QPointF(sz.width() - ox, oy) + ps); | 205 | QPointF(sz.width() - ox, oy) + ps); | ||
211 | } | 206 | } | ||
212 | } | 207 | } | ||
213 | 208 | | |||
214 | context.painter->restore(); | 209 | context.painter()->restore(); | ||
215 | } | 210 | } | ||
216 | else { | 211 | else { | ||
217 | kreportWarning() << "unrecognized primitive type"; | 212 | kreportWarning() << "unrecognized primitive type"; | ||
218 | } | 213 | } | ||
219 | } | 214 | } | ||
220 | 215 | | |||
221 | return true; | 216 | return true; | ||
222 | } | 217 | } | ||
223 | 218 | | |||
224 | } | 219 | } |
let's remove?