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 "monitorscene.h"
26 #include <QGraphicsRectItem>
28 GeometryWidget::GeometryWidget(Monitor* monitor, int clipPos, QWidget* parent ):
38 m_scene = monitor->getEffectScene();
39 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateGeometry()));
40 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
42 connect(m_monitor->render, SIGNAL(rendererPosition(int)), this, SLOT(slotCheckPosition(int)));
44 connect(m_ui.spinX, SIGNAL(valueChanged(int)), this, SLOT(slotSetX(int)));
45 connect(m_ui.spinY, SIGNAL(valueChanged(int)), this, SLOT(slotSetY(int)));
46 connect(m_ui.spinWidth, SIGNAL(valueChanged(int)), this, SLOT(slotSetWidth(int)));
47 connect(m_ui.spinHeight, SIGNAL(valueChanged(int)), this, SLOT(slotSetHeight(int)));
50 GeometryWidget::~GeometryWidget()
52 m_monitor->slotEffectScene(false);
53 m_scene->disconnect(this);
58 QString GeometryWidget::getValue() const
60 return m_geometry->serialise();
63 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
66 m_outPoint = maxframe;
67 QString value = elem.attribute("value");
69 char *tmp = (char *) qstrdup(value.toUtf8().data());
71 m_geometry->parse(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
73 m_geometry = new Mlt::Geometry(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
76 Mlt::GeometryItem item;
78 m_geometry->fetch(&item, 0);
80 m_rect = new QGraphicsRectItem(QRectF(0, 0, item.w(), item.h()));
81 m_rect->setPos(item.x(), item.y());
83 m_rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
85 QPen framepen(Qt::DotLine);
86 framepen.setColor(Qt::yellow);
87 m_rect->setPen(framepen);
88 m_rect->setBrush(Qt::transparent);
89 m_scene->addItem(m_rect);
91 slotUpdateProperties();
92 slotCheckPosition(m_monitor->render->seekFramePosition());
95 void GeometryWidget::slotCheckPosition(int renderPos)
97 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint)
98 m_monitor->slotEffectScene(true);
100 m_monitor->slotEffectScene(false);
103 void GeometryWidget::slotUpdateGeometry()
105 Mlt::GeometryItem item;
106 m_geometry->next_key(&item, 0);
108 QRectF rectSize = m_rect->rect().normalized();
109 QPointF rectPos = m_rect->pos();
112 item.w(rectSize.width());
113 item.h(rectSize.height());
114 m_geometry->insert(item);
115 emit parameterChanged();
118 void GeometryWidget::slotUpdateProperties()
120 QRectF rectSize = m_rect->rect().normalized();
121 QPointF rectPos = m_rect->pos();
123 m_ui.spinX->blockSignals(true);
124 m_ui.spinY->blockSignals(true);
125 m_ui.spinWidth->blockSignals(true);
126 m_ui.spinHeight->blockSignals(true);
128 m_ui.spinX->setValue(rectPos.x());
129 m_ui.spinY->setValue(rectPos.y());
130 m_ui.spinWidth->setValue(rectSize.width());
131 m_ui.spinHeight->setValue(rectSize.height());
133 m_ui.spinX->blockSignals(false);
134 m_ui.spinY->blockSignals(false);
135 m_ui.spinWidth->blockSignals(false);
136 m_ui.spinHeight->blockSignals(false);
139 void GeometryWidget::slotSetX(int value)
141 m_rect->setPos(value, m_ui.spinY->value());
142 slotUpdateGeometry();
145 void GeometryWidget::slotSetY(int value)
147 m_rect->setPos(m_ui.spinX->value(), value);
148 slotUpdateGeometry();
151 void GeometryWidget::slotSetWidth(int value)
153 m_rect->setRect(0, 0, value, m_ui.spinHeight->value());
154 slotUpdateGeometry();
157 void GeometryWidget::slotSetHeight(int value)
159 m_rect->setRect(0, 0, m_ui.spinWidth->value(), value);
160 slotUpdateGeometry();
163 #include "geometrywidget.moc"