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 buttonShowLines->setChecked(KdenliveSettings::onmonitoreffects_cornersshowlines());
64 connect(buttonShowLines, SIGNAL(toggled(bool)), this, SLOT(slotShowLines(bool)));
65 m_config->addWidget(buttonShowLines, 0, 2);
66 QToolButton *buttonShowControls = new QToolButton(m_config);
67 buttonShowControls->setIcon(KIcon("transform-move"));
68 buttonShowControls->setToolTip(i18n("Show additional controls"));
69 buttonShowControls->setCheckable(true);
70 buttonShowControls->setChecked(KdenliveSettings::onmonitoreffects_cornersshowcontrols());
71 connect(buttonShowControls, SIGNAL(toggled(bool)), this, SLOT(slotShowControls(bool)));
72 m_config->addWidget(buttonShowControls, 0, 3);
74 int width = m_monitor->render->frameRenderWidth();
75 int height = m_monitor->render->renderHeight();
77 m_ui.spinX1->setRange(-width, width * 2);
78 m_ui.spinX2->setRange(-width, width * 2);
79 m_ui.spinX3->setRange(-width, width * 2);
80 m_ui.spinX4->setRange(-width, width * 2);
81 m_ui.spinY1->setRange(-height, height * 2);
82 m_ui.spinY2->setRange(-height, height * 2);
83 m_ui.spinY3->setRange(-height, height * 2);
84 m_ui.spinY4->setRange(-height, height * 2);
86 m_ui.toolReset1->setIcon(KIcon("edit-undo"));
87 m_ui.toolReset1->setToolTip(i18n("Reset Corner 1"));
88 m_ui.toolReset2->setIcon(KIcon("edit-undo"));
89 m_ui.toolReset2->setToolTip(i18n("Reset Corner 2"));
90 m_ui.toolReset3->setIcon(KIcon("edit-undo"));
91 m_ui.toolReset3->setToolTip(i18n("Reset Corner 3"));
92 m_ui.toolReset4->setIcon(KIcon("edit-undo"));
93 m_ui.toolReset4->setToolTip(i18n("Reset Corner 4"));
95 connect(m_ui.spinX1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
96 connect(m_ui.spinX2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
97 connect(m_ui.spinX3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
98 connect(m_ui.spinX4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
99 connect(m_ui.spinY1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
100 connect(m_ui.spinY2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
101 connect(m_ui.spinY3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
102 connect(m_ui.spinY4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
104 connect(m_ui.toolReset1, SIGNAL(clicked()), this, SLOT(slotResetCorner1()));
105 connect(m_ui.toolReset2, SIGNAL(clicked()), this, SLOT(slotResetCorner2()));
106 connect(m_ui.toolReset3, SIGNAL(clicked()), this, SLOT(slotResetCorner3()));
107 connect(m_ui.toolReset4, SIGNAL(clicked()), this, SLOT(slotResetCorner4()));
109 connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool)));
110 connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
111 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
114 CornersWidget::~CornersWidget()
117 m_scene->removeItem(m_item);
120 m_monitor->slotEffectScene(false);
123 void CornersWidget::setRange(int minframe, int maxframe)
125 m_inPoint = minframe;
126 m_outPoint = maxframe;
127 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
130 void CornersWidget::slotUpdateItem()
132 QPointF c1(m_ui.spinX1->value(), m_ui.spinY1->value());
133 QPointF c2(m_ui.spinX2->value(), m_ui.spinY2->value());
134 QPointF c3(m_ui.spinX3->value(), m_ui.spinY3->value());
135 QPointF c4(m_ui.spinX4->value(), m_ui.spinY4->value());
137 m_item->setPolygon(QPolygonF() << c1 << c2 << c3 << c4);
139 emit parameterChanged();
142 void CornersWidget::slotUpdateProperties(bool changed)
144 QPolygon pol = m_item->polygon().toPolygon();
146 m_ui.spinX1->setValue(pol.at(0).x());
147 m_ui.spinX2->setValue(pol.at(1).x());
148 m_ui.spinX3->setValue(pol.at(2).x());
149 m_ui.spinX4->setValue(pol.at(3).x());
150 m_ui.spinY1->setValue(pol.at(0).y());
151 m_ui.spinY2->setValue(pol.at(1).y());
152 m_ui.spinY3->setValue(pol.at(2).y());
153 m_ui.spinY4->setValue(pol.at(3).y());
157 emit parameterChanged();
161 QPolygon CornersWidget::getValue()
163 qreal width = m_monitor->render->frameRenderWidth();
164 qreal height = m_monitor->render->renderHeight();
165 QPolygon corners = m_item->polygon().toPolygon();
168 for (int i = 0; i < 4; ++i) {
170 p.setX((p.x() / width + 1) / 3.0 * m_factor);
171 p.setY((p.y() / height + 1) / 3.0 * m_factor);
177 void CornersWidget::setValue(const QPolygon& points)
179 int width = m_monitor->render->frameRenderWidth();
180 int height = m_monitor->render->renderHeight();
183 for (int i = 0; i < 4; ++i) {
185 p.setX((p.x() / (qreal)m_factor * 3 - 1) * width);
186 p.setY((p.y() / (qreal)m_factor * 3 - 1) * height);
189 m_item->setPolygon(corners);
191 slotUpdateProperties(false);
194 void CornersWidget::slotCheckMonitorPosition(int renderPos)
198 We do only get the position in timeline if this geometry belongs to a transition,
199 therefore we need two ways here.
202 emit checkMonitorPosition(renderPos);
204 if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
205 if (!m_scene->views().at(0)->isVisible())
206 m_monitor->slotEffectScene(true);
208 m_monitor->slotEffectScene(false);
214 void CornersWidget::slotShowScene(bool show)
218 m_monitor->slotEffectScene(false);
220 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
223 void CornersWidget::slotShowLines(bool show)
225 KdenliveSettings::setOnmonitoreffects_cornersshowlines(show);
229 void CornersWidget::slotShowControls(bool show)
231 KdenliveSettings::setOnmonitoreffects_cornersshowcontrols(show);
235 void CornersWidget::slotResetCorner1()
238 m_ui.spinX1->setValue(0);
239 m_ui.spinY1->setValue(0);
244 void CornersWidget::slotResetCorner2()
247 m_ui.spinX2->setValue(m_monitor->render->frameRenderWidth());
248 m_ui.spinY2->setValue(0);
253 void CornersWidget::slotResetCorner3()
256 m_ui.spinX3->setValue(m_monitor->render->frameRenderWidth());
257 m_ui.spinY3->setValue(m_monitor->render->renderHeight());
262 void CornersWidget::slotResetCorner4()
265 m_ui.spinX4->setValue(0);
266 m_ui.spinY4->setValue(m_monitor->render->renderHeight());
271 #include "cornerswidget.moc"