libs/flake
KoParameterToPathCommand.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE project 00002 * Copyright (C) 2006,2008 Jan Hambrecht <jaham@gmx.net> 00003 * Copyright (C) 2006,2007 Thorsten Zachmann <zachmann@kde.org> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "KoParameterToPathCommand.h" 00022 #include "KoParameterShape.h" 00023 #include <klocale.h> 00024 00025 KoParameterToPathCommand::KoParameterToPathCommand(KoParameterShape *shape, QUndoCommand *parent) 00026 : QUndoCommand(parent) 00027 { 00028 m_shapes.append(shape); 00029 initialize(); 00030 setText(i18n("Convert to Path")); 00031 } 00032 00033 KoParameterToPathCommand::KoParameterToPathCommand(const QList<KoParameterShape*> &shapes, QUndoCommand *parent) 00034 : QUndoCommand(parent) 00035 , m_shapes(shapes) 00036 { 00037 initialize(); 00038 setText(i18n("Convert to Path")); 00039 } 00040 00041 KoParameterToPathCommand::~KoParameterToPathCommand() 00042 { 00043 qDeleteAll(m_copies); 00044 } 00045 00046 void KoParameterToPathCommand::redo() 00047 { 00048 QUndoCommand::redo(); 00049 for (int i = 0; i < m_shapes.size(); ++i) { 00050 KoParameterShape * parameterShape = m_shapes.at(i); 00051 parameterShape->update(); 00052 parameterShape->setModified(true); 00053 parameterShape->update(); 00054 } 00055 } 00056 00057 void KoParameterToPathCommand::undo() 00058 { 00059 QUndoCommand::undo(); 00060 for (int i = 0; i < m_shapes.size(); ++i) { 00061 KoParameterShape * parameterShape = m_shapes.at(i); 00062 parameterShape->update(); 00063 parameterShape->setModified(false); 00064 copyPath(parameterShape, m_copies[i]); 00065 parameterShape->update(); 00066 } 00067 } 00068 00069 void KoParameterToPathCommand::initialize() 00070 { 00071 foreach(KoParameterShape *shape, m_shapes) { 00072 KoPathShape * p = new KoPathShape(); 00073 copyPath(p, shape); 00074 m_copies.append(p); 00075 } 00076 } 00077 00078 void KoParameterToPathCommand::copyPath(KoPathShape * dst, KoPathShape * src) 00079 { 00080 dst->clear(); 00081 00082 int subpathCount = src->subpathCount(); 00083 for (int subpathIndex = 0; subpathIndex < subpathCount; ++subpathIndex) { 00084 int pointCount = src->pointCountSubpath(subpathIndex); 00085 if (! pointCount) 00086 continue; 00087 00088 KoSubpath * subpath = new KoSubpath; 00089 for (int pointIndex = 0; pointIndex < pointCount; ++pointIndex) { 00090 KoPathPoint * p = src->pointByIndex(KoPathPointIndex(subpathIndex, pointIndex)); 00091 KoPathPoint * c = new KoPathPoint(*p); 00092 c->setParent(dst); 00093 subpath->append(c); 00094 } 00095 dst->addSubpath(subpath, subpathIndex); 00096 } 00097 dst->setTransformation(src->transformation()); 00098 }
