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"));
390 void GeometryWidget::slotSyncPosition(int relTimelinePos)
392 // do only sync if this effect is keyframable
393 if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
394 relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
395 if (relTimelinePos != m_timePos->getValue())
396 slotPositionChanged(relTimelinePos, false);
400 int GeometryWidget::currentPosition() const
402 return m_inPoint + m_timePos->getValue();
405 void GeometryWidget::slotRequestSeek(int pos)
407 if (KdenliveSettings::transitionfollowcursor())
408 emit seekToPos(m_clipPos + pos);
412 void GeometryWidget::slotPositionChanged(int pos, bool seek)
415 pos = m_timePos->getValue();
417 m_timePos->setValue(pos);
419 //m_timeline->blockSignals(true);
420 m_timeline->setValue(pos);
421 //m_timeline->blockSignals(false);
423 Mlt::GeometryItem item;
424 Mlt::GeometryItem previousItem;
425 if (m_geometry->fetch(&item, pos) || item.key() == false) {
427 m_rect->setEnabled(false);
428 m_scene->setEnabled(false);
429 m_ui.widgetGeometry->setEnabled(false);
430 m_ui.buttonAddDelete->setIcon(KIcon("list-add"));
431 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
434 m_rect->setEnabled(true);
435 m_scene->setEnabled(true);
436 m_ui.widgetGeometry->setEnabled(true);
437 m_ui.buttonAddDelete->setIcon(KIcon("list-remove"));
438 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
441 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
443 m_scene->removeItem(m_previous);
446 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
447 // previous frame already here, do nothing
450 if (m_previous == NULL) {
451 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
452 m_previous->setBrush(QColor(200, 200, 0, 20));
453 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
454 m_previous->setPos(previousItem.x(), previousItem.y());
455 m_previous->setZValue(-1);
456 m_previous->setEnabled(false);
459 m_previous->setPos(previousItem.x(), previousItem.y());
460 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
462 m_previous->setData(Qt::UserRole, previousItem.frame());
463 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
466 m_rect->setPos(item.x(), item.y());
467 m_rect->setRect(0, 0, item.w(), item.h());
469 m_opacity->blockSignals(true);
470 m_opacity->setValue(item.mix());
471 m_opacity->blockSignals(false);
473 for (int i = 0; i < m_extraGeometries.count(); i++) {
474 Mlt::Geometry *geom = m_extraGeometries.at(i);
475 QString name = m_extraGeometryNames.at(i);
476 if (!geom->fetch(&item, pos)) {
477 DragValue *widget = findChild<DragValue *>(name);
479 widget->blockSignals(true);
480 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
481 widget->blockSignals(false);
486 slotUpdateProperties();
488 if (seek && KdenliveSettings::transitionfollowcursor())
489 emit seekToPos(m_clipPos + pos);
492 void GeometryWidget::slotKeyframeMoved(int pos)
494 slotPositionChanged(pos);
495 slotUpdateGeometry();
496 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
499 void GeometryWidget::slotAddKeyframe(int pos)
501 Mlt::GeometryItem item;
503 pos = m_timePos->getValue();
505 QRectF r = m_rect->rect().normalized();
506 QPointF rectpos = m_rect->pos();
511 item.mix(m_opacity->value());
512 m_geometry->insert(item);
514 for (int i = 0; i < m_extraGeometries.count(); i++) {
515 Mlt::Geometry *geom = m_extraGeometries.at(i);
516 QString name = m_extraGeometryNames.at(i);
517 DragValue *widget = findChild<DragValue *>(name);
519 Mlt::GeometryItem item2;
521 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
526 m_timeline->update();
527 slotPositionChanged(pos, false);
528 emit parameterChanged();
531 void GeometryWidget::slotDeleteKeyframe(int pos)
533 Mlt::GeometryItem item;
535 pos = m_timePos->getValue();
536 // check there is more than one keyframe, do not allow to delete last one
537 if (m_geometry->next_key(&item, pos + 1)) {
538 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
541 m_geometry->remove(pos);
543 for (int i = 0; i < m_extraGeometries.count(); i++) {
544 Mlt::Geometry *geom = m_extraGeometries.at(i);
548 m_timeline->update();
549 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
550 m_scene->removeItem(m_geomPath);
551 m_geomPath->setPoints(m_geometry);
552 m_scene->addItem(m_geomPath);
554 slotPositionChanged(pos, false);
555 emit parameterChanged();
558 void GeometryWidget::slotPreviousKeyframe()
560 Mlt::GeometryItem item;
561 // Go to start if no keyframe is found
562 int currentPos = m_timePos->getValue();
564 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
567 slotPositionChanged(pos);
570 void GeometryWidget::slotNextKeyframe()
572 Mlt::GeometryItem item;
573 // Go to end if no keyframe is found
574 int pos = m_timeline->frameLength;
575 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
578 slotPositionChanged(pos);
581 void GeometryWidget::slotAddDeleteKeyframe()
583 Mlt::GeometryItem item;
584 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
587 slotDeleteKeyframe();
590 void GeometryWidget::slotUpdatePath()
592 if (!m_geomPath) return;
593 QList <QPointF> points = m_geomPath->points();
594 Mlt::GeometryItem item;
597 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
598 QPointF center = points.at(ix);
599 QSizeF size(item.w(), item.h());
600 item.x(center.x() - size.width()/2);
601 item.y(center.y() - size.height()/2);
602 m_geometry->insert(item);
603 pos = item.frame() + 1;
606 slotPositionChanged(-1, false);
607 emit parameterChanged();
611 void GeometryWidget::slotUpdateGeometry()
613 Mlt::GeometryItem item;
614 int pos = m_timePos->getValue();
616 // get keyframe and make sure it is the correct one
617 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
620 QRectF rectSize = m_rect->rect().normalized();
621 QPointF rectPos = m_rect->pos();
624 item.w(rectSize.width());
625 item.h(rectSize.height());
626 m_geometry->insert(item);
628 for (int i = 0; i < m_extraGeometries.count(); i++) {
629 Mlt::Geometry *geom = m_extraGeometries.at(i);
630 QString name = m_extraGeometryNames.at(i);
631 Mlt::GeometryItem item2;
632 DragValue *widget = findChild<DragValue *>(name);
633 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
634 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
638 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
639 m_scene->removeItem(m_geomPath);
640 m_geomPath->setPoints(m_geometry);
641 m_scene->addItem(m_geomPath);
643 emit parameterChanged();
646 void GeometryWidget::slotUpdateProperties()
648 QRectF rectSize = m_rect->rect().normalized();
649 QPointF rectPos = m_rect->pos();
651 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
652 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
654 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
656 m_spinX->blockSignals(true);
657 m_spinY->blockSignals(true);
658 m_spinWidth->blockSignals(true);
659 m_spinHeight->blockSignals(true);
660 m_spinSize->blockSignals(true);
662 m_spinX->setValue(rectPos.x());
663 m_spinY->setValue(rectPos.y());
664 m_spinWidth->setValue(rectSize.width());
665 m_spinHeight->setValue(rectSize.height());
666 m_spinSize->setValue(size);
668 m_spinX->blockSignals(false);
669 m_spinY->blockSignals(false);
670 m_spinWidth->blockSignals(false);
671 m_spinHeight->blockSignals(false);
672 m_spinSize->blockSignals(false);
676 void GeometryWidget::slotSetX(double value)
678 m_rect->setPos(value, m_spinY->value());
679 slotUpdateGeometry();
682 void GeometryWidget::slotSetY(double value)
684 m_rect->setPos(m_spinX->value(), value);
685 slotUpdateGeometry();
688 void GeometryWidget::slotSetWidth(double value)
690 m_rect->setRect(0, 0, value, m_spinHeight->value());
691 slotUpdateGeometry();
694 void GeometryWidget::slotSetHeight(double value)
696 m_rect->setRect(0, 0, m_spinWidth->value(), value);
697 slotUpdateGeometry();
700 void GeometryWidget::updateMonitorGeometry()
702 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
703 slotUpdateGeometry();
707 void GeometryWidget::slotResize(double value)
709 m_rect->setRect(0, 0,
710 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
711 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
712 slotUpdateGeometry();
716 void GeometryWidget::slotSetOpacity(double value)
718 int pos = m_timePos->getValue();
719 Mlt::GeometryItem item;
720 if (m_geometry->fetch(&item, pos) || item.key() == false)
723 m_geometry->insert(item);
724 emit parameterChanged();
728 void GeometryWidget::slotMoveLeft()
730 m_rect->setPos(0, m_rect->pos().y());
731 slotUpdateGeometry();
734 void GeometryWidget::slotCenterH()
736 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
737 slotUpdateGeometry();
740 void GeometryWidget::slotMoveRight()
742 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
743 slotUpdateGeometry();
746 void GeometryWidget::slotMoveTop()
748 m_rect->setPos(m_rect->pos().x(), 0);
749 slotUpdateGeometry();
752 void GeometryWidget::slotCenterV()
754 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
755 slotUpdateGeometry();
758 void GeometryWidget::slotMoveBottom()
760 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
761 slotUpdateGeometry();
765 void GeometryWidget::slotSetSynchronize(bool sync)
767 KdenliveSettings::setTransitionfollowcursor(sync);
769 emit seekToPos(m_clipPos + m_timePos->getValue());
772 void GeometryWidget::setFrameSize(QPoint size)
777 void GeometryWidget::slotAdjustToFrameSize()
779 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
780 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
782 m_spinWidth->blockSignals(true);
783 m_spinHeight->blockSignals(true);
784 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
785 m_spinHeight->setValue(m_frameSize.y());
786 m_spinWidth->blockSignals(false);
787 m_spinHeight->blockSignals(false);
788 updateMonitorGeometry();
791 void GeometryWidget::slotFitToWidth()
793 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
794 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
796 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
797 m_spinWidth->blockSignals(true);
798 m_spinHeight->blockSignals(true);
799 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
800 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
801 m_spinWidth->blockSignals(false);
802 m_spinHeight->blockSignals(false);
803 updateMonitorGeometry();
806 void GeometryWidget::slotFitToHeight()
808 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
809 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
811 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
812 m_spinWidth->blockSignals(true);
813 m_spinHeight->blockSignals(true);
814 m_spinHeight->setValue(m_monitor->render->renderHeight());
815 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
816 m_spinWidth->blockSignals(false);
817 m_spinHeight->blockSignals(false);
818 updateMonitorGeometry();
821 void GeometryWidget::slotResetKeyframes()
823 // Delete existing keyframes
824 Mlt::GeometryItem item;
825 while (!m_geometry->next_key(&item, 1)) {
826 m_geometry->remove(item.frame());
829 // Delete extra geometry keyframes too
830 for (int i = 0; i < m_extraGeometries.count(); i++) {
831 Mlt::Geometry *geom = m_extraGeometries.at(i);
832 while (!geom->next_key(&item, 1)) {
833 geom->remove(item.frame());
837 // Create neutral first keyframe
841 item.w(m_monitor->render->frameRenderWidth());
842 item.h(m_monitor->render->renderHeight());
844 m_geometry->insert(item);
845 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
846 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
847 m_scene->removeItem(m_geomPath);
848 m_geomPath->setPoints(m_geometry);
849 m_scene->addItem(m_geomPath);
851 slotPositionChanged(-1, false);
852 emit parameterChanged();
855 void GeometryWidget::slotResetNextKeyframes()
857 // Delete keyframes after cursor pos
858 Mlt::GeometryItem item;
859 int pos = m_timePos->getValue();
860 while (!m_geometry->next_key(&item, pos)) {
861 m_geometry->remove(item.frame());
864 // Delete extra geometry keyframes too
865 for (int i = 0; i < m_extraGeometries.count(); i++) {
866 Mlt::Geometry *geom = m_extraGeometries.at(i);
867 while (!geom->next_key(&item, pos)) {
868 geom->remove(item.frame());
872 // Make sure we have at least one keyframe
873 if (m_geometry->next_key(&item, 0)) {
877 item.w(m_monitor->render->frameRenderWidth());
878 item.h(m_monitor->render->renderHeight());
880 m_geometry->insert(item);
882 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
883 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
884 m_scene->removeItem(m_geomPath);
885 m_geomPath->setPoints(m_geometry);
886 m_scene->addItem(m_geomPath);
888 slotPositionChanged(-1, false);
889 emit parameterChanged();
892 void GeometryWidget::slotResetPreviousKeyframes()
894 // Delete keyframes before cursor pos
895 Mlt::GeometryItem item;
897 while (!m_geometry->next_key(&item, pos) && pos < m_timePos->getValue()) {
898 pos = item.frame() + 1;
899 m_geometry->remove(item.frame());
902 // Delete extra geometry keyframes too
903 for (int i = 0; i < m_extraGeometries.count(); i++) {
904 Mlt::Geometry *geom = m_extraGeometries.at(i);
906 while (!geom->next_key(&item, pos) && pos < m_timePos->getValue()) {
907 pos = item.frame() + 1;
908 geom->remove(item.frame());
912 // Make sure we have at least one keyframe
913 if (!m_geometry->next_key(&item, 0)) {
917 item.w(m_monitor->render->frameRenderWidth());
918 item.h(m_monitor->render->renderHeight());
920 m_geometry->insert(item);
926 item.w(m_monitor->render->frameRenderWidth());
927 item.h(m_monitor->render->renderHeight());
929 m_geometry->insert(item);
931 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
932 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
933 m_scene->removeItem(m_geomPath);
934 m_geomPath->setPoints(m_geometry);
935 m_scene->addItem(m_geomPath);
937 slotPositionChanged(-1, false);
938 emit parameterChanged();
941 void GeometryWidget::importKeyframes(const QString &data, int maximum)
943 QStringList list = data.split(';', QString::SkipEmptyParts);
944 if (list.isEmpty()) return;
945 QPoint screenSize = m_frameSize;
946 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
947 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
949 // Clear existing keyframes
950 Mlt::GeometryItem item;
952 while (!m_geometry->next_key(&item, 0)) {
953 m_geometry->remove(item.frame());
957 if (maximum > 0 && list.count() > maximum) {
958 offset = list.count() / maximum;
960 for (int i = 0; i < list.count(); i += offset) {
961 QString geom = list.at(i);
962 if (geom.contains('=')) {
963 item.frame(geom.section('=', 0, 0).toInt());
964 geom = geom.section('=', 1);
967 if (geom.contains('/')) {
968 item.x(geom.section('/', 0, 0).toDouble());
969 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
975 if (geom.contains('x')) {
976 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
977 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
980 item.w(screenSize.x());
981 item.h(screenSize.y());
985 m_geometry->insert(item);
987 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
988 if (m_geomPath && KdenliveSettings::onmonitoreffects_geometryshowpath()) {
989 m_scene->removeItem(m_geomPath);
990 m_geomPath->setPoints(m_geometry);
991 m_scene->addItem(m_geomPath);
993 slotPositionChanged(-1, false);
994 emit parameterChanged();
997 void GeometryWidget::slotUpdateRange(int inPoint, int outPoint)
1000 m_outPoint = outPoint;
1001 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
1002 m_timePos->setRange(0, m_outPoint - m_inPoint);
1005 #include "geometrywidget.moc"