File indexing completed on 2024-06-23 04:27:04

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "RectangleShapeConfigCommand.h"
0008 #include "RectangleShape.h"
0009 #include <klocalizedstring.h>
0010 #include "kis_command_ids.h"
0011 
0012 
0013 RectangleShapeConfigCommand::RectangleShapeConfigCommand(RectangleShape *rectangle, qreal cornerRadiusX, qreal cornerRadiusY, KUndo2Command *parent)
0014     : KUndo2Command(parent)
0015     , m_rectangle(rectangle)
0016     , m_newCornerRadiusX(cornerRadiusX)
0017     , m_newCornerRadiusY(cornerRadiusY)
0018 {
0019     Q_ASSERT(m_rectangle);
0020 
0021     setText(kundo2_i18n("Change rectangle"));
0022 
0023     m_oldCornerRadiusX = m_rectangle->cornerRadiusX();
0024     m_oldCornerRadiusY = m_rectangle->cornerRadiusY();
0025 }
0026 
0027 void RectangleShapeConfigCommand::redo()
0028 {
0029     KUndo2Command::redo();
0030 
0031     m_rectangle->update();
0032 
0033     if (m_oldCornerRadiusX != m_newCornerRadiusX) {
0034         m_rectangle->setCornerRadiusX(m_newCornerRadiusX);
0035     }
0036     if (m_oldCornerRadiusY != m_newCornerRadiusY) {
0037         m_rectangle->setCornerRadiusY(m_newCornerRadiusY);
0038     }
0039 
0040     m_rectangle->update();
0041 }
0042 
0043 void RectangleShapeConfigCommand::undo()
0044 {
0045     KUndo2Command::undo();
0046 
0047     m_rectangle->update();
0048 
0049     if (m_oldCornerRadiusX != m_newCornerRadiusX) {
0050         m_rectangle->setCornerRadiusX(m_oldCornerRadiusX);
0051     }
0052     if (m_oldCornerRadiusY != m_newCornerRadiusY) {
0053         m_rectangle->setCornerRadiusY(m_oldCornerRadiusY);
0054     }
0055 
0056     m_rectangle->update();
0057 }
0058 
0059 int RectangleShapeConfigCommand::id() const
0060 {
0061     return KisCommandUtils::ChangeRectangleShapeId;
0062 }
0063 
0064 bool RectangleShapeConfigCommand::mergeWith(const KUndo2Command *command)
0065 {
0066     const RectangleShapeConfigCommand *other = dynamic_cast<const RectangleShapeConfigCommand*>(command);
0067 
0068     if (!other || other->m_rectangle != m_rectangle) {
0069         return false;
0070     }
0071 
0072     m_newCornerRadiusX = other->m_newCornerRadiusX;
0073     m_newCornerRadiusY = other->m_newCornerRadiusY;
0074 
0075     return true;
0076 }