More clever ratio locking in effect/transition

parent b279de93
......@@ -255,9 +255,9 @@ Item {
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.width = Math.round(newwidth / root.scalex);
framesize.y = (framerect.y + (framerect.height - newheight) - frame.y) / root.scaley;
framesize.height = newheight / root.scaley;
framesize.height = Math.round(framesize.width / root.lockratio)
} else {
framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex;
framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex;
......@@ -314,8 +314,8 @@ Item {
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;
framesize.width = Math.round(newwidth / root.scalex);
framesize.height = Math.round(framesize.width / root.lockratio)
} else {
framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex;
framesize.y = (framerect.y + (mouseY - oldMouseY) - frame.y) / root.scaley;
......@@ -358,10 +358,9 @@ Item {
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;
framesize.width = Math.round(newwidth / root.scalex);
framesize.height = Math.round(framesize.width / root.lockratio)
} else {
framesize.x = (framerect.x + (mouseX - oldMouseX) - frame.x) / root.scalex;
framesize.width = (framerect.width - (mouseX - oldMouseX)) / root.scalex;
......@@ -404,9 +403,8 @@ Item {
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;
framesize.width = Math.round(newwidth / root.scalex);
framesize.height = Math.round(framesize.width / root.lockratio)
} else {
framesize.width = (framerect.width + (mouseX - oldMouseX)) / root.scalex;
framesize.height = (framerect.height + (mouseY - oldMouseY)) / root.scaley;
......
......@@ -509,6 +509,18 @@ void AnimationWidget::slotPositionChanged(int pos, bool seek)
updateSlider(pos - m_offset);
m_previous->setEnabled(pos > 0);
m_next->setEnabled(pos < (m_outPoint - m_inPoint - 1));
// scene ratio lock
if (m_spinWidth && m_spinWidth->isEnabled()) {
double ratio = m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight();
bool lockRatio = m_spinHeight->value() == (int) (m_spinWidth->value() / ratio + 0.5);
qDebug()<<"CALCULATED: "<<m_spinHeight->value()<<" = "<<(int) (m_spinWidth->value() / ratio + 0.5);
m_lockRatio->blockSignals(true);
m_lockRatio->setChecked(lockRatio);
m_lockRatio->blockSignals(false);
m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_lockRatio->isChecked() ? ratio : -1);
}
if (seek) {
emit seekToPos(pos);
}
......@@ -794,12 +806,11 @@ void AnimationWidget::buildRectWidget(const QString &paramTag, const QDomElement
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);
m_lockRatio = new QAction(KoIconUtils::themedIcon(QStringLiteral("link")), i18n("Lock aspect ratio"), this);
m_lockRatio->setCheckable(true);
connect(m_lockRatio, &QAction::triggered, this, &AnimationWidget::slotLockRatio);
QToolButton *ratioButton = new QToolButton;
ratioButton->setDefaultAction(lockRatio);
ratioButton->setDefaultAction(m_lockRatio);
horLayout->addWidget(ratioButton);
m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this);
......@@ -1313,9 +1324,6 @@ void AnimationWidget::connectMonitor(bool activate)
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);
......@@ -1447,7 +1455,7 @@ void AnimationWidget::slotAdjustToSource()
m_spinWidth->blockSignals(false);
m_spinHeight->blockSignals(false);
slotAdjustRectKeyframeValue();
if (KdenliveSettings::lock_ratio()) {
if (m_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());
}
}
......@@ -1562,7 +1570,6 @@ void AnimationWidget::slotImportKeyframes()
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 {
......@@ -1572,7 +1579,7 @@ void AnimationWidget::slotLockRatio()
void AnimationWidget::slotAdjustRectWidth()
{
if (KdenliveSettings::lock_ratio()) {
if (m_lockRatio->isChecked()) {
m_spinHeight->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinHeight->setValue((int) (m_spinWidth->value() * m_frameSize.y() / m_frameSize.x() + 0.5));
......@@ -1586,7 +1593,7 @@ void AnimationWidget::slotAdjustRectWidth()
void AnimationWidget::slotAdjustRectHeight()
{
if (KdenliveSettings::lock_ratio()) {
if (m_lockRatio->isChecked()) {
m_spinWidth->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinWidth->setValue((int) (m_spinHeight->value() * m_frameSize.x() / m_frameSize.y() + 0.5));
......
......@@ -97,6 +97,7 @@ private:
DragValue *m_spinSize;
DragValue *m_spinOpacity;
QAction *m_originalSize;
QAction *m_lockRatio;
int m_offset;
void parseKeyframes();
void rebuildKeyframes();
......
......@@ -98,12 +98,11 @@ GeometryWidget::GeometryWidget(EffectMetaInfo *info, int clipPos, bool showRotat
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);
m_lockRatio = new QAction(KoIconUtils::themedIcon(QStringLiteral("link")), i18n("Lock aspect ratio"), this);
m_lockRatio->setCheckable(true);
connect(m_lockRatio, &QAction::triggered, this, &GeometryWidget::slotLockRatio);
QToolButton *ratioButton = new QToolButton;
ratioButton->setDefaultAction(lockRatio);
ratioButton->setDefaultAction(m_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);
......@@ -501,6 +500,17 @@ void GeometryWidget::slotPositionChanged(int pos, bool seek)
}
m_monitor->setUpEffectGeometry(r, calculateCenters());
slotUpdateProperties(r);
// scene ratio lock
if (m_ui.widgetGeometry->isEnabled()) {
double ratio = m_originalSize->isChecked() ? (double)m_frameSize.x() / m_frameSize.y() : (double)m_monitor->render->frameRenderWidth() / m_monitor->render->renderHeight();
bool lockRatio = m_spinHeight->value() == (int) (m_spinWidth->value() / ratio + 0.5);
m_lockRatio->blockSignals(true);
m_lockRatio->setChecked(lockRatio);
m_lockRatio->blockSignals(false);
m_monitor->setEffectSceneProperty(QStringLiteral("lockratio"), m_lockRatio->isChecked() ? ratio : -1);
}
if (seek && KdenliveSettings::transitionfollowcursor()) {
emit seekToPos(pos);
}
......@@ -519,16 +529,13 @@ void GeometryWidget::slotInitScene(int pos)
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)
{
slotPositionChanged(pos);
slotUpdateGeometry();
QTimer::singleShot(100, this, &GeometryWidget::valueChanged);
}
......@@ -832,7 +839,7 @@ void GeometryWidget::slotSetY(double value)
void GeometryWidget::slotSetWidth(double value)
{
if (KdenliveSettings::lock_ratio()) {
if (m_lockRatio->isChecked()) {
m_spinHeight->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinHeight->setValue((int) (value * m_frameSize.y() / m_frameSize.x() + 0.5));
......@@ -848,7 +855,7 @@ void GeometryWidget::slotSetWidth(double value)
void GeometryWidget::slotSetHeight(double value)
{
if (KdenliveSettings::lock_ratio()) {
if (m_lockRatio->isChecked()) {
m_spinWidth->blockSignals(true);
if (m_originalSize->isChecked()) {
m_spinWidth->setValue((int) (value * m_frameSize.x() / m_frameSize.y() + 0.5));
......@@ -943,7 +950,7 @@ void GeometryWidget::setFrameSize(const QPoint &size)
} else {
m_originalSize->setEnabled(true);
}
if (KdenliveSettings::lock_ratio()) {
if (m_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);
......@@ -966,7 +973,7 @@ void GeometryWidget::slotAdjustToSource()
m_spinWidth->blockSignals(false);
m_spinHeight->blockSignals(false);
updateMonitorGeometry();
if (KdenliveSettings::lock_ratio()) {
if (m_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());
}
}
......@@ -1192,7 +1199,6 @@ void GeometryWidget::slotUpdateRange(int inPoint, int outPoint)
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 {
......
......@@ -106,6 +106,8 @@ private:
QPoint m_frameSize;
/** @brief Action switching between profile and source size. */
QAction *m_originalSize;
/** @brief Action locking image ratio. */
QAction *m_lockRatio;
/** @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. */
......
......@@ -948,10 +948,4 @@
<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>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment