]> git.sesse.net Git - kdenlive/blob - src/geometrywidget.cpp
Fix monitor scene sometimes forcing monitor minimum size
[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     QMenu *menu = new QMenu(this);
114     QAction *adjustSize = new QAction(i18n("Adjust to original size"), this);
115     connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
116     menu->addAction(adjustSize);
117     QAction *fitToWidth = new QAction(i18n("Fit to width"), this);
118     connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
119     menu->addAction(fitToWidth);
120     QAction *fitToHeight = new QAction(i18n("Fit to height"), this);
121     connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
122     menu->addAction(fitToHeight);
123     menu->addSeparator();
124
125     QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
126     connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
127     menu->addAction(alignleft);
128     QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
129     connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
130     menu->addAction(alignhcenter);
131     QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
132     connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
133     menu->addAction(alignright);
134     QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
135     connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
136     menu->addAction(aligntop);
137     QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
138     connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
139     menu->addAction(alignvcenter);
140     QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
141     connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
142     menu->addAction(alignbottom);
143     m_ui.buttonOptions->setMenu(menu);
144
145     QHBoxLayout *alignLayout = new QHBoxLayout;
146     alignLayout->setSpacing(0);
147     QToolButton *alignButton = new QToolButton;
148     alignButton->setDefaultAction(alignleft);
149     alignButton->setAutoRaise(true);
150     alignLayout->addWidget(alignButton);
151
152     alignButton = new QToolButton;
153     alignButton->setDefaultAction(alignhcenter);
154     alignButton->setAutoRaise(true);
155     alignLayout->addWidget(alignButton);
156
157     alignButton = new QToolButton;
158     alignButton->setDefaultAction(alignright);
159     alignButton->setAutoRaise(true);
160     alignLayout->addWidget(alignButton);
161
162     alignButton = new QToolButton;
163     alignButton->setDefaultAction(aligntop);
164     alignButton->setAutoRaise(true);
165     alignLayout->addWidget(alignButton);
166
167     alignButton = new QToolButton;
168     alignButton->setDefaultAction(alignvcenter);
169     alignButton->setAutoRaise(true);
170     alignLayout->addWidget(alignButton);
171
172     alignButton = new QToolButton;
173     alignButton->setDefaultAction(alignbottom);
174     alignButton->setAutoRaise(true);
175     alignLayout->addWidget(alignButton);
176     alignLayout->addStretch(10);
177
178     m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
179     //m_ui.horizontalLayout->addStretch(10);
180     
181     m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
182     m_ui.horizontalLayout2->addWidget(m_spinSize);
183     
184     m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
185     m_ui.horizontalLayout2->addWidget(m_opacity);
186
187
188     if (showRotation) {
189         m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
190         m_rotateX->setObjectName("rotate_x");
191         m_ui.horizontalLayout3->addWidget(m_rotateX);
192         m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800,  -1, QString(), true, this);
193         m_rotateY->setObjectName("rotate_y");
194         m_ui.horizontalLayout3->addWidget(m_rotateY);
195         m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800,  -1, QString(), true, this);
196         m_rotateZ->setObjectName("rotate_z");
197         m_ui.horizontalLayout3->addWidget(m_rotateZ);
198         connect(m_rotateX,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
199         connect(m_rotateY,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
200         connect(m_rotateZ,            SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
201     }
202     
203     /*
204         Setup of geometry controls
205     */
206
207     connect(m_spinX,            SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
208     connect(m_spinY,            SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
209     connect(m_spinWidth,        SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
210     connect(m_spinHeight,       SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
211
212     connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
213
214     connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
215     
216     /*connect(m_ui.buttonMoveLeft,   SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
217     connect(m_ui.buttonCenterH,    SIGNAL(clicked()), this, SLOT(slotCenterH()));
218     connect(m_ui.buttonMoveRight,  SIGNAL(clicked()), this, SLOT(slotMoveRight()));
219     connect(m_ui.buttonMoveTop,    SIGNAL(clicked()), this, SLOT(slotMoveTop()));
220     connect(m_ui.buttonCenterV,    SIGNAL(clicked()), this, SLOT(slotCenterV()));
221     connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
222
223
224     /*
225         Setup of configuration controls
226     */
227
228     connect(m_scene, SIGNAL(addKeyframe()),    this, SLOT(slotAddKeyframe()));
229     connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
230 }
231
232 GeometryWidget::~GeometryWidget()
233 {
234     m_scene->setEnabled(true);
235     delete m_timePos;
236     delete m_timeline;
237     delete m_spinX;
238     delete m_spinY;
239     delete m_spinWidth;
240     delete m_spinHeight;
241     delete m_opacity;
242     m_scene->removeItem(m_rect);
243     if (m_rect) delete m_rect;
244     if (m_previous) delete m_previous;
245     delete m_geometry;
246     m_extraGeometryNames.clear();
247     m_extraFactors.clear();
248     while (!m_extraGeometries.isEmpty()) {
249         Mlt::Geometry *g = m_extraGeometries.takeFirst();
250         delete g;
251     }
252 }
253
254 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
255 {
256     KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
257     slotPositionChanged(-1, false);
258 }
259
260 void GeometryWidget::updateTimecodeFormat()
261 {
262     m_timePos->slotUpdateTimeCodeFormat();
263 }
264
265 QString GeometryWidget::getValue() const
266 {
267     return m_geometry->serialise();
268 }
269
270 QString GeometryWidget::getExtraValue(const QString &name) const
271 {
272     int ix = m_extraGeometryNames.indexOf(name);
273     QString val = m_extraGeometries.at(ix)->serialise();
274     if (!val.contains("=")) val = val.section('/', 0, 0);
275     else {
276         QStringList list = val.split(';', QString::SkipEmptyParts);
277         val.clear();
278         val.append(list.takeFirst().section('/', 0, 0));
279         foreach (const QString value, list) {
280             val.append(';' + value.section('/', 0, 0));
281         }
282     }
283     return val;
284 }
285
286 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
287 {
288     m_inPoint = minframe;
289     m_outPoint = maxframe;
290
291     if (m_geometry)
292         m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
293     else
294         m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
295
296     if (elem.attribute("fixed") == "1" || maxframe < minframe) {
297         // Keyframes are disabled
298         m_ui.widgetTimeWrapper->setHidden(true);
299     } else {
300         m_ui.widgetTimeWrapper->setHidden(false);
301         m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
302         m_timeline->update();
303         m_timePos->setRange(0, m_outPoint - m_inPoint);
304     }
305
306     // no opacity
307     if (elem.attribute("opacity") == "false") {
308         m_opacity->setHidden(true);
309         m_ui.horizontalLayout2->addStretch(2);
310     }
311
312     Mlt::GeometryItem item;
313
314     m_geometry->fetch(&item, 0);
315     delete m_rect;
316     m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
317     m_rect->setPos(item.x(), item.y());
318     m_rect->setZValue(0);
319     m_scene->addItem(m_rect);
320     connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
321     m_scene->centerView();
322     slotPositionChanged(0, false);
323 }
324
325 void GeometryWidget::addParameter(const QDomElement elem)
326 {
327     Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
328     m_extraGeometries.append(geometry);
329     m_timeline->addGeometry(geometry);
330     m_extraFactors.append(elem.attribute("factor", "1"));
331     m_extraGeometryNames.append(elem.attribute("name"));
332     //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
333 }
334
335 void GeometryWidget::slotSyncPosition(int relTimelinePos)
336 {
337     // do only sync if this effect is keyframable
338     if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
339         relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
340         if (relTimelinePos != m_timePos->getValue())
341             slotPositionChanged(relTimelinePos, false);
342     }
343 }
344
345
346 void GeometryWidget::slotPositionChanged(int pos, bool seek)
347 {
348     if (pos == -1)
349         pos = m_timePos->getValue();
350     else
351         m_timePos->setValue(pos);
352
353     m_timeline->blockSignals(true);
354     m_timeline->setValue(pos);
355     m_timeline->blockSignals(false);
356
357     Mlt::GeometryItem item;
358     Mlt::GeometryItem previousItem;
359     if (m_geometry->fetch(&item, pos) || item.key() == false) {
360         // no keyframe
361         m_rect->setEnabled(false);
362         m_scene->setEnabled(false);
363         m_ui.widgetGeometry->setEnabled(false);
364         m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
365         m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
366     } else {
367         // keyframe
368         m_rect->setEnabled(true);
369         m_scene->setEnabled(true);
370         m_ui.widgetGeometry->setEnabled(true);
371         m_ui.buttonAddDelete->setIcon(KIcon("edit-delete"));
372         m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
373     }
374     
375     if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
376         if (m_previous) {
377             m_scene->removeItem(m_previous);
378         }
379     }
380     else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
381         // previous frame already here, do nothing
382     }
383     else {
384         if (m_previous == NULL) {
385             m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
386             m_previous->setBrush(QColor(200, 200, 0, 20));
387             m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
388             m_previous->setPos(previousItem.x(), previousItem.y());
389             m_previous->setZValue(-1);
390             m_previous->setEnabled(false);
391         }
392         else {
393             m_previous->setPos(previousItem.x(), previousItem.y());
394             m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
395         }
396         m_previous->setData(Qt::UserRole, previousItem.frame());
397         if (m_previous->scene() == 0) m_scene->addItem(m_previous);
398     }
399
400     m_rect->setPos(item.x(), item.y());
401     m_rect->setRect(0, 0, item.w(), item.h());
402
403     m_opacity->blockSignals(true);
404     m_opacity->setValue(item.mix());
405     m_opacity->blockSignals(false);
406
407     for (int i = 0; i < m_extraGeometries.count(); i++) {
408         Mlt::Geometry *geom = m_extraGeometries.at(i);
409         QString name = m_extraGeometryNames.at(i);
410         if (!geom->fetch(&item, pos)) {
411             DragValue *widget = findChild<DragValue *>(name);
412             if (widget) {
413                 widget->blockSignals(true);
414                 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
415                 widget->blockSignals(false);
416             }
417         }
418     }
419
420     slotUpdateProperties();
421
422     if (seek && KdenliveSettings::transitionfollowcursor())
423         emit seekToPos(m_clipPos + pos);
424 }
425
426 void GeometryWidget::slotKeyframeMoved(int pos)
427 {
428     slotPositionChanged(pos);
429     slotUpdateGeometry();
430     QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
431 }
432
433 void GeometryWidget::slotAddKeyframe(int pos)
434 {
435     Mlt::GeometryItem item;
436     if (pos == -1)
437         pos = m_timePos->getValue();
438     item.frame(pos);
439     QRectF r = m_rect->rect().normalized();
440     QPointF rectpos = m_rect->pos();
441     item.x(rectpos.x());
442     item.y(rectpos.y());
443     item.w(r.width());
444     item.h(r.height());
445     item.mix(m_opacity->value());
446     m_geometry->insert(item);
447
448     for (int i = 0; i < m_extraGeometries.count(); i++) {
449         Mlt::Geometry *geom = m_extraGeometries.at(i);
450         QString name = m_extraGeometryNames.at(i);
451         DragValue *widget = findChild<DragValue *>(name);
452         if (widget) {
453             Mlt::GeometryItem item2;
454             item2.frame(pos);
455             item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
456             geom->insert(item2);
457         }
458     }
459     
460     m_timeline->update();
461     slotPositionChanged(pos, false);
462     emit parameterChanged();
463 }
464
465 void GeometryWidget::slotDeleteKeyframe(int pos)
466 {
467     Mlt::GeometryItem item;
468     if (pos == -1)
469         pos = m_timePos->getValue();
470     // check there is more than one keyframe, do not allow to delete last one
471     if (m_geometry->next_key(&item, pos + 1)) {
472         if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
473             return;
474     }
475     m_geometry->remove(pos);
476
477     for (int i = 0; i < m_extraGeometries.count(); i++) {
478         Mlt::Geometry *geom = m_extraGeometries.at(i);
479         geom->remove(pos);
480     }
481
482     m_timeline->update();
483     slotPositionChanged(pos, false);
484     emit parameterChanged();
485 }
486
487 void GeometryWidget::slotPreviousKeyframe()
488 {
489     Mlt::GeometryItem item;
490     // Go to start if no keyframe is found
491     int currentPos = m_timePos->getValue();
492     int pos = 0;
493     if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
494         pos = item.frame();
495
496     slotPositionChanged(pos);
497 }
498
499 void GeometryWidget::slotNextKeyframe()
500 {
501     Mlt::GeometryItem item;
502     // Go to end if no keyframe is found
503     int pos = m_timeline->frameLength;
504     if (!m_geometry->next_key(&item, m_timeline->value() + 1))
505         pos = item.frame();
506
507     slotPositionChanged(pos);
508 }
509
510 void GeometryWidget::slotAddDeleteKeyframe()
511 {
512     Mlt::GeometryItem item;
513     if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
514         slotAddKeyframe();
515     else
516         slotDeleteKeyframe();
517 }
518
519
520
521 void GeometryWidget::slotUpdateGeometry()
522 {
523     Mlt::GeometryItem item;
524     int pos = m_timePos->getValue();
525
526     // get keyframe and make sure it is the correct one
527     if (m_geometry->next_key(&item, pos) || item.frame() != pos)
528         return;
529
530     QRectF rectSize = m_rect->rect().normalized();
531     QPointF rectPos = m_rect->pos();
532     item.x(rectPos.x());
533     item.y(rectPos.y());
534     item.w(rectSize.width());
535     item.h(rectSize.height());
536     m_geometry->insert(item);
537
538     for (int i = 0; i < m_extraGeometries.count(); i++) {
539         Mlt::Geometry *geom = m_extraGeometries.at(i);
540         QString name = m_extraGeometryNames.at(i);
541         Mlt::GeometryItem item2;
542         DragValue *widget = findChild<DragValue *>(name);
543         if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
544             item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
545             geom->insert(item2);
546         }
547     }
548     emit parameterChanged();
549 }
550
551 void GeometryWidget::slotUpdateProperties()
552 {
553     QRectF rectSize = m_rect->rect().normalized();
554     QPointF rectPos = m_rect->pos();
555     double size;
556     if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
557         size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
558     else
559         size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
560
561     m_spinX->blockSignals(true);
562     m_spinY->blockSignals(true);
563     m_spinWidth->blockSignals(true);
564     m_spinHeight->blockSignals(true);
565     m_spinSize->blockSignals(true);
566
567     m_spinX->setValue(rectPos.x());
568     m_spinY->setValue(rectPos.y());
569     m_spinWidth->setValue(rectSize.width());
570     m_spinHeight->setValue(rectSize.height());
571     m_spinSize->setValue(size);
572
573     m_spinX->blockSignals(false);
574     m_spinY->blockSignals(false);
575     m_spinWidth->blockSignals(false);
576     m_spinHeight->blockSignals(false);
577     m_spinSize->blockSignals(false);
578 }
579
580
581 void GeometryWidget::slotSetX(double value)
582 {
583     m_rect->setPos(value, m_spinY->value());
584     slotUpdateGeometry();
585 }
586
587 void GeometryWidget::slotSetY(double value)
588 {
589     m_rect->setPos(m_spinX->value(), value);
590     slotUpdateGeometry();
591 }
592
593 void GeometryWidget::slotSetWidth(double value)
594 {
595     m_rect->setRect(0, 0, value, m_spinHeight->value());
596     slotUpdateGeometry();
597 }
598
599 void GeometryWidget::slotSetHeight(double value)
600 {
601     m_rect->setRect(0, 0, m_spinWidth->value(), value);
602     slotUpdateGeometry();
603 }
604
605 void GeometryWidget::updateMonitorGeometry()
606 {
607     m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
608     slotUpdateGeometry();
609 }
610
611
612 void GeometryWidget::slotResize(double value)
613 {
614     m_rect->setRect(0, 0,
615                     (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
616                     (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
617     slotUpdateGeometry();
618 }
619
620
621 void GeometryWidget::slotSetOpacity(double value)
622 {
623     int pos = m_timePos->getValue();
624     Mlt::GeometryItem item;
625     if (m_geometry->fetch(&item, pos) || item.key() == false)
626         return;
627     item.mix(value);
628     m_geometry->insert(item);
629     emit parameterChanged();
630 }
631
632
633 void GeometryWidget::slotMoveLeft()
634 {
635     m_rect->setPos(0, m_rect->pos().y());
636     slotUpdateGeometry();
637 }
638
639 void GeometryWidget::slotCenterH()
640 {
641     m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
642     slotUpdateGeometry();
643 }
644
645 void GeometryWidget::slotMoveRight()
646 {
647     m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
648     slotUpdateGeometry();
649 }
650
651 void GeometryWidget::slotMoveTop()
652 {
653     m_rect->setPos(m_rect->pos().x(), 0);
654     slotUpdateGeometry();
655 }
656
657 void GeometryWidget::slotCenterV()
658 {
659     m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
660     slotUpdateGeometry();
661 }
662
663 void GeometryWidget::slotMoveBottom()
664 {
665     m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
666     slotUpdateGeometry();
667 }
668
669
670 void GeometryWidget::slotSetSynchronize(bool sync)
671 {
672     KdenliveSettings::setTransitionfollowcursor(sync);
673     if (sync)
674         emit seekToPos(m_clipPos + m_timePos->getValue());
675 }
676
677 void GeometryWidget::setFrameSize(QPoint size)
678 {
679     m_frameSize = size;
680 }
681
682 void GeometryWidget::slotAdjustToFrameSize()
683 {
684     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
685         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
686     }
687     m_spinWidth->blockSignals(true);
688     m_spinHeight->blockSignals(true);
689     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
690     m_spinHeight->setValue(m_frameSize.y());
691     m_spinWidth->blockSignals(false);
692     m_spinHeight->blockSignals(false);
693     updateMonitorGeometry();
694 }
695
696 void GeometryWidget::slotFitToWidth()
697 {
698     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
699         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
700     }
701     double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
702     m_spinWidth->blockSignals(true);
703     m_spinHeight->blockSignals(true);
704     m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
705     m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
706     m_spinWidth->blockSignals(false);
707     m_spinHeight->blockSignals(false);
708     updateMonitorGeometry();
709 }
710
711 void GeometryWidget::slotFitToHeight()
712 {
713     if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
714         m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
715     }
716     double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
717     m_spinWidth->blockSignals(true);
718     m_spinHeight->blockSignals(true);
719     m_spinHeight->setValue(m_monitor->render->renderHeight());
720     m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
721     m_spinWidth->blockSignals(false);
722     m_spinHeight->blockSignals(false);
723     updateMonitorGeometry();
724 }
725
726 #include "geometrywidget.moc"