KQuickImageEditor

imagedocument.h
1/*
2 * SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#pragma once
8
9#include <QImage>
10#include <QObject>
11#include <QStack>
12#include <QUrl>
13#include <qqmlregistration.h>
14
15#include "commands/undocommand.h"
16
17/**
18 * @brief An ImageDocument is the base class of the ImageEditor.
19 *
20 * This class handles various image manipulation and contains an undo stack to allow
21 * reverting the last actions. This class does not display the image, use @c ImageItem
22 * for this task.
23 *
24 * @code{.qml}
25 * KQuickImageEditor.ImageDocument {
26 * id: imageDocument
27 * path: myModel.image
28 * }
29 *
30 * Kirigami.Actions {
31 * iconName: "object-rotate-left"
32 * onTriggered: imageDocument.rotate(-90);
33 * }
34 *
35 * KQuickImageEditor.ImageItem {
36 * image: imageDocument.image
37 * }
38 * @endcode
39 */
40class ImageDocument : public QObject
41{
43 QML_ELEMENT
44
45 Q_PROPERTY(QUrl path READ path WRITE setPath NOTIFY pathChanged)
46 Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
47 Q_PROPERTY(bool edited READ edited WRITE setEdited NOTIFY editedChanged)
48
49public:
50 ImageDocument(QObject *parent = nullptr);
51 ~ImageDocument() override = default;
52
53 /**
54 * The image was is displayed. This propriety is updated when the path change
55 * or commands are applied.
56 *
57 * @see imageChanged
58 */
59 QImage image() const;
60
61 /**
62 * This propriety store if the document was changed or not.
63 *
64 * @see setEdited
65 * @see editedChanged
66 */
67 bool edited() const;
68
69 /**
70 * Change the edited value.
71 * @param value The new value.
72 */
73 void setEdited(bool value);
74
75 QUrl path() const;
76 void setPath(const QUrl &path);
77
78 /**
79 * Rotate the image.
80 * @param angle The angle of the rotation in degree.
81 */
82 Q_INVOKABLE void rotate(int angle);
83
84 /**
85 * Mirror the image.
86 * @param horizontal Mirror the image horizontally.
87 * @param vertical Mirror the image vertically.
88 */
89 Q_INVOKABLE void mirror(bool horizontal, bool vertical);
90
91 /**
92 * Crop the image.
93 * @param x The x coordinate of the new image in the old image.
94 * @param y The y coordinate of the new image in the old image.
95 * @param width The width of the new image.
96 * @param height The height of the new image.
97 */
98 Q_INVOKABLE void crop(int x, int y, int width, int height);
99
100 /**
101 * Resize the image.
102 * @param width The width of the new image.
103 * @param height The height of the new image.
104 */
105 Q_INVOKABLE void resize(int width, int height);
106
107 /**
108 * Undo the last edit on the images.
109 */
110 Q_INVOKABLE void undo();
111
112 /**
113 * Cancel all the edit.
114 */
115 Q_INVOKABLE void cancel();
116
117 /**
118 * Save current edited image in place. This is a destructive operation and can't be reverted.
119 * @return true iff the file saving operation was successful.
120 */
121 Q_INVOKABLE bool save();
122
123 /**
124 * Save current edited image as a new image.
125 * @param location The location where to save the new image.
126 * @return true iff the file saving operattion was successful.
127 */
128 Q_INVOKABLE bool saveAs(const QUrl &location);
129
131 void pathChanged(const QUrl &url);
132 void imageChanged();
133 void editedChanged();
134
135private:
136 QUrl m_path;
137 QStack<UndoCommand *> m_undos;
138 QImage m_image;
139 bool m_edited;
140};
An ImageDocument is the base class of the ImageEditor.
Q_INVOKABLE void undo()
Undo the last edit on the images.
Q_INVOKABLE void rotate(int angle)
Rotate the image.
Q_INVOKABLE bool saveAs(const QUrl &location)
Save current edited image as a new image.
Q_INVOKABLE bool save()
Save current edited image in place.
Q_INVOKABLE void mirror(bool horizontal, bool vertical)
Mirror the image.
Q_INVOKABLE void crop(int x, int y, int width, int height)
Crop the image.
Q_INVOKABLE void cancel()
Cancel all the edit.
void setEdited(bool value)
Change the edited value.
Q_INVOKABLE void resize(int width, int height)
Resize the image.
Q_INVOKABLEQ_INVOKABLE
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
QObject * parent() const const
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.