KDeclarative

qpixmapitem.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 QPIXMAPITEM_H
9#define QPIXMAPITEM_H
10
11#include <QPixmap>
12#include <QQuickPaintedItem>
13
14class QPixmapItem : public QQuickPaintedItem
15{
17 QML_ELEMENT
18
19 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged RESET resetPixmap)
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 };
36 Q_ENUM(FillMode)
37
38 explicit QPixmapItem(QQuickItem *parent = nullptr);
39 ~QPixmapItem() override;
40
41 void setPixmap(const QPixmap &pixmap);
42 QPixmap pixmap() const;
43 void resetPixmap();
44
45 int nativeWidth() const;
46 int nativeHeight() const;
47
48 int paintedWidth() const;
49 int paintedHeight() const;
50
51 FillMode fillMode() const;
52 void setFillMode(FillMode mode);
53
54 void paint(QPainter *painter) override;
55
56 bool isNull() const;
57
59 void nativeWidthChanged();
60 void nativeHeightChanged();
61 void fillModeChanged();
62 void pixmapChanged();
63 void nullChanged();
64 void paintedWidthChanged();
65 void paintedHeightChanged();
66
67protected:
68 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
69
70private:
71 QPixmap m_pixmap;
72 FillMode m_fillMode;
73 QRect m_paintedRect;
74
75private Q_SLOTS:
76 void updatePaintedRect();
77};
78
79#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 Fri Jul 19 2024 11:51:26 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.