KDeclarative

qimageitem.h
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 QIMAGEITEM_H
9#define QIMAGEITEM_H
10
11#include <QImage>
12#include <QQuickPaintedItem>
13
14class QImageItem : public QQuickPaintedItem
15{
17 QML_ELEMENT
18
19 Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged RESET resetImage)
20 Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged)
21 Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged)
22 Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedWidthChanged)
23 Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedHeightChanged)
24 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
25 Q_PROPERTY(bool null READ isNull NOTIFY nullChanged)
26
27public:
28 enum FillMode {
29 Stretch, // the image is scaled to fit
30 PreserveAspectFit, // the image is scaled uniformly to fit without cropping
31 PreserveAspectCrop, // the image is scaled uniformly to fill, cropping if necessary
32 Tile, // the image is duplicated horizontally and vertically
33 TileVertically, // the image is stretched horizontally and tiled vertically
34 TileHorizontally, // the image is stretched vertically and tiled horizontally
35 Pad, /**< the image is not transformed @since 5.96 **/
36 };
37 Q_ENUM(FillMode)
38
39 explicit QImageItem(QQuickItem *parent = nullptr);
40 ~QImageItem() override;
41
42 void setImage(const QImage &image);
43 QImage image() const;
44 void resetImage();
45
46 int nativeWidth() const;
47 int nativeHeight() const;
48
49 int paintedWidth() const;
50 int paintedHeight() const;
51
52 FillMode fillMode() const;
53 void setFillMode(FillMode mode);
54
55 void paint(QPainter *painter) override;
56
57 bool isNull() const;
58
60 void nativeWidthChanged();
61 void nativeHeightChanged();
62 void fillModeChanged();
63 void imageChanged();
64 void nullChanged();
65 void paintedWidthChanged();
66 void paintedHeightChanged();
67
68protected:
69 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
70
71private:
72 QImage m_image;
73 FillMode m_fillMode;
74 QRect m_paintedRect;
75
76private Q_SLOTS:
77 void updatePaintedRect();
78};
79
80#endif
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.