timeline/various: implemented block copy/paste

Implemented the ability to copy/paste blocks/clips in the timeline. This did
require some large scale changes and reworking of the copy/paste system
introduced a few commits ago, but should be largely functional now.
This commit is contained in:
itsmattkc
2020-03-31 02:19:05 +11:00
parent 67d8ad571d
commit 2bda306866
35 changed files with 466 additions and 233 deletions
+4 -93
View File
@@ -513,103 +513,14 @@ void Core::SetAutorecoveryInterval(int minutes)
autorecovery_timer_.setInterval(minutes * 60000);
}
void Core::CopyNodesToClipboard(const QList<Node *> &nodes)
void Core::CopyStringToClipboard(const QString &s)
{
QString copy_str;
QXmlStreamWriter writer(&copy_str);
writer.setAutoFormatting(true);
writer.writeStartDocument();
writer.writeStartElement(QStringLiteral("olive"));
foreach (Node* n, nodes) {
n->Save(&writer);
}
writer.writeEndElement(); // clipboard
writer.writeEndDocument();
QGuiApplication::clipboard()->setText(copy_str);
QGuiApplication::clipboard()->setText(s);
}
QList<Node*> Core::PasteNodesFromClipboard(Sequence *graph)
QString Core::PasteStringFromClipboard()
{
QString clipboard = QGuiApplication::clipboard()->text();
if (clipboard.isEmpty()) {
return QList<Node*>();
}
QXmlStreamReader reader(clipboard);
QList<Node*> pasted_nodes;
QHash<quintptr, NodeOutput*> output_ptrs;
QList<NodeParam::SerializedConnection> desired_connections;
QList<NodeInput::FootageConnection> footage_connections;
while (XMLReadNextStartElement(&reader)) {
if (reader.name() == QStringLiteral("olive")) {
while (XMLReadNextStartElement(&reader)) {
if (reader.name() == QStringLiteral("node")) {
Node* node = XMLLoadNode(&reader);
if (node) {
node->Load(&reader, output_ptrs, desired_connections, footage_connections, nullptr);
graph->AddNode(node);
pasted_nodes.append(node);
}
} else {
reader.skipCurrentElement();
}
}
} else {
reader.skipCurrentElement();
}
}
// Make connections
if (!desired_connections.isEmpty()) {
XMLConnectNodes(output_ptrs, desired_connections);
}
// Connect footage to existing footage if it exists
if (!footage_connections.isEmpty()) {
// Get list of all footage from project
// FIXME: Assumes sequence
QList<ItemPtr> footage = graph->project()->get_items_of_type(Item::kFootage);
if (!footage.isEmpty()) {
foreach (const NodeInput::FootageConnection& con, footage_connections) {
if (con.footage) {
// Assume this is a pointer to a Stream*
Stream* loaded_stream = reinterpret_cast<Stream*>(con.footage);
bool found = false;
foreach (ItemPtr item, footage) {
const QList<StreamPtr>& streams = std::static_pointer_cast<Footage>(item)->streams();
foreach (StreamPtr s, streams) {
if (s.get() == loaded_stream) {
con.input->set_standard_value(QVariant::fromValue(s));
found = true;
break;
}
}
if (found) {
break;
}
}
}
}
}
}
return pasted_nodes;
return QGuiApplication::clipboard()->text();
}
bool Core::SaveActiveProject()