Krita Source Code Documentation
Loading...
Searching...
No Matches
KoShapeAlignCommand Class Reference

The undo / redo command for aligning shapes. More...

#include <KoShapeAlignCommand.h>

+ Inheritance diagram for KoShapeAlignCommand:

Public Types

enum  Align {
  HorizontalLeftAlignment , HorizontalCenterAlignment , HorizontalRightAlignment , VerticalBottomAlignment ,
  VerticalCenterAlignment , VerticalTopAlignment
}
 The different alignment options for this command. More...
 

Public Member Functions

 KoShapeAlignCommand (const QList< KoShape * > &shapes, Align align, const QRectF &boundingRect, KUndo2Command *parent=0)
 
 Private ()
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoShapeAlignCommand () override
 
 ~Private ()
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
virtual bool canAnnihilateWith (const KUndo2Command *other) const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual int id () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
virtual bool mergeWith (const KUndo2Command *other)
 
virtual void redoMergedCommands ()
 
void setEndTime ()
 
virtual void setEndTime (const QTime &time)
 
void setExtraData (KUndo2CommandExtraData *data)
 
void setText (const KUndo2MagicString &text)
 
void setTime ()
 
virtual void setTime (const QTime &time)
 
virtual void setTimedID (int timedID)
 
KUndo2MagicString text () const
 
virtual QTime time () const
 
virtual int timedId () const
 
virtual bool timedMergeWith (KUndo2Command *other)
 
virtual void undoMergedCommands ()
 
virtual ~KUndo2Command ()
 

Public Attributes

KoShapeMoveCommandcommand
 

Private Attributes

Private *const d
 
- Private Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Additional Inherited Members

- Private Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Detailed Description

The undo / redo command for aligning shapes.

Definition at line 16 of file KoShapeAlignCommand.cpp.

Member Enumeration Documentation

◆ Align

The different alignment options for this command.

Enumerator
HorizontalLeftAlignment 

Align left.

HorizontalCenterAlignment 

Align Centered horizontally.

HorizontalRightAlignment 

Align Right.

VerticalBottomAlignment 

Align bottom.

VerticalCenterAlignment 

Align centered vertically.

VerticalTopAlignment 

Align top.

Definition at line 24 of file KoShapeAlignCommand.h.

Constructor & Destructor Documentation

◆ ~Private()

KoShapeAlignCommand::~Private ( )
inline

Definition at line 20 of file KoShapeAlignCommand.cpp.

20 {
21 delete command;
22 }
KoShapeMoveCommand * command

◆ KoShapeAlignCommand()

KoShapeAlignCommand::KoShapeAlignCommand ( const QList< KoShape * > & shapes,
Align align,
const QRectF & boundingRect,
KUndo2Command * parent = 0 )

Command to align a set of shapes in a rect

Parameters
shapesa set of all the shapes that should be aligned
alignthe alignment type
boundingRectthe rect the shape will be aligned in
parentthe parent command used for macro commands

Definition at line 26 of file KoShapeAlignCommand.cpp.

27 : KUndo2Command(parent),
28 d(new Private())
29{
30 QList<QPointF> previousPositions;
31 QList<QPointF> newPositions;
32 QPointF position;
33 QPointF delta;
34 QRectF bRect;
35 Q_FOREACH (KoShape *shape, shapes) {
36// if (dynamic_cast<KoShapeGroup*> (shape))
37// debugFlake <<"Found Group";
38// else if (dynamic_cast<KoShapeContainer*> (shape))
39// debugFlake <<"Found Container";
40// else
41// debugFlake <<"Found shape";
42 position = shape->absolutePosition();
43 previousPositions << position;
44 bRect = shape->absoluteOutlineRect();
45 switch (align) {
47 delta = QPointF(boundingRect.left(), bRect.y()) - bRect.topLeft();
48 break;
50 delta = QPointF(boundingRect.center().x() - bRect.width() / 2, bRect.y()) - bRect.topLeft();
51 break;
53 delta = QPointF(boundingRect.right() - bRect.width(), bRect.y()) - bRect.topLeft();
54 break;
56 delta = QPointF(bRect.x(), boundingRect.top()) - bRect.topLeft();
57 break;
59 delta = QPointF(bRect.x(), boundingRect.center().y() - bRect.height() / 2) - bRect.topLeft();
60 break;
62 delta = QPointF(bRect.x(), boundingRect.bottom() - bRect.height()) - bRect.topLeft();
63 break;
64 };
65 newPositions << position + delta;
66//debugFlake <<"-> moving" << position.x() <<"," << position.y() <<" to" <<
67// (position + delta).x() << ", " << (position+delta).y() << Qt::endl;
68 }
69 d->command = new KoShapeMoveCommand(shapes, previousPositions, newPositions);
70
71 setText(kundo2_i18n("Align shapes"));
72}
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
The undo / redo command for shape moving.
QPointF absolutePosition(KoFlake::AnchorPosition anchor=KoFlake::Center) const
Definition KoShape.cpp:653
QRectF absoluteOutlineRect() const
Definition KoShape.cpp:368
KUndo2MagicString kundo2_i18n(const char *text)

References KoShape::absoluteOutlineRect(), KoShape::absolutePosition(), d, HorizontalCenterAlignment, HorizontalLeftAlignment, HorizontalRightAlignment, kundo2_i18n(), KUndo2Command::setText(), VerticalBottomAlignment, VerticalCenterAlignment, and VerticalTopAlignment.

◆ ~KoShapeAlignCommand()

KoShapeAlignCommand::~KoShapeAlignCommand ( )
override

Definition at line 74 of file KoShapeAlignCommand.cpp.

75{
76 delete d;
77}

References d.

Member Function Documentation

◆ Private()

KoShapeAlignCommand::Private ( )
inline

Definition at line 19 of file KoShapeAlignCommand.cpp.

19: command(0) {}

◆ redo()

void KoShapeAlignCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 79 of file KoShapeAlignCommand.cpp.

80{
82 d->command->redo();
83}
virtual void redo()

References d, and KUndo2Command::redo().

◆ undo()

void KoShapeAlignCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 85 of file KoShapeAlignCommand.cpp.

86{
88 d->command->undo();
89}
virtual void undo()

References d, and KUndo2Command::undo().

Member Data Documentation

◆ command

KoShapeMoveCommand* KoShapeAlignCommand::command

Definition at line 23 of file KoShapeAlignCommand.cpp.

◆ d

Private* const KoShapeAlignCommand::d
private

Definition at line 47 of file KoShapeAlignCommand.h.


The documentation for this class was generated from the following files: