File indexing completed on 2024-05-19 15:09:26
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 0018 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged RESET resetPixmap) 0019 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth) 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 void setSmooth(const bool smooth); 0046 bool smooth() const; 0047 0048 int nativeWidth() const; 0049 int nativeHeight() const; 0050 0051 int paintedWidth() const; 0052 int paintedHeight() const; 0053 0054 FillMode fillMode() const; 0055 void setFillMode(FillMode mode); 0056 0057 void paint(QPainter *painter) override; 0058 0059 bool isNull() const; 0060 0061 Q_SIGNALS: 0062 void nativeWidthChanged(); 0063 void nativeHeightChanged(); 0064 void fillModeChanged(); 0065 void pixmapChanged(); 0066 void nullChanged(); 0067 void paintedWidthChanged(); 0068 void paintedHeightChanged(); 0069 0070 protected: 0071 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; 0072 0073 private: 0074 QPixmap m_pixmap; 0075 bool m_smooth; 0076 FillMode m_fillMode; 0077 QRect m_paintedRect; 0078 0079 private Q_SLOTS: 0080 void updatePaintedRect(); 0081 }; 0082 0083 #endif