libs/flake
KoShapeAlignCommand.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 #include "KoShapeAlignCommand.h"
00022 #include "KoShape.h"
00023 #include "KoShapeGroup.h"
00024 #include "commands/KoShapeMoveCommand.h"
00025
00026 #include <klocale.h>
00027
00028
00029 class KoShapeAlignCommand::Private
00030 {
00031 public:
00032 Private() : command(0) {}
00033 ~Private() {
00034 delete command;
00035 }
00036 KoShapeMoveCommand *command;
00037 };
00038
00039 KoShapeAlignCommand::KoShapeAlignCommand(const QList<KoShape*> &shapes, Align align, QRectF boundingRect,
00040 QUndoCommand *parent)
00041 : QUndoCommand(parent),
00042 d(new Private())
00043 {
00044 QList<QPointF> previousPositions;
00045 QList<QPointF> newPositions;
00046 QPointF position;
00047 QPointF delta;
00048 QRectF bRect;
00049 foreach(KoShape *shape, shapes) {
00050
00051
00052
00053
00054
00055
00056 position = shape->position();
00057 previousPositions << position;
00058 bRect = shape->boundingRect();
00059 switch (align) {
00060 case HorizontalLeftAlignment:
00061 delta = QPointF(boundingRect.left(), bRect.y()) - bRect.topLeft();
00062 break;
00063 case HorizontalCenterAlignment:
00064 delta = QPointF(boundingRect.center().x() - bRect.width() / 2, bRect.y()) - bRect.topLeft();
00065 break;
00066 case HorizontalRightAlignment:
00067 delta = QPointF(boundingRect.right() - bRect.width(), bRect.y()) - bRect.topLeft();
00068 break;
00069 case VerticalTopAlignment:
00070 delta = QPointF(bRect.x(), boundingRect.top()) - bRect.topLeft();
00071 break;
00072 case VerticalCenterAlignment:
00073 delta = QPointF(bRect.x(), boundingRect.center().y() - bRect.height() / 2) - bRect.topLeft();
00074 break;
00075 case VerticalBottomAlignment:
00076 delta = QPointF(bRect.x(), boundingRect.bottom() - bRect.height()) - bRect.topLeft();
00077 break;
00078 };
00079 newPositions << position + delta;
00080
00081
00082 }
00083 d->command = new KoShapeMoveCommand(shapes, previousPositions, newPositions);
00084
00085 setText(i18n("Align shapes"));
00086 }
00087
00088 KoShapeAlignCommand::~KoShapeAlignCommand()
00089 {
00090 delete d;
00091 }
00092
00093 void KoShapeAlignCommand::redo()
00094 {
00095 QUndoCommand::redo();
00096 d->command->redo();
00097 }
00098
00099 void KoShapeAlignCommand::undo()
00100 {
00101 QUndoCommand::undo();
00102 d->command->undo();
00103 }
|