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 all keyframes"), this);
123 connect(resetKeyframes, SIGNAL(triggered()), this, SLOT(slotResetKeyframes()));
124 menu->addAction(resetKeyframes);
126 QAction *resetNextKeyframes = new QAction(i18n("Reset keyframes after cursor"), this);
127 connect(resetNextKeyframes, SIGNAL(triggered()), this, SLOT(slotResetNextKeyframes()));
128 menu->addAction(resetNextKeyframes);
129 QAction *resetPreviousKeyframes = new QAction(i18n("Reset keyframes before cursor"), this);
130 connect(resetPreviousKeyframes, SIGNAL(triggered()), this, SLOT(slotResetPreviousKeyframes()));
131 menu->addAction(resetPreviousKeyframes);
132 menu->addSeparator();
134 QAction *syncTimeline = new QAction(KIcon("insert-link"), i18n("Synchronize with timeline cursor"), this);
135 syncTimeline->setCheckable(true);
136 syncTimeline->setChecked(KdenliveSettings::transitionfollowcursor());
137 connect(syncTimeline, SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
138 menu->addAction(syncTimeline);
140 QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
141 connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
142 QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
143 connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
144 QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
145 connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
146 QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
147 connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
148 QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
149 connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
150 QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
151 connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
153 m_ui.buttonOptions->setMenu(menu);
154 m_ui.buttonOptions->setIcon(KIcon("configure"));
155 m_ui.buttonOptions->setToolTip(i18n("Options"));
156 m_ui.buttonOptions->setIconSize(iconSize);
158 QHBoxLayout *alignLayout = new QHBoxLayout;
159 alignLayout->setSpacing(0);
160 QToolButton *alignButton = new QToolButton;
161 alignButton->setDefaultAction(alignleft);
162 alignButton->setAutoRaise(true);
163 alignLayout->addWidget(alignButton);
165 alignButton = new QToolButton;
166 alignButton->setDefaultAction(alignhcenter);
167 alignButton->setAutoRaise(true);
168 alignLayout->addWidget(alignButton);
170 alignButton = new QToolButton;
171 alignButton->setDefaultAction(alignright);
172 alignButton->setAutoRaise(true);
173 alignLayout->addWidget(alignButton);
175 alignButton = new QToolButton;
176 alignButton->setDefaultAction(aligntop);
177 alignButton->setAutoRaise(true);
178 alignLayout->addWidget(alignButton);
180 alignButton = new QToolButton;
181 alignButton->setDefaultAction(alignvcenter);
182 alignButton->setAutoRaise(true);
183 alignLayout->addWidget(alignButton);
185 alignButton = new QToolButton;
186 alignButton->setDefaultAction(alignbottom);
187 alignButton->setAutoRaise(true);
188 alignLayout->addWidget(alignButton);
190 alignButton = new QToolButton;
191 alignButton->setDefaultAction(adjustSize);
192 alignButton->setAutoRaise(true);
193 alignLayout->addWidget(alignButton);
195 alignButton = new QToolButton;
196 alignButton->setDefaultAction(fitToWidth);
197 alignButton->setAutoRaise(true);
198 alignLayout->addWidget(alignButton);
200 alignButton = new QToolButton;
201 alignButton->setDefaultAction(fitToHeight);
202 alignButton->setAutoRaise(true);
203 alignLayout->addWidget(alignButton);
204 alignLayout->addStretch(10);
206 m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
207 //m_ui.horizontalLayout->addStretch(10);
209 m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
210 m_ui.horizontalLayout2->addWidget(m_spinSize);
212 m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
213 m_ui.horizontalLayout2->addWidget(m_opacity);
217 m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
218 m_rotateX->setObjectName("rotate_x");
219 m_ui.horizontalLayout3->addWidget(m_rotateX);
220 m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800, -1, QString(), true, this);
221 m_rotateY->setObjectName("rotate_y");
222 m_ui.horizontalLayout3->addWidget(m_rotateY);
223 m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800, -1, QString(), true, this);
224 m_rotateZ->setObjectName("rotate_z");
225 m_ui.horizontalLayout3->addWidget(m_rotateZ);
226 connect(m_rotateX, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
227 connect(m_rotateY, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
228 connect(m_rotateZ, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
232 Setup of geometry controls
235 connect(m_spinX, SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
236 connect(m_spinY, SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
237 connect(m_spinWidth, SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
238 connect(m_spinHeight, SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
240 connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
242 connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
244 /*connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
245 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
246 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
247 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
248 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
249 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
253 Setup of configuration controls
256 connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
257 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
260 GeometryWidget::~GeometryWidget()
262 m_scene->setEnabled(false);
271 m_scene->removeItem(m_rect);
275 m_scene->removeItem(m_geomPath);
278 if (m_previous) delete m_previous;
280 m_extraGeometryNames.clear();
281 m_extraFactors.clear();
282 while (!m_extraGeometries.isEmpty()) {
283 Mlt::Geometry *g = m_extraGeometries.takeFirst();
288 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
290 KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
291 slotPositionChanged(-1, false);
294 void GeometryWidget::updateTimecodeFormat()
296 m_timePos->slotUpdateTimeCodeFormat();
299 QString GeometryWidget::getValue() const
301 return m_geometry->serialise();
304 QString GeometryWidget::getExtraValue(const QString &name) const
306 int ix = m_extraGeometryNames.indexOf(name);
307 QString val = m_extraGeometries.at(ix)->serialise();
308 if (!val.contains("=")) val = val.section('/', 0, 0);
310 QStringList list = val.split(';', QString::SkipEmptyParts);
312 val.append(list.takeFirst().section('/', 0, 0));
313 foreach (const QString &value, list) {
314 val.append(';' + value.section('/', 0, 0));
320 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
322 m_inPoint = minframe;
323 m_outPoint = maxframe;
326 m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
328 m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
330 if (elem.attribute("fixed") == "1" || maxframe < minframe) {
331 // Keyframes are disabled
332 m_ui.widgetTimeWrapper->setHidden(true);
334 m_ui.widgetTimeWrapper->setHidden(false);
335 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
337 m_timePos->setRange(0, m_outPoint - m_inPoint);
340 if (elem.attribute("opacity") == "false") {
341 m_opacity->setHidden(true);
342 m_ui.horizontalLayout2->addStretch(2);
345 Mlt::GeometryItem item;
346 m_geometry->fetch(&item, 0);
348 m_scene->removeItem(m_rect);
352 m_scene->removeItem(m_geomPath);
355 m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
356 m_rect->setPos(item.x(), item.y());
357 m_rect->setZValue(0);
358 m_scene->addItem(m_rect);
359 connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
360 m_geomPath = new OnMonitorPathItem(m_monitor->render->dar());
361 connect(m_geomPath, SIGNAL(changed()), this, SLOT(slotUpdatePath()));
362 m_geomPath->setPen(QPen(Qt::red));
363 m_geomPath->setPoints(m_geometry);
364 m_scene->addItem(m_geomPath);
365 m_scene->centerView();
366 slotPositionChanged(0, false);
369 void GeometryWidget::addParameter(const QDomElement elem)
371 Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
372 m_extraGeometries.append(geometry);
373 m_timeline->addGeometry(geometry);
374 m_extraFactors.append(elem.attribute("factor", "1"));
375 m_extraGeometryNames.append(elem.attribute("name"));
376 //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
379 void GeometryWidget::slotSyncPosition(int relTimelinePos)
381 // do only sync if this effect is keyframable
382 if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
383 relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
384 if (relTimelinePos != m_timePos->getValue())
385 slotPositionChanged(relTimelinePos, false);
389 int GeometryWidget::currentPosition() const
391 return m_inPoint + m_timePos->getValue();
394 void GeometryWidget::slotRequestSeek(int pos)
396 if (KdenliveSettings::transitionfollowcursor())
397 emit seekToPos(m_clipPos + pos);
401 void GeometryWidget::slotPositionChanged(int pos, bool seek)
404 pos = m_timePos->getValue();
406 m_timePos->setValue(pos);
408 //m_timeline->blockSignals(true);
409 m_timeline->setValue(pos);
410 //m_timeline->blockSignals(false);
412 Mlt::GeometryItem item;
413 Mlt::GeometryItem previousItem;
414 if (m_geometry->fetch(&item, pos) || item.key() == false) {
416 m_rect->setEnabled(false);
417 m_scene->setEnabled(false);
418 m_ui.widgetGeometry->setEnabled(false);
419 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
420 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
423 m_rect->setEnabled(true);
424 m_scene->setEnabled(true);
425 m_ui.widgetGeometry->setEnabled(true);
426 m_ui.buttonAddDelete->setIcon(KIcon("list-remove"));
427 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
430 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
432 m_scene->removeItem(m_previous);
435 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
436 // previous frame already here, do nothing
439 if (m_previous == NULL) {
440 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
441 m_previous->setBrush(QColor(200, 200, 0, 20));
442 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
443 m_previous->setPos(previousItem.x(), previousItem.y());
444 m_previous->setZValue(-1);
445 m_previous->setEnabled(false);
448 m_previous->setPos(previousItem.x(), previousItem.y());
449 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
451 m_previous->setData(Qt::UserRole, previousItem.frame());
452 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
455 m_rect->setPos(item.x(), item.y());
456 m_rect->setRect(0, 0, item.w(), item.h());
458 m_opacity->blockSignals(true);
459 m_opacity->setValue(item.mix());
460 m_opacity->blockSignals(false);
462 for (int i = 0; i < m_extraGeometries.count(); i++) {
463 Mlt::Geometry *geom = m_extraGeometries.at(i);
464 QString name = m_extraGeometryNames.at(i);
465 if (!geom->fetch(&item, pos)) {
466 DragValue *widget = findChild<DragValue *>(name);
468 widget->blockSignals(true);
469 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
470 widget->blockSignals(false);
475 slotUpdateProperties();
477 if (seek && KdenliveSettings::transitionfollowcursor())
478 emit seekToPos(m_clipPos + pos);
481 void GeometryWidget::slotKeyframeMoved(int pos)
483 slotPositionChanged(pos);
484 slotUpdateGeometry();
485 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
488 void GeometryWidget::slotAddKeyframe(int pos)
490 Mlt::GeometryItem item;
492 pos = m_timePos->getValue();
494 QRectF r = m_rect->rect().normalized();
495 QPointF rectpos = m_rect->pos();
500 item.mix(m_opacity->value());
501 m_geometry->insert(item);
503 for (int i = 0; i < m_extraGeometries.count(); i++) {
504 Mlt::Geometry *geom = m_extraGeometries.at(i);
505 QString name = m_extraGeometryNames.at(i);
506 DragValue *widget = findChild<DragValue *>(name);
508 Mlt::GeometryItem item2;
510 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
515 m_timeline->update();
516 slotPositionChanged(pos, false);
517 emit parameterChanged();
520 void GeometryWidget::slotDeleteKeyframe(int pos)
522 Mlt::GeometryItem item;
524 pos = m_timePos->getValue();
525 // check there is more than one keyframe, do not allow to delete last one
526 if (m_geometry->next_key(&item, pos + 1)) {
527 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
530 m_geometry->remove(pos);
532 for (int i = 0; i < m_extraGeometries.count(); i++) {
533 Mlt::Geometry *geom = m_extraGeometries.at(i);
537 m_timeline->update();
539 m_scene->removeItem(m_geomPath);
540 m_geomPath->setPoints(m_geometry);
541 m_scene->addItem(m_geomPath);
543 slotPositionChanged(pos, false);
544 emit parameterChanged();
547 void GeometryWidget::slotPreviousKeyframe()
549 Mlt::GeometryItem item;
550 // Go to start if no keyframe is found
551 int currentPos = m_timePos->getValue();
553 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
556 slotPositionChanged(pos);
559 void GeometryWidget::slotNextKeyframe()
561 Mlt::GeometryItem item;
562 // Go to end if no keyframe is found
563 int pos = m_timeline->frameLength;
564 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
567 slotPositionChanged(pos);
570 void GeometryWidget::slotAddDeleteKeyframe()
572 Mlt::GeometryItem item;
573 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
576 slotDeleteKeyframe();
579 void GeometryWidget::slotUpdatePath()
581 if (!m_geomPath) return;
582 QList <QPointF> points = m_geomPath->points();
583 Mlt::GeometryItem item;
586 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
587 QPointF center = points.at(ix);
588 QSizeF size(item.w(), item.h());
589 item.x(center.x() - size.width()/2);
590 item.y(center.y() - size.height()/2);
591 m_geometry->insert(item);
592 pos = item.frame() + 1;
595 slotPositionChanged(-1, false);
596 emit parameterChanged();
600 void GeometryWidget::slotUpdateGeometry()
602 Mlt::GeometryItem item;
603 int pos = m_timePos->getValue();
605 // get keyframe and make sure it is the correct one
606 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
609 QRectF rectSize = m_rect->rect().normalized();
610 QPointF rectPos = m_rect->pos();
613 item.w(rectSize.width());
614 item.h(rectSize.height());
615 m_geometry->insert(item);
617 for (int i = 0; i < m_extraGeometries.count(); i++) {
618 Mlt::Geometry *geom = m_extraGeometries.at(i);
619 QString name = m_extraGeometryNames.at(i);
620 Mlt::GeometryItem item2;
621 DragValue *widget = findChild<DragValue *>(name);
622 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
623 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
628 m_scene->removeItem(m_geomPath);
629 m_geomPath->setPoints(m_geometry);
630 m_scene->addItem(m_geomPath);
632 emit parameterChanged();
635 void GeometryWidget::slotUpdateProperties()
637 QRectF rectSize = m_rect->rect().normalized();
638 QPointF rectPos = m_rect->pos();
640 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
641 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
643 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
645 m_spinX->blockSignals(true);
646 m_spinY->blockSignals(true);
647 m_spinWidth->blockSignals(true);
648 m_spinHeight->blockSignals(true);
649 m_spinSize->blockSignals(true);
651 m_spinX->setValue(rectPos.x());
652 m_spinY->setValue(rectPos.y());
653 m_spinWidth->setValue(rectSize.width());
654 m_spinHeight->setValue(rectSize.height());
655 m_spinSize->setValue(size);
657 m_spinX->blockSignals(false);
658 m_spinY->blockSignals(false);
659 m_spinWidth->blockSignals(false);
660 m_spinHeight->blockSignals(false);
661 m_spinSize->blockSignals(false);
665 void GeometryWidget::slotSetX(double value)
667 m_rect->setPos(value, m_spinY->value());
668 slotUpdateGeometry();
671 void GeometryWidget::slotSetY(double value)
673 m_rect->setPos(m_spinX->value(), value);
674 slotUpdateGeometry();
677 void GeometryWidget::slotSetWidth(double value)
679 m_rect->setRect(0, 0, value, m_spinHeight->value());
680 slotUpdateGeometry();
683 void GeometryWidget::slotSetHeight(double value)
685 m_rect->setRect(0, 0, m_spinWidth->value(), value);
686 slotUpdateGeometry();
689 void GeometryWidget::updateMonitorGeometry()
691 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
692 slotUpdateGeometry();
696 void GeometryWidget::slotResize(double value)
698 m_rect->setRect(0, 0,
699 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
700 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
701 slotUpdateGeometry();
705 void GeometryWidget::slotSetOpacity(double value)
707 int pos = m_timePos->getValue();
708 Mlt::GeometryItem item;
709 if (m_geometry->fetch(&item, pos) || item.key() == false)
712 m_geometry->insert(item);
713 emit parameterChanged();
717 void GeometryWidget::slotMoveLeft()
719 m_rect->setPos(0, m_rect->pos().y());
720 slotUpdateGeometry();
723 void GeometryWidget::slotCenterH()
725 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
726 slotUpdateGeometry();
729 void GeometryWidget::slotMoveRight()
731 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
732 slotUpdateGeometry();
735 void GeometryWidget::slotMoveTop()
737 m_rect->setPos(m_rect->pos().x(), 0);
738 slotUpdateGeometry();
741 void GeometryWidget::slotCenterV()
743 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
744 slotUpdateGeometry();
747 void GeometryWidget::slotMoveBottom()
749 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
750 slotUpdateGeometry();
754 void GeometryWidget::slotSetSynchronize(bool sync)
756 KdenliveSettings::setTransitionfollowcursor(sync);
758 emit seekToPos(m_clipPos + m_timePos->getValue());
761 void GeometryWidget::setFrameSize(QPoint size)
766 void GeometryWidget::slotAdjustToFrameSize()
768 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
769 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
771 m_spinWidth->blockSignals(true);
772 m_spinHeight->blockSignals(true);
773 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
774 m_spinHeight->setValue(m_frameSize.y());
775 m_spinWidth->blockSignals(false);
776 m_spinHeight->blockSignals(false);
777 updateMonitorGeometry();
780 void GeometryWidget::slotFitToWidth()
782 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
783 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
785 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
786 m_spinWidth->blockSignals(true);
787 m_spinHeight->blockSignals(true);
788 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
789 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
790 m_spinWidth->blockSignals(false);
791 m_spinHeight->blockSignals(false);
792 updateMonitorGeometry();
795 void GeometryWidget::slotFitToHeight()
797 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
798 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
800 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
801 m_spinWidth->blockSignals(true);
802 m_spinHeight->blockSignals(true);
803 m_spinHeight->setValue(m_monitor->render->renderHeight());
804 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
805 m_spinWidth->blockSignals(false);
806 m_spinHeight->blockSignals(false);
807 updateMonitorGeometry();
810 void GeometryWidget::slotResetKeyframes()
812 // Delete existing keyframes
813 Mlt::GeometryItem item;
814 while (!m_geometry->next_key(&item, 1)) {
815 m_geometry->remove(item.frame());
818 // Create neutral first keyframe
822 item.w(m_monitor->render->frameRenderWidth());
823 item.h(m_monitor->render->renderHeight());
825 m_geometry->insert(item);
826 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
828 m_scene->removeItem(m_geomPath);
829 m_geomPath->setPoints(m_geometry);
830 m_scene->addItem(m_geomPath);
832 slotPositionChanged(-1, false);
833 emit parameterChanged();
836 void GeometryWidget::slotResetNextKeyframes()
838 // Delete keyframes after cursor pos
839 Mlt::GeometryItem item;
840 int pos = m_timePos->getValue();
841 while (!m_geometry->next_key(&item, pos)) {
842 m_geometry->remove(item.frame());
845 // Make sure we have at least one keyframe
846 if (m_geometry->next_key(&item, 0)) {
850 item.w(m_monitor->render->frameRenderWidth());
851 item.h(m_monitor->render->renderHeight());
853 m_geometry->insert(item);
855 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
857 m_scene->removeItem(m_geomPath);
858 m_geomPath->setPoints(m_geometry);
859 m_scene->addItem(m_geomPath);
861 slotPositionChanged(-1, false);
862 emit parameterChanged();
865 void GeometryWidget::slotResetPreviousKeyframes()
867 // Delete keyframes before cursor pos
868 Mlt::GeometryItem item;
870 while (!m_geometry->next_key(&item, pos) && pos < m_timePos->getValue()) {
871 pos = item.frame() + 1;
872 m_geometry->remove(item.frame());
875 // Make sure we have at least one keyframe
876 if (!m_geometry->next_key(&item, 0)) {
880 item.w(m_monitor->render->frameRenderWidth());
881 item.h(m_monitor->render->renderHeight());
883 m_geometry->insert(item);
889 item.w(m_monitor->render->frameRenderWidth());
890 item.h(m_monitor->render->renderHeight());
892 m_geometry->insert(item);
894 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
896 m_scene->removeItem(m_geomPath);
897 m_geomPath->setPoints(m_geometry);
898 m_scene->addItem(m_geomPath);
900 slotPositionChanged(-1, false);
901 emit parameterChanged();
904 void GeometryWidget::importKeyframes(const QString &data, int maximum)
906 QStringList list = data.split(';', QString::SkipEmptyParts);
907 if (list.isEmpty()) return;
908 QPoint screenSize = m_frameSize;
909 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
910 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
912 // Clear existing keyframes
913 Mlt::GeometryItem item;
915 while (!m_geometry->next_key(&item, 0)) {
916 m_geometry->remove(item.frame());
920 if (maximum > 0 && list.count() > maximum) {
921 offset = list.count() / maximum;
923 for (int i = 0; i < list.count(); i += offset) {
924 QString geom = list.at(i);
925 if (geom.contains('=')) {
926 item.frame(geom.section('=', 0, 0).toInt());
927 geom = geom.section('=', 1);
930 if (geom.contains('/')) {
931 item.x(geom.section('/', 0, 0).toDouble());
932 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
938 if (geom.contains('x')) {
939 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
940 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
943 item.w(screenSize.x());
944 item.h(screenSize.y());
948 m_geometry->insert(item);
950 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
952 m_scene->removeItem(m_geomPath);
953 m_geomPath->setPoints(m_geometry);
954 m_scene->addItem(m_geomPath);
956 slotPositionChanged(-1, false);
957 emit parameterChanged();
960 void GeometryWidget::slotUpdateRange(int inPoint, int outPoint)
963 m_outPoint = outPoint;
964 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
965 m_timePos->setRange(0, m_outPoint - m_inPoint);
968 #include "geometrywidget.moc"