| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwareinternalrectanglenode.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 24 | ** | - | ||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qsgsoftwareinternalrectanglenode_p.h" | - | ||||||||||||
| 41 | #include <qmath.h> | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #include <QtGui/QPainter> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QSGSoftwareInternalRectangleNode::QSGSoftwareInternalRectangleNode() | - | ||||||||||||
| 48 | : m_penWidth(0) | - | ||||||||||||
| 49 | , m_radius(0) | - | ||||||||||||
| 50 | , m_vertical(true) | - | ||||||||||||
| 51 | , m_cornerPixmapIsDirty(true) | - | ||||||||||||
| 52 | , m_devicePixelRatio(1) | - | ||||||||||||
| 53 | { | - | ||||||||||||
| 54 | m_pen.setJoinStyle(Qt::MiterJoin); | - | ||||||||||||
| 55 | m_pen.setMiterLimit(0); | - | ||||||||||||
| 56 | setMaterial((QSGMaterial*)1); | - | ||||||||||||
| 57 | setGeometry((QSGGeometry*)1); | - | ||||||||||||
| 58 | } never executed: end of block | 0 | ||||||||||||
| 59 | - | |||||||||||||
| 60 | void QSGSoftwareInternalRectangleNode::setRect(const QRectF &rect) | - | ||||||||||||
| 61 | { | - | ||||||||||||
| 62 | QRect alignedRect = rect.toAlignedRect(); | - | ||||||||||||
| 63 | if (m_rect != alignedRect) {
| 0 | ||||||||||||
| 64 | m_rect = alignedRect; | - | ||||||||||||
| 65 | markDirty(DirtyMaterial); | - | ||||||||||||
| 66 | } never executed: end of block | 0 | ||||||||||||
| 67 | } never executed: end of block | 0 | ||||||||||||
| 68 | - | |||||||||||||
| 69 | void QSGSoftwareInternalRectangleNode::setColor(const QColor &color) | - | ||||||||||||
| 70 | { | - | ||||||||||||
| 71 | if (m_color != color) {
| 0 | ||||||||||||
| 72 | m_color = color; | - | ||||||||||||
| 73 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 74 | markDirty(DirtyMaterial); | - | ||||||||||||
| 75 | } never executed: end of block | 0 | ||||||||||||
| 76 | } never executed: end of block | 0 | ||||||||||||
| 77 | - | |||||||||||||
| 78 | void QSGSoftwareInternalRectangleNode::setPenColor(const QColor &color) | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | if (m_penColor != color) {
| 0 | ||||||||||||
| 81 | m_penColor = color; | - | ||||||||||||
| 82 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 83 | markDirty(DirtyMaterial); | - | ||||||||||||
| 84 | } never executed: end of block | 0 | ||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | void QSGSoftwareInternalRectangleNode::setPenWidth(qreal width) | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | if (m_penWidth != width) {
| 0 | ||||||||||||
| 90 | m_penWidth = width; | - | ||||||||||||
| 91 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 92 | markDirty(DirtyMaterial); | - | ||||||||||||
| 93 | } never executed: end of block | 0 | ||||||||||||
| 94 | } never executed: end of block | 0 | ||||||||||||
| 95 | - | |||||||||||||
| 96 | //Move first stop by pos relative to seconds | - | ||||||||||||
| 97 | static QGradientStop interpolateStop(const QGradientStop &firstStop, const QGradientStop &secondStop, double newPos) | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | double distance = secondStop.first - firstStop.first; | - | ||||||||||||
| 100 | double distanceDelta = newPos - firstStop.first; | - | ||||||||||||
| 101 | double modifierValue = distanceDelta / distance; | - | ||||||||||||
| 102 | int redDelta = (secondStop.second.red() - firstStop.second.red()) * modifierValue; | - | ||||||||||||
| 103 | int greenDelta = (secondStop.second.green() - firstStop.second.green()) * modifierValue; | - | ||||||||||||
| 104 | int blueDelta = (secondStop.second.blue() - firstStop.second.blue()) * modifierValue; | - | ||||||||||||
| 105 | int alphaDelta = (secondStop.second.alpha() - firstStop.second.alpha()) * modifierValue; | - | ||||||||||||
| 106 | - | |||||||||||||
| 107 | QGradientStop newStop; | - | ||||||||||||
| 108 | newStop.first = newPos; | - | ||||||||||||
| 109 | newStop.second = QColor(firstStop.second.red() + redDelta, | - | ||||||||||||
| 110 | firstStop.second.green() + greenDelta, | - | ||||||||||||
| 111 | firstStop.second.blue() + blueDelta, | - | ||||||||||||
| 112 | firstStop.second.alpha() + alphaDelta); | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | return newStop; never executed: return newStop; | 0 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | void QSGSoftwareInternalRectangleNode::setGradientStops(const QGradientStops &stops) | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | //normalize stops | - | ||||||||||||
| 120 | bool needsNormalization = false; | - | ||||||||||||
| 121 | for (const QGradientStop &stop : qAsConst(stops)) { | - | ||||||||||||
| 122 | if (stop.first < 0.0 || stop.first > 1.0) {
| 0 | ||||||||||||
| 123 | needsNormalization = true; | - | ||||||||||||
| 124 | continue; never executed: continue; | 0 | ||||||||||||
| 125 | } | - | ||||||||||||
| 126 | } never executed: end of block | 0 | ||||||||||||
| 127 | - | |||||||||||||
| 128 | if (needsNormalization) {
| 0 | ||||||||||||
| 129 | QGradientStops normalizedStops; | - | ||||||||||||
| 130 | if (stops.count() == 1) {
| 0 | ||||||||||||
| 131 | //If there is only one stop, then the position does not matter | - | ||||||||||||
| 132 | //It is just treated as a color | - | ||||||||||||
| 133 | QGradientStop stop = stops.at(0); | - | ||||||||||||
| 134 | stop.first = 0.0; | - | ||||||||||||
| 135 | normalizedStops.append(stop); | - | ||||||||||||
| 136 | } else { never executed: end of block | 0 | ||||||||||||
| 137 | //Clip stops to only the first below 0.0 and above 1.0 | - | ||||||||||||
| 138 | int below = -1; | - | ||||||||||||
| 139 | int above = -1; | - | ||||||||||||
| 140 | QVector<int> between; | - | ||||||||||||
| 141 | for (int i = 0; i < stops.count(); ++i) {
| 0 | ||||||||||||
| 142 | if (stops.at(i).first < 0.0) {
| 0 | ||||||||||||
| 143 | below = i; | - | ||||||||||||
| 144 | } else if (stops.at(i).first > 1.0) { never executed: end of block
| 0 | ||||||||||||
| 145 | above = i; | - | ||||||||||||
| 146 | break; never executed: break; | 0 | ||||||||||||
| 147 | } else { | - | ||||||||||||
| 148 | between.append(i); | - | ||||||||||||
| 149 | } never executed: end of block | 0 | ||||||||||||
| 150 | } | - | ||||||||||||
| 151 | - | |||||||||||||
| 152 | //Interpoloate new color values for above and below | - | ||||||||||||
| 153 | if (below != -1 ) {
| 0 | ||||||||||||
| 154 | //If there are more than one stops left, interpolate | - | ||||||||||||
| 155 | if (below + 1 < stops.count()) {
| 0 | ||||||||||||
| 156 | normalizedStops.append(interpolateStop(stops.at(below), stops.at(below + 1), 0.0)); | - | ||||||||||||
| 157 | } else { never executed: end of block | 0 | ||||||||||||
| 158 | QGradientStop singleStop; | - | ||||||||||||
| 159 | singleStop.first = 0.0; | - | ||||||||||||
| 160 | singleStop.second = stops.at(below).second; | - | ||||||||||||
| 161 | normalizedStops.append(singleStop); | - | ||||||||||||
| 162 | } never executed: end of block | 0 | ||||||||||||
| 163 | } | - | ||||||||||||
| 164 | - | |||||||||||||
| 165 | for (int i = 0; i < between.count(); ++i)
| 0 | ||||||||||||
| 166 | normalizedStops.append(stops.at(between.at(i))); never executed: normalizedStops.append(stops.at(between.at(i))); | 0 | ||||||||||||
| 167 | - | |||||||||||||
| 168 | if (above != -1) {
| 0 | ||||||||||||
| 169 | //If there stops before above, interpolate | - | ||||||||||||
| 170 | if (above >= 1) {
| 0 | ||||||||||||
| 171 | normalizedStops.append(interpolateStop(stops.at(above), stops.at(above - 1), 1.0)); | - | ||||||||||||
| 172 | } else { never executed: end of block | 0 | ||||||||||||
| 173 | QGradientStop singleStop; | - | ||||||||||||
| 174 | singleStop.first = 1.0; | - | ||||||||||||
| 175 | singleStop.second = stops.at(above).second; | - | ||||||||||||
| 176 | normalizedStops.append(singleStop); | - | ||||||||||||
| 177 | } never executed: end of block | 0 | ||||||||||||
| 178 | } | - | ||||||||||||
| 179 | } never executed: end of block | 0 | ||||||||||||
| 180 | - | |||||||||||||
| 181 | m_stops = normalizedStops; | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | } else { never executed: end of block | 0 | ||||||||||||
| 184 | m_stops = stops; | - | ||||||||||||
| 185 | } never executed: end of block | 0 | ||||||||||||
| 186 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 187 | markDirty(DirtyMaterial); | - | ||||||||||||
| 188 | } never executed: end of block | 0 | ||||||||||||
| 189 | - | |||||||||||||
| 190 | void QSGSoftwareInternalRectangleNode::setGradientVertical(bool vertical) | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | if (m_vertical != vertical) {
| 0 | ||||||||||||
| 193 | m_vertical = vertical; | - | ||||||||||||
| 194 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 195 | markDirty(DirtyMaterial); | - | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | } never executed: end of block | 0 | ||||||||||||
| 198 | - | |||||||||||||
| 199 | void QSGSoftwareInternalRectangleNode::setRadius(qreal radius) | - | ||||||||||||
| 200 | { | - | ||||||||||||
| 201 | if (m_radius != radius) {
| 0 | ||||||||||||
| 202 | m_radius = radius; | - | ||||||||||||
| 203 | m_cornerPixmapIsDirty = true; | - | ||||||||||||
| 204 | markDirty(DirtyMaterial); | - | ||||||||||||
| 205 | } never executed: end of block | 0 | ||||||||||||
| 206 | } never executed: end of block | 0 | ||||||||||||
| 207 | - | |||||||||||||
| 208 | void QSGSoftwareInternalRectangleNode::setAligned(bool /*aligned*/) | - | ||||||||||||
| 209 | { | - | ||||||||||||
| 210 | } | - | ||||||||||||
| 211 | - | |||||||||||||
| 212 | void QSGSoftwareInternalRectangleNode::update() | - | ||||||||||||
| 213 | { | - | ||||||||||||
| 214 | if (!m_penWidth || m_penColor == Qt::transparent) {
| 0 | ||||||||||||
| 215 | m_pen = Qt::NoPen; | - | ||||||||||||
| 216 | } else { never executed: end of block | 0 | ||||||||||||
| 217 | m_pen = QPen(m_penColor); | - | ||||||||||||
| 218 | m_pen.setWidthF(m_penWidth); | - | ||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||
| 220 | - | |||||||||||||
| 221 | if (!m_stops.isEmpty()) {
| 0 | ||||||||||||
| 222 | QLinearGradient gradient(QPoint(0,0), QPoint(m_vertical ? 0 : 1, m_vertical ? 1 : 0)); | - | ||||||||||||
| 223 | gradient.setStops(m_stops); | - | ||||||||||||
| 224 | gradient.setCoordinateMode(QGradient::ObjectBoundingMode); | - | ||||||||||||
| 225 | m_brush = QBrush(gradient); | - | ||||||||||||
| 226 | } else { never executed: end of block | 0 | ||||||||||||
| 227 | m_brush = QBrush(m_color); | - | ||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||
| 229 | - | |||||||||||||
| 230 | if (m_cornerPixmapIsDirty) {
| 0 | ||||||||||||
| 231 | generateCornerPixmap(); | - | ||||||||||||
| 232 | m_cornerPixmapIsDirty = false; | - | ||||||||||||
| 233 | } never executed: end of block | 0 | ||||||||||||
| 234 | } never executed: end of block | 0 | ||||||||||||
| 235 | - | |||||||||||||
| 236 | void QSGSoftwareInternalRectangleNode::paint(QPainter *painter) | - | ||||||||||||
| 237 | { | - | ||||||||||||
| 238 | //We can only check for a device pixel ratio change when we know what | - | ||||||||||||
| 239 | //paint device is being used. | - | ||||||||||||
| 240 | if (!qFuzzyCompare(painter->device()->devicePixelRatioF(), m_devicePixelRatio)) {
| 0 | ||||||||||||
| 241 | m_devicePixelRatio = painter->device()->devicePixelRatioF(); | - | ||||||||||||
| 242 | generateCornerPixmap(); | - | ||||||||||||
| 243 | } never executed: end of block | 0 | ||||||||||||
| 244 | - | |||||||||||||
| 245 | if (painter->transform().isRotating()) {
| 0 | ||||||||||||
| 246 | //Rotated rectangles lose the benefits of direct rendering, and have poor rendering | - | ||||||||||||
| 247 | //quality when using only blits and fills. | - | ||||||||||||
| 248 | - | |||||||||||||
| 249 | if (m_radius == 0 && m_penWidth == 0) {
| 0 | ||||||||||||
| 250 | //Non-Rounded Rects without borders (fall back to drawRect) | - | ||||||||||||
| 251 | //Most common case | - | ||||||||||||
| 252 | painter->setPen(Qt::NoPen); | - | ||||||||||||
| 253 | painter->setBrush(m_brush); | - | ||||||||||||
| 254 | painter->drawRect(m_rect); | - | ||||||||||||
| 255 | } else { never executed: end of block | 0 | ||||||||||||
| 256 | //Rounded Rects and Rects with Borders | - | ||||||||||||
| 257 | //Avoids broken behaviors of QPainter::drawRect/roundedRect | - | ||||||||||||
| 258 | QPixmap pixmap = QPixmap(qRound(m_rect.width() * m_devicePixelRatio), qRound(m_rect.height() * m_devicePixelRatio)); | - | ||||||||||||
| 259 | pixmap.fill(Qt::transparent); | - | ||||||||||||
| 260 | pixmap.setDevicePixelRatio(m_devicePixelRatio); | - | ||||||||||||
| 261 | QPainter pixmapPainter(&pixmap); | - | ||||||||||||
| 262 | paintRectangle(&pixmapPainter, QRect(0, 0, m_rect.width(), m_rect.height())); | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | QPainter::RenderHints previousRenderHints = painter->renderHints(); | - | ||||||||||||
| 265 | painter->setRenderHint(QPainter::SmoothPixmapTransform, true); | - | ||||||||||||
| 266 | painter->drawPixmap(m_rect, pixmap); | - | ||||||||||||
| 267 | painter->setRenderHints(previousRenderHints); | - | ||||||||||||
| 268 | } never executed: end of block | 0 | ||||||||||||
| 269 | - | |||||||||||||
| 270 | - | |||||||||||||
| 271 | } else { | - | ||||||||||||
| 272 | //Paint directly | - | ||||||||||||
| 273 | paintRectangle(painter, m_rect); | - | ||||||||||||
| 274 | } never executed: end of block | 0 | ||||||||||||
| 275 | - | |||||||||||||
| 276 | } | - | ||||||||||||
| 277 | - | |||||||||||||
| 278 | bool QSGSoftwareInternalRectangleNode::isOpaque() const | - | ||||||||||||
| 279 | { | - | ||||||||||||
| 280 | if (m_radius > 0.0f)
| 0 | ||||||||||||
| 281 | return false; never executed: return false; | 0 | ||||||||||||
| 282 | if (m_color.alpha() < 255)
| 0 | ||||||||||||
| 283 | return false; never executed: return false; | 0 | ||||||||||||
| 284 | if (m_penWidth > 0.0f && m_penColor.alpha() < 255)
| 0 | ||||||||||||
| 285 | return false; never executed: return false; | 0 | ||||||||||||
| 286 | if (m_stops.count() > 0) {
| 0 | ||||||||||||
| 287 | for (const QGradientStop &stop : qAsConst(m_stops)) { | - | ||||||||||||
| 288 | if (stop.second.alpha() < 255)
| 0 | ||||||||||||
| 289 | return false; never executed: return false; | 0 | ||||||||||||
| 290 | } never executed: end of block | 0 | ||||||||||||
| 291 | } never executed: end of block | 0 | ||||||||||||
| 292 | - | |||||||||||||
| 293 | return true; never executed: return true; | 0 | ||||||||||||
| 294 | } | - | ||||||||||||
| 295 | - | |||||||||||||
| 296 | QRectF QSGSoftwareInternalRectangleNode::rect() const | - | ||||||||||||
| 297 | { | - | ||||||||||||
| 298 | //TODO: double check that this is correct. | - | ||||||||||||
| 299 | return m_rect; never executed: return m_rect; | 0 | ||||||||||||
| 300 | } | - | ||||||||||||
| 301 | - | |||||||||||||
| 302 | void QSGSoftwareInternalRectangleNode::paintRectangle(QPainter *painter, const QRect &rect) | - | ||||||||||||
| 303 | { | - | ||||||||||||
| 304 | //Radius should never exceeds half of the width or half of the height | - | ||||||||||||
| 305 | int radius = qFloor(qMin(qMin(rect.width(), rect.height()) * 0.5, m_radius)); | - | ||||||||||||
| 306 | - | |||||||||||||
| 307 | QPainter::RenderHints previousRenderHints = painter->renderHints(); | - | ||||||||||||
| 308 | painter->setRenderHint(QPainter::Antialiasing, false); | - | ||||||||||||
| 309 | - | |||||||||||||
| 310 | if (m_penWidth > 0) {
| 0 | ||||||||||||
| 311 | //Fill border Rects | - | ||||||||||||
| 312 | - | |||||||||||||
| 313 | //Borders can not be more than half the height/width of a rect | - | ||||||||||||
| 314 | double borderWidth = qMin(m_penWidth, rect.width() * 0.5); | - | ||||||||||||
| 315 | double borderHeight = qMin(m_penWidth, rect.height() * 0.5); | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | - | |||||||||||||
| 318 | - | |||||||||||||
| 319 | if (borderWidth > radius) {
| 0 | ||||||||||||
| 320 | //4 Rects | - | ||||||||||||
| 321 | QRectF borderTopOutside(QPointF(rect.x() + radius, rect.y()), | - | ||||||||||||
| 322 | QPointF(rect.x() + rect.width() - radius, rect.y() + radius)); | - | ||||||||||||
| 323 | QRectF borderTopInside(QPointF(rect.x() + borderWidth, rect.y() + radius), | - | ||||||||||||
| 324 | QPointF(rect.x() + rect.width() - borderWidth, rect.y() + borderHeight)); | - | ||||||||||||
| 325 | QRectF borderBottomOutside(QPointF(rect.x() + radius, rect.y() + rect.height() - radius), | - | ||||||||||||
| 326 | QPointF(rect.x() + rect.width() - radius, rect.y() + rect.height())); | - | ||||||||||||
| 327 | QRectF borderBottomInside(QPointF(rect.x() + borderWidth, rect.y() + rect.height() - borderHeight), | - | ||||||||||||
| 328 | QPointF(rect.x() + rect.width() - borderWidth, rect.y() + rect.height() - radius)); | - | ||||||||||||
| 329 | - | |||||||||||||
| 330 | if (borderTopOutside.isValid())
| 0 | ||||||||||||
| 331 | painter->fillRect(borderTopOutside, m_penColor); never executed: painter->fillRect(borderTopOutside, m_penColor); | 0 | ||||||||||||
| 332 | if (borderTopInside.isValid())
| 0 | ||||||||||||
| 333 | painter->fillRect(borderTopInside, m_penColor); never executed: painter->fillRect(borderTopInside, m_penColor); | 0 | ||||||||||||
| 334 | if (borderBottomOutside.isValid())
| 0 | ||||||||||||
| 335 | painter->fillRect(borderBottomOutside, m_penColor); never executed: painter->fillRect(borderBottomOutside, m_penColor); | 0 | ||||||||||||
| 336 | if (borderBottomInside.isValid())
| 0 | ||||||||||||
| 337 | painter->fillRect(borderBottomInside, m_penColor); never executed: painter->fillRect(borderBottomInside, m_penColor); | 0 | ||||||||||||
| 338 | - | |||||||||||||
| 339 | } else { never executed: end of block | 0 | ||||||||||||
| 340 | //2 Rects | - | ||||||||||||
| 341 | QRectF borderTop(QPointF(rect.x() + radius, rect.y()), | - | ||||||||||||
| 342 | QPointF(rect.x() + rect.width() - radius, rect.y() + borderHeight)); | - | ||||||||||||
| 343 | QRectF borderBottom(QPointF(rect.x() + radius, rect.y() + rect.height() - borderHeight), | - | ||||||||||||
| 344 | QPointF(rect.x() + rect.width() - radius, rect.y() + rect.height())); | - | ||||||||||||
| 345 | if (borderTop.isValid())
| 0 | ||||||||||||
| 346 | painter->fillRect(borderTop, m_penColor); never executed: painter->fillRect(borderTop, m_penColor); | 0 | ||||||||||||
| 347 | if (borderBottom.isValid())
| 0 | ||||||||||||
| 348 | painter->fillRect(borderBottom, m_penColor); never executed: painter->fillRect(borderBottom, m_penColor); | 0 | ||||||||||||
| 349 | } never executed: end of block | 0 | ||||||||||||
| 350 | QRectF borderLeft(QPointF(rect.x(), rect.y() + radius), | - | ||||||||||||
| 351 | QPointF(rect.x() + borderWidth, rect.y() + rect.height() - radius)); | - | ||||||||||||
| 352 | QRectF borderRight(QPointF(rect.x() + rect.width() - borderWidth, rect.y() + radius), | - | ||||||||||||
| 353 | QPointF(rect.x() + rect.width(), rect.y() + rect.height() - radius)); | - | ||||||||||||
| 354 | if (borderLeft.isValid())
| 0 | ||||||||||||
| 355 | painter->fillRect(borderLeft, m_penColor); never executed: painter->fillRect(borderLeft, m_penColor); | 0 | ||||||||||||
| 356 | if (borderRight.isValid())
| 0 | ||||||||||||
| 357 | painter->fillRect(borderRight, m_penColor); never executed: painter->fillRect(borderRight, m_penColor); | 0 | ||||||||||||
| 358 | } never executed: end of block | 0 | ||||||||||||
| 359 | - | |||||||||||||
| 360 | - | |||||||||||||
| 361 | if (radius > 0) {
| 0 | ||||||||||||
| 362 | - | |||||||||||||
| 363 | if (radius * 2 >= rect.width() && radius * 2 >= rect.height()) {
| 0 | ||||||||||||
| 364 | //Blit whole pixmap for circles | - | ||||||||||||
| 365 | painter->drawPixmap(rect, m_cornerPixmap, m_cornerPixmap.rect()); | - | ||||||||||||
| 366 | } else { never executed: end of block | 0 | ||||||||||||
| 367 | - | |||||||||||||
| 368 | //blit 4 corners to border | - | ||||||||||||
| 369 | int scaledRadius = qRound(radius * m_devicePixelRatio); | - | ||||||||||||
| 370 | QRectF topLeftCorner(QPointF(rect.x(), rect.y()), | - | ||||||||||||
| 371 | QPointF(rect.x() + radius, rect.y() + radius)); | - | ||||||||||||
| 372 | painter->drawPixmap(topLeftCorner, m_cornerPixmap, QRectF(0, 0, scaledRadius, scaledRadius)); | - | ||||||||||||
| 373 | QRectF topRightCorner(QPointF(rect.x() + rect.width() - radius, rect.y()), | - | ||||||||||||
| 374 | QPointF(rect.x() + rect.width(), rect.y() + radius)); | - | ||||||||||||
| 375 | painter->drawPixmap(topRightCorner, m_cornerPixmap, QRectF(scaledRadius, 0, scaledRadius, scaledRadius)); | - | ||||||||||||
| 376 | QRectF bottomLeftCorner(QPointF(rect.x(), rect.y() + rect.height() - radius), | - | ||||||||||||
| 377 | QPointF(rect.x() + radius, rect.y() + rect.height())); | - | ||||||||||||
| 378 | painter->drawPixmap(bottomLeftCorner, m_cornerPixmap, QRectF(0, scaledRadius, scaledRadius, scaledRadius)); | - | ||||||||||||
| 379 | QRectF bottomRightCorner(QPointF(rect.x() + rect.width() - radius, rect.y() + rect.height() - radius), | - | ||||||||||||
| 380 | QPointF(rect.x() + rect.width(), rect.y() + rect.height())); | - | ||||||||||||
| 381 | painter->drawPixmap(bottomRightCorner, m_cornerPixmap, QRectF(scaledRadius, scaledRadius, scaledRadius, scaledRadius)); | - | ||||||||||||
| 382 | - | |||||||||||||
| 383 | } never executed: end of block | 0 | ||||||||||||
| 384 | - | |||||||||||||
| 385 | } | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | QRectF brushRect = QRectF(rect).marginsRemoved(QMarginsF(m_penWidth, m_penWidth, m_penWidth, m_penWidth)); | - | ||||||||||||
| 388 | if (brushRect.width() < 0)
| 0 | ||||||||||||
| 389 | brushRect.setWidth(0); never executed: brushRect.setWidth(0); | 0 | ||||||||||||
| 390 | if (brushRect.height() < 0)
| 0 | ||||||||||||
| 391 | brushRect.setHeight(0); never executed: brushRect.setHeight(0); | 0 | ||||||||||||
| 392 | double innerRectRadius = qMax(0.0, radius - m_penWidth); | - | ||||||||||||
| 393 | - | |||||||||||||
| 394 | //If not completely transparent or has a gradient | - | ||||||||||||
| 395 | if (m_color.alpha() > 0 || !m_stops.empty()) {
| 0 | ||||||||||||
| 396 | if (innerRectRadius > 0) {
| 0 | ||||||||||||
| 397 | //Rounded Rect | - | ||||||||||||
| 398 | if (m_stops.empty()) {
| 0 | ||||||||||||
| 399 | //Rounded Rects without gradient need 3 blits | - | ||||||||||||
| 400 | QRectF centerRect(QPointF(brushRect.x() + innerRectRadius, brushRect.y()), | - | ||||||||||||
| 401 | QPointF(brushRect.x() + brushRect.width() - innerRectRadius, brushRect.y() + brushRect.height())); | - | ||||||||||||
| 402 | painter->fillRect(centerRect, m_color); | - | ||||||||||||
| 403 | QRectF leftRect(QPointF(brushRect.x(), brushRect.y() + innerRectRadius), | - | ||||||||||||
| 404 | QPointF(brushRect.x() + innerRectRadius, brushRect.y() + brushRect.height() - innerRectRadius)); | - | ||||||||||||
| 405 | painter->fillRect(leftRect, m_color); | - | ||||||||||||
| 406 | QRectF rightRect(QPointF(brushRect.x() + brushRect.width() - innerRectRadius, brushRect.y() + innerRectRadius), | - | ||||||||||||
| 407 | QPointF(brushRect.x() + brushRect.width(), brushRect.y() + brushRect.height() - innerRectRadius)); | - | ||||||||||||
| 408 | painter->fillRect(rightRect, m_color); | - | ||||||||||||
| 409 | } else { never executed: end of block | 0 | ||||||||||||
| 410 | //Rounded Rect with gradient (slow) | - | ||||||||||||
| 411 | painter->setPen(Qt::NoPen); | - | ||||||||||||
| 412 | painter->setBrush(m_brush); | - | ||||||||||||
| 413 | painter->drawRoundedRect(brushRect, innerRectRadius, innerRectRadius); | - | ||||||||||||
| 414 | } never executed: end of block | 0 | ||||||||||||
| 415 | } else { | - | ||||||||||||
| 416 | //non-rounded rects only need 1 blit | - | ||||||||||||
| 417 | painter->fillRect(brushRect, m_brush); | - | ||||||||||||
| 418 | } never executed: end of block | 0 | ||||||||||||
| 419 | } | - | ||||||||||||
| 420 | - | |||||||||||||
| 421 | painter->setRenderHints(previousRenderHints); | - | ||||||||||||
| 422 | } never executed: end of block | 0 | ||||||||||||
| 423 | - | |||||||||||||
| 424 | void QSGSoftwareInternalRectangleNode::generateCornerPixmap() | - | ||||||||||||
| 425 | { | - | ||||||||||||
| 426 | //Generate new corner Pixmap | - | ||||||||||||
| 427 | int radius = qFloor(qMin(qMin(m_rect.width(), m_rect.height()) * 0.5, m_radius)); | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | m_cornerPixmap = QPixmap(qRound(radius * 2 * m_devicePixelRatio), qRound(radius * 2 * m_devicePixelRatio)); | - | ||||||||||||
| 430 | m_cornerPixmap.setDevicePixelRatio(m_devicePixelRatio); | - | ||||||||||||
| 431 | m_cornerPixmap.fill(Qt::transparent); | - | ||||||||||||
| 432 | - | |||||||||||||
| 433 | if (radius > 0) {
| 0 | ||||||||||||
| 434 | QPainter cornerPainter(&m_cornerPixmap); | - | ||||||||||||
| 435 | cornerPainter.setRenderHint(QPainter::Antialiasing); | - | ||||||||||||
| 436 | cornerPainter.setCompositionMode(QPainter::CompositionMode_Source); | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | //Paint outer cicle | - | ||||||||||||
| 439 | if (m_penWidth > 0) {
| 0 | ||||||||||||
| 440 | cornerPainter.setPen(Qt::NoPen); | - | ||||||||||||
| 441 | cornerPainter.setBrush(m_penColor); | - | ||||||||||||
| 442 | cornerPainter.drawRoundedRect(QRectF(0, 0, radius * 2, radius *2), radius, radius); | - | ||||||||||||
| 443 | } never executed: end of block | 0 | ||||||||||||
| 444 | - | |||||||||||||
| 445 | //Paint inner circle | - | ||||||||||||
| 446 | if (radius > m_penWidth) {
| 0 | ||||||||||||
| 447 | cornerPainter.setPen(Qt::NoPen); | - | ||||||||||||
| 448 | if (m_stops.isEmpty())
| 0 | ||||||||||||
| 449 | cornerPainter.setBrush(m_brush); never executed: cornerPainter.setBrush(m_brush); | 0 | ||||||||||||
| 450 | else | - | ||||||||||||
| 451 | cornerPainter.setBrush(Qt::transparent); never executed: cornerPainter.setBrush(Qt::transparent); | 0 | ||||||||||||
| 452 | - | |||||||||||||
| 453 | QMarginsF adjustmentMargins(m_penWidth, m_penWidth, m_penWidth, m_penWidth); | - | ||||||||||||
| 454 | QRectF cornerCircleRect = QRectF(0, 0, radius * 2, radius * 2).marginsRemoved(adjustmentMargins); | - | ||||||||||||
| 455 | cornerPainter.drawRoundedRect(cornerCircleRect, radius, radius); | - | ||||||||||||
| 456 | } never executed: end of block | 0 | ||||||||||||
| 457 | cornerPainter.end(); | - | ||||||||||||
| 458 | } never executed: end of block | 0 | ||||||||||||
| 459 | } never executed: end of block | 0 | ||||||||||||
| 460 | - | |||||||||||||
| 461 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |