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

#include <KisAnimatedOpacityProperty.h>

+ Inheritance diagram for KisAnimatedOpacityProperty:

Public Slots

void slotKeyChanged (const KisKeyframeChannel *, int time)
 
void slotKeyRemoval (const KisKeyframeChannel *, int)
 

Signals

void changed (quint8 value)
 

Public Member Functions

KisScalarKeyframeChannelchannel () const
 
quint8 get ()
 
bool hasChannel ()
 
 KisAnimatedOpacityProperty (KisDefaultBoundsBaseSP bounds, KoProperties *const props, quint8 defaultValue, QObject *parent=nullptr)
 
void makeAnimated (KisNode *parentNode)
 
void set (const quint8 value)
 
void transferKeyframeData (const KisAnimatedOpacityProperty &rhs)
 
void updateDefaultBounds (KisDefaultBoundsBaseSP bounds)
 

Private Attributes

KisDefaultBoundsBaseSP m_bounds
 
QScopedPointer< KisScalarKeyframeChannelm_channel
 
quint8 m_defaultValue
 
KoProperties *const m_props
 

Detailed Description

Definition at line 21 of file KisAnimatedOpacityProperty.h.

Constructor & Destructor Documentation

◆ KisAnimatedOpacityProperty()

KisAnimatedOpacityProperty::KisAnimatedOpacityProperty ( KisDefaultBoundsBaseSP bounds,
KoProperties *const props,
quint8 defaultValue,
QObject * parent = nullptr )

Definition at line 10 of file KisAnimatedOpacityProperty.cpp.

11 : QObject(parent),
13 m_props(props),
14 m_defaultValue(defaultValue)
15{
16}
#define bounds(x, a, b)

Member Function Documentation

◆ changed

void KisAnimatedOpacityProperty::changed ( quint8 value)
signal

◆ channel()

KisScalarKeyframeChannel * KisAnimatedOpacityProperty::channel ( ) const
inline

Definition at line 30 of file KisAnimatedOpacityProperty.h.

30{ return m_channel.data(); }
QScopedPointer< KisScalarKeyframeChannel > m_channel

◆ get()

quint8 KisAnimatedOpacityProperty::get ( )

Definition at line 18 of file KisAnimatedOpacityProperty.cpp.

18 {
19 QVariant variant;
20 bool ok = m_props->property("opacity", variant);
21 const quint8 value = ok ? variant.toInt() : m_defaultValue;
22
23 if (m_channel) {
24 qreal chanValue = m_channel->currentValue();
25 if (!qIsNaN(chanValue)){
26 return (chanValue * 255 / 100);
27 }
28 }
29
30 return value;
31}
float value(const T *src, size_t ch)
bool property(const QString &name, QVariant &value) const

References m_channel, m_defaultValue, m_props, KoProperties::property(), and value().

◆ hasChannel()

bool KisAnimatedOpacityProperty::hasChannel ( )
inline

Definition at line 29 of file KisAnimatedOpacityProperty.h.

29{ return !m_channel.isNull(); }

◆ makeAnimated()

void KisAnimatedOpacityProperty::makeAnimated ( KisNode * parentNode)

Definition at line 68 of file KisAnimatedOpacityProperty.cpp.

68 {
71 new KisDefaultBoundsNodeWrapper(parentNode)
72 ));
73
74 m_channel->setNode(parentNode);
75 m_channel->setDefaultBounds(new KisDefaultBoundsNodeWrapper(parentNode));
76 m_channel->setLimits(0, 100);
77 m_channel->setDefaultInterpolationMode(KisScalarKeyframe::Linear);
78 m_channel->setDefaultValue(100);
79
80 connect(m_channel.data(), SIGNAL(sigKeyframeChanged(const KisKeyframeChannel*,int)), this, SLOT(slotKeyChanged(const KisKeyframeChannel*,int)));
81 connect(m_channel.data(), SIGNAL(sigKeyframeHasBeenRemoved(const KisKeyframeChannel*,int)), this, SLOT(slotKeyRemoval(const KisKeyframeChannel*,int)));
82}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void slotKeyChanged(const KisKeyframeChannel *, int time)
void slotKeyRemoval(const KisKeyframeChannel *, int)
KisKeyframeChannel stores and manages KisKeyframes. Maps units of time to virtual keyframe values....
static const KoID Opacity
The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisSca...

References connect(), KisScalarKeyframe::Linear, m_channel, KisKeyframeChannel::Opacity, slotKeyChanged(), and slotKeyRemoval().

◆ set()

void KisAnimatedOpacityProperty::set ( const quint8 value)

Definition at line 33 of file KisAnimatedOpacityProperty.cpp.

