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 ***************************************************************************/
20 #include "cornerswidget.h"
22 #include "monitorscene.h"
23 #include "monitorscenecontrolwidget.h"
24 #include "onmonitoritems/onmonitorcornersitem.h"
27 #include <QGraphicsView>
28 #include <QHBoxLayout>
32 CornersWidget::CornersWidget(Monitor* monitor, int clipPos, bool isEffect, int factor, QWidget* parent) :
44 m_scene = monitor->getEffectScene();
46 m_item = new OnMonitorCornersItem(m_scene);
47 m_scene->addItem(m_item);
49 m_config = new MonitorSceneControlWidget(m_scene, m_ui.frameConfig);
50 QHBoxLayout *layout = new QHBoxLayout(m_ui.frameConfig);
51 layout->setContentsMargins(0, 0, 0, 0);
52 layout->addWidget(m_config);
53 QHBoxLayout *layout2 = new QHBoxLayout(m_ui.widgetConfigButton);
54 layout2->setContentsMargins(0, 0, 0, 0);
55 layout2->addWidget(m_config->getShowHideButton());
57 int width = m_monitor->render->frameRenderWidth();
58 int height = m_monitor->render->renderHeight();
60 m_ui.spinX1->setRange(-width, width * 2);
61 m_ui.spinX2->setRange(-width, width * 2);
62 m_ui.spinX3->setRange(-width, width * 2);
63 m_ui.spinX4->setRange(-width, width * 2);
64 m_ui.spinY1->setRange(-height, height * 2);
65 m_ui.spinY2->setRange(-height, height * 2);
66 m_ui.spinY3->setRange(-height, height * 2);
67 m_ui.spinY4->setRange(-height, height * 2);
69 m_ui.toolReset1->setIcon(KIcon("edit-undo"));
70 m_ui.toolReset1->setToolTip(i18n("Reset Corner 1"));
71 m_ui.toolReset2->setIcon(KIcon("edit-undo"));
72 m_ui.toolReset2->setToolTip(i18n("Reset Corner 2"));
73 m_ui.toolReset3->setIcon(KIcon("edit-undo"));
74 m_ui.toolReset3->setToolTip(i18n("Reset Corner 3"));
75 m_ui.toolReset4->setIcon(KIcon("edit-undo"));
76 m_ui.toolReset4->setToolTip(i18n("Reset Corner 4"));
78 connect(m_ui.spinX1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
79 connect(m_ui.spinX2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
80 connect(m_ui.spinX3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
81 connect(m_ui.spinX4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
82 connect(m_ui.spinY1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
83 connect(m_ui.spinY2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
84 connect(m_ui.spinY3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
85 connect(m_ui.spinY4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
87 connect(m_ui.toolReset1, SIGNAL(clicked()), this, SLOT(slotResetCorner1()));
88 connect(m_ui.toolReset2, SIGNAL(clicked()), this, SLOT(slotResetCorner2()));
89 connect(m_ui.toolReset3, SIGNAL(clicked()), this, SLOT(slotResetCorner3()));
90 connect(m_ui.toolReset4, SIGNAL(clicked()), this, SLOT(slotResetCorner4()));
92 connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool)));
93 connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
94 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
97 CornersWidget::~CornersWidget()
100 m_scene->removeItem(m_item);
103 m_monitor->slotEffectScene(false);
106 void CornersWidget::setRange(int minframe, int maxframe)
108 m_inPoint = minframe;
109 m_outPoint = maxframe;
110 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
113 void CornersWidget::slotUpdateItem()
115 QPointF c1(m_ui.spinX1->value(), m_ui.spinY1->value());
116 QPointF c2(m_ui.spinX2->value(), m_ui.spinY2->value());
117 QPointF c3(m_ui.spinX3->value(), m_ui.spinY3->value());
118 QPointF c4(m_ui.spinX4->value(), m_ui.spinY4->value());
120 m_item->setPolygon(QPolygonF() << c1 << c2 << c3 << c4);
122 emit parameterChanged();
125 void CornersWidget::slotUpdateProperties(bool changed)
127 QPolygon pol = m_item->polygon().toPolygon();
129 m_ui.spinX1->setValue(pol.at(0).x());
130 m_ui.spinX2->setValue(pol.at(1).x());
131 m_ui.spinX3->setValue(pol.at(2).x());
132 m_ui.spinX4->setValue(pol.at(3).x());
133 m_ui.spinY1->setValue(pol.at(0).y());
134 m_ui.spinY2->setValue(pol.at(1).y());
135 m_ui.spinY3->setValue(pol.at(2).y());
136 m_ui.spinY4->setValue(pol.at(3).y());
140 emit parameterChanged();
144 QPolygon CornersWidget::getValue()
146 qreal width = m_monitor->render->frameRenderWidth();
147 qreal height = m_monitor->render->renderHeight();
148 QPolygon corners = m_item->polygon().toPolygon();
151 for (int i = 0; i < 4; ++i) {
153 p.setX((p.x() / width + 1) / 3.0 * m_factor);
154 p.setY((p.y() / height + 1) / 3.0 * m_factor);
160 void CornersWidget::setValue(const QPolygon& points)
162 int width = m_monitor->render->frameRenderWidth();
163 int height = m_monitor->render->renderHeight();
166 for (int i = 0; i < 4; ++i) {
168 p.setX((p.x() / (qreal)m_factor * 3 - 1) * width);
169 p.setY((p.y() / (qreal)m_factor * 3 - 1) * height);
172 m_item->setPolygon(corners);
174 slotUpdateProperties(false);
177 void CornersWidget::slotCheckMonitorPosition(int renderPos)
181 We do only get the position in timeline if this geometry belongs to a transition,
182 therefore we need two ways here.
185 emit checkMonitorPosition(renderPos);
187 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
188 if (!m_scene->views().at(0)->isVisible())
189 m_monitor->slotEffectScene(true);
191 m_monitor->slotEffectScene(false);
197 void CornersWidget::slotShowScene(bool show)
201 m_monitor->slotEffectScene(false);
203 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
206 void CornersWidget::slotResetCorner1()
209 m_ui.spinX1->setValue(0);
210 m_ui.spinY1->setValue(0);
215 void CornersWidget::slotResetCorner2()
218 m_ui.spinX2->setValue(m_monitor->render->frameRenderWidth());
219 m_ui.spinY2->setValue(0);
224 void CornersWidget::slotResetCorner3()
227 m_ui.spinX3->setValue(m_monitor->render->frameRenderWidth());
228 m_ui.spinY3->setValue(m_monitor->render->renderHeight());
233 void CornersWidget::slotResetCorner4()
236 m_ui.spinX4->setValue(0);
237 m_ui.spinY4->setValue(m_monitor->render->renderHeight());
242 #include "cornerswidget.moc"