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("draw-path"), i18n("Show path"), this, SLOT(slotShowPath(bool)), true, KdenliveSettings::onmonitoreffects_geometryshowpath());
61 edit->addCustomButton(KIcon("transform-crop"), i18n("Show previous keyframe"), this, SLOT(slotShowPreviousKeyFrame(bool)), true, KdenliveSettings::onmonitoreffects_geometryshowprevious());
62 m_scene = edit->getScene();
66 Setup of timeline and keyframe controls
69 ((QGridLayout *)(m_ui.widgetTimeWrapper->layout()))->addWidget(m_timePos, 1, 5);
71 QVBoxLayout *layout = new QVBoxLayout(m_ui.frameTimeline);
72 m_timeline = new KeyframeHelper(m_ui.frameTimeline);
73 layout->addWidget(m_timeline);
74 layout->setContentsMargins(0, 0, 0, 0);
76 int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
77 QSize iconSize(size, size);
79 m_ui.buttonPrevious->setIcon(KIcon("media-skip-backward"));
80 m_ui.buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
81 m_ui.buttonPrevious->setIconSize(iconSize);
82 m_ui.buttonNext->setIcon(KIcon("media-skip-forward"));
83 m_ui.buttonNext->setToolTip(i18n("Go to next keyframe"));
84 m_ui.buttonNext->setIconSize(iconSize);
85 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
86 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
87 m_ui.buttonAddDelete->setIconSize(iconSize);
89 connect(m_timeline, SIGNAL(requestSeek(int)), this, SLOT(slotRequestSeek(int)));
90 connect(m_timeline, SIGNAL(keyframeMoved(int)), this, SLOT(slotKeyframeMoved(int)));
91 connect(m_timeline, SIGNAL(addKeyframe(int)), this, SLOT(slotAddKeyframe(int)));
92 connect(m_timeline, SIGNAL(removeKeyframe(int)), this, SLOT(slotDeleteKeyframe(int)));
93 connect(m_timePos, SIGNAL(timeCodeEditingFinished()), this, SLOT(slotPositionChanged()));
94 connect(m_ui.buttonPrevious, SIGNAL(clicked()), this, SLOT(slotPreviousKeyframe()));
95 connect(m_ui.buttonNext, SIGNAL(clicked()), this, SLOT(slotNextKeyframe()));
96 connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
98 m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
99 m_ui.horizontalLayout->addWidget(m_spinX, 0, 0);
101 m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
102 m_ui.horizontalLayout->addWidget(m_spinY, 0, 1);
104 m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this);
105 m_ui.horizontalLayout->addWidget(m_spinWidth, 0, 2);
107 m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this);
108 m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 3);
110 m_ui.horizontalLayout->setColumnStretch(4, 10);
112 QMenu *menu = new QMenu(this);
113 QAction *adjustSize = new QAction(KIcon("zoom-fit-best"), i18n("Adjust to original size"), this);
114 connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
115 QAction *fitToWidth = new QAction(KIcon("zoom-fit-width"), i18n("Fit to width"), this);
116 connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
117 QAction *fitToHeight = new QAction(KIcon("zoom-fit-height"), i18n("Fit to height"), this);
118 connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
120 QAction *importKeyframes = new QAction(i18n("Import keyframes from clip"), this);
121 connect(importKeyframes, SIGNAL(triggered()), this, SIGNAL(importClipKeyframes()));
122 menu->addAction(importKeyframes);
123 QAction *resetKeyframes = new QAction(i18n("Reset all keyframes"), this);
124 connect(resetKeyframes, SIGNAL(triggered()), this, SLOT(slotResetKeyframes()));
125 menu->addAction(resetKeyframes);
127 QAction *resetNextKeyframes = new QAction(i18n("Reset keyframes after cursor"), this);
128 connect(resetNextKeyframes, SIGNAL(triggered()), this, SLOT(slotResetNextKeyframes()));
129 menu->addAction(resetNextKeyframes);
130 QAction *resetPreviousKeyframes = new QAction(i18n("Reset keyframes before cursor"), this);
131 connect(resetPreviousKeyframes, SIGNAL(triggered()), this, SLOT(slotResetPreviousKeyframes()));
132 menu->addAction(resetPreviousKeyframes);
133 menu->addSeparator();
135 QAction *syncTimeline = new QAction(KIcon("insert-link"), i18n("Synchronize with timeline cursor"), this);
136 syncTimeline->setCheckable(true);
137 syncTimeline->setChecked(KdenliveSettings::transitionfollowcursor());
138 connect(syncTimeline, SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
139 menu->addAction(syncTimeline);
141 QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
142 connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
143 QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
144 connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
145 QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
146 connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
147 QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
148 connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
149 QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
150 connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
151 QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
152 connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
154 m_ui.buttonOptions->setMenu(menu);
155 m_ui.buttonOptions->setIcon(KIcon("configure"));
156 m_ui.buttonOptions->setToolTip(i18n("Options"));
157 m_ui.buttonOptions->setIconSize(iconSize);
159 QHBoxLayout *alignLayout = new QHBoxLayout;
160 alignLayout->setSpacing(0);
161 QToolButton *alignButton = new QToolButton;
162 alignButton->setDefaultAction(alignleft);
163 alignButton->setAutoRaise(true);
164 alignLayout->addWidget(alignButton);
166 alignButton = new QToolButton;
167 alignButton->setDefaultAction(alignhcenter);
168 alignButton->setAutoRaise(true);
169 alignLayout->addWidget(alignButton);
171 alignButton = new QToolButton;
172 alignButton->setDefaultAction(alignright);
173 alignButton->setAutoRaise(true);
174 alignLayout->addWidget(alignButton);
176 alignButton = new QToolButton;
177 alignButton->setDefaultAction(aligntop);
178 alignButton->setAutoRaise(true);
179 alignLayout->addWidget(alignButton);
181 alignButton = new QToolButton;
182 alignButton->setDefaultAction(alignvcenter);
183 alignButton->setAutoRaise(true);
184 alignLayout->addWidget(alignButton);
186 alignButton = new QToolButton;
187 alignButton->setDefaultAction(alignbottom);
188 alignButton->setAutoRaise(true);
189 alignLayout->addWidget(alignButton);
191 alignButton = new QToolButton;
192 alignButton->setDefaultAction(adjustSize);
193 alignButton->setAutoRaise(true);
194 alignLayout->addWidget(alignButton);
196 alignButton = new QToolButton;
197 alignButton->setDefaultAction(fitToWidth);
198 alignButton->setAutoRaise(true);
199 alignLayout->addWidget(alignButton);
201 alignButton = new QToolButton;
202 alignButton->setDefaultAction(fitToHeight);
203 alignButton->setAutoRaise(true);
204 alignLayout->addWidget(alignButton);
205 alignLayout->addStretch(10);
207 m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
208 //m_ui.horizontalLayout->addStretch(10);
210 m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
211 m_ui.horizontalLayout2->addWidget(m_spinSize);
213 m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
214 m_ui.horizontalLayout2->addWidget(m_opacity);
218 m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
219 m_rotateX->setObjectName("rotate_x");
220 m_ui.horizontalLayout3->addWidget(m_rotateX);
221 m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800, -1, QString(), true, this);
222 m_rotateY->setObjectName("rotate_y");
223 m_ui.horizontalLayout3->addWidget(m_rotateY);
224 m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800, -1, QString(), true, this);
225 m_rotateZ->setObjectName("rotate_z");
226 m_ui.horizontalLayout3->addWidget(m_rotateZ);
227 connect(m_rotateX, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
228 connect(m_rotateY, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
229 connect(m_rotateZ, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
233 Setup of geometry controls
236 connect(m_spinX, SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
237 connect(m_spinY, SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
238 connect(m_spinWidth, SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
239 connect(m_spinHeight, SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
241 connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
243 connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
245 /*connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
246 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
247 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
248 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
249 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
250 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
254 Setup of configuration controls
257 connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
258 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
261 GeometryWidget::~GeometryWidget()
263 m_scene->setEnabled(false);
272 m_scene->removeItem(m_rect);
276 m_scene->removeItem(m_geomPath);
279 if (m_previous) delete m_previous;
281 m_extraGeometryNames.clear();
282 m_extraFactors.clear();
283 while (!m_extraGeometries.isEmpty()) {
284 Mlt::Geometry *g = m_extraGeometries.takeFirst();
289 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
291 KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
292 slotPositionChanged(-1, false);
295 void GeometryWidget::slotShowPath(bool show)
297 KdenliveSettings::setOnmonitoreffects_geometryshowpath(show);
299 if (show) m_scene->addItem(m_geomPath);
300 else m_scene->removeItem(m_geomPath);
302 slotPositionChanged(-1, false);
305 void GeometryWidget::updateTimecodeFormat()
307 m_timePos->slotUpdateTimeCodeFormat();
310 QString GeometryWidget::getValue() const
312 return m_geometry->serialise();
315 QString GeometryWidget::getExtraValue(const QString &name) const
317 int ix = m_extraGeometryNames.indexOf(name);
318 QString val = m_extraGeometries.at(ix)->serialise();
319 if (!val.contains("=")) val = val.section('/', 0, 0);
321 QStringList list = val.split(';', QString::SkipEmptyParts);
323 val.append(list.takeFirst().section('/', 0, 0));
324 foreach (const QString &value, list) {
325 val.append(';' + value.section('/', 0, 0));
331 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
333 m_inPoint = minframe;
334 m_outPoint = maxframe;
337 m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
339 m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
341 if (elem.attribute("fixed") == "1" || maxframe < minframe) {
342 // Keyframes are disabled
343 m_ui.widgetTimeWrapper->setHidden(true);
345 m_ui.widgetTimeWrapper->setHidden(false);
346 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
348 m_timePos->setRange(0, m_outPoint - m_inPoint);
351 if (elem.attribute("opacity") == "false") {
352 m_opacity->setHidden(true);
353 m_ui.horizontalLayout2->addStretch(2);
356 Mlt::GeometryItem item;
357 m_geometry->fetch(&item, 0);
359 m_scene->removeItem(m_rect);
363 m_scene->removeItem(m_geomPath);
366 m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
367 m_rect->setPos(item.x(), item.y());
368 m_rect->setZValue(0);
369 m_scene->addItem(m_rect);
370 connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
371 m_geomPath = new OnMonitorPathItem(m_monitor->render->dar());
372 connect(m_geomPath, SIGNAL(changed()), this, SLOT(slotUpdatePath()));
373 m_geomPath->setPen(QPen(Qt::red));
374 m_geomPath->setPoints(m_geometry);
375 if (KdenliveSettings::onmonitoreffects_geometryshowpath())
376 m_scene->addItem(m_geomPath);
377 m_scene->centerView();
378 slotPositionChanged(0, false);
381 void GeometryWidget::addParameter(const QDomElement elem)
383 Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
384 m_extraGeometries.append(geometry);
385 m_timeline->addGeometry(geometry);
386 m_extraFactors.append(elem.attribute("factor", "1"));
387 m_extraGeometryNames.append(elem.attribute("name"));
388 //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
391 void GeometryWidget::slotSyncPosition(int relTimelinePos)
393 // do only sync if this effect is keyframable
394 if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
395 relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
396 if (relTimelinePos != m_timePos->getValue())
397 slotPositionChanged(relTimelinePos, false);
401 int GeometryWidget::currentPosition() const
403 return m_inPoint + m_timePos->getValue();
406 void GeometryWidget::slotRequestSeek(int pos)
408 if (KdenliveSettings::transitionfollowcursor())
409 emit seekToPos(m_clipPos + pos);
413 void GeometryWidget::slotPositionChanged(int pos, bool seek)
416 pos = m_timePos->getValue();
418 m_timePos->setValue(pos);
420 //m_timeline->blockSignals(true);
421 m_timeline->setValue(pos);
422 //m_timeline->blockSignals(false);
424 Mlt::GeometryItem item;
425 Mlt::GeometryItem previousItem;
426 if (m_geometry->fetch(&item, pos) || item.key() == false) {
428 m_rect->setEnabled(false);
429 m_scene->setEnabled(false);
430 m_ui.widgetGeometry->setEnabled(false);
431 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
432 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
435 m_rect->setEnabled(true);
436 m_scene->setEnabled(true);
437 m_ui.widgetGeometry->setEnabled(true);
438 m_ui.buttonAddDelete->setIcon(KIcon("list-remove"));
439 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
442 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
444 m_scene->removeItem(m_previous);
447 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
448 // previous frame already here, do nothing
451 if (m_previous == NULL) {
452 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
453 m_previous->setBrush(QColor(200, 200, 0, 20));
454 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
455 m_previous->setPos(previousItem.x(), previousItem.y());
456 m_previous->setZValue(-1);
457 m_previous->setEnabled(false);
460 m_previous->setPos(previousItem.x(), previousItem.y());
461 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
463 m_previous->setData(Qt::UserRole, previousItem.frame());
464 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
467 m_rect->setPos(item.x(), item.y());
468 m_rect->setRect(0, 0, item.w(), item.h());
470 m_opacity->blockSignals(true);
471 m_opacity->setValue(item.mix());
472 m_opacity->blockSignals(false);
474 for (int i = 0; i < m_extraGeometries.count(); i++) {
475 Mlt::Geometry *geom = m_extraGeometries.at(i);
476 QString name = m_extraGeometryNames.at(i);
477 if (!geom->fetch(&item, pos)) {
478 DragValue *widget = findChild<DragValue *>(name);
480 widget->blockSignals(true);
481 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
482 widget->blockSignals(false);
487 slotUpdateProperties();
489 if (seek && KdenliveSettings::transitionfollowcursor())
490 emit seekToPos(m_clipPos + pos);
493 void GeometryWidget::slotKeyframeMoved(int pos)
495 slotPositionChanged(pos);
496 slotUpdateGeometry();
497 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
500 void GeometryWidget::slotAddKeyframe(int pos)
502 Mlt::GeometryItem item;
504 pos = m_timePos->getValue();
506 QRectF r = m_rect->rect().normalized();
507 QPointF rectpos = m_rect->pos();
512 item.mix(m_opacity->value());
513 m_geometry->insert(item);
515 for (int i = 0; i < m_extraGeometries.count(); i++) {
516 Mlt::Geometry *geom = m_extraGeometries.at(i);
517 QString name = m_extraGeometryNames.at(i);
518 DragValue *widget = findChild<DragValue *>(name);
520 Mlt::GeometryItem item2;
522 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
527 m_timeline->update();
528 slotPositionChanged(pos, false);
529 emit parameterChanged();
532 void GeometryWidget::slotDeleteKeyframe(int pos)
534 Mlt::GeometryItem item;
536 pos = m_timePos->getValue();
537 // check there is more than one keyframe, do not allow to delete last one
538 if (m_geometry->next_key(&item, pos + 1)) {
539 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
542 m_geometry->remove(pos);
544 for (int i = 0; i < m_extraGeometries.count(); i++) {
545 Mlt::Geometry *geom = m_extraGeometries.at(i);
549 m_timeline->update();
550 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
551 m_scene->removeItem(m_geomPath);
552 m_geomPath->setPoints(m_geometry);
553 m_scene->addItem(m_geomPath);
555 slotPositionChanged(pos, false);
556 emit parameterChanged();
559 void GeometryWidget::slotPreviousKeyframe()
561 Mlt::GeometryItem item;
562 // Go to start if no keyframe is found
563 int currentPos = m_timePos->getValue();
565 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
568 slotPositionChanged(pos);
571 void GeometryWidget::slotNextKeyframe()
573 Mlt::GeometryItem item;
574 // Go to end if no keyframe is found
575 int pos = m_timeline->frameLength;
576 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
579 slotPositionChanged(pos);
582 void GeometryWidget::slotAddDeleteKeyframe()
584 Mlt::GeometryItem item;
585 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
588 slotDeleteKeyframe();
591 void GeometryWidget::slotUpdatePath()
593 if (!m_geomPath) return;
594 QList <QPointF> points = m_geomPath->points();
595 Mlt::GeometryItem item;
598 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
599 QPointF center = points.at(ix);
600 QSizeF size(item.w(), item.h());
601 item.x(center.x() - size.width()/2);
602 item.y(center.y() - size.height()/2);
603 m_geometry->insert(item);
604 pos = item.frame() + 1;
607 slotPositionChanged(-1, false);
608 emit parameterChanged();
612 void GeometryWidget::slotUpdateGeometry()
614 Mlt::GeometryItem item;
615 int pos = m_timePos->getValue();
617 // get keyframe and make sure it is the correct one
618 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
621 QRectF rectSize = m_rect->rect().normalized();
622 QPointF rectPos = m_rect->pos();
625 item.w(rectSize.width());
626 item.h(rectSize.height());
627 m_geometry->insert(item);
629 for (int i = 0; i < m_extraGeometries.count(); i++) {
630 Mlt::Geometry *geom = m_extraGeometries.at(i);
631 QString name = m_extraGeometryNames.at(i);
632 Mlt::GeometryItem item2;
633 DragValue *widget = findChild<DragValue *>(name);
634 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
635 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
639 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
640 m_scene->removeItem(m_geomPath);
641 m_geomPath->setPoints(m_geometry);
642 m_scene->addItem(m_geomPath);
644 emit parameterChanged();
647 void GeometryWidget::slotUpdateProperties()
649 QRectF rectSize = m_rect->rect().normalized();
650 QPointF rectPos = m_rect->pos();
652 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
653 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
655 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
657 m_spinX->blockSignals(true);
658 m_spinY->blockSignals(true);
659 m_spinWidth->blockSignals(true);
660 m_spinHeight->blockSignals(true);
661 m_spinSize->blockSignals(true);
663 m_spinX->setValue(rectPos.x());
664 m_spinY->setValue(rectPos.y());
665 m_spinWidth->setValue(rectSize.width());
666 m_spinHeight->setValue(rectSize.height());
667 m_spinSize->setValue(size);
669 m_spinX->blockSignals(false);
670 m_spinY->blockSignals(false);
671 m_spinWidth->blockSignals(false);
672 m_spinHeight->blockSignals(false);
673 m_spinSize->blockSignals(false);
677 void GeometryWidget::slotSetX(double value)
679 m_rect->setPos(value, m_spinY->value());
680 slotUpdateGeometry();
683 void GeometryWidget::slotSetY(double value)
685 m_rect->setPos(m_spinX->value(), value);
686 slotUpdateGeometry();
689 void GeometryWidget::slotSetWidth(double value)
691 m_rect->setRect(0, 0, value, m_spinHeight->value());
692 slotUpdateGeometry();
695 void GeometryWidget::slotSetHeight(double value)
697 m_rect->setRect(0, 0, m_spinWidth->value(), value);
698 slotUpdateGeometry();
701 void GeometryWidget::updateMonitorGeometry()
703 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
704 slotUpdateGeometry();
708 void GeometryWidget::slotResize(double value)
710 m_rect->setRect(0, 0,
711 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
712 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
713 slotUpdateGeometry();
717 void GeometryWidget::slotSetOpacity(double value)
719 int pos = m_timePos->getValue();
720 Mlt::GeometryItem item;
721 if (m_geometry->fetch(&item, pos) || item.key() == false)
724 m_geometry->insert(item);
725 emit parameterChanged();
729 void GeometryWidget::slotMoveLeft()
731 m_rect->setPos(0, m_rect->pos().y());
732 slotUpdateGeometry();
735 void GeometryWidget::slotCenterH()
737 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
738 slotUpdateGeometry();
741 void GeometryWidget::slotMoveRight()
743 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
744 slotUpdateGeometry();
747 void GeometryWidget::slotMoveTop()
749 m_rect->setPos(m_rect->pos().x(), 0);
750 slotUpdateGeometry();
753 void GeometryWidget::slotCenterV()
755 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
756 slotUpdateGeometry();
759 void GeometryWidget::slotMoveBottom()
761 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
762 slotUpdateGeometry();
766 void GeometryWidget::slotSetSynchronize(bool sync)
768 KdenliveSettings::setTransitionfollowcursor(sync);
770 emit seekToPos(m_clipPos + m_timePos->getValue());
773 void GeometryWidget::setFrameSize(QPoint size)
778 void GeometryWidget::slotAdjustToFrameSize()
780 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
781 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
783 m_spinWidth->blockSignals(true);
784 m_spinHeight->blockSignals(true);
785 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
786 m_spinHeight->setValue(m_frameSize.y());
787 m_spinWidth->blockSignals(false);
788 m_spinHeight->blockSignals(false);
789 updateMonitorGeometry();
792 void GeometryWidget::slotFitToWidth()
794 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
795 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
797 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
798 m_spinWidth->blockSignals(true);
799 m_spinHeight->blockSignals(true);
800 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
801 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
802 m_spinWidth->blockSignals(false);
803 m_spinHeight->blockSignals(false);
804 updateMonitorGeometry();
807 void GeometryWidget::slotFitToHeight()
809 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
810 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
812 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
813 m_spinWidth->blockSignals(true);
814 m_spinHeight->blockSignals(true);
815 m_spinHeight->setValue(m_monitor->render->renderHeight());
816 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
817 m_spinWidth->blockSignals(false);
818 m_spinHeight->blockSignals(false);
819 updateMonitorGeometry();
822 void GeometryWidget::slotResetKeyframes()
824 // Delete existing keyframes
825 Mlt::GeometryItem item;
826 while (!m_geometry->next_key(&item, 1)) {
827 m_geometry->remove(item.frame());
830 // Create neutral first keyframe
834 item.w(m_monitor->render->frameRenderWidth());
835 item.h(m_monitor->render->renderHeight());
837 m_geometry->insert(item);
838 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
839 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
840 m_scene->removeItem(m_geomPath);
841 m_geomPath->setPoints(m_geometry);
842 m_scene->addItem(m_geomPath);
844 slotPositionChanged(-1, false);
845 emit parameterChanged();
848 void GeometryWidget::slotResetNextKeyframes()
850 // Delete keyframes after cursor pos
851 Mlt::GeometryItem item;
852 int pos = m_timePos->getValue();
853 while (!m_geometry->next_key(&item, pos)) {
854 m_geometry->remove(item.frame());
857 // Make sure we have at least one keyframe
858 if (m_geometry->next_key(&item, 0)) {
862 item.w(m_monitor->render->frameRenderWidth());
863 item.h(m_monitor->render->renderHeight());
865 m_geometry->insert(item);
867 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
868 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
869 m_scene->removeItem(m_geomPath);
870 m_geomPath->setPoints(m_geometry);
871 m_scene->addItem(m_geomPath);
873 slotPositionChanged(-1, false);
874 emit parameterChanged();
877 void GeometryWidget::slotResetPreviousKeyframes()
879 // Delete keyframes before cursor pos
880 Mlt::GeometryItem item;
882 while (!m_geometry->next_key(&item, pos) && pos < m_timePos->getValue()) {
883 pos = item.frame() + 1;
884 m_geometry->remove(item.frame());
887 // Make sure we have at least one keyframe
888 if (!m_geometry->next_key(&item, 0)) {
892 item.w(m_monitor->render->frameRenderWidth());
893 item.h(m_monitor->render->renderHeight());
895 m_geometry->insert(item);
901 item.w(m_monitor->render->frameRenderWidth());
902 item.h(m_monitor->render->renderHeight());
904 m_geometry->insert(item);
906 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
907 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
908 m_scene->removeItem(m_geomPath);
909 m_geomPath->setPoints(m_geometry);
910 m_scene->addItem(m_geomPath);
912 slotPositionChanged(-1, false);
913 emit parameterChanged();
916 void GeometryWidget::importKeyframes(const QString &data, int maximum)
918 QStringList list = data.split(';', QString::SkipEmptyParts);
919 if (list.isEmpty()) return;
920 QPoint screenSize = m_frameSize;
921 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
922 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
924 // Clear existing keyframes
925 Mlt::GeometryItem item;
927 while (!m_geometry->next_key(&item, 0)) {
928 m_geometry->remove(item.frame());
932 if (maximum > 0 && list.count() > maximum) {
933 offset = list.count() / maximum;
935 for (int i = 0; i < list.count(); i += offset) {
936 QString geom = list.at(i);
937 if (geom.contains('=')) {
938 item.frame(geom.section('=', 0, 0).toInt());
939 geom = geom.section('=', 1);
942 if (geom.contains('/')) {
943 item.x(geom.section('/', 0, 0).toDouble());
944 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
950 if (geom.contains('x')) {
951 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
952 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
955 item.w(screenSize.x());
956 item.h(screenSize.y());
960 m_geometry->insert(item);
962 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
963 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
964 m_scene->removeItem(m_geomPath);
965 m_geomPath->setPoints(m_geometry);
966 m_scene->addItem(m_geomPath);
968 slotPositionChanged(-1, false);
969 emit parameterChanged();
972 void GeometryWidget::slotUpdateRange(int inPoint, int outPoint)
975 m_outPoint = outPoint;
976 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
977 m_timePos->setRange(0, m_outPoint - m_inPoint);
980 #include "geometrywidget.moc"