Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qdrawutil.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, | - | ||||||||||||
4 | const QPalette &pal, bool sunken, | - | ||||||||||||
5 | int lineWidth, int midLineWidth) | - | ||||||||||||
6 | { | - | ||||||||||||
7 | if (!((__builtin_expect(!!(!
| 0 | ||||||||||||
8 | QMessageLogger(__FILE__, 9197, __PRETTY_FUNCTION__).warning("qDrawShadeLine: Invalid parameters"); | - | ||||||||||||
9 | return; never executed: return; | 0 | ||||||||||||
10 | } | - | ||||||||||||
11 | int tlw = lineWidth*2 + midLineWidth; | - | ||||||||||||
12 | QPen oldPen = p->pen(); | - | ||||||||||||
13 | if (sunken
| 0 | ||||||||||||
14 | p->setPen(pal.color(QPalette::Dark)); never executed: p->setPen(pal.color(QPalette::Dark)); | 0 | ||||||||||||
15 | else | - | ||||||||||||
16 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
17 | QPolygon a; | - | ||||||||||||
18 | int i; | - | ||||||||||||
19 | if (y1 == y2
| 0 | ||||||||||||
20 | int y = y1 - tlw/2; | - | ||||||||||||
21 | if (x1 > x2
| 0 | ||||||||||||
22 | int t = x1; | - | ||||||||||||
23 | x1 = x2; | - | ||||||||||||
24 | x2 = t; | - | ||||||||||||
25 | } never executed: end of block | 0 | ||||||||||||
26 | x2--; | - | ||||||||||||
27 | for (i=0; i<lineWidth
| 0 | ||||||||||||
28 | a.setPoints(3, x1+i, y+tlw-1-i, | - | ||||||||||||
29 | x1+i, y+i, | - | ||||||||||||
30 | x2-i, y+i); | - | ||||||||||||
31 | p->drawPolyline(a); | - | ||||||||||||
32 | } never executed: end of block | 0 | ||||||||||||
33 | if (midLineWidth > 0
| 0 | ||||||||||||
34 | p->setPen(pal.mid().color()); | - | ||||||||||||
35 | for (i=0; i<midLineWidth
| 0 | ||||||||||||
36 | p->drawLine(x1+lineWidth, y+lineWidth+i, never executed: p->drawLine(x1+lineWidth, y+lineWidth+i, x2-lineWidth, y+lineWidth+i); | 0 | ||||||||||||
37 | x2-lineWidth, y+lineWidth+i); never executed: p->drawLine(x1+lineWidth, y+lineWidth+i, x2-lineWidth, y+lineWidth+i); | 0 | ||||||||||||
38 | } never executed: end of block | 0 | ||||||||||||
39 | if (sunken
| 0 | ||||||||||||
40 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
41 | else | - | ||||||||||||
42 | p->setPen(pal.dark().color()); never executed: p->setPen(pal.dark().color()); | 0 | ||||||||||||
43 | for (i=0; i<lineWidth
| 0 | ||||||||||||
44 | a.setPoints(3, x1+i, y+tlw-i-1, | - | ||||||||||||
45 | x2-i, y+tlw-i-1, | - | ||||||||||||
46 | x2-i, y+i+1); | - | ||||||||||||
47 | p->drawPolyline(a); | - | ||||||||||||
48 | } never executed: end of block | 0 | ||||||||||||
49 | } never executed: end of block | 0 | ||||||||||||
50 | else if (x1 == x2
| 0 | ||||||||||||
51 | int x = x1 - tlw/2; | - | ||||||||||||
52 | if (y1 > y2
| 0 | ||||||||||||
53 | int t = y1; | - | ||||||||||||
54 | y1 = y2; | - | ||||||||||||
55 | y2 = t; | - | ||||||||||||
56 | } never executed: end of block | 0 | ||||||||||||
57 | y2--; | - | ||||||||||||
58 | for (i=0; i<lineWidth
| 0 | ||||||||||||
59 | a.setPoints(3, x+i, y2, | - | ||||||||||||
60 | x+i, y1+i, | - | ||||||||||||
61 | x+tlw-1, y1+i); | - | ||||||||||||
62 | p->drawPolyline(a); | - | ||||||||||||
63 | } never executed: end of block | 0 | ||||||||||||
64 | if (midLineWidth > 0
| 0 | ||||||||||||
65 | p->setPen(pal.mid().color()); | - | ||||||||||||
66 | for (i=0; i<midLineWidth
| 0 | ||||||||||||
67 | p->drawLine(x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2); never executed: p->drawLine(x+lineWidth+i, y1+lineWidth, x+lineWidth+i, y2); | 0 | ||||||||||||
68 | } never executed: end of block | 0 | ||||||||||||
69 | if (sunken
| 0 | ||||||||||||
70 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
71 | else | - | ||||||||||||
72 | p->setPen(pal.dark().color()); never executed: p->setPen(pal.dark().color()); | 0 | ||||||||||||
73 | for (i=0; i<lineWidth
| 0 | ||||||||||||
74 | a.setPoints(3, x+lineWidth, y2-i, | - | ||||||||||||
75 | x+tlw-i-1, y2-i, | - | ||||||||||||
76 | x+tlw-i-1, y1+lineWidth); | - | ||||||||||||
77 | p->drawPolyline(a); | - | ||||||||||||
78 | } never executed: end of block | 0 | ||||||||||||
79 | } never executed: end of block | 0 | ||||||||||||
80 | p->setPen(oldPen); | - | ||||||||||||
81 | } never executed: end of block | 0 | ||||||||||||
82 | void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, | - | ||||||||||||
83 | const QPalette &pal, bool sunken, | - | ||||||||||||
84 | int lineWidth, int midLineWidth, | - | ||||||||||||
85 | const QBrush *fill) | - | ||||||||||||
86 | { | - | ||||||||||||
87 | if (w == 0
| 0 | ||||||||||||
88 | return; never executed: return; | 0 | ||||||||||||
89 | if (!(__builtin_expect(!!(
| 0 | ||||||||||||
90 | QMessageLogger(__FILE__, 207213, __PRETTY_FUNCTION__).warning("qDrawShadeRect: Invalid parameters"); | - | ||||||||||||
91 | return; never executed: return; | 0 | ||||||||||||
92 | } | - | ||||||||||||
93 | QPen oldPen = p->pen(); | - | ||||||||||||
94 | if (sunken
| 0 | ||||||||||||
95 | p->setPen(pal.dark().color()); never executed: p->setPen(pal.dark().color()); | 0 | ||||||||||||
96 | else | - | ||||||||||||
97 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
98 | int x1=x, y1=y, x2=x+w-1, y2=y+h-1; | - | ||||||||||||
99 | - | |||||||||||||
100 | if (lineWidth == 1
| 0 | ||||||||||||
101 | p->drawRect(x1, y1, w-2, h-2); | - | ||||||||||||
102 | if (sunken
| 0 | ||||||||||||
103 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
104 | else | - | ||||||||||||
105 | p->setPen(pal.dark().color()); never executed: p->setPen(pal.dark().color()); | 0 | ||||||||||||
106 | QLineF lines[4] = { QLineF(x1+1, y1+1, x2-2, y1+1), | - | ||||||||||||
107 | QLineF(x1+1, y1+2, x1+1, y2-2), | - | ||||||||||||
108 | QLineF(x1, y2, x2, y2), | - | ||||||||||||
109 | QLineF(x2,y1, x2,y2-1) }; | - | ||||||||||||
110 | p->drawLines(lines, 4); | - | ||||||||||||
111 | } never executed: else {end of block | 0 | ||||||||||||
112 | int m = lineWidth+midLineWidth; | - | ||||||||||||
113 | int i, j=0, k=m; | - | ||||||||||||
114 | for (i=0; i<lineWidth
| 0 | ||||||||||||
115 | QLineF lines[4] = { QLineF(x1+i, y2-i, x1+i, y1+i), | - | ||||||||||||
116 | QLineF(x1+i, y1+i, x2-i, y1+i), | - | ||||||||||||
117 | QLineF(x1+k, y2-k, x2-k, y2-k), | - | ||||||||||||
118 | QLineF(x2-k, y2-k, x2-k, y1+k) }; | - | ||||||||||||
119 | p->drawLines(lines, 4); | - | ||||||||||||
120 | k++; | - | ||||||||||||
121 | } never executed: end of block | 0 | ||||||||||||
122 | p->setPen(pal.mid().color()); | - | ||||||||||||
123 | j = lineWidth*2; | - | ||||||||||||
124 | for (i=0; i<midLineWidth
| 0 | ||||||||||||
125 | p->drawRect(x1+lineWidth+i, y1+lineWidth+i, w-j-1, h-j-1); | - | ||||||||||||
126 | j += 2; | - | ||||||||||||
127 | } never executed: end of block | 0 | ||||||||||||
128 | if (sunken
| 0 | ||||||||||||
129 | p->setPen(pal.light().color()); never executed: p->setPen(pal.light().color()); | 0 | ||||||||||||
130 | else | - | ||||||||||||
131 | p->setPen(pal.dark().color()); never executed: p->setPen(pal.dark().color()); | 0 | ||||||||||||
132 | k = m; | - | ||||||||||||
133 | for (i=0; i<lineWidth
| 0 | ||||||||||||
134 | QLineF lines[4] = { QLineF(x1+1+i, y2-i, x2-i, y2-i), | - | ||||||||||||
135 | QLineF(x2-i, y2-i, x2-i, y1+i+1), | - | ||||||||||||
136 | QLineF(x1+k, y2-k, x1+k, y1+k), | - | ||||||||||||
137 | QLineF(x1+k, y1+k, x2-k, y1+k) }; | - | ||||||||||||
138 | p->drawLines(lines, 4); | - | ||||||||||||
139 | k++; | - | ||||||||||||
140 | } never executed: end of block | 0 | ||||||||||||
141 | } never executed: end of block | 0 | ||||||||||||
142 | if (fill
| 0 | ||||||||||||
143 | QBrush oldBrush = p->brush(); | - | ||||||||||||
144 | int tlw = lineWidth + midLineWidth; | - | ||||||||||||
145 | p->setPen(Qt::NoPen); | - | ||||||||||||
146 | p->setBrush(*fill); | - | ||||||||||||
147 | p->drawRect(x+tlw, y+tlw, w-2*tlw, h-2*tlw); | - | ||||||||||||
148 | p->setBrush(oldBrush); | - | ||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||
150 | p->setPen(oldPen); | - | ||||||||||||
151 | } never executed: end of block | 0 | ||||||||||||
152 | void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, | - | ||||||||||||
153 | const QPalette &pal, bool sunken, | - | ||||||||||||
154 | int lineWidth, const QBrush *fill) | - | ||||||||||||
155 | { | - | ||||||||||||
156 | if (w == 0
| 0 | ||||||||||||
157 | return; never executed: return; | 0 | ||||||||||||
158 | if (!((__builtin_expect(!!(
| 0 | ||||||||||||
159 | QMessageLogger(__FILE__, 307313, __PRETTY_FUNCTION__).warning("qDrawShadePanel: Invalid parameters"); | - | ||||||||||||
160 | } never executed: end of block | 0 | ||||||||||||
161 | QColor shade = pal.dark().color(); | - | ||||||||||||
162 | QColor light = pal.light().color(); | - | ||||||||||||
163 | if (fill
| 0 | ||||||||||||
164 | if (fill->color() == shade
| 0 | ||||||||||||
165 | shade = pal.shadow().color(); never executed: shade = pal.shadow().color(); | 0 | ||||||||||||
166 | if (fill->color() == light
| 0 | ||||||||||||
167 | light = pal.midlight().color(); never executed: light = pal.midlight().color(); | 0 | ||||||||||||
168 | } never executed: end of block | 0 | ||||||||||||
169 | QPen oldPen = p->pen(); | - | ||||||||||||
170 | QVector<QLineF> lines; | - | ||||||||||||
171 | lines.reserve(2*lineWidth); | - | ||||||||||||
172 | - | |||||||||||||
173 | if (sunken
| 0 | ||||||||||||
174 | p->setPen(shade); never executed: p->setPen(shade); | 0 | ||||||||||||
175 | else | - | ||||||||||||
176 | p->setPen(light); never executed: p->setPen(light); | 0 | ||||||||||||
177 | int x1, y1, x2, y2; | - | ||||||||||||
178 | int i; | - | ||||||||||||
179 | x1 = x; | - | ||||||||||||
180 | y1 = y2 = y; | - | ||||||||||||
181 | x2 = x+w-2; | - | ||||||||||||
182 | for (i=0; i<lineWidth
| 0 | ||||||||||||
183 | lines << QLineF(x1, y1++, x2--, y2++); | - | ||||||||||||
184 | } never executed: end of block | 0 | ||||||||||||
185 | x2 = x1; | - | ||||||||||||
186 | y1 = y+h-2; | - | ||||||||||||
187 | for (i=0; i<lineWidth
| 0 | ||||||||||||
188 | lines << QLineF(x1++, y1, x2++, y2--); | - | ||||||||||||
189 | } never executed: end of block | 0 | ||||||||||||
190 | p->drawLines(lines); | - | ||||||||||||
191 | lines.clear(); | - | ||||||||||||
192 | if (sunken
| 0 | ||||||||||||
193 | p->setPen(light); never executed: p->setPen(light); | 0 | ||||||||||||
194 | else | - | ||||||||||||
195 | p->setPen(shade); never executed: p->setPen(shade); | 0 | ||||||||||||
196 | x1 = x; | - | ||||||||||||
197 | y1 = y2 = y+h-1; | - | ||||||||||||
198 | x2 = x+w-1; | - | ||||||||||||
199 | for (i=0; i<lineWidth
| 0 | ||||||||||||
200 | lines << QLineF(x1++, y1--, x2, y2--); | - | ||||||||||||
201 | } never executed: end of block | 0 | ||||||||||||
202 | x1 = x2; | - | ||||||||||||
203 | y1 = y; | - | ||||||||||||
204 | y2 = y+h-lineWidth-1; | - | ||||||||||||
205 | for (i=0; i<lineWidth
| 0 | ||||||||||||
206 | lines << QLineF(x1--, y1++, x2--, y2); | - | ||||||||||||
207 | } never executed: end of block | 0 | ||||||||||||
208 | p->drawLines(lines); | - | ||||||||||||
209 | if (fill
| 0 | ||||||||||||
210 | p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); never executed: p->fillRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2, *fill); | 0 | ||||||||||||
211 | p->setPen(oldPen); | - | ||||||||||||
212 | } never executed: end of block | 0 | ||||||||||||
213 | static void qDrawWinShades(QPainter *p, | - | ||||||||||||
214 | int x, int y, int w, int h, | - | ||||||||||||
215 | const QColor &c1, const QColor &c2, | - | ||||||||||||
216 | const QColor &c3, const QColor &c4, | - | ||||||||||||
217 | const QBrush *fill) | - | ||||||||||||
218 | { | - | ||||||||||||
219 | if (w < 2 || h < 2) | - | ||||||||||||
220 | return; | - | ||||||||||||
221 | QPen oldPen = p->pen(); | - | ||||||||||||
222 | QPoint a[3] = { QPoint(x, y+h-2), QPoint(x, y), QPoint(x+w-2, y) }; | - | ||||||||||||
223 | p->setPen(c1); | - | ||||||||||||
224 | p->drawPolyline(a, 3); | - | ||||||||||||
225 | QPoint b[3] = { QPoint(x, y+h-1), QPoint(x+w-1, y+h-1), QPoint(x+w-1, y) }; | - | ||||||||||||
226 | p->setPen(c2); | - | ||||||||||||
227 | p->drawPolyline(b, 3); | - | ||||||||||||
228 | if (w > 4 && h > 4) { | - | ||||||||||||
229 | QPoint c[3] = { QPoint(x+1, y+h-3), QPoint(x+1, y+1), QPoint(x+w-3, y+1) }; | - | ||||||||||||
230 | p->setPen(c3); | - | ||||||||||||
231 | p->drawPolyline(c, 3); | - | ||||||||||||
232 | QPoint d[3] = { QPoint(x+1, y+h-2), QPoint(x+w-2, y+h-2), QPoint(x+w-2, y+1) }; | - | ||||||||||||
233 | p->setPen(c4); | - | ||||||||||||
234 | p->drawPolyline(d, 3); | - | ||||||||||||
235 | if (fill) | - | ||||||||||||
236 | p->fillRect(QRect(x+2, y+2, w-4, h-4), *fill); | - | ||||||||||||
237 | } | - | ||||||||||||
238 | p->setPen(oldPen); | - | ||||||||||||
239 | } | - | ||||||||||||
240 | void qDrawWinButton(QPainter *p, int x, int y, int w, int h, | - | ||||||||||||
241 | const QPalette &pal, bool sunken, | - | ||||||||||||
242 | const QBrush *fill) | - | ||||||||||||
243 | { | - | ||||||||||||
244 | if (sunken) | - | ||||||||||||
245 | qDrawWinShades(p, x, y, w, h, | - | ||||||||||||
246 | pal.shadow().color(), pal.light().color(), pal.dark().color(), | - | ||||||||||||
247 | pal.button().color(), fill); | - | ||||||||||||
248 | else | - | ||||||||||||
249 | qDrawWinShades(p, x, y, w, h, | - | ||||||||||||
250 | pal.light().color(), pal.shadow().color(), pal.button().color(), | - | ||||||||||||
251 | pal.dark().color(), fill); | - | ||||||||||||
252 | } | - | ||||||||||||
253 | void qDrawWinPanel(QPainter *p, int x, int y, int w, int h, | - | ||||||||||||
254 | const QPalette &pal, bool sunken, | - | ||||||||||||
255 | const QBrush *fill) | - | ||||||||||||
256 | { | - | ||||||||||||
257 | if (sunken) | - | ||||||||||||
258 | qDrawWinShades(p, x, y, w, h, | - | ||||||||||||
259 | pal.dark().color(), pal.light().color(), pal.shadow().color(), | - | ||||||||||||
260 | pal.midlight().color(), fill); | - | ||||||||||||
261 | else | - | ||||||||||||
262 | qDrawWinShades(p, x, y, w, h, | - | ||||||||||||
263 | pal.light().color(), pal.shadow().color(), pal.midlight().color(), | - | ||||||||||||
264 | pal.dark().color(), fill); | - | ||||||||||||
265 | } | - | ||||||||||||
266 | void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, | - | ||||||||||||
267 | int lineWidth, const QBrush *fill) | - | ||||||||||||
268 | { | - | ||||||||||||
269 | if (w == 0
| 0 | ||||||||||||
270 | return; never executed: return; | 0 | ||||||||||||
271 | if (!((__builtin_expect(!!(
| 0 | ||||||||||||
272 | QMessageLogger(__FILE__, 513519, __PRETTY_FUNCTION__).warning("qDrawPlainRect: Invalid parameters"); | - | ||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||
274 | QPen oldPen = p->pen(); | - | ||||||||||||
275 | QBrush oldBrush = p->brush(); | - | ||||||||||||
276 | p->setPen(c); | - | ||||||||||||
277 | p->setBrush(Qt::NoBrush); | - | ||||||||||||
278 | for (int i=0; i<lineWidth
| 0 | ||||||||||||
279 | p->drawRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1); never executed: p->drawRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1); | 0 | ||||||||||||
280 | if (fill
| 0 | ||||||||||||
281 | p->setPen(Qt::NoPen); | - | ||||||||||||
282 | p->setBrush(*fill); | - | ||||||||||||
283 | p->drawRect(x+lineWidth, y+lineWidth, w-lineWidth*2, h-lineWidth*2); | - | ||||||||||||
284 | } never executed: end of block | 0 | ||||||||||||
285 | p->setPen(oldPen); | - | ||||||||||||
286 | p->setBrush(oldBrush); | - | ||||||||||||
287 | } never executed: end of block | 0 | ||||||||||||
288 | void qDrawShadeLine(QPainter *p, const QPoint &p1, const QPoint &p2, | - | ||||||||||||
289 | const QPalette &pal, bool sunken, | - | ||||||||||||
290 | int lineWidth, int midLineWidth) | - | ||||||||||||
291 | { | - | ||||||||||||
292 | qDrawShadeLine(p, p1.x(), p1.y(), p2.x(), p2.y(), pal, sunken, | - | ||||||||||||
293 | lineWidth, midLineWidth); | - | ||||||||||||
294 | } | - | ||||||||||||
295 | void qDrawShadeRect(QPainter *p, const QRect &r, | - | ||||||||||||
296 | const QPalette &pal, bool sunken, | - | ||||||||||||
297 | int lineWidth, int midLineWidth, | - | ||||||||||||
298 | const QBrush *fill) | - | ||||||||||||
299 | { | - | ||||||||||||
300 | qDrawShadeRect(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, | - | ||||||||||||
301 | lineWidth, midLineWidth, fill); | - | ||||||||||||
302 | } | - | ||||||||||||
303 | void qDrawShadePanel(QPainter *p, const QRect &r, | - | ||||||||||||
304 | const QPalette &pal, bool sunken, | - | ||||||||||||
305 | int lineWidth, const QBrush *fill) | - | ||||||||||||
306 | { | - | ||||||||||||
307 | qDrawShadePanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, | - | ||||||||||||
308 | lineWidth, fill); | - | ||||||||||||
309 | } | - | ||||||||||||
310 | void qDrawWinButton(QPainter *p, const QRect &r, | - | ||||||||||||
311 | const QPalette &pal, bool sunken, const QBrush *fill) | - | ||||||||||||
312 | { | - | ||||||||||||
313 | qDrawWinButton(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill); | - | ||||||||||||
314 | } | - | ||||||||||||
315 | void qDrawWinPanel(QPainter *p, const QRect &r, | - | ||||||||||||
316 | const QPalette &pal, bool sunken, const QBrush *fill) | - | ||||||||||||
317 | { | - | ||||||||||||
318 | qDrawWinPanel(p, r.x(), r.y(), r.width(), r.height(), pal, sunken, fill); | - | ||||||||||||
319 | } | - | ||||||||||||
320 | void qDrawPlainRect(QPainter *p, const QRect &r, const QColor &c, | - | ||||||||||||
321 | int lineWidth, const QBrush *fill) | - | ||||||||||||
322 | { | - | ||||||||||||
323 | qDrawPlainRect(p, r.x(), r.y(), r.width(), r.height(), c, | - | ||||||||||||
324 | lineWidth, fill); | - | ||||||||||||
325 | } | - | ||||||||||||
326 | typedef QVarLengthArray<QPainter::PixmapFragment, 16> QPixmapFragmentsArray; | - | ||||||||||||
327 | void qDrawBorderPixmap(QPainter *painter, const QRect &targetRect, const QMargins &targetMargins, | - | ||||||||||||
328 | const QPixmap &pixmap, const QRect &sourceRect,const QMargins &sourceMargins, | - | ||||||||||||
329 | const QTileRules &rules, QDrawBorderPixmap::DrawingHints hints) | - | ||||||||||||
330 | { | - | ||||||||||||
331 | QPainter::PixmapFragment d; | - | ||||||||||||
332 | d.opacity = 1.0; | - | ||||||||||||
333 | d.rotation = 0.0; | - | ||||||||||||
334 | - | |||||||||||||
335 | QPixmapFragmentsArray opaqueData; | - | ||||||||||||
336 | QPixmapFragmentsArray translucentData; | - | ||||||||||||
337 | - | |||||||||||||
338 | - | |||||||||||||
339 | const int sourceCenterTop = sourceRect.top() + sourceMargins.top(); | - | ||||||||||||
340 | const int sourceCenterLeft = sourceRect.left() + sourceMargins.left(); | - | ||||||||||||
341 | const int sourceCenterBottom = sourceRect.bottom() - sourceMargins.bottom() + 1; | - | ||||||||||||
342 | const int sourceCenterRight = sourceRect.right() - sourceMargins.right() + 1; | - | ||||||||||||
343 | const int sourceCenterWidth = sourceCenterRight - sourceCenterLeft; | - | ||||||||||||
344 | const int sourceCenterHeight = sourceCenterBottom - sourceCenterTop; | - | ||||||||||||
345 | - | |||||||||||||
346 | const int targetCenterTop = targetRect.top() + targetMargins.top(); | - | ||||||||||||
347 | const int targetCenterLeft = targetRect.left() + targetMargins.left(); | - | ||||||||||||
348 | const int targetCenterBottom = targetRect.bottom() - targetMargins.bottom() + 1; | - | ||||||||||||
349 | const int targetCenterRight = targetRect.right() - targetMargins.right() + 1; | - | ||||||||||||
350 | const int targetCenterWidth = targetCenterRight - targetCenterLeft; | - | ||||||||||||
351 | const int targetCenterHeight = targetCenterBottom - targetCenterTop; | - | ||||||||||||
352 | - | |||||||||||||
353 | QVarLengthArray<qreal, 16> xTarget; | - | ||||||||||||
354 | QVarLengthArray<qreal, 16> yTarget; | - | ||||||||||||
355 | - | |||||||||||||
356 | int columns = 3; | - | ||||||||||||
357 | int rows = 3; | - | ||||||||||||
358 | if (rules.horizontal != Qt::StretchTile && sourceCenterWidth != 0) | - | ||||||||||||
359 | columns = qMax(3, 2 + qCeil(targetCenterWidth / qreal(sourceCenterWidth))); | - | ||||||||||||
360 | if (rules.vertical != Qt::StretchTile && sourceCenterHeight != 0) | - | ||||||||||||
361 | rows = qMax(3, 2 + qCeil(targetCenterHeight / qreal(sourceCenterHeight))); | - | ||||||||||||
362 | - | |||||||||||||
363 | xTarget.resize(columns + 1); | - | ||||||||||||
364 | yTarget.resize(rows + 1); | - | ||||||||||||
365 | - | |||||||||||||
366 | bool oldAA = painter->testRenderHint(QPainter::Antialiasing); | - | ||||||||||||
367 | if (painter->paintEngine()->type() != QPaintEngine::OpenGL | - | ||||||||||||
368 | && painter->paintEngine()->type() != QPaintEngine::OpenGL2 | - | ||||||||||||
369 | && oldAA && painter->combinedTransform().type() != QTransform::TxNone) { | - | ||||||||||||
370 | painter->setRenderHint(QPainter::Antialiasing, false); | - | ||||||||||||
371 | } | - | ||||||||||||
372 | - | |||||||||||||
373 | xTarget[0] = targetRect.left(); | - | ||||||||||||
374 | xTarget[1] = targetCenterLeft; | - | ||||||||||||
375 | xTarget[columns - 1] = targetCenterRight; | - | ||||||||||||
376 | xTarget[columns] = targetRect.left() + targetRect.width(); | - | ||||||||||||
377 | - | |||||||||||||
378 | yTarget[0] = targetRect.top(); | - | ||||||||||||
379 | yTarget[1] = targetCenterTop; | - | ||||||||||||
380 | yTarget[rows - 1] = targetCenterBottom; | - | ||||||||||||
381 | yTarget[rows] = targetRect.top() + targetRect.height(); | - | ||||||||||||
382 | - | |||||||||||||
383 | qreal dx = targetCenterWidth; | - | ||||||||||||
384 | qreal dy = targetCenterHeight; | - | ||||||||||||
385 | - | |||||||||||||
386 | switch (rules.horizontal) { | - | ||||||||||||
387 | case Qt::StretchTile: | - | ||||||||||||
388 | dx = targetCenterWidth; | - | ||||||||||||
389 | break; | - | ||||||||||||
390 | case Qt::RepeatTile: | - | ||||||||||||
391 | dx = sourceCenterWidth; | - | ||||||||||||
392 | break; | - | ||||||||||||
393 | case Qt::RoundTile: | - | ||||||||||||
394 | dx = targetCenterWidth / qreal(columns - 2); | - | ||||||||||||
395 | break; | - | ||||||||||||
396 | } | - | ||||||||||||
397 | - | |||||||||||||
398 | for (int i = 2; i < columns - 1; ++i) | - | ||||||||||||
399 | xTarget[i] = xTarget[i - 1] + dx; | - | ||||||||||||
400 | - | |||||||||||||
401 | switch (rules.vertical) { | - | ||||||||||||
402 | case Qt::StretchTile: | - | ||||||||||||
403 | dy = targetCenterHeight; | - | ||||||||||||
404 | break; | - | ||||||||||||
405 | case Qt::RepeatTile: | - | ||||||||||||
406 | dy = sourceCenterHeight; | - | ||||||||||||
407 | break; | - | ||||||||||||
408 | case Qt::RoundTile: | - | ||||||||||||
409 | dy = targetCenterHeight / qreal(rows - 2); | - | ||||||||||||
410 | break; | - | ||||||||||||
411 | } | - | ||||||||||||
412 | - | |||||||||||||
413 | for (int i = 2; i < rows - 1; ++i) | - | ||||||||||||
414 | yTarget[i] = yTarget[i - 1] + dy; | - | ||||||||||||
415 | - | |||||||||||||
416 | - | |||||||||||||
417 | if (targetMargins.top() > 0 && targetMargins.left() > 0 && sourceMargins.top() > 0 && sourceMargins.left() > 0) { | - | ||||||||||||
418 | d.x = (0.5 * (xTarget[1] + xTarget[0])); | - | ||||||||||||
419 | d.y = (0.5 * (yTarget[1] + yTarget[0])); | - | ||||||||||||
420 | d.sourceLeft = sourceRect.left(); | - | ||||||||||||
421 | d.sourceTop = sourceRect.top(); | - | ||||||||||||
422 | d.width = sourceMargins.left(); | - | ||||||||||||
423 | d.height = sourceMargins.top(); | - | ||||||||||||
424 | d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; | - | ||||||||||||
425 | d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; | - | ||||||||||||
426 | if (hints & QDrawBorderPixmap::OpaqueTopLeft) | - | ||||||||||||
427 | opaqueData.append(d); | - | ||||||||||||
428 | else | - | ||||||||||||
429 | translucentData.append(d); | - | ||||||||||||
430 | } | - | ||||||||||||
431 | if (targetMargins.top() > 0 && targetMargins.right() > 0 && sourceMargins.top() > 0 && sourceMargins.right() > 0) { | - | ||||||||||||
432 | d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); | - | ||||||||||||
433 | d.y = (0.5 * (yTarget[1] + yTarget[0])); | - | ||||||||||||
434 | d.sourceLeft = sourceCenterRight; | - | ||||||||||||
435 | d.sourceTop = sourceRect.top(); | - | ||||||||||||
436 | d.width = sourceMargins.right(); | - | ||||||||||||
437 | d.height = sourceMargins.top(); | - | ||||||||||||
438 | d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; | - | ||||||||||||
439 | d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; | - | ||||||||||||
440 | if (hints & QDrawBorderPixmap::OpaqueTopRight) | - | ||||||||||||
441 | opaqueData.append(d); | - | ||||||||||||
442 | else | - | ||||||||||||
443 | translucentData.append(d); | - | ||||||||||||
444 | } | - | ||||||||||||
445 | if (targetMargins.bottom() > 0 && targetMargins.left() > 0 && sourceMargins.bottom() > 0 && sourceMargins.left() > 0) { | - | ||||||||||||
446 | d.x = (0.5 * (xTarget[1] + xTarget[0])); | - | ||||||||||||
447 | d.y =(0.5 * (yTarget[rows] + yTarget[rows - 1])); | - | ||||||||||||
448 | d.sourceLeft = sourceRect.left(); | - | ||||||||||||
449 | d.sourceTop = sourceCenterBottom; | - | ||||||||||||
450 | d.width = sourceMargins.left(); | - | ||||||||||||
451 | d.height = sourceMargins.bottom(); | - | ||||||||||||
452 | d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; | - | ||||||||||||
453 | d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; | - | ||||||||||||
454 | if (hints & QDrawBorderPixmap::OpaqueBottomLeft) | - | ||||||||||||
455 | opaqueData.append(d); | - | ||||||||||||
456 | else | - | ||||||||||||
457 | translucentData.append(d); | - | ||||||||||||
458 | } | - | ||||||||||||
459 | if (targetMargins.bottom() > 0 && targetMargins.right() > 0 && sourceMargins.bottom() > 0 && sourceMargins.right() > 0) { | - | ||||||||||||
460 | d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); | - | ||||||||||||
461 | d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1])); | - | ||||||||||||
462 | d.sourceLeft = sourceCenterRight; | - | ||||||||||||
463 | d.sourceTop = sourceCenterBottom; | - | ||||||||||||
464 | d.width = sourceMargins.right(); | - | ||||||||||||
465 | d.height = sourceMargins.bottom(); | - | ||||||||||||
466 | d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; | - | ||||||||||||
467 | d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; | - | ||||||||||||
468 | if (hints & QDrawBorderPixmap::OpaqueBottomRight) | - | ||||||||||||
469 | opaqueData.append(d); | - | ||||||||||||
470 | else | - | ||||||||||||
471 | translucentData.append(d); | - | ||||||||||||
472 | } | - | ||||||||||||
473 | - | |||||||||||||
474 | - | |||||||||||||
475 | if (targetCenterWidth > 0 && sourceCenterWidth > 0) { | - | ||||||||||||
476 | if (targetMargins.top() > 0 && sourceMargins.top() > 0) { | - | ||||||||||||
477 | QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueTop ? opaqueData : translucentData; | - | ||||||||||||
478 | d.sourceLeft = sourceCenterLeft; | - | ||||||||||||
479 | d.sourceTop = sourceRect.top(); | - | ||||||||||||
480 | d.width = sourceCenterWidth; | - | ||||||||||||
481 | d.height = sourceMargins.top(); | - | ||||||||||||
482 | d.y = (0.5 * (yTarget[1] + yTarget[0])); | - | ||||||||||||
483 | d.scaleX = dx / d.width; | - | ||||||||||||
484 | d.scaleY = qreal(yTarget[1] - yTarget[0]) / d.height; | - | ||||||||||||
485 | for (int i = 1; i < columns - 1; ++i) { | - | ||||||||||||
486 | d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); | - | ||||||||||||
487 | data.append(d); | - | ||||||||||||
488 | } | - | ||||||||||||
489 | if (rules.horizontal == Qt::RepeatTile) | - | ||||||||||||
490 | data[data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX); | - | ||||||||||||
491 | } | - | ||||||||||||
492 | if (targetMargins.bottom() > 0 && sourceMargins.bottom() > 0) { | - | ||||||||||||
493 | QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueBottom ? opaqueData : translucentData; | - | ||||||||||||
494 | d.sourceLeft = sourceCenterLeft; | - | ||||||||||||
495 | d.sourceTop = sourceCenterBottom; | - | ||||||||||||
496 | d.width = sourceCenterWidth; | - | ||||||||||||
497 | d.height = sourceMargins.bottom(); | - | ||||||||||||
498 | d.y = (0.5 * (yTarget[rows] + yTarget[rows - 1])); | - | ||||||||||||
499 | d.scaleX = dx / d.width; | - | ||||||||||||
500 | d.scaleY = qreal(yTarget[rows] - yTarget[rows - 1]) / d.height; | - | ||||||||||||
501 | for (int i = 1; i < columns - 1; ++i) { | - | ||||||||||||
502 | d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); | - | ||||||||||||
503 | data.append(d); | - | ||||||||||||
504 | } | - | ||||||||||||
505 | if (rules.horizontal == Qt::RepeatTile) | - | ||||||||||||
506 | data[data.size() - 1].width = ((xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX); | - | ||||||||||||
507 | } | - | ||||||||||||
508 | } | - | ||||||||||||
509 | - | |||||||||||||
510 | - | |||||||||||||
511 | if (targetCenterHeight > 0 && sourceCenterHeight > 0) { | - | ||||||||||||
512 | if (targetMargins.left() > 0 && sourceMargins.left() > 0) { | - | ||||||||||||
513 | QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueLeft ? opaqueData : translucentData; | - | ||||||||||||
514 | d.sourceLeft = sourceRect.left(); | - | ||||||||||||
515 | d.sourceTop = sourceCenterTop; | - | ||||||||||||
516 | d.width = sourceMargins.left(); | - | ||||||||||||
517 | d.height = sourceCenterHeight; | - | ||||||||||||
518 | d.x = (0.5 * (xTarget[1] + xTarget[0])); | - | ||||||||||||
519 | d.scaleX = qreal(xTarget[1] - xTarget[0]) / d.width; | - | ||||||||||||
520 | d.scaleY = dy / d.height; | - | ||||||||||||
521 | for (int i = 1; i < rows - 1; ++i) { | - | ||||||||||||
522 | d.y = (0.5 * (yTarget[i + 1] + yTarget[i])); | - | ||||||||||||
523 | data.append(d); | - | ||||||||||||
524 | } | - | ||||||||||||
525 | if (rules.vertical == Qt::RepeatTile) | - | ||||||||||||
526 | data[data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY); | - | ||||||||||||
527 | } | - | ||||||||||||
528 | if (targetMargins.right() > 0 && sourceMargins.right() > 0) { | - | ||||||||||||
529 | QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueRight ? opaqueData : translucentData; | - | ||||||||||||
530 | d.sourceLeft = sourceCenterRight; | - | ||||||||||||
531 | d.sourceTop = sourceCenterTop; | - | ||||||||||||
532 | d.width = sourceMargins.right(); | - | ||||||||||||
533 | d.height = sourceCenterHeight; | - | ||||||||||||
534 | d.x = (0.5 * (xTarget[columns] + xTarget[columns - 1])); | - | ||||||||||||
535 | d.scaleX = qreal(xTarget[columns] - xTarget[columns - 1]) / d.width; | - | ||||||||||||
536 | d.scaleY = dy / d.height; | - | ||||||||||||
537 | for (int i = 1; i < rows - 1; ++i) { | - | ||||||||||||
538 | d.y = (0.5 * (yTarget[i + 1] + yTarget[i])); | - | ||||||||||||
539 | data.append(d); | - | ||||||||||||
540 | } | - | ||||||||||||
541 | if (rules.vertical == Qt::RepeatTile) | - | ||||||||||||
542 | data[data.size() - 1].height = ((yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY); | - | ||||||||||||
543 | } | - | ||||||||||||
544 | } | - | ||||||||||||
545 | - | |||||||||||||
546 | - | |||||||||||||
547 | if (targetCenterWidth > 0 && targetCenterHeight > 0 && sourceCenterWidth > 0 && sourceCenterHeight > 0) { | - | ||||||||||||
548 | QPixmapFragmentsArray &data = hints & QDrawBorderPixmap::OpaqueCenter ? opaqueData : translucentData; | - | ||||||||||||
549 | d.sourceLeft = sourceCenterLeft; | - | ||||||||||||
550 | d.sourceTop = sourceCenterTop; | - | ||||||||||||
551 | d.width = sourceCenterWidth; | - | ||||||||||||
552 | d.height = sourceCenterHeight; | - | ||||||||||||
553 | d.scaleX = dx / d.width; | - | ||||||||||||
554 | d.scaleY = dy / d.height; | - | ||||||||||||
555 | - | |||||||||||||
556 | qreal repeatWidth = (xTarget[columns - 1] - xTarget[columns - 2]) / d.scaleX; | - | ||||||||||||
557 | qreal repeatHeight = (yTarget[rows - 1] - yTarget[rows - 2]) / d.scaleY; | - | ||||||||||||
558 | - | |||||||||||||
559 | for (int j = 1; j < rows - 1; ++j) { | - | ||||||||||||
560 | d.y = (0.5 * (yTarget[j + 1] + yTarget[j])); | - | ||||||||||||
561 | for (int i = 1; i < columns - 1; ++i) { | - | ||||||||||||
562 | d.x = (0.5 * (xTarget[i + 1] + xTarget[i])); | - | ||||||||||||
563 | data.append(d); | - | ||||||||||||
564 | } | - | ||||||||||||
565 | if (rules.horizontal == Qt::RepeatTile) | - | ||||||||||||
566 | data[data.size() - 1].width = repeatWidth; | - | ||||||||||||
567 | } | - | ||||||||||||
568 | if (rules.vertical == Qt::RepeatTile) { | - | ||||||||||||
569 | for (int i = 1; i < columns - 1; ++i) | - | ||||||||||||
570 | data[data.size() - i].height = repeatHeight; | - | ||||||||||||
571 | } | - | ||||||||||||
572 | } | - | ||||||||||||
573 | - | |||||||||||||
574 | if (opaqueData.size()) | - | ||||||||||||
575 | painter->drawPixmapFragments(opaqueData.data(), opaqueData.size(), pixmap, QPainter::OpaqueHint); | - | ||||||||||||
576 | if (translucentData.size()) | - | ||||||||||||
577 | painter->drawPixmapFragments(translucentData.data(), translucentData.size(), pixmap); | - | ||||||||||||
578 | - | |||||||||||||
579 | if (oldAA) | - | ||||||||||||
580 | painter->setRenderHint(QPainter::Antialiasing, true); | - | ||||||||||||
581 | } | - | ||||||||||||
582 | - | |||||||||||||
583 | - | |||||||||||||
Switch to Source code | Preprocessed file |