33 {
34 quint8 valueToAssign;
35 if (m_channel && m_channel->keyframeCount() > 0) {
36 const int currentTime = m_bounds->currentTime();
37 const float currentValue = m_channel->valueAt(currentTime);
38 KisScalarKeyframeSP key = m_channel->keyframeAt<KisScalarKeyframe>(currentTime);
39
40 if (!key) {
41 m_channel->addScalarKeyframe(currentTime, currentValue);
42 key = m_channel->keyframeAt<KisScalarKeyframe>(currentTime);
43 KIS_ASSERT(key);
44 }
45
46 const int translatedOldValue = key->value() * 255 / 100; //0..100 -> 0..255
47
48 if (translatedOldValue == value) {
49 return;
50 }
51
52 key->setValue(qreal(value) * 100 / 255);
53
54 valueToAssign = qreal(m_channel->currentValue()) * 255 / 100;
55 } else {
56 valueToAssign = value;
57 }
58
59 if (m_props->intProperty("opacity", m_defaultValue) == valueToAssign) {
60 return;
61 }
62
63 m_props->setProperty("opacity", valueToAssign);
64 KIS_ASSERT(valueToAssign == value); //Sanity check.
65 Q_EMIT changed(valueToAssign);
66}
void changed(quint8 value)
virtual int currentTime() const =0
The KisScalarKeyframe class is a concrete subclass of KisKeyframe that wraps a scalar value and inter...
int intProperty(const QString &name, int defaultValue=0) const
void setProperty(const QString &name, const QVariant &value)
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References changed(), KisDefaultBoundsBase::currentTime(), KoProperties::intProperty(), KIS_ASSERT, m_bounds, m_channel, m_defaultValue, m_props, KoProperties::setProperty(), and value().

◆ slotKeyChanged

void KisAnimatedOpacityProperty::slotKeyChanged ( const KisKeyframeChannel * ,
int time )
slot

Definition at line 103 of file KisAnimatedOpacityProperty.cpp.

103 {
104
105 if (m_channel->isCurrentTimeAffectedBy(time)) {
106 Q_EMIT changed(m_channel->currentValue() * 255 / 100);
107 }
108}

References changed(), and m_channel.

◆ slotKeyRemoval

void KisAnimatedOpacityProperty::slotKeyRemoval ( const KisKeyframeChannel * ,
int  )
slot

Definition at line 110 of file KisAnimatedOpacityProperty.cpp.

111{
112 //Key removed is the last one, we should let everyone know that we'll be
113 //reverting to the previous opacity value.
114 //This will either be the last keyframe value or the last cached value assignment.
115 if (m_channel && m_channel->keyframeCount() == 0) {
116 Q_EMIT changed(m_props->intProperty("opacity", 255));
117 } else {
118 Q_EMIT changed(m_channel->currentValue() * 255 / 100);
119 }
120}

References changed(), KoProperties::intProperty(), m_channel, and m_props.

◆ transferKeyframeData()

void KisAnimatedOpacityProperty::transferKeyframeData ( const KisAnimatedOpacityProperty & rhs)

Definition at line 84 of file KisAnimatedOpacityProperty.cpp.

84 {
88 KIS_ASSERT(channelNew);
89 m_channel.reset(channelNew);
90 m_channel->setDefaultBounds(m_bounds);
91
92 connect(m_channel.data(), SIGNAL(sigKeyframeChanged(const KisKeyframeChannel*,int)), this, SLOT(slotKeyChanged(const KisKeyframeChannel*,int)));
93 connect(m_channel.data(), SIGNAL(sigKeyframeHasBeenRemoved(const KisKeyframeChannel*,int)), this, SLOT(slotKeyRemoval(const KisKeyframeChannel*,int)));
94}
KisScalarKeyframeChannel * channel() const
#define KIS_ASSERT_RECOVER(cond)
Definition kis_assert.h:55

References channel(), connect(), KIS_ASSERT, KIS_ASSERT_RECOVER, m_bounds, m_channel, slotKeyChanged(), and slotKeyRemoval().

◆ updateDefaultBounds()

void KisAnimatedOpacityProperty::updateDefaultBounds ( KisDefaultBoundsBaseSP bounds)

Definition at line 96 of file KisAnimatedOpacityProperty.cpp.

96 {
98 if (m_channel) {
99 m_channel->setDefaultBounds(m_bounds);
100 }
101}

References bounds, m_bounds, and m_channel.

Member Data Documentation

◆ m_bounds

KisDefaultBoundsBaseSP KisAnimatedOpacityProperty::m_bounds
private

Definition at line 45 of file KisAnimatedOpacityProperty.h.

◆ m_channel

QScopedPointer<KisScalarKeyframeChannel> KisAnimatedOpacityProperty::m_channel
private

Definition at line 47 of file KisAnimatedOpacityProperty.h.

◆ m_defaultValue

quint8 KisAnimatedOpacityProperty::m_defaultValue
private

Definition at line 48 of file KisAnimatedOpacityProperty.h.

◆ m_props

KoProperties* const KisAnimatedOpacityProperty::m_props
private

Definition at line 46 of file KisAnimatedOpacityProperty.h.


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