Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix timeline corruption when zooming with mouse wheel over selected item

Fix transitions appearing behind grouped clips
parent 341314cc
......@@ -54,19 +54,20 @@ const QString stopmotionMonitor("stopmotionMonitor");
enum OperationType {
None = 0,
MoveOperation = 1,
ResizeStart = 2,
ResizeEnd = 3,
FadeIn = 4,
FadeOut = 5,
TransitionStart = 6,
TransitionEnd = 7,
MoveGuide = 8,
KeyFrame = 9,
Seek = 10,
Spacer = 11,
RubberSelection = 12,
ScrollTimeline = 13
MoveOperation,
ResizeStart,
ResizeEnd,
FadeIn,
FadeOut,
TransitionStart,
TransitionEnd,
MoveGuide,
KeyFrame,
Seek,
Spacer,
RubberSelection,
ScrollTimeline,
ZoomTimeline
};
enum ClipType {
......
......@@ -224,7 +224,7 @@ void StatusBarMessageLabel::paintEvent(QPaintEvent*)
backgroundColor = KStatefulBrush(KColorScheme::Window, KColorScheme::NegativeBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())).brush(this).color();
}
if (m_state == Desaturate && m_illumination > 0) {
backgroundColor.setAlpha(m_illumination * 2);
backgroundColor.setAlpha(qMax(m_illumination * 2, 255));
}
painter.fillRect(0, 0, width(), height(), backgroundColor);
......
......@@ -184,10 +184,20 @@ void AbstractGroupItem::paint(QPainter *p, const QStyleOptionGraphicsItem *optio
QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange) {
if (value.toBool()) setZValue(10);
if (value.toBool()) setZValue(3);
else setZValue(1);
}
if (change == ItemPositionChange && scene() && parentItem() == 0) {
CustomTrackScene *scene = NULL;
if (change == ItemPositionChange && parentItem() == 0) {
scene = projectScene();
}
if (scene) {
// calculate new position.
if (scene->isZooming) {
// For some reason, mouse wheel on selected itm sometimes triggered
// a position change event corrupting timeline, so discard it
return pos();
}
// calculate new position.
const int trackHeight = KdenliveSettings::trackheight();
QPointF start = sceneBoundingRect().topLeft();
......@@ -277,7 +287,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
QPainterPath shape;
if (projectScene()->editMode() == NormalEdit) {
shape = clipGroupShape(newPos - pos());
collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
collidingItems = scene->items(shape, Qt::IntersectsItemShape);
collidingItems.removeAll(this);
for (int i = 0; i < children.count(); ++i) {
if (children.at(i)->type() == GroupWidget) {
......@@ -315,7 +325,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
newPos.setX(newPos.x() + offset);
}
// If there is still a collision after our position adjust, restore original pos
collidingItems = scene()->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape);
collidingItems = scene->items(clipGroupShape(newPos - pos()), Qt::IntersectsItemShape);
collidingItems.removeAll(this);
for (int i = 0; i < children.count(); ++i) {
if (children.at(i)->type() == GroupWidget) {
......@@ -333,7 +343,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
if (projectScene()->editMode() == NormalEdit) {
shape = transitionGroupShape(newPos - pos());
collidingItems = scene()->items(shape, Qt::IntersectsItemShape);
collidingItems = scene->items(shape, Qt::IntersectsItemShape);
collidingItems.removeAll(this);
for (int i = 0; i < children.count(); ++i) {
if (children.at(i)->type() == GroupWidget) {
......@@ -372,7 +382,7 @@ QVariant AbstractGroupItem::itemChange(GraphicsItemChange change, const QVariant
newPos.setX(newPos.x() + offset);
}
// If there is still a collision after our position adjust, restore original pos
collidingItems = scene()->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape);
collidingItems = scene->items(transitionGroupShape(newPos - pos()), Qt::IntersectsItemShape);
for (int i = 0; i < children.count(); ++i) {
collidingItems.removeAll(children.at(i));
}
......
......@@ -1368,23 +1368,32 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange) {
if (value.toBool())
setZValue(10);
setZValue(3);
else
setZValue(2);
}
if (change == ItemPositionChange && scene()) {
CustomTrackScene *scene = NULL;
if (change == ItemPositionChange) {
scene = projectScene();
}
if (scene) {
// calculate new position.
//if (parentItem()) return pos();
if (scene->isZooming) {
// For some reason, mouse wheel on selected itm sometimes triggered
// a position change event corrupting timeline, so discard it
return pos();
}
if (property("resizingEnd").isValid()) return pos();
QPointF newPos = value.toPointF();
////qDebug() << "/// MOVING CLIP ITEM.------------\n++++++++++";
int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
int xpos = scene->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
xpos = qMax(xpos, 0);
newPos.setX(xpos);
// Warning: newPos gives a position relative to the click event, so hack to get absolute pos
int yOffset = property("y_absolute").toInt() + newPos.y();
int newTrack = yOffset / KdenliveSettings::trackheight();
newTrack = qMin(newTrack, projectScene()->tracksCount() - 1);
newTrack = qMin(newTrack, scene->tracksCount() - 1);
newTrack = qMax(newTrack, 0);
QStringList lockedTracks = property("locked_tracks").toStringList();
if (lockedTracks.contains(QString::number(newTrack))) {
......@@ -1396,8 +1405,8 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
QRectF sceneShape = rect();
sceneShape.translate(newPos);
QList<QGraphicsItem*> items;
if (projectScene()->editMode() == NormalEdit) {
items = scene()->items(sceneShape, Qt::IntersectsItemShape);
if (scene->editMode() == NormalEdit) {
items = scene->items(sceneShape, Qt::IntersectsItemShape);
}
items.removeAll(this);
bool forwardMove = newPos.x() > pos().x();
......@@ -1425,7 +1434,7 @@ QVariant ClipItem::itemChange(GraphicsItemChange change, const QVariant &value)
sceneShape.translate(QPointF(offset, 0));
newPos.setX(newPos.x() + offset);
}
QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
QList<QGraphicsItem*> subitems = scene->items(sceneShape, Qt::IntersectsItemShape);
subitems.removeAll(this);
for (int j = 0; j < subitems.count(); ++j) {
if (!subitems.at(j)->isEnabled()) continue;
......
......@@ -25,7 +25,8 @@ CustomTrackScene::CustomTrackScene(KdenliveDoc *doc, QObject *parent) :
QGraphicsScene(parent),
m_document(doc),
m_scale(1.0, 1.0),
m_editMode(NormalEdit)
m_editMode(NormalEdit),
isZooming(false)
{
}
......
......@@ -59,6 +59,7 @@ public:
MltVideoProfile profile() const;
void setEditMode(EditMode mode);
EditMode editMode() const;
bool isZooming;
private:
KdenliveDoc *m_document;
......
......@@ -315,14 +315,21 @@ bool CustomTrackView::checkTrackHeight()
void CustomTrackView::wheelEvent(QWheelEvent * e)
{
if (e->modifiers() == Qt::ControlModifier) {
if (e->delta() > 0) emit zoomIn();
else emit zoomOut();
if (m_operationMode == None || m_operationMode == ZoomTimeline) {
if (e->delta() > 0) emit zoomIn();
else emit zoomOut();
}
} else {
if (e->delta() <= 0) horizontalScrollBar()->setValue(horizontalScrollBar()->value() + horizontalScrollBar()->singleStep());
else horizontalScrollBar()->setValue(horizontalScrollBar()->value() - horizontalScrollBar()->singleStep());
}
}
void CustomTrackView::setOperation(OperationType op)
{
m_operationMode = op;
}
int CustomTrackView::getPreviousVideoTrack(int track)
{
track = m_document->tracksCount() - track - 1;
......@@ -501,7 +508,6 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
QGraphicsView::mouseMoveEvent(event);
return;
}
if (event->buttons() & Qt::MidButton) return;
if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SpacerTool && m_operationMode != ResizeStart && m_operationMode != ResizeEnd)) {
event->setAccepted(true);
......@@ -512,7 +518,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
if (event->buttons() != Qt::NoButton) {
bool move = (event->pos() - m_clickEvent).manhattanLength() >= QApplication::startDragDistance();
if (m_dragItem && move) m_clipDrag = true;
if (m_dragItem && move && m_operationMode != ZoomTimeline) m_clipDrag = true;
if (m_dragItem && m_tool == SelectTool) {
if (m_operationMode == MoveOperation && m_clipDrag) {
QGraphicsView::mouseMoveEvent(event);
......@@ -607,7 +613,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event)
return;
}
if (item && event->buttons() == Qt::NoButton) {
if (item && event->buttons() == Qt::NoButton && m_operationMode != ZoomTimeline) {
AbstractClipItem *clip = static_cast <AbstractClipItem*>(item);
if (m_tool == RazorTool) {
// razor tool over a clip, display current frame in monitor
......@@ -1002,7 +1008,7 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event)
}
QGraphicsView::mousePressEvent(event);
event->ignore();
return;
return;
}
if (m_tool == SpacerTool) {
......@@ -3664,15 +3670,14 @@ void CustomTrackView::completeSpaceOperation(int track, GenTime &timeOffset)
}
clearSelection();
m_operationMode = None;
m_operationMode = None;
return;
}
void CustomTrackView::mouseReleaseEvent(QMouseEvent * event)
{
if (m_moveOpMode == Seek) m_moveOpMode = None;
if (m_operationMode == ScrollTimeline) {
if (m_operationMode == ScrollTimeline || m_operationMode == ZoomTimeline) {
m_operationMode = None;
setDragMode(QGraphicsView::NoDrag);
QGraphicsView::mouseReleaseEvent(event);
......@@ -5805,8 +5810,10 @@ void CustomTrackView::setTool(ProjectTool tool)
void CustomTrackView::setScale(double scaleFactor, double verticalScale)
{
QMatrix newmatrix;
newmatrix = newmatrix.scale(scaleFactor, verticalScale);
m_scene->isZooming = true;
m_scene->setScale(scaleFactor, verticalScale);
removeTipAnimation();
bool adjust = false;
......@@ -5830,6 +5837,7 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale)
}
double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y();
centerOn(QPointF(cursorPos(), verticalPos));
m_scene->isZooming = false;
}
void CustomTrackView::slotRefreshGuides()
......
......@@ -220,6 +220,8 @@ public:
void createGroupForSelectedItems(QList<QGraphicsItem *> &selection);
void selectItemsRightOfFrame(int frame);
void resetSelectionGroup(bool selectItems = true);
/** @brief We are performing a timeline operation. */
void setOperation(OperationType op);
public slots:
/** @brief Send seek request to MLT. */
......
......@@ -37,7 +37,7 @@ Transition::Transition(const ItemInfo &info, int transitiontrack, double fps, co
m_automaticTransition(automaticTransition),
m_transitionTrack(transitiontrack)
{
setZValue(3);
setZValue(4);
m_info.cropDuration = info.endPos - info.startPos;
setPos(info.startPos.frames(fps), (int)(info.track * KdenliveSettings::trackheight() + itemOffset() + 1));
......@@ -204,11 +204,20 @@ int Transition::type() const
QVariant Transition::itemChange(GraphicsItemChange change, const QVariant &value)
{
if (change == QGraphicsItem::ItemSelectedChange) {
if (value.toBool()) setZValue(10);
else setZValue(3);
if (value.toBool()) setZValue(5);
else setZValue(4);
}
if (change == ItemPositionChange && scene()) {
CustomTrackScene *scene = NULL;
if (change == ItemPositionChange) {
scene = projectScene();
}
if (scene) {
// calculate new position.
if (scene->isZooming) {
// For some reason, mouse wheel on selected itm sometimes triggered
// a position change event corrupting timeline, so discard it
return pos();
}
QPointF newPos = value.toPointF();
int xpos = projectScene()->getSnapPointForPos((int) newPos.x(), KdenliveSettings::snaptopoints());
xpos = qMax(xpos, 0);
......@@ -228,7 +237,7 @@ QVariant Transition::itemChange(GraphicsItemChange change, const QVariant &value
QList<QGraphicsItem*> items;
// TODO: manage transitions in OVERWRITE MODE
//if (projectScene()->editMode() == NORMALEDIT)
items = scene()->items(sceneShape, Qt::IntersectsItemShape);
items = scene->items(sceneShape, Qt::IntersectsItemShape);
items.removeAll(this);
bool forwardMove = newPos.x() > pos().x();
......@@ -256,7 +265,7 @@ QVariant Transition::itemChange(GraphicsItemChange change, const QVariant &value
sceneShape.translate(QPointF(offset, 0));
newPos.setX(newPos.x() + offset);
}
QList<QGraphicsItem*> subitems = scene()->items(sceneShape, Qt::IntersectsItemShape);
QList<QGraphicsItem*> subitems = scene->items(sceneShape, Qt::IntersectsItemShape);
subitems.removeAll(this);
for (int j = 0; j < subitems.count(); ++j) {
if (!subitems.at(j)->isEnabled()) continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment