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

The command for setting the node opacity. More...

#include <kis_node_opacity_command.h>

+ Inheritance diagram for KisNodeOpacityCommand:

Public Member Functions

bool canAnnihilateWith (const KUndo2Command *command) const override
 
bool canMergeWith (const KUndo2Command *command) const override
 
int id () const override
 
 KisNodeOpacityCommand (KisNodeSP node, quint8 newOpacity)
 
bool mergeWith (const KUndo2Command *command) override
 
void redo () override
 
void undo () override
 
- Public Member Functions inherited from KisNodeCommand
 KisNodeCommand (const KUndo2MagicString &name, KisNodeSP node)
 
 ~KisNodeCommand () override
 
- Public Member Functions inherited from KUndo2Command
QString actionText () const
 
const KUndo2Commandchild (int index) const
 
int childCount () const
 
virtual QTime endTime () const
 
KUndo2CommandExtraDataextraData () const
 
bool hasParent () const
 
virtual bool isMerged () const
 
 KUndo2Command (const KUndo2MagicString &text, KUndo2Command *parent=0)
 
 KUndo2Command (KUndo2Command *parent=0)
 
virtual QVector< KUndo2Command * > mergeCommandsVector () const
 
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 Member Functions inherited from KisAsynchronouslyMergeableCommandInterface
virtual ~KisAsynchronouslyMergeableCommandInterface ()
 

Private Attributes

QScopedPointer< KUndo2Commandm_autokey
 
quint8 m_newOpacity
 
boost::optional< quint8 > m_oldOpacity
 

Additional Inherited Members

- Protected Attributes inherited from KisNodeCommand
KisNodeSP m_node
 

Detailed Description

The command for setting the node opacity.

Definition at line 15 of file kis_node_opacity_command.h.

Constructor & Destructor Documentation

◆ KisNodeOpacityCommand()

KisNodeOpacityCommand::KisNodeOpacityCommand ( KisNodeSP node,
quint8 newOpacity )

Constructor

Parameters
nodeThe node the command will be working on.
oldOpacitythe old node opacity
newOpacitythe new node opacity

Definition at line 21 of file kis_node_opacity_command.cpp.

21 :
22 KisNodeCommand(kundo2_i18n("Opacity Change"), node)
23{
24 m_newOpacity = newOpacity;
25
27
28 const int time = node->image()->animationInterface()->currentTime();
29
31 if (channel && !channel->keyframeAt(time)) {
32 KisScalarKeyframeChannel* scalarChannel = dynamic_cast<KisScalarKeyframeChannel*>(channel);
33 KIS_ASSERT(scalarChannel);
35 scalarChannel->addScalarKeyframe(time, newOpacity, m_autokey.data());
36 }
37}
virtual QTime time() const
KisImageAnimationInterface * animationInterface() const
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
KisKeyframeSP keyframeAt(int time) const
Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
static const KoID Opacity
KisNodeCommand(const KUndo2MagicString &name, KisNodeSP node)
QScopedPointer< KUndo2Command > m_autokey
The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisSca...
void addScalarKeyframe(int time, qreal value, KUndo2Command *parentUndoCmd=nullptr)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)
KisImageWSP image

References KisScalarKeyframeChannel::addScalarKeyframe(), KisImage::animationInterface(), KisImageAnimationInterface::currentTime(), KisBaseNode::getKeyframeChannel(), KisBaseNode::image, KisKeyframeChannel::keyframeAt(), KIS_ASSERT, KIS_SAFE_ASSERT_RECOVER_RETURN, m_autokey, m_newOpacity, KisNodeCommand::m_node, KisKeyframeChannel::Opacity, and KUndo2Command::time().

Member Function Documentation

◆ canAnnihilateWith()

bool KisNodeOpacityCommand::canAnnihilateWith ( const KUndo2Command * other) const
overridevirtual

Attempts to merge this command with command and checks if the two commands compensate each other. If the function returns true, both commands are removed from the stack.

If this function returns true, calling this command's redo() followed by other redo() must have no effect.

The function itself shouldn't do any changes to the command, because after returning true, the command will be deleted as a "noop"

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 107 of file kis_node_opacity_command.cpp.

108{
109 const KisNodeOpacityCommand *other =
110 dynamic_cast<const KisNodeOpacityCommand*>(command);
111
112 if (!other || other->m_node != m_node) {
113 return false;
114 }
115
116 if (m_autokey || other->m_autokey) {
117 return false;
118 }
119
121 return *m_oldOpacity == other->m_newOpacity;
122}
The command for setting the node opacity.
boost::optional< quint8 > m_oldOpacity
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129

References KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE, m_autokey, m_newOpacity, KisNodeCommand::m_node, and m_oldOpacity.

◆ canMergeWith()

bool KisNodeOpacityCommand::canMergeWith ( const KUndo2Command * command) const
overridevirtual
Returns
true if command can be merged with (*this) command using KUndo2Command::mergeWith() call.

