KDeclarative

qpixmapitem.h
1 /*
2  SPDX-FileCopyrightText: 2011 Marco Martin <[email protected]>
3  SPDX-FileCopyrightText: 2015 Luca Beltrame <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef QPIXMAPITEM_H
9 #define QPIXMAPITEM_H
10 
11 #include <QQuickPaintedItem>
12 #include <QPixmap>
13 
14 class QPixmapItem : public QQuickPaintedItem
15 {
16  Q_OBJECT
17 
18  Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged RESET resetPixmap)
19  Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
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 
27 public:
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  void setSmooth(const bool smooth);
46  bool smooth() const;
47 
48  int nativeWidth() const;
49  int nativeHeight() const;
50 
51  int paintedWidth() const;
52  int paintedHeight() const;
53 
54  FillMode fillMode() const;
55  void setFillMode(FillMode mode);
56 
57  void paint(QPainter *painter) override;
58 
59  bool isNull() const;
60 
61 Q_SIGNALS:
62  void nativeWidthChanged();
63  void nativeHeightChanged();
64  void fillModeChanged();
65  void pixmapChanged();
66  void nullChanged();
67  void paintedWidthChanged();
68  void paintedHeightChanged();
69 
70 protected:
71  void geometryChanged(const QRectF & newGeometry, const QRectF & oldGeometry) override;
72 
73 private:
74  QPixmap m_pixmap;
75  bool m_smooth;
76  FillMode m_fillMode;
77  QRect m_paintedRect;
78 
79 private Q_SLOTS:
80  void updatePaintedRect();
81 
82 };
83 
84 #endif
Q_ENUM(...)
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 22:44:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.