Fix crash when adding corners effect (some porting required)

BUG: 355285
parent ff2dbd40
......@@ -21,6 +21,7 @@ install(FILES
kdenlivetranscodingrc
kdenlivemonitor.qml
kdenlivemonitoreffectscene.qml
kdenlivemonitorcornerscene.qml
kdenlivemonitorsplit.qml
DESTINATION ${DATA_INSTALL_DIR}/kdenlive)
install(FILES kdenlive.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR})
......
import QtQuick 2.0
Item {
id: root
objectName: "rootcornerscene"
// default size, but scalable by user
height: 300; width: 400
property string comment
property string framenum
property rect framesize
property point profile
property point center
property double scale
onScaleChanged: canvas.requestPaint()
property bool iskeyframe
property int requestedKeyFrame
property var centerPoints: []
onCenterPointsChanged: canvas.requestPaint()
signal effectPolygonChanged()
signal addKeyframe()
signal seekToKeyframe()
Text {
id: fontReference
property int fontSize
fontSize: font.pointSize
}
Canvas {
id: canvas
property double handleSize
width: root.width
height: root.height
anchors.centerIn: root
contextType: "2d";
handleSize: fontReference.fontSize / 2
renderStrategy: Canvas.Threaded;
onPaint:
{
if (context) {
context.clearRect(0,0, width, height);
context.beginPath()
context.strokeStyle = Qt.rgba(1, 0, 0, 0.5)
context.fillStyle = Qt.rgba(1, 0, 0, 0.5)
context.lineWidth = 2
for(var i = 0; i < root.centerPoints.length; i++)
{
var p1 = convertPoint(root.centerPoints[i])
if(i == 0)
{
context.moveTo(p1.x, p1.y)
context.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
continue
}
context.lineTo(p1.x, p1.y)
context.fillRect(p1.x - handleSize, p1.y - handleSize, 2 * handleSize, 2 * handleSize);
}
var p1 = convertPoint(root.centerPoints[0])
context.lineTo(p1.x, p1.y)
context.stroke()
context.restore()
}
}
function convertPoint(p)
{
var x = frame.x + p.x * root.scale
var y = frame.y + p.y * root.scale
return Qt.point(x,y);
}
}
Rectangle {
id: frame
objectName: "referenceframe"
property color hoverColor: "#ff0000"
width: root.profile.x * root.scale
height: root.profile.y * root.scale
x: root.center.x - width / 2
y: root.center.y - height / 2
color: "transparent"
border.color: "#ffffff00"
}
MouseArea {
id: global
objectName: "global"
width: root.width; height: root.height
anchors.centerIn: root
hoverEnabled: true
cursorShape: containsMouse ? Qt.PointingHandCursor : Qt.ArrowCursor
readonly property bool containsMouse: {
if (pressed && root.requestedKeyFrame >= 0) return true;
for(var i = 0; i < root.centerPoints.length; i++)
{
var p1 = canvas.convertPoint(root.centerPoints[i])
if (Math.abs(p1.x - mouseX) <= canvas.handleSize && Math.abs(p1.y - mouseY) <= canvas.handleSize) {
root.requestedKeyFrame = i
return true
}
}
root.requestedKeyFrame = -1
return false
}
onDoubleClicked: {
root.addKeyframe()
}
onPositionChanged: {
if (pressed && root.requestedKeyFrame >= 0) {
root.centerPoints[root.requestedKeyFrame].x = (mouseX - frame.x) / root.scale;
root.centerPoints[root.requestedKeyFrame].y = (mouseY - frame.y) / root.scale;
canvas.requestPaint()
}
}
onReleased: {
root.effectPolygonChanged()
}
}
}
......@@ -117,6 +117,13 @@ enum ProjectTool {
SpacerTool = 2
};
enum MonitorSceneType {
MonitorSceneNone = 0,
MonitorSceneGeometry,
MonitorSceneCorners,
MonitorSceneRoto
};
enum TransitionType {
/** TRANSITIONTYPE: between 0-99: video trans, 100-199: video+audio trans, 200-299: audio trans */
LumaTransition = 0,
......
......@@ -322,7 +322,7 @@ void CollapsibleEffect::slotDisable(bool disable, bool emitInfo)
if (!disable || KdenliveSettings::disable_effect_parameters()) {
widgetFrame->setEnabled(!disable);
}
if (emitInfo) emit effectStateChanged(disable, effectIndex(), isActive() && needsMonitorEffectScene());
if (emitInfo) emit effectStateChanged(disable, effectIndex(), needsMonitorEffectScene());
}
void CollapsibleEffect::slotDeleteEffect()
......@@ -521,8 +521,6 @@ void CollapsibleEffect::setupWidget(const ItemInfo &info, EffectMetaInfo *metaIn
connect (m_paramWidget, SIGNAL(checkMonitorPosition(int)), this, SIGNAL(checkMonitorPosition(int)));
connect (m_paramWidget, SIGNAL(seekTimeline(int)), this, SIGNAL(seekTimeline(int)));
connect(m_paramWidget, SIGNAL(importClipKeyframes()), this, SIGNAL(importClipKeyframes()));
}
void CollapsibleEffect::slotDisableEffect(bool disable)
......@@ -530,7 +528,7 @@ void CollapsibleEffect::slotDisableEffect(bool disable)
title->setEnabled(!disable);
m_enabledButton->setActive(disable);
m_effect.setAttribute("disable", disable ? 1 : 0);
emit effectStateChanged(disable, effectIndex(), isActive() && needsMonitorEffectScene());
emit effectStateChanged(disable, effectIndex(), needsMonitorEffectScene());
}
bool CollapsibleEffect::isGroup() const
......@@ -645,12 +643,12 @@ void CollapsibleEffect::adjustButtons(int ix, int max)
buttonDown->setVisible(ix < max - 1);
}
bool CollapsibleEffect::needsMonitorEffectScene() const
MonitorSceneType CollapsibleEffect::needsMonitorEffectScene() const
{
if (m_paramWidget)
return m_paramWidget->needsMonitorEffectScene();
else
return false;
return MonitorSceneNone;
}
void CollapsibleEffect::setRange(int inPoint , int outPoint)
......
......@@ -71,8 +71,8 @@ public:
void groupStateChanged(bool collapsed);
/** @brief Show / hide up / down buttons. */
void adjustButtons(int ix, int max);
/** @brief Returns true of this effect requires an on monitor adjustable effect scene. */
bool needsMonitorEffectScene() const;
/** @brief Returns this effect's monitor scene type if any is needed. */
MonitorSceneType needsMonitorEffectScene() const;
/** @brief Set clip in / out points. */
void setRange(int inPoint , int outPoint);
/** @brief Import keyframes from a clip's data. */
......@@ -132,7 +132,7 @@ protected:
signals:
void parameterChanged(const QDomElement &, const QDomElement&, int);
void syncEffectsPos(int);
void effectStateChanged(bool, int ix, bool effectNeedsMonitorScene);
void effectStateChanged(bool, int ix, MonitorSceneType effectNeedsMonitorScene);
void deleteEffect(const QDomElement &);
void activateEffect(int);
void checkMonitorPosition(int);
......
......@@ -188,9 +188,9 @@ void EffectStackEdit::initEffectScene(int pos)
}
bool EffectStackEdit::needsMonitorEffectScene() const
MonitorSceneType EffectStackEdit::needsMonitorEffectScene() const
{
if (!m_paramWidget) return false;
if (!m_paramWidget) return MonitorSceneNone;
return m_paramWidget->needsMonitorEffectScene();
}
......
......@@ -51,8 +51,8 @@ public:
Monitor *monitor();
/** @brief Install event filter so that scrolling with mouse wheel does not change parameter value. */
virtual bool eventFilter( QObject * o, QEvent * e );
/** @brief Returns true if this transition requires an on monitor scene. */
bool needsMonitorEffectScene() const;
/** @brief Returns type of monitor scene requested by this transition. */
MonitorSceneType needsMonitorEffectScene() const;
/** @brief Set keyframes for this transition. */
void setKeyframes(const QString &data, int maximum);
void updatePalette();
......
......@@ -28,8 +28,6 @@
#include "effectslist/effectslist.h"
#include "timeline/clipitem.h"
#include "project/transitionsettings.h"
#include "monitor/monitoreditwidget.h"
#include "monitor/monitorscene.h"
#include "utils/KoIconUtils.h"
#include "mltcontroller/clipcontroller.h"
#include "timeline/transition.h"
......@@ -54,11 +52,11 @@ EffectStackView2::EffectStackView2(Monitor *projectMonitor, QWidget *parent) :
m_draggedEffect(NULL),
m_draggedGroup(NULL),
m_groupIndex(0),
m_monitorSceneWanted(false),
m_monitorSceneWanted(MonitorSceneNone),
m_trackInfo(),
m_transition(NULL)
{
m_effectMetaInfo.monitor = NULL;
m_effectMetaInfo.monitor = projectMonitor;
m_effects = QList <CollapsibleEffect*>();
setAcceptDrops(true);
setLayout(&m_layout);
......@@ -134,7 +132,7 @@ void EffectStackView2::slotTransitionItemSelected(Transition* t, int nextTrack,
void EffectStackView2::slotRenderPos(int pos)
{
if (m_effects.isEmpty()) return;
if (m_monitorSceneWanted) slotCheckMonitorPosition(pos);
if (m_monitorSceneWanted != MonitorSceneNone) slotCheckMonitorPosition(pos);
if (m_status == TIMELINE_CLIP && m_clipref) pos = pos - m_clipref->startPos().frames(KdenliveSettings::project_fps());
for (int i = 0; i< m_effects.count(); ++i)
......@@ -191,9 +189,9 @@ void EffectStackView2::slotClipItemSelected(ClipItem* c, Monitor *m)
if (m_clipref == NULL) {
//TODO: clear list, reset paramdesc and info
// If monitor scene is displayed, hide it
if (m_monitorSceneWanted) {
m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_monitorSceneWanted = false;
if (m_monitorSceneWanted != MonitorSceneNone) {
m_monitorSceneWanted = MonitorSceneNone;
m_effectMetaInfo.monitor->slotShowEffectScene(m_monitorSceneWanted);
}
m_status = EMPTY;
clear();
......@@ -239,9 +237,9 @@ void EffectStackView2::slotMasterClipItemSelected(ClipController* c, Monitor *m)
if (m_masterclipref == NULL) {
//TODO: clear list, reset paramdesc and info
// If monitor scene is displayed, hide it
if (m_monitorSceneWanted) {
m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_monitorSceneWanted = false;
if (m_monitorSceneWanted != MonitorSceneNone) {
m_monitorSceneWanted = MonitorSceneNone;
m_effectMetaInfo.monitor->slotShowEffectScene(m_monitorSceneWanted);
}
m_status = EMPTY;
clear();
......@@ -278,7 +276,7 @@ void EffectStackView2::slotTrackItemSelected(int ix, const TrackInfo &info, Moni
void EffectStackView2::setupListView()
{
blockSignals(true);
m_monitorSceneWanted = false;
m_monitorSceneWanted = MonitorSceneNone;
m_draggedEffect = NULL;
m_draggedGroup = NULL;
disconnect(m_effectMetaInfo.monitor, SIGNAL(renderPosition(int)), this, SLOT(slotRenderPos(int)));
......@@ -366,7 +364,7 @@ void EffectStackView2::setupListView()
isSelected = currentEffect->effectIndex() == m_masterclipref->selectedEffectIndex;
}
if (isSelected) {
if (currentEffect->needsMonitorEffectScene()) m_monitorSceneWanted = true;
m_monitorSceneWanted = currentEffect->needsMonitorEffectScene();
}
currentEffect->setActive(isSelected);
m_effects.append(currentEffect);
......@@ -393,7 +391,7 @@ void EffectStackView2::setupListView()
vbox1->addStretch(10);
slotUpdateCheckAllButton();
// show monitor scene if necessary
if (!m_monitorSceneWanted) m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_effectMetaInfo.monitor->slotShowEffectScene(m_monitorSceneWanted);
// Wait a little bit for the new layout to be ready, then check if we have a scrollbar
QTimer::singleShot(200, this, SLOT(slotCheckWheelEventFilter()));
......@@ -409,7 +407,7 @@ void EffectStackView2::connectEffect(CollapsibleEffect *currentEffect)
connect(currentEffect, SIGNAL(reloadEffects()), this , SIGNAL(reloadEffects()));
connect(currentEffect, SIGNAL(resetEffect(int)), this , SLOT(slotResetEffect(int)));
connect(currentEffect, SIGNAL(changeEffectPosition(QList<int>,bool)), this , SLOT(slotMoveEffectUp(QList<int>,bool)));
connect(currentEffect, SIGNAL(effectStateChanged(bool,int,bool)), this, SLOT(slotUpdateEffectState(bool,int,bool)));
connect(currentEffect, SIGNAL(effectStateChanged(bool,int,MonitorSceneType)), this, SLOT(slotUpdateEffectState(bool,int,MonitorSceneType)));
connect(currentEffect, SIGNAL(activateEffect(int)), this, SLOT(slotSetCurrentEffect(int)));
connect(currentEffect, SIGNAL(seekTimeline(int)), this , SLOT(slotSeekTimeline(int)));
connect(currentEffect, SIGNAL(createGroup(int)), this , SLOT(slotCreateGroup(int)));
......@@ -545,15 +543,15 @@ void EffectStackView2::startDrag()
}
void EffectStackView2::slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene)
void EffectStackView2::slotUpdateEffectState(bool disable, int index, MonitorSceneType needsMonitorEffectScene)
{
if (m_monitorSceneWanted && disable) {
m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_monitorSceneWanted = false;
if (m_monitorSceneWanted != MonitorSceneNone && disable) {
m_monitorSceneWanted = MonitorSceneNone;
m_effectMetaInfo.monitor->slotShowEffectScene(MonitorSceneNone);
}
else if (!disable && !m_monitorSceneWanted && needsMonitorEffectScene) {
m_effectMetaInfo.monitor->slotShowEffectScene(true);
m_monitorSceneWanted = true;
else if (!disable && m_monitorSceneWanted == needsMonitorEffectScene) {
m_monitorSceneWanted = needsMonitorEffectScene;
m_effectMetaInfo.monitor->slotShowEffectScene(m_monitorSceneWanted);
}
switch (m_status) {
case TIMELINE_TRACK:
......@@ -597,17 +595,17 @@ void EffectStackView2::slotSeekTimeline(int pos)
void EffectStackView2::slotCheckMonitorPosition(int renderPos)
{
if (m_monitorSceneWanted) {
if (m_monitorSceneWanted != MonitorSceneNone) {
if (m_status == TIMELINE_TRACK || m_status == MASTER_CLIP || (m_clipref && renderPos >= m_clipref->startPos().frames(KdenliveSettings::project_fps()) && renderPos <= m_clipref->endPos().frames(KdenliveSettings::project_fps()))) {
if (!m_effectMetaInfo.monitor->effectSceneDisplayed()) {
m_effectMetaInfo.monitor->slotShowEffectScene(true);
if (!m_effectMetaInfo.monitor->effectSceneDisplayed(m_monitorSceneWanted)) {
m_effectMetaInfo.monitor->slotShowEffectScene(m_monitorSceneWanted);
}
} else {
m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_effectMetaInfo.monitor->slotShowEffectScene(MonitorSceneNone);
}
}
else {
m_effectMetaInfo.monitor->slotShowEffectScene(false);
m_effectMetaInfo.monitor->slotShowEffectScene(MonitorSceneNone);
}
}
......@@ -624,7 +622,7 @@ int EffectStackView2::trackIndex() const
void EffectStackView2::clear()
{
m_effects.clear();
m_monitorSceneWanted = false;
m_monitorSceneWanted = MonitorSceneNone;
QWidget *view = m_ui.container->takeWidget();
if (view) {
delete view;
......
......@@ -126,7 +126,7 @@ private:
int m_groupIndex;
/** @brief The current effect may require an on monitor scene. */
bool m_monitorSceneWanted;
MonitorSceneType m_monitorSceneWanted;
/** If in track mode: Info of the edited track to be able to access its duration. */
TrackInfo m_trackInfo;
......@@ -204,7 +204,7 @@ private slots:
void slotRenderPos(int pos);
/** @brief Called whenever an effect is enabled / disabled by user. */
void slotUpdateEffectState(bool disable, int index, bool needsMonitorEffectScene);
void slotUpdateEffectState(bool disable, int index, MonitorSceneType needsMonitorEffectScene);
void slotSetCurrentEffect(int ix);
......
......@@ -102,7 +102,7 @@ ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo
m_geometryWidget(NULL),
m_metaInfo(metaInfo),
m_effect(effect),
m_needsMonitorEffectScene(false)
m_monitorEffectScene(MonitorSceneNone)
{
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
......@@ -230,7 +230,7 @@ ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo
connect(pl, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
} else if (type == "geometry") {
if (true /*KdenliveSettings::on_monitor_effects()*/) {
m_needsMonitorEffectScene = true;
m_monitorEffectScene = MonitorSceneGeometry;
m_geometryWidget = new GeometryWidget(m_metaInfo->monitor, m_metaInfo->timecode, info.startPos.frames(KdenliveSettings::project_fps()), effect.hasAttribute("showrotation"), parent);
m_geometryWidget->setFrameSize(m_metaInfo->frameSize);
connect(m_geometryWidget, SIGNAL(parameterChanged()), this, SLOT(slotCollectAllParameters()));
......@@ -271,7 +271,7 @@ ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo
// we want a corners-keyframe-widget
CornersWidget *corners = new CornersWidget(m_metaInfo->monitor, pa, m_in, m_out, m_metaInfo->timecode, e.attribute("active_keyframe", "-1").toInt(), parent);
connect(this, SIGNAL(updateRange(int,int)), corners, SLOT(slotUpdateRange(int,int)));
m_needsMonitorEffectScene = true;
m_monitorEffectScene = MonitorSceneCorners;
connect(this, SIGNAL(syncEffectsPos(int)), corners, SLOT(slotSyncPosition(int)));
geo = static_cast<KeyframeEdit *>(corners);
} else {
......@@ -367,7 +367,7 @@ ParameterContainer::ParameterContainer(const QDomElement &effect, const ItemInfo
if (!depends.isEmpty())
meetDependency(paramName, type, EffectsList::parameter(e, depends));
} else if (type == "roto-spline") {
m_needsMonitorEffectScene = true;
m_monitorEffectScene = MonitorSceneRoto;
RotoWidget *roto = new RotoWidget(value.toLatin1(), m_metaInfo->monitor, info, m_metaInfo->timecode, parent);
connect(roto, SIGNAL(valueChanged()), this, SLOT(slotCollectAllParameters()));
connect(roto, SIGNAL(seekToPos(int)), this, SIGNAL(seekTimeline(int)));
......@@ -933,9 +933,9 @@ void ParameterContainer::clearLayout(QLayout *layout)
}
}
bool ParameterContainer::needsMonitorEffectScene() const
MonitorSceneType ParameterContainer::needsMonitorEffectScene() const
{
return m_needsMonitorEffectScene;
return m_monitorEffectScene;
}
void ParameterContainer::setKeyframes(const QString &data, int maximum)
......
......@@ -59,7 +59,7 @@ class MySpinBox : public QSpinBox
public:
explicit MySpinBox(QWidget * parent = 0);
protected:
void focusInEvent(QFocusEvent*);
void focusOutEvent(QFocusEvent*);
......@@ -75,7 +75,7 @@ public:
void updateTimecodeFormat();
void updateParameter(const QString &key, const QString &value);
/** @brief Returns true of this effect requires an on monitor adjustable effect scene. */
bool needsMonitorEffectScene() const;
MonitorSceneType needsMonitorEffectScene() const;
/** @brief Set keyframes for this param. */
void setKeyframes(const QString &data, int maximum);
/** @brief Update the in / out for the clip. */
......@@ -107,7 +107,7 @@ private:
EffectMetaInfo *m_metaInfo;
QDomElement m_effect;
QVBoxLayout *m_vbox;
bool m_needsMonitorEffectScene;
MonitorSceneType m_monitorEffectScene;
signals:
void parameterChanged(const QDomElement &, const QDomElement&, int);
......@@ -116,7 +116,7 @@ signals:
void disableCurrentFilter(bool);
void checkMonitorPosition(int);
void seekTimeline(int);
void showComments(bool);
void showComments(bool);
/** @brief Start an MLT filter job on this clip.
* @param filterParams a QMap containing filter name under the "filter" key, and all filter properties
* @param consumerParams a QMap containing consumer name under the "consumer" key, and all consumer properties
......
......@@ -22,7 +22,6 @@
#include "renderer.h"
#include "kdenlivesettings.h"
#include "monitor/monitor.h"
#include "monitor/monitorscene.h"
#include "monitor/monitoreditwidget.h"
#include "onmonitoritems/onmonitorcornersitem.h"
......@@ -35,49 +34,24 @@ inline int lerp( const int a, const int b, double t )
return a + (b - a) * t;
}
//TODO: port to new qml monitor edit
CornersWidget::CornersWidget(Monitor *monitor, const QDomElement& e, int minFrame, int maxFrame, const Timecode &tc, int activeKeyframe, QWidget* parent) :
KeyframeEdit(e, minFrame, maxFrame, tc, activeKeyframe, parent),
m_monitor(monitor),
m_pos(0)
{
//MonitorEditWidget *edit = NULL; //monitor->getEffectEdit();
m_scene = NULL; //edit->getScene();
//m_scene->cleanup();
m_item = NULL; //new OnMonitorCornersItem();
/*m_scene->addItem(m_item);
// TODO: Better Icons
edit->removeCustomControls();
edit->addCustomButton(KoIconUtils::themedIcon("transform-move"), i18n("Show additional controls"), this, SLOT(slotShowControls(bool)),
true, KdenliveSettings::onmonitoreffects_cornersshowcontrols());
edit->addCustomButton(KoIconUtils::themedIcon("insert-horizontal-rule"), i18n("Show/Hide the lines connecting the corners"), this, SLOT(slotShowLines(bool)),
true, KdenliveSettings::onmonitoreffects_cornersshowlines());
connect(m_item, SIGNAL(changed()), this, SLOT(slotUpdateProperties()));
connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotInsertKeyframe()));
connect(keyframe_list, SIGNAL(cellChanged(int,int)), this, SLOT(slotUpdateItem()));
m_scene->centerView();
*/
m_monitor->slotShowEffectScene(MonitorSceneCorners);
connect(m_monitor, SIGNAL(effectChanged(QVariantList)), this, SLOT(slotUpdateGeometry(QVariantList)));
connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateItem()));
}
CornersWidget::~CornersWidget()
{
if (m_scene) m_scene->removeItem(m_item);
if (m_item) delete m_item;
if (m_monitor) {
/*MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();*/
}
}
void CornersWidget::addParameter(const QDomElement &e, int activeKeyframe)
{
KeyframeEdit::addParameter(e, activeKeyframe);
if (!m_item->polygon().count())
//if (!m_item->polygon().count())
slotUpdateItem();
}
......@@ -95,7 +69,7 @@ void CornersWidget::slotUpdateItem()
break;
}
QList<QPointF> points, pointsPrev, pointsNext;
QVariantList points, pointsPrev, pointsNext;
pointsPrev = getPoints(keyframeOld);
pointsNext = getPoints(keyframe);
if (pointsPrev.count() != 4 || pointsNext.count() != 4)
......@@ -107,57 +81,56 @@ void CornersWidget::slotUpdateItem()
points = pointsNext;
} else {
for (int i = 0; i < 4; ++i)
points.append(QLineF(pointsPrev.at(i), pointsNext.at(i)).pointAt(position));
points.append(QVariant(QLineF(pointsPrev.at(i).toPointF(), pointsNext.at(i).toPointF()).pointAt(position)));
}
m_scene->blockSignals(true);
m_item->setPolygon(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3));
m_scene->blockSignals(false);
//m_item->setPolygon(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3));
//m_monitor->setUpEffectGeometry(QPolygonF() << points.at(0) << points.at(1) << points.at(2) << points.at(3));
m_monitor->setUpEffectGeometry(QRect(), points);
bool enable = getPos(keyframe->row()) == m_pos || keyframe_list->rowCount() == 1;
m_item->setEnabled(enable);
m_scene->setEnabled(enable);
m_monitor->setEffectKeyframe(enable);
}
void CornersWidget::slotUpdateProperties()
void CornersWidget::slotUpdateGeometry(QVariantList points)
{
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)
for (int col = 0; col < 4; ++col) {
QPointF value = points.at(col).toPointF();
/*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));
val += 2000;*/
int valX = 2000 * value.x() / m_monitor->render->frameRenderWidth() + 2000;
int valY = 2000 * value.y() / m_monitor->render->renderHeight() + 2000;
QTableWidgetItem *nitem = keyframe_list->item(item->row(), col * 2);
if (nitem->text().toInt() != valX)
nitem->setText(QString::number(valX));
nitem = keyframe_list->item(item->row(), col * 2 + 1);
if (nitem->text().toInt() != valY)
nitem->setText(QString::number(valY));
}
slotAdjustKeyframeInfo(false);
}
QList<QPointF> CornersWidget::getPoints(QTableWidgetItem* keyframe)
QVariantList CornersWidget::getPoints(QTableWidgetItem* keyframe)
{
QList<QPointF> points;
QVariantList points;
if (!keyframe)
return points;
for (int col = 0; col < 8; ++col) {
for (int col = 0; col < 4; ++col) {
if (!keyframe_list->item(keyframe->row(), col))
return QList<QPointF>();
double val = (keyframe_list->item(keyframe->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 QVariantList();
double xVal = (keyframe_list->item(keyframe->row(), col * 2)->text().toInt() - 2000) / 2000.;
double yVal = (keyframe_list->item(keyframe->row(), col * 2 + 1)->text().toInt() - 2000) / 2000.;
points << QPointF(xVal * m_monitor->render->frameRenderWidth(), yVal * m_monitor->render->renderHeight());
}
return points;
}
......@@ -166,23 +139,24 @@ QList<QPointF> CornersWidget::getPoints(QTableWidgetItem* keyframe)
void CornersWidget::slotShowLines(bool show)
{
KdenliveSettings::setOnmonitoreffects_cornersshowlines(show);
m_item->update();
//m_item->update();
}
void CornersWidget::slotShowControls(bool show)
{
KdenliveSettings::setOnmonitoreffects_cornersshowcontrols(show);
m_item->update();
//m_item->update();
}
void CornersWidget::slotSyncPosition(int relTimelinePos)
{
if (keyframe_list->rowCount()) {
relTimelinePos = qBound(0, relTimelinePos, m_max);
if (relTimelinePos != m_pos - m_min) {
slotUpdateItem();
/*if (relTimelinePos != m_pos - m_min) {
m_pos = relTimelinePos + m_min;
slotUpdateItem();
}
}*/
}
}
......@@ -220,14 +194,14 @@ void CornersWidget::slotInsertKeyframe()
keyframe_list->insertRow(row);
keyframe_list->setVerticalHeaderItem(row, new QTableWidgetItem(getPosString(m_pos)));
QPolygonF pol = m_item->polygon();
QVariantList points = m_monitor->effectPolygon();
double val;
for (int i = 0; i < keyframe_list->columnCount(); ++i) {
if (i < 8) {
if (i % 2 == 0)
val = pol.at(i / 2).x() / (double)m_monitor->render->frameRenderWidth();
val = points.at(i / 2).toPointF().x() / (double)m_monitor->render->frameRenderWidth();
else
val = pol.at(i / 2).y() / (double)m_monitor->render->renderHeight();
val = points.at(i / 2).toPointF().y() / (double)m_monitor->render->renderHeight();
val *= 2000;
val += 2000;
keyframe_list->setItem(row, i, new QTableWidgetItem(QString::number((int)val)));
......
......@@ -51,19 +51,17 @@ public slots:
private:
Monitor *m_monitor;
MonitorScene *m_scene;
OnMonitorCornersItem *m_item;
int m_pos;
/** @brief Returns the corner positions set in the row of @param keyframe. */
QList <QPointF> getPoints(QTableWidgetItem *keyframe);
QVariantList getPoints(QTableWidgetItem *keyframe);
private slots:
/** @brief Updates the on-monitor item according to the current timeline position. */
void slotUpdateItem();
/** @brief Updates the keyframe editor according to the on-monitor item. */
void slotUpdateProperties();
void slotUpdateGeometry(QVariantList points);