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 <QGridLayout>
33 CornersWidget::CornersWidget(Monitor *monitor, QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent) :
34 KeyframeEdit(e, minFrame, maxFrame, tc, activeKeyframe, parent),
38 m_scene = monitor->getEffectScene();
40 m_item = new OnMonitorCornersItem(m_scene);
41 m_scene->addItem(m_item);
43 m_config = new MonitorSceneControlWidget(m_scene, this);
44 QGridLayout *l = static_cast<QGridLayout *>(layout());
45 l->addWidget(m_config->getShowHideButton(), 1, 1);
46 l->addWidget(m_config, 1, 2);
48 QToolButton *buttonShowLines = new QToolButton(m_config);
50 buttonShowLines->setIcon(KIcon("insert-horizontal-rule"));
51 buttonShowLines->setToolTip(i18n("Show/Hide the lines connecting the corners"));
52 buttonShowLines->setCheckable(true);
53 buttonShowLines->setChecked(KdenliveSettings::onmonitoreffects_cornersshowlines());
54 connect(buttonShowLines, SIGNAL(toggled(bool)), this, SLOT(slotShowLines(bool)));
55 m_config->addWidget(buttonShowLines, 0, 2);
56 QToolButton *buttonShowControls = new QToolButton(m_config);
57 buttonShowControls->setIcon(KIcon("transform-move"));
58 buttonShowControls->setToolTip(i18n("Show additional controls"));
59 buttonShowControls->setCheckable(true);
60 buttonShowControls->setChecked(KdenliveSettings::onmonitoreffects_cornersshowcontrols());
61 connect(buttonShowControls, SIGNAL(toggled(bool)), this, SLOT(slotShowControls(bool)));
62 m_config->addWidget(buttonShowControls, 0, 3);
64 connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool)));
65 connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
66 connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
68 connect(keyframe_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateItem()));
69 connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotUpdateItem()));
72 CornersWidget::~CornersWidget()
75 m_scene->removeItem(m_item);
78 m_monitor->slotEffectScene(false);
81 void CornersWidget::addParameter(QDomElement e, int activeKeyframe)
83 KeyframeEdit::addParameter(e, activeKeyframe);
85 if (!m_item->polygon().count())
89 void CornersWidget::slotUpdateItem()
91 if (keyframe_list->columnCount() < 8)
94 QTableWidgetItem *item = keyframe_list->currentItem();
98 QList<QPointF> points;
100 for (int col = 0; col < 8; col++) {
101 if (!keyframe_list->item(item->row(), col))
103 val = (keyframe_list->item(item->row(), col)->text().toInt() - 2000) / 2000.;
105 points << QPointF(val * m_monitor->render->frameRenderWidth(), 0);
107 points[col / 2].setY(val * m_monitor->render->renderHeight());
110 m_scene->blockSignals(true);
111 m_item->setPolygon(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3));
112 m_scene->blockSignals(false);
115 void CornersWidget::slotUpdateProperties()
117 if (keyframe_list->columnCount() < 8)
120 QPolygonF pol = m_item->polygon();
122 QTableWidgetItem *item = keyframe_list->currentItem();
124 for (int col = 0; col < 8; col++) {
126 val = pol.at(col / 2).x() / (double)m_monitor->render->frameRenderWidth();
128 val = pol.at(col / 2).y() / (double)m_monitor->render->renderHeight();
131 QTableWidgetItem *nitem = keyframe_list->item(item->row(), col);
132 if (nitem->text().toInt() != (int)val)
133 nitem->setText(QString::number((int)val));
136 slotAdjustKeyframeInfo(false);
139 void CornersWidget::slotCheckMonitorPosition(int renderPos)
142 emit checkMonitorPosition(renderPos);
145 void CornersWidget::slotShowScene(bool show)
149 m_monitor->slotEffectScene(false);
151 slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
154 void CornersWidget::slotShowLines(bool show)
156 KdenliveSettings::setOnmonitoreffects_cornersshowlines(show);
160 void CornersWidget::slotShowControls(bool show)
162 KdenliveSettings::setOnmonitoreffects_cornersshowcontrols(show);
166 #include "cornerswidget.moc"