Commit beb7d916 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix aspect ratio not working on title images

BUG: 420676
parent 488a1d8d
......@@ -225,6 +225,9 @@ TitleWidget::TitleWidget(const QUrl &url, const Timecode &tc, QString projectTit
connect(buttonAlignCenter, &QAbstractButton::clicked, this, &TitleWidget::slotUpdateText);
connect(edit_gradient, &QAbstractButton::clicked, this, &TitleWidget::slotEditGradient);
connect(edit_rect_gradient, &QAbstractButton::clicked, this, &TitleWidget::slotEditGradient);
connect(preserveAspectRatio, static_cast<void (QCheckBox::*)(int)>(&QCheckBox::stateChanged), [&] () {
slotValueChanged(ValueWidth);
});
displayBg->setChecked(KdenliveSettings::titlerShowbg());
connect(displayBg, static_cast<void (QCheckBox::*)(int)>(&QCheckBox::stateChanged), [&] (int state) {
......@@ -1238,6 +1241,8 @@ void TitleWidget::slotValueChanged(int type)
// Scaling factor
double scale = 1;
double scalex = t.scalex;
double scaley = t.scaley;
// We want to keep the aspect ratio of the image as the user does not yet have the possibility
// to restore the original ratio. You rarely want to change it anyway.
......@@ -1245,18 +1250,23 @@ void TitleWidget::slotValueChanged(int type)
case ValueWidth:
// Add 0.5 because otherwise incrementing by 1 might have no effect
length = val / (cos(alpha) + 1 / phi * sin(alpha)) + 0.5;
scale = length / i->boundingRect().width();
scalex = length / i->boundingRect().width();
if (preserveAspectRatio->isChecked()) {
scaley = scalex;
}
break;
case ValueHeight:
length = val / (phi * sin(alpha) + cos(alpha)) + 0.5;
scale = length / i->boundingRect().height();
scaley = length / i->boundingRect().height();
if (preserveAspectRatio->isChecked()) {
scalex = scaley;
}
break;
}
t.scalex = scale;
t.scaley = scale;
t.scalex = scalex;
t.scaley = scaley;
QTransform qtrans;
qtrans.scale(scale, scale);
qtrans.scale(scalex, scaley);
qtrans.rotate(t.rotatex, Qt::XAxis);
qtrans.rotate(t.rotatey, Qt::YAxis);
qtrans.rotate(t.rotatez, Qt::ZAxis);
......@@ -2921,8 +2931,10 @@ void TitleWidget::prepareTools(QGraphicsItem *referenceItem)
updateCoordinates(referenceItem);
updateDimension(referenceItem);
enableToolbars(TITLE_IMAGE);
QSignalBlocker bk(preserveAspectRatio);
Transform t = m_transformations.value(referenceItem);
preserveAspectRatio->setChecked(t.scalex == t.scaley);
} else {
showToolbars(TITLE_SELECT);
......
......@@ -351,14 +351,14 @@
<property name="flat">
<bool>false</bool>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>255</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="defaultColor">
<property name="defaultColor" stdset="0">
<color>
<red>255</red>
<green>0</green>
......@@ -643,8 +643,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>628</width>
<height>729</height>
<width>544</width>
<height>506</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_9">
......@@ -781,7 +781,7 @@
<item row="5" column="0" colspan="7">
<widget class="QGroupBox" name="shadowBox">
<property name="title">
<string>Sh&amp;adow</string>
<string>Sha&amp;dow</string>
</property>
<property name="checkable">
<bool>true</bool>
......@@ -821,14 +821,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="color">
<property name="color" stdset="0">
<color alpha="100">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="alphaChannelEnabled">
<property name="alphaChannelEnabled" stdset="0">
<bool>true</bool>
</property>
</widget>
......@@ -982,14 +982,14 @@
<property name="flat">
<bool>false</bool>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</property>
<property name="defaultColor">
<property name="defaultColor" stdset="0">
<color>
<red>0</red>
<green>0</green>
......@@ -1047,14 +1047,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="defaultColor">
<property name="defaultColor" stdset="0">
<color>
<red>0</red>
<green>0</green>
......@@ -1112,14 +1112,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="defaultColor">
<property name="defaultColor" stdset="0">
<color>
<red>0</red>
<green>0</green>
......@@ -1162,7 +1162,7 @@
<item row="0" column="0">
<widget class="QCheckBox" name="preserveAspectRatio">
<property name="enabled">
<bool>false</bool>
<bool>true</bool>
</property>
<property name="text">
<string>Preserve aspect ratio</string>
......@@ -1231,14 +1231,14 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="color">
<property name="color" stdset="0">
<color>
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</property>
<property name="defaultColor">
<property name="defaultColor" stdset="0">
<color>
<red>0</red>
<green>0</green>
......
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