#include "monitorscenecontrolwidget.h"
#include "onmonitoritems/onmonitorcornersitem.h"
#include "renderer.h"
+#include "kdenlivesettings.h"
#include <QGraphicsView>
-#include <QHBoxLayout>
+#include <QGridLayout>
#include <KIcon>
-CornersWidget::CornersWidget(Monitor* monitor, int clipPos, bool isEffect, int factor, QWidget* parent) :
- QWidget(parent),
+CornersWidget::CornersWidget(Monitor *monitor, QDomElement e, int minFrame, int maxFrame, Timecode tc, int activeKeyframe, QWidget* parent) :
+ KeyframeEdit(e, minFrame, maxFrame, tc, activeKeyframe, parent),
m_monitor(monitor),
- m_clipPos(clipPos),
- m_inPoint(0),
- m_outPoint(1),
- m_isEffect(isEffect),
- m_showScene(true),
- m_factor(factor)
+ m_showScene(true)
{
- m_ui.setupUi(this);
-
m_scene = monitor->getEffectScene();
m_item = new OnMonitorCornersItem(m_scene);
m_scene->addItem(m_item);
- m_config = new MonitorSceneControlWidget(m_scene, m_ui.frameConfig);
- QHBoxLayout *layout = new QHBoxLayout(m_ui.frameConfig);
- layout->addWidget(m_config->getShowHideButton());
- layout->addWidget(m_config);
-
- int width = m_monitor->render->frameRenderWidth();
- int height = m_monitor->render->renderHeight();
-
- m_ui.spinX1->setRange(-width, width * 2);
- m_ui.spinX2->setRange(-width, width * 2);
- m_ui.spinX3->setRange(-width, width * 2);
- m_ui.spinX4->setRange(-width, width * 2);
- m_ui.spinY1->setRange(-height, height * 2);
- m_ui.spinY2->setRange(-height, height * 2);
- m_ui.spinY3->setRange(-height, height * 2);
- m_ui.spinY4->setRange(-height, height * 2);
-
- m_ui.toolReset1->setIcon(KIcon("edit-undo"));
- m_ui.toolReset1->setToolTip(i18n("Reset Corner 1"));
- m_ui.toolReset2->setIcon(KIcon("edit-undo"));
- m_ui.toolReset2->setToolTip(i18n("Reset Corner 2"));
- m_ui.toolReset3->setIcon(KIcon("edit-undo"));
- m_ui.toolReset3->setToolTip(i18n("Reset Corner 3"));
- m_ui.toolReset4->setIcon(KIcon("edit-undo"));
- m_ui.toolReset4->setToolTip(i18n("Reset Corner 4"));
-
- connect(m_ui.spinX1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinX2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinX3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinX4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinY1, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinY2, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinY3, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
- connect(m_ui.spinY4, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateItem()));
-
- connect(m_ui.toolReset1, SIGNAL(clicked()), this, SLOT(slotResetCorner1()));
- connect(m_ui.toolReset2, SIGNAL(clicked()), this, SLOT(slotResetCorner2()));
- connect(m_ui.toolReset3, SIGNAL(clicked()), this, SLOT(slotResetCorner3()));
- connect(m_ui.toolReset4, SIGNAL(clicked()), this, SLOT(slotResetCorner4()));
+ m_config = new MonitorSceneControlWidget(m_scene, this);
+ QGridLayout *l = static_cast<QGridLayout *>(layout());
+ l->addWidget(m_config->getShowHideButton(), 1, 1);
+ l->addWidget(m_config, 1, 2);
+
+ QToolButton *buttonShowLines = new QToolButton(m_config);
+ // TODO: Better Icons
+ buttonShowLines->setIcon(KIcon("insert-horizontal-rule"));
+ buttonShowLines->setToolTip(i18n("Show/Hide the lines connecting the corners"));
+ buttonShowLines->setCheckable(true);
+ buttonShowLines->setChecked(KdenliveSettings::onmonitoreffects_cornersshowlines());
+ connect(buttonShowLines, SIGNAL(toggled(bool)), this, SLOT(slotShowLines(bool)));
+ m_config->addWidget(buttonShowLines, 0, 2);
+ QToolButton *buttonShowControls = new QToolButton(m_config);
+ buttonShowControls->setIcon(KIcon("transform-move"));
+ buttonShowControls->setToolTip(i18n("Show additional controls"));
+ buttonShowControls->setCheckable(true);
+ buttonShowControls->setChecked(KdenliveSettings::onmonitoreffects_cornersshowcontrols());
+ connect(buttonShowControls, SIGNAL(toggled(bool)), this, SLOT(slotShowControls(bool)));
+ m_config->addWidget(buttonShowControls, 0, 3);
connect(m_config, SIGNAL(showScene(bool)), this, SLOT(slotShowScene(bool)));
connect(m_monitor, SIGNAL(renderPosition(int)), this, SLOT(slotCheckMonitorPosition(int)));
connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateProperties()));
+
+ connect(keyframe_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateItem()));
+ connect(keyframe_list, SIGNAL(cellChanged(int, int)), this, SLOT(slotUpdateItem()));
}
CornersWidget::~CornersWidget()
m_monitor->slotEffectScene(false);
}
-void CornersWidget::setRange(int minframe, int maxframe)
-{
- m_inPoint = minframe;
- m_outPoint = maxframe;
- slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
-}
-
-void CornersWidget::slotUpdateItem()
+void CornersWidget::addParameter(QDomElement e, int activeKeyframe)
{
- QPointF c1(m_ui.spinX1->value(), m_ui.spinY1->value());
- QPointF c2(m_ui.spinX2->value(), m_ui.spinY2->value());
- QPointF c3(m_ui.spinX3->value(), m_ui.spinY3->value());
- QPointF c4(m_ui.spinX4->value(), m_ui.spinY4->value());
-
- m_item->setPolygon(QPolygonF() << c1 << c2 << c3 << c4);
+ KeyframeEdit::addParameter(e, activeKeyframe);
- emit parameterChanged();
-}
-
-void CornersWidget::slotUpdateProperties(bool changed)
-{
- QPolygon pol = m_item->polygon().toPolygon();
- blockSignals(true);
- m_ui.spinX1->setValue(pol.at(0).x());
- m_ui.spinX2->setValue(pol.at(1).x());
- m_ui.spinX3->setValue(pol.at(2).x());
- m_ui.spinX4->setValue(pol.at(3).x());
- m_ui.spinY1->setValue(pol.at(0).y());
- m_ui.spinY2->setValue(pol.at(1).y());
- m_ui.spinY3->setValue(pol.at(2).y());
- m_ui.spinY4->setValue(pol.at(3).y());
- blockSignals(false);
-
- if (changed)
- emit parameterChanged();
+ if (!m_item->polygon().count())
+ slotUpdateItem();
}
-
-QPolygon CornersWidget::getValue()
+void CornersWidget::slotUpdateItem()
{
- qreal width = m_monitor->render->frameRenderWidth();
- qreal height = m_monitor->render->renderHeight();
- QPolygon corners = m_item->polygon().toPolygon();
- QPolygon points;
- QPoint p;
- for (int i = 0; i < 4; ++i) {
- p = corners.at(i);
- p.setX((p.x() / width + 1) / 3.0 * m_factor);
- p.setY((p.y() / height + 1) / 3.0 * m_factor);
- points << p;
+ if (keyframe_list->columnCount() < 8)
+ return;
+
+ QTableWidgetItem *item = keyframe_list->currentItem();
+ if (!item)
+ return;
+
+ QList<QPointF> points;
+ double val;
+ for (int col = 0; col < 8; col++) {
+ if (!keyframe_list->item(item->row(), col))
+ return;
+ val = (keyframe_list->item(item->row(), col)->text().toInt() - 2000) / 2000.;
+ if (col % 2 == 0)
+ points << QPointF(val * m_monitor->render->frameRenderWidth(), 0);
+ else
+ points[col / 2].setY(val * m_monitor->render->renderHeight());
}
- return points;
+
+ m_scene->blockSignals(true);
+ m_item->setPolygon(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3));
+ m_scene->blockSignals(false);
}
-void CornersWidget::setValue(const QPolygon& points)
+void CornersWidget::slotUpdateProperties()
{
- int width = m_monitor->render->frameRenderWidth();
- int height = m_monitor->render->renderHeight();
- QPolygonF corners;
- QPoint p;
- for (int i = 0; i < 4; ++i) {
- p = points.at(i);
- p.setX((p.x() / (qreal)m_factor * 3 - 1) * width);
- p.setY((p.y() / (qreal)m_factor * 3 - 1) * height);
- corners << p;
+ if (keyframe_list->columnCount() < 8)
+ return;
+
+ QPolygonF pol = m_item->polygon();
+
+ QTableWidgetItem *item = keyframe_list->currentItem();
+ double val;
+ for (int col = 0; col < 8; col++) {
+ if (col % 2 == 0)
+ val = pol.at(col / 2).x() / (double)m_monitor->render->frameRenderWidth();
+ else
+ val = pol.at(col / 2).y() / (double)m_monitor->render->renderHeight();
+ val *= 2000;
+ val += 2000;
+ QTableWidgetItem *nitem = keyframe_list->item(item->row(), col);
+ if (nitem->text().toInt() != (int)val)
+ nitem->setText(QString::number((int)val));
}
- m_item->setPolygon(corners);
- slotUpdateProperties(false);
+ slotAdjustKeyframeInfo(false);
}
void CornersWidget::slotCheckMonitorPosition(int renderPos)
{
- if (m_showScene) {
- /*
- We do only get the position in timeline if this geometry belongs to a transition,
- therefore we need two ways here.
- */
- if (m_isEffect) {
- emit checkMonitorPosition(renderPos);
- } else {
- if (renderPos >= m_clipPos && renderPos <= m_clipPos + m_outPoint - m_inPoint) {
- if (!m_scene->views().at(0)->isVisible())
- m_monitor->slotEffectScene(true);
- } else {
- m_monitor->slotEffectScene(false);
- }
- }
- }
+ if (m_showScene)
+ emit checkMonitorPosition(renderPos);
}
void CornersWidget::slotShowScene(bool show)
slotCheckMonitorPosition(m_monitor->render->seekFramePosition());
}
-void CornersWidget::slotResetCorner1()
-{
- blockSignals(true);
- m_ui.spinX1->setValue(0);
- m_ui.spinY1->setValue(0);
- blockSignals(false);
- slotUpdateItem();
-}
-
-void CornersWidget::slotResetCorner2()
-{
- blockSignals(true);
- m_ui.spinX2->setValue(m_monitor->render->frameRenderWidth());
- m_ui.spinY2->setValue(0);
- blockSignals(false);
- slotUpdateItem();
-}
-
-void CornersWidget::slotResetCorner3()
+void CornersWidget::slotShowLines(bool show)
{
- blockSignals(true);
- m_ui.spinX3->setValue(m_monitor->render->frameRenderWidth());
- m_ui.spinY3->setValue(m_monitor->render->renderHeight());
- blockSignals(false);
- slotUpdateItem();
+ KdenliveSettings::setOnmonitoreffects_cornersshowlines(show);
+ m_item->update();
}
-void CornersWidget::slotResetCorner4()
+void CornersWidget::slotShowControls(bool show)
{
- blockSignals(true);
- m_ui.spinX4->setValue(0);
- m_ui.spinY4->setValue(m_monitor->render->renderHeight());
- blockSignals(false);
- slotUpdateItem();
+ KdenliveSettings::setOnmonitoreffects_cornersshowcontrols(show);
+ m_item->update();
}
#include "cornerswidget.moc"