File indexing completed on 2024-09-29 04:13:50

0001 /*
0002  * SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  */
0006 
0007 #include "cropcommand.h"
0008 
0009 CropCommand::CropCommand(const QRect &cropRect)
0010     : m_cropRect(cropRect)
0011 {
0012 }
0013 
0014 QImage CropCommand::undo(QImage image)
0015 {
0016     Q_UNUSED(image)
0017     return m_image;
0018 }
0019 
0020 QImage CropCommand::redo(QImage image)
0021 {
0022     m_image = image;
0023     if (m_cropRect.x() < 0) {
0024         m_cropRect.setWidth(m_cropRect.width() + m_cropRect.x());
0025         m_cropRect.setX(0);
0026     }
0027     if (m_cropRect.y() < 0) {
0028         m_cropRect.setHeight(m_cropRect.height() + m_cropRect.y());
0029         m_cropRect.setY(0);
0030     }
0031     if (m_image.width() < m_cropRect.width() + m_cropRect.x()) {
0032         m_cropRect.setWidth(m_image.width() - m_cropRect.x());
0033     }
0034     if (m_image.height() < m_cropRect.height() + m_cropRect.y()) {
0035         m_cropRect.setHeight(m_image.height() - m_cropRect.y());
0036     }
0037     return m_image.copy(m_cropRect);
0038 }