这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions app/src/layeropacitydialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void LayerOpacityDialog::updateUI()
canAdjust = true;
}

updateSelectedFramesUI();

ui->chooseOpacitySlider->setEnabled(canAdjust);
ui->chooseOpacitySpinBox->setEnabled(canAdjust);
}
Expand Down Expand Up @@ -148,42 +150,61 @@ void LayerOpacityDialog::fade(OpacityFadeType fadeType)

if (selectedKeys.count() < mMinSelectedFrames) { return; }

// OUT
int fadeFromPos = selectedKeys.first();
int fadeStart = 1;
int fadeEnd = selectedKeys.count();

if (fadeType == OpacityFadeType::IN) {
fadeFromPos = selectedKeys.last();
fadeStart = 0;
fadeEnd = selectedKeys.count() - 1;
}

KeyFrame* keyframe = currentLayer->getLastKeyFrameAtPosition(fadeFromPos);
if (keyframe == nullptr) { return; }

qreal initialOpacity = getOpacityForKeyFrame(currentLayer, keyframe);

qreal imageCount = static_cast<qreal>(selectedKeys.count());
for (int i = fadeStart; i < fadeEnd; i++)
{
qreal imageCount = static_cast<qreal>(selectedKeys.count() - 1);

qreal opacityStepper = 0.0;
switch (fadeType) {
case OpacityFadeType::IN:
{
// When the opacity is 100% act as we're doing a full fade in from 0-100%
if (initialOpacity >= 1.0) {
initialOpacity = 0.0;
}
opacityStepper = (1.0 - initialOpacity) / imageCount;
break;
}
case OpacityFadeType::OUT:
{
// When the opacity is 0%, act as we're doing a full fade out from 100-0%
if (initialOpacity <= 0) {
initialOpacity = 1.0;
}
opacityStepper = initialOpacity / imageCount;
break;
}
}

for (int i = 0; i < selectedKeys.count(); i++) {
keyframe = currentLayer->getLastKeyFrameAtPosition(selectedKeys.at(i));
if (keyframe == nullptr) { continue; }

qreal newOpacity = 0;
if (fadeType == OpacityFadeType::IN) {
newOpacity = static_cast<qreal>((i + 1) / imageCount) * initialOpacity;
} else {
newOpacity = static_cast<qreal>(initialOpacity - (i / imageCount) * initialOpacity);
switch (fadeType)
{
case OpacityFadeType::IN: {
newOpacity = initialOpacity + (i * opacityStepper);
break;
}
case OpacityFadeType::OUT: {
newOpacity = initialOpacity - (i * opacityStepper);
break;
}
}
setOpacityForKeyFrame(currentLayer, keyframe, newOpacity);
}

keyframe = currentLayer->getLastKeyFrameAtPosition(mEditor->currentFrame());
if (keyframe == nullptr) { return; }

qreal imageOpacity = getOpacityForKeyFrame(currentLayer, keyframe);
updateValues(imageOpacity);
if (keyframe) {
qreal imageOpacity = getOpacityForKeyFrame(currentLayer, keyframe);
updateValues(imageOpacity);
}

emit mEditor->framesModified();
}
Expand Down Expand Up @@ -224,14 +245,20 @@ void LayerOpacityDialog::onCurrentFrameChanged(int frame)
}

void LayerOpacityDialog::onSelectedFramesChanged()
{
updateUI();
}

void LayerOpacityDialog::updateSelectedFramesUI()
{
Layer* currentLayer = mLayerManager->currentLayer();
if (currentLayer == nullptr) { return; }

QList<int> frames = currentLayer->getSelectedFramesByPos();

ui->groupBoxFade->setEnabled(frames.count() >= mMinSelectedFrames);
updateUI();
int minSelectedFrames = frames.count() >= mMinSelectedFrames;
ui->groupBoxFade->setEnabled(minSelectedFrames);
ui->rbSelectedKeyframes->setEnabled(minSelectedFrames);
}

void LayerOpacityDialog::onPlayStateChanged(bool isPlaying)
Expand Down
2 changes: 2 additions & 0 deletions app/src/layeropacitydialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private slots:
void setOpacityForSelectedKeyframes();
void setOpacityForLayer();

void updateSelectedFramesUI();

Ui::LayerOpacityDialog *ui;

Editor* mEditor = nullptr;
Expand Down
1 change: 1 addition & 0 deletions app/src/timelinecells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@ void TimeLineCells::mouseMoveEvent(QMouseEvent* event)
currentLayer->deselectAll();
currentLayer->setFrameSelected(mStartFrameNumber, true);
currentLayer->extendSelectionTo(mFramePosMoveX);
emit mEditor->selectedFramesChanged();
}
mLastFrameNumber = mFramePosMoveX;
updateContent();
Expand Down
9 changes: 9 additions & 0 deletions app/ui/layeropacitydialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<property name="text">
<string>Fade in</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand All @@ -134,6 +137,9 @@
<property name="text">
<string>Fade out</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
Expand All @@ -159,6 +165,9 @@
<property name="text">
<string>Close</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
Expand Down