1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
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. *
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. *
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 ***************************************************************************/
21 #include "geometrywidget.h"
24 #include "keyframehelper.h"
25 #include "timecodedisplay.h"
26 #include "monitorscene.h"
27 #include "monitoreditwidget.h"
28 #include "onmonitoritems/onmonitorrectitem.h"
29 #include "onmonitoritems/onmonitorpathitem.h"
30 #include "kdenlivesettings.h"
31 #include "dragvalue.h"
34 #include <QGraphicsView>
35 #include <QVBoxLayout>
36 #include <QGridLayout>
41 GeometryWidget::GeometryWidget(Monitor* monitor, Timecode timecode, int clipPos, bool isEffect, bool showRotation, QWidget* parent):
44 m_timePos(new TimecodeDisplay(timecode)),
54 m_showRotation(showRotation)
57 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
58 MonitorEditWidget *edit = monitor->getEffectEdit();
59 edit->removeCustomControls();
60 edit->addCustomButton(KIcon("transform-crop"), i18n("Show previous keyframe"), this, SLOT(slotShowPreviousKeyFrame(bool)), true, KdenliveSettings::onmonitoreffects_geometryshowprevious());
61 m_scene = edit->getScene();
65 Setup of timeline and keyframe controls
68 ((QGridLayout *)(m_ui.widgetTimeWrapper->layout()))->addWidget(m_timePos, 1, 5);
70 QVBoxLayout *layout = new QVBoxLayout(m_ui.frameTimeline);
71 m_timeline = new KeyframeHelper(m_ui.frameTimeline);
72 layout->addWidget(m_timeline);
73 layout->setContentsMargins(0, 0, 0, 0);
75 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
76 QSize iconSize(size, size);
78 m_ui.buttonPrevious->setIcon(KIcon("media-skip-backward"));
79 m_ui.buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
80 m_ui.buttonPrevious->setIconSize(iconSize);
81 m_ui.buttonNext->setIcon(KIcon("media-skip-forward"));
82 m_ui.buttonNext->setToolTip(i18n("Go to next keyframe"));
83 m_ui.buttonNext->setIconSize(iconSize);
84 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
85 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
86 m_ui.buttonAddDelete->setIconSize(iconSize);
88 connect(m_timeline, SIGNAL(requestSeek(int)), this, SLOT(slotRequestSeek(int)));
89 connect(m_timeline, SIGNAL(keyframeMoved(int)), this, SLOT(slotKeyframeMoved(int)));
90 connect(m_timeline, SIGNAL(addKeyframe(int)), this, SLOT(slotAddKeyframe(int)));
91 connect(m_timeline, SIGNAL(removeKeyframe(int)), this, SLOT(slotDeleteKeyframe(int)));
92 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotPositionChanged()));
93 connect(m_ui.buttonPrevious, SIGNAL(clicked()), this, SLOT(slotPreviousKeyframe()));
94 connect(m_ui.buttonNext, SIGNAL(clicked()), this, SLOT(slotNextKeyframe()));
95 connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
97 m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
98 m_ui.horizontalLayout->addWidget(m_spinX, 0, 0);
100 m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
101 m_ui.horizontalLayout->addWidget(m_spinY, 0, 1);
103 m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this);
104 m_ui.horizontalLayout->addWidget(m_spinWidth, 0, 2);
106 m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this);
107 m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 3);
109 m_ui.horizontalLayout->setColumnStretch(4, 10);
111 QMenu *menu = new QMenu(this);
112 QAction *adjustSize = new QAction(KIcon("zoom-fit-best"), i18n("Adjust to original size"), this);
113 connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
114 QAction *fitToWidth = new QAction(KIcon("zoom-fit-width"), i18n("Fit to width"), this);
115 connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
116 QAction *fitToHeight = new QAction(KIcon("zoom-fit-height"), i18n("Fit to height"), this);
117 connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
119 QAction *importKeyframes = new QAction(i18n("Import keyframes from clip"), this);
120 connect(importKeyframes, SIGNAL(triggered()), this, SIGNAL(importClipKeyframes()));
121 menu->addAction(importKeyframes);
122 QAction *resetKeyframes = new QAction(i18n("Reset keyframes"), this);
123 connect(resetKeyframes, SIGNAL(triggered()), this, SLOT(slotResetKeyframes()));
124 menu->addAction(resetKeyframes);
125 menu->addSeparator();
127 QAction *syncTimeline = new QAction(KIcon("insert-link"), i18n("Synchronize with timeline cursor"), this);
128 syncTimeline->setCheckable(true);
129 syncTimeline->setChecked(KdenliveSettings::transitionfollowcursor());
130 connect(syncTimeline, SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
131 menu->addAction(syncTimeline);
133 QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
134 connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
135 QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
136 connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
137 QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
138 connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
139 QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
140 connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
141 QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
142 connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
143 QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
144 connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
146 m_ui.buttonOptions->setMenu(menu);
147 m_ui.buttonOptions->setIcon(KIcon("configure"));
148 m_ui.buttonOptions->setToolTip(i18n("Options"));
149 m_ui.buttonOptions->setIconSize(iconSize);
151 QHBoxLayout *alignLayout = new QHBoxLayout;
152 alignLayout->setSpacing(0);
153 QToolButton *alignButton = new QToolButton;
154 alignButton->setDefaultAction(alignleft);
155 alignButton->setAutoRaise(true);
156 alignLayout->addWidget(alignButton);
158 alignButton = new QToolButton;
159 alignButton->setDefaultAction(alignhcenter);
160 alignButton->setAutoRaise(true);
161 alignLayout->addWidget(alignButton);
163 alignButton = new QToolButton;
164 alignButton->setDefaultAction(alignright);
165 alignButton->setAutoRaise(true);
166 alignLayout->addWidget(alignButton);
168 alignButton = new QToolButton;
169 alignButton->setDefaultAction(aligntop);
170 alignButton->setAutoRaise(true);
171 alignLayout->addWidget(alignButton);
173 alignButton = new QToolButton;
174 alignButton->setDefaultAction(alignvcenter);
175 alignButton->setAutoRaise(true);
176 alignLayout->addWidget(alignButton);
178 alignButton = new QToolButton;
179 alignButton->setDefaultAction(alignbottom);
180 alignButton->setAutoRaise(true);
181 alignLayout->addWidget(alignButton);
183 alignButton = new QToolButton;
184 alignButton->setDefaultAction(adjustSize);
185 alignButton->setAutoRaise(true);
186 alignLayout->addWidget(alignButton);
188 alignButton = new QToolButton;
189 alignButton->setDefaultAction(fitToWidth);
190 alignButton->setAutoRaise(true);
191 alignLayout->addWidget(alignButton);
193 alignButton = new QToolButton;
194 alignButton->setDefaultAction(fitToHeight);
195 alignButton->setAutoRaise(true);
196 alignLayout->addWidget(alignButton);
197 alignLayout->addStretch(10);
199 m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
200 //m_ui.horizontalLayout->addStretch(10);
202 m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
203 m_ui.horizontalLayout2->addWidget(m_spinSize);
205 m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
206 m_ui.horizontalLayout2->addWidget(m_opacity);
210 m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
211 m_rotateX->setObjectName("rotate_x");
212 m_ui.horizontalLayout3->addWidget(m_rotateX);
213 m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800, -1, QString(), true, this);
214 m_rotateY->setObjectName("rotate_y");
215 m_ui.horizontalLayout3->addWidget(m_rotateY);
216 m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800, -1, QString(), true, this);
217 m_rotateZ->setObjectName("rotate_z");
218 m_ui.horizontalLayout3->addWidget(m_rotateZ);
219 connect(m_rotateX, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
220 connect(m_rotateY, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
221 connect(m_rotateZ, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
225 Setup of geometry controls
228 connect(m_spinX, SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
229 connect(m_spinY, SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
230 connect(m_spinWidth, SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
231 connect(m_spinHeight, SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
233 connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
235 connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
237 /*connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
238 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
239 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
240 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
241 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
242 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
246 Setup of configuration controls
249 connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
250 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
253 GeometryWidget::~GeometryWidget()
255 m_scene->setEnabled(false);
264 m_scene->removeItem(m_rect);
268 m_scene->removeItem(m_geomPath);
271 if (m_previous) delete m_previous;
273 m_extraGeometryNames.clear();
274 m_extraFactors.clear();
275 while (!m_extraGeometries.isEmpty()) {
276 Mlt::Geometry *g = m_extraGeometries.takeFirst();
281 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
283 KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
284 slotPositionChanged(-1, false);
287 void GeometryWidget::updateTimecodeFormat()
289 m_timePos->slotUpdateTimeCodeFormat();
292 QString GeometryWidget::getValue() const
294 return m_geometry->serialise();
297 QString GeometryWidget::getExtraValue(const QString &name) const
299 int ix = m_extraGeometryNames.indexOf(name);
300 QString val = m_extraGeometries.at(ix)->serialise();
301 if (!val.contains("=")) val = val.section('/', 0, 0);
303 QStringList list = val.split(';', QString::SkipEmptyParts);
305 val.append(list.takeFirst().section('/', 0, 0));
306 foreach (const QString &value, list) {
307 val.append(';' + value.section('/', 0, 0));
313 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
315 m_inPoint = minframe;
316 m_outPoint = maxframe;
319 m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
321 m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
323 if (elem.attribute("fixed") == "1" || maxframe < minframe) {
324 // Keyframes are disabled
325 m_ui.widgetTimeWrapper->setHidden(true);
327 m_ui.widgetTimeWrapper->setHidden(false);
328 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
329 m_timePos->setRange(0, m_outPoint - m_inPoint);
333 if (elem.attribute("opacity") == "false") {
334 m_opacity->setHidden(true);
335 m_ui.horizontalLayout2->addStretch(2);
338 Mlt::GeometryItem item;
339 m_geometry->fetch(&item, 0);
341 m_scene->removeItem(m_rect);
345 m_scene->removeItem(m_geomPath);
348 m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
349 m_rect->setPos(item.x(), item.y());
350 m_rect->setZValue(0);
351 m_scene->addItem(m_rect);
352 connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
353 m_geomPath = new OnMonitorPathItem(m_monitor->render->dar());
354 connect(m_geomPath, SIGNAL(changed()), this, SLOT(slotUpdatePath()));
355 m_geomPath->setPen(QPen(Qt::red));
356 m_geomPath->setPoints(m_geometry);
357 m_scene->addItem(m_geomPath);
358 m_scene->centerView();
359 slotPositionChanged(0, false);
362 void GeometryWidget::addParameter(const QDomElement elem)
364 Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
365 m_extraGeometries.append(geometry);
366 m_timeline->addGeometry(geometry);
367 m_extraFactors.append(elem.attribute("factor", "1"));
368 m_extraGeometryNames.append(elem.attribute("name"));
369 //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
372 void GeometryWidget::slotSyncPosition(int relTimelinePos)
374 // do only sync if this effect is keyframable
375 if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
376 relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
377 if (relTimelinePos != m_timePos->getValue())
378 slotPositionChanged(relTimelinePos, false);
382 void GeometryWidget::slotRequestSeek(int pos)
384 if (KdenliveSettings::transitionfollowcursor())
385 emit seekToPos(m_clipPos + pos);
389 void GeometryWidget::slotPositionChanged(int pos, bool seek)
392 pos = m_timePos->getValue();
394 m_timePos->setValue(pos);
396 //m_timeline->blockSignals(true);
397 m_timeline->setValue(pos);
398 //m_timeline->blockSignals(false);
400 Mlt::GeometryItem item;
401 Mlt::GeometryItem previousItem;
402 if (m_geometry->fetch(&item, pos) || item.key() == false) {
404 m_rect->setEnabled(false);
405 m_scene->setEnabled(false);
406 m_ui.widgetGeometry->setEnabled(false);
407 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
408 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
411 m_rect->setEnabled(true);
412 m_scene->setEnabled(true);
413 m_ui.widgetGeometry->setEnabled(true);
414 m_ui.buttonAddDelete->setIcon(KIcon("list-remove"));
415 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
418 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
420 m_scene->removeItem(m_previous);
423 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
424 // previous frame already here, do nothing
427 if (m_previous == NULL) {
428 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
429 m_previous->setBrush(QColor(200, 200, 0, 20));
430 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
431 m_previous->setPos(previousItem.x(), previousItem.y());
432 m_previous->setZValue(-1);
433 m_previous->setEnabled(false);
436 m_previous->setPos(previousItem.x(), previousItem.y());
437 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
439 m_previous->setData(Qt::UserRole, previousItem.frame());
440 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
443 m_rect->setPos(item.x(), item.y());
444 m_rect->setRect(0, 0, item.w(), item.h());
446 m_opacity->blockSignals(true);
447 m_opacity->setValue(item.mix());
448 m_opacity->blockSignals(false);
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 if (!geom->fetch(&item, pos)) {
454 DragValue *widget = findChild<DragValue *>(name);
456 widget->blockSignals(true);
457 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
458 widget->blockSignals(false);
463 slotUpdateProperties();
465 if (seek && KdenliveSettings::transitionfollowcursor())
466 emit seekToPos(m_clipPos + pos);
469 void GeometryWidget::slotKeyframeMoved(int pos)
471 slotPositionChanged(pos);
472 slotUpdateGeometry();
473 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
476 void GeometryWidget::slotAddKeyframe(int pos)
478 Mlt::GeometryItem item;
480 pos = m_timePos->getValue();
482 QRectF r = m_rect->rect().normalized();
483 QPointF rectpos = m_rect->pos();
488 item.mix(m_opacity->value());
489 m_geometry->insert(item);
491 for (int i = 0; i < m_extraGeometries.count(); i++) {
492 Mlt::Geometry *geom = m_extraGeometries.at(i);
493 QString name = m_extraGeometryNames.at(i);
494 DragValue *widget = findChild<DragValue *>(name);
496 Mlt::GeometryItem item2;
498 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
503 m_timeline->update();
504 slotPositionChanged(pos, false);
505 emit parameterChanged();
508 void GeometryWidget::slotDeleteKeyframe(int pos)
510 Mlt::GeometryItem item;
512 pos = m_timePos->getValue();
513 // check there is more than one keyframe, do not allow to delete last one
514 if (m_geometry->next_key(&item, pos + 1)) {
515 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
518 m_geometry->remove(pos);
520 for (int i = 0; i < m_extraGeometries.count(); i++) {
521 Mlt::Geometry *geom = m_extraGeometries.at(i);
525 m_timeline->update();
527 m_scene->removeItem(m_geomPath);
528 m_geomPath->setPoints(m_geometry);
529 m_scene->addItem(m_geomPath);
531 slotPositionChanged(pos, false);
532 emit parameterChanged();
535 void GeometryWidget::slotPreviousKeyframe()
537 Mlt::GeometryItem item;
538 // Go to start if no keyframe is found
539 int currentPos = m_timePos->getValue();
541 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
544 slotPositionChanged(pos);
547 void GeometryWidget::slotNextKeyframe()
549 Mlt::GeometryItem item;
550 // Go to end if no keyframe is found
551 int pos = m_timeline->frameLength;
552 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
555 slotPositionChanged(pos);
558 void GeometryWidget::slotAddDeleteKeyframe()
560 Mlt::GeometryItem item;
561 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
564 slotDeleteKeyframe();
567 void GeometryWidget::slotUpdatePath()
569 if (!m_geomPath) return;
570 QList <QPointF> points = m_geomPath->points();
571 Mlt::GeometryItem item;
574 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
575 QPointF center = points.at(ix);
576 QSizeF size(item.w(), item.h());
577 item.x(center.x() - size.width()/2);
578 item.y(center.y() - size.height()/2);
579 m_geometry->insert(item);
580 pos = item.frame() + 1;
583 slotPositionChanged(-1, false);
584 emit parameterChanged();
588 void GeometryWidget::slotUpdateGeometry()
590 Mlt::GeometryItem item;
591 int pos = m_timePos->getValue();
593 // get keyframe and make sure it is the correct one
594 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
597 QRectF rectSize = m_rect->rect().normalized();
598 QPointF rectPos = m_rect->pos();
601 item.w(rectSize.width());
602 item.h(rectSize.height());
603 m_geometry->insert(item);
605 for (int i = 0; i < m_extraGeometries.count(); i++) {
606 Mlt::Geometry *geom = m_extraGeometries.at(i);
607 QString name = m_extraGeometryNames.at(i);
608 Mlt::GeometryItem item2;
609 DragValue *widget = findChild<DragValue *>(name);
610 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
611 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
616 m_scene->removeItem(m_geomPath);
617 m_geomPath->setPoints(m_geometry);
618 m_scene->addItem(m_geomPath);
620 emit parameterChanged();
623 void GeometryWidget::slotUpdateProperties()
625 QRectF rectSize = m_rect->rect().normalized();
626 QPointF rectPos = m_rect->pos();
628 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
629 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
631 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
633 m_spinX->blockSignals(true);
634 m_spinY->blockSignals(true);
635 m_spinWidth->blockSignals(true);
636 m_spinHeight->blockSignals(true);
637 m_spinSize->blockSignals(true);
639 m_spinX->setValue(rectPos.x());
640 m_spinY->setValue(rectPos.y());
641 m_spinWidth->setValue(rectSize.width());
642 m_spinHeight->setValue(rectSize.height());
643 m_spinSize->setValue(size);
645 m_spinX->blockSignals(false);
646 m_spinY->blockSignals(false);
647 m_spinWidth->blockSignals(false);
648 m_spinHeight->blockSignals(false);
649 m_spinSize->blockSignals(false);
653 void GeometryWidget::slotSetX(double value)
655 m_rect->setPos(value, m_spinY->value());
656 slotUpdateGeometry();
659 void GeometryWidget::slotSetY(double value)
661 m_rect->setPos(m_spinX->value(), value);
662 slotUpdateGeometry();
665 void GeometryWidget::slotSetWidth(double value)
667 m_rect->setRect(0, 0, value, m_spinHeight->value());
668 slotUpdateGeometry();
671 void GeometryWidget::slotSetHeight(double value)
673 m_rect->setRect(0, 0, m_spinWidth->value(), value);
674 slotUpdateGeometry();
677 void GeometryWidget::updateMonitorGeometry()
679 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
680 slotUpdateGeometry();
684 void GeometryWidget::slotResize(double value)
686 m_rect->setRect(0, 0,
687 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
688 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
689 slotUpdateGeometry();
693 void GeometryWidget::slotSetOpacity(double value)
695 int pos = m_timePos->getValue();
696 Mlt::GeometryItem item;
697 if (m_geometry->fetch(&item, pos) || item.key() == false)
700 m_geometry->insert(item);
701 emit parameterChanged();
705 void GeometryWidget::slotMoveLeft()
707 m_rect->setPos(0, m_rect->pos().y());
708 slotUpdateGeometry();
711 void GeometryWidget::slotCenterH()
713 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
714 slotUpdateGeometry();
717 void GeometryWidget::slotMoveRight()
719 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
720 slotUpdateGeometry();
723 void GeometryWidget::slotMoveTop()
725 m_rect->setPos(m_rect->pos().x(), 0);
726 slotUpdateGeometry();
729 void GeometryWidget::slotCenterV()
731 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
732 slotUpdateGeometry();
735 void GeometryWidget::slotMoveBottom()
737 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
738 slotUpdateGeometry();
742 void GeometryWidget::slotSetSynchronize(bool sync)
744 KdenliveSettings::setTransitionfollowcursor(sync);
746 emit seekToPos(m_clipPos + m_timePos->getValue());
749 void GeometryWidget::setFrameSize(QPoint size)
754 void GeometryWidget::slotAdjustToFrameSize()
756 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
757 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
759 m_spinWidth->blockSignals(true);
760 m_spinHeight->blockSignals(true);
761 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
762 m_spinHeight->setValue(m_frameSize.y());
763 m_spinWidth->blockSignals(false);
764 m_spinHeight->blockSignals(false);
765 updateMonitorGeometry();
768 void GeometryWidget::slotFitToWidth()
770 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
771 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
773 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
774 m_spinWidth->blockSignals(true);
775 m_spinHeight->blockSignals(true);
776 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
777 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
778 m_spinWidth->blockSignals(false);
779 m_spinHeight->blockSignals(false);
780 updateMonitorGeometry();
783 void GeometryWidget::slotFitToHeight()
785 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
786 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
788 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
789 m_spinWidth->blockSignals(true);
790 m_spinHeight->blockSignals(true);
791 m_spinHeight->setValue(m_monitor->render->renderHeight());
792 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
793 m_spinWidth->blockSignals(false);
794 m_spinHeight->blockSignals(false);
795 updateMonitorGeometry();
798 void GeometryWidget::slotResetKeyframes()
800 // Delete existing keyframes
801 Mlt::GeometryItem item;
802 while (!m_geometry->next_key(&item, 1)) {
803 m_geometry->remove(item.frame());
806 // Create neutral first keyframe
810 item.w(m_monitor->render->frameRenderWidth());
811 item.h(m_monitor->render->renderHeight());
813 m_geometry->insert(item);
814 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
816 m_scene->removeItem(m_geomPath);
817 m_geomPath->setPoints(m_geometry);
818 m_scene->addItem(m_geomPath);
820 slotPositionChanged(-1, false);
821 emit parameterChanged();
825 void GeometryWidget::importKeyframes(const QString &data, int maximum)
827 QStringList list = data.split(';', QString::SkipEmptyParts);
828 if (list.isEmpty()) return;
829 QPoint screenSize = m_frameSize;
830 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
831 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
833 // Clear existing keyframes
834 Mlt::GeometryItem item;
836 while (!m_geometry->next_key(&item, 0)) {
837 m_geometry->remove(item.frame());
841 if (maximum > 0 && list.count() > maximum) {
842 offset = list.count() / maximum;
844 for (int i = 0; i < list.count(); i += offset) {
845 QString geom = list.at(i);
846 if (geom.contains('=')) {
847 item.frame(geom.section('=', 0, 0).toInt());
848 geom = geom.section('=', 1);
851 if (geom.contains('/')) {
852 item.x(geom.section('/', 0, 0).toDouble());
853 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
859 if (geom.contains('x')) {
860 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
861 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
864 item.w(screenSize.x());
865 item.h(screenSize.y());
869 m_geometry->insert(item);
871 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
873 m_scene->removeItem(m_geomPath);
874 m_geomPath->setPoints(m_geometry);
875 m_scene->addItem(m_geomPath);
877 slotPositionChanged(-1, false);
878 emit parameterChanged();
882 #include "geometrywidget.moc"