moved timeline interactivity to separate classes
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 Olive Team
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "widget/timelineview/timelineview.h"
|
||||
|
||||
#include <QMimeData>
|
||||
|
||||
TimelineView::ImportTool::ImportTool(TimelineView *parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
|
||||
{
|
||||
QStringList mime_formats = event->mimeData()->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->mimeData()->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;
|
||||
|
||||
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);
|
||||
|
||||
StreamPtr stream = footage->stream(0);
|
||||
|
||||
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
|
||||
|
||||
rational footage_duration(stream->timebase().numerator() * stream->duration(),
|
||||
stream->timebase().denominator());
|
||||
|
||||
ghost->SetIn(0);
|
||||
ghost->SetOut(footage_duration);
|
||||
ghost->SetStream(stream);
|
||||
|
||||
parent()->AddGhost(ghost);
|
||||
}
|
||||
}
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
// FIXME: Implement dropping from file
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::ImportTool::DragMove(QDragMoveEvent *event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::ImportTool::DragLeave(QDragLeaveEvent *event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
parent()->ClearGhosts();
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::ImportTool::DragDrop(QDropEvent *event)
|
||||
{
|
||||
if (parent()->HasGhosts()) {
|
||||
parent()->ClearGhosts();
|
||||
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user