7#include "imagedocument.h"
9#include "commands/cropcommand.h"
10#include "commands/mirrorcommand.h"
11#include "commands/resizecommand.h"
12#include "commands/rotatecommand.h"
13#include "commands/colorcommands.h"
16ImageDocument::ImageDocument(
QObject *parent)
19 m_changesApplied =
true;
21 connect(
this, &ImageDocument::pathChanged,
this, [
this](
const QUrl &url) {
23 m_originalImage = m_image;
25 Q_EMIT editedChanged();
26 Q_EMIT imageChanged();
32 while (!m_undos.empty()) {
33 const auto command = m_undos.pop();
35 m_image = command->undo(m_image);
49bool ImageDocument::edited()
const
58 qDebug() <<
"No more commands to undo";
62 const auto command = m_undos.pop();
63 m_image = command->undo();
64 m_originalImage = m_image;
67 if (m_undos.empty()) {
75 m_image = command->redo(m_image);
76 m_undos.append(command);
84 m_image = command->redo(m_image);
85 m_undos.append(command);
93 m_image = command->redo(m_image);
95 m_undos.append(command);
103 transform.rotate(angle);
105 m_image = command->redo(m_image);
106 m_undos.append(command);
116 m_changesApplied = !value;
117 Q_EMIT changesAppliedChanged();
119 if (m_edited == value) {
128 return m_originalImage.save(m_path.isLocalFile() ? m_path.toLocalFile() : m_path.toString());
133 return m_originalImage.save(location.isLocalFile() ? location.toLocalFile() : location.
toString());
136void ImageDocument::adjustBrightness(
int value)
138 if(value == m_brightness)
141 auto oldBrightness = m_brightness;
142 m_brightness = value;
143 const auto command =
new ColorCommands::Brightness(m_image, m_brightness, [
this, oldBrightness]()
145 this->m_brightness = oldBrightness;
146 Q_EMIT brightnessChanged();
149 m_image = command->redo(m_originalImage);
150 m_undos.append(command);
151 Q_EMIT brightnessChanged();
156void ImageDocument::adjustContrast(
int value)
158 if(value == m_contrast)
161 auto oldContrast = m_contrast;
163 const auto command =
new ColorCommands::Contrast(m_image, m_contrast, [
this, oldContrast]()
165 this->m_contrast = oldContrast;
169 m_image = command->redo(m_originalImage);
170 m_undos.append(command);
176void ImageDocument::adjustSaturation(
int value)
178 if(m_image.isGrayscale())
181 if(value == m_saturation)
184 auto oldSaturation = m_saturation;
185 m_saturation = value;
186 const auto command =
new ColorCommands::Saturation(m_image, m_saturation, [
this, oldSaturation]()
188 this->m_saturation = oldSaturation;
189 Q_EMIT saturationChanged();
192 m_image = command->redo(m_originalImage);
193 m_undos.append(command);
196 Q_EMIT saturationChanged();
199void ImageDocument::adjustHue(
int value)
201 qDebug() <<
"adjust HUE DOCUMENT" << value;
202 if(m_image.isGrayscale())
208 auto oldValue = m_hue;
210 const auto command =
new ColorCommands::Hue(m_image, m_hue, [
this, oldValue]()
212 this->m_hue = oldValue;
216 m_image = command->redo(m_originalImage);
217 m_undos.append(command);
220 Q_EMIT saturationChanged();
223void ImageDocument::applyChanges()
227 m_originalImage = m_image;
228 m_changesApplied =
true;
229 Q_EMIT changesAppliedChanged();
232int ImageDocument::brightness()
const
237int ImageDocument::contrast()
const
242int ImageDocument::saturation()
const
247int ImageDocument::hue()
const
252QUrl ImageDocument::path()
const
257void ImageDocument::setPath(
const QUrl &path)
265QRectF ImageDocument::area()
const
270void ImageDocument::setArea(
const QRectF &newArea)
272 if (m_area == newArea)
278void ImageDocument::resetArea()
283void ImageDocument::resetValues()
290 Q_EMIT saturationChanged();
291 Q_EMIT brightnessChanged();
295bool ImageDocument::changesApplied()
const
297 return m_changesApplied;
CropCommand that crop the current image.
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.
MirrorCommand that mirror an image horizontally or vertically.
ResizeCommand that resizes the current image.
RotateCommand that rotates the current image.
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isLocalFile() const const
QString toLocalFile() const const
QString toString(FormattingOptions options) const const
QString toString() const const