]> git.sesse.net Git - kdenlive/blob - src/geometrywidget.cpp
Fix geometry widget layout
[kdenlive] / src / geometrywidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "geometrywidget.h"
22 #include "monitor.h"
23 #include "renderer.h"
24 #include "keyframehelper.h"
25 #include "timecodedisplay.h"
26 #include "monitorscene.h"
27 #include "monitoreditwidget.h"
28 #include "onmonitoritems/onmonitorrectitem.h"
29 #include "kdenlivesettings.h"
30 #include "dragvalue.h"
31
32 #include <QtCore>
33 #include <QGraphicsView>
34 #include <QVBoxLayout>
35 #include <QGridLayout>
36 #include <QMenu>
37
38
39
40 GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, bool isEffect, bool showRotation, QWidget* parent):
41     QWidget(parent),
42     m_monitor(monitor),
43     m_timePos(new TimecodeDisplay(timecode)),
44     m_clipPos(clipPos),
45     m_inPoint(0),
46     m_outPoint(1),
47     m_isEffect(isEffect),
48     m_rect(NULL),
49     m_previous(NULL),
50     m_geometry(NULL),
51     m_showScene(true),
52     m_showRotation(showRotation)
53 {
54     m_ui.setupUi(this);
55     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
56     MonitorEditWidget *edit = monitor->getEffectEdit();
57     edit->removeCustomControls();
58     edit->addCustomButton(KIcon("transform-crop"), i18n("Show previous keyframe"), this, SLOT(slotShowPreviousKeyFrame(bool)), true, KdenliveSettings::onmonitoreffects_geometryshowprevious());
59     m_scene = edit->getScene();
60     m_scene->cleanup();
61
62     /*
63         Setup of timeline and keyframe controls
64     */
65
66     ((QGridLayout *)(m_ui.widgetTimeWrapper->layout()))->addWidget(m_timePos, 1, 6);
67
68     QVBoxLayout *layout = new QVBoxLayout(m_ui.frameTimeline);
69     m_timeline = new KeyframeHelper(m_ui.frameTimeline);
70     layout->addWidget(m_timeline);
71     layout->setContentsMargins(0, 0, 0, 0);
72     
73     int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
74     QSize iconSize(size, size);
75
76     m_ui.buttonPrevious->setIcon(KIcon("media-skip-backward"));
77     m_ui.buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
78     m_ui.buttonPrevious->setIconSize(iconSize);
79     m_ui.buttonNext->setIcon(KIcon("media-skip-forward"));
80     m_ui.buttonNext->setToolTip(i18n("Go to next keyframe"));
81     m_ui.buttonNext->setIconSize(iconSize);
82     m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
83     m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
84     m_ui.buttonAddDelete->setIconSize(iconSize);
85
86     m_ui.buttonSync->setIcon(KIcon("insert-link"));
87     m_ui.buttonSync->setToolTip(i18n("Synchronize with timeline cursor"));
88     m_ui.buttonSync->setChecked(KdenliveSettings::transitionfollowcursor());
89     m_ui.buttonSync->setIconSize(iconSize);
90
91     connect(m_timeline, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
92     connect(m_timeline, SIGNAL(keyframeMoved(int)),   this, SLOT(slotKeyframeMoved(int)));
93     connect(m_timeline, SIGNAL(addKeyframe(int)),     this, SLOT(slotAddKeyframe(int)));
94     connect(m_timeline, SIGNAL(removeKeyframe(int)),  this, SLOT(slotDeleteKeyframe(int)));
95     connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotPositionChanged()));
96     connect(m_ui.buttonPrevious,  SIGNAL(clicked()), this, SLOT(slotPreviousKeyframe()));
97     connect(m_ui.buttonNext,      SIGNAL(clicked()), this, SLOT(slotNextKeyframe()));
98     connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
99     connect(m_ui.buttonSync,      SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
100
101     m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
102     m_ui.horizontalLayout->addWidget(m_spinX, 0, 0);
103     
104     m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
105     m_ui.horizontalLayout->addWidget(m_spinY, 0, 1);
106     
107     m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this);
108     m_ui.horizontalLayout->addWidget(m_spinWidth, 0, 2);
109     
110     m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this);
111     m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 3);
112
113     m_ui.horizontalLayout->setColumnStretch(4, 10);
114
115     QMenu *menu = new QMenu(this);
116     QAction *adjustSize = new QAction(i18n("Adjust to original size"), this);
117     connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
118     menu->addAction(adjustSize);
119     QAction *fitToWidth = new QAction(i18n("Fit to width"), this);
120     connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
121     menu->addAction(fitToWidth);
122     QAction *fitToHeight = new QAction(i18n("Fit to height"), this);
123     connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
124     menu->addAction(fitToHeight);
125     menu->addSeparator();
126
127     QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
128     connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
129     menu->addAction(alignleft);
130     QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
131     connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
132     menu->addAction(alignhcenter);
133     QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
134     connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
135     menu->addAction(alignright);
136     QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
137     connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
138     menu->addAction(aligntop);
139     QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
140     connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
141     menu->addAction(alignvcenter);
142     QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
143     connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
144     menu->addAction(alignbottom);
145     m_ui.buttonOptions->setMenu(menu);
146
147     QHBoxLayout *alignLayout = new QHBoxLayout;
148     alignLayout->setSpacing(0);
149     QToolButton *alignButton = new QToolButton;
150     alignButton->setDefaultAction(alignleft);
151     alignButton->setAutoRaise(true);
152     alignLayout->addWidget(alignButton);
153
154     alignButton = new QToolButton;
155     alignButton->setDefaultAction(alignhcenter);
156     alignButton->setAutoRaise(true);
157     alignLayout->addWidget(alignButton);
158
159     alignButton = new QToolButton;
160     alignButton->setDefaultAction(alignright);
161     alignButton->setAutoRaise(true);
162     alignLayout->addWidget(alignButton);
163
164     alignButton = new QToolButton;
165     alignButton->setDefaultAction(aligntop);
166     alignButton->setAutoRaise(true);
167     alignLayout->addWidget(alignButton);
168
169     alignButton = new QToolButton;
170     alignButton->setDefaultAction(alignvcenter);
171     alignButton->setAutoRaise(true);
172     alignLayout->addWidget(alignButton);
173
174     alignButton = new QToolButton;
175     alignButton->setDefaultAction(alignbottom);
176     alignButton->setAutoRaise(true);
177     alignLayout->addWidget(alignButton);
178     alignLayout->addStretch(10);
179
180     m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
181     //m_ui.horizontalLayout->addStretch(10);
182     
183     m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
184     m_ui.horizontalLayout2->addWidget(m_spinSize);
185     
186     m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
187     m_ui.horizontalLayout2->addWidget(m_opacity);
188
189
190     if (showRotation) {
191         m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
192         m_rotateX->setObjectName("rotate_x");
193         m_ui.horizontalLayout3->addWidget(m_rotateX);
194         m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800,  -1, QString(), true, this);
195         m_rotateY->setObjectName("rotate_y");
196         m_ui.horizontalLayout3->addWidget(m_rotateY);
197         m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800,  -1, QString(), true, this);
198         m_rotateZ->setObjectName("rotate_z");
199         m_ui.horizontalLayout3->addWidget(m_rotateZ);
200         connect(m_rotateX,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
201         connect(m_rotateY,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
202         connect(m_rotateZ,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
203     }
204     
205     /*
206         Setup of geometry controls
207     */
208
209     connect(m_spinX,            SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
210     connect(m_spinY,            SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
211     connect(m_spinWidth,        SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
212     connect(m_spinHeight,       SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
213
214     connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
215
216     connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
217     
218     /*connect(m_ui.buttonMoveLeft,   SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
219     connect(m_ui.buttonCenterH,    SIGNAL(clicked()), this, SLOT(slotCenterH()));
220     connect(m_ui.buttonMoveRight,  SIGNAL(clicked()), this, SLOT(slotMoveRight()));
221     connect(m_ui.buttonMoveTop,    SIGNAL(clicked()), this, SLOT(slotMoveTop()));
222     connect(m_ui.buttonCenterV,    SIGNAL(clicked()), this, SLOT(slotCenterV()));
223     connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
224
225
226     /*
227         Setup of configuration controls
228     */
229
230     connect(m_scene, SIGNAL(addKeyframe()),    this, SLOT(slotAddKeyframe()));
231     connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
232 }
233
234 GeometryWidget::~GeometryWidget()
235 {
236     m_scene->setEnabled(true);
237     delete m_timePos;
238     delete m_timeline;
239     delete m_spinX;
240     delete m_spinY;
241     delete m_spinWidth;
242     delete m_spinHeight;
243     delete m_opacity;
244     m_scene->removeItem(m_rect);
245     if (m_rect) delete m_rect;
246     if (m_previous) delete m_previous;
247     delete m_geometry;
248     m_extraGeometryNames.clear();
249     m_extraFactors.clear();
250     while (!m_extraGeometries.isEmpty()) {
251         Mlt::Geometry *g = m_extraGeometries.takeFirst();
252         delete g;
253     }
254 }
255
256 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
257 {
258     KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
259     slotPositionChanged(-1, false);
260 }
261
262 void GeometryWidget::updateTimecodeFormat()
263 {
264     m_timePos->slotUpdateTimeCodeFormat();
265 }
266
267 QString GeometryWidget::getValue() const
268 {
269     return m_geometry->serialise();
270 }
271
272 QString GeometryWidget::getExtraValue(const QString &name) const
273 {
274     int ix = m_extraGeometryNames.indexOf(name);
275     QString val = m_extraGeometries.at(ix)->serialise();
276     if (!val.contains("=")) val = val.section('/', 0, 0);
277     else {
278         QStringList list = val.split(';', QString::SkipEmptyParts);
279         val.clear();
280         val.append(list.takeFirst().section('/', 0, 0));
281         foreach (const QString value, list) {
282             val.append(';' + value.section('/', 0, 0));
283         }
284     }
285     return val;
286 }
287
288 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
289 {
290     m_inPoint = minframe;
291     m_outPoint = maxframe;
292
293     if (m_geometry)
294         m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
295     else
296         m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
297
298     if (elem.attribute("fixed") == "1" || maxframe < minframe) {
299         // Keyframes are disabled
300         m_ui.widgetTimeWrapper->setHidden(true);
301     } else {
302         m_ui.widgetTimeWrapper->setHidden(false);
303         m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
304         m_timeline->update();
305         m_timePos->setRange(0, m_outPoint - m_inPoint);
306     }
307
308     // no opacity
309     if (elem.attribute("opacity") == "false") {
310         m_opacity->setHidden(true);
311         m_ui.horizontalLayout2->addStretch(2);
312     }
313
314     Mlt::GeometryItem item;
315
316     m_geometry->fetch(&item, 0);
317     delete m_rect;
318     m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
319     m_rect->setPos(item.x(), item.y());
320     m_rect->setZValue(0);
321     m_scene->addItem(m_rect);
322     connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
323     m_scene->centerView();
324     slotPositionChanged(0, false);
325 }
326
327 void GeometryWidget::addParameter(const QDomElement elem)
328 {
329     Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
330     m_extraGeometries.append(geometry);
331     m_timeline->addGeometry(geometry);
332     m_extraFactors.append(elem.attribute("factor", "1"));
333     m_extraGeometryNames.append(elem.attribute("name"));
334     //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
335 }
336
337 void GeometryWidget::slotSyncPosition(int relTimelinePos)
338 {
339     // do only sync if this effect is keyframable
340     if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
341         relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
342         if (relTimelinePos != m_timePos->getValue())
343             slotPositionChanged(relTimelinePos, false);
344     }
345 }
346
347
348 void GeometryWidget::slotPositionChanged(int pos, bool seek)
349 {
350     if (pos == -1)
351         pos = m_timePos->getValue();
352     else
353         m_timePos->setValue(pos);
354
355     m_timeline->blockSignals(true);
356     m_timeline->setValue(pos);
357     m_timeline->blockSignals(false);
358
359     Mlt::GeometryItem item;
360     Mlt::GeometryItem previousItem;
361     if (m_geometry->fetch(&item, pos) || item.key() == false) {
362         // no keyframe
363         m_rect->setEnabled(false);
364         m_scene->setEnabled(false);
365         m_ui.widgetGeometry->setEnabled(false);
366         m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
367         m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
368     } else {
369         // keyframe
370         m_rect->setEnabled(true);
371         m_scene->setEnabled(true);
372         m_ui.widgetGeometry->setEnabled(true);
373         m_ui.buttonAddDelete->setIcon(KIcon("edit-delete"));
374         m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
375     }
376     
377     if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
378         if (m_previous) {
379             m_scene->removeItem(m_previous);
380         }
381     }
382     else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
383         // previous frame already here, do nothing
384     }
385     else {
386         if (m_previous == NULL) {
387             m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
388             m_previous->setBrush(QColor(200, 200, 0, 20));
389             m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
390             m_previous->setPos(previousItem.x(), previousItem.y());
391             m_previous->setZValue(-1);
392             m_previous->setEnabled(false);
393         }
394         else {
395             m_previous->setPos(previousItem.x(), previousItem.y());
396             m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
397         }
398         m_previous->setData(Qt::UserRole, previousItem.frame());
399         if (m_previous->scene() == 0) m_scene->addItem(m_previous);
400     }
401
402     m_rect->setPos(item.x(), item.y());
403     m_rect->setRect(0, 0, item.w(), item.h());
404
405     m_opacity->blockSignals(true);
406     m_opacity->setValue(item.mix());
407     m_opacity->blockSignals(false);
408
409     for (int i = 0; i < m_extraGeometries.count(); i++) {
410         Mlt::Geometry *geom = m_extraGeometries.at(i);
411         QString name = m_extraGeometryNames.at(i);
412         if (!geom->fetch(&item, pos)) {
413             DragValue *widget = findChild<DragValue *>(name);
414             if (widget) {
415                 widget->blockSignals(true);
416                 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
417                 widget->blockSignals(false);
418             }
419         }
420     }
421
422     slotUpdateProperties();
423
424     if (seek && KdenliveSettings::transitionfollowcursor())
425         emit seekToPos(m_clipPos + pos);
426 }
427
428 void GeometryWidget::slotKeyframeMoved(int pos)
429 {
430     slotPositionChanged(pos);
431     slotUpdateGeometry();
432     QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
433 }
434
435 void GeometryWidget::slotAddKeyframe(int pos)
436 {
437     Mlt::GeometryItem item;
438     if (pos == -1)
439         pos = m_timePos->getValue();
440     item.frame(pos);
441     QRectF r = m_rect->rect().normalized();
442     QPointF rectpos = m_rect->pos();
443     item.x(rectpos.x());
444     item.y(rectpos.y());
445     item.w(r.width());
446     item.h(r.height());
447     item.mix(m_opacity->value());
448     m_geometry->insert(item);
449
450     for (int i = 0; i < m_extraGeometries.count(); i++) {
451         Mlt::Geometry *geom = m_extraGeometries.at(i);
452         QString name = m_extraGeometryNames.at(i);
453         DragValue *widget = findChild<DragValue *>(name);
454         if (widget) {
455             Mlt::GeometryItem item2;
456             item2.frame(pos);
457             item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
458             geom->insert(item2);
459         }
460     }
461     
462     m_timeline->update();
463     slotPositionChanged(pos, false);
464     emit parameterChanged();
465 }
466
467 void GeometryWidget::slotDeleteKeyframe(int pos)
468 {
469     Mlt::GeometryItem item;
470     if (pos == -1)
471         pos = m_timePos->getValue();
472     // check there is more than one keyframe, do not allow to delete last one
473     if (m_geometry->next_key(&item, pos + 1)) {
474         if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
475             return;
476     }
477     m_geometry->remove(pos);
478
479     for (int i = 0; i < m_extraGeometries.count(); i++) {
480         Mlt::Geometry *geom = m_extraGeometries.at(i);
481         geom->remove(pos);
482     }
483
484     m_timeline->update();
485     slotPositionChanged(pos, false);
486     emit parameterChanged();
487 }
488
489 void GeometryWidget::slotPreviousKeyframe()
490 {
491     Mlt::GeometryItem item;
492     // Go to start if no keyframe is found
493     int currentPos = m_timePos->getValue();
494     int pos = 0;
495     if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
496         pos = item.frame();
497
498     slotPositionChanged(pos);
499 }
500
501 void GeometryWidget::slotNextKeyframe()
502 {
503     Mlt::GeometryItem item;
504     // Go to end if no keyframe is found
505     int pos = m_timeline->frameLength;
506     if (!m_geometry->next_key(&item, m_timeline->value() + 1))
507         pos = item.frame();
508
509     slotPositionChanged(pos);
510 }
511
512 void GeometryWidget::slotAddDeleteKeyframe()
513 {
514     Mlt::GeometryItem item;
515     if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
516         slotAddKeyframe();
517     else
518         slotDeleteKeyframe();
519 }
520
521
522
523 void GeometryWidget::slotUpdateGeometry()
524 {
525     Mlt::GeometryItem item;
526     int pos = m_timePos->getValue();
527
528     // get keyframe and make sure it is the correct one
529     if (m_geometry->next_key(&item, pos) || item.frame() != pos)
530         return;
531
532     QRectF rectSize = m_rect->rect().normalized();
533     QPointF rectPos = m_rect->pos();
534     item.x(rectPos.x());
535     item.y(rectPos.y());
536     item.w(rectSize.width());
537     item.h(rectSize.height());
538     m_geometry->insert(item);
539
540     for (int i = 0; i < m_extraGeometries.count(); i++) {
541         Mlt::Geometry *geom = m_extraGeometries.at(i);
542         QString name = m_extraGeometryNames.at(i);
543         Mlt::GeometryItem item2;
544         DragValue *widget = findChild<DragValue *>(name);
545         if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
546             item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
547             geom->insert(item2);
548         }
549     }
550     emit parameterChanged();
551 }
552
553 void GeometryWidget::slotUpdateProperties()
554 {
555     QRectF rectSize = m_rect->rect().normalized();
556     QPointF rectPos = m_rect->pos();
557     double size;
558     if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
559         size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
560     else
561         size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
562
563     m_spinX->blockSignals(true);
564     m_spinY->blockSignals(true);
565     m_spinWidth->blockSignals(true);
566     m_spinHeight->blockSignals(true);
567     m_spinSize->blockSignals(true);
568
569     m_spinX->setValue(rectPos.x());
570     m_spinY->setValue(rectPos.y());
571     m_spinWidth->setValue(rectSize.width());
572     m_spinHeight->setValue(rectSize.height());
573     m_spinSize->setValue(size);
574
575     m_spinX->blockSignals(false);
576     m_spinY->blockSignals(false);
577     m_spinWidth->blockSignals(false);
578     m_spinHeight->blockSignals(false);
579     m_spinSize->blockSignals(false);
580 }
581
582
583 void GeometryWidget::slotSetX(double value)
584 {
585     m_rect->setPos(value, m_spinY->value());
586     slotUpdateGeometry();
587 }
588
589 void GeometryWidget::slotSetY(double value)
590 {
591     m_rect->setPos(m_spinX->value(), value);
592     slotUpdateGeometry();
593 }
594
595 void GeometryWidget::slotSetWidth(double value)
596 {
597     m_rect->setRect(0, 0, value, m_spinHeight->value());
598     slotUpdateGeometry();
599 }
600
601 void GeometryWidget::slotSetHeight(double value)
602 {
603     m_rect->setRect(0, 0, m_spinWidth->value(), value);
604     slotUpdateGeometry();
605 }
606
607 void GeometryWidget::updateMonitorGeometry()
608 {
609     m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
610     slotUpdateGeometry();
611 }
612
613
614 void GeometryWidget::slotResize(double value)
615 {
616     m_rect->setRect(0, 0,
617                     (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
618                     (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
619     slotUpdateGeometry();
620 }
621
622
623 void GeometryWidget::slotSetOpacity(double value)
624 {
625     int pos = m_timePos->getValue();
626     Mlt::GeometryItem item;
627     if (m_geometry->fetch(&item, pos) || item.key() == false)
628         return;
629     item.mix(value);
630     m_geometry->insert(item);
631     emit parameterChanged();
632 }
633
634
635 void GeometryWidget::slotMoveLeft()
636 {
637     m_rect->setPos(0, m_rect->pos().y());
638     slotUpdateGeometry();
639 }
640
641 void GeometryWidget::slotCenterH()
642 {
643     m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
644     slotUpdateGeometry();
645 }
646
647 void GeometryWidget::slotMoveRight()
648 {
649     m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
650     slotUpdateGeometry();
651 }
652
653 void GeometryWidget::slotMoveTop()
654 {
655     m_rect->setPos(m_rect->pos().x(), 0);
656     slotUpdateGeometry();
657 }
658
659 void GeometryWidget::slotCenterV()
660 {
661     m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
662     slotUpdateGeometry();
663 }
664
665 void GeometryWidget::slotMoveBottom()
666 {
667     m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
668     slotUpdateGeometry();
669 }
670
671
672 void GeometryWidget::slotSetSynchronize(bool sync)
673 {
674     KdenliveSettings::setTransitionfollowcursor(sync);
675     if (sync)
676         emit seekToPos(m_clipPos + m_timePos->getValue());
677 }
678
679 void GeometryWidget::setFrameSize(QPoint size)
680 {
681     m_frameSize = size;
682 }
683
684 void GeometryWidget::slotAdjustToFrameSize()
685 {
686     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
687         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
688     }
689     m_spinWidth->blockSignals(true);
690     m_spinHeight->blockSignals(true);
691     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
692     m_spinHeight->setValue(m_frameSize.y());
693     m_spinWidth->blockSignals(false);
694     m_spinHeight->blockSignals(false);
695     updateMonitorGeometry();
696 }
697
698 void GeometryWidget::slotFitToWidth()
699 {
700     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
701         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
702     }
703     double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
704     m_spinWidth->blockSignals(true);
705     m_spinHeight->blockSignals(true);
706     m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
707     m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
708     m_spinWidth->blockSignals(false);
709     m_spinHeight->blockSignals(false);
710     updateMonitorGeometry();
711 }
712
713 void GeometryWidget::slotFitToHeight()
714 {
715     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
716         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
717     }
718     double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
719     m_spinWidth->blockSignals(true);
720     m_spinHeight->blockSignals(true);
721     m_spinHeight->setValue(m_monitor->render->renderHeight());
722     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
723     m_spinWidth->blockSignals(false);
724     m_spinHeight->blockSignals(false);
725     updateMonitorGeometry();
726 }
727
728 #include "geometrywidget.moc"