File indexing completed on 2025-10-26 03:41:34
0001 /* 0002 SPDX-FileCopyrightText: 2011 Marco Martin <mart@kde.org> 0003 SPDX-FileCopyrightText: 2015 Luca Beltrame <lbeltrame@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef QPIXMAPITEM_H 0009 #define QPIXMAPITEM_H 0010 0011 #include <QPixmap> 0012 #include <QQuickPaintedItem> 0013 0014 class QPixmapItem : public QQuickPaintedItem 0015 { 0016 Q_OBJECT 0017 QML_ELEMENT 0018 0019 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged RESET resetPixmap) 0020 Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged) 0021 Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged) 0022 Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedWidthChanged) 0023 Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedHeightChanged) 0024 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged) 0025 Q_PROPERTY(bool null READ isNull NOTIFY nullChanged) 0026 0027 public: 0028 enum FillMode { 0029 Stretch, // the image is scaled to fit 0030 PreserveAspectFit, // the image is scaled uniformly to fit without cropping 0031 PreserveAspectCrop, // the image is scaled uniformly to fill, cropping if necessary 0032 Tile, // the image is duplicated horizontally and vertically 0033 TileVertically, // the image is stretched horizontally and tiled vertically 0034 TileHorizontally, // the image is stretched vertically and tiled horizontally 0035 }; 0036 Q_ENUM(FillMode) 0037 0038 explicit QPixmapItem(QQuickItem *parent = nullptr); 0039 ~QPixmapItem() override; 0040 0041 void setPixmap(const QPixmap &pixmap); 0042 QPixmap pixmap() const; 0043 void resetPixmap(); 0044 0045 int nativeWidth() const; 0046 int nativeHeight() const; 0047 0048 int paintedWidth() const; 0049 int paintedHeight() const; 0050 0051 FillMode fillMode() const; 0052 void setFillMode(FillMode mode); 0053 0054 void paint(QPainter *painter) override; 0055 0056 bool isNull() const; 0057 0058 Q_SIGNALS: 0059 void nativeWidthChanged(); 0060 void nativeHeightChanged(); 0061 void fillModeChanged(); 0062 void pixmapChanged(); 0063 void nullChanged(); 0064 void paintedWidthChanged(); 0065 void paintedHeightChanged(); 0066 0067 protected: 0068 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; 0069 0070 private: 0071 QPixmap m_pixmap; 0072 FillMode m_fillMode; 0073 QRect m_paintedRect; 0074 0075 private Q_SLOTS: 0076 void updatePaintedRect(); 0077 }; 0078 0079 #endif