|
From: Jean-Baptiste M. <nu...@kd...> - 2017-03-22 10:58:37
|
Git commit 243dff060b4b94878d6b3231d61cee1ea0dc4b12 by Jean-Baptiste Mardelle. Committed on 22/03/2017 at 10:57. Pushed by mardelle into branch 'Applications/17.04'. Add option to lock aspect ratio in geometry effects/transitions M +53 -16 data/kdenlivemonitoreffectscene.qml M +110 -23 src/effectstack/widgets/animationwidget.cpp M +5 -0 src/effectstack/widgets/animationwidget.h M +97 -23 src/effectstack/widgets/geometrywidget.cpp M +5 -1 src/effectstack/widgets/geometrywidget.h M +6 -0 src/kdenlivesettings.kcfg M +9 -0 src/monitor/monitor.cpp M +2 -0 src/monitor/monitor.h https://commits.kde.org/kdenlive/243dff060b4b94878d6b3231d61cee1ea0dc4b12 diff --git a/data/kdenlivemonitoreffectscene.qml b/data/kdenlivemonitoreffectscene.qml index d9350f913..126e66d7a 100644 --- a/data/kdenlivemonitoreffectscene.qml +++ b/data/kdenlivemonitoreffectscene.qml @@ -16,6 +16,7 @@ Item { property double scaley property double offsetx : 0 property double offsety : 0 + property double lockratio : -1 onScalexChanged: canvas.requestPaint() onScaleyChanged: canvas.requestPaint() onOffsetxChanged: canvas.requestPaint() @@ -224,7 +225,7 @@ Item { color: "transparent" border.color: "#ffff0000" Rectangle { - id: "tlhandle" + id: tlhandle anchors { top: parent.top left: parent.left @@ -249,10 +250,20 @@ Item { } onPositionChanged: { if (pressed) { - framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex; - framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex; - framesize.y = (framerect.y + (mouseY - oldMouseY) - frame.y) / root.scaley; - framesize.height = (framerect.height - (mouseY - oldMouseY)) / root.scaley; + if (root.lockratio > 0) { + var delta = Math.max(mouseX - oldMouseX, mouseY - oldMouseY) + var newwidth = framerect.width - delta + var newheight = newwidth / root.lockratio + framesize.x = (framerect.x + (framerect.width - newwidth) - frame.x) / root.scalex; + framesize.width = newwidth / root.scalex; + framesize.y = (framerect.y + (framerect.height - newheight) - frame.y) / root.scaley; + framesize.height = newheight / root.scaley; + } else { + framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex; + framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex; + framesize.y = (framerect.y + (mouseY - oldMouseY) - frame.y) / root.scaley; + framesize.height = (framerect.height - (mouseY - oldMouseY)) / root.scaley; + } root.effectChanged() } } @@ -273,7 +284,7 @@ Item { } } Rectangle { - id: "trhandle" + id: trhandle anchors { top: parent.top right: parent.right @@ -298,9 +309,18 @@ Item { } onPositionChanged: { if (pressed) { - framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex; - framesize.y = (framerect.y + (mouseY - oldMouseY) - frame.y) / root.scaley; - framesize.height = (framerect.height - (mouseY - oldMouseY)) / root.scaley; + if (root.lockratio > 0) { + var delta = Math.max(oldMouseX - mouseX, mouseY - oldMouseY) + var newheight = framerect.height - delta + var newwidth = newheight * root.lockratio + framesize.y = (framerect.y + (framerect.height - newheight) - frame.y) / root.scaley; + framesize.width = newwidth / root.scalex; + framesize.height = newheight / root.scaley; + } else { + framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex; + framesize.y = (framerect.y + (mouseY - oldMouseY) - frame.y) / root.scaley; + framesize.height = (framerect.height - (mouseY - oldMouseY)) / root.scaley; + } root.effectChanged() } } @@ -310,7 +330,7 @@ Item { } } Rectangle { - id: "blhandle" + id: blhandle anchors { bottom: parent.bottom left: parent.left @@ -335,9 +355,18 @@ Item { } onPositionChanged: { if (pressed) { - framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex; - framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex; - framesize.height = (framerect.height + (mouseY - oldMouseY)) / root.scaley; + if (root.lockratio > 0) { + var delta = Math.max(mouseX - oldMouseX, oldMouseY - mouseY) + var newwidth = framerect.width - delta + var newheight = newwidth / root.lockratio + framesize.x = (framerect.x + (framerect.width - newwidth) - frame.x) / root.scalex; + framesize.width = newwidth / root.scalex; + framesize.height = newheight / root.scaley; + } else { + framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex; + framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex; + framesize.height = (framerect.height + (mouseY - oldMouseY)) / root.scaley; + } root.effectChanged() } } @@ -347,7 +376,7 @@ Item { } } Rectangle { - id: "brhandle" + id: brhandle anchors { bottom: parent.bottom right: parent.right @@ -372,8 +401,16 @@ Item { } onPositionChanged: { if (pressed) { - framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex; - framesize.height = (framerect.height + (mouseY - oldMouseY)) / root.scaley; + if (root.lockratio > 0) { + var delta = Math.max(oldMouseX - mouseX, oldMouseY - mouseY) + var newwidth = framerect.width - delta + var newheight = newwidth / root.lockratio + framesize.width = newwidth / root.scalex; + framesize.height = newheight / root.scaley; + } else { + framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex; + framesize.height = (framerect.height + (mouseY - oldMouseY)) / root.scaley; + } root.effectChanged() } } diff --git a/src/effectstack/widgets/animationwidget.cpp b/src/effectstack/widgets/animationwidget.cpp index 17006011b..d182ebecf 100644 --- a/src/effectstack/widgets/animationwidget.cpp +++ b/src/effectstack/widgets/animationwidget.cpp @@ -90,6 +90,10 @@ AnimationWidget::AnimationWidget(EffectMetaInfo *info, int clipPos, int min, int connect(m_ruler, &AnimKeyframeRuler::moveKeyframe, this, &AnimationWidget::moveKeyframe); connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotPositionChanged())); + if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { + m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); + } + // seek to previous m_previous = tb->addAction(KoIconUtils::themedIcon(QStringLiteral("media-skip-backward")), i18n("Previous keyframe"), this, SLOT(slotPrevious())); @@ -591,8 +595,22 @@ void AnimationWidget::updateRect(int pos) m_spinY->setValue(rect.y); m_spinWidth->setValue(rect.w); m_spinHeight->setValue(rect.h); - double scale = qMin(rect.w / m_monitor->render->frameRenderWidth(), rect.h / m_monitor->render->renderHeight()); - m_spinSize->setValue(100.0 * scale); + double size; + if (rect.w / m_monitor->render->dar() > rect.h) { + if (m_originalSize->isChecked()) { + size = rect.w * 100.0 / m_frameSize.x(); + } else { + size = rect.w * 100.0 / m_monitor->render->frameRenderWidth(); + } + } else { + if (m_originalSize->isChecked()) { + size = rect.h * 100.0 / m_frameSize.y(); + } else { + size = rect.h * 100.0 / m_monitor->render->renderHeight(); + } + } + + m_spinSize->setValue(size); if (m_spinOpacity) { m_spinOpacity->blockSignals(true); m_spinOpacity->setValue(100.0 * rect.o); @@ -772,11 +790,20 @@ void AnimationWidget::buildRectWidget(const QString ¶mTag, const QDomElement horLayout->addWidget(m_spinY); m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this); - connect(m_spinWidth, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectKeyframeValue); + connect(m_spinWidth, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectWidth); horLayout->addWidget(m_spinWidth); + // Lock ratio stuff + QAction *lockRatio = new QAction(KoIconUtils::themedIcon(QStringLiteral("link")), i18n("Lock aspect ratio"), this); + lockRatio->setCheckable(true); + lockRatio->setChecked(KdenliveSettings::lock_ratio()); + connect(lockRatio, &QAction::triggered, this, &AnimationWidget::slotLockRatio); + QToolButton *ratioButton = new QToolButton; + ratioButton->setDefaultAction(lockRatio); + horLayout->addWidget(ratioButton); + m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this); - connect(m_spinHeight, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectKeyframeValue); + connect(m_spinHeight, &DragValue::valueChanged, this, &AnimationWidget::slotAdjustRectHeight); horLayout->addWidget(m_spinHeight); horLayout->addStretch(10); @@ -792,8 +819,9 @@ void AnimationWidget::buildRectWidget(const QString ¶mTag, const QDomElement } // Build buttons - QAction *originalSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-original")), i18n("Adjust to original size"), this); - connect(originalSize, &QAction::triggered, this, &AnimationWidget::slotAdjustToSource); + m_originalSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-original")), i18n("Adjust to original size"), this); + connect(m_originalSize, &QAction::triggered, this, &AnimationWidget::slotAdjustToSource); + m_originalSize->setCheckable(true); QAction *adjustSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-fit-best")), i18n("Adjust and center in frame"), this); connect(adjustSize, &QAction::triggered, this, &AnimationWidget::slotAdjustToFrameSize); QAction *fitToWidth = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-fit-width")), i18n("Fit to width"), this); @@ -847,7 +875,7 @@ void AnimationWidget::buildRectWidget(const QString ¶mTag, const QDomElement alignLayout->addWidget(alignButton); alignButton = new QToolButton; - alignButton->setDefaultAction(originalSize); + alignButton->setDefaultAction(m_originalSize); alignButton->setAutoRaise(true); alignLayout->addWidget(alignButton); @@ -932,9 +960,23 @@ void AnimationWidget::slotAdjustRectKeyframeValue() rect.w = m_spinWidth->value(); rect.h = m_spinHeight->value(); rect.o = m_spinOpacity ? m_spinOpacity->value() / 100.0 : 1; - double scale = qMin(m_spinWidth->value() / m_monitor->render->frameRenderWidth(), m_spinHeight->value() / m_monitor->render->renderHeight()); + + double size; + if (m_spinWidth->value() / m_monitor->render->dar() > m_spinHeight->value()) { + if (m_originalSize->isChecked()) { + size = m_spinWidth->value() * 100.0 / m_frameSize.x(); + } else { + size = m_spinWidth->value() * 100.0 / m_monitor->render->frameRenderWidth(); + } + } else { + if (m_originalSize->isChecked()) { + size = m_spinHeight->value() * 100.0 / m_frameSize.y(); + } else { + size = m_spinHeight->value() * 100.0 / m_monitor->render->renderHeight(); + } + } m_spinSize->blockSignals(true); - m_spinSize->setValue(100.0 * scale); + m_spinSize->setValue(size); m_spinSize->blockSignals(false); if (m_animController.is_key(pos)) { // This is a keyframe @@ -955,8 +997,10 @@ void AnimationWidget::slotResize(double value) { m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); - m_spinWidth->setValue(m_monitor->render->frameRenderWidth() * value / 100.0); - m_spinHeight->setValue(m_monitor->render->renderHeight() * value / 100.0); + int w = m_originalSize->isChecked() ? m_frameSize.x() : m_monitor->render->frameRenderWidth(); + int h = m_originalSize->isChecked() ? m_frameSize.y() : m_monitor->render->renderHeight(); + m_spinWidth->setValue(w * value / 100.0); + m_spinHeight->setValue(h * value / 100.0); m_spinWidth->blockSignals(false); m_spinHeight->blockSignals(false); slotAdjustRectKeyframeValue(); @@ -1259,6 +1303,19 @@ void AnimationWidget::connectMonitor(bool activate) connect(m_monitor, SIGNAL(deleteKeyframe()), this, SLOT(slotDeleteKeyframe()), Qt::UniqueConnection); int framePos = qBound<int>(0, m_monitor->render->seekFramePosition() - m_clipPos, m_timePos->maximum()); slotPositionChanged(framePos, false); + double ratio = (double)m_spinWidth->value() / m_spinHeight->value(); + if (m_frameSize.x() != m_monitor->render->frameRenderWidth() || m_frameSize.y() != m_monitor->render->renderHeight()) { + // Source frame size different than project frame size, enable original size option accordingly + bool isOriginalSize = qAbs((double)m_frameSize.x()/m_frameSize.y() - ratio) < qAbs((double)m_monitor->render->frameRenderWidth()/m_monitor->render->renderHeight() - ratio); + if (isOriginalSize) { + m_originalSize->blockSignals(true); + m_originalSize->setChecked(true); + m_originalSize->blockSignals(false); + } + } + if (KdenliveSettings::lock_ratio()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } } else { disconnect(m_monitor, &Monitor::effectChanged, this, &AnimationWidget::slotUpdateGeometryRect); disconnect(m_monitor, &Monitor::effectPointsChanged, this, &AnimationWidget::slotUpdateCenters); @@ -1383,9 +1440,6 @@ QString AnimationWidget::defaultValue(const QString ¶mName) void AnimationWidget::slotAdjustToSource() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); m_spinWidth->setValue((int)(m_frameSize.x() / m_monitor->render->sar() + 0.5), false); @@ -1393,13 +1447,13 @@ void AnimationWidget::slotAdjustToSource() m_spinWidth->blockSignals(false); m_spinHeight->blockSignals(false); slotAdjustRectKeyframeValue(); + if (KdenliveSettings::lock_ratio()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } } void AnimationWidget::slotAdjustToFrameSize() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double monitorDar = m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight(); double sourceDar = m_frameSize.x() / m_frameSize.y(); m_spinWidth->blockSignals(true); @@ -1430,9 +1484,6 @@ void AnimationWidget::slotAdjustToFrameSize() void AnimationWidget::slotFitToWidth() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar(); m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); @@ -1445,9 +1496,6 @@ void AnimationWidget::slotFitToWidth() void AnimationWidget::slotFitToHeight() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y(); m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); @@ -1510,3 +1558,42 @@ void AnimationWidget::slotImportKeyframes() QString values = clipboard->text(); emit setKeyframes(values); } + +void AnimationWidget::slotLockRatio() +{ + QAction *lockRatio = qobject_cast<QAction*> (QObject::sender()); + KdenliveSettings::setLock_ratio(lockRatio->isChecked()); + if (lockRatio->isChecked()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } else { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), -1); + } +} + +void AnimationWidget::slotAdjustRectWidth() +{ + if (KdenliveSettings::lock_ratio()) { + m_spinHeight->blockSignals(true); + if (m_originalSize->isChecked()) { + m_spinHeight->setValue((int) (m_spinWidth->value() * m_frameSize.y() / m_frameSize.x() + 0.5)); + } else { + m_spinHeight->setValue((int) (m_spinWidth->value() * m_monitor->render->renderHeight() / m_monitor->render->frameRenderWidth() + 0.5)); + } + m_spinHeight->blockSignals(false); + } + slotAdjustRectKeyframeValue(); +} + +void AnimationWidget::slotAdjustRectHeight() +{ + if (KdenliveSettings::lock_ratio()) { + m_spinWidth->blockSignals(true); + if (m_originalSize->isChecked()) { + m_spinWidth->setValue((int) (m_spinHeight->value() * m_frameSize.x() / m_frameSize.y() + 0.5)); + } else { + m_spinWidth->setValue((int) (m_spinHeight->value() * m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight() + 0.5)); + } + m_spinWidth->blockSignals(false); + } + slotAdjustRectKeyframeValue(); +} diff --git a/src/effectstack/widgets/animationwidget.h b/src/effectstack/widgets/animationwidget.h index bf77c49ea..68029f1f7 100644 --- a/src/effectstack/widgets/animationwidget.h +++ b/src/effectstack/widgets/animationwidget.h @@ -96,6 +96,7 @@ private: DragValue *m_spinHeight; DragValue *m_spinSize; DragValue *m_spinOpacity; + QAction *m_originalSize; int m_offset; void parseKeyframes(); void rebuildKeyframes(); @@ -160,6 +161,10 @@ private slots: void slotCenterV(); /** @brief Moves the rect to the bottom frame border (y position = frame height - rect height). */ void slotMoveBottom(); + /** @brief Un/Lock aspect ratio for size in effect parameter. */ + void slotLockRatio(); + void slotAdjustRectHeight(); + void slotAdjustRectWidth(); signals: void seekToPos(int); diff --git a/src/effectstack/widgets/geometrywidget.cpp b/src/effectstack/widgets/geometrywidget.cpp index 834d5e1cd..422de7901 100644 --- a/src/effectstack/widgets/geometrywidget.cpp +++ b/src/effectstack/widgets/geometrywidget.cpp @@ -55,7 +55,10 @@ GeometryWidget::GeometryWidget(EffectMetaInfo *info, int clipPos, bool showRotat /* Setup of timeline and keyframe controls */ - + if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { + m_originalSize->setEnabled(false); + m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); + } ((QGridLayout *)(m_ui.widgetTimeWrapper->layout()))->addWidget(m_timePos, 1, 5); QVBoxLayout *layout = new QVBoxLayout(m_ui.frameTimeline); @@ -94,14 +97,24 @@ GeometryWidget::GeometryWidget(EffectMetaInfo *info, int clipPos, bool showRotat m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this); m_ui.horizontalLayout->addWidget(m_spinWidth, 0, 2); + // Lock ratio stuff + QAction *lockRatio = new QAction(KoIconUtils::themedIcon(QStringLiteral("link")), i18n("Lock aspect ratio"), this); + lockRatio->setCheckable(true); + lockRatio->setChecked(KdenliveSettings::lock_ratio()); + connect(lockRatio, &QAction::triggered, this, &GeometryWidget::slotLockRatio); + QToolButton *ratioButton = new QToolButton; + ratioButton->setDefaultAction(lockRatio); + m_ui.horizontalLayout->addWidget(ratioButton, 0, 3); + m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this); - m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 3); + m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 4); - m_ui.horizontalLayout->setColumnStretch(4, 10); + m_ui.horizontalLayout->setColumnStretch(5, 10); QMenu *menu = new QMenu(this); - QAction *originalSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-original")), i18n("Adjust to original size"), this); - connect(originalSize, &QAction::triggered, this, &GeometryWidget::slotAdjustToSource); + m_originalSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-original")), i18n("Adjust to original size"), this); + connect(m_originalSize, &QAction::triggered, this, &GeometryWidget::slotAdjustToSource); + m_originalSize->setCheckable(true); QAction *adjustSize = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-fit-best")), i18n("Adjust and center in frame"), this); connect(adjustSize, &QAction::triggered, this, &GeometryWidget::slotAdjustToFrameSize); QAction *fitToWidth = new QAction(KoIconUtils::themedIcon(QStringLiteral("zoom-fit-width")), i18n("Fit to width"), this); @@ -181,7 +194,7 @@ GeometryWidget::GeometryWidget(EffectMetaInfo *info, int clipPos, bool showRotat alignLayout->addWidget(alignButton); alignButton = new QToolButton; - alignButton->setDefaultAction(originalSize); + alignButton->setDefaultAction(m_originalSize); alignButton->setAutoRaise(true); alignLayout->addWidget(alignButton); @@ -496,6 +509,20 @@ void GeometryWidget::slotPositionChanged(int pos, bool seek) void GeometryWidget::slotInitScene(int pos) { slotPositionChanged(pos, false); + double ratio = (double)m_spinWidth->value() / m_spinHeight->value(); + if (m_frameSize.x() != m_monitor->render->frameRenderWidth() || m_frameSize.y() != m_monitor->render->renderHeight()) { + // Source frame size different than project frame size, enable original size option accordingly + bool isOriginalSize = qAbs((double)m_frameSize.x()/m_frameSize.y() - ratio) < qAbs((double)m_monitor->render->frameRenderWidth()/m_monitor->render->renderHeight() - ratio); + if (isOriginalSize) { + m_originalSize->blockSignals(true); + m_originalSize->setChecked(true); + m_originalSize->blockSignals(false); + } + } + // scene ratio lock + if (KdenliveSettings::lock_ratio()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } } void GeometryWidget::slotKeyframeMoved(int pos) @@ -744,9 +771,17 @@ void GeometryWidget::slotUpdateProperties(QRect rect) } double size; if (rect.width() / m_monitor->render->dar() > rect.height()) { - size = rect.width() * 100.0 / m_monitor->render->frameRenderWidth(); + if (m_originalSize->isChecked()) { + size = rect.width() * 100.0 / m_frameSize.x(); + } else { + size = rect.width() * 100.0 / m_monitor->render->frameRenderWidth(); + } } else { - size = rect.height() * 100.0 / m_monitor->render->renderHeight(); + if (m_originalSize->isChecked()) { + size = rect.height() * 100.0 / m_frameSize.y(); + } else { + size = rect.height() * 100.0 / m_monitor->render->renderHeight(); + } } m_spinX->blockSignals(true); @@ -797,6 +832,15 @@ void GeometryWidget::slotSetY(double value) void GeometryWidget::slotSetWidth(double value) { + if (KdenliveSettings::lock_ratio()) { + m_spinHeight->blockSignals(true); + if (m_originalSize->isChecked()) { + m_spinHeight->setValue((int) (value * m_frameSize.y() / m_frameSize.x() + 0.5)); + } else { + m_spinHeight->setValue((int) (value * m_monitor->render->renderHeight() / m_monitor->render->frameRenderWidth() + 0.5)); + } + m_spinHeight->blockSignals(false); + } m_monitor->setUpEffectGeometry(QRect(m_spinX->value(), m_spinY->value(), value, m_spinHeight->value())); slotUpdateGeometry(); m_monitor->setUpEffectGeometry(QRect(), calculateCenters()); @@ -804,6 +848,15 @@ void GeometryWidget::slotSetWidth(double value) void GeometryWidget::slotSetHeight(double value) { + if (KdenliveSettings::lock_ratio()) { + m_spinWidth->blockSignals(true); + if (m_originalSize->isChecked()) { + m_spinWidth->setValue((int) (value * m_frameSize.x() / m_frameSize.y() + 0.5)); + } else { + m_spinWidth->setValue((int) (value * m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight() + 0.5)); + } + m_spinWidth->blockSignals(false); + } m_monitor->setUpEffectGeometry(QRect(m_spinX->value(), m_spinY->value(), m_spinWidth->value(), value)); slotUpdateGeometry(); m_monitor->setUpEffectGeometry(QRect(), calculateCenters()); @@ -818,7 +871,9 @@ void GeometryWidget::updateMonitorGeometry() void GeometryWidget::slotResize(double value) { - m_monitor->setUpEffectGeometry(QRect(m_spinX->value(), m_spinY->value(), (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5), (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5))); + int w = m_originalSize->isChecked() ? m_frameSize.x() : m_monitor->render->frameRenderWidth(); + int h = m_originalSize->isChecked() ? m_frameSize.y() : m_monitor->render->renderHeight(); + m_monitor->setUpEffectGeometry(QRect(m_spinX->value(), m_spinY->value(), (int)((w * value / 100.0) + 0.5), (int)((h * value / 100.0) + 0.5))); slotUpdateGeometry(); m_monitor->setUpEffectGeometry(QRect(), calculateCenters()); } @@ -882,27 +937,42 @@ void GeometryWidget::slotSetSynchronize(bool sync) void GeometryWidget::setFrameSize(const QPoint &size) { m_frameSize = size; + if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { + m_originalSize->setEnabled(false); + m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); + } else { + m_originalSize->setEnabled(true); + } + if (KdenliveSettings::lock_ratio()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } else { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), -1); + } } void GeometryWidget::slotAdjustToSource() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); - m_spinWidth->setValue((int)(m_frameSize.x() / m_monitor->render->sar() + 0.5)); - m_spinHeight->setValue(m_frameSize.y()); + if (m_originalSize->isChecked()) { + // Adjust to source size + m_spinWidth->setValue((int)(m_frameSize.x() / m_monitor->render->sar() + 0.5)); + m_spinHeight->setValue(m_frameSize.y()); + } else { + // Adjust to profile size + m_spinWidth->setValue((int)(m_monitor->render->frameRenderWidth() / m_monitor->render->sar() + 0.5)); + m_spinHeight->setValue(m_monitor->render->renderHeight()); + } m_spinWidth->blockSignals(false); m_spinHeight->blockSignals(false); updateMonitorGeometry(); + if (KdenliveSettings::lock_ratio()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } } void GeometryWidget::slotAdjustToFrameSize() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double monitorDar = m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight(); double sourceDar = m_frameSize.x() / m_frameSize.y(); m_spinWidth->blockSignals(true); @@ -933,9 +1003,6 @@ void GeometryWidget::slotAdjustToFrameSize() void GeometryWidget::slotFitToWidth() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar(); m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); @@ -948,9 +1015,6 @@ void GeometryWidget::slotFitToWidth() void GeometryWidget::slotFitToHeight() { - if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) { - m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight()); - } double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y(); m_spinWidth->blockSignals(true); m_spinHeight->blockSignals(true); @@ -1125,3 +1189,13 @@ void GeometryWidget::slotUpdateRange(int inPoint, int outPoint) m_timePos->setRange(0, m_outPoint - m_inPoint); } +void GeometryWidget::slotLockRatio() +{ + QAction *lockRatio = qobject_cast<QAction*> (QObject::sender()); + KdenliveSettings::setLock_ratio(lockRatio->isChecked()); + if (lockRatio->isChecked()) { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight()); + } else { + m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), -1); + } +} diff --git a/src/effectstack/widgets/geometrywidget.h b/src/effectstack/widgets/geometrywidget.h index 9bec34360..b3088ca7f 100644 --- a/src/effectstack/widgets/geometrywidget.h +++ b/src/effectstack/widgets/geometrywidget.h @@ -104,6 +104,8 @@ private: DragValue *m_rotateY; DragValue *m_rotateZ; QPoint m_frameSize; + /** @brief Action switching between profile and source size. */ + QAction *m_originalSize; /** @brief True if this is a fixed parameter (no kexframes allowed). */ bool m_fixedGeom; /** @brief True if there is only one keyframe in this geometry. */ @@ -188,8 +190,10 @@ private slots: void slotShowPreviousKeyFrame(bool show); /** @brief Show / hide keyframe path in monitor scene. */ void slotShowPath(bool show); - /** @brief Eduit center points for the geometry keyframes. */ + /** @brief Edit center points for the geometry keyframes. */ void slotUpdateCenters(const QVariantList ¢ers); + /** @brief Un/Lock aspect ratio for size in effect parameter. */ + void slotLockRatio(); signals: void seekToPos(int); diff --git a/src/kdenlivesettings.kcfg b/src/kdenlivesettings.kcfg index ac98a78f9..2c29f9da5 100644 --- a/src/kdenlivesettings.kcfg +++ b/src/kdenlivesettings.kcfg @@ -948,4 +948,10 @@ <default>false</default> </entry> </group> + <group name="effects"> + <entry name="lock_ratio" type="Bool"> + <label>Lock size ratio in effects.</label> + <default>true</default> + </entry> + </group> </kcfg> diff --git a/src/monitor/monitor.cpp b/src/monitor/monitor.cpp index 8433aab35..58e5f00ac 100644 --- a/src/monitor/monitor.cpp +++ b/src/monitor/monitor.cpp @@ -1655,6 +1655,15 @@ void Monitor::setUpEffectGeometry(const QRect &r, const QVariantList &list, cons } } +void Monitor::setEffectSceneProperty(const QString &name, const QVariant &value) +{ + QQuickItem *root = m_glMonitor->rootObject(); + if (!root) { + return; + } + root->setProperty(name.toUtf8().constData(), value); +} + QRect Monitor::effectRect() const { QQuickItem *root = m_glMonitor->rootObject(); diff --git a/src/monitor/monitor.h b/src/monitor/monitor.h index a14ddb3fd..0884ac79d 100644 --- a/src/monitor/monitor.h +++ b/src/monitor/monitor.h @@ -121,6 +121,8 @@ public: int getZoneStart(); int getZoneEnd(); void setUpEffectGeometry(const QRect &r, const QVariantList &list = QVariantList(), const QVariantList &types = QVariantList()); + /** @brief Set a property on the effect scene */ + void setEffectSceneProperty(const QString &name, const QVariant &value); /** @brief Returns effective display size */ QSize profileSize() const; QRect effectRect() const; |