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, 6);
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("document-new"));
85 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
86 m_ui.buttonAddDelete->setIconSize(iconSize);
88 m_ui.buttonSync->setIcon(KIcon("insert-link"));
89 m_ui.buttonSync->setToolTip(i18n("Synchronize with timeline cursor"));
90 m_ui.buttonSync->setChecked(KdenliveSettings::transitionfollowcursor());
91 m_ui.buttonSync->setIconSize(iconSize);
93 connect(m_timeline, SIGNAL(requestSeek(int)), this, SLOT(slotRequestSeek(int)));
94 connect(m_timeline, SIGNAL(keyframeMoved(int)), this, SLOT(slotKeyframeMoved(int)));
95 connect(m_timeline, SIGNAL(addKeyframe(int)), this, SLOT(slotAddKeyframe(int)));
96 connect(m_timeline, SIGNAL(removeKeyframe(int)), this, SLOT(slotDeleteKeyframe(int)));
97 connect(m_timePos, SIGNAL(editingFinished()), this, SLOT(slotPositionChanged()));
98 connect(m_ui.buttonPrevious, SIGNAL(clicked()), this, SLOT(slotPreviousKeyframe()));
99 connect(m_ui.buttonNext, SIGNAL(clicked()), this, SLOT(slotNextKeyframe()));
100 connect(m_ui.buttonAddDelete, SIGNAL(clicked()), this, SLOT(slotAddDeleteKeyframe()));
101 connect(m_ui.buttonSync, SIGNAL(toggled(bool)), this, SLOT(slotSetSynchronize(bool)));
103 m_spinX = new DragValue(i18nc("x axis position", "X"), 0, 0, -99000, 99000, -1, QString(), false, this);
104 m_ui.horizontalLayout->addWidget(m_spinX, 0, 0);
106 m_spinY = new DragValue(i18nc("y axis position", "Y"), 0, 0, -99000, 99000, -1, QString(), false, this);
107 m_ui.horizontalLayout->addWidget(m_spinY, 0, 1);
109 m_spinWidth = new DragValue(i18nc("Frame width", "W"), m_monitor->render->frameRenderWidth(), 0, 1, 99000, -1, QString(), false, this);
110 m_ui.horizontalLayout->addWidget(m_spinWidth, 0, 2);
112 m_spinHeight = new DragValue(i18nc("Frame height", "H"), m_monitor->render->renderHeight(), 0, 1, 99000, -1, QString(), false, this);
113 m_ui.horizontalLayout->addWidget(m_spinHeight, 0, 3);
115 m_ui.horizontalLayout->setColumnStretch(4, 10);
117 QMenu *menu = new QMenu(this);
118 QAction *adjustSize = new QAction(i18n("Adjust to original size"), this);
119 connect(adjustSize, SIGNAL(triggered()), this, SLOT(slotAdjustToFrameSize()));
120 menu->addAction(adjustSize);
121 QAction *fitToWidth = new QAction(i18n("Fit to width"), this);
122 connect(fitToWidth, SIGNAL(triggered()), this, SLOT(slotFitToWidth()));
123 menu->addAction(fitToWidth);
124 QAction *fitToHeight = new QAction(i18n("Fit to height"), this);
125 connect(fitToHeight, SIGNAL(triggered()), this, SLOT(slotFitToHeight()));
126 menu->addAction(fitToHeight);
127 menu->addSeparator();
128 QAction *importKeyframes = new QAction(i18n("Import keyframes from clip"), this);
129 connect(importKeyframes, SIGNAL(triggered()), this, SIGNAL(importClipKeyframes()));
130 menu->addAction(importKeyframes);
131 menu->addSeparator();
132 QAction *alignleft = new QAction(KIcon("kdenlive-align-left"), i18n("Align left"), this);
133 connect(alignleft, SIGNAL(triggered()), this, SLOT(slotMoveLeft()));
134 menu->addAction(alignleft);
135 QAction *alignhcenter = new QAction(KIcon("kdenlive-align-hor"), i18n("Center horizontally"), this);
136 connect(alignhcenter, SIGNAL(triggered()), this, SLOT(slotCenterH()));
137 menu->addAction(alignhcenter);
138 QAction *alignright = new QAction(KIcon("kdenlive-align-right"), i18n("Align right"), this);
139 connect(alignright, SIGNAL(triggered()), this, SLOT(slotMoveRight()));
140 menu->addAction(alignright);
141 QAction *aligntop = new QAction(KIcon("kdenlive-align-top"), i18n("Align top"), this);
142 connect(aligntop, SIGNAL(triggered()), this, SLOT(slotMoveTop()));
143 menu->addAction(aligntop);
144 QAction *alignvcenter = new QAction(KIcon("kdenlive-align-vert"), i18n("Center vertically"), this);
145 connect(alignvcenter, SIGNAL(triggered()), this, SLOT(slotCenterV()));
146 menu->addAction(alignvcenter);
147 QAction *alignbottom = new QAction(KIcon("kdenlive-align-bottom"), i18n("Align bottom"), this);
148 connect(alignbottom, SIGNAL(triggered()), this, SLOT(slotMoveBottom()));
149 menu->addAction(alignbottom);
150 m_ui.buttonOptions->setMenu(menu);
152 QHBoxLayout *alignLayout = new QHBoxLayout;
153 alignLayout->setSpacing(0);
154 QToolButton *alignButton = new QToolButton;
155 alignButton->setDefaultAction(alignleft);
156 alignButton->setAutoRaise(true);
157 alignLayout->addWidget(alignButton);
159 alignButton = new QToolButton;
160 alignButton->setDefaultAction(alignhcenter);
161 alignButton->setAutoRaise(true);
162 alignLayout->addWidget(alignButton);
164 alignButton = new QToolButton;
165 alignButton->setDefaultAction(alignright);
166 alignButton->setAutoRaise(true);
167 alignLayout->addWidget(alignButton);
169 alignButton = new QToolButton;
170 alignButton->setDefaultAction(aligntop);
171 alignButton->setAutoRaise(true);
172 alignLayout->addWidget(alignButton);
174 alignButton = new QToolButton;
175 alignButton->setDefaultAction(alignvcenter);
176 alignButton->setAutoRaise(true);
177 alignLayout->addWidget(alignButton);
179 alignButton = new QToolButton;
180 alignButton->setDefaultAction(alignbottom);
181 alignButton->setAutoRaise(true);
182 alignLayout->addWidget(alignButton);
183 alignLayout->addStretch(10);
185 m_ui.horizontalLayout->addLayout(alignLayout, 1, 0, 1, 4);
186 //m_ui.horizontalLayout->addStretch(10);
188 m_spinSize = new DragValue(i18n("Size"), 100, 2, 1, 99000, -1, i18n("%"), false, this);
189 m_ui.horizontalLayout2->addWidget(m_spinSize);
191 m_opacity = new DragValue(i18n("Opacity"), 100, 0, 0, 100, -1, i18n("%"), true, this);
192 m_ui.horizontalLayout2->addWidget(m_opacity);
196 m_rotateX = new DragValue(i18n("Rotate X"), 0, 0, -1800, 1800, -1, QString(), true, this);
197 m_rotateX->setObjectName("rotate_x");
198 m_ui.horizontalLayout3->addWidget(m_rotateX);
199 m_rotateY = new DragValue(i18n("Rotate Y"), 0, 0, -1800, 1800, -1, QString(), true, this);
200 m_rotateY->setObjectName("rotate_y");
201 m_ui.horizontalLayout3->addWidget(m_rotateY);
202 m_rotateZ = new DragValue(i18n("Rotate Z"), 0, 0, -1800, 1800, -1, QString(), true, this);
203 m_rotateZ->setObjectName("rotate_z");
204 m_ui.horizontalLayout3->addWidget(m_rotateZ);
205 connect(m_rotateX, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
206 connect(m_rotateY, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
207 connect(m_rotateZ, SIGNAL(valueChanged(double)), this, SLOT(slotUpdateGeometry()));
211 Setup of geometry controls
214 connect(m_spinX, SIGNAL(valueChanged(double)), this, SLOT(slotSetX(double)));
215 connect(m_spinY, SIGNAL(valueChanged(double)), this, SLOT(slotSetY(double)));
216 connect(m_spinWidth, SIGNAL(valueChanged(double)), this, SLOT(slotSetWidth(double)));
217 connect(m_spinHeight, SIGNAL(valueChanged(double)), this, SLOT(slotSetHeight(double)));
219 connect(m_spinSize, SIGNAL(valueChanged(double)), this, SLOT(slotResize(double)));
221 connect(m_opacity, SIGNAL(valueChanged(double)), this, SLOT(slotSetOpacity(double)));
223 /*connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
224 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
225 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
226 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
227 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
228 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));*/
232 Setup of configuration controls
235 connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
236 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
239 GeometryWidget::~GeometryWidget()
241 m_scene->setEnabled(true);
249 m_scene->removeItem(m_rect);
250 m_scene->removeItem(m_geomPath);
251 if (m_rect) delete m_rect;
252 if (m_geomPath) delete m_geomPath;
253 if (m_previous) delete m_previous;
255 m_extraGeometryNames.clear();
256 m_extraFactors.clear();
257 while (!m_extraGeometries.isEmpty()) {
258 Mlt::Geometry *g = m_extraGeometries.takeFirst();
263 void GeometryWidget::slotShowPreviousKeyFrame(bool show)
265 KdenliveSettings::setOnmonitoreffects_geometryshowprevious(show);
266 slotPositionChanged(-1, false);
269 void GeometryWidget::updateTimecodeFormat()
271 m_timePos->slotUpdateTimeCodeFormat();
274 QString GeometryWidget::getValue() const
276 return m_geometry->serialise();
279 QString GeometryWidget::getExtraValue(const QString &name) const
281 int ix = m_extraGeometryNames.indexOf(name);
282 QString val = m_extraGeometries.at(ix)->serialise();
283 if (!val.contains("=")) val = val.section('/', 0, 0);
285 QStringList list = val.split(';', QString::SkipEmptyParts);
287 val.append(list.takeFirst().section('/', 0, 0));
288 foreach (const QString &value, list) {
289 val.append(';' + value.section('/', 0, 0));
295 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
297 m_inPoint = minframe;
298 m_outPoint = maxframe;
301 m_geometry->parse(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
303 m_geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), maxframe - minframe, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
305 if (elem.attribute("fixed") == "1" || maxframe < minframe) {
306 // Keyframes are disabled
307 m_ui.widgetTimeWrapper->setHidden(true);
309 m_ui.widgetTimeWrapper->setHidden(false);
310 m_timeline->setKeyGeometry(m_geometry, m_outPoint - m_inPoint);
311 m_timeline->update();
312 m_timePos->setRange(0, m_outPoint - m_inPoint);
316 if (elem.attribute("opacity") == "false") {
317 m_opacity->setHidden(true);
318 m_ui.horizontalLayout2->addStretch(2);
321 Mlt::GeometryItem item;
322 m_geometry->fetch(&item, 0);
324 m_scene->removeItem(m_rect);
328 m_scene->removeItem(m_geomPath);
331 m_rect = new OnMonitorRectItem(QRectF(0, 0, item.w(), item.h()), m_monitor->render->dar());
332 m_rect->setPos(item.x(), item.y());
333 m_rect->setZValue(0);
334 m_scene->addItem(m_rect);
335 connect(m_rect, SIGNAL(changed()), this, SLOT(slotUpdateGeometry()));
336 m_geomPath = new OnMonitorPathItem(m_monitor->render->dar());
337 connect(m_geomPath, SIGNAL(changed()), this, SLOT(slotUpdatePath()));
338 m_geomPath->setPen(QPen(Qt::red));
339 m_scene->addItem(m_geomPath);
340 m_geomPath->setPoints(m_geometry);
341 m_scene->centerView();
342 slotPositionChanged(0, false);
345 void GeometryWidget::addParameter(const QDomElement elem)
347 Mlt::Geometry *geometry = new Mlt::Geometry(elem.attribute("value").toUtf8().data(), m_outPoint - m_inPoint, m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
348 m_extraGeometries.append(geometry);
349 m_timeline->addGeometry(geometry);
350 m_extraFactors.append(elem.attribute("factor", "1"));
351 m_extraGeometryNames.append(elem.attribute("name"));
352 //kDebug()<<"ADDED PARAM: "<<elem.attribute("value");
355 void GeometryWidget::slotSyncPosition(int relTimelinePos)
357 // do only sync if this effect is keyframable
358 if (m_timePos->maximum() > 0 && KdenliveSettings::transitionfollowcursor()) {
359 relTimelinePos = qBound(0, relTimelinePos, m_timePos->maximum());
360 if (relTimelinePos != m_timePos->getValue())
361 slotPositionChanged(relTimelinePos, false);
365 void GeometryWidget::slotRequestSeek(int pos)
367 if (KdenliveSettings::transitionfollowcursor())
368 emit seekToPos(m_clipPos + pos);
372 void GeometryWidget::slotPositionChanged(int pos, bool seek)
375 pos = m_timePos->getValue();
377 m_timePos->setValue(pos);
379 //m_timeline->blockSignals(true);
380 m_timeline->setValue(pos);
381 //m_timeline->blockSignals(false);
383 Mlt::GeometryItem item;
384 Mlt::GeometryItem previousItem;
385 if (m_geometry->fetch(&item, pos) || item.key() == false) {
387 m_rect->setEnabled(false);
388 m_scene->setEnabled(false);
389 m_ui.widgetGeometry->setEnabled(false);
390 m_ui.buttonAddDelete->setIcon(KIcon("document-new"));
391 m_ui.buttonAddDelete->setToolTip(i18n("Add keyframe"));
394 m_rect->setEnabled(true);
395 m_scene->setEnabled(true);
396 m_ui.widgetGeometry->setEnabled(true);
397 m_ui.buttonAddDelete->setIcon(KIcon("edit-delete"));
398 m_ui.buttonAddDelete->setToolTip(i18n("Delete keyframe"));
401 if (KdenliveSettings::onmonitoreffects_geometryshowprevious() == false || m_geometry->prev_key(&previousItem, pos - 1) || previousItem.frame() == item.frame()) {
403 m_scene->removeItem(m_previous);
406 else if (m_previous && m_previous->scene() && m_previous->data(Qt::UserRole).toInt() == previousItem.frame()) {
407 // previous frame already here, do nothing
410 if (m_previous == NULL) {
411 m_previous = new QGraphicsRectItem(0, 0, previousItem.w(), previousItem.h());
412 m_previous->setBrush(QColor(200, 200, 0, 20));
413 m_previous->setPen(QPen(Qt::white, 0, Qt::DotLine));
414 m_previous->setPos(previousItem.x(), previousItem.y());
415 m_previous->setZValue(-1);
416 m_previous->setEnabled(false);
419 m_previous->setPos(previousItem.x(), previousItem.y());
420 m_previous->setRect(0, 0, previousItem.w(), previousItem.h());
422 m_previous->setData(Qt::UserRole, previousItem.frame());
423 if (m_previous->scene() == 0) m_scene->addItem(m_previous);
426 m_rect->setPos(item.x(), item.y());
427 m_rect->setRect(0, 0, item.w(), item.h());
429 m_opacity->blockSignals(true);
430 m_opacity->setValue(item.mix());
431 m_opacity->blockSignals(false);
433 for (int i = 0; i < m_extraGeometries.count(); i++) {
434 Mlt::Geometry *geom = m_extraGeometries.at(i);
435 QString name = m_extraGeometryNames.at(i);
436 if (!geom->fetch(&item, pos)) {
437 DragValue *widget = findChild<DragValue *>(name);
439 widget->blockSignals(true);
440 widget->setValue(item.x() * m_extraFactors.at(i).toInt());
441 widget->blockSignals(false);
446 slotUpdateProperties();
448 if (seek && KdenliveSettings::transitionfollowcursor())
449 emit seekToPos(m_clipPos + pos);
452 void GeometryWidget::slotKeyframeMoved(int pos)
454 slotPositionChanged(pos);
455 slotUpdateGeometry();
456 QTimer::singleShot(100, this, SIGNAL(parameterChanged()));
459 void GeometryWidget::slotAddKeyframe(int pos)
461 Mlt::GeometryItem item;
463 pos = m_timePos->getValue();
465 QRectF r = m_rect->rect().normalized();
466 QPointF rectpos = m_rect->pos();
471 item.mix(m_opacity->value());
472 m_geometry->insert(item);
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 DragValue *widget = findChild<DragValue *>(name);
479 Mlt::GeometryItem item2;
481 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
486 m_timeline->update();
487 slotPositionChanged(pos, false);
488 emit parameterChanged();
491 void GeometryWidget::slotDeleteKeyframe(int pos)
493 Mlt::GeometryItem item;
495 pos = m_timePos->getValue();
496 // check there is more than one keyframe, do not allow to delete last one
497 if (m_geometry->next_key(&item, pos + 1)) {
498 if (m_geometry->prev_key(&item, pos - 1) || item.frame() == pos)
501 m_geometry->remove(pos);
503 for (int i = 0; i < m_extraGeometries.count(); i++) {
504 Mlt::Geometry *geom = m_extraGeometries.at(i);
508 m_timeline->update();
509 slotPositionChanged(pos, false);
510 emit parameterChanged();
513 void GeometryWidget::slotPreviousKeyframe()
515 Mlt::GeometryItem item;
516 // Go to start if no keyframe is found
517 int currentPos = m_timePos->getValue();
519 if (!m_geometry->prev_key(&item, currentPos - 1) && item.frame() < currentPos)
522 slotPositionChanged(pos);
525 void GeometryWidget::slotNextKeyframe()
527 Mlt::GeometryItem item;
528 // Go to end if no keyframe is found
529 int pos = m_timeline->frameLength;
530 if (!m_geometry->next_key(&item, m_timeline->value() + 1))
533 slotPositionChanged(pos);
536 void GeometryWidget::slotAddDeleteKeyframe()
538 Mlt::GeometryItem item;
539 if (m_geometry->fetch(&item, m_timePos->getValue()) || item.key() == false)
542 slotDeleteKeyframe();
545 void GeometryWidget::slotUpdatePath()
547 if (!m_geomPath) return;
548 QList <QPointF> points = m_geomPath->points();
549 Mlt::GeometryItem item;
552 while (ix < points.count() && !m_geometry->next_key(&item, pos)) {
553 QPointF center = points.at(ix);
554 QSizeF size(item.w(), item.h());
555 item.x(center.x() - size.width()/2);
556 item.y(center.y() - size.height()/2);
557 m_geometry->insert(item);
558 pos = item.frame() + 1;
561 slotPositionChanged(-1, false);
562 emit parameterChanged();
566 void GeometryWidget::slotUpdateGeometry()
568 Mlt::GeometryItem item;
569 int pos = m_timePos->getValue();
571 // get keyframe and make sure it is the correct one
572 if (m_geometry->next_key(&item, pos) || item.frame() != pos)
575 QRectF rectSize = m_rect->rect().normalized();
576 QPointF rectPos = m_rect->pos();
579 item.w(rectSize.width());
580 item.h(rectSize.height());
581 m_geometry->insert(item);
583 for (int i = 0; i < m_extraGeometries.count(); i++) {
584 Mlt::Geometry *geom = m_extraGeometries.at(i);
585 QString name = m_extraGeometryNames.at(i);
586 Mlt::GeometryItem item2;
587 DragValue *widget = findChild<DragValue *>(name);
588 if (widget && !geom->next_key(&item2, pos) && item2.frame() == pos) {
589 item2.x((double) widget->value() / m_extraFactors.at(i).toInt());
593 if (m_geomPath) m_geomPath->setPoints(m_geometry);
594 emit parameterChanged();
597 void GeometryWidget::slotUpdateProperties()
599 QRectF rectSize = m_rect->rect().normalized();
600 QPointF rectPos = m_rect->pos();
602 if (rectSize.width() / m_monitor->render->dar() > rectSize.height())
603 size = rectSize.width() * 100.0 / m_monitor->render->frameRenderWidth();
605 size = rectSize.height() * 100.0 / m_monitor->render->renderHeight();
607 m_spinX->blockSignals(true);
608 m_spinY->blockSignals(true);
609 m_spinWidth->blockSignals(true);
610 m_spinHeight->blockSignals(true);
611 m_spinSize->blockSignals(true);
613 m_spinX->setValue(rectPos.x());
614 m_spinY->setValue(rectPos.y());
615 m_spinWidth->setValue(rectSize.width());
616 m_spinHeight->setValue(rectSize.height());
617 m_spinSize->setValue(size);
619 m_spinX->blockSignals(false);
620 m_spinY->blockSignals(false);
621 m_spinWidth->blockSignals(false);
622 m_spinHeight->blockSignals(false);
623 m_spinSize->blockSignals(false);
627 void GeometryWidget::slotSetX(double value)
629 m_rect->setPos(value, m_spinY->value());
630 slotUpdateGeometry();
633 void GeometryWidget::slotSetY(double value)
635 m_rect->setPos(m_spinX->value(), value);
636 slotUpdateGeometry();
639 void GeometryWidget::slotSetWidth(double value)
641 m_rect->setRect(0, 0, value, m_spinHeight->value());
642 slotUpdateGeometry();
645 void GeometryWidget::slotSetHeight(double value)
647 m_rect->setRect(0, 0, m_spinWidth->value(), value);
648 slotUpdateGeometry();
651 void GeometryWidget::updateMonitorGeometry()
653 m_rect->setRect(0, 0, m_spinWidth->value(), m_spinHeight->value());
654 slotUpdateGeometry();
658 void GeometryWidget::slotResize(double value)
660 m_rect->setRect(0, 0,
661 (int)((m_monitor->render->frameRenderWidth() * value / 100.0) + 0.5),
662 (int)((m_monitor->render->renderHeight() * value / 100.0) + 0.5));
663 slotUpdateGeometry();
667 void GeometryWidget::slotSetOpacity(double value)
669 int pos = m_timePos->getValue();
670 Mlt::GeometryItem item;
671 if (m_geometry->fetch(&item, pos) || item.key() == false)
674 m_geometry->insert(item);
675 emit parameterChanged();
679 void GeometryWidget::slotMoveLeft()
681 m_rect->setPos(0, m_rect->pos().y());
682 slotUpdateGeometry();
685 void GeometryWidget::slotCenterH()
687 m_rect->setPos((m_monitor->render->frameRenderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
688 slotUpdateGeometry();
691 void GeometryWidget::slotMoveRight()
693 m_rect->setPos(m_monitor->render->frameRenderWidth() - m_rect->rect().width(), m_rect->pos().y());
694 slotUpdateGeometry();
697 void GeometryWidget::slotMoveTop()
699 m_rect->setPos(m_rect->pos().x(), 0);
700 slotUpdateGeometry();
703 void GeometryWidget::slotCenterV()
705 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
706 slotUpdateGeometry();
709 void GeometryWidget::slotMoveBottom()
711 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
712 slotUpdateGeometry();
716 void GeometryWidget::slotSetSynchronize(bool sync)
718 KdenliveSettings::setTransitionfollowcursor(sync);
720 emit seekToPos(m_clipPos + m_timePos->getValue());
723 void GeometryWidget::setFrameSize(QPoint size)
728 void GeometryWidget::slotAdjustToFrameSize()
730 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
731 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
733 m_spinWidth->blockSignals(true);
734 m_spinHeight->blockSignals(true);
735 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() + 0.5));
736 m_spinHeight->setValue(m_frameSize.y());
737 m_spinWidth->blockSignals(false);
738 m_spinHeight->blockSignals(false);
739 updateMonitorGeometry();
742 void GeometryWidget::slotFitToWidth()
744 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
745 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
747 double factor = (double) m_monitor->render->frameRenderWidth() / m_frameSize.x() * m_monitor->render->sar();
748 m_spinWidth->blockSignals(true);
749 m_spinHeight->blockSignals(true);
750 m_spinHeight->setValue((int) (m_frameSize.y() * factor + 0.5));
751 m_spinWidth->setValue(m_monitor->render->frameRenderWidth());
752 m_spinWidth->blockSignals(false);
753 m_spinHeight->blockSignals(false);
754 updateMonitorGeometry();
757 void GeometryWidget::slotFitToHeight()
759 if (m_frameSize == QPoint() || m_frameSize.x() == 0 || m_frameSize.y() == 0) {
760 m_frameSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
762 double factor = (double) m_monitor->render->renderHeight() / m_frameSize.y();
763 m_spinWidth->blockSignals(true);
764 m_spinHeight->blockSignals(true);
765 m_spinHeight->setValue(m_monitor->render->renderHeight());
766 m_spinWidth->setValue((int) (m_frameSize.x() / m_monitor->render->sar() * factor + 0.5));
767 m_spinWidth->blockSignals(false);
768 m_spinHeight->blockSignals(false);
769 updateMonitorGeometry();
772 void GeometryWidget::importKeyframes(const QString &data)
774 QStringList list = data.split(';', QString::SkipEmptyParts);
775 QPoint screenSize = m_frameSize;
776 if (screenSize == QPoint() || screenSize.x() == 0 || screenSize.y() == 0) {
777 screenSize = QPoint(m_monitor->render->frameRenderWidth(), m_monitor->render->renderHeight());
779 for (int i = 0; i < list.count(); i++) {
780 Mlt::GeometryItem item;
781 QString geom = list.at(i);
782 if (geom.contains('=')) {
783 item.frame(geom.section('=', 0, 0).toInt());
785 geom = geom.section('=', 1);
786 if (geom.contains('/')) {
787 item.x(geom.section('/', 0, 0).toDouble());
788 item.y(geom.section('/', 1, 1).section(':', 0, 0).toDouble());
794 if (geom.contains('x')) {
795 item.w(geom.section('x', 0, 0).section(':', 1, 1).toDouble());
796 item.h(geom.section('x', 1, 1).section(':', 0, 0).toDouble());
799 item.w(screenSize.x());
800 item.h(screenSize.y());
804 m_geometry->insert(item);
806 emit parameterChanged();
809 #include "geometrywidget.moc"