libs/flake
KoPathPointMoveCommand.cppGo to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "KoPathPointMoveCommand.h"
00023 #include "KoPathPoint.h"
00024 #include <klocale.h>
00025
00026 KoPathPointMoveCommand::KoPathPointMoveCommand(const QList<KoPathPointData> &pointData, const QPointF &offset, QUndoCommand *parent)
00027 : QUndoCommand(parent)
00028 , m_undoCalled(true)
00029 {
00030 setText(i18n("Move points"));
00031
00032 foreach( const KoPathPointData &data, pointData ) {
00033 if (!m_points.contains(data)) {
00034 m_points[data] = offset;
00035 m_paths.insert(data.pathShape);
00036 }
00037 }
00038 }
00039
00040 KoPathPointMoveCommand::KoPathPointMoveCommand(const QList<KoPathPointData> &pointData, const QList<QPointF> &offsets, QUndoCommand *parent)
00041 : QUndoCommand(parent)
00042 , m_undoCalled(true)
00043 {
00044 Q_ASSERT(pointData.count() == offsets.count());
00045
00046 setText(i18n("Move points"));
00047
00048 uint dataCount = pointData.count();
00049 for (uint i = 0; i < dataCount; ++i) {
00050 const KoPathPointData & data = pointData[i];
00051 if (!m_points.contains(data)) {
00052 m_points[data] = offsets[i];
00053 m_paths.insert(data.pathShape);
00054 }
00055 }
00056 }
00057
00058 void KoPathPointMoveCommand::redo()
00059 {
00060 QUndoCommand::redo();
00061 if (! m_undoCalled)
00062 return;
00063
00064 applyOffset( 1.0 );
00065
00066 m_undoCalled = false;
00067 }
00068
00069 void KoPathPointMoveCommand::undo()
00070 {
00071 QUndoCommand::undo();
00072 if (m_undoCalled)
00073 return;
00074
00075 applyOffset( -1.0 );
00076
00077 m_undoCalled = true;
00078 }
00079
00080 void KoPathPointMoveCommand::applyOffset( qreal factor )
00081 {
00082 foreach(KoPathShape * path, m_paths) {
00083
00084 path->update();
00085 }
00086
00087 QMap<KoPathPointData, QPointF>::iterator it(m_points.begin());
00088 for (; it != m_points.end(); ++it) {
00089 KoPathShape * path = it.key().pathShape;
00090
00091 QPointF shapeOffset = path->documentToShape(factor*it.value()) - path->documentToShape(QPointF());
00092 QMatrix matrix;
00093 matrix.translate(shapeOffset.x(), shapeOffset.y());
00094
00095 KoPathPoint * p = path->pointByIndex(it.key().pointIndex);
00096 if ( p )
00097 p->map(matrix, true);
00098 }
00099
00100 foreach(KoPathShape * path, m_paths) {
00101 path->normalize();
00102
00103 path->update();
00104 }
00105 }
|