timeline: implemented adding objects in the timeline (e.g. solid, title)
This commit is contained in:
+13
-2
@@ -63,6 +63,7 @@ Core Core::instance_;
|
|||||||
Core::Core() :
|
Core::Core() :
|
||||||
main_window_(nullptr),
|
main_window_(nullptr),
|
||||||
tool_(Tool::kPointer),
|
tool_(Tool::kPointer),
|
||||||
|
addable_object_(Tool::kAddableEmpty),
|
||||||
snapping_(true),
|
snapping_(true),
|
||||||
queue_autorecovery_(false)
|
queue_autorecovery_(false)
|
||||||
{
|
{
|
||||||
@@ -187,12 +188,22 @@ void Core::ImportFiles(const QStringList &urls, ProjectViewModel* model, Folder*
|
|||||||
task_dialog->open();
|
task_dialog->open();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tool::Item &Core::tool()
|
const Tool::Item &Core::tool() const
|
||||||
{
|
{
|
||||||
return tool_;
|
return tool_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool &Core::snapping()
|
const Tool::AddableObject &Core::selected_addable_object() const
|
||||||
|
{
|
||||||
|
return addable_object_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Core::SetSelectedAddableObject(const Tool::AddableObject &obj)
|
||||||
|
{
|
||||||
|
addable_object_ = obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool &Core::snapping() const
|
||||||
{
|
{
|
||||||
return snapping_;
|
return snapping_;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-3
@@ -105,12 +105,17 @@ public:
|
|||||||
/**
|
/**
|
||||||
* @brief Get the currently active tool
|
* @brief Get the currently active tool
|
||||||
*/
|
*/
|
||||||
const Tool::Item& tool();
|
const Tool::Item& tool() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the currently selected object that the add tool should make (if the add tool is active)
|
||||||
|
*/
|
||||||
|
const Tool::AddableObject& selected_addable_object() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get current snapping value
|
* @brief Get current snapping value
|
||||||
*/
|
*/
|
||||||
const bool& snapping();
|
const bool& snapping() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the currently active project
|
* @brief Get the currently active project
|
||||||
@@ -264,6 +269,11 @@ public slots:
|
|||||||
*/
|
*/
|
||||||
void CreateNewSequence();
|
void CreateNewSequence();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the currently selected object that the add tool should make
|
||||||
|
*/
|
||||||
|
void SetSelectedAddableObject(const Tool::AddableObject& obj);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
/**
|
/**
|
||||||
* @brief Signal emitted when a project is opened
|
* @brief Signal emitted when a project is opened
|
||||||
@@ -345,7 +355,12 @@ private:
|
|||||||
Tool::Item tool_;
|
Tool::Item tool_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Current snapping toggle
|
* @brief Currently active addable object
|
||||||
|
*/
|
||||||
|
Tool::AddableObject addable_object_;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Current snapping setting
|
||||||
*/
|
*/
|
||||||
bool snapping_;
|
bool snapping_;
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ ToolPanel::ToolPanel(QWidget *parent) :
|
|||||||
|
|
||||||
setWidget(t);
|
setWidget(t);
|
||||||
|
|
||||||
connect(t, SIGNAL(ToolChanged(const Tool::Item&)), Core::instance(), SLOT(SetTool(const Tool::Item&)));
|
connect(t, &Toolbar::ToolChanged, Core::instance(), &Core::SetTool);
|
||||||
connect(Core::instance(), SIGNAL(ToolChanged(const Tool::Item&)), t, SLOT(SetTool(const Tool::Item&)));
|
connect(Core::instance(), &Core::ToolChanged, t, &Toolbar::SetTool);
|
||||||
|
|
||||||
connect(t, SIGNAL(SnappingChanged(const bool&)), Core::instance(), SLOT(SetSnapping(const bool&)));
|
connect(t, &Toolbar::SnappingChanged, Core::instance(), &Core::SetSnapping);
|
||||||
connect(Core::instance(), SIGNAL(SnappingChanged(const bool&)), t, SLOT(SetSnapping(const bool&)));
|
connect(Core::instance(), &Core::SnappingChanged, t, &Toolbar::SetSnapping);
|
||||||
|
|
||||||
|
connect(t, &Toolbar::AddableObjectChanged, Core::instance(), &Core::SetSelectedAddableObject);
|
||||||
|
|
||||||
Retranslate();
|
Retranslate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@
|
|||||||
#ifndef TOOL_H
|
#ifndef TOOL_H
|
||||||
#define TOOL_H
|
#define TOOL_H
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class Tool {
|
class Tool {
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +72,49 @@ public:
|
|||||||
|
|
||||||
kCount
|
kCount
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tools that can be added using the kAdd tool
|
||||||
|
*/
|
||||||
|
enum AddableObject {
|
||||||
|
/// An empty clip
|
||||||
|
kAddableEmpty,
|
||||||
|
|
||||||
|
/// A video clip showing a generic video placeholder
|
||||||
|
kAddableBars,
|
||||||
|
|
||||||
|
/// A video clip with a solid connected
|
||||||
|
kAddableSolid,
|
||||||
|
|
||||||
|
/// A video clip with a title connected
|
||||||
|
kAddableTitle,
|
||||||
|
|
||||||
|
/// An audio clip with a sine connected to it
|
||||||
|
kAddableTone,
|
||||||
|
|
||||||
|
kAddableCount
|
||||||
|
};
|
||||||
|
|
||||||
|
static QString GetAddableObjectName(const AddableObject& a)
|
||||||
|
{
|
||||||
|
switch (a) {
|
||||||
|
case kAddableEmpty:
|
||||||
|
return QCoreApplication::translate("Tool", "Empty");
|
||||||
|
case kAddableBars:
|
||||||
|
return QCoreApplication::translate("Tool", "Bars");
|
||||||
|
case kAddableSolid:
|
||||||
|
return QCoreApplication::translate("Tool", "Solid");
|
||||||
|
case kAddableTitle:
|
||||||
|
return QCoreApplication::translate("Tool", "Title");
|
||||||
|
case kAddableTone:
|
||||||
|
return QCoreApplication::translate("Tool", "Tone");
|
||||||
|
case kAddableCount:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QCoreApplication::translate("Tool", "Unknown");
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOL_H
|
#endif // TOOL_H
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "widget/timelinewidget/timelinewidget.h"
|
#include "widget/timelinewidget/timelinewidget.h"
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "node/factory.h"
|
||||||
#include "widget/nodeview/nodeviewundo.h"
|
#include "widget/nodeview/nodeviewundo.h"
|
||||||
|
|
||||||
TimelineWidget::AddTool::AddTool(TimelineWidget *parent) :
|
TimelineWidget::AddTool::AddTool(TimelineWidget *parent) :
|
||||||
@@ -18,16 +19,37 @@ void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
drag_start_point_ = event->GetFrame();
|
Timeline::TrackType add_type = Timeline::kTrackTypeNone;
|
||||||
|
|
||||||
ghost_ = new TimelineViewGhostItem();
|
switch (Core::instance()->selected_addable_object()) {
|
||||||
ghost_->SetIn(drag_start_point_);
|
case ::Tool::kAddableBars:
|
||||||
ghost_->SetOut(drag_start_point_);
|
case ::Tool::kAddableSolid:
|
||||||
ghost_->SetTrack(track);
|
case ::Tool::kAddableTitle:
|
||||||
ghost_->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
|
add_type = Timeline::kTrackTypeVideo;
|
||||||
parent()->AddGhost(ghost_);
|
break;
|
||||||
|
case ::Tool::kAddableTone:
|
||||||
|
add_type = Timeline::kTrackTypeAudio;
|
||||||
|
break;
|
||||||
|
case ::Tool::kAddableEmpty:
|
||||||
|
// Leave as "none", which means this block can be placed on any track
|
||||||
|
break;
|
||||||
|
case ::Tool::kAddableCount:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
snap_points_.append(drag_start_point_);
|
if (add_type == Timeline::kTrackTypeNone
|
||||||
|
|| add_type == track.type()) {
|
||||||
|
drag_start_point_ = event->GetFrame();
|
||||||
|
|
||||||
|
ghost_ = new TimelineViewGhostItem();
|
||||||
|
ghost_->SetIn(drag_start_point_);
|
||||||
|
ghost_->SetOut(drag_start_point_);
|
||||||
|
ghost_->SetTrack(track);
|
||||||
|
ghost_->SetYCoords(parent()->GetTrackY(track), parent()->GetTrackHeight(track));
|
||||||
|
parent()->AddGhost(ghost_);
|
||||||
|
|
||||||
|
snap_points_.append(drag_start_point_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimelineWidget::AddTool::MouseMove(TimelineViewMouseEvent *event)
|
void TimelineWidget::AddTool::MouseMove(TimelineViewMouseEvent *event)
|
||||||
@@ -51,7 +73,11 @@ void TimelineWidget::AddTool::MouseRelease(TimelineViewMouseEvent *event)
|
|||||||
|
|
||||||
ClipBlock* clip = new ClipBlock();
|
ClipBlock* clip = new ClipBlock();
|
||||||
clip->set_length_and_media_out(ghost_->AdjustedLength());
|
clip->set_length_and_media_out(ghost_->AdjustedLength());
|
||||||
new NodeAddCommand(static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent()),
|
clip->set_block_name(::Tool::GetAddableObjectName(Core::instance()->selected_addable_object()));
|
||||||
|
|
||||||
|
NodeGraph* graph = static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent());
|
||||||
|
|
||||||
|
new NodeAddCommand(graph,
|
||||||
clip,
|
clip,
|
||||||
command);
|
command);
|
||||||
|
|
||||||
@@ -61,6 +87,32 @@ void TimelineWidget::AddTool::MouseRelease(TimelineViewMouseEvent *event)
|
|||||||
ghost_->GetAdjustedIn(),
|
ghost_->GetAdjustedIn(),
|
||||||
command);
|
command);
|
||||||
|
|
||||||
|
switch (Core::instance()->selected_addable_object()) {
|
||||||
|
case ::Tool::kAddableEmpty:
|
||||||
|
// Empty, nothing to be done
|
||||||
|
break;
|
||||||
|
case ::Tool::kAddableSolid:
|
||||||
|
{
|
||||||
|
Node* solid = NodeFactory::CreateFromID(QStringLiteral("org.olivevideoeditor.Olive.solidgenerator"));
|
||||||
|
|
||||||
|
new NodeAddCommand(graph,
|
||||||
|
solid,
|
||||||
|
command);
|
||||||
|
|
||||||
|
new NodeEdgeAddCommand(solid->output(), clip->texture_input(), command);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ::Tool::kAddableBars:
|
||||||
|
case ::Tool::kAddableTitle:
|
||||||
|
case ::Tool::kAddableTone:
|
||||||
|
// Not implemented yet
|
||||||
|
qWarning() << "Unimplemented add object:" << Core::instance()->selected_addable_object();
|
||||||
|
break;
|
||||||
|
case ::Tool::kAddableCount:
|
||||||
|
// Invalid value, do nothing
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
Core::instance()->undo_stack()->push(command);
|
Core::instance()->undo_stack()->push(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <QButtonGroup>
|
#include <QButtonGroup>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
|
||||||
|
#include "widget/menu/menu.h"
|
||||||
#include "ui/icons/icons.h"
|
#include "ui/icons/icons.h"
|
||||||
|
|
||||||
Toolbar::Toolbar(QWidget *parent) :
|
Toolbar::Toolbar(QWidget *parent) :
|
||||||
@@ -49,7 +50,10 @@ Toolbar::Toolbar(QWidget *parent) :
|
|||||||
|
|
||||||
// Create snapping button, which is not actually a tool, it's a toggle option
|
// Create snapping button, which is not actually a tool, it's a toggle option
|
||||||
btn_snapping_toggle_ = CreateNonToolButton();
|
btn_snapping_toggle_ = CreateNonToolButton();
|
||||||
connect(btn_snapping_toggle_, SIGNAL(clicked(bool)), this, SLOT(SnappingButtonClicked(bool)));
|
connect(btn_snapping_toggle_, &QPushButton::clicked, this, &Toolbar::SnappingButtonClicked);
|
||||||
|
|
||||||
|
// Connect add button to menu signal
|
||||||
|
connect(btn_add_, &QPushButton::clicked, this, &Toolbar::AddButtonClicked);
|
||||||
|
|
||||||
Retranslate();
|
Retranslate();
|
||||||
UpdateIcons();
|
UpdateIcons();
|
||||||
@@ -160,3 +164,22 @@ void Toolbar::SnappingButtonClicked(bool b)
|
|||||||
{
|
{
|
||||||
emit SnappingChanged(b);
|
emit SnappingChanged(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Toolbar::AddButtonClicked()
|
||||||
|
{
|
||||||
|
QMenu m(this);
|
||||||
|
|
||||||
|
for (int i=0;i<Tool::kAddableCount;i++) {
|
||||||
|
QAction* action = m.addAction(Tool::GetAddableObjectName(static_cast<Tool::AddableObject>(i)));
|
||||||
|
action->setData(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(&m, &QMenu::triggered, this, &Toolbar::AddMenuItemTriggered);
|
||||||
|
|
||||||
|
m.exec(QCursor::pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Toolbar::AddMenuItemTriggered(QAction* a)
|
||||||
|
{
|
||||||
|
emit AddableObjectChanged(static_cast<Tool::AddableObject>(a->data().toInt()));
|
||||||
|
}
|
||||||
|
|||||||
@@ -106,6 +106,11 @@ signals:
|
|||||||
*/
|
*/
|
||||||
void SnappingChanged(const bool& b);
|
void SnappingChanged(const bool& b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Emitted when the addable object is changed from the add tool menu
|
||||||
|
*/
|
||||||
|
void AddableObjectChanged(const Tool::AddableObject& obj);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Reset all strings based on the currently selected language
|
* @brief Reset all strings based on the currently selected language
|
||||||
@@ -195,6 +200,19 @@ private slots:
|
|||||||
* The new snapping value received from the sender's clicked signal
|
* The new snapping value received from the sender's clicked signal
|
||||||
*/
|
*/
|
||||||
void SnappingButtonClicked(bool b);
|
void SnappingButtonClicked(bool b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receiver for the add button
|
||||||
|
*
|
||||||
|
* The add button pops up a list for which object to create.
|
||||||
|
*/
|
||||||
|
void AddButtonClicked();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Receiver for the menu created by AddButtonClicked()
|
||||||
|
*/
|
||||||
|
void AddMenuItemTriggered(QAction* a);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TOOLBAR_H
|
#endif // TOOLBAR_H
|
||||||
|
|||||||
Reference in New Issue
Block a user