| 1 | /**************************************************************************** | 
| 2 | ** | 
| 3 | ** Copyright (C) 2017 The Qt Company Ltd. | 
| 4 | ** Contact: http://www.qt.io/licensing/ | 
| 5 | ** | 
| 6 | ** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit. | 
| 7 | ** | 
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ | 
| 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 3 as published by the Free Software | 
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 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.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 later as published by the Free | 
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in | 
| 29 | ** the packaging of this file. Please review the following information to | 
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be | 
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. | 
| 32 | ** | 
| 33 | ** $QT_END_LICENSE$ | 
| 34 | ** | 
| 35 | ****************************************************************************/ | 
| 36 |  | 
| 37 | #include "qquickpaddedrectangle_p.h" | 
| 38 |  | 
| 39 | #include <QtQuick/private/qsgadaptationlayer_p.h> | 
| 40 |  | 
| 41 | QT_BEGIN_NAMESPACE | 
| 42 |  | 
| 43 | QQuickPaddedRectangle::QQuickPaddedRectangle(QQuickItem *parent) : | 
| 44 |     QQuickRectangle(parent) | 
| 45 | { | 
| 46 | } | 
| 47 |  | 
| 48 | qreal QQuickPaddedRectangle::padding() const | 
| 49 | { | 
| 50 |     return m_padding; | 
| 51 | } | 
| 52 |  | 
| 53 | void QQuickPaddedRectangle::setPadding(qreal padding) | 
| 54 | { | 
| 55 |     if (!qFuzzyCompare(p1: m_padding, p2: padding)) { | 
| 56 |         m_padding = padding; | 
| 57 |         update(); | 
| 58 |         emit paddingChanged(); | 
| 59 |         if (m_hasTopPadding) | 
| 60 |             emit topPaddingChanged(); | 
| 61 |         if (!m_hasLeftPadding) | 
| 62 |             emit leftPaddingChanged(); | 
| 63 |         if (!m_hasRightPadding) | 
| 64 |             emit rightPaddingChanged(); | 
| 65 |         if (!m_hasBottomPadding) | 
| 66 |             emit bottomPaddingChanged(); | 
| 67 |     } | 
| 68 | } | 
| 69 |  | 
| 70 | void QQuickPaddedRectangle::resetPadding() | 
| 71 | { | 
| 72 |     setPadding(0); | 
| 73 | } | 
| 74 |  | 
| 75 | qreal QQuickPaddedRectangle::topPadding() const | 
| 76 | { | 
| 77 |     return m_hasTopPadding ? m_topPadding : m_padding; | 
| 78 | } | 
| 79 |  | 
| 80 | void QQuickPaddedRectangle::setTopPadding(qreal padding) | 
| 81 | { | 
| 82 |     setTopPadding(padding, has: true); | 
| 83 | } | 
| 84 |  | 
| 85 | void QQuickPaddedRectangle::resetTopPadding() | 
| 86 | { | 
| 87 |     setTopPadding(padding: 0, has: false); | 
| 88 | } | 
| 89 |  | 
| 90 | qreal QQuickPaddedRectangle::leftPadding() const | 
| 91 | { | 
| 92 |     return m_hasLeftPadding ? m_leftPadding : m_padding; | 
| 93 | } | 
| 94 |  | 
| 95 | void QQuickPaddedRectangle::setLeftPadding(qreal padding) | 
| 96 | { | 
| 97 |     setLeftPadding(padding, has: true); | 
| 98 | } | 
| 99 |  | 
| 100 | void QQuickPaddedRectangle::resetLeftPadding() | 
| 101 | { | 
| 102 |     setLeftPadding(padding: 0, has: false); | 
| 103 | } | 
| 104 |  | 
| 105 | qreal QQuickPaddedRectangle::rightPadding() const | 
| 106 | { | 
| 107 |     return m_hasRightPadding ? m_rightPadding : m_padding; | 
| 108 | } | 
| 109 |  | 
| 110 | void QQuickPaddedRectangle::setRightPadding(qreal padding) | 
| 111 | { | 
| 112 |     setRightPadding(padding, has: true); | 
| 113 | } | 
| 114 |  | 
| 115 | void QQuickPaddedRectangle::resetRightPadding() | 
| 116 | { | 
| 117 |     setRightPadding(padding: 0, has: false); | 
| 118 | } | 
| 119 |  | 
| 120 | qreal QQuickPaddedRectangle::bottomPadding() const | 
| 121 | { | 
| 122 |     return m_hasBottomPadding ? m_bottomPadding : m_padding; | 
| 123 | } | 
| 124 |  | 
| 125 | void QQuickPaddedRectangle::setBottomPadding(qreal padding) | 
| 126 | { | 
| 127 |     setBottomPadding(padding, has: true); | 
| 128 | } | 
| 129 |  | 
| 130 | void QQuickPaddedRectangle::resetBottomPadding() | 
| 131 | { | 
| 132 |     setBottomPadding(padding: 0, has: false); | 
| 133 | } | 
| 134 |  | 
| 135 | void QQuickPaddedRectangle::setTopPadding(qreal padding, bool has) | 
| 136 | { | 
| 137 |     qreal oldPadding = topPadding(); | 
| 138 |     m_hasTopPadding = has; | 
| 139 |     m_topPadding = padding; | 
| 140 |     if (!qFuzzyCompare(p1: oldPadding, p2: padding)) { | 
| 141 |         update(); | 
| 142 |         emit topPaddingChanged(); | 
| 143 |     } | 
| 144 | } | 
| 145 |  | 
| 146 | void QQuickPaddedRectangle::setLeftPadding(qreal padding, bool has) | 
| 147 | { | 
| 148 |     qreal oldPadding = leftPadding(); | 
| 149 |     m_hasLeftPadding = has; | 
| 150 |     m_leftPadding = padding; | 
| 151 |     if (!qFuzzyCompare(p1: oldPadding, p2: padding)) { | 
| 152 |         update(); | 
| 153 |         emit leftPaddingChanged(); | 
| 154 |     } | 
| 155 | } | 
| 156 |  | 
| 157 | void QQuickPaddedRectangle::setRightPadding(qreal padding, bool has) | 
| 158 | { | 
| 159 |     qreal oldPadding = rightPadding(); | 
| 160 |     m_hasRightPadding = has; | 
| 161 |     m_rightPadding = padding; | 
| 162 |     if (!qFuzzyCompare(p1: oldPadding, p2: padding)) { | 
| 163 |         update(); | 
| 164 |         emit rightPaddingChanged(); | 
| 165 |     } | 
| 166 | } | 
| 167 |  | 
| 168 | void QQuickPaddedRectangle::setBottomPadding(qreal padding, bool has) | 
| 169 | { | 
| 170 |     qreal oldPadding = bottomPadding(); | 
| 171 |     m_hasBottomPadding = has; | 
| 172 |     m_bottomPadding = padding; | 
| 173 |     if (!qFuzzyCompare(p1: oldPadding, p2: padding)) { | 
| 174 |         update(); | 
| 175 |         emit bottomPaddingChanged(); | 
| 176 |     } | 
| 177 | } | 
| 178 |  | 
| 179 | QSGNode *QQuickPaddedRectangle::updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) | 
| 180 | { | 
| 181 |     QSGTransformNode *transformNode = static_cast<QSGTransformNode *>(node); | 
| 182 |     if (!transformNode) | 
| 183 |         transformNode = new QSGTransformNode; | 
| 184 |  | 
| 185 |     QSGInternalRectangleNode *rectNode = static_cast<QSGInternalRectangleNode *>(QQuickRectangle::updatePaintNode(transformNode->firstChild(), data)); | 
| 186 |  | 
| 187 |     if (rectNode) { | 
| 188 |         if (!transformNode->firstChild()) | 
| 189 |             transformNode->appendChildNode(node: rectNode); | 
| 190 |  | 
| 191 |         qreal top = topPadding(); | 
| 192 |         qreal left = leftPadding(); | 
| 193 |         qreal right = rightPadding(); | 
| 194 |         qreal bottom = bottomPadding(); | 
| 195 |  | 
| 196 |         if (!qFuzzyIsNull(d: top) || !qFuzzyIsNull(d: left) || !qFuzzyIsNull(d: right) || !qFuzzyIsNull(d: bottom)) { | 
| 197 |             QMatrix4x4 m; | 
| 198 |             m.translate(x: left, y: top); | 
| 199 |             transformNode->setMatrix(m); | 
| 200 |  | 
| 201 |             qreal w = qMax<qreal>(a: 0.0, b: width() -left-right); | 
| 202 |             qreal h = qMax<qreal>(a: 0.0, b: height() -top-bottom); | 
| 203 |  | 
| 204 |             rectNode->setRect(QRectF(0, 0, w, h)); | 
| 205 |             rectNode->update(); | 
| 206 |         } | 
| 207 |     } | 
| 208 |     return transformNode; | 
| 209 | } | 
| 210 |  | 
| 211 | QT_END_NAMESPACE | 
| 212 |  |