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"
27 #include <QGraphicsView>
28 #include <QGraphicsRectItem>
30 GeometryWidget::GeometryWidget(Monitor* monitor, int clipPos, bool isEffect, QWidget* parent ):
41 m_scene = monitor->getEffectScene();
43 m_ui.buttonMoveLeft->setIcon(KIcon("kdenlive-align-left"));
44 m_ui.buttonMoveLeft->setToolTip(i18n("Move to left"));
45 m_ui.buttonCenterH->setIcon(KIcon("kdenlive-align-hor"));
46 m_ui.buttonCenterH->setToolTip(i18n("Center horizontally"));
47 m_ui.buttonMoveRight->setIcon(KIcon("kdenlive-align-right"));
48 m_ui.buttonMoveRight->setToolTip(i18n("Move to right"));
49 m_ui.buttonMoveTop->setIcon(KIcon("kdenlive-align-top"));
50 m_ui.buttonMoveTop->setToolTip(i18n("Move to top"));
51 m_ui.buttonCenterV->setIcon(KIcon("kdenlive-align-vert"));
52 m_ui.buttonCenterV->setToolTip(i18n("Center vertically"));
53 m_ui.buttonMoveBottom->setIcon(KIcon("kdenlive-align-bottom"));
54 m_ui.buttonMoveBottom->setToolTip(i18n("Move to bottom"));
57 connect(m_ui.spinX, SIGNAL(valueChanged(int)), this, SLOT(slotSetX(int)));
58 connect(m_ui.spinY, SIGNAL(valueChanged(int)), this, SLOT(slotSetY(int)));
59 connect(m_ui.spinWidth, SIGNAL(valueChanged(int)), this, SLOT(slotSetWidth(int)));
60 connect(m_ui.spinHeight, SIGNAL(valueChanged(int)), this, SLOT(slotSetHeight(int)));
62 connect(m_ui.spinSize, SIGNAL(valueChanged(int)), this, SLOT(slotResize(int)));
64 connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
65 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
66 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
67 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
68 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
69 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));
71 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateGeometry()));
72 connect(m_monitor->render, SIGNAL(rendererPosition(int)), this, SLOT(slotCheckPosition(int)));
73 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
76 GeometryWidget::~GeometryWidget()
78 m_scene->removeItem(m_rect);
80 m_monitor->slotEffectScene(false);
83 QString GeometryWidget::getValue() const
85 return m_geometry->serialise();
88 void GeometryWidget::setupParam(const QDomElement elem, int minframe, int maxframe)
91 m_outPoint = maxframe;
92 QString value = elem.attribute("value");
94 char *tmp = (char *) qstrdup(value.toUtf8().data());
96 m_geometry->parse(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
98 m_geometry = new Mlt::Geometry(tmp, maxframe - minframe, m_monitor->render->renderWidth(), m_monitor->render->renderHeight());
101 Mlt::GeometryItem item;
103 m_geometry->fetch(&item, 0);
105 m_rect = new QGraphicsRectItem(QRectF(0, 0, item.w(), item.h()));
106 m_rect->setPos(item.x(), item.y());
107 m_rect->setZValue(0);
108 m_rect->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable);
110 QPen framepen(Qt::SolidLine);
111 framepen.setColor(Qt::yellow);
112 m_rect->setPen(framepen);
113 m_rect->setBrush(Qt::transparent);
114 m_scene->addItem(m_rect);
116 slotUpdateProperties();
117 slotCheckPosition(m_monitor->render->seekFramePosition());
120 void GeometryWidget::slotCheckPosition(int renderPos)
123 We do only get the position in timeline if this geometry belongs to a transition,
124 therefore we need to ways here.
127 emit checkMonitorPosition(renderPos);
129 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
130 if (!m_scene->views().at(0)->isVisible())
131 m_monitor->slotEffectScene(true);
133 m_monitor->slotEffectScene(false);
138 void GeometryWidget::slotUpdateGeometry()
140 Mlt::GeometryItem item;
141 m_geometry->next_key(&item, 0);
143 QRectF rectSize = m_rect->rect().normalized();
144 QPointF rectPos = m_rect->pos();
147 item.w(rectSize.width());
148 item.h(rectSize.height());
149 m_geometry->insert(item);
150 emit parameterChanged();
153 void GeometryWidget::slotUpdateProperties()
155 QRectF rectSize = m_rect->rect().normalized();
156 QPointF rectPos = m_rect->pos();
158 if (rectSize.width() / m_monitor->render->dar() < rectSize.height())
159 size = (int)(rectSize.width() * 100 / m_monitor->render->renderWidth());
161 size = (int)(rectSize.height() * 100 / m_monitor->render->renderHeight());
163 m_ui.spinX->blockSignals(true);
164 m_ui.spinY->blockSignals(true);
165 m_ui.spinWidth->blockSignals(true);
166 m_ui.spinHeight->blockSignals(true);
167 m_ui.spinSize->blockSignals(true);
169 m_ui.spinX->setValue(rectPos.x());
170 m_ui.spinY->setValue(rectPos.y());
171 m_ui.spinWidth->setValue(rectSize.width());
172 m_ui.spinHeight->setValue(rectSize.height());
173 m_ui.spinSize->setValue(size);
175 m_ui.spinX->blockSignals(false);
176 m_ui.spinY->blockSignals(false);
177 m_ui.spinWidth->blockSignals(false);
178 m_ui.spinHeight->blockSignals(false);
179 m_ui.spinSize->blockSignals(false);
183 void GeometryWidget::slotSetX(int value)
185 m_rect->setPos(value, m_ui.spinY->value());
186 slotUpdateGeometry();
189 void GeometryWidget::slotSetY(int value)
191 m_rect->setPos(m_ui.spinX->value(), value);
192 slotUpdateGeometry();
195 void GeometryWidget::slotSetWidth(int value)
197 m_rect->setRect(0, 0, value, m_ui.spinHeight->value());
198 slotUpdateGeometry();
201 void GeometryWidget::slotSetHeight(int value)
203 m_rect->setRect(0, 0, m_ui.spinWidth->value(), value);
204 slotUpdateGeometry();
208 void GeometryWidget::slotResize(int value)
210 m_rect->setRect(0, 0, m_monitor->render->renderWidth() * value / 100, m_monitor->render->renderHeight() * value / 100);
211 slotUpdateGeometry();
215 void GeometryWidget::slotMoveLeft()
217 m_rect->setPos(0, m_rect->pos().y());
218 slotUpdateGeometry();
221 void GeometryWidget::slotCenterH()
223 m_rect->setPos((m_monitor->render->renderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
224 slotUpdateGeometry();
227 void GeometryWidget::slotMoveRight()
229 m_rect->setPos(m_monitor->render->renderWidth() - m_rect->rect().width(), m_rect->pos().y());
230 slotUpdateGeometry();
233 void GeometryWidget::slotMoveTop()
235 m_rect->setPos(m_rect->pos().x(), 0);
236 slotUpdateGeometry();
239 void GeometryWidget::slotCenterV()
241 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
242 slotUpdateGeometry();
245 void GeometryWidget::slotMoveBottom()
247 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
248 slotUpdateGeometry();
251 #include "geometrywidget.moc"