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 QML_ELEMENT
17
18 Q_PROPERTY(QImage image READ image WRITE setImage NOTIFY imageChanged RESET resetImage)
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
28public:
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 int nativeWidth() const;
47 int nativeHeight() const;
48
49 int paintedWidth() const;
50 int paintedHeight() const;
51 int verticalPadding() const;
52 int horizontalPadding() const;
53
54 FillMode fillMode() const;
55 void setFillMode(FillMode mode);
56
57 void paint(QPainter *painter) override;
58
59 bool isNull() const;
60
62 void nativeWidthChanged();
63 void nativeHeightChanged();
64 void fillModeChanged();
65 void imageChanged();
66 void nullChanged();
67 void paintedWidthChanged();
68 void paintedHeightChanged();
69 void verticalPaddingChanged();
70 void horizontalPaddingChanged();
71
72protected:
73 void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override;
74
75private:
76 QImage m_image;
77 bool m_smooth;
78 FillMode m_fillMode;
79 QRect m_paintedRect;
80
81private Q_SLOTS:
82 void updatePaintedRect();
83};
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 Mon Nov 18 2024 12:17:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.