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

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

#include <KoShapeDistributeCommand.h>

+ Inheritance diagram for KoShapeDistributeCommand:

Public Types

enum  Distribute {
  HorizontalCenterDistribution , HorizontalGapsDistribution , HorizontalLeftDistribution , HorizontalRightDistribution ,
  VerticalCenterDistribution , VerticalGapsDistribution , VerticalBottomDistribution , VerticalTopDistribution
}
 The different options to distribute with this command. More...
 

Public Member Functions

qreal getAvailableSpace (KoShape *first, KoShape *last, qreal extent, const QRectF &boundingRect)
 
 KoShapeDistributeCommand (const QList< KoShape * > &shapes, Distribute distribute, const QRectF &boundingRect, KUndo2Command *parent=0)
 
 Private ()
 
void redo () override
 redo the command
 
void undo () override
 revert the actions done in redo
 
 ~KoShapeDistributeCommand () 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
 
Distribute distribute
 

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 distributing shapes.

Definition at line 16 of file KoShapeDistributeCommand.cpp.

Member Enumeration Documentation

◆ Distribute

The different options to distribute with this command.

Enumerator
HorizontalCenterDistribution 

Horizontal centered.

HorizontalGapsDistribution 

Horizontal Gaps.

HorizontalLeftDistribution 

Horizontal Left.

HorizontalRightDistribution 

Horizontal Right.

VerticalCenterDistribution 

Vertical centered.

VerticalGapsDistribution 

Vertical Gaps.

VerticalBottomDistribution 

Vertical bottom.

VerticalTopDistribution 

Vertical top.

Definition at line 24 of file KoShapeDistributeCommand.h.

Constructor & Destructor Documentation

◆ ~Private()

KoShapeDistributeCommand::~Private ( )
inline

Definition at line 20 of file KoShapeDistributeCommand.cpp.

20 {
21 delete command;
22 }

◆ KoShapeDistributeCommand()

