KQuickImageEditor

imageitem.h
1 /*
2  * SPDX-FileCopyrightText: (C) 2011 Marco Martin <[email protected]>
3  * SPDX-FileCopyrightText: (C) 2020 Luca Beltrame <[email protected]>
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  */
7 
8 #pragma once
9 
10 #include <QImage>
11 #include <QQuickPaintedItem>
12 
13 class ImageItem : public QQuickPaintedItem
14 {
15  Q_OBJECT
16 
17  Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged RESET resetImage)
18  Q_PROPERTY(bool smooth READ smooth WRITE setSmooth)
19  Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged)
20  Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged)
21  Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedWidthChanged)
22  Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedHeightChanged)
23  Q_PROPERTY(int verticalPadding READ verticalPadding NOTIFY verticalPaddingChanged)
24  Q_PROPERTY(int horizontalPadding READ horizontalPadding NOTIFY horizontalPaddingChanged)
25  Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
26  Q_PROPERTY(bool null READ isNull NOTIFY nullChanged)
27 
28 public:
29  enum FillMode {
30  Stretch, // the image is scaled to fit
31  PreserveAspectFit, // the image is scaled uniformly to fit without cropping
32  PreserveAspectCrop, // the image is scaled uniformly to fill, cropping if necessary
33  Tile, // the image is duplicated horizontally and vertically
34  TileVertically, // the image is stretched horizontally and tiled vertically
35  TileHorizontally // the image is stretched vertically and tiled horizontally
36  };
37  Q_ENUM(FillMode)
38 
39  explicit ImageItem(QQuickItem *parent = nullptr);
40  ~ImageItem() override = default;
41 
42  void setImage(const QImage &image);
43  QImage image() const;
44  void resetImage();
45 
46  void setSmooth(const bool smooth);
47  bool smooth() const;
48 
49  int nativeWidth() const;
50  int nativeHeight() const;
51 
52  int paintedWidth() const;
53  int paintedHeight() const;
54  int verticalPadding() const;
55  int horizontalPadding() const;
56 
57  FillMode fillMode() const;
58  void setFillMode(FillMode mode);
59 
60  void paint(QPainter *painter) override;
61 
62  bool isNull() const;
63 
64 Q_SIGNALS:
65  void nativeWidthChanged();
66  void nativeHeightChanged();
67  void fillModeChanged();
68  void imageChanged();
69  void nullChanged();
70  void paintedWidthChanged();
71  void paintedHeightChanged();
72  void verticalPaddingChanged();
73  void horizontalPaddingChanged();
74 
75 protected:
76  void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
77 
78 private:
79  QImage m_image;
80  bool m_smooth;
81  FillMode m_fillMode;
82  QRect m_paintedRect;
83 
84 private Q_SLOTS:
85  void updatePaintedRect();
86 };
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 Oct 18 2021 23:08:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.