]> git.sesse.net Git - kdenlive/blobdiff - src/geometrywidget.cpp
* Fix wrong resizing in composite transition when using "Fit to width / height"
[kdenlive] / src / geometrywidget.cpp
index b3479c6c734c52f09748cb599cafa1333a6b7f9e..6e3850758d6191c46fd2ebc18a7a2c87f09315b0 100644 (file)
@@ -50,6 +50,7 @@ GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos,
     m_showScene(true)
 {
     m_ui.setupUi(this);
+    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
     MonitorEditWidget *edit = monitor->getEffectEdit();
     edit->showVisibilityButton(true);
     m_scene = edit->getScene();
@@ -87,28 +88,28 @@ GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos,
     connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
     connect(m_ui.buttonSync,      SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
 
-    m_spinX = new DragValue(i18n("X"), 0, -1, QString(), false, this);
+    m_spinX = new DragValue(i18n("X"), 0, 0, -1, QString(), false, this);
     m_spinX->setRange(-10000, 10000);
     m_ui.horizontalLayout->addWidget(m_spinX);
     
-    m_spinY = new DragValue(i18n("Y"), 0, -1, QString(), false, this);
+    m_spinY = new DragValue(i18n("Y"), 0, 0, -1, QString(), false, this);
     m_spinY->setRange(-10000, 10000);
     m_ui.horizontalLayout->addWidget(m_spinY);
     
-    m_spinWidth = new DragValue(i18n("W"), m_monitor->render->frameRenderWidth(), -1, QString(), false, this);
+    m_spinWidth = new DragValue(i18n("W"), m_monitor->render->frameRenderWidth(), 0, -1, QString(), false, this);
     m_spinWidth->setRange(1, 10000);
     m_ui.horizontalLayout->addWidget(m_spinWidth);
     
-    m_spinHeight = new DragValue(i18n("H"), m_monitor->render->renderHeight(), -1, QString(), false, this);
+    m_spinHeight = new DragValue(i18n("H"), m_monitor->render->renderHeight(), 0, -1, QString(), false, this);
     m_spinHeight->setRange(1, 10000);
     m_ui.horizontalLayout->addWidget(m_spinHeight);
     m_ui.horizontalLayout->addStretch(10);
     
-    m_spinSize = new DragValue(i18n("Size"), 100, -1, i18n("%"), false, this);
+    m_spinSize = new DragValue(i18n("Size"), 100, 2, -1, i18n("%"), false, this);
     m_spinSize->setRange(1, 10000);
     m_ui.horizontalLayout2->addWidget(m_spinSize);
     
-    m_opacity = new DragValue(i18n("Opacity"), 100, -1, i18n("%"), true, this);
+    m_opacity = new DragValue(i18n("Opacity"), 100, 0, -1, i18n("%"), true, this);
     m_ui.horizontalLayout2->addWidget(m_opacity);
     
     /*
@@ -120,7 +121,7 @@ GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos,
     connect(m_spinWidth,        SIGNAL(valueChanged(int)), this, SLOT(slotSetWidth(int)));
     connect(m_spinHeight,       SIGNAL(valueChanged(int)), this, SLOT(slotSetHeight(int)));
 
-    connect(m_spinSize,         SIGNAL(valueChanged(int)), this, SLOT(slotResize(int)));
+    connect(m_spinSize,         SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
 
     connect(m_opacity, SIGNAL(valueChanged(int)), this, SLOT(slotSetOpacity(int)));
     
@@ -247,8 +248,7 @@ void GeometryWidget::slotSyncPosition(int relTimelinePos)
 {
     // do only sync if this effect is keyframable
     if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
-        relTimelinePos = qMax(0, relTimelinePos);
-        relTimelinePos = qMin(relTimelinePos, m_timePos->maximum());
+        relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
         if (relTimelinePos != m_timePos->getValue())
             slotPositionChanged(relTimelinePos, false);
     }
@@ -417,11 +417,11 @@ void GeometryWidget::slotUpdateProperties()
 {
     QRectF rectSize = m_rect->rect().normalized();
     QPointF rectPos = m_rect->pos();
-    int size;
-    if (rectSize.width() / m_monitor->render->dar() < rectSize.height())
-        size = (int)((rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth()) + 0.5);
+    double size;
+    if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
+        size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
     else
-        size = (int)((rectSize.height() * 100.0 / m_monitor->render->renderHeight()) + 0.5);
+        size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
 
     m_spinX->blockSignals(true);
     m_spinY->blockSignals(true);
@@ -468,7 +468,7 @@ void GeometryWidget::slotSetHeight(int value)
 }
 
 
-void GeometryWidget::slotResize(int value)
+void GeometryWidget::slotResize(double value)
 {
     m_rect->setRect(0, 0,
                     (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
@@ -550,22 +550,24 @@ void GeometryWidget::setFrameSize(QPoint size)
 void GeometryWidget::slotAdjustToFrameSize()
 {
     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
-    m_spinWidth->setValue(m_frameSize.x());
+    m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
     m_spinHeight->setValue(m_frameSize.y());
 }
 
 void GeometryWidget::slotFitToWidth()
 {
     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
-    double factor = 100.0 * m_monitor->render->frameRenderWidth() / m_frameSize.x() + 0.5;
-    m_spinSize->setValue(factor);
+    double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
+    m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
+    m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
 }
 
 void GeometryWidget::slotFitToHeight()
 {
     if (m_frameSize == QPoint()) m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
-    double factor = 100.0 * m_monitor->render->renderHeight() / m_frameSize.y() + 0.5;
-    m_spinSize->setValue(factor);
+    double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
+    m_spinHeight->setValue(m_monitor->render->renderHeight());
+    m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
 }
 
 #include "geometrywidget.moc"