KoShapeDistributeCommand::KoShapeDistributeCommand ( const QList< KoShape * > & shapes,
Distribute distribute,
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 distributed
distributethe distribution type
boundingRectthe rect the shapes will be distributed in
parentthe parent command used for macro commands

Definition at line 30 of file KoShapeDistributeCommand.cpp.

31 : KUndo2Command(parent),
32 d(new Private())
33{
34 d->distribute = distribute;
35 QMap<qreal, KoShape*> sortedPos;
36 QRectF bRect;
37 qreal extent = 0.0;
38 // sort by position and calculate sum of objects width/height
39 Q_FOREACH (KoShape *shape, shapes) {
40 bRect = shape->absoluteOutlineRect();
41 switch (d->distribute) {
43 sortedPos[bRect.center().x()] = shape;
44 break;
47 sortedPos[bRect.left()] = shape;
48 extent += bRect.width();
49 break;
51 sortedPos[bRect.right()] = shape;
52 break;
54 sortedPos[bRect.center().y()] = shape;
55 break;
58 sortedPos[bRect.bottom()] = shape;
59 extent += bRect.height();
60 break;
62 sortedPos[bRect.top()] = shape;
63 break;
64 }
65 }
66 KoShape* first = sortedPos.begin().value();
67 KoShape* last = (--sortedPos.end()).value();
68
69 // determine the available space to distribute
70 qreal space = d->getAvailableSpace(first, last, extent, boundingRect);
71 qreal pos = 0.0, step = space / qreal(shapes.count() - 1);
72
73 QList<QPointF> previousPositions;
74 QList<QPointF> newPositions;
75 QPointF position;
76 QPointF delta;
77 QMapIterator<qreal, KoShape*> it(sortedPos);
78 while (it.hasNext()) {
79 it.next();
80 position = it.value()->absolutePosition();
81 previousPositions << position;
82
83 bRect = it.value()->absoluteOutlineRect();
84 switch (d->distribute) {
86 delta = QPointF(boundingRect.x() + first->absoluteOutlineRect().width() / 2 + pos - bRect.width() / 2, bRect.y()) - bRect.topLeft();
87 break;
89 delta = QPointF(boundingRect.left() + pos, bRect.y()) - bRect.topLeft();
90 pos += bRect.width();
91 break;
93 delta = QPointF(boundingRect.left() + pos, bRect.y()) - bRect.topLeft();
94 break;
96 delta = QPointF(boundingRect.left() + first->absoluteOutlineRect().width() + pos - bRect.width(), bRect.y()) - bRect.topLeft();
97 break;
99 delta = QPointF(bRect.x(), boundingRect.y() + first->absoluteOutlineRect().height() / 2 + pos - bRect.height() / 2) - bRect.topLeft();
100 break;
102 delta = QPointF(bRect.x(), boundingRect.top() + pos) - bRect.topLeft();
103 pos += bRect.height();
104 break;
106 delta = QPointF(bRect.x(), boundingRect.top() + first->absoluteOutlineRect().height() + pos - bRect.height()) - bRect.topLeft();
107 break;
109 delta = QPointF(bRect.x(), boundingRect.top() + pos) - bRect.topLeft();
110 break;
111 };
112 newPositions << position + delta;
113 pos += step;
114 }
115 d->command = new KoShapeMoveCommand(sortedPos.values(), previousPositions, newPositions);
116
117 setText(kundo2_i18n("Distribute shapes"));
118}
float value(const T *src, size_t ch)
void setText(const KUndo2MagicString &text)
KUndo2Command(KUndo2Command *parent=0)
The undo / redo command for shape moving.
QRectF absoluteOutlineRect() const
Definition KoShape.cpp:368
KUndo2MagicString kundo2_i18n(const char *text)

References KoShape::absoluteOutlineRect(), d, distribute, HorizontalCenterDistribution, HorizontalGapsDistribution, HorizontalLeftDistribution, HorizontalRightDistribution, kundo2_i18n(), KUndo2Command::setText(), value(), VerticalBottomDistribution, VerticalCenterDistribution, VerticalGapsDistribution, and VerticalTopDistribution.

◆ ~KoShapeDistributeCommand()

KoShapeDistributeCommand::~KoShapeDistributeCommand ( )
override

Definition at line 120 of file KoShapeDistributeCommand.cpp.

121{
122 delete d;
123}

References d.

Member Function Documentation

◆ getAvailableSpace()

qreal KoShapeDistributeCommand::getAvailableSpace ( KoShape * first,
KoShape * last,
qreal extent,
const QRectF & boundingRect )

◆ Private()

KoShapeDistributeCommand::Private ( )
inline

Definition at line 19 of file KoShapeDistributeCommand.cpp.

19: command(0) {}

◆ redo()

void KoShapeDistributeCommand::redo ( )
overridevirtual

redo the command

Reimplemented from KUndo2Command.

Definition at line 125 of file KoShapeDistributeCommand.cpp.

126{
128 d->command->redo();
129}
virtual void redo()

References d, and KUndo2Command::redo().

◆ undo()

void KoShapeDistributeCommand::undo ( )
overridevirtual

revert the actions done in redo

Reimplemented from KUndo2Command.

Definition at line 131 of file KoShapeDistributeCommand.cpp.

132{
134 d->command->undo();
135}
virtual void undo()

References d, and KUndo2Command::undo().

Member Data Documentation

◆ command

KoShapeMoveCommand* KoShapeDistributeCommand::command

Definition at line 27 of file KoShapeDistributeCommand.cpp.

◆ d

Private* const KoShapeDistributeCommand::d
private

Definition at line 51 of file KoShapeDistributeCommand.h.

◆ distribute

Distribute KoShapeDistributeCommand::distribute

Definition at line 26 of file KoShapeDistributeCommand.cpp.


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