moved several files around

Mostly moved classes that became node derivatives into the node/ folder.
This commit is contained in:
itsmattkc
2021-04-08 12:15:59 +10:00
parent 2791e8d738
commit cb75e37e77
115 changed files with 159 additions and 128 deletions
+23
View File
@@ -0,0 +1,23 @@
# Olive - Non-Linear Video Editor
# Copyright (C) 2020 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}
node/project/folder/folder.h
node/project/folder/folder.cpp
PARENT_SCOPE
)
+158
View File
@@ -0,0 +1,158 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 "folder.h"
#include "common/xmlutils.h"
#include "node/project/footage/footage.h"
#include "node/project/sequence/sequence.h"
#include "ui/icons/icons.h"
namespace olive {
#define super Node
const QString Folder::kChildInput = QStringLiteral("child_in");
Folder::Folder()
{
AddInput(kChildInput, NodeValue::kNone, InputFlags(kInputFlagArray | kInputFlagNotKeyframable));
}
QIcon Folder::icon() const
{
return icon::Folder;
}
void Folder::Retranslate()
{
super::Retranslate();
SetInputName(kChildInput, tr("Children"));
}
bool ChildExistsWithNameInternal(const Folder* n, const QString& s)
{
for (int i=0; i<n->item_child_count(); i++) {
Node* child = n->item_child(i);
if (child->GetLabel() == s) {
return true;
} else {
Folder* subfolder = dynamic_cast<Folder*>(child);
if (subfolder && ChildExistsWithNameInternal(subfolder, s)) {
return true;
}
}
}
return false;
}
bool Folder::ChildExistsWithName(const QString &s) const
{
return ChildExistsWithNameInternal(this, s);
}
int Folder::index_of_child_in_array(Node *item) const
{
int index_of_item = item_children_.indexOf(item);
if (index_of_item == -1) {
return -1;
}
return item_element_index_.at(index_of_item);
}
void Folder::InputConnectedEvent(const QString &input, int element, const NodeOutput &output)
{
if (input == kChildInput && element != -1) {
Node* item = output.node();
// The insert index is always our "count" because we only support appending in our internal
// model. For sorting/organizing, a QSortFilterProxyModel is used instead.
emit BeginInsertItem(item, item_child_count());
item_children_.append(item);
item_element_index_.append(element);
item->SetFolder(this);
emit EndInsertItem();
}
}
void Folder::InputDisconnectedEvent(const QString &input, int element, const NodeOutput &output)
{
if (input == kChildInput && element != -1) {
Node* item = output.node();
int child_index = item_children_.indexOf(item);
emit BeginRemoveItem(item, child_index);
item_children_.removeAt(child_index);
item_element_index_.removeAt(child_index);
item->SetFolder(nullptr);
emit EndRemoveItem();
}
}
FolderAddChild::FolderAddChild(Folder *folder, Node *child, bool autoposition) :
folder_(folder),
child_(child),
autoposition_(autoposition),
position_command_(nullptr)
{
}
FolderAddChild::~FolderAddChild()
{
delete position_command_;
}
Project *FolderAddChild::GetRelevantProject() const
{
return folder_->project();
}
void FolderAddChild::redo()
{
int array_index = folder_->InputArraySize(Folder::kChildInput);
folder_->InputArrayAppend(Folder::kChildInput, false);
Node::ConnectEdge(child_, NodeInput(folder_, Folder::kChildInput, array_index));
if (autoposition_) {
old_position_ = child_->GetPosition();
if (!position_command_) {
position_command_ = new NodeSetPositionAsChildCommand(child_, folder_, array_index, array_index+1, true);
}
position_command_->redo();
}
}
void FolderAddChild::undo()
{
if (position_command_) {
position_command_->undo();
}
Node::DisconnectEdge(child_, NodeInput(folder_, Folder::kChildInput, folder_->InputArraySize(Folder::kChildInput)-1));
folder_->InputArrayRemoveLast(Folder::kChildInput);
}
}
+191
View File
@@ -0,0 +1,191 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 FOLDER_H
#define FOLDER_H
#include "node/node.h"
namespace olive {
/**
* @brief The Folder class representing a directory in a project structure
*
* The Item base class already has support for children, but this functionality is disabled by default
* (see CanHaveChildren() override). The Folder is a specific type that enables this functionality.
*/
class Folder : public Node
{
Q_OBJECT
public:
Folder();
NODE_DEFAULT_DESTRUCTOR(Folder)
virtual Node* copy() const override
{
return new Folder();
}
virtual QString Name() const override
{
return tr("Folder");
}
virtual QString id() const override
{
return QStringLiteral("org.olivevideoeditor.Olive.folder");
}
virtual QVector<CategoryID> Category() const override
{
return {kCategoryProject};
}
virtual QString Description() const override
{
return tr("Organize several items into a single collection.");
}
virtual QIcon icon() const override;
virtual void Retranslate() override;
bool ChildExistsWithName(const QString& s) const;
int item_child_count() const
{
return item_children_.size();
}
Node* item_child(int i) const
{
return item_children_.at(i);
}
const QVector<Node*>& children() const
{
return item_children_;
}
virtual bool IsItem() const override
{
return true;
}
int index_of_child(Node* item) const
{
return item_children_.indexOf(item);
}
int index_of_child_in_array(Node* item) const;
template <typename T>
QVector<T*> ListChildrenOfType() const
{
QVector<T*> list;
foreach (Node* node, item_children_) {
T* cast_test = dynamic_cast<T*>(node);
if (cast_test) {
list.append(cast_test);
}
}
return list;
}
static const QString kChildInput;
signals:
void BeginInsertItem(Node* n, int index);
void EndInsertItem();
void BeginRemoveItem(Node* n, int index);
void EndRemoveItem();
protected:
virtual void InputConnectedEvent(const QString& input, int element, const NodeOutput& output) override;
virtual void InputDisconnectedEvent(const QString& input, int element, const NodeOutput& output) override;
private:
template<typename T>
static void ListOutputsOfTypeInternal(const Folder* n, QVector<T*>& list, bool recursive)
{
foreach (const Node::OutputConnection& c, n->output_connections()) {
Node* connected = c.second.node();
T* cast_test = dynamic_cast<T*>(connected);
if (cast_test) {
// Avoid duplicates
if (!list.contains(cast_test)) {
list.append(cast_test);
}
}
if (recursive) {
Folder* subfolder = dynamic_cast<Folder*>(connected);
if (subfolder) {
ListOutputsOfTypeInternal(subfolder, list, recursive);
}
}
}
}
QVector<Node*> item_children_;
QVector<int> item_element_index_;
};
class FolderAddChild : public UndoCommand
{
public:
FolderAddChild(Folder* folder, Node* child, bool autoposition = true);
virtual ~FolderAddChild() override;
virtual Project * GetRelevantProject() const override;
virtual void redo() override;
virtual void undo() override;
private:
Folder* folder_;
Node* child_;
bool autoposition_;
QPointF old_position_;
NodeSetPositionAsChildCommand* position_command_;
};
}
#endif // FOLDER_H