reimplemented pointer default functionality
This commit is contained in:
@@ -14,9 +14,14 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
add_subdirectory(tool)
|
||||
add_subdirectory(undo)
|
||||
add_subdirectory(view)
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelinewidget/timelinescaledobject.h
|
||||
widget/timelinewidget/timelinescaledobject.cpp
|
||||
widget/timelinewidget/timelinewidget.h
|
||||
widget/timelinewidget/timelinewidget.cpp
|
||||
PARENT_SCOPE
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "timelinescaledobject.h"
|
||||
|
||||
TimelineScaledObject::TimelineScaledObject() :
|
||||
scale_(1.0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const rational &TimelineScaledObject::timebase()
|
||||
{
|
||||
return timebase_;
|
||||
}
|
||||
|
||||
const double &TimelineScaledObject::timebase_dbl()
|
||||
{
|
||||
return timebase_dbl_;
|
||||
}
|
||||
|
||||
double TimelineScaledObject::TimeToScene(const rational &time)
|
||||
{
|
||||
return time.toDouble() * scale_;
|
||||
}
|
||||
|
||||
rational TimelineScaledObject::SceneToTime(const double &x)
|
||||
{
|
||||
// Adjust screen point by scale and timebase
|
||||
qint64 scaled_x_mvmt = qRound64(x / scale_ / timebase_dbl_);
|
||||
|
||||
// Return a time in the timebase
|
||||
return rational(scaled_x_mvmt * timebase_.numerator(), timebase_.denominator());
|
||||
}
|
||||
|
||||
void TimelineScaledObject::SetTimebaseInternal(const rational &timebase)
|
||||
{
|
||||
timebase_ = timebase;
|
||||
timebase_dbl_ = timebase_.toDouble();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef TIMELINESCALEDOBJECT_H
|
||||
#define TIMELINESCALEDOBJECT_H
|
||||
|
||||
#include "common/rational.h"
|
||||
|
||||
class TimelineScaledObject
|
||||
{
|
||||
public:
|
||||
TimelineScaledObject();
|
||||
|
||||
const rational& timebase();
|
||||
const double& timebase_dbl();
|
||||
|
||||
protected:
|
||||
double TimeToScene(const rational& time);
|
||||
rational SceneToTime(const double &x);
|
||||
|
||||
void SetTimebaseInternal(const rational& timebase);
|
||||
|
||||
double scale_;
|
||||
|
||||
private:
|
||||
|
||||
rational timebase_;
|
||||
|
||||
double timebase_dbl_;
|
||||
};
|
||||
|
||||
#endif // TIMELINESCALEDOBJECT_H
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
rubberband_(QRubberBand::Rectangle, this),
|
||||
timeline_node_(nullptr),
|
||||
playhead_(0)
|
||||
{
|
||||
@@ -584,3 +585,52 @@ void TimelineWidget::AddGhost(TimelineViewGhostItem *ghost)
|
||||
ghost_items_.append(ghost);
|
||||
views_.at(ghost->Track().type())->scene()->addItem(ghost);
|
||||
}
|
||||
|
||||
void TimelineWidget::StartRubberBandSelect(bool clear_current_selection)
|
||||
{
|
||||
rubberband_origin_ = QCursor::pos();
|
||||
rubberband_.show();
|
||||
|
||||
if (!clear_current_selection) {
|
||||
foreach (TimelineView* view, views_) {
|
||||
rubberband_already_selected_.append(view->scene()->selectedItems());
|
||||
}
|
||||
}
|
||||
|
||||
MoveRubberBandSelect();
|
||||
}
|
||||
|
||||
void TimelineWidget::MoveRubberBandSelect()
|
||||
{
|
||||
QPoint rubberband_now = QCursor::pos();
|
||||
|
||||
rubberband_.setGeometry(QRect(mapFromGlobal(rubberband_origin_), mapFromGlobal(rubberband_now)).normalized());
|
||||
|
||||
foreach (TimelineView* view, views_) {
|
||||
view->DeselectAll();
|
||||
|
||||
// Map global mouse coordinates to viewport
|
||||
|
||||
QRect mapped_rect(view->viewport()->mapFromGlobal(rubberband_origin_),
|
||||
view->viewport()->mapFromGlobal(rubberband_now));
|
||||
|
||||
// Normalize and get items in rect
|
||||
QList<QGraphicsItem*> rubberband_items = view->items(mapped_rect.normalized());
|
||||
|
||||
// Select them all
|
||||
foreach (QGraphicsItem* item, rubberband_items) {
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (QGraphicsItem* item, rubberband_already_selected_) {
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::EndRubberBandSelect()
|
||||
{
|
||||
MoveRubberBandSelect();
|
||||
rubberband_.hide();
|
||||
rubberband_already_selected_.clear();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
#define TIMELINEWIDGET_H
|
||||
|
||||
#include <QScrollBar>
|
||||
#include <QRubberBand>
|
||||
#include <QWidget>
|
||||
|
||||
#include "widget/timelineview/timelinescaledobject.h"
|
||||
#include "widget/timelineview/timelineview.h"
|
||||
#include "widget/timelinewidget/timelinescaledobject.h"
|
||||
#include "widget/timelinewidget/view/timelineview.h"
|
||||
#include "widget/timeruler/timeruler.h"
|
||||
|
||||
/**
|
||||
@@ -81,13 +82,9 @@ private:
|
||||
|
||||
const QGraphicsView::DragMode& drag_mode();
|
||||
|
||||
bool enable_default_behavior();
|
||||
|
||||
protected:
|
||||
void set_drag_mode(const QGraphicsView::DragMode& mode);
|
||||
|
||||
void set_enable_default_behavior(bool enable);
|
||||
|
||||
/**
|
||||
* @brief Retrieve the QGraphicsItem at a particular scene position
|
||||
*
|
||||
@@ -133,8 +130,6 @@ private:
|
||||
|
||||
QGraphicsView::DragMode drag_mode_;
|
||||
|
||||
bool enable_default_behavior_;
|
||||
|
||||
};
|
||||
|
||||
class PointerTool : public Tool
|
||||
@@ -190,6 +185,7 @@ private:
|
||||
bool movement_allowed_;
|
||||
bool trimming_allowed_;
|
||||
bool track_movement_allowed_;
|
||||
bool rubberband_selecting_;
|
||||
};
|
||||
|
||||
class ImportTool : public Tool
|
||||
@@ -288,6 +284,13 @@ private:
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event);
|
||||
};
|
||||
|
||||
void StartRubberBandSelect(bool clear_current_selection);
|
||||
void MoveRubberBandSelect();
|
||||
void EndRubberBandSelect();
|
||||
QRubberBand rubberband_;
|
||||
QPoint rubberband_origin_;
|
||||
QList<QGraphicsItem*> rubberband_already_selected_;
|
||||
|
||||
Tool* GetActiveTool();
|
||||
|
||||
QVector< std::shared_ptr<Tool> > tools_;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# 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/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelinewidget/tool/hand.cpp
|
||||
widget/timelinewidget/tool/import.cpp
|
||||
widget/timelinewidget/tool/pointer.cpp
|
||||
widget/timelinewidget/tool/razor.cpp
|
||||
widget/timelinewidget/tool/ripple.cpp
|
||||
widget/timelinewidget/tool/rolling.cpp
|
||||
widget/timelinewidget/tool/slide.cpp
|
||||
widget/timelinewidget/tool/slip.cpp
|
||||
widget/timelinewidget/tool/tool.cpp
|
||||
widget/timelinewidget/tool/zoom.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,29 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
TimelineWidget::HandTool::HandTool(TimelineWidget* parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
set_drag_mode(QGraphicsView::ScrollHandDrag);
|
||||
}
|
||||
@@ -0,0 +1,256 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "config/config.h"
|
||||
#include "common/qtversionabstraction.h"
|
||||
#include "core.h"
|
||||
#include "node/distort/transform/transform.h"
|
||||
#include "node/color/opacity/opacity.h"
|
||||
#include "node/input/media/media.h"
|
||||
|
||||
TrackType TrackTypeFromStreamType(Stream::Type stream_type)
|
||||
{
|
||||
switch (stream_type) {
|
||||
case Stream::kVideo:
|
||||
case Stream::kImage:
|
||||
return kTrackTypeVideo;
|
||||
case Stream::kAudio:
|
||||
return kTrackTypeAudio;
|
||||
case Stream::kSubtitle:
|
||||
return kTrackTypeSubtitle;
|
||||
case Stream::kUnknown:
|
||||
case Stream::kData:
|
||||
case Stream::kAttachment:
|
||||
break;
|
||||
}
|
||||
|
||||
return kTrackTypeNone;
|
||||
}
|
||||
|
||||
TimelineWidget::ImportTool::ImportTool(TimelineWidget *parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
// Calculate width used for importing to give ghosts a slight lead-in so the ghosts aren't right on the cursor
|
||||
QFontMetrics fm = parent->fontMetrics();
|
||||
import_pre_buffer_ = QFontMetricsWidth(&fm, "HHHHHHHH");
|
||||
}
|
||||
|
||||
void TimelineWidget::ImportTool::DragEnter(TimelineViewMouseEvent *event)
|
||||
{
|
||||
QStringList mime_formats = event->GetMimeData()->formats();
|
||||
|
||||
// Listen for MIME data from a ProjectViewModel
|
||||
if (mime_formats.contains("application/x-oliveprojectitemdata")) {
|
||||
// FIXME: Implement audio insertion
|
||||
|
||||
// Data is drag/drop data from a ProjectViewModel
|
||||
QByteArray model_data = event->GetMimeData()->data("application/x-oliveprojectitemdata");
|
||||
|
||||
// Use QDataStream to deserialize the data
|
||||
QDataStream stream(&model_data, QIODevice::ReadOnly);
|
||||
|
||||
// Variables to deserialize into
|
||||
quintptr item_ptr;
|
||||
int r;
|
||||
|
||||
// Set drag start position
|
||||
drag_start_ = event->GetCoordinates();
|
||||
|
||||
// Set ghosts to start where the cursor entered
|
||||
|
||||
rational ghost_start = drag_start_.GetFrame() - parent()->SceneToTime(import_pre_buffer_);
|
||||
|
||||
snap_points_.clear();
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
stream >> r >> item_ptr;
|
||||
|
||||
// Get Item object
|
||||
Item* item = reinterpret_cast<Item*>(item_ptr);
|
||||
|
||||
// Check if Item is Footage
|
||||
if (item->type() == Item::kFootage) {
|
||||
// If the Item is Footage, we can create a Ghost from it
|
||||
Footage* footage = static_cast<Footage*>(item);
|
||||
|
||||
// Each stream is offset by one track per track "type", we keep track of them in this vector
|
||||
QVector<int> track_offsets(kTrackTypeCount);
|
||||
track_offsets.fill(drag_start_.GetTrack().index());
|
||||
|
||||
rational footage_duration;
|
||||
|
||||
// Loop through all streams in footage
|
||||
foreach (StreamPtr stream, footage->streams()) {
|
||||
TrackType track_type = TrackTypeFromStreamType(stream->type());
|
||||
|
||||
// Check if this stream has a compatible TrackList
|
||||
if (track_type == kTrackTypeNone) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
if (stream->type() == Stream::kImage) {
|
||||
// Stream is essentially length-less - use config's default image length
|
||||
footage_duration = Config::Current()["DefaultStillLength"].value<rational>();
|
||||
} else {
|
||||
// Use duration from file
|
||||
footage_duration = rational(stream->timebase().numerator() * stream->duration(),
|
||||
stream->timebase().denominator());
|
||||
}
|
||||
|
||||
ghost->SetIn(ghost_start);
|
||||
ghost->SetOut(ghost_start + footage_duration);
|
||||
ghost->SetTrack(TrackReference(track_type, track_offsets.at(track_type)));
|
||||
|
||||
// Increment track count for this track type
|
||||
track_offsets[track_type]++;
|
||||
|
||||
snap_points_.append(ghost->In());
|
||||
snap_points_.append(ghost->Out());
|
||||
|
||||
ghost->setData(TimelineViewGhostItem::kAttachedFootage, QVariant::fromValue(stream));
|
||||
ghost->SetMode(olive::timeline::kMove);
|
||||
|
||||
parent()->AddGhost(ghost);
|
||||
}
|
||||
|
||||
// Stack each ghost one after the other
|
||||
ghost_start += footage_duration;
|
||||
}
|
||||
}
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
// FIXME: Implement dropping from file
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
rational time_movement = event->GetCoordinates().GetFrame() - drag_start_.GetFrame();
|
||||
int track_movement = event->GetCoordinates().GetTrack().index() - drag_start_.GetTrack().index();
|
||||
|
||||
// If snapping is enabled, check for snap points
|
||||
if (olive::core.snapping()) {
|
||||
SnapPoint(snap_points_, &time_movement);
|
||||
}
|
||||
|
||||
time_movement = ValidateFrameMovement(time_movement, parent()->ghost_items_);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
rational earliest_ghost = RATIONAL_MAX;
|
||||
|
||||
// Move ghosts to the mouse cursor
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
ghost->SetInAdjustment(time_movement);
|
||||
ghost->SetOutAdjustment(time_movement);
|
||||
ghost->SetTrackAdjustment(track_movement);
|
||||
|
||||
TrackReference adjusted_track = ghost->GetAdjustedTrack();
|
||||
ghost->SetYCoords(parent()->GetTrackY(adjusted_track), parent()->GetTrackHeight(adjusted_track));
|
||||
|
||||
earliest_ghost = qMin(earliest_ghost, ghost->GetAdjustedIn());
|
||||
}
|
||||
|
||||
// Generate tooltip (showing earliest in point of imported clip)
|
||||
int64_t earliest_timestamp = olive::time_to_timestamp(earliest_ghost, parent()->timebase());
|
||||
QString tooltip_text = olive::timestamp_to_timecode(earliest_timestamp,
|
||||
parent()->timebase(),
|
||||
olive::CurrentTimecodeDisplay());
|
||||
QToolTip::showText(QCursor::pos(),
|
||||
tooltip_text,
|
||||
parent());
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::ImportTool::DragLeave(QDragLeaveEvent* event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
parent()->ClearGhosts();
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
// We use QObject as the parent for the nodes we create. If there is no TimelineOutput node, this object going out
|
||||
// of scope will delete the nodes. If there is, they'll become parents of the NodeGraph instead
|
||||
QObject node_memory_manager;
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
ClipBlock* clip = new ClipBlock();
|
||||
MediaInput* media = new MediaInput();
|
||||
TransformDistort* transform = new TransformDistort();
|
||||
OpacityNode* opacity = new OpacityNode();
|
||||
|
||||
// Set parents to node_memory_manager in case no TimelineOutput receives this signal
|
||||
clip->setParent(&node_memory_manager);
|
||||
media->setParent(&node_memory_manager);
|
||||
transform->setParent(&node_memory_manager);
|
||||
opacity->setParent(&node_memory_manager);
|
||||
|
||||
clip->set_length(ghost->Length());
|
||||
StreamPtr footage_stream = ghost->data(TimelineViewGhostItem::kAttachedFootage).value<StreamPtr>();
|
||||
media->SetFootage(footage_stream);
|
||||
clip->set_block_name(footage_stream->footage()->name());
|
||||
|
||||
NodeParam::ConnectEdge(opacity->texture_output(), clip->texture_input());
|
||||
NodeParam::ConnectEdge(media->texture_output(), opacity->texture_input());
|
||||
NodeParam::ConnectEdge(transform->matrix_output(), media->matrix_input());
|
||||
|
||||
|
||||
if (event->GetModifiers() & Qt::ControlModifier) {
|
||||
//emit parent()->RequestInsertBlockAtTime(clip, ghost->GetAdjustedIn());
|
||||
} else {
|
||||
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(ghost->Track().type()),
|
||||
ghost->Track().index(),
|
||||
clip,
|
||||
ghost->GetAdjustedIn(),
|
||||
command);
|
||||
}
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
|
||||
parent()->ClearGhosts();
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,518 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QToolTip>
|
||||
|
||||
#include "common/clamp.h"
|
||||
#include "common/flipmodifiers.h"
|
||||
#include "common/range.h"
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "config/config.h"
|
||||
#include "core.h"
|
||||
#include "node/block/gap/gap.h"
|
||||
|
||||
TimelineWidget::PointerTool::PointerTool(TimelineWidget *parent) :
|
||||
Tool(parent),
|
||||
movement_allowed_(true),
|
||||
trimming_allowed_(true),
|
||||
track_movement_allowed_(true),
|
||||
rubberband_selecting_(false)
|
||||
{
|
||||
set_drag_mode(QGraphicsView::RubberBandDrag);
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::MousePress(TimelineViewMouseEvent *event)
|
||||
{
|
||||
// Main selection code
|
||||
|
||||
TimelineViewBlockItem* item = GetItemAtScenePos(event->GetCoordinates());
|
||||
|
||||
bool selectable_item = (item != nullptr && item->flags() & QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
// If this item is already selected
|
||||
if (selectable_item
|
||||
&& item->isSelected()) {
|
||||
|
||||
// If shift is held, deselect it
|
||||
if (event->GetModifiers() & Qt::ShiftModifier) {
|
||||
item->setSelected(false);
|
||||
}
|
||||
|
||||
// Otherwise do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
// If not holding shift, deselect all clips
|
||||
if (!(event->GetModifiers() & Qt::ShiftModifier)) {
|
||||
parent()->DeselectAll();
|
||||
}
|
||||
|
||||
if (selectable_item) {
|
||||
// Select this item
|
||||
item->setSelected(true);
|
||||
} else {
|
||||
// Start rubberband drag
|
||||
parent()->StartRubberBandSelect(!(event->GetModifiers() & Qt::ShiftModifier));
|
||||
|
||||
rubberband_selecting_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (rubberband_selecting_) {
|
||||
|
||||
// Process rubberband select
|
||||
parent()->MoveRubberBandSelect();
|
||||
|
||||
} else if (!dragging_) {
|
||||
// Now that the cursor has moved, we will assume the intention is to drag
|
||||
|
||||
// If we haven't started dragging yet, we'll initiate a drag here
|
||||
InitiateDrag(event->GetCoordinates());
|
||||
|
||||
// Set dragging to true here so no matter what, the drag isn't re-initiated until it's completed
|
||||
dragging_ = true;
|
||||
|
||||
} else if (!parent()->ghost_items_.isEmpty()) {
|
||||
|
||||
// We're already dragging AND we have ghosts to work with
|
||||
ProcessDrag(event->GetCoordinates());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (rubberband_selecting_) {
|
||||
parent()->EndRubberBandSelect();
|
||||
|
||||
rubberband_selecting_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!parent()->ghost_items_.isEmpty()) {
|
||||
MouseReleaseInternal(event);
|
||||
}
|
||||
|
||||
if (dragging_) {
|
||||
parent()->ClearGhosts();
|
||||
snap_points_.clear();
|
||||
}
|
||||
|
||||
dragging_ = false;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::SetMovementAllowed(bool allowed)
|
||||
{
|
||||
movement_allowed_ = allowed;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::SetTrackMovementAllowed(bool allowed)
|
||||
{
|
||||
track_movement_allowed_ = allowed;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::SetTrimmingAllowed(bool allowed)
|
||||
{
|
||||
trimming_allowed_ = allowed;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
// We create a QObject on the stack so that when we allocate objects on the heap, they aren't parent-less and will
|
||||
// get cleaned up if they aren't re-parented by the attached NodeGraph
|
||||
QObject block_memory_manager;
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Since all the ghosts will be leaving their old position in some way, we replace all of them with gaps here so the
|
||||
// entire timeline isn't disrupted in the process
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Replace old Block with a new Gap
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->setParent(&block_memory_manager);
|
||||
gap->set_length(b->length());
|
||||
|
||||
new TrackReplaceBlockCommand(parent()->GetTrackFromReference(ghost->Track()),
|
||||
b,
|
||||
gap,
|
||||
command);
|
||||
}
|
||||
|
||||
// Now we place the clips back in the timeline where the user moved them. It's legal for them to overwrite parts or
|
||||
// all of the gaps we inserted earlier
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Normal blocks work in conjunction with the gap made above
|
||||
if (ghost->mode() == olive::timeline::kTrimIn || ghost->mode() == olive::timeline::kTrimOut) {
|
||||
// If we were trimming, we'll need to change the length
|
||||
|
||||
// If we were trimming the in point, we'll need to adjust the media in too
|
||||
if (ghost->mode() == olive::timeline::kTrimIn) {
|
||||
new BlockResizeWithMediaInCommand(b, ghost->AdjustedLength(), command);
|
||||
} else {
|
||||
new BlockResizeCommand(b, ghost->AdjustedLength(), command);
|
||||
}
|
||||
}
|
||||
|
||||
const TrackReference& track_ref = ghost->GetAdjustedTrack();
|
||||
|
||||
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(track_ref.type()),
|
||||
track_ref.index(),
|
||||
b,
|
||||
ghost->GetAdjustedIn(),
|
||||
command);
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *>& ghosts)
|
||||
{
|
||||
// Default behavior is to validate all movement and trimming
|
||||
time_movement = ValidateFrameMovement(time_movement, ghosts);
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, true);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, true);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::InitiateDrag(const TimelineCoordinate &mouse_pos)
|
||||
{
|
||||
// Record where the drag started in timeline coordinates
|
||||
drag_start_ = mouse_pos;
|
||||
|
||||
// Get the item that was clicked
|
||||
TimelineViewBlockItem* clicked_item = GetItemAtScenePos(drag_start_);
|
||||
|
||||
// We only initiate a pointer drag if the user actually dragged an item, otherwise if they dragged on empty space
|
||||
// QGraphicsView default behavior would initiate a rubberband drag
|
||||
if (clicked_item != nullptr) {
|
||||
|
||||
// Clear snap points
|
||||
snap_points_.clear();
|
||||
|
||||
// Record where the drag started in timeline coordinates
|
||||
track_start_ = mouse_pos.GetTrack();
|
||||
|
||||
// Determine whether we're trimming or moving based on the position of the cursor
|
||||
olive::timeline::MovementMode trim_mode = olive::timeline::kNone;
|
||||
|
||||
// FIXME: Hardcoded number
|
||||
const int kTrimHandle = 20;
|
||||
|
||||
qreal mouse_x = parent()->TimeToScene(mouse_pos.GetFrame());
|
||||
|
||||
if (trimming_allowed_ && mouse_x < clicked_item->x() + kTrimHandle) {
|
||||
trim_mode = olive::timeline::kTrimIn;
|
||||
} else if (trimming_allowed_ && mouse_x > clicked_item->x() + clicked_item->rect().right() - kTrimHandle) {
|
||||
trim_mode = olive::timeline::kTrimOut;
|
||||
} else if (movement_allowed_) {
|
||||
// Some derived classes don't allow movement
|
||||
trim_mode = olive::timeline::kMove;
|
||||
}
|
||||
|
||||
// Gaps can't be moved, only trimmed
|
||||
if (clicked_item->block()->type() == Block::kGap && trim_mode == olive::timeline::kMove) {
|
||||
trim_mode = olive::timeline::kNone;
|
||||
}
|
||||
|
||||
// Make sure we can actually perform an action here
|
||||
if (trim_mode != olive::timeline::kNone) {
|
||||
InitiateGhosts(clicked_item, trim_mode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos)
|
||||
{
|
||||
// Determine track movement
|
||||
const TrackReference& cursor_track = mouse_pos.GetTrack();
|
||||
int track_movement = 0;
|
||||
|
||||
if (track_movement_allowed_) {
|
||||
track_movement = cursor_track.index() - track_start_.index();
|
||||
}
|
||||
|
||||
// Determine frame movement
|
||||
rational time_movement = mouse_pos.GetFrame() - drag_start_.GetFrame();
|
||||
|
||||
// Perform snapping if enabled (adjusts time_movement if it's close to any potential snap points)
|
||||
if (olive::core.snapping()) {
|
||||
SnapPoint(snap_points_, &time_movement);
|
||||
}
|
||||
|
||||
// Validate movement (enforce all ghosts moving in legal ways)
|
||||
time_movement = FrameValidateInternal(time_movement, parent()->ghost_items_);
|
||||
track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_);
|
||||
|
||||
// Perform movement
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
switch (ghost->mode()) {
|
||||
case olive::timeline::kNone:
|
||||
break;
|
||||
case olive::timeline::kTrimIn:
|
||||
ghost->SetInAdjustment(time_movement);
|
||||
break;
|
||||
case olive::timeline::kTrimOut:
|
||||
ghost->SetOutAdjustment(time_movement);
|
||||
break;
|
||||
case olive::timeline::kMove:
|
||||
{
|
||||
ghost->SetInAdjustment(time_movement);
|
||||
ghost->SetOutAdjustment(time_movement);
|
||||
|
||||
// Track movement is only legal for moving, not for trimming
|
||||
ghost->SetTrackAdjustment(track_movement);
|
||||
|
||||
const TrackReference& track = ghost->GetAdjustedTrack();
|
||||
ghost->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Show tooltip
|
||||
// Generate tooltip (showing earliest in point of imported clip)
|
||||
int64_t earliest_timestamp = olive::time_to_timestamp(time_movement, parent()->timebase());
|
||||
QString tooltip_text = olive::timestamp_to_timecode(earliest_timestamp,
|
||||
parent()->timebase(),
|
||||
olive::CurrentTimecodeDisplay(),
|
||||
true);
|
||||
QToolTip::showText(QCursor::pos(),
|
||||
tooltip_text,
|
||||
parent());
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_item,
|
||||
olive::timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
{
|
||||
// Convert selected items list to clips list
|
||||
QList<TimelineViewBlockItem*> clips = parent()->GetSelectedBlocks();
|
||||
|
||||
// If trimming multiple clips, we only trim the earliest in each track (trimming in) or the latest in each track
|
||||
// (trimming out). If the current clip is NOT one of these, we only trim it.
|
||||
bool multitrim_enabled = true;
|
||||
|
||||
// Determine if the clicked item is the earliest/latest in the track for in/out trimming respectively
|
||||
if (trim_mode == olive::timeline::kTrimIn
|
||||
|| trim_mode == olive::timeline::kTrimOut) {
|
||||
multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
}
|
||||
|
||||
// For each selected item, create a "ghost", a visual representation of the action before it gets performed
|
||||
foreach (TimelineViewBlockItem* clip_item, clips) {
|
||||
// Determine correct mode for ghost
|
||||
//
|
||||
// Movement is indiscriminate, all the ghosts can be set to do this, however trimming is limited to one block
|
||||
// PER TRACK
|
||||
|
||||
bool include_this_clip = true;
|
||||
|
||||
if (clip_item != clicked_item
|
||||
&& (trim_mode == olive::timeline::kTrimIn || trim_mode == olive::timeline::kTrimOut)) {
|
||||
include_this_clip = multitrim_enabled ? IsClipTrimmable(clip_item, clips, trim_mode) : false;
|
||||
}
|
||||
|
||||
if (include_this_clip) {
|
||||
Block* block = clip_item->block();
|
||||
olive::timeline::MovementMode block_mode = trim_mode;
|
||||
|
||||
if (block->type() == Block::kGap && !allow_gap_trimming) {
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
// Trim the previous clip's out point instead
|
||||
block = block->previous();
|
||||
} else {
|
||||
// Assume kTrimOut
|
||||
block = block->next();
|
||||
}
|
||||
block_mode = FlipTrimMode(trim_mode);
|
||||
}
|
||||
|
||||
if (block != nullptr) {
|
||||
AddGhostFromBlock(block, clip_item->Track(), block_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromBlock(Block* block, const TrackReference& track, olive::timeline::MovementMode mode)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = TimelineViewGhostItem::FromBlock(block,
|
||||
track,
|
||||
parent()->GetTrackY(track),
|
||||
parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const rational &in, const rational &out, const TrackReference& track, olive::timeline::MovementMode mode)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
ghost->SetIn(in);
|
||||
ghost->SetOut(out);
|
||||
ghost->SetTrack(track);
|
||||
ghost->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
|
||||
|
||||
AddGhostInternal(ghost, mode);
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, olive::timeline::MovementMode mode)
|
||||
{
|
||||
ghost->SetMode(mode);
|
||||
|
||||
// Prepare snap points (optimizes snapping for later)
|
||||
switch (mode) {
|
||||
case olive::timeline::kMove:
|
||||
snap_points_.append(ghost->In());
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
case olive::timeline::kTrimIn:
|
||||
snap_points_.append(ghost->In());
|
||||
break;
|
||||
case olive::timeline::kTrimOut:
|
||||
snap_points_.append(ghost->Out());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
parent()->AddGhost(ghost);
|
||||
}
|
||||
|
||||
bool TimelineWidget::PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip,
|
||||
const QList<TimelineViewBlockItem*>& items,
|
||||
const olive::timeline::MovementMode& mode)
|
||||
{
|
||||
foreach (TimelineViewBlockItem* compare, items) {
|
||||
if (clip->Track() == compare->Track()
|
||||
&& clip != compare
|
||||
&& ((compare->block()->in() < clip->block()->in() && mode == olive::timeline::kTrimIn)
|
||||
|| (compare->block()->out() > clip->block()->out() && mode == olive::timeline::kTrimOut))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimIn) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Determine the earliest in point this block could have
|
||||
rational earliest_in = qMax(rational(0), block->in() - block->media_in());
|
||||
|
||||
if (prevent_overwriting) {
|
||||
// Look for a Block in the way
|
||||
Block* prev = block->previous();
|
||||
while (prev != nullptr) {
|
||||
if (prev->type() == Block::kClip) {
|
||||
earliest_in = qMax(earliest_in, prev->out());
|
||||
break;
|
||||
}
|
||||
prev = prev->previous();
|
||||
}
|
||||
}
|
||||
|
||||
// Determine the latest point this block could have
|
||||
rational latest_in = ghost->Out();
|
||||
|
||||
if (!ghost->CanHaveZeroLength()) {
|
||||
latest_in -= parent()->timebase();
|
||||
}
|
||||
|
||||
// Clamp adjusted value between the earliest and latest values
|
||||
rational adjusted = ghost->In() + movement;
|
||||
rational clamped = clamp(adjusted, earliest_in, latest_in);
|
||||
|
||||
if (clamped != adjusted) {
|
||||
movement = clamped - ghost->In();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement,
|
||||
const QVector<TimelineViewGhostItem *> ghosts,
|
||||
bool prevent_overwriting)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kTrimOut) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Block* block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Determine earliest and latest out points
|
||||
rational earliest_out = ghost->In();
|
||||
|
||||
if (!ghost->CanHaveZeroLength()) {
|
||||
earliest_out += parent()->timebase();
|
||||
}
|
||||
|
||||
rational latest_out = RATIONAL_MAX;
|
||||
|
||||
if (prevent_overwriting) {
|
||||
// Determine if there's a block in the way
|
||||
Block* next = block->next();
|
||||
while (next != nullptr && next->type() != Block::kEnd) {
|
||||
if (next->type() == Block::kClip) {
|
||||
latest_out = qMin(latest_out, next->in());
|
||||
break;
|
||||
}
|
||||
next = next->next();
|
||||
}
|
||||
}
|
||||
|
||||
// Clamp adjusted value between the earliest and latest values
|
||||
rational adjusted = ghost->Out() + movement;
|
||||
rational clamped = clamp(adjusted, earliest_out, latest_out);
|
||||
|
||||
if (clamped != adjusted) {
|
||||
movement = clamped - ghost->Out();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
TimelineWidget::RazorTool::RazorTool(TimelineWidget* parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineWidget::RazorTool::MousePress(TimelineViewMouseEvent *event)
|
||||
{
|
||||
split_tracks_.clear();
|
||||
|
||||
MouseMove(event);
|
||||
}
|
||||
|
||||
void TimelineWidget::RazorTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (!dragging_) {
|
||||
drag_start_ = event->GetCoordinates();
|
||||
dragging_ = true;
|
||||
}
|
||||
|
||||
// Split at the current cursor track
|
||||
TrackReference split_track = event->GetCoordinates().GetTrack();
|
||||
|
||||
if (!split_tracks_.contains(split_track)) {
|
||||
split_tracks_.append(split_track);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::RazorTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
// Always split at the same time
|
||||
rational split_time = drag_start_.GetFrame();
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
foreach (const TrackReference& track, split_tracks_) {
|
||||
new TrackSplitAtTimeCommand(parent()->GetTrackFromReference(track), split_time, command);
|
||||
}
|
||||
|
||||
split_tracks_.clear();
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
|
||||
dragging_ = false;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include "node/block/gap/gap.h"
|
||||
|
||||
TimelineWidget::RippleTool::RippleTool(TimelineWidget* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetMovementAllowed(false);
|
||||
}
|
||||
|
||||
void TimelineWidget::RippleTool::MouseReleaseInternal(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
// For ripple operations, all ghosts will be moving the same way
|
||||
olive::timeline::MovementMode movement_mode = parent()->ghost_items_.first()->mode();
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (b == nullptr) {
|
||||
// This is a gap we are creating
|
||||
|
||||
// Make sure there's actually a gap being created
|
||||
if (ghost->AdjustedLength() > 0) {
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(ghost->AdjustedLength());
|
||||
|
||||
Block* block_to_append_gap_to = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kReferenceBlock));
|
||||
|
||||
new TrackInsertBlockBetweenBlocksCommand(parent()->GetTrackFromReference(ghost->Track()),
|
||||
gap,
|
||||
block_to_append_gap_to,
|
||||
block_to_append_gap_to->next());
|
||||
}
|
||||
} else {
|
||||
// This was a Block that already existed
|
||||
if (ghost->AdjustedLength() > 0) {
|
||||
if (movement_mode == olive::timeline::kTrimIn) {
|
||||
// We'll need to shift the media in point too
|
||||
new BlockResizeWithMediaInCommand(b, ghost->AdjustedLength(), command);
|
||||
} else {
|
||||
new BlockResizeCommand(b, ghost->AdjustedLength(), command);
|
||||
}
|
||||
} else {
|
||||
// Assumed the Block was a Gap and it was reduced to zero length, remove it here
|
||||
new TrackRippleRemoveBlockCommand(parent()->GetTrackFromReference(ghost->Track()), b, command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
rational TimelineWidget::RippleTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *> &ghosts)
|
||||
{
|
||||
// Only validate trimming, and we don't care about "overwriting" since the ripple tool is nondestructive
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, false);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, false);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
|
||||
void TimelineWidget::RippleTool::InitiateGhosts(TimelineViewBlockItem *clicked_item,
|
||||
olive::timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
{
|
||||
Q_UNUSED(allow_gap_trimming)
|
||||
|
||||
PointerTool::InitiateGhosts(clicked_item, trim_mode, true);
|
||||
|
||||
if (parent()->ghost_items_.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the earliest ripple
|
||||
rational earliest_ripple = RATIONAL_MAX;
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
rational ghost_ripple_point;
|
||||
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
ghost_ripple_point = ghost->In();
|
||||
} else {
|
||||
ghost_ripple_point = ghost->Out();
|
||||
}
|
||||
|
||||
earliest_ripple = qMin(earliest_ripple, ghost_ripple_point);
|
||||
}
|
||||
|
||||
// For each track that does NOT have a ghost, we need to make one for Gaps
|
||||
foreach (TrackOutput* track, parent()->timeline_node_->Tracks()) {
|
||||
// Determine if we've already created a ghost on this track
|
||||
bool ghost_on_this_track_exists = false;
|
||||
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (parent()->GetTrackFromReference(ghost->Track()) == track) {
|
||||
ghost_on_this_track_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no ghost on this track, create one
|
||||
if (!ghost_on_this_track_exists) {
|
||||
// Find the block that starts just before the ripple point, and ends either on or just after it
|
||||
Block* block_before_ripple = track->NearestBlockBefore(earliest_ripple);
|
||||
|
||||
// If block is null, there will be no blocks after to ripple
|
||||
if (block_before_ripple != nullptr
|
||||
&& block_before_ripple->type() != Block::kEnd
|
||||
&& block_before_ripple->next()->type() != Block::kEnd) {
|
||||
TimelineViewGhostItem* ghost;
|
||||
|
||||
TrackReference track_ref(track->track_type(), track->Index());
|
||||
|
||||
if (block_before_ripple->type() == Block::kGap) {
|
||||
// If this Block is already a Gap, ghost it now
|
||||
ghost = AddGhostFromBlock(block_before_ripple, track_ref, trim_mode);
|
||||
} else {
|
||||
// If there's no gap here, we'll need to create one
|
||||
ghost = AddGhostFromNull(block_before_ripple->out(), block_before_ripple->out(), track_ref, trim_mode);
|
||||
ghost->setData(TimelineViewGhostItem::kReferenceBlock, Node::PtrToValue(block_before_ripple));
|
||||
}
|
||||
|
||||
ghost->SetInvisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include "node/block/gap/gap.h"
|
||||
|
||||
TimelineWidget::RollingTool::RollingTool(TimelineWidget* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetMovementAllowed(false);
|
||||
}
|
||||
|
||||
void TimelineWidget::RollingTool::MouseReleaseInternal(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == olive::timeline::kTrimIn) {
|
||||
if (b->previous() == nullptr) {
|
||||
// We'll need to insert a gap here, so we'll do a Place command instead
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(ghost->Length());
|
||||
|
||||
new TrackReplaceBlockCommand(parent()->GetTrackFromReference(ghost->Track()), b, gap, command);
|
||||
}
|
||||
|
||||
new BlockResizeWithMediaInCommand(b, ghost->AdjustedLength(), command);
|
||||
|
||||
if (b->previous() == nullptr) {
|
||||
const TrackReference& track_ref = ghost->Track();
|
||||
|
||||
new TrackPlaceBlockCommand(parent()->timeline_node_->track_list(track_ref.type()),
|
||||
track_ref.index(),
|
||||
b,
|
||||
ghost->GetAdjustedIn(),
|
||||
command);
|
||||
}
|
||||
} else if (ghost->mode() == olive::timeline::kTrimOut) {
|
||||
new BlockResizeCommand(b, ghost->AdjustedLength(), command);
|
||||
}
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
rational TimelineWidget::RollingTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *> &ghosts)
|
||||
{
|
||||
// Only validate trimming, and we don't care about "overwriting" since the rolling tool is designed to trim at collisions
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, false);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, false);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
|
||||
void TimelineWidget::RollingTool::InitiateGhosts(TimelineViewBlockItem *clicked_item,
|
||||
olive::timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
{
|
||||
Q_UNUSED(allow_gap_trimming)
|
||||
|
||||
PointerTool::InitiateGhosts(clicked_item, trim_mode, true);
|
||||
|
||||
// For each ghost, we make an equivalent Ghost on the next/previous block
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* ghost_block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == olive::timeline::kTrimIn && ghost_block->previous() != nullptr) {
|
||||
// Add an extra Ghost for the previous block
|
||||
AddGhostFromBlock(ghost_block->previous(), ghost->Track(), olive::timeline::kTrimOut);
|
||||
} else if (ghost->mode() == olive::timeline::kTrimOut && ghost_block->next() != nullptr && ghost_block->next()->type() != Block::kEnd) {
|
||||
AddGhostFromBlock(ghost_block->next(), ghost->Track(), olive::timeline::kTrimIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include "node/block/gap/gap.h"
|
||||
|
||||
TimelineWidget::SlideTool::SlideTool(TimelineWidget* parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetTrimmingAllowed(false);
|
||||
SetTrackMovementAllowed(false);
|
||||
}
|
||||
|
||||
void TimelineWidget::SlideTool::MouseReleaseInternal(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
if (ghost->mode() == olive::timeline::kTrimIn) {
|
||||
new BlockResizeWithMediaInCommand(b, ghost->AdjustedLength(), command);
|
||||
} else if (ghost->mode() == olive::timeline::kTrimOut) {
|
||||
new BlockResizeCommand(b, ghost->AdjustedLength(), command);
|
||||
} else if (ghost->mode() == olive::timeline::kMove && b->previous() == nullptr) {
|
||||
GapBlock* gap = new GapBlock();
|
||||
gap->set_length(ghost->InAdjustment());
|
||||
new TrackPrependBlockCommand(parent()->GetTrackFromReference(ghost->Track()), gap, command);
|
||||
}
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
rational TimelineWidget::SlideTool::FrameValidateInternal(rational time_movement, const QVector<TimelineViewGhostItem *> &ghosts)
|
||||
{
|
||||
// Only validate trimming, and we don't care about "overwriting" since the rolling tool is designed to trim at collisions
|
||||
time_movement = ValidateInTrimming(time_movement, ghosts, false);
|
||||
time_movement = ValidateOutTrimming(time_movement, ghosts, false);
|
||||
|
||||
return time_movement;
|
||||
}
|
||||
|
||||
void TimelineWidget::SlideTool::InitiateGhosts(TimelineViewBlockItem *clicked_item,
|
||||
olive::timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
{
|
||||
Q_UNUSED(allow_gap_trimming)
|
||||
|
||||
PointerTool::InitiateGhosts(clicked_item, trim_mode, true);
|
||||
|
||||
// For each ghost, we make an equivalent Ghost on the next/previous block
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* ghost_block = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Add trimming ghosts for each side of the Block
|
||||
|
||||
if (ghost_block->previous() != nullptr) {
|
||||
// Add an extra Ghost for the previous block
|
||||
AddGhostFromBlock(ghost_block->previous(), ghost->Track(), olive::timeline::kTrimOut);
|
||||
}
|
||||
|
||||
if (ghost_block->next() != nullptr && ghost_block->next()->type() != Block::kEnd) {
|
||||
AddGhostFromBlock(ghost_block->next(), ghost->Track(), olive::timeline::kTrimIn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <QToolTip>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "config/config.h"
|
||||
|
||||
TimelineWidget::SlipTool::SlipTool(TimelineWidget *parent) :
|
||||
PointerTool(parent)
|
||||
{
|
||||
SetTrimmingAllowed(false);
|
||||
SetTrackMovementAllowed(false);
|
||||
}
|
||||
|
||||
void TimelineWidget::SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos)
|
||||
{
|
||||
// Determine frame movement
|
||||
rational time_movement = drag_start_.GetFrame() - mouse_pos.GetFrame();
|
||||
|
||||
// Validate slip (enforce all ghosts moving in legal ways)
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
if (ghost->MediaIn() + time_movement < 0) {
|
||||
time_movement = -ghost->MediaIn();
|
||||
}
|
||||
}
|
||||
|
||||
// Perform slip
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
ghost->SetMediaInAdjustment(time_movement);
|
||||
}
|
||||
|
||||
// Show tooltip
|
||||
// Generate tooltip (showing earliest in point of imported clip)
|
||||
int64_t earliest_timestamp = olive::time_to_timestamp(time_movement, parent()->timebase());
|
||||
QString tooltip_text = olive::timestamp_to_timecode(earliest_timestamp,
|
||||
parent()->timebase(),
|
||||
olive::CurrentTimecodeDisplay(),
|
||||
true);
|
||||
QToolTip::showText(QCursor::pos(),
|
||||
tooltip_text,
|
||||
parent());
|
||||
}
|
||||
|
||||
void TimelineWidget::SlipTool::MouseReleaseInternal(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
|
||||
QUndoCommand* command = new QUndoCommand();
|
||||
|
||||
// Find earliest point to ripple around
|
||||
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
new BlockSetMediaInCommand(b, ghost->GetAdjustedMediaIn(), command);
|
||||
}
|
||||
|
||||
olive::undo_stack.pushIfHasChildren(command);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <float.h>
|
||||
|
||||
#include "common/range.h"
|
||||
|
||||
TimelineWidget::Tool::Tool(TimelineWidget *parent) :
|
||||
dragging_(false),
|
||||
parent_(parent),
|
||||
drag_mode_(QGraphicsView::NoDrag)
|
||||
{
|
||||
}
|
||||
|
||||
TimelineWidget::Tool::~Tool()
|
||||
{
|
||||
}
|
||||
|
||||
TimelineWidget *TimelineWidget::Tool::parent()
|
||||
{
|
||||
return parent_;
|
||||
}
|
||||
|
||||
olive::timeline::MovementMode TimelineWidget::Tool::FlipTrimMode(const olive::timeline::MovementMode &trim_mode)
|
||||
{
|
||||
if (trim_mode == olive::timeline::kTrimIn) {
|
||||
return olive::timeline::kTrimOut;
|
||||
}
|
||||
|
||||
if (trim_mode == olive::timeline::kTrimOut) {
|
||||
return olive::timeline::kTrimIn;
|
||||
}
|
||||
|
||||
return trim_mode;
|
||||
}
|
||||
|
||||
const QGraphicsView::DragMode &TimelineWidget::Tool::drag_mode()
|
||||
{
|
||||
return drag_mode_;
|
||||
}
|
||||
|
||||
void TimelineWidget::Tool::set_drag_mode(const QGraphicsView::DragMode &mode)
|
||||
{
|
||||
drag_mode_ = mode;
|
||||
}
|
||||
|
||||
TimelineViewBlockItem *TimelineWidget::Tool::GetItemAtScenePos(const TimelineCoordinate& coord)
|
||||
{
|
||||
QMapIterator<Block*, TimelineViewBlockItem*> iterator(parent()->block_items_);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
|
||||
Block* b = iterator.key();
|
||||
TimelineViewBlockItem* item = iterator.value();
|
||||
|
||||
if (b->in() <= coord.GetFrame()
|
||||
&& b->out() > coord.GetFrame()
|
||||
&& item->Track() == coord.GetTrack()) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void AttemptSnap(const QList<double>& proposed_pts,
|
||||
double compare_point,
|
||||
const QList<rational>& start_times,
|
||||
rational compare_time,
|
||||
rational* movement,
|
||||
double* diff) {
|
||||
const qreal kSnapRange = 10; // FIXME: Hardcoded number
|
||||
|
||||
for (int i=0;i<proposed_pts.size();i++) {
|
||||
// Attempt snapping to clip out point
|
||||
if (InRange(proposed_pts.at(i), compare_point, kSnapRange)) {
|
||||
double this_diff = qAbs(compare_point - proposed_pts.at(i));
|
||||
|
||||
if (this_diff < *diff
|
||||
&& start_times.at(i) + *movement >= 0) {
|
||||
*movement = compare_time - start_times.at(i);
|
||||
*diff = this_diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rational TimelineWidget::Tool::ValidateFrameMovement(rational movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
if (ghost->mode() != olive::timeline::kMove) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prevents any ghosts from going below 0:00:00 time
|
||||
if (ghost->In() + movement < 0) {
|
||||
movement = -ghost->In();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem *> ghosts)
|
||||
{
|
||||
foreach (TimelineViewGhostItem* ghost, ghosts) {
|
||||
// Prevents any ghosts from going to a non-existent negative track
|
||||
if (ghost->Track().index() + movement < 0) {
|
||||
if (ghost->mode() != olive::timeline::kMove) {
|
||||
continue;
|
||||
}
|
||||
|
||||
movement = -ghost->Track().index();
|
||||
}
|
||||
}
|
||||
|
||||
return movement;
|
||||
}
|
||||
|
||||
bool TimelineWidget::Tool::SnapPoint(QList<rational> start_times, rational* movement, int snap_points)
|
||||
{
|
||||
double diff = DBL_MAX;
|
||||
|
||||
QList<double> proposed_pts;
|
||||
|
||||
foreach (rational s, start_times) {
|
||||
proposed_pts.append((s + *movement).toDouble() * parent()->scale_);
|
||||
}
|
||||
|
||||
if (snap_points & kSnapToPlayhead) {
|
||||
|
||||
|
||||
rational playhead_abs_time = rational(parent()->playhead_ * parent()->timebase().numerator(),
|
||||
parent()->timebase().denominator());
|
||||
|
||||
qreal playhead_pos = playhead_abs_time.toDouble() * parent()->scale_;
|
||||
|
||||
AttemptSnap(proposed_pts, playhead_pos, start_times, playhead_abs_time, movement, &diff);
|
||||
}
|
||||
|
||||
if (snap_points & kSnapToClips) {
|
||||
QMapIterator<Block*, TimelineViewBlockItem*> iterator(parent()->block_items_);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
|
||||
TimelineViewBlockItem* item = iterator.value();
|
||||
|
||||
if (item != nullptr) {
|
||||
qreal rect_left = item->x();
|
||||
qreal rect_right = rect_left + item->rect().width();
|
||||
|
||||
// Attempt snapping to clip in point
|
||||
AttemptSnap(proposed_pts, rect_left, start_times, item->block()->in(), movement, &diff);
|
||||
|
||||
// Attempt snapping to clip out point
|
||||
AttemptSnap(proposed_pts, rect_right, start_times, item->block()->out(), movement, &diff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (diff < DBL_MAX);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/***
|
||||
|
||||
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/timelinewidget/timelinewidget.h"
|
||||
|
||||
TimelineWidget::ZoomTool::ZoomTool(TimelineWidget *parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineWidget::ZoomTool::MousePress(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void TimelineWidget::ZoomTool::MouseMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
Q_UNUSED(event)
|
||||
}
|
||||
|
||||
void TimelineWidget::ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
{
|
||||
double scale = parent()->scale_;
|
||||
|
||||
// Normalize zoom location for 1.0 scale
|
||||
double frame_x = parent()->TimeToScene(event->GetCoordinates().GetFrame());
|
||||
|
||||
if (event->GetModifiers() & Qt::AltModifier) {
|
||||
// Zoom out if the user clicks while holding Alt
|
||||
scale *= 0.5;
|
||||
} else {
|
||||
// Otherwise zoom in
|
||||
scale *= 2;
|
||||
}
|
||||
|
||||
parent()->SetScale(scale);
|
||||
|
||||
// Adjust zoom location for new scale
|
||||
frame_x *= scale;
|
||||
|
||||
parent()->CenterOn(frame_x);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
# 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/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelinewidget/undo/undo.h
|
||||
widget/timelinewidget/undo/undo.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,441 @@
|
||||
/***
|
||||
|
||||
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 "undo.h"
|
||||
|
||||
#include "node/graph.h"
|
||||
|
||||
#include <QDebug>
|
||||
Block* CreateSplitBlock(Block* block, rational point, QObject* parent = nullptr)
|
||||
{
|
||||
Block* copy = block->copy();
|
||||
copy->set_length_and_media_in(block->length() - (point - block->in()));
|
||||
copy->setParent(parent);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
Node* TakeNodeFromParentGraph(Node* n, QObject* new_parent = nullptr) {
|
||||
static_cast<NodeGraph*>(n->parent())->TakeNode(n, new_parent);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
BlockResizeCommand::BlockResizeCommand(Block *block, rational new_length, QUndoCommand* parent) :
|
||||
QUndoCommand(parent),
|
||||
block_(block),
|
||||
old_length_(block->length()),
|
||||
new_length_(new_length)
|
||||
{
|
||||
}
|
||||
|
||||
void BlockResizeCommand::redo()
|
||||
{
|
||||
block_->set_length(new_length_);
|
||||
}
|
||||
|
||||
void BlockResizeCommand::undo()
|
||||
{
|
||||
block_->set_length(old_length_);
|
||||
}
|
||||
|
||||
BlockResizeWithMediaInCommand::BlockResizeWithMediaInCommand(Block *block, rational new_length, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
block_(block),
|
||||
old_length_(block->length()),
|
||||
new_length_(new_length)
|
||||
{
|
||||
}
|
||||
|
||||
void BlockResizeWithMediaInCommand::redo()
|
||||
{
|
||||
block_->set_length_and_media_in(new_length_);
|
||||
}
|
||||
|
||||
void BlockResizeWithMediaInCommand::undo()
|
||||
{
|
||||
block_->set_length_and_media_in(old_length_);
|
||||
}
|
||||
|
||||
BlockSetMediaInCommand::BlockSetMediaInCommand(Block *block, rational new_media_in, QUndoCommand* parent) :
|
||||
QUndoCommand(parent),
|
||||
block_(block),
|
||||
old_media_in_(block->media_in()),
|
||||
new_media_in_(new_media_in)
|
||||
{
|
||||
}
|
||||
|
||||
void BlockSetMediaInCommand::redo()
|
||||
{
|
||||
block_->set_media_in(new_media_in_);
|
||||
}
|
||||
|
||||
void BlockSetMediaInCommand::undo()
|
||||
{
|
||||
block_->set_media_in(old_media_in_);
|
||||
}
|
||||
|
||||
TrackRippleRemoveBlockCommand::TrackRippleRemoveBlockCommand(TrackOutput *track, Block *block, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
block_(block),
|
||||
before_(block->previous()),
|
||||
after_(block->next())
|
||||
{
|
||||
}
|
||||
|
||||
void TrackRippleRemoveBlockCommand::redo()
|
||||
{
|
||||
track_->RippleRemoveBlock(block_);
|
||||
}
|
||||
|
||||
void TrackRippleRemoveBlockCommand::undo()
|
||||
{
|
||||
track_->InsertBlockBetweenBlocks(block_, before_, after_);
|
||||
}
|
||||
|
||||
TrackInsertBlockBetweenBlocksCommand::TrackInsertBlockBetweenBlocksCommand(TrackOutput *track,
|
||||
Block *block,
|
||||
Block *before,
|
||||
Block *after,
|
||||
QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
block_(block),
|
||||
before_(before),
|
||||
after_(after)
|
||||
{
|
||||
}
|
||||
|
||||
void TrackInsertBlockBetweenBlocksCommand::redo()
|
||||
{
|
||||
track_->InsertBlockBetweenBlocks(block_, before_, after_);
|
||||
}
|
||||
|
||||
void TrackInsertBlockBetweenBlocksCommand::undo()
|
||||
{
|
||||
track_->RippleRemoveBlock(block_);
|
||||
}
|
||||
|
||||
TrackRippleRemoveAreaCommand::TrackRippleRemoveAreaCommand(TrackOutput *track, rational in, rational out, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
in_(in),
|
||||
out_(out),
|
||||
splice_(nullptr),
|
||||
trim_out_(nullptr),
|
||||
trim_in_(nullptr),
|
||||
insert_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void TrackRippleRemoveAreaCommand::SetInsert(Block *insert)
|
||||
{
|
||||
insert_ = insert;
|
||||
}
|
||||
|
||||
void TrackRippleRemoveAreaCommand::redo()
|
||||
{
|
||||
// Iterate through blocks determining which need trimming/removing/splitting
|
||||
foreach (Block* block, track_->Blocks()) {
|
||||
if (block->in() < in_ && block->out() > out_) {
|
||||
// The area entirely within this Block
|
||||
splice_ = block;
|
||||
|
||||
// We don't need to do anything else here
|
||||
break;
|
||||
} else if (block->in() >= in_ && block->out() <= out_) {
|
||||
// This Block's is entirely within the area
|
||||
removed_blocks_.append(block);
|
||||
} else if (block->in() < in_ && block->out() >= in_) {
|
||||
// This Block's out point exceeds `in`
|
||||
trim_out_ = block;
|
||||
} else if (block->in() <= out_ && block->out() > out_) {
|
||||
// This Block's in point exceeds `out`
|
||||
trim_in_ = block;
|
||||
}
|
||||
}
|
||||
|
||||
track_->BlockInvalidateCache();
|
||||
|
||||
// If we picked up a block to splice
|
||||
if (splice_ != nullptr) {
|
||||
|
||||
// Split the block here
|
||||
Block* copy = CreateSplitBlock(splice_, out_);
|
||||
|
||||
splice_original_length_ = splice_->length();
|
||||
splice_->set_length(out_ - splice_->in());
|
||||
|
||||
track_->AddBlockToGraph(copy);
|
||||
Node::CopyInputs(splice_, copy);
|
||||
|
||||
track_->InsertBlockAfter(copy, splice_);
|
||||
|
||||
// Perform all further actions as if we were just trimming these clips
|
||||
trim_out_ = splice_;
|
||||
trim_in_ = copy;
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the in point of
|
||||
if (trim_in_ != nullptr) {
|
||||
trim_in_old_length_ = trim_in_->length();
|
||||
trim_in_new_length_ = trim_in_->out() - out_;
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the out point of
|
||||
if (trim_out_ != nullptr) {
|
||||
trim_out_old_length_ = trim_out_->length();
|
||||
trim_out_new_length_ = in_ - trim_out_->in();
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the in point of
|
||||
if (trim_in_old_length_ != trim_in_new_length_) {
|
||||
trim_in_->set_length_and_media_in(trim_in_new_length_);
|
||||
}
|
||||
|
||||
// Remove all blocks that are flagged for removal
|
||||
foreach (Block* remove_block, removed_blocks_) {
|
||||
track_->RippleRemoveBlock(remove_block);
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the out point of
|
||||
if (trim_out_old_length_ != trim_out_new_length_) {
|
||||
trim_out_->set_length(trim_out_new_length_);
|
||||
}
|
||||
|
||||
// If we were given a block to insert, insert it here
|
||||
if (insert_ != nullptr) {
|
||||
track_->AddBlockToGraph(insert_);
|
||||
|
||||
if (trim_out_ == nullptr) {
|
||||
// This is the start of the Sequence
|
||||
track_->PrependBlock(insert_);
|
||||
} else if (trim_in_ == nullptr) {
|
||||
// This is the end of the Sequence
|
||||
track_->AppendBlock(insert_);
|
||||
} else {
|
||||
// This is somewhere in the middle of the Sequence
|
||||
track_->InsertBlockBetweenBlocks(insert_, trim_out_, trim_in_);
|
||||
}
|
||||
}
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
|
||||
track_->InvalidateCache(in_, out_);
|
||||
}
|
||||
|
||||
void TrackRippleRemoveAreaCommand::undo()
|
||||
{
|
||||
track_->BlockInvalidateCache();
|
||||
|
||||
// If we were given a block to insert, insert it here
|
||||
if (insert_ != nullptr) {
|
||||
track_->RippleRemoveBlock(insert_);
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the out point of
|
||||
if (trim_out_old_length_ != trim_out_new_length_) {
|
||||
trim_out_->set_length(trim_out_old_length_);
|
||||
}
|
||||
|
||||
// Remove all blocks that are flagged for removal
|
||||
foreach (Block* remove_block, removed_blocks_) {
|
||||
if (trim_in_ == nullptr) {
|
||||
track_->AppendBlock(remove_block);
|
||||
} else {
|
||||
track_->InsertBlockBefore(remove_block, trim_in_);
|
||||
}
|
||||
}
|
||||
|
||||
// If we picked up a block to trim the in point of
|
||||
if (trim_in_old_length_ != trim_in_new_length_) {
|
||||
trim_in_->set_length_and_media_in(trim_in_old_length_);
|
||||
}
|
||||
|
||||
// If we're splicing, trim_in_ is a copy
|
||||
if (splice_ != nullptr) {
|
||||
track_->RippleRemoveBlock(trim_in_);
|
||||
|
||||
// Remove node
|
||||
TakeNodeFromParentGraph(trim_in_, &memory_manager_);
|
||||
|
||||
splice_->set_length(splice_original_length_);
|
||||
}
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
|
||||
track_->InvalidateCache(in_, out_);
|
||||
}
|
||||
|
||||
TrackPlaceBlockCommand::TrackPlaceBlockCommand(TrackList *timeline, int track, Block *block, rational in, QUndoCommand *parent) :
|
||||
TrackRippleRemoveAreaCommand(nullptr, in, 0, parent), // Out gets set correctly in redo()
|
||||
timeline_(timeline),
|
||||
track_index_(track),
|
||||
gap_(nullptr)
|
||||
{
|
||||
insert_ = block;
|
||||
insert_->setParent(&memory_manager_);
|
||||
}
|
||||
|
||||
void TrackPlaceBlockCommand::redo()
|
||||
{
|
||||
added_track_count_ = 0;
|
||||
|
||||
// Get track (or make it if necessary)
|
||||
while (track_index_ >= timeline_->Tracks().size()) {
|
||||
timeline_->AddTrack();
|
||||
|
||||
added_track_count_++;
|
||||
}
|
||||
|
||||
track_ = timeline_->TrackAt(track_index_);
|
||||
|
||||
append_ = (in_ >= track_->in());
|
||||
|
||||
// Check if the placement location is past the end of the timeline
|
||||
if (append_) {
|
||||
if (in_ > track_->in()) {
|
||||
// If so, insert a gap here
|
||||
gap_ = new GapBlock();
|
||||
gap_->set_length(in_ - track_->in());
|
||||
track_->AppendBlock(gap_);
|
||||
}
|
||||
|
||||
track_->AppendBlock(insert_);
|
||||
} else {
|
||||
out_ = in_ + insert_->length();
|
||||
|
||||
// Place the Block at this point
|
||||
TrackRippleRemoveAreaCommand::redo();
|
||||
}
|
||||
}
|
||||
|
||||
void TrackPlaceBlockCommand::undo()
|
||||
{
|
||||
if (append_) {
|
||||
track_->RippleRemoveBlock(insert_);
|
||||
TakeNodeFromParentGraph(insert_, &memory_manager_);
|
||||
|
||||
if (gap_ != nullptr) {
|
||||
track_->RippleRemoveBlock(gap_);
|
||||
delete TakeNodeFromParentGraph(gap_);
|
||||
}
|
||||
} else {
|
||||
TrackRippleRemoveAreaCommand::undo();
|
||||
}
|
||||
|
||||
for (;added_track_count_>0;added_track_count_--) {
|
||||
timeline_->RemoveTrack();
|
||||
}
|
||||
}
|
||||
|
||||
BlockSplitCommand::BlockSplitCommand(TrackOutput* track, Block *block, rational point, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
block_(block),
|
||||
new_length_(point - block->in()),
|
||||
old_length_(block->length())
|
||||
{
|
||||
Q_ASSERT(point > block_->in() && point < block_->out());
|
||||
|
||||
// Ensures that this block is deleted if this action is undone
|
||||
new_block_ = CreateSplitBlock(block_, point, &memory_manager_);
|
||||
}
|
||||
|
||||
void BlockSplitCommand::redo()
|
||||
{
|
||||
track_->BlockInvalidateCache();
|
||||
|
||||
block_->set_length(new_length_);
|
||||
|
||||
track_->AddBlockToGraph(new_block_);
|
||||
Node::CopyInputs(block_, new_block_);
|
||||
|
||||
// Will re-parent new_block_ to the track's graph
|
||||
track_->InsertBlockAfter(new_block_, block_);
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
}
|
||||
|
||||
void BlockSplitCommand::undo()
|
||||
{
|
||||
track_->BlockInvalidateCache();
|
||||
|
||||
block_->set_length(old_length_);
|
||||
track_->RippleRemoveBlock(new_block_);
|
||||
|
||||
TakeNodeFromParentGraph(new_block_, &memory_manager_);
|
||||
|
||||
track_->UnblockInvalidateCache();
|
||||
}
|
||||
|
||||
TrackSplitAtTimeCommand::TrackSplitAtTimeCommand(TrackOutput *track, rational point, QUndoCommand *parent) :
|
||||
QUndoCommand(parent)
|
||||
{
|
||||
// Find Block that contains this time
|
||||
for (int i=0;i<track->Blocks().size();i++) {
|
||||
Block* b = track->Blocks().at(i);
|
||||
|
||||
if (b->out() == point) {
|
||||
// This time is between blocks, no split needs to occur
|
||||
return;
|
||||
} else if (b->in() < point && b->out() > point) {
|
||||
// We found the Block, split it
|
||||
new BlockSplitCommand(track, b, point, this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TrackReplaceBlockCommand::TrackReplaceBlockCommand(TrackOutput* track, Block *old, Block *replace, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
old_(old),
|
||||
replace_(replace)
|
||||
{
|
||||
}
|
||||
|
||||
void TrackReplaceBlockCommand::redo()
|
||||
{
|
||||
track_->ReplaceBlock(old_, replace_);
|
||||
}
|
||||
|
||||
void TrackReplaceBlockCommand::undo()
|
||||
{
|
||||
track_->ReplaceBlock(replace_, old_);
|
||||
}
|
||||
|
||||
TrackPrependBlockCommand::TrackPrependBlockCommand(TrackOutput *track, Block *block, QUndoCommand *parent) :
|
||||
QUndoCommand(parent),
|
||||
track_(track),
|
||||
block_(block)
|
||||
{
|
||||
}
|
||||
|
||||
void TrackPrependBlockCommand::redo()
|
||||
{
|
||||
track_->PrependBlock(block_);
|
||||
}
|
||||
|
||||
void TrackPrependBlockCommand::undo()
|
||||
{
|
||||
track_->RippleRemoveBlock(block_);
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEUNDOABLE_H
|
||||
#define TIMELINEUNDOABLE_H
|
||||
|
||||
#include <QUndoCommand>
|
||||
|
||||
#include "node/block/block.h"
|
||||
#include "node/block/gap/gap.h"
|
||||
#include "node/output/timeline/timeline.h"
|
||||
#include "node/output/track/track.h"
|
||||
|
||||
class BlockResizeCommand : public QUndoCommand {
|
||||
public:
|
||||
BlockResizeCommand(Block* block, rational new_length, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Block* block_;
|
||||
rational old_length_;
|
||||
rational new_length_;
|
||||
};
|
||||
|
||||
class BlockResizeWithMediaInCommand : public QUndoCommand {
|
||||
public:
|
||||
BlockResizeWithMediaInCommand(Block* block, rational new_length, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Block* block_;
|
||||
rational old_length_;
|
||||
rational new_length_;
|
||||
};
|
||||
|
||||
class BlockSetMediaInCommand : public QUndoCommand {
|
||||
public:
|
||||
BlockSetMediaInCommand(Block* block, rational new_media_in, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
Block* block_;
|
||||
rational old_media_in_;
|
||||
rational new_media_in_;
|
||||
};
|
||||
|
||||
class TrackRippleRemoveBlockCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackRippleRemoveBlockCommand(TrackOutput* track, Block* block, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
|
||||
Block* block_;
|
||||
|
||||
Block* before_;
|
||||
Block* after_;
|
||||
};
|
||||
|
||||
class TrackPrependBlockCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackPrependBlockCommand(TrackOutput* track, Block* block, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
Block* block_;
|
||||
};
|
||||
|
||||
class TrackInsertBlockBetweenBlocksCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackInsertBlockBetweenBlocksCommand(TrackOutput* track, Block* block, Block* before, Block* after, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
|
||||
Block* block_;
|
||||
|
||||
Block* before_;
|
||||
Block* after_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Clears the area between in and out
|
||||
*
|
||||
* The area between `in` and `out` is guaranteed to be freed. BLocks are trimmed and removed to free this space.
|
||||
* By default, nothing takes this area meaning all subsequent clips are pushed backward, however you can specify
|
||||
* a block to insert at the `in` point. No checking is done to ensure `insert` is the same length as `in` to `out`.
|
||||
*/
|
||||
class TrackRippleRemoveAreaCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackRippleRemoveAreaCommand(TrackOutput* track, rational in, rational out, QUndoCommand* parent = nullptr);
|
||||
|
||||
void SetInsert(Block* insert);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
protected:
|
||||
TrackOutput* track_;
|
||||
rational in_;
|
||||
rational out_;
|
||||
|
||||
Block* splice_;
|
||||
rational splice_original_length_;
|
||||
|
||||
Block* trim_out_;
|
||||
QVector<Block*> removed_blocks_;
|
||||
Block* trim_in_;
|
||||
|
||||
rational trim_in_old_length_;
|
||||
rational trim_out_old_length_;
|
||||
|
||||
rational trim_in_new_length_;
|
||||
rational trim_out_new_length_;
|
||||
|
||||
Block* insert_;
|
||||
|
||||
QObject memory_manager_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Destructively places `block` at the in point `start`
|
||||
*
|
||||
* The Block is guaranteed to be placed at the starting point specified. If there are Blocks in this area, they are
|
||||
* either trimmed or removed to make space for this Block. Additionally, if the Block is placed beyond the end of
|
||||
* the Sequence, a GapBlock is inserted to compensate.
|
||||
*/
|
||||
class TrackPlaceBlockCommand : public TrackRippleRemoveAreaCommand {
|
||||
public:
|
||||
TrackPlaceBlockCommand(TrackList *timeline, int track, Block* block, rational in, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackList* timeline_;
|
||||
int track_index_;
|
||||
bool append_;
|
||||
GapBlock* gap_;
|
||||
int added_track_count_;
|
||||
};
|
||||
|
||||
class BlockSplitCommand : public QUndoCommand {
|
||||
public:
|
||||
BlockSplitCommand(TrackOutput* track, Block* block, rational point, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
Block* block_;
|
||||
|
||||
rational new_length_;
|
||||
rational old_length_;
|
||||
|
||||
Block* new_block_;
|
||||
|
||||
QObject memory_manager_;
|
||||
};
|
||||
|
||||
class TrackSplitAtTimeCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackSplitAtTimeCommand(TrackOutput* track, rational point, QUndoCommand* parent = nullptr);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Replaces Block `old` with Block `replace`
|
||||
*
|
||||
* Both blocks must have equal lengths.
|
||||
*/
|
||||
class TrackReplaceBlockCommand : public QUndoCommand {
|
||||
public:
|
||||
TrackReplaceBlockCommand(TrackOutput* track, Block* old, Block* replace, QUndoCommand* parent = nullptr);
|
||||
|
||||
virtual void redo() override;
|
||||
virtual void undo() override;
|
||||
|
||||
private:
|
||||
TrackOutput* track_;
|
||||
Block* old_;
|
||||
Block* replace_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEUNDOABLE_H
|
||||
@@ -0,0 +1,34 @@
|
||||
# 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/>.
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelinewidget/view/timelineplayhead.h
|
||||
widget/timelinewidget/view/timelineplayhead.cpp
|
||||
widget/timelinewidget/view/timelineview.h
|
||||
widget/timelinewidget/view/timelineview.cpp
|
||||
widget/timelinewidget/view/timelineviewmouseevent.h
|
||||
widget/timelinewidget/view/timelineviewmouseevent.cpp
|
||||
widget/timelinewidget/view/timelineviewrect.h
|
||||
widget/timelinewidget/view/timelineviewrect.cpp
|
||||
widget/timelinewidget/view/timelineviewblockitem.h
|
||||
widget/timelinewidget/view/timelineviewblockitem.cpp
|
||||
widget/timelinewidget/view/timelineviewenditem.h
|
||||
widget/timelinewidget/view/timelineviewenditem.cpp
|
||||
widget/timelinewidget/view/timelineviewghostitem.h
|
||||
widget/timelinewidget/view/timelineviewghostitem.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
@@ -0,0 +1,46 @@
|
||||
/***
|
||||
|
||||
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 "timelineplayhead.h"
|
||||
|
||||
TimelinePlayhead::TimelinePlayhead()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QColor TimelinePlayhead::PlayheadColor()
|
||||
{
|
||||
return playhead_color_;
|
||||
}
|
||||
|
||||
QColor TimelinePlayhead::PlayheadHighlightColor()
|
||||
{
|
||||
return playhead_highlight_color_;
|
||||
}
|
||||
|
||||
void TimelinePlayhead::SetPlayheadColor(QColor c)
|
||||
{
|
||||
playhead_color_ = c;
|
||||
}
|
||||
|
||||
void TimelinePlayhead::SetPlayheadHighlightColor(QColor c)
|
||||
{
|
||||
playhead_highlight_color_ = c;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEPLAYHEADSTYLE_H
|
||||
#define TIMELINEPLAYHEADSTYLE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
/**
|
||||
* @brief A QWidget proxy for TimeRuler and TimelinePlayheadItem to allow them to share CSS values
|
||||
*
|
||||
* To allow Qt CSS customization (which is only available to QWidgets) to be accessed by TimeRuler
|
||||
*/
|
||||
class TimelinePlayhead : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor playheadColor READ PlayheadColor WRITE SetPlayheadColor DESIGNABLE true)
|
||||
Q_PROPERTY(QColor playheadHighlightColor READ PlayheadHighlightColor WRITE SetPlayheadHighlightColor DESIGNABLE true)
|
||||
public:
|
||||
TimelinePlayhead();
|
||||
|
||||
QColor PlayheadColor();
|
||||
QColor PlayheadHighlightColor();
|
||||
|
||||
void SetPlayheadColor(QColor c);
|
||||
void SetPlayheadHighlightColor(QColor c);
|
||||
|
||||
private:
|
||||
QColor playhead_color_;
|
||||
QColor playhead_highlight_color_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEPLAYHEADSTYLE_H
|
||||
@@ -0,0 +1,318 @@
|
||||
/***
|
||||
|
||||
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 "timelineview.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMimeData>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QtMath>
|
||||
#include <QPen>
|
||||
|
||||
#include "common/flipmodifiers.h"
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "core.h"
|
||||
#include "node/input/media/media.h"
|
||||
#include "project/item/footage/footage.h"
|
||||
|
||||
TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignment, QWidget *parent) :
|
||||
QGraphicsView(parent),
|
||||
playhead_(0),
|
||||
type_(type)
|
||||
{
|
||||
Q_ASSERT(vertical_alignment == Qt::AlignTop || vertical_alignment == Qt::AlignBottom);
|
||||
setAlignment(Qt::AlignLeft | vertical_alignment);
|
||||
|
||||
setScene(&scene_);
|
||||
setDragMode(RubberBandDrag);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
|
||||
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(UpdateSceneRect()));
|
||||
|
||||
// Create end item
|
||||
end_item_ = new TimelineViewEndItem();
|
||||
scene_.addItem(end_item_);
|
||||
|
||||
// Set default scale
|
||||
SetScale(1.0);
|
||||
}
|
||||
|
||||
void TimelineView::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
|
||||
// Force redraw for playhead
|
||||
viewport()->update();
|
||||
|
||||
end_item_->SetScale(scale_);
|
||||
}
|
||||
|
||||
void TimelineView::SetTimebase(const rational &timebase)
|
||||
{
|
||||
SetTimebaseInternal(timebase);
|
||||
|
||||
// Timebase influences position/visibility of playhead
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void TimelineView::SelectAll()
|
||||
{
|
||||
QList<QGraphicsItem*> all_items = items();
|
||||
|
||||
foreach (QGraphicsItem* i, all_items) {
|
||||
i->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::DeselectAll()
|
||||
{
|
||||
QList<QGraphicsItem*> all_items = items();
|
||||
|
||||
foreach (QGraphicsItem* i, all_items) {
|
||||
i->setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::SetTime(const int64_t time)
|
||||
{
|
||||
playhead_ = time;
|
||||
|
||||
// Force redraw for playhead
|
||||
viewport()->update();
|
||||
}
|
||||
|
||||
void TimelineView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->modifiers());
|
||||
|
||||
emit MousePressed(&timeline_event);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TimelineView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->modifiers());
|
||||
|
||||
emit MouseMoved(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->modifiers());
|
||||
|
||||
emit MouseReleased(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->modifiers());
|
||||
|
||||
emit MouseDoubleClicked(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->keyboardModifiers());
|
||||
|
||||
timeline_event.SetMimeData(event->mimeData());
|
||||
timeline_event.SetEvent(event);
|
||||
|
||||
emit DragEntered(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->keyboardModifiers());
|
||||
|
||||
timeline_event.SetMimeData(event->mimeData());
|
||||
timeline_event.SetEvent(event);
|
||||
|
||||
emit DragMoved(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::dragLeaveEvent(QDragLeaveEvent *event)
|
||||
{
|
||||
emit DragLeft(event);
|
||||
}
|
||||
|
||||
void TimelineView::dropEvent(QDropEvent *event)
|
||||
{
|
||||
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
|
||||
event->keyboardModifiers());
|
||||
|
||||
timeline_event.SetMimeData(event->mimeData());
|
||||
timeline_event.SetEvent(event);
|
||||
|
||||
emit DragDropped(&timeline_event);
|
||||
}
|
||||
|
||||
void TimelineView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
|
||||
UpdateSceneRect();
|
||||
}
|
||||
|
||||
void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
QGraphicsView::drawForeground(painter, rect);
|
||||
|
||||
if (!timebase().isNull()) {
|
||||
double x = TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
|
||||
double width = TimeToScene(timebase());
|
||||
|
||||
QRectF playhead_rect(x, rect.top(), width, rect.height());
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(playhead_style_.PlayheadHighlightColor());
|
||||
painter->drawRect(playhead_rect);
|
||||
|
||||
painter->setPen(playhead_style_.PlayheadColor());
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawLine(QLineF(playhead_rect.topLeft(), playhead_rect.bottomLeft()));
|
||||
}
|
||||
}
|
||||
|
||||
Stream::Type TimelineView::TrackTypeToStreamType(TrackType track_type)
|
||||
{
|
||||
switch (track_type) {
|
||||
case kTrackTypeNone:
|
||||
case kTrackTypeCount:
|
||||
break;
|
||||
case kTrackTypeVideo:
|
||||
return Stream::kVideo;
|
||||
case kTrackTypeAudio:
|
||||
return Stream::kAudio;
|
||||
case kTrackTypeSubtitle:
|
||||
return Stream::kSubtitle;
|
||||
}
|
||||
|
||||
return Stream::kUnknown;
|
||||
}
|
||||
|
||||
TimelineCoordinate TimelineView::ScreenToCoordinate(const QPoint& pt)
|
||||
{
|
||||
return SceneToCoordinate(mapToScene(pt));
|
||||
}
|
||||
|
||||
TimelineCoordinate TimelineView::SceneToCoordinate(const QPointF& pt)
|
||||
{
|
||||
return TimelineCoordinate(SceneToTime(pt.x()), TrackReference(type_, SceneToTrack(pt.y())));
|
||||
}
|
||||
|
||||
int TimelineView::GetTrackY(int track_index)
|
||||
{
|
||||
int y = 0;
|
||||
|
||||
for (int i=0;i<track_index;i++) {
|
||||
y += GetTrackHeight(i);
|
||||
}
|
||||
|
||||
if (alignment() & Qt::AlignBottom) {
|
||||
y = -y - GetTrackHeight(0);
|
||||
}
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
int TimelineView::GetTrackHeight(int track_index)
|
||||
{
|
||||
// FIXME: Make this adjustable
|
||||
Q_UNUSED(track_index)
|
||||
|
||||
return fontMetrics().height() * 3;
|
||||
}
|
||||
|
||||
int TimelineView::SceneToTrack(double y)
|
||||
{
|
||||
int track = -1;
|
||||
int heights = 0;
|
||||
|
||||
if (alignment() & Qt::AlignBottom) {
|
||||
y = -y;
|
||||
}
|
||||
|
||||
do {
|
||||
track++;
|
||||
heights += GetTrackHeight(track);
|
||||
} while (y > heights);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
void TimelineView::UserSetTime(const int64_t &time)
|
||||
{
|
||||
SetTime(time);
|
||||
emit TimeChanged(time);
|
||||
}
|
||||
|
||||
rational TimelineView::GetPlayheadTime()
|
||||
{
|
||||
return rational(playhead_ * timebase().numerator(), timebase().denominator());
|
||||
}
|
||||
|
||||
void TimelineView::UpdateSceneRect()
|
||||
{
|
||||
QRectF bounding_rect = scene_.itemsBoundingRect();
|
||||
|
||||
// Ensure the scene height is always AT LEAST the height of the view
|
||||
// The scrollbar appears to have a 1px margin on the top and bottom, hence the -2
|
||||
int minimum_height = height() - horizontalScrollBar()->height() - 2;
|
||||
|
||||
if (alignment() & Qt::AlignBottom) {
|
||||
// Ensure the scene left and bottom are always 0
|
||||
bounding_rect.setBottomLeft(QPointF(0, 0));
|
||||
|
||||
if (bounding_rect.top() > minimum_height) {
|
||||
bounding_rect.setTop(-minimum_height);
|
||||
}
|
||||
} else {
|
||||
// Ensure the scene left and top are always 0
|
||||
bounding_rect.setTopLeft(QPointF(0, 0));
|
||||
|
||||
if (bounding_rect.height() < minimum_height) {
|
||||
bounding_rect.setHeight(minimum_height);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
|
||||
end_item_->SetEndPadding(width()/4);
|
||||
|
||||
// If the scene is already this rect, do nothing
|
||||
if (scene_.sceneRect() == bounding_rect) {
|
||||
return;
|
||||
}
|
||||
|
||||
scene_.setSceneRect(bounding_rect);
|
||||
}
|
||||
|
||||
void TimelineView::SetEndTime(const rational &length)
|
||||
{
|
||||
end_item_->SetEndTime(length);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEVIEW_H
|
||||
#define TIMELINEVIEW_H
|
||||
|
||||
#include <QGraphicsView>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragMoveEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include <QDropEvent>
|
||||
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "node/output/timeline/timeline.h"
|
||||
#include "timelineplayhead.h"
|
||||
#include "timelineviewblockitem.h"
|
||||
#include "timelineviewmouseevent.h"
|
||||
#include "timelineviewenditem.h"
|
||||
#include "timelineviewghostitem.h"
|
||||
#include "widget/timelinewidget/undo/undo.h"
|
||||
#include "undo/undostack.h"
|
||||
|
||||
/**
|
||||
* @brief A widget for viewing and interacting Sequences
|
||||
*
|
||||
* This widget primarily exposes users to viewing and modifying Block nodes, usually through a TimelineOutput node.
|
||||
*/
|
||||
class TimelineView : public QGraphicsView, public TimelineScaledObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TimelineView(const TrackType& type,
|
||||
Qt::Alignment vertical_alignment = Qt::AlignTop,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
void SetScale(const double& scale);
|
||||
|
||||
void SelectAll();
|
||||
|
||||
void DeselectAll();
|
||||
|
||||
void SetEndTime(const rational& length);
|
||||
|
||||
int GetTrackY(int track_index);
|
||||
int GetTrackHeight(int track_index);
|
||||
|
||||
public slots:
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
void SetTime(const int64_t time);
|
||||
|
||||
signals:
|
||||
void ScaleChanged(double scale);
|
||||
|
||||
void TimeChanged(const int64_t& time);
|
||||
|
||||
void MousePressed(TimelineViewMouseEvent* event);
|
||||
void MouseMoved(TimelineViewMouseEvent* event);
|
||||
void MouseReleased(TimelineViewMouseEvent* event);
|
||||
void MouseDoubleClicked(TimelineViewMouseEvent* event);
|
||||
|
||||
void DragEntered(TimelineViewMouseEvent* event);
|
||||
void DragMoved(TimelineViewMouseEvent* event);
|
||||
void DragLeft(QDragLeaveEvent* event);
|
||||
void DragDropped(TimelineViewMouseEvent* event);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event) override;
|
||||
virtual void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
virtual void dropEvent(QDropEvent *event) override;
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
private:
|
||||
TrackType ConnectedTrackType();
|
||||
Stream::Type TrackTypeToStreamType(TrackType track_type);
|
||||
|
||||
TimelineCoordinate ScreenToCoordinate(const QPoint& pt);
|
||||
TimelineCoordinate SceneToCoordinate(const QPointF& pt);
|
||||
|
||||
int SceneToTrack(double y);
|
||||
|
||||
void UserSetTime(const int64_t& time);
|
||||
|
||||
QGraphicsScene scene_;
|
||||
|
||||
int64_t playhead_;
|
||||
|
||||
QVector<int> track_heights_;
|
||||
|
||||
TimelineViewEndItem* end_item_;
|
||||
|
||||
TimelinePlayhead playhead_style_;
|
||||
|
||||
rational GetPlayheadTime();
|
||||
|
||||
void UpdatePlayheadRect();
|
||||
|
||||
QRect playhead_rect_;
|
||||
|
||||
TrackType type_;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes
|
||||
*/
|
||||
void UpdateSceneRect();
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEW_H
|
||||
@@ -0,0 +1,111 @@
|
||||
/***
|
||||
|
||||
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 "timelineviewblockitem.h"
|
||||
|
||||
#include <QBrush>
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
TimelineViewBlockItem::TimelineViewBlockItem(QGraphicsItem* parent) :
|
||||
TimelineViewRect(parent),
|
||||
block_(nullptr)
|
||||
{
|
||||
setBrush(Qt::white);
|
||||
}
|
||||
|
||||
Block *TimelineViewBlockItem::block()
|
||||
{
|
||||
return block_;
|
||||
}
|
||||
|
||||
void TimelineViewBlockItem::SetBlock(Block *block)
|
||||
{
|
||||
block_ = block;
|
||||
|
||||
setFlag(QGraphicsItem::ItemIsSelectable, block_->type() == Block::kClip);
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewBlockItem::UpdateRect()
|
||||
{
|
||||
if (block_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
double item_left = TimeToScene(block_->in());
|
||||
double item_width = TimeToScene(block_->length());
|
||||
|
||||
// -1 on width and height so we don't overlap any adjacent clips
|
||||
setRect(0, y_, item_width - 1, height_ - 1);
|
||||
setPos(item_left, 0.0);
|
||||
|
||||
// FIXME: Untranslated
|
||||
setToolTip(QString("%1\n\nIn: %2\nOut: %3\nMedia In: %4").arg(block_->Name(),
|
||||
QString::number(block_->in().toDouble()),
|
||||
QString::number(block_->out().toDouble()),
|
||||
QString::number(block_->media_in().toDouble())));
|
||||
}
|
||||
|
||||
void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
Q_UNUSED(widget)
|
||||
|
||||
if (block_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (block_->type()) {
|
||||
case Block::kClip:
|
||||
/*QLinearGradient grad;
|
||||
grad.setStart(0, rect().top());
|
||||
grad.setFinalStop(0, rect().bottom());
|
||||
grad.setColorAt(0.0, QColor(160, 160, 240));
|
||||
grad.setColorAt(1.0, QColor(128, 128, 192));
|
||||
painter->fillRect(rect(), grad);*/
|
||||
painter->fillRect(rect(), QColor(128, 128, 192));
|
||||
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
painter->fillRect(rect(), QColor(0, 0, 0, 64));
|
||||
}
|
||||
|
||||
painter->setPen(Qt::white);
|
||||
painter->drawLine(rect().topLeft(), QPointF(rect().right(), rect().top()));
|
||||
painter->drawLine(rect().topLeft(), QPointF(rect().left(), rect().bottom() - 1));
|
||||
|
||||
painter->drawText(rect(), static_cast<int>(Qt::AlignLeft | Qt::AlignTop), block_->block_name());
|
||||
|
||||
painter->setPen(QColor(64, 64, 64));
|
||||
painter->drawLine(QPointF(rect().left(), rect().bottom() - 1), QPointF(rect().right(), rect().bottom() - 1));
|
||||
painter->drawLine(QPointF(rect().right(), rect().bottom() - 1), QPointF(rect().right(), rect().top()));
|
||||
break;
|
||||
case Block::kGap:
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
// FIXME: Make this palette or CSS
|
||||
painter->fillRect(rect(), Qt::white);
|
||||
}
|
||||
break;
|
||||
case Block::kEnd:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEVIEWCLIPITEM_H
|
||||
#define TIMELINEVIEWCLIPITEM_H
|
||||
|
||||
#include "timelineviewrect.h"
|
||||
#include "node/block/clip/clip.h"
|
||||
|
||||
/**
|
||||
* @brief A graphical representation of a ClipBlock
|
||||
*/
|
||||
class TimelineViewBlockItem : public TimelineViewRect
|
||||
{
|
||||
public:
|
||||
TimelineViewBlockItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
Block* block();
|
||||
void SetBlock(Block *block);
|
||||
|
||||
virtual void UpdateRect() override;
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||
|
||||
private:
|
||||
Block* block_;
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWCLIPITEM_H
|
||||
@@ -0,0 +1,37 @@
|
||||
#include "timelineviewenditem.h"
|
||||
|
||||
TimelineViewEndItem::TimelineViewEndItem(QGraphicsItem *parent) :
|
||||
TimelineViewRect(parent),
|
||||
end_padding_(0)
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineViewEndItem::SetEndTime(const rational &time)
|
||||
{
|
||||
end_time_ = time;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewEndItem::SetEndPadding(int padding)
|
||||
{
|
||||
end_padding_ = padding;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewEndItem::UpdateRect()
|
||||
{
|
||||
// Doesn't need to be more than one pixel
|
||||
setRect(0, 0, 1, 1);
|
||||
|
||||
setPos(TimeToScene(end_time_) + end_padding_, 0);
|
||||
}
|
||||
|
||||
void TimelineViewEndItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
// Item is invisible, this is a no-op
|
||||
Q_UNUSED(painter)
|
||||
Q_UNUSED(option)
|
||||
Q_UNUSED(widget)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef TIMELINEVIEWENDITEM_H
|
||||
#define TIMELINEVIEWENDITEM_H
|
||||
|
||||
#include "timelineviewrect.h"
|
||||
|
||||
/**
|
||||
* @brief An item placed at the end point of the Timeline to ensure the correct scene size
|
||||
*/
|
||||
class TimelineViewEndItem : public TimelineViewRect
|
||||
{
|
||||
public:
|
||||
TimelineViewEndItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
void SetEndTime(const rational& time);
|
||||
|
||||
void SetEndPadding(int padding);
|
||||
|
||||
virtual void UpdateRect() override;
|
||||
|
||||
protected:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
|
||||
|
||||
private:
|
||||
rational end_time_;
|
||||
|
||||
int end_padding_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWENDITEM_H
|
||||
@@ -0,0 +1,194 @@
|
||||
/***
|
||||
|
||||
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 "timelineviewghostitem.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) :
|
||||
TimelineViewRect(parent),
|
||||
track_adj_(0),
|
||||
stream_(nullptr),
|
||||
mode_(olive::timeline::kNone),
|
||||
can_have_zero_length_(true)
|
||||
{
|
||||
SetInvisible(false);
|
||||
}
|
||||
|
||||
TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track, int y, int height)
|
||||
{
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
ghost->SetIn(block->in());
|
||||
ghost->SetOut(block->out());
|
||||
ghost->SetMediaIn(block->media_in());
|
||||
ghost->SetTrack(track);
|
||||
ghost->SetYCoords(y, height);
|
||||
ghost->setData(kAttachedBlock, Node::PtrToValue(block));
|
||||
|
||||
if (block->type() == Block::kClip) {
|
||||
ghost->can_have_zero_length_ = false;
|
||||
}
|
||||
|
||||
return ghost;
|
||||
}
|
||||
|
||||
bool TimelineViewGhostItem::CanHaveZeroLength()
|
||||
{
|
||||
return can_have_zero_length_;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetInvisible(bool invisible)
|
||||
{
|
||||
setBrush(Qt::NoBrush);
|
||||
|
||||
if (invisible) {
|
||||
setPen(Qt::NoPen);
|
||||
} else {
|
||||
setPen(QPen(Qt::yellow, 2)); // FIXME: Make customizable via CSS
|
||||
}
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::In() const
|
||||
{
|
||||
return in_;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::Out() const
|
||||
{
|
||||
return out_;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::MediaIn() const
|
||||
{
|
||||
return media_in_;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::Length() const
|
||||
{
|
||||
return out_ - in_;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::AdjustedLength() const
|
||||
{
|
||||
return GetAdjustedOut() - GetAdjustedIn();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetIn(const rational &in)
|
||||
{
|
||||
in_ = in;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetOut(const rational &out)
|
||||
{
|
||||
out_ = out;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetMediaIn(const rational &media_in)
|
||||
{
|
||||
media_in_ = media_in;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetInAdjustment(const rational &in_adj)
|
||||
{
|
||||
in_adj_ = in_adj;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetOutAdjustment(const rational &out_adj)
|
||||
{
|
||||
out_adj_ = out_adj;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj)
|
||||
{
|
||||
track_adj_ = track_adj;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetMediaInAdjustment(const rational &media_in_adj)
|
||||
{
|
||||
media_in_adj_ = media_in_adj;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::InAdjustment() const
|
||||
{
|
||||
return in_adj_;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::OutAdjustment() const
|
||||
{
|
||||
return out_adj_;
|
||||
}
|
||||
|
||||
const rational &TimelineViewGhostItem::MediaInAdjustment() const
|
||||
{
|
||||
return media_in_adj_;
|
||||
}
|
||||
|
||||
const int &TimelineViewGhostItem::TrackAdjustment() const
|
||||
{
|
||||
return track_adj_;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::GetAdjustedIn() const
|
||||
{
|
||||
return in_ + in_adj_;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::GetAdjustedOut() const
|
||||
{
|
||||
return out_ + out_adj_;
|
||||
}
|
||||
|
||||
rational TimelineViewGhostItem::GetAdjustedMediaIn() const
|
||||
{
|
||||
return media_in_ + media_in_adj_;
|
||||
}
|
||||
|
||||
TrackReference TimelineViewGhostItem::GetAdjustedTrack() const
|
||||
{
|
||||
return TrackReference(track_.type(), track_.index() + track_adj_);
|
||||
}
|
||||
|
||||
const olive::timeline::MovementMode &TimelineViewGhostItem::mode() const
|
||||
{
|
||||
return mode_;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::SetMode(const olive::timeline::MovementMode &mode)
|
||||
{
|
||||
mode_ = mode;
|
||||
}
|
||||
|
||||
void TimelineViewGhostItem::UpdateRect()
|
||||
{
|
||||
rational length = GetAdjustedOut() - GetAdjustedIn();
|
||||
|
||||
setRect(0, y_, TimeToScene(length), height_ - 1);
|
||||
|
||||
setPos(TimeToScene(GetAdjustedIn()), 0);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEVIEWGHOSTITEM_H
|
||||
#define TIMELINEVIEWGHOSTITEM_H
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
#include "common/timelinecommon.h"
|
||||
#include "project/item/footage/footage.h"
|
||||
#include "timelineviewblockitem.h"
|
||||
#include "timelineviewrect.h"
|
||||
|
||||
/**
|
||||
* @brief A graphical representation of changes the user is making before they apply it
|
||||
*/
|
||||
class TimelineViewGhostItem : public TimelineViewRect
|
||||
{
|
||||
public:
|
||||
enum DataType {
|
||||
kAttachedBlock,
|
||||
kReferenceBlock,
|
||||
kAttachedFootage
|
||||
};
|
||||
|
||||
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
|
||||
|
||||
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height);
|
||||
|
||||
bool CanHaveZeroLength();
|
||||
|
||||
void SetInvisible(bool invisible);
|
||||
|
||||
const rational& In() const;
|
||||
const rational& Out() const;
|
||||
const rational& MediaIn() const;
|
||||
|
||||
rational Length() const;
|
||||
rational AdjustedLength() const;
|
||||
|
||||
void SetIn(const rational& in);
|
||||
void SetOut(const rational& out);
|
||||
void SetMediaIn(const rational& media_in);
|
||||
|
||||
void SetInAdjustment(const rational& in_adj);
|
||||
void SetOutAdjustment(const rational& out_adj);
|
||||
void SetTrackAdjustment(const int& track_adj);
|
||||
void SetMediaInAdjustment(const rational& media_in_adj);
|
||||
|
||||
const rational& InAdjustment() const;
|
||||
const rational& OutAdjustment() const;
|
||||
const rational& MediaInAdjustment() const;
|
||||
const int& TrackAdjustment() const;
|
||||
|
||||
rational GetAdjustedIn() const;
|
||||
rational GetAdjustedOut() const;
|
||||
rational GetAdjustedMediaIn() const;
|
||||
TrackReference GetAdjustedTrack() const;
|
||||
|
||||
const olive::timeline::MovementMode& mode() const;
|
||||
void SetMode(const olive::timeline::MovementMode& mode);
|
||||
|
||||
virtual void UpdateRect() override;
|
||||
|
||||
protected:
|
||||
|
||||
private:
|
||||
rational in_;
|
||||
rational out_;
|
||||
rational media_in_;
|
||||
|
||||
rational in_adj_;
|
||||
rational out_adj_;
|
||||
rational media_in_adj_;
|
||||
|
||||
int track_adj_;
|
||||
|
||||
StreamPtr stream_;
|
||||
|
||||
olive::timeline::MovementMode mode_;
|
||||
|
||||
bool can_have_zero_length_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWGHOSTITEM_H
|
||||
@@ -0,0 +1,79 @@
|
||||
/***
|
||||
|
||||
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 "timelineviewmouseevent.h"
|
||||
|
||||
#include <QEvent>
|
||||
|
||||
TimelineViewMouseEvent::TimelineViewMouseEvent(const TimelineCoordinate &coord,
|
||||
const Qt::KeyboardModifiers &modifiers) :
|
||||
coord_(coord),
|
||||
modifiers_(modifiers),
|
||||
source_event_(nullptr),
|
||||
mime_data_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
TimelineViewMouseEvent::TimelineViewMouseEvent(const rational &frame,
|
||||
const TrackReference &track,
|
||||
const Qt::KeyboardModifiers &modifiers) :
|
||||
coord_(frame, track),
|
||||
modifiers_(modifiers),
|
||||
source_event_(nullptr),
|
||||
mime_data_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
const TimelineCoordinate &TimelineViewMouseEvent::GetCoordinates()
|
||||
{
|
||||
return coord_;
|
||||
}
|
||||
|
||||
const Qt::KeyboardModifiers TimelineViewMouseEvent::GetModifiers()
|
||||
{
|
||||
return modifiers_;
|
||||
}
|
||||
|
||||
const QMimeData* TimelineViewMouseEvent::GetMimeData()
|
||||
{
|
||||
return mime_data_;
|
||||
}
|
||||
|
||||
void TimelineViewMouseEvent::SetMimeData(const QMimeData *data)
|
||||
{
|
||||
mime_data_ = data;
|
||||
}
|
||||
|
||||
void TimelineViewMouseEvent::SetEvent(QEvent *event)
|
||||
{
|
||||
source_event_ = event;
|
||||
}
|
||||
|
||||
void TimelineViewMouseEvent::accept()
|
||||
{
|
||||
if (source_event_ != nullptr)
|
||||
source_event_->accept();
|
||||
}
|
||||
|
||||
void TimelineViewMouseEvent::ignore()
|
||||
{
|
||||
if (source_event_ != nullptr)
|
||||
source_event_->ignore();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEVIEWMOUSEEVENT_H
|
||||
#define TIMELINEVIEWMOUSEEVENT_H
|
||||
|
||||
#include <QMimeData>
|
||||
#include <QPointF>
|
||||
#include <QPoint>
|
||||
|
||||
#include "timeline/timelinecoordinate.h"
|
||||
|
||||
class TimelineViewMouseEvent
|
||||
{
|
||||
public:
|
||||
TimelineViewMouseEvent(const TimelineCoordinate& coord,
|
||||
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier);
|
||||
|
||||
TimelineViewMouseEvent(const rational& frame,
|
||||
const TrackReference &track,
|
||||
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier);
|
||||
|
||||
const TimelineCoordinate& GetCoordinates();
|
||||
const Qt::KeyboardModifiers GetModifiers();
|
||||
|
||||
const QMimeData *GetMimeData();
|
||||
void SetMimeData(const QMimeData *data);
|
||||
|
||||
void SetEvent(QEvent* event);
|
||||
|
||||
void accept();
|
||||
void ignore();
|
||||
|
||||
private:
|
||||
TimelineCoordinate coord_;
|
||||
|
||||
Qt::KeyboardModifiers modifiers_;
|
||||
|
||||
QEvent* source_event_;
|
||||
|
||||
const QMimeData* mime_data_;
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWMOUSEEVENT_H
|
||||
@@ -0,0 +1,54 @@
|
||||
/***
|
||||
|
||||
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 "timelineviewrect.h"
|
||||
|
||||
TimelineViewRect::TimelineViewRect(QGraphicsItem* parent) :
|
||||
QGraphicsRectItem(parent),
|
||||
y_(0),
|
||||
height_(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TimelineViewRect::SetYCoords(int y, int height)
|
||||
{
|
||||
y_ = y;
|
||||
height_ = height;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
const TrackReference &TimelineViewRect::Track()
|
||||
{
|
||||
return track_;
|
||||
}
|
||||
|
||||
void TimelineViewRect::SetTrack(const TrackReference &track)
|
||||
{
|
||||
track_ = track;
|
||||
}
|
||||
|
||||
void TimelineViewRect::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/***
|
||||
|
||||
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/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef TIMELINEVIEWRECT_H
|
||||
#define TIMELINEVIEWRECT_H
|
||||
|
||||
#include <QGraphicsRectItem>
|
||||
|
||||
#include "timeline/timelinecoordinate.h"
|
||||
#include "../timelinescaledobject.h"
|
||||
|
||||
/**
|
||||
* @brief A base class for graphical representations of Block nodes
|
||||
*/
|
||||
class TimelineViewRect : public QGraphicsRectItem, public TimelineScaledObject
|
||||
{
|
||||
public:
|
||||
TimelineViewRect(QGraphicsItem* parent = nullptr);
|
||||
|
||||
void SetYCoords(int y, int height);
|
||||
|
||||
const TrackReference& Track();
|
||||
void SetTrack(const TrackReference& track);
|
||||
|
||||
void SetScale(const double& scale);
|
||||
|
||||
virtual void UpdateRect() = 0;
|
||||
|
||||
protected:
|
||||
int y_;
|
||||
|
||||
int height_;
|
||||
|
||||
TrackReference track_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWRECT_H
|
||||
Reference in New Issue
Block a user