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);
330 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 int GeometryWidget::currentPosition() const
384 return m_inPoint + m_timePos->getValue();
387 void GeometryWidget::slotRequestSeek(int pos)
389 if (KdenliveSettings::transitionfollowcursor())
390 emit seekToPos(m_clipPos + pos);
394 void GeometryWidget::slotPositionChanged(int pos, bool seek)
397 pos = m_timePos->getValue();
399 m_timePos->setValue(pos);
401 //m_timeline->blockSignals(true);
402 m_timeline->setValue(pos);
403 //m_timeline->blockSignals(false);
405 Mlt::GeometryItem item;
406 Mlt::GeometryItem previousItem;
407 if (m_geometry->fetch(&item, pos) || item.key() == false) {
409 m_rect->setEnabled(false);
410 m_scene->setEnabled(false);
411 m_ui.widgetGeometry->setEnabled(false);
412 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
413 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
416 m_rect->setEnabled(true);
417 m_scene->setEnabled(true);
418 m_ui.widgetGeometry->setEnabled(true);
419 m_ui.buttonAddDelete->setIcon(KIcon("list-remove"));
420 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
423 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
425 m_scene->removeItem(m_previous);
428 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
429 // previous frame already here, do nothing
432 if (m_previous == NULL) {
433 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
434 m_previous->setBrush(QColor(200, 200, 0, 20));
435 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
436 m_previous->setPos(previousItem.x(), previousItem.y());
437 m_previous->setZValue(-1);
438 m_previous->setEnabled(false);
441 m_previous->setPos(previousItem.x(), previousItem.y());
442 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
444 m_previous->setData(Qt::UserRole, previousItem.frame());
445 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
448 m_rect->setPos(item.x(), item.y());
449 m_rect->setRect(0, 0, item.w(), item.h());
451 m_opacity->blockSignals(true);
452 m_opacity->setValue(item.mix());
453 m_opacity->blockSignals(false);
455 for (int i = 0; i < m_extraGeometries.count(); i++) {
456 Mlt::Geometry *geom = m_extraGeometries.at(i);
457 QString name = m_extraGeometryNames.at(i);
458 if (!geom->fetch(&item, pos)) {
459 DragValue *widget = findChild<DragValue *>(name);
461 widget->blockSignals(true);
462 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
463 widget->blockSignals(false);
468 slotUpdateProperties();
470 if (seek && KdenliveSettings::transitionfollowcursor())
471 emit seekToPos(m_clipPos + pos);
474 void GeometryWidget::slotKeyframeMoved(int pos)
476 slotPositionChanged(pos);
477 slotUpdateGeometry();
478 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
481 void GeometryWidget::slotAddKeyframe(int pos)
483 Mlt::GeometryItem item;
485 pos = m_timePos->getValue();
487 QRectF r = m_rect->rect().normalized();
488 QPointF rectpos = m_rect->pos();
493 item.mix(m_opacity->value());
494 m_geometry->insert(item);
496 for (int i = 0; i < m_extraGeometries.count(); i++) {
497 Mlt::Geometry *geom = m_extraGeometries.at(i);
498 QString name = m_extraGeometryNames.at(i);
499 DragValue *widget = findChild<DragValue *>(name);
501 Mlt::GeometryItem item2;
503 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
508 m_timeline->update();
509 slotPositionChanged(pos, false);
510 emit parameterChanged();
513 void GeometryWidget::slotDeleteKeyframe(int pos)
515 Mlt::GeometryItem item;
517 pos = m_timePos->getValue();
518 // check there is more than one keyframe, do not allow to delete last one
519 if (m_geometry->next_key(&item, pos + 1)) {
520 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
523 m_geometry->remove(pos);
525 for (int i = 0; i < m_extraGeometries.count(); i++) {
526 Mlt::Geometry *geom = m_extraGeometries.at(i);
530 m_timeline->update();
532 m_scene->removeItem(m_geomPath);
533 m_geomPath->setPoints(m_geometry);
534 m_scene->addItem(m_geomPath);
536 slotPositionChanged(pos, false);
537 emit parameterChanged();
540 void GeometryWidget::slotPreviousKeyframe()
542 Mlt::GeometryItem item;
543 // Go to start if no keyframe is found
544 int currentPos = m_timePos->getValue();
546 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
549 slotPositionChanged(pos);
552 void GeometryWidget::slotNextKeyframe()
554 Mlt::GeometryItem item;
555 // Go to end if no keyframe is found
556 int pos = m_timeline->frameLength;
557 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
560 slotPositionChanged(pos);
563 void GeometryWidget::slotAddDeleteKeyframe()
565 Mlt::GeometryItem item;
566 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
569 slotDeleteKeyframe();
572 void GeometryWidget::slotUpdatePath()
574 if (!m_geomPath) return;
575 QList <QPointF> points = m_geomPath->points();
576 Mlt::GeometryItem item;
579 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
580 QPointF center = points.at(ix);
581 QSizeF size(item.w(), item.h());
582 item.x(center.x() - size.width()/2);
583 item.y(center.y() - size.height()/2);
584 m_geometry->insert(item);
585 pos = item.frame() + 1;
588 slotPositionChanged(-1, false);
589 emit parameterChanged();
593 void GeometryWidget::slotUpdateGeometry()
595 Mlt::GeometryItem item;
596 int pos = m_timePos->getValue();
598 // get keyframe and make sure it is the correct one
599 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
602 QRectF rectSize = m_rect->rect().normalized();
603 QPointF rectPos = m_rect->pos();
606 item.w(rectSize.width());
607 item.h(rectSize.height());
608 m_geometry->insert(item);
610 for (int i = 0; i < m_extraGeometries.count(); i++) {
611 Mlt::Geometry *geom = m_extraGeometries.at(i);
612 QString name = m_extraGeometryNames.at(i);
613 Mlt::GeometryItem item2;
614 DragValue *widget = findChild<DragValue *>(name);
615 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
616 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
621 m_scene->removeItem(m_geomPath);
622 m_geomPath->setPoints(m_geometry);
623 m_scene->addItem(m_geomPath);
625 emit parameterChanged();
628 void GeometryWidget::slotUpdateProperties()
630 QRectF rectSize = m_rect->rect().normalized();
631 QPointF rectPos = m_rect->pos();
633 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
634 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
636 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
638 m_spinX->blockSignals(true);
639 m_spinY->blockSignals(true);
640 m_spinWidth->blockSignals(true);
641 m_spinHeight->blockSignals(true);
642 m_spinSize->blockSignals(true);
644 m_spinX->setValue(rectPos.x());
645 m_spinY->setValue(rectPos.y());
646 m_spinWidth->setValue(rectSize.width());
647 m_spinHeight->setValue(rectSize.height());
648 m_spinSize->setValue(size);
650 m_spinX->blockSignals(false);
651 m_spinY->blockSignals(false);
652 m_spinWidth->blockSignals(false);
653 m_spinHeight->blockSignals(false);
654 m_spinSize->blockSignals(false);
658 void GeometryWidget::slotSetX(double value)
660 m_rect->setPos(value, m_spinY->value());
661 slotUpdateGeometry();
664 void GeometryWidget::slotSetY(double value)
666 m_rect->setPos(m_spinX->value(), value);
667 slotUpdateGeometry();
670 void GeometryWidget::slotSetWidth(double value)
672 m_rect->setRect(0, 0, value, m_spinHeight->value());
673 slotUpdateGeometry();
676 void GeometryWidget::slotSetHeight(double value)
678 m_rect->setRect(0, 0, m_spinWidth->value(), value);
679 slotUpdateGeometry();
682 void GeometryWidget::updateMonitorGeometry()
684 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
685 slotUpdateGeometry();
689 void GeometryWidget::slotResize(double value)
691 m_rect->setRect(0, 0,
692 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
693 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
694 slotUpdateGeometry();
698 void GeometryWidget::slotSetOpacity(double value)
700 int pos = m_timePos->getValue();
701 Mlt::GeometryItem item;
702 if (m_geometry->fetch(&item, pos) || item.key() == false)
705 m_geometry->insert(item);
706 emit parameterChanged();
710 void GeometryWidget::slotMoveLeft()
712 m_rect->setPos(0, m_rect->pos().y());
713 slotUpdateGeometry();
716 void GeometryWidget::slotCenterH()
718 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
719 slotUpdateGeometry();
722 void GeometryWidget::slotMoveRight()
724 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
725 slotUpdateGeometry();
728 void GeometryWidget::slotMoveTop()
730 m_rect->setPos(m_rect->pos().x(), 0);
731 slotUpdateGeometry();
734 void GeometryWidget::slotCenterV()
736 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
737 slotUpdateGeometry();
740 void GeometryWidget::slotMoveBottom()
742 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
743 slotUpdateGeometry();
747 void GeometryWidget::slotSetSynchronize(bool sync)
749 KdenliveSettings::setTransitionfollowcursor(sync);
751 emit seekToPos(m_clipPos + m_timePos->getValue());
754 void GeometryWidget::setFrameSize(QPoint size)
759 void GeometryWidget::slotAdjustToFrameSize()
761 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
762 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
764 m_spinWidth->blockSignals(true);
765 m_spinHeight->blockSignals(true);
766 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
767 m_spinHeight->setValue(m_frameSize.y());
768 m_spinWidth->blockSignals(false);
769 m_spinHeight->blockSignals(false);
770 updateMonitorGeometry();
773 void GeometryWidget::slotFitToWidth()
775 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
776 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
778 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
779 m_spinWidth->blockSignals(true);
780 m_spinHeight->blockSignals(true);
781 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
782 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
783 m_spinWidth->blockSignals(false);
784 m_spinHeight->blockSignals(false);
785 updateMonitorGeometry();
788 void GeometryWidget::slotFitToHeight()
790 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
791 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
793 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
794 m_spinWidth->blockSignals(true);
795 m_spinHeight->blockSignals(true);
796 m_spinHeight->setValue(m_monitor->render->renderHeight());
797 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
798 m_spinWidth->blockSignals(false);
799 m_spinHeight->blockSignals(false);
800 updateMonitorGeometry();
803 void GeometryWidget::slotResetKeyframes()
805 // Delete existing keyframes
806 Mlt::GeometryItem item;
807 while (!m_geometry->next_key(&item, 1)) {
808 m_geometry->remove(item.frame());
811 // Create neutral first keyframe
815 item.w(m_monitor->render->frameRenderWidth());
816 item.h(m_monitor->render->renderHeight());
818 m_geometry->insert(item);
819 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
821 m_scene->removeItem(m_geomPath);
822 m_geomPath->setPoints(m_geometry);
823 m_scene->addItem(m_geomPath);
825 slotPositionChanged(-1, false);
826 emit parameterChanged();
830 void GeometryWidget::importKeyframes(const QString &data, int maximum)
832 QStringList list = data.split(';', QString::SkipEmptyParts);
833 if (list.isEmpty()) return;
834 QPoint screenSize = m_frameSize;
835 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
836 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
838 // Clear existing keyframes
839 Mlt::GeometryItem item;
841 while (!m_geometry->next_key(&item, 0)) {
842 m_geometry->remove(item.frame());
846 if (maximum > 0 && list.count() > maximum) {
847 offset = list.count() / maximum;
849 for (int i = 0; i < list.count(); i += offset) {
850 QString geom = list.at(i);
851 if (geom.contains('=')) {
852 item.frame(geom.section('=', 0, 0).toInt());
853 geom = geom.section('=', 1);
856 if (geom.contains('/')) {
857 item.x(geom.section('/', 0, 0).toDouble());
858 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
864 if (geom.contains('x')) {
865 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
866 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
869 item.w(screenSize.x());
870 item.h(screenSize.y());
874 m_geometry->insert(item);
876 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
878 m_scene->removeItem(m_geomPath);
879 m_geomPath->setPoints(m_geometry);
880 m_scene->addItem(m_geomPath);
882 slotPositionChanged(-1, false);
883 emit parameterChanged();
886 void GeometryWidget::slotUpdateRange(int inPoint, int outPoint)
889 m_outPoint = outPoint;
890 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
891 m_timePos->setRange(0, m_outPoint - m_inPoint);
894 #include "geometrywidget.moc"