Changeset View
Changeset View
Standalone View
Standalone View
src/shadowedrectangle.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 107 | { | |||
---|---|---|---|---|---|
108 | if (newColor == m_color) { | 108 | if (newColor == m_color) { | ||
109 | return; | 109 | return; | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | m_color = newColor; | 112 | m_color = newColor; | ||
113 | Q_EMIT changed(); | 113 | Q_EMIT changed(); | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | CornersGroup::CornersGroup(QObject* parent) | ||||
117 | : QObject(parent) | ||||
118 | { | ||||
119 | } | ||||
120 | | ||||
121 | qreal CornersGroup::topLeft() const | ||||
122 | { | ||||
123 | return m_topLeft; | ||||
124 | } | ||||
125 | | ||||
126 | void CornersGroup::setTopLeft(qreal newTopLeft) | ||||
127 | { | ||||
128 | if (newTopLeft == m_topLeft) { | ||||
129 | return; | ||||
130 | } | ||||
131 | | ||||
132 | m_topLeft = newTopLeft; | ||||
133 | Q_EMIT changed(); | ||||
134 | } | ||||
135 | | ||||
136 | qreal CornersGroup::topRight() const | ||||
137 | { | ||||
138 | return m_topRight; | ||||
139 | } | ||||
140 | | ||||
141 | void CornersGroup::setTopRight(qreal newTopRight) | ||||
142 | { | ||||
143 | if (newTopRight == m_topRight) { | ||||
144 | return; | ||||
145 | } | ||||
146 | | ||||
147 | m_topRight = newTopRight; | ||||
148 | Q_EMIT changed(); | ||||
149 | } | ||||
150 | | ||||
151 | qreal CornersGroup::bottomLeft() const | ||||
152 | { | ||||
153 | return m_bottomLeft; | ||||
154 | } | ||||
155 | | ||||
156 | void CornersGroup::setBottomLeft(qreal newBottomLeft) | ||||
157 | { | ||||
158 | if (newBottomLeft == m_bottomLeft) { | ||||
159 | return; | ||||
160 | } | ||||
161 | | ||||
162 | m_bottomLeft = newBottomLeft; | ||||
163 | Q_EMIT changed(); | ||||
164 | } | ||||
165 | | ||||
166 | qreal CornersGroup::bottomRight() const | ||||
167 | { | ||||
168 | return m_bottomRight; | ||||
169 | } | ||||
170 | | ||||
171 | void CornersGroup::setBottomRight(qreal newBottomRight) | ||||
172 | { | ||||
173 | if (newBottomRight == m_bottomRight) { | ||||
174 | return; | ||||
175 | } | ||||
176 | | ||||
177 | m_bottomRight = newBottomRight; | ||||
178 | Q_EMIT changed(); | ||||
179 | } | ||||
180 | | ||||
181 | QVector4D CornersGroup::toVector4D(float all) const | ||||
182 | { | ||||
183 | return QVector4D{ | ||||
184 | m_bottomRight < 0.0 ? all : m_bottomRight, | ||||
185 | m_topRight < 0.0 ? all : m_topRight, | ||||
186 | m_bottomLeft < 0.0 ? all : m_bottomLeft, | ||||
187 | m_topLeft < 0.0 ? all : m_topLeft | ||||
188 | }; | ||||
189 | } | ||||
190 | | ||||
116 | ShadowedRectangle::ShadowedRectangle(QQuickItem *parentItem) | 191 | ShadowedRectangle::ShadowedRectangle(QQuickItem *parentItem) | ||
117 | : QQuickItem(parentItem), m_border(new BorderGroup), m_shadow(new ShadowGroup) | 192 | : QQuickItem(parentItem) | ||
193 | , m_border(new BorderGroup) | ||||
194 | , m_shadow(new ShadowGroup) | ||||
195 | , m_corners(new CornersGroup) | ||||
118 | { | 196 | { | ||
119 | setFlag(QQuickItem::ItemHasContents, true); | 197 | setFlag(QQuickItem::ItemHasContents, true); | ||
120 | 198 | | |||
121 | connect(m_border.get(), &BorderGroup::changed, this, &ShadowedRectangle::update); | 199 | connect(m_border.get(), &BorderGroup::changed, this, &ShadowedRectangle::update); | ||
122 | connect(m_shadow.get(), &ShadowGroup::changed, this, &ShadowedRectangle::update); | 200 | connect(m_shadow.get(), &ShadowGroup::changed, this, &ShadowedRectangle::update); | ||
201 | connect(m_corners.get(), &CornersGroup::changed, this, &ShadowedRectangle::update); | ||||
123 | } | 202 | } | ||
124 | 203 | | |||
125 | ShadowedRectangle::~ShadowedRectangle() | 204 | ShadowedRectangle::~ShadowedRectangle() | ||
126 | { | 205 | { | ||
127 | } | 206 | } | ||
128 | 207 | | |||
129 | BorderGroup *ShadowedRectangle::border() const | 208 | BorderGroup *ShadowedRectangle::border() const | ||
130 | { | 209 | { | ||
131 | return m_border.get(); | 210 | return m_border.get(); | ||
132 | } | 211 | } | ||
133 | 212 | | |||
134 | ShadowGroup *ShadowedRectangle::shadow() const | 213 | ShadowGroup *ShadowedRectangle::shadow() const | ||
135 | { | 214 | { | ||
136 | return m_shadow.get(); | 215 | return m_shadow.get(); | ||
137 | } | 216 | } | ||
138 | 217 | | |||
218 | CornersGroup *ShadowedRectangle::corners() const | ||||
219 | { | ||||
220 | return m_corners.get(); | ||||
221 | } | ||||
222 | | ||||
139 | qreal ShadowedRectangle::radius() const | 223 | qreal ShadowedRectangle::radius() const | ||
140 | { | 224 | { | ||
141 | return m_radius; | 225 | return m_radius; | ||
142 | } | 226 | } | ||
143 | 227 | | |||
144 | void ShadowedRectangle::setRadius(qreal newRadius) | 228 | void ShadowedRectangle::setRadius(qreal newRadius) | ||
145 | { | 229 | { | ||
146 | if (newRadius == m_radius) { | 230 | if (newRadius == m_radius) { | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | 270 | { | |||
189 | if (!node) { | 273 | if (!node) { | ||
190 | node = new ShadowedRectangleNode{}; | 274 | node = new ShadowedRectangleNode{}; | ||
191 | } | 275 | } | ||
192 | 276 | | |||
193 | auto shadowNode = static_cast<ShadowedRectangleNode*>(node); | 277 | auto shadowNode = static_cast<ShadowedRectangleNode*>(node); | ||
194 | shadowNode->setBorderEnabled(m_border->isEnabled()); | 278 | shadowNode->setBorderEnabled(m_border->isEnabled()); | ||
195 | shadowNode->setRect(boundingRect()); | 279 | shadowNode->setRect(boundingRect()); | ||
196 | shadowNode->setSize(m_shadow->size()); | 280 | shadowNode->setSize(m_shadow->size()); | ||
197 | shadowNode->setRadius(m_radius); | 281 | shadowNode->setRadius(m_corners->toVector4D(m_radius)); | ||
198 | shadowNode->setOffset(QVector2D{float(m_shadow->xOffset()), float(m_shadow->yOffset())}); | 282 | shadowNode->setOffset(QVector2D{float(m_shadow->xOffset()), float(m_shadow->yOffset())}); | ||
199 | shadowNode->setColor(m_color); | 283 | shadowNode->setColor(m_color); | ||
200 | shadowNode->setShadowColor(m_shadow->color()); | 284 | shadowNode->setShadowColor(m_shadow->color()); | ||
201 | shadowNode->setBorderWidth(m_border->width()); | 285 | shadowNode->setBorderWidth(m_border->width()); | ||
202 | shadowNode->setBorderColor(m_border->color()); | 286 | shadowNode->setBorderColor(m_border->color()); | ||
203 | shadowNode->updateGeometry(); | 287 | shadowNode->updateGeometry(); | ||
204 | return shadowNode; | 288 | return shadowNode; | ||
205 | } | 289 | } | ||
Show All 28 Lines |