1 | /* |
2 | SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> |
3 | SPDX-FileCopyrightText: 2015 Luca Beltrame <lbeltrame@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | |
8 | #ifndef QPIXMAPITEM_H |
9 | #define QPIXMAPITEM_H |
10 | |
11 | #include <QPixmap> |
12 | #include <QQuickPaintedItem> |
13 | |
14 | /*! |
15 | * \qmltype QPixMapItem |
16 | * \inqmlmodule org.kde.kquickcontrols.addons |
17 | */ |
18 | class QPixmapItem : public QQuickPaintedItem |
19 | { |
20 | Q_OBJECT |
21 | QML_ELEMENT |
22 | |
23 | /*! \qmlproperty QPixMap QPixMapItem::pixmap */ |
24 | Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged RESET resetPixmap) |
25 | /*! \qmlproperty int QPixMapItem::nativeWidth */ |
26 | Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged) |
27 | /*! \qmlproperty int QPixMapItem::nativeHeight */ |
28 | Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged) |
29 | /*! \qmlproperty int QPixMapItem::paintedWidth */ |
30 | Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedWidthChanged) |
31 | /*! \qmlproperty int QPixMapItem::paintedHeight */ |
32 | Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedHeightChanged) |
33 | /*! \qmlproperty FillMode QPixMapItem::fillMode |
34 | * \value Stretch |
35 | * The image is scaled to fit. |
36 | * \value PreserveAspectFit |
37 | * the image is scaled uniformly to fit without cropping. |
38 | * \value PreserveAspectCrop |
39 | * The image is scaled uniformly to fill, cropping if necessary. |
40 | * \value Tile |
41 | * The image is duplicated horizontally and vertically. |
42 | * \value TileVertically |
43 | * The image is stretched horizontally and tiled vertically. |
44 | * \value TileHorizontally |
45 | * The image is stretched vertically and tiled horizontally. |
46 | */ |
47 | Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) |
48 | /*! \qmlproperty bool QPixMapItem::null */ |
49 | Q_PROPERTY(bool null READ isNull NOTIFY nullChanged) |
50 | |
51 | public: |
52 | enum FillMode { |
53 | Stretch, |
54 | PreserveAspectFit, |
55 | PreserveAspectCrop, |
56 | Tile, |
57 | TileVertically, |
58 | TileHorizontally, |
59 | }; |
60 | Q_ENUM(FillMode) |
61 | |
62 | explicit QPixmapItem(QQuickItem *parent = nullptr); |
63 | ~QPixmapItem() override; |
64 | |
65 | void setPixmap(const QPixmap &pixmap); |
66 | QPixmap pixmap() const; |
67 | void resetPixmap(); |
68 | |
69 | int nativeWidth() const; |
70 | int nativeHeight() const; |
71 | |
72 | int paintedWidth() const; |
73 | int paintedHeight() const; |
74 | |
75 | FillMode fillMode() const; |
76 | void setFillMode(FillMode mode); |
77 | |
78 | void paint(QPainter *painter) override; |
79 | |
80 | bool isNull() const; |
81 | |
82 | Q_SIGNALS: |
83 | /*! \qmlsignal QPixMapItem::nativeWidthChanged */ |
84 | void nativeWidthChanged(); |
85 | /*! \qmlsignal QPixMapItem::nativeHeightChanged */ |
86 | void nativeHeightChanged(); |
87 | /*! \qmlsignal QPixMapItem::fillModeChanged */ |
88 | void fillModeChanged(); |
89 | /*! \qmlsignal QPixMapItem::pixmapChanged */ |
90 | void pixmapChanged(); |
91 | /*! \qmlsignal QPixMapItem::nullChanged */ |
92 | void nullChanged(); |
93 | /*! \qmlsignal QPixMapItem::paintedWidthChanged */ |
94 | void paintedWidthChanged(); |
95 | /*! \qmlsignal QPixMapItem::paintedHeightChanged */ |
96 | void paintedHeightChanged(); |
97 | |
98 | protected: |
99 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
100 | |
101 | private: |
102 | QPixmap m_pixmap; |
103 | FillMode m_fillMode; |
104 | QRect m_paintedRect; |
105 | |
106 | private Q_SLOTS: |
107 | void updatePaintedRect(); |
108 | }; |
109 | |
110 | #endif |
111 | |