base pointer movement in timeline

This commit is contained in:
itsmattkc
2019-08-21 15:10:55 +10:00
parent 78d96ecd28
commit f03cc8fe07
14 changed files with 166 additions and 62 deletions
@@ -18,5 +18,6 @@ set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelineview/tool/import.cpp
widget/timelineview/tool/pointer.cpp
widget/timelineview/tool/tool.cpp
PARENT_SCOPE
)
+13 -10
View File
@@ -51,7 +51,8 @@ void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
drag_start_ = GetScenePos(event->pos());
// Set ghosts to start where the cursor entered
rational ghost_start = parent()->SceneToTime(drag_start_.x());
// FIXME: 100 = magic number so that imported clips are not right on the cursor when dragged in
rational ghost_start = parent()->SceneToTime(drag_start_.x() - 100);
while (!stream.atEnd()) {
stream >> r >> item_ptr;
@@ -92,22 +93,24 @@ void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
void TimelineView::ImportTool::DragMove(QDragMoveEvent *event)
{
if (parent()->HasGhosts()) {
QPointF pos = GetScenePos(event->pos());
QPointF movement = pos - drag_start_;
rational time_movement = parent()->SceneToTime(movement.x());
int ghost_track = parent()->SceneToTrack(pos.y());
int ghost_y = parent()->GetTrackY(ghost_track);
int ghost_height = parent()->GetTrackHeight(ghost_track);
time_movement = ValidateMovement(time_movement, parent()->ghost_items_);
// Move ghosts to the mouse cursor
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
QPointF pos = GetScenePos(event->pos());
QPointF movement = pos - drag_start_;
rational time_movement = parent()->SceneToTime(movement.x());
ghost->SetInAdjustment(time_movement);
ghost->SetOutAdjustment(time_movement);
int ghost_track = parent()->SceneToTrack(pos.y());
ghost->SetTrack(ghost_track);
int ghost_y = parent()->GetTrackY(ghost_track);
int ghost_height = parent()->GetTrackHeight(ghost_track);
ghost->SetY(ghost_y);
ghost->SetHeight(ghost_height);
}
+20 -9
View File
@@ -20,6 +20,8 @@
#include "widget/timelineview/timelineview.h"
#include "node/block/gap/gap.h"
TimelineView::PointerTool::PointerTool(TimelineView *parent) :
Tool(parent)
{
@@ -71,6 +73,9 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
ghost->SetScale(parent()->scale_);
ghost->SetData(Node::PtrToValue(clip));
// FIXME: Very bad. Change immediately.
ghost->SetTrack(parent()->SceneToTrack(drag_start_.y()));
ghost->setPos(clip_item->pos());
parent()->ghost_items_.append(ghost);
@@ -89,12 +94,7 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
rational time_movement = parent()->SceneToTime(movement.x());
// Validate movement
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
rational validator = ghost->In() + time_movement;
if (validator < 0) {
time_movement = rational(0) - ghost->In();
}
}
time_movement = ValidateMovement(time_movement, parent()->ghost_items_);
// Perform movement
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
@@ -110,13 +110,24 @@ void TimelineView::PointerTool::MouseRelease(QMouseEvent *event)
parent()->QGraphicsView::mouseReleaseEvent(event);
/*
QObject block_memory_manager;
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
Block* b = Node::ValueToPtr<Block>(ghost->data());
emit parent()->RequestPlaceBlock(b, ghost->In());
// Replace old Block with a new Gap
GapBlock* gap = new GapBlock();
gap->setParent(&block_memory_manager);
gap->set_length(b->length());
emit parent()->RequestReplaceBlock(b, gap, ghost->Track());
}
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
Block* b = Node::ValueToPtr<Block>(ghost->data());
emit parent()->RequestPlaceBlock(b, ghost->GetAdjustedIn(), ghost->Track());
}
*/
parent()->ClearGhosts();
+70
View File
@@ -0,0 +1,70 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2019 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "widget/timelineview/timelineview.h"
TimelineView::Tool::Tool(TimelineView *parent) :
dragging_(false),
parent_(parent)
{
}
TimelineView::Tool::~Tool(){}
void TimelineView::Tool::MousePress(QMouseEvent *){}
void TimelineView::Tool::MouseMove(QMouseEvent *){}
void TimelineView::Tool::MouseRelease(QMouseEvent *){}
void TimelineView::Tool::DragEnter(QDragEnterEvent *){}
void TimelineView::Tool::DragMove(QDragMoveEvent *){}
void TimelineView::Tool::DragLeave(QDragLeaveEvent *){}
void TimelineView::Tool::DragDrop(QDropEvent *){}
TimelineView *TimelineView::Tool::parent()
{
return parent_;
}
QPointF TimelineView::Tool::GetScenePos(const QPoint &screen_pos)
{
return parent()->mapToScene(screen_pos);
}
QGraphicsItem *TimelineView::Tool::GetItemAtScenePos(const QPointF &scene_pos)
{
return parent()->scene_.itemAt(scene_pos, parent()->transform());
}
rational TimelineView::Tool::ValidateMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
{
foreach (TimelineViewGhostItem* ghost, ghosts) {
rational validator = ghost->In() + movement;
if (validator < 0) {
movement = rational(0) - ghost->In();
}
}
return movement;
}