KQuickImageEditor

imageitem.h
1/*
2 * SPDX-FileCopyrightText: (C) 2011 Marco Martin <mart@kde.org>
3 * SPDX-FileCopyrightText: (C) 2020 Luca Beltrame <lbeltrame@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8#pragma once
9
10#include <QImage>
11#include <QQuickPaintedItem>
12
13class ImageItem : public QQuickPaintedItem
14{
16
17 Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged RESET resetImage)
18 Q_PROPERTY(int nativeWidth READ nativeWidth NOTIFY nativeWidthChanged)
19 Q_PROPERTY(int nativeHeight READ nativeHeight NOTIFY nativeHeightChanged)
20 Q_PROPERTY(int paintedWidth READ paintedWidth NOTIFY paintedWidthChanged)
21 Q_PROPERTY(int paintedHeight READ paintedHeight NOTIFY paintedHeightChanged)
22 Q_PROPERTY(int verticalPadding READ verticalPadding NOTIFY verticalPaddingChanged)
23 Q_PROPERTY(int horizontalPadding READ horizontalPadding NOTIFY horizontalPaddingChanged)
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 ImageItem(QQuickItem *parent = nullptr);
39 ~ImageItem() override = default;
40
41 void setImage(const QImage &image);
42 QImage image() const;
43 void resetImage();
44
45 int nativeWidth() const;
46 int nativeHeight() const;
47
48 int paintedWidth() const;
49 int paintedHeight() const;
50 int verticalPadding() const;
51 int horizontalPadding() const;
52
53 FillMode fillMode() const;
54 void setFillMode(FillMode mode);
55
56 void paint(QPainter *painter) override;
57
58 bool isNull() const;
59
61 void nativeWidthChanged();
62 void nativeHeightChanged();
63 void fillModeChanged();
64 void imageChanged();
65 void nullChanged();
66 void paintedWidthChanged();
67 void paintedHeightChanged();
68 void verticalPaddingChanged();
69 void horizontalPaddingChanged();
70
71protected:
72#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
73 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override;
74#else
75 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
76#endif
77
78private:
79 QImage m_image;
80 bool m_smooth;
81 FillMode m_fillMode;
82 QRect m_paintedRect;
83
84private Q_SLOTS:
85 void updatePaintedRect();
86};
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 Tue Mar 26 2024 11:19:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.