1 | /* |
2 | * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef PAINTEDRECTANGLEITEM_H |
8 | #define PAINTEDRECTANGLEITEM_H |
9 | |
10 | #include <QQuickPaintedItem> |
11 | |
12 | /** |
13 | * A rectangle with a border and rounded corners, rendered through QPainter. |
14 | * |
15 | * This is a helper used by ShadowedRectangle as fallback for when software |
16 | * rendering is used, which means our shaders cannot be used. |
17 | * |
18 | * Since we cannot actually use QSGPaintedNode, we need to do some trickery |
19 | * using QQuickPaintedItem as a child of ShadowedRectangle. |
20 | * |
21 | * \warning This item is **not** intended as a general purpose item. |
22 | */ |
23 | class PaintedRectangleItem : public QQuickPaintedItem |
24 | { |
25 | Q_OBJECT |
26 | public: |
27 | explicit PaintedRectangleItem(QQuickItem *parent = nullptr); |
28 | |
29 | void setColor(const QColor &color); |
30 | void setRadius(qreal radius); |
31 | void setBorderColor(const QColor &color); |
32 | void setBorderWidth(qreal width); |
33 | |
34 | void paint(QPainter *painter) override; |
35 | |
36 | private: |
37 | QColor m_color; |
38 | qreal m_radius = 0.0; |
39 | QColor m_borderColor; |
40 | qreal m_borderWidth = 0.0; |
41 | }; |
42 | |
43 | #endif // PAINTEDRECTANGLEITEM_H |
44 | |