WARNING: if canMergeWith() returned true, then mergeWith() must also return true. Otherwise KisSavedMacroCommand will be able to enter inconsistent state and assert.

Implements KisAsynchronouslyMergeableCommandInterface.

Definition at line 93 of file kis_node_opacity_command.cpp.

94{
95 const KisNodeOpacityCommand *other =
96 dynamic_cast<const KisNodeOpacityCommand*>(command);
97 if (!other) return false;
98
99
100 bool otherCreatedKeyframe = bool(other->m_autokey);
101 bool weCreatedKeyframe = bool(m_autokey);
102 bool canMergeKeyframe = ((otherCreatedKeyframe ^ weCreatedKeyframe) == true) || (!otherCreatedKeyframe && !weCreatedKeyframe);
103
104 return other->m_node == m_node && canMergeKeyframe;
105}

References m_autokey, and KisNodeCommand::m_node.

◆ id()

int KisNodeOpacityCommand::id ( ) const
overridevirtual

Returns the ID of this command.

A command ID is used in command compression. It must be an integer unique to this command's class, or -1 if the command doesn't support compression.

If the command supports compression this function must be overridden in the derived class to return the correct ID. The base implementation returns -1.

KUndo2QStack::push() will only try to merge two commands if they have the same ID, and the ID is not -1.

See also
mergeWith(), KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 70 of file kis_node_opacity_command.cpp.

References KisCommandUtils::ChangeNodeOpacityId.

◆ mergeWith()

bool KisNodeOpacityCommand::mergeWith ( const KUndo2Command * command)
overridevirtual

Attempts to merge this command with command. Returns true on success; otherwise returns false.

If this function returns true, calling this command's redo() must have the same effect as redoing both this command and command. Similarly, calling this command's undo() must have the same effect as undoing command and this command.

KUndo2QStack will only try to merge two commands if they have the same id, and the id is not -1.

The default implementation returns false.

See also
id() KUndo2QStack::push()

Reimplemented from KUndo2Command.

Definition at line 75 of file kis_node_opacity_command.cpp.

76{
77 const KisNodeOpacityCommand *other =
78 dynamic_cast<const KisNodeOpacityCommand*>(command);
79
80 if (other && other->m_node == m_node) {
81 // verify both commands have been executed and they are consecutive
85
87 return true;
88 }
89
90 return false;
91}
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130

References KIS_SAFE_ASSERT_RECOVER_NOOP, m_newOpacity, KisNodeCommand::m_node, and m_oldOpacity.

◆ redo()

void KisNodeOpacityCommand::redo ( )
overridevirtual

Applies a change to the document. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls redo() on all child commands.

See also
undo()

Reimplemented from KUndo2Command.

Definition at line 39 of file kis_node_opacity_command.cpp.

40{
41 if (!m_oldOpacity) {
43 }
44
45 if (m_autokey) {
46 m_autokey->redo();
47 }
48
51
52 // BUG:499389 workaround.
53 // Unlike drawing, non-animated opacity changes need to be recached across all raster frames.
54 // It's probably better to change KisNode::setDirty, KisImage::requestProjectionUpdate, and/or KisProjectionUpdateFlags.
56}
static KisTimeSpan infinite(int start)
void setOpacity(quint8 val)
quint8 opacity() const
void invalidateFrames(const KisTimeSpan &range, const QRect &rect)
Definition kis_node.cpp:616
virtual void setDirty()
Definition kis_node.cpp:577

References KisTimeSpan::infinite(), KisNode::invalidateFrames(), m_autokey, m_newOpacity, KisNodeCommand::m_node, m_oldOpacity, KisBaseNode::opacity(), KisNode::setDirty(), and KisBaseNode::setOpacity().

◆ undo()

void KisNodeOpacityCommand::undo ( )
overridevirtual

Reverts a change to the document. After undo() is called, the state of the document should be the same as before redo() was called. This function must be implemented in the derived class. Calling KUndo2QStack::push(), KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to undefined behavior.

The default implementation calls undo() on all child commands in reverse order.

See also
redo()

Reimplemented from KUndo2Command.

Definition at line 58 of file kis_node_opacity_command.cpp.

59{
61
64
65 if (m_autokey) {
66 m_autokey->undo();
67 }
68}

References KIS_SAFE_ASSERT_RECOVER_RETURN, m_autokey, KisNodeCommand::m_node, m_oldOpacity, KisNode::setDirty(), and KisBaseNode::setOpacity().

Member Data Documentation

◆ m_autokey

QScopedPointer<KUndo2Command> KisNodeOpacityCommand::m_autokey
private

Definition at line 37 of file kis_node_opacity_command.h.

◆ m_newOpacity

quint8 KisNodeOpacityCommand::m_newOpacity
private

Definition at line 38 of file kis_node_opacity_command.h.

◆ m_oldOpacity

boost::optional<quint8> KisNodeOpacityCommand::m_oldOpacity
private

Definition at line 36 of file kis_node_opacity_command.h.


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