KQuickImageEditor

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