Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_node_opacity_command.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2002 Patrick Julien <freak@codepimps.org>
3 * SPDX-FileCopyrightText: 2005 C. Boemann <cbo@boemann.dk>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#include <klocalizedstring.h>
9#include "kis_node.h"
11#include "kis_command_ids.h"
12#include "kis_command_utils.h"
14#include "kis_image.h"
17#include "kis_time_span.h"
18
19using namespace KisCommandUtils;
20
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}
38
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}
57
69
74
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}
92
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}
106
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}
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
the base command for commands altering a node
The command for setting the node opacity.
bool canAnnihilateWith(const KUndo2Command *command) const override
KisNodeOpacityCommand(KisNodeSP node, quint8 newOpacity)
boost::optional< quint8 > m_oldOpacity
QScopedPointer< KUndo2Command > m_autokey
bool mergeWith(const KUndo2Command *command) override
bool canMergeWith(const KUndo2Command *command) const override
The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisSca...
void addScalarKeyframe(int time, qreal value, KUndo2Command *parentUndoCmd=nullptr)
static KisTimeSpan infinite(int start)
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
#define KIS_SAFE_ASSERT_RECOVER_NOOP(cond)
Definition kis_assert.h:130
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
KUndo2MagicString kundo2_i18n(const char *text)
void setOpacity(quint8 val)
KisKeyframeChannel * getKeyframeChannel(const QString &id, bool create)
KisImageWSP image
quint8 opacity() const
void invalidateFrames(const KisTimeSpan &range, const QRect &rect)
Definition kis_node.cpp:616
virtual void setDirty()
Definition kis_node.cpp:577