Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/painting/qcssutil.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
16 | ** | - | ||||||||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qcssutil_p.h" | - | ||||||||||||||||||
35 | #include "private/qcssparser_p.h" | - | ||||||||||||||||||
36 | #include "qpainter.h" | - | ||||||||||||||||||
37 | #include <qmath.h> | - | ||||||||||||||||||
38 | - | |||||||||||||||||||
39 | #ifndef QT_NO_CSSPARSER | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
42 | - | |||||||||||||||||||
43 | using namespace QCss; | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | static QPen qPenFromStyle(const QBrush& b, qreal width, BorderStyle s) | - | ||||||||||||||||||
46 | { | - | ||||||||||||||||||
47 | Qt::PenStyle ps = Qt::NoPen; | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | switch (s) { | - | ||||||||||||||||||
50 | case BorderStyle_Dotted: never executed: case BorderStyle_Dotted: | 0 | ||||||||||||||||||
51 | ps = Qt::DotLine; | - | ||||||||||||||||||
52 | break; never executed: break; | 0 | ||||||||||||||||||
53 | case BorderStyle_Dashed: never executed: case BorderStyle_Dashed: | 0 | ||||||||||||||||||
54 | ps = width == 1 ? Qt::DotLine : Qt::DashLine;
| 0 | ||||||||||||||||||
55 | break; never executed: break; | 0 | ||||||||||||||||||
56 | case BorderStyle_DotDash: never executed: case BorderStyle_DotDash: | 0 | ||||||||||||||||||
57 | ps = Qt::DashDotLine; | - | ||||||||||||||||||
58 | break; never executed: break; | 0 | ||||||||||||||||||
59 | case BorderStyle_DotDotDash: never executed: case BorderStyle_DotDotDash: | 0 | ||||||||||||||||||
60 | ps = Qt::DashDotDotLine; | - | ||||||||||||||||||
61 | break; never executed: break; | 0 | ||||||||||||||||||
62 | case BorderStyle_Inset: never executed: case BorderStyle_Inset: | 0 | ||||||||||||||||||
63 | case BorderStyle_Outset: never executed: case BorderStyle_Outset: | 0 | ||||||||||||||||||
64 | case BorderStyle_Solid: never executed: case BorderStyle_Solid: | 0 | ||||||||||||||||||
65 | ps = Qt::SolidLine; | - | ||||||||||||||||||
66 | break; never executed: break; | 0 | ||||||||||||||||||
67 | default: never executed: default: | 0 | ||||||||||||||||||
68 | break; never executed: break; | 0 | ||||||||||||||||||
69 | } | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | return QPen(b, width, ps, Qt::FlatCap); never executed: return QPen(b, width, ps, Qt::FlatCap); | 0 | ||||||||||||||||||
72 | } | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | void qDrawRoundedCorners(QPainter *p, qreal x1, qreal y1, qreal x2, qreal y2, | - | ||||||||||||||||||
75 | const QSizeF& r1, const QSizeF& r2, | - | ||||||||||||||||||
76 | Edge edge, BorderStyle s, QBrush c) | - | ||||||||||||||||||
77 | { | - | ||||||||||||||||||
78 | const qreal pw = (edge == TopEdge || edge == BottomEdge) ? y2-y1 : x2-x1;
| 0 | ||||||||||||||||||
79 | if (s == BorderStyle_Double) {
| 0 | ||||||||||||||||||
80 | qreal wby3 = pw/3; | - | ||||||||||||||||||
81 | switch (edge) { | - | ||||||||||||||||||
82 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
83 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
84 | qDrawRoundedCorners(p, x1, y1, x2, y1+wby3, r1, r2, edge, BorderStyle_Solid, c); | - | ||||||||||||||||||
85 | qDrawRoundedCorners(p, x1, y2-wby3, x2, y2, r1, r2, edge, BorderStyle_Solid, c); | - | ||||||||||||||||||
86 | break; never executed: break; | 0 | ||||||||||||||||||
87 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
88 | qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
89 | qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
90 | break; never executed: break; | 0 | ||||||||||||||||||
91 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
92 | qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, RightEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
93 | qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, RightEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
94 | break; never executed: break; | 0 | ||||||||||||||||||
95 | default: never executed: default: | 0 | ||||||||||||||||||
96 | break; never executed: break; | 0 | ||||||||||||||||||
97 | } | - | ||||||||||||||||||
98 | return; never executed: return; | 0 | ||||||||||||||||||
99 | } else if (s == BorderStyle_Ridge || s == BorderStyle_Groove) {
| 0 | ||||||||||||||||||
100 | BorderStyle s1, s2; | - | ||||||||||||||||||
101 | if (s == BorderStyle_Groove) {
| 0 | ||||||||||||||||||
102 | s1 = BorderStyle_Inset; | - | ||||||||||||||||||
103 | s2 = BorderStyle_Outset; | - | ||||||||||||||||||
104 | } else { never executed: end of block | 0 | ||||||||||||||||||
105 | s1 = BorderStyle_Outset; | - | ||||||||||||||||||
106 | s2 = BorderStyle_Inset; | - | ||||||||||||||||||
107 | } never executed: end of block | 0 | ||||||||||||||||||
108 | int pwby2 = qRound(pw/2); | - | ||||||||||||||||||
109 | switch (edge) { | - | ||||||||||||||||||
110 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
111 | qDrawRoundedCorners(p, x1, y1, x2, y1 + pwby2, r1, r2, TopEdge, s1, c); | - | ||||||||||||||||||
112 | qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, TopEdge, s2, c); | - | ||||||||||||||||||
113 | break; never executed: break; | 0 | ||||||||||||||||||
114 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
115 | qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, BottomEdge, s1, c); | - | ||||||||||||||||||
116 | qDrawRoundedCorners(p, x1, y1, x2, y2-pwby2, r1, r2, BottomEdge, s2, c); | - | ||||||||||||||||||
117 | break; never executed: break; | 0 | ||||||||||||||||||
118 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
119 | qDrawRoundedCorners(p, x1, y1, x1 + pwby2, y2, r1, r2, LeftEdge, s1, c); | - | ||||||||||||||||||
120 | qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, LeftEdge, s2, c); | - | ||||||||||||||||||
121 | break; never executed: break; | 0 | ||||||||||||||||||
122 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
123 | qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, RightEdge, s1, c); | - | ||||||||||||||||||
124 | qDrawRoundedCorners(p, x1, y1, x2 - pwby2, y2, r1, r2, RightEdge, s2, c); | - | ||||||||||||||||||
125 | break; never executed: break; | 0 | ||||||||||||||||||
126 | default: never executed: default: | 0 | ||||||||||||||||||
127 | break; never executed: break; | 0 | ||||||||||||||||||
128 | } | - | ||||||||||||||||||
129 | } else if ((s == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
| 0 | ||||||||||||||||||
130 | || (s == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
| 0 | ||||||||||||||||||
131 | c = c.color().lighter(); never executed: c = c.color().lighter(); | 0 | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | p->save(); | - | ||||||||||||||||||
134 | qreal pwby2 = pw/2; | - | ||||||||||||||||||
135 | p->setBrush(Qt::NoBrush); | - | ||||||||||||||||||
136 | QPen pen = qPenFromStyle(c, pw, s); | - | ||||||||||||||||||
137 | pen.setCapStyle(Qt::SquareCap); // this eliminates the offby1 errors that we might hit below | - | ||||||||||||||||||
138 | p->setPen(pen); | - | ||||||||||||||||||
139 | switch (edge) { | - | ||||||||||||||||||
140 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
141 | if (!r1.isEmpty())
| 0 | ||||||||||||||||||
142 | p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2, never executed: p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16); | 0 | ||||||||||||||||||
143 | 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16); never executed: p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16); | 0 | ||||||||||||||||||
144 | if (!r2.isEmpty())
| 0 | ||||||||||||||||||
145 | p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2, never executed: p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16); | 0 | ||||||||||||||||||
146 | 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16); never executed: p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16); | 0 | ||||||||||||||||||
147 | break; never executed: break; | 0 | ||||||||||||||||||
148 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
149 | if (!r1.isEmpty())
| 0 | ||||||||||||||||||
150 | p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2, never executed: p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16); | 0 | ||||||||||||||||||
151 | 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16); never executed: p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16); | 0 | ||||||||||||||||||
152 | if (!r2.isEmpty())
| 0 | ||||||||||||||||||
153 | p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2, never executed: p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16); | 0 | ||||||||||||||||||
154 | 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16); never executed: p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16); | 0 | ||||||||||||||||||
155 | break; never executed: break; | 0 | ||||||||||||||||||
156 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
157 | if (!r1.isEmpty())
| 0 | ||||||||||||||||||
158 | p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2, never executed: p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16); | 0 | ||||||||||||||||||
159 | 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16); never executed: p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16); | 0 | ||||||||||||||||||
160 | if (!r2.isEmpty())
| 0 | ||||||||||||||||||
161 | p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2, never executed: p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16); | 0 | ||||||||||||||||||
162 | 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16); never executed: p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16); | 0 | ||||||||||||||||||
163 | break; never executed: break; | 0 | ||||||||||||||||||
164 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
165 | if (!r1.isEmpty())
| 0 | ||||||||||||||||||
166 | p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2, never executed: p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16); | 0 | ||||||||||||||||||
167 | 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16); never executed: p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16); | 0 | ||||||||||||||||||
168 | if (!r2.isEmpty())
| 0 | ||||||||||||||||||
169 | p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2, never executed: p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16); | 0 | ||||||||||||||||||
170 | 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16); never executed: p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16); | 0 | ||||||||||||||||||
171 | break; never executed: break; | 0 | ||||||||||||||||||
172 | default: never executed: default: | 0 | ||||||||||||||||||
173 | break; never executed: break; | 0 | ||||||||||||||||||
174 | } | - | ||||||||||||||||||
175 | p->restore(); | - | ||||||||||||||||||
176 | } never executed: end of block | 0 | ||||||||||||||||||
177 | - | |||||||||||||||||||
178 | - | |||||||||||||||||||
179 | void qDrawEdge(QPainter *p, qreal x1, qreal y1, qreal x2, qreal y2, qreal dw1, qreal dw2, | - | ||||||||||||||||||
180 | QCss::Edge edge, QCss::BorderStyle style, QBrush c) | - | ||||||||||||||||||
181 | { | - | ||||||||||||||||||
182 | p->save(); | - | ||||||||||||||||||
183 | const qreal width = (edge == TopEdge || edge == BottomEdge) ? (y2-y1) : (x2-x1);
| 0 | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | if (width <= 2 && style == BorderStyle_Double)
| 0 | ||||||||||||||||||
186 | style = BorderStyle_Solid; never executed: style = BorderStyle_Solid; | 0 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | switch (style) { | - | ||||||||||||||||||
189 | case BorderStyle_Inset: never executed: case BorderStyle_Inset: | 0 | ||||||||||||||||||
190 | case BorderStyle_Outset: never executed: case BorderStyle_Outset: | 0 | ||||||||||||||||||
191 | if ((style == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge))
| 0 | ||||||||||||||||||
192 | || (style == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge)))
| 0 | ||||||||||||||||||
193 | c = c.color().lighter(); never executed: c = c.color().lighter(); | 0 | ||||||||||||||||||
194 | // fall through! | - | ||||||||||||||||||
195 | case BorderStyle_Solid: { code before this statement never executed: case BorderStyle_Solid: never executed: case BorderStyle_Solid: | 0 | ||||||||||||||||||
196 | p->setPen(Qt::NoPen); | - | ||||||||||||||||||
197 | p->setBrush(c); | - | ||||||||||||||||||
198 | if (width == 1 || (dw1 == 0 && dw2 == 0)) {
| 0 | ||||||||||||||||||
199 | p->drawRect(QRectF(x1, y1, x2-x1, y2-y1)); | - | ||||||||||||||||||
200 | } else { // draw trapezoid never executed: end of block | 0 | ||||||||||||||||||
201 | QPolygonF quad; | - | ||||||||||||||||||
202 | switch (edge) { | - | ||||||||||||||||||
203 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
204 | quad << QPointF(x1, y1) << QPointF(x1 + dw1, y2) | - | ||||||||||||||||||
205 | << QPointF(x2 - dw2, y2) << QPointF(x2, y1); | - | ||||||||||||||||||
206 | break; never executed: break; | 0 | ||||||||||||||||||
207 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
208 | quad << QPointF(x1 + dw1, y1) << QPointF(x1, y2) | - | ||||||||||||||||||
209 | << QPointF(x2, y2) << QPointF(x2 - dw2, y1); | - | ||||||||||||||||||
210 | break; never executed: break; | 0 | ||||||||||||||||||
211 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
212 | quad << QPointF(x1, y1) << QPointF(x1, y2) | - | ||||||||||||||||||
213 | << QPointF(x2, y2 - dw2) << QPointF(x2, y1 + dw1); | - | ||||||||||||||||||
214 | break; never executed: break; | 0 | ||||||||||||||||||
215 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
216 | quad << QPointF(x1, y1 + dw1) << QPointF(x1, y2 - dw2) | - | ||||||||||||||||||
217 | << QPointF(x2, y2) << QPointF(x2, y1); | - | ||||||||||||||||||
218 | break; never executed: break; | 0 | ||||||||||||||||||
219 | default: never executed: default: | 0 | ||||||||||||||||||
220 | break; never executed: break; | 0 | ||||||||||||||||||
221 | } | - | ||||||||||||||||||
222 | p->drawConvexPolygon(quad); | - | ||||||||||||||||||
223 | } never executed: end of block | 0 | ||||||||||||||||||
224 | break; never executed: break; | 0 | ||||||||||||||||||
225 | } | - | ||||||||||||||||||
226 | case BorderStyle_Dotted: never executed: case BorderStyle_Dotted: | 0 | ||||||||||||||||||
227 | case BorderStyle_Dashed: never executed: case BorderStyle_Dashed: | 0 | ||||||||||||||||||
228 | case BorderStyle_DotDash: never executed: case BorderStyle_DotDash: | 0 | ||||||||||||||||||
229 | case BorderStyle_DotDotDash: never executed: case BorderStyle_DotDotDash: | 0 | ||||||||||||||||||
230 | p->setPen(qPenFromStyle(c, width, style)); | - | ||||||||||||||||||
231 | if (width == 1)
| 0 | ||||||||||||||||||
232 | p->drawLine(QLineF(x1, y1, x2 - 1, y2 - 1)); never executed: p->drawLine(QLineF(x1, y1, x2 - 1, y2 - 1)); | 0 | ||||||||||||||||||
233 | else if (edge == TopEdge || edge == BottomEdge)
| 0 | ||||||||||||||||||
234 | p->drawLine(QLineF(x1 + width/2, (y1 + y2)/2, x2 - width/2, (y1 + y2)/2)); never executed: p->drawLine(QLineF(x1 + width/2, (y1 + y2)/2, x2 - width/2, (y1 + y2)/2)); | 0 | ||||||||||||||||||
235 | else | - | ||||||||||||||||||
236 | p->drawLine(QLineF((x1+x2)/2, y1 + width/2, (x1+x2)/2, y2 - width/2)); never executed: p->drawLine(QLineF((x1+x2)/2, y1 + width/2, (x1+x2)/2, y2 - width/2)); | 0 | ||||||||||||||||||
237 | break; never executed: break; | 0 | ||||||||||||||||||
238 | - | |||||||||||||||||||
239 | case BorderStyle_Double: { never executed: case BorderStyle_Double: | 0 | ||||||||||||||||||
240 | int wby3 = qRound(width/3); | - | ||||||||||||||||||
241 | int dw1by3 = qRound(dw1/3); | - | ||||||||||||||||||
242 | int dw2by3 = qRound(dw2/3); | - | ||||||||||||||||||
243 | switch (edge) { | - | ||||||||||||||||||
244 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
245 | qDrawEdge(p, x1, y1, x2, y1 + wby3, dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
246 | qDrawEdge(p, x1 + dw1 - dw1by3, y2 - wby3, x2 - dw2 + dw1by3, y2, | - | ||||||||||||||||||
247 | dw1by3, dw2by3, TopEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
248 | break; never executed: break; | 0 | ||||||||||||||||||
249 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
250 | qDrawEdge(p, x1, y1, x1 + wby3, y2, dw1by3, dw2by3, LeftEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
251 | qDrawEdge(p, x2 - wby3, y1 + dw1 - dw1by3, x2, y2 - dw2 + dw2by3, dw1by3, dw2by3, | - | ||||||||||||||||||
252 | LeftEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
253 | break; never executed: break; | 0 | ||||||||||||||||||
254 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
255 | qDrawEdge(p, x1 + dw1 - dw1by3, y1, x2 - dw2 + dw2by3, y1 + wby3, dw1by3, dw2by3, | - | ||||||||||||||||||
256 | BottomEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
257 | qDrawEdge(p, x1, y2 - wby3, x2, y2, dw1by3, dw2by3, BottomEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
258 | break; never executed: break; | 0 | ||||||||||||||||||
259 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
260 | qDrawEdge(p, x2 - wby3, y1, x2, y2, dw1by3, dw2by3, RightEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
261 | qDrawEdge(p, x1, y1 + dw1 - dw1by3, x1 + wby3, y2 - dw2 + dw2by3, dw1by3, dw2by3, | - | ||||||||||||||||||
262 | RightEdge, BorderStyle_Solid, c); | - | ||||||||||||||||||
263 | break; never executed: break; | 0 | ||||||||||||||||||
264 | default: never executed: default: | 0 | ||||||||||||||||||
265 | break; never executed: break; | 0 | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | break; never executed: break; | 0 | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | case BorderStyle_Ridge: never executed: case BorderStyle_Ridge: | 0 | ||||||||||||||||||
270 | case BorderStyle_Groove: { never executed: case BorderStyle_Groove: | 0 | ||||||||||||||||||
271 | BorderStyle s1, s2; | - | ||||||||||||||||||
272 | if (style == BorderStyle_Groove) {
| 0 | ||||||||||||||||||
273 | s1 = BorderStyle_Inset; | - | ||||||||||||||||||
274 | s2 = BorderStyle_Outset; | - | ||||||||||||||||||
275 | } else { never executed: end of block | 0 | ||||||||||||||||||
276 | s1 = BorderStyle_Outset; | - | ||||||||||||||||||
277 | s2 = BorderStyle_Inset; | - | ||||||||||||||||||
278 | } never executed: end of block | 0 | ||||||||||||||||||
279 | int dw1by2 = qFloor(dw1/2), dw2by2 = qFloor(dw2/2); | - | ||||||||||||||||||
280 | int wby2 = qRound(width/2); | - | ||||||||||||||||||
281 | switch (edge) { | - | ||||||||||||||||||
282 | case TopEdge: never executed: case TopEdge: | 0 | ||||||||||||||||||
283 | qDrawEdge(p, x1, y1, x2, y1 + wby2, dw1by2, dw2by2, TopEdge, s1, c); | - | ||||||||||||||||||
284 | qDrawEdge(p, x1 + dw1by2, y1 + wby2, x2 - dw2by2, y2, dw1by2, dw2by2, TopEdge, s2, c); | - | ||||||||||||||||||
285 | break; never executed: break; | 0 | ||||||||||||||||||
286 | case BottomEdge: never executed: case BottomEdge: | 0 | ||||||||||||||||||
287 | qDrawEdge(p, x1, y1 + wby2, x2, y2, dw1by2, dw2by2, BottomEdge, s1, c); | - | ||||||||||||||||||
288 | qDrawEdge(p, x1 + dw1by2, y1, x2 - dw2by2, y1 + wby2, dw1by2, dw2by2, BottomEdge, s2, c); | - | ||||||||||||||||||
289 | break; never executed: break; | 0 | ||||||||||||||||||
290 | case LeftEdge: never executed: case LeftEdge: | 0 | ||||||||||||||||||
291 | qDrawEdge(p, x1, y1, x1 + wby2, y2, dw1by2, dw2by2, LeftEdge, s1, c); | - | ||||||||||||||||||
292 | qDrawEdge(p, x1 + wby2, y1 + dw1by2, x2, y2 - dw2by2, dw1by2, dw2by2, LeftEdge, s2, c); | - | ||||||||||||||||||
293 | break; never executed: break; | 0 | ||||||||||||||||||
294 | case RightEdge: never executed: case RightEdge: | 0 | ||||||||||||||||||
295 | qDrawEdge(p, x1 + wby2, y1, x2, y2, dw1by2, dw2by2, RightEdge, s1, c); | - | ||||||||||||||||||
296 | qDrawEdge(p, x1, y1 + dw1by2, x1 + wby2, y2 - dw2by2, dw1by2, dw2by2, RightEdge, s2, c); | - | ||||||||||||||||||
297 | break; never executed: break; | 0 | ||||||||||||||||||
298 | default: never executed: default: | 0 | ||||||||||||||||||
299 | break; never executed: break; | 0 | ||||||||||||||||||
300 | } | - | ||||||||||||||||||
301 | } | - | ||||||||||||||||||
302 | default: code before this statement never executed: default: never executed: default: | 0 | ||||||||||||||||||
303 | break; never executed: break; | 0 | ||||||||||||||||||
304 | } | - | ||||||||||||||||||
305 | p->restore(); | - | ||||||||||||||||||
306 | } never executed: end of block | 0 | ||||||||||||||||||
307 | - | |||||||||||||||||||
308 | void qNormalizeRadii(const QRect &br, const QSize *radii, | - | ||||||||||||||||||
309 | QSize *tlr, QSize *trr, QSize *blr, QSize *brr) | - | ||||||||||||||||||
310 | { | - | ||||||||||||||||||
311 | *tlr = radii[0].expandedTo(QSize(0, 0)); | - | ||||||||||||||||||
312 | *trr = radii[1].expandedTo(QSize(0, 0)); | - | ||||||||||||||||||
313 | *blr = radii[2].expandedTo(QSize(0, 0)); | - | ||||||||||||||||||
314 | *brr = radii[3].expandedTo(QSize(0, 0)); | - | ||||||||||||||||||
315 | if (tlr->width() + trr->width() > br.width())
| 0 | ||||||||||||||||||
316 | *tlr = *trr = QSize(0, 0); never executed: *tlr = *trr = QSize(0, 0); | 0 | ||||||||||||||||||
317 | if (blr->width() + brr->width() > br.width())
| 0 | ||||||||||||||||||
318 | *blr = *brr = QSize(0, 0); never executed: *blr = *brr = QSize(0, 0); | 0 | ||||||||||||||||||
319 | if (tlr->height() + blr->height() > br.height())
| 0 | ||||||||||||||||||
320 | *tlr = *blr = QSize(0, 0); never executed: *tlr = *blr = QSize(0, 0); | 0 | ||||||||||||||||||
321 | if (trr->height() + brr->height() > br.height())
| 0 | ||||||||||||||||||
322 | *trr = *brr = QSize(0, 0); never executed: *trr = *brr = QSize(0, 0); | 0 | ||||||||||||||||||
323 | } never executed: end of block | 0 | ||||||||||||||||||
324 | - | |||||||||||||||||||
325 | // Determines if Edge e1 draws over Edge e2. Depending on this trapezoids or rectanges are drawn | - | ||||||||||||||||||
326 | static bool paintsOver(const QCss::BorderStyle *styles, const QBrush *colors, QCss::Edge e1, QCss::Edge e2) | - | ||||||||||||||||||
327 | { | - | ||||||||||||||||||
328 | QCss::BorderStyle s1 = styles[e1]; | - | ||||||||||||||||||
329 | QCss::BorderStyle s2 = styles[e2]; | - | ||||||||||||||||||
330 | - | |||||||||||||||||||
331 | if (s2 == BorderStyle_None || colors[e2] == Qt::transparent)
| 0 | ||||||||||||||||||
332 | return true; never executed: return true; | 0 | ||||||||||||||||||
333 | - | |||||||||||||||||||
334 | if ((s1 == BorderStyle_Solid && s2 == BorderStyle_Solid) && (colors[e1] == colors[e2]))
| 0 | ||||||||||||||||||
335 | return true; never executed: return true; | 0 | ||||||||||||||||||
336 | - | |||||||||||||||||||
337 | return false; never executed: return false; | 0 | ||||||||||||||||||
338 | } | - | ||||||||||||||||||
339 | - | |||||||||||||||||||
340 | void qDrawBorder(QPainter *p, const QRect &rect, const QCss::BorderStyle *styles, | - | ||||||||||||||||||
341 | const int *borders, const QBrush *colors, const QSize *radii) | - | ||||||||||||||||||
342 | { | - | ||||||||||||||||||
343 | const QRectF br(rect); | - | ||||||||||||||||||
344 | QSize tlr, trr, blr, brr; | - | ||||||||||||||||||
345 | qNormalizeRadii(rect, radii, &tlr, &trr, &blr, &brr); | - | ||||||||||||||||||
346 | - | |||||||||||||||||||
347 | // Drawn in increasing order of precendence | - | ||||||||||||||||||
348 | if (styles[BottomEdge] != BorderStyle_None && borders[BottomEdge] > 0) {
| 0 | ||||||||||||||||||
349 | qreal dw1 = (blr.width() || paintsOver(styles, colors, BottomEdge, LeftEdge)) ? 0 : borders[LeftEdge];
| 0 | ||||||||||||||||||
350 | qreal dw2 = (brr.width() || paintsOver(styles, colors, BottomEdge, RightEdge)) ? 0 : borders[RightEdge];
| 0 | ||||||||||||||||||
351 | qreal x1 = br.x() + blr.width(); | - | ||||||||||||||||||
352 | qreal y1 = br.y() + br.height() - borders[BottomEdge]; | - | ||||||||||||||||||
353 | qreal x2 = br.x() + br.width() - brr.width(); | - | ||||||||||||||||||
354 | qreal y2 = br.y() + br.height() ; | - | ||||||||||||||||||
355 | - | |||||||||||||||||||
356 | qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, BottomEdge, styles[BottomEdge], colors[BottomEdge]); | - | ||||||||||||||||||
357 | if (blr.width() || brr.width())
| 0 | ||||||||||||||||||
358 | qDrawRoundedCorners(p, x1, y1, x2, y2, blr, brr, BottomEdge, styles[BottomEdge], colors[BottomEdge]); never executed: qDrawRoundedCorners(p, x1, y1, x2, y2, blr, brr, BottomEdge, styles[BottomEdge], colors[BottomEdge]); | 0 | ||||||||||||||||||
359 | } never executed: end of block | 0 | ||||||||||||||||||
360 | if (styles[RightEdge] != BorderStyle_None && borders[RightEdge] > 0) {
| 0 | ||||||||||||||||||
361 | qreal dw1 = (trr.height() || paintsOver(styles, colors, RightEdge, TopEdge)) ? 0 : borders[TopEdge];
| 0 | ||||||||||||||||||
362 | qreal dw2 = (brr.height() || paintsOver(styles, colors, RightEdge, BottomEdge)) ? 0 : borders[BottomEdge];
| 0 | ||||||||||||||||||
363 | qreal x1 = br.x() + br.width() - borders[RightEdge]; | - | ||||||||||||||||||
364 | qreal y1 = br.y() + trr.height(); | - | ||||||||||||||||||
365 | qreal x2 = br.x() + br.width(); | - | ||||||||||||||||||
366 | qreal y2 = br.y() + br.height() - brr.height(); | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, RightEdge, styles[RightEdge], colors[RightEdge]); | - | ||||||||||||||||||
369 | if (trr.height() || brr.height())
| 0 | ||||||||||||||||||
370 | qDrawRoundedCorners(p, x1, y1, x2, y2, trr, brr, RightEdge, styles[RightEdge], colors[RightEdge]); never executed: qDrawRoundedCorners(p, x1, y1, x2, y2, trr, brr, RightEdge, styles[RightEdge], colors[RightEdge]); | 0 | ||||||||||||||||||
371 | } never executed: end of block | 0 | ||||||||||||||||||
372 | if (styles[LeftEdge] != BorderStyle_None && borders[LeftEdge] > 0) {
| 0 | ||||||||||||||||||
373 | qreal dw1 = (tlr.height() || paintsOver(styles, colors, LeftEdge, TopEdge)) ? 0 : borders[TopEdge];
| 0 | ||||||||||||||||||
374 | qreal dw2 = (blr.height() || paintsOver(styles, colors, LeftEdge, BottomEdge)) ? 0 : borders[BottomEdge];
| 0 | ||||||||||||||||||
375 | qreal x1 = br.x(); | - | ||||||||||||||||||
376 | qreal y1 = br.y() + tlr.height(); | - | ||||||||||||||||||
377 | qreal x2 = br.x() + borders[LeftEdge]; | - | ||||||||||||||||||
378 | qreal y2 = br.y() + br.height() - blr.height(); | - | ||||||||||||||||||
379 | - | |||||||||||||||||||
380 | qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, LeftEdge, styles[LeftEdge], colors[LeftEdge]); | - | ||||||||||||||||||
381 | if (tlr.height() || blr.height())
| 0 | ||||||||||||||||||
382 | qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, blr, LeftEdge, styles[LeftEdge], colors[LeftEdge]); never executed: qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, blr, LeftEdge, styles[LeftEdge], colors[LeftEdge]); | 0 | ||||||||||||||||||
383 | } never executed: end of block | 0 | ||||||||||||||||||
384 | if (styles[TopEdge] != BorderStyle_None && borders[TopEdge] > 0) {
| 0 | ||||||||||||||||||
385 | qreal dw1 = (tlr.width() || paintsOver(styles, colors, TopEdge, LeftEdge)) ? 0 : borders[LeftEdge];
| 0 | ||||||||||||||||||
386 | qreal dw2 = (trr.width() || paintsOver(styles, colors, TopEdge, RightEdge)) ? 0 : borders[RightEdge];
| 0 | ||||||||||||||||||
387 | qreal x1 = br.x() + tlr.width(); | - | ||||||||||||||||||
388 | qreal y1 = br.y(); | - | ||||||||||||||||||
389 | qreal x2 = br.left() + br.width() - trr.width(); | - | ||||||||||||||||||
390 | qreal y2 = br.y() + borders[TopEdge]; | - | ||||||||||||||||||
391 | - | |||||||||||||||||||
392 | qDrawEdge(p, x1, y1, x2, y2, dw1, dw2, TopEdge, styles[TopEdge], colors[TopEdge]); | - | ||||||||||||||||||
393 | if (tlr.width() || trr.width())
| 0 | ||||||||||||||||||
394 | qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, trr, TopEdge, styles[TopEdge], colors[TopEdge]); never executed: qDrawRoundedCorners(p, x1, y1, x2, y2, tlr, trr, TopEdge, styles[TopEdge], colors[TopEdge]); | 0 | ||||||||||||||||||
395 | } never executed: end of block | 0 | ||||||||||||||||||
396 | } never executed: end of block | 0 | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | #endif //QT_NO_CSSPARSER | - | ||||||||||||||||||
399 | - | |||||||||||||||||||
400 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |