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, QWidget* parent ):
40 m_scene = monitor->getEffectScene();
42 m_ui.buttonMoveLeft->setIcon(KIcon("kdenlive-align-left"));
43 m_ui.buttonMoveLeft->setToolTip(i18n("Move to left"));
44 m_ui.buttonCenterH->setIcon(KIcon("kdenlive-align-hor"));
45 m_ui.buttonCenterH->setToolTip(i18n("Center horizontally"));
46 m_ui.buttonMoveRight->setIcon(KIcon("kdenlive-align-right"));
47 m_ui.buttonMoveRight->setToolTip(i18n("Move to right"));
48 m_ui.buttonMoveTop->setIcon(KIcon("kdenlive-align-top"));
49 m_ui.buttonMoveTop->setToolTip(i18n("Move to top"));
50 m_ui.buttonCenterV->setIcon(KIcon("kdenlive-align-vert"));
51 m_ui.buttonCenterV->setToolTip(i18n("Center vertically"));
52 m_ui.buttonMoveBottom->setIcon(KIcon("kdenlive-align-bottom"));
53 m_ui.buttonMoveBottom->setToolTip(i18n("Move to bottom"));
56 connect(m_ui.spinX, SIGNAL(valueChanged(int)), this, SLOT(slotSetX(int)));
57 connect(m_ui.spinY, SIGNAL(valueChanged(int)), this, SLOT(slotSetY(int)));
58 connect(m_ui.spinWidth, SIGNAL(valueChanged(int)), this, SLOT(slotSetWidth(int)));
59 connect(m_ui.spinHeight, SIGNAL(valueChanged(int)), this, SLOT(slotSetHeight(int)));
61 connect(m_ui.spinSize, SIGNAL(valueChanged(int)), this, SLOT(slotResize(int)));
63 connect(m_ui.buttonMoveLeft, SIGNAL(clicked()), this, SLOT(slotMoveLeft()));
64 connect(m_ui.buttonCenterH, SIGNAL(clicked()), this, SLOT(slotCenterH()));
65 connect(m_ui.buttonMoveRight, SIGNAL(clicked()), this, SLOT(slotMoveRight()));
66 connect(m_ui.buttonMoveTop, SIGNAL(clicked()), this, SLOT(slotMoveTop()));
67 connect(m_ui.buttonCenterV, SIGNAL(clicked()), this, SLOT(slotCenterV()));
68 connect(m_ui.buttonMoveBottom, SIGNAL(clicked()), this, SLOT(slotMoveBottom()));
70 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateGeometry()));
71 connect(m_monitor->render, SIGNAL(rendererPosition(int)), this, SLOT(slotCheckPosition(int)));
72 connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateProperties()));
75 GeometryWidget::~GeometryWidget()
78 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::DotLine);
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)
122 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
123 if (!m_scene->views().at(0)->isVisible())
124 m_monitor->slotEffectScene(true);
126 m_monitor->slotEffectScene(false);
130 void GeometryWidget::slotUpdateGeometry()
132 Mlt::GeometryItem item;
133 m_geometry->next_key(&item, 0);
135 QRectF rectSize = m_rect->rect().normalized();
136 QPointF rectPos = m_rect->pos();
139 item.w(rectSize.width());
140 item.h(rectSize.height());
141 m_geometry->insert(item);
142 emit parameterChanged();
145 void GeometryWidget::slotUpdateProperties()
147 QRectF rectSize = m_rect->rect().normalized();
148 QPointF rectPos = m_rect->pos();
150 if (rectSize.width() / m_monitor->render->dar() < rectSize.height())
151 size = (int)(rectSize.width() * 100 / m_monitor->render->renderWidth());
153 size = (int)(rectSize.height() * 100 / m_monitor->render->renderHeight());
155 m_ui.spinX->blockSignals(true);
156 m_ui.spinY->blockSignals(true);
157 m_ui.spinWidth->blockSignals(true);
158 m_ui.spinHeight->blockSignals(true);
159 m_ui.spinSize->blockSignals(true);
161 m_ui.spinX->setValue(rectPos.x());
162 m_ui.spinY->setValue(rectPos.y());
163 m_ui.spinWidth->setValue(rectSize.width());
164 m_ui.spinHeight->setValue(rectSize.height());
165 m_ui.spinSize->setValue(size);
167 m_ui.spinX->blockSignals(false);
168 m_ui.spinY->blockSignals(false);
169 m_ui.spinWidth->blockSignals(false);
170 m_ui.spinHeight->blockSignals(false);
171 m_ui.spinSize->blockSignals(false);
175 void GeometryWidget::slotSetX(int value)
177 m_rect->setPos(value, m_ui.spinY->value());
178 slotUpdateGeometry();
181 void GeometryWidget::slotSetY(int value)
183 m_rect->setPos(m_ui.spinX->value(), value);
184 slotUpdateGeometry();
187 void GeometryWidget::slotSetWidth(int value)
189 m_rect->setRect(0, 0, value, m_ui.spinHeight->value());
190 slotUpdateGeometry();
193 void GeometryWidget::slotSetHeight(int value)
195 m_rect->setRect(0, 0, m_ui.spinWidth->value(), value);
196 slotUpdateGeometry();
200 void GeometryWidget::slotResize(int value)
202 m_rect->setRect(0, 0, m_monitor->render->renderWidth() * value / 100, m_monitor->render->renderHeight() * value / 100);
203 slotUpdateGeometry();
207 void GeometryWidget::slotMoveLeft()
209 m_rect->setPos(0, m_rect->pos().y());
210 slotUpdateGeometry();
213 void GeometryWidget::slotCenterH()
215 m_rect->setPos((m_monitor->render->renderWidth() - m_rect->rect().width()) / 2, m_rect->pos().y());
216 slotUpdateGeometry();
219 void GeometryWidget::slotMoveRight()
221 m_rect->setPos(m_monitor->render->renderWidth() - m_rect->rect().width(), m_rect->pos().y());
222 slotUpdateGeometry();
225 void GeometryWidget::slotMoveTop()
227 m_rect->setPos(m_rect->pos().x(), 0);
228 slotUpdateGeometry();
231 void GeometryWidget::slotCenterV()
233 m_rect->setPos(m_rect->pos().x(), (m_monitor->render->renderHeight() - m_rect->rect().height()) / 2);
234 slotUpdateGeometry();
237 void GeometryWidget::slotMoveBottom()
239 m_rect->setPos(m_rect->pos().x(), m_monitor->render->renderHeight() - m_rect->rect().height());
240 slotUpdateGeometry();
243 #include "geometrywidget.moc"