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"
26 #include "kdenlivesettings.h"
28 #include <QGraphicsView>
29 #include <QHBoxLayout>
33 CornersWidget::CornersWidget(Monitor* monitor, int clipPos, bool isEffect, int factor, QWidget* parent) :
45 m_scene = monitor->getEffectScene();
47 m_item = new OnMonitorCornersItem(m_scene);
48 m_scene->addItem(m_item);
50 m_config = new MonitorSceneControlWidget(m_scene, m_ui.frameConfig);
51 QHBoxLayout *layout = new QHBoxLayout(m_ui.frameConfig);
52 layout->setContentsMargins(0, 0, 0, 0);
53 layout->addWidget(m_config);
54 QHBoxLayout *layout2 = new QHBoxLayout(m_ui.widgetConfigButton);
55 layout2->setContentsMargins(0, 0, 0, 0);
56 layout2->addWidget(m_config->getShowHideButton());
58 QToolButton *buttonShowLines = new QToolButton(m_config);
60 buttonShowLines->setIcon(KIcon("insert-horizontal-rule"));
61 buttonShowLines->setToolTip(i18n("Show/Hide the lines connecting the corners"));
62 buttonShowLines->setCheckable(true);
63 connect(buttonShowLines, SIGNAL(toggled(bool)), this, SLOT(slotShowLines(bool)));
64 m_config->addWidget(buttonShowLines, 0, 2);
66 int width = m_monitor->render->frameRenderWidth();
67 int height = m_monitor->render->renderHeight();
69 m_ui.spinX1->setRange(-width, width * 2);
70 m_ui.spinX2->setRange(-width, width * 2);
71 m_ui.spinX3->setRange(-width, width * 2);
72 m_ui.spinX4->setRange(-width, width * 2);
73 m_ui.spinY1->setRange(-height, height * 2);
74 m_ui.spinY2->setRange(-height, height * 2);
75 m_ui.spinY3->setRange(-height, height * 2);
76 m_ui.spinY4->setRange(-height, height * 2);
78 m_ui.toolReset1->setIcon(KIcon("edit-undo"));
79 m_ui.toolReset1->setToolTip(i18n("Reset Corner 1"));
80 m_ui.toolReset2->setIcon(KIcon("edit-undo"));
81 m_ui.toolReset2->setToolTip(i18n("Reset Corner 2"));
82 m_ui.toolReset3->setIcon(KIcon("edit-undo"));
83 m_ui.toolReset3->setToolTip(i18n("Reset Corner 3"));
84 m_ui.toolReset4->setIcon(KIcon("edit-undo"));
85 m_ui.toolReset4->setToolTip(i18n("Reset Corner 4"));
87 connect(m_ui.spinX1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
88 connect(m_ui.spinX2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
89 connect(m_ui.spinX3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
90 connect(m_ui.spinX4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
91 connect(m_ui.spinY1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
92 connect(m_ui.spinY2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
93 connect(m_ui.spinY3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
94 connect(m_ui.spinY4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
96 connect(m_ui.toolReset1, SIGNAL(clicked()), this, SLOT(slotResetCorner1()));
97 connect(m_ui.toolReset2, SIGNAL(clicked()), this, SLOT(slotResetCorner2()));
98 connect(m_ui.toolReset3, SIGNAL(clicked()), this, SLOT(slotResetCorner3()));
99 connect(m_ui.toolReset4, SIGNAL(clicked()), this, SLOT(slotResetCorner4()));
101 connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool)));
102 connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
103 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
106 CornersWidget::~CornersWidget()
109 m_scene->removeItem(m_item);
112 m_monitor->slotEffectScene(false);
115 void CornersWidget::setRange(int minframe, int maxframe)
117 m_inPoint = minframe;
118 m_outPoint = maxframe;
119 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
122 void CornersWidget::slotUpdateItem()
124 QPointF c1(m_ui.spinX1->value(), m_ui.spinY1->value());
125 QPointF c2(m_ui.spinX2->value(), m_ui.spinY2->value());
126 QPointF c3(m_ui.spinX3->value(), m_ui.spinY3->value());
127 QPointF c4(m_ui.spinX4->value(), m_ui.spinY4->value());
129 m_item->setPolygon(QPolygonF() << c1 << c2 << c3 << c4);
131 emit parameterChanged();
134 void CornersWidget::slotUpdateProperties(bool changed)
136 QPolygon pol = m_item->polygon().toPolygon();
138 m_ui.spinX1->setValue(pol.at(0).x());
139 m_ui.spinX2->setValue(pol.at(1).x());
140 m_ui.spinX3->setValue(pol.at(2).x());
141 m_ui.spinX4->setValue(pol.at(3).x());
142 m_ui.spinY1->setValue(pol.at(0).y());
143 m_ui.spinY2->setValue(pol.at(1).y());
144 m_ui.spinY3->setValue(pol.at(2).y());
145 m_ui.spinY4->setValue(pol.at(3).y());
149 emit parameterChanged();
153 QPolygon CornersWidget::getValue()
155 qreal width = m_monitor->render->frameRenderWidth();
156 qreal height = m_monitor->render->renderHeight();
157 QPolygon corners = m_item->polygon().toPolygon();
160 for (int i = 0; i < 4; ++i) {
162 p.setX((p.x() / width + 1) / 3.0 * m_factor);
163 p.setY((p.y() / height + 1) / 3.0 * m_factor);
169 void CornersWidget::setValue(const QPolygon& points)
171 int width = m_monitor->render->frameRenderWidth();
172 int height = m_monitor->render->renderHeight();
175 for (int i = 0; i < 4; ++i) {
177 p.setX((p.x() / (qreal)m_factor * 3 - 1) * width);
178 p.setY((p.y() / (qreal)m_factor * 3 - 1) * height);
181 m_item->setPolygon(corners);
183 slotUpdateProperties(false);
186 void CornersWidget::slotCheckMonitorPosition(int renderPos)
190 We do only get the position in timeline if this geometry belongs to a transition,
191 therefore we need two ways here.
194 emit checkMonitorPosition(renderPos);
196 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
197 if (!m_scene->views().at(0)->isVisible())
198 m_monitor->slotEffectScene(true);
200 m_monitor->slotEffectScene(false);
206 void CornersWidget::slotShowScene(bool show)
210 m_monitor->slotEffectScene(false);
212 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
215 void CornersWidget::slotShowLines(bool show)
217 KdenliveSettings::setOnmonitoreffects_cornersshowlines(show);
221 void CornersWidget::slotResetCorner1()
224 m_ui.spinX1->setValue(0);
225 m_ui.spinY1->setValue(0);
230 void CornersWidget::slotResetCorner2()
233 m_ui.spinX2->setValue(m_monitor->render->frameRenderWidth());
234 m_ui.spinY2->setValue(0);
239 void CornersWidget::slotResetCorner3()
242 m_ui.spinX3->setValue(m_monitor->render->frameRenderWidth());
243 m_ui.spinY3->setValue(m_monitor->render->renderHeight());
248 void CornersWidget::slotResetCorner4()
251 m_ui.spinX4->setValue(0);
252 m_ui.spinY4->setValue(m_monitor->render->renderHeight());
257 #include "cornerswidget.moc"