text: minor refactoring to make rect setting code more reusable

This commit is contained in:
itsmattkc
2022-05-13 08:41:22 -07:00
parent b63b792d5a
commit 07f92911cd
5 changed files with 54 additions and 36 deletions
@@ -25,6 +25,7 @@
#include "common/util.h"
#include "core.h"
#include "widget/nodeparamview/nodeparamviewundo.h"
namespace olive {
@@ -102,6 +103,21 @@ void ShapeNodeBase::UpdateGizmoPositions(const NodeValueRow &row, const NodeGlob
poly_gizmo_->SetPolygon(QRectF(left_pt, top_pt, right_pt - left_pt, bottom_pt - top_pt));
}
void ShapeNodeBase::SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command)
{
// Normalize around center of sequence
rect.translate(-sequence_res.width()*0.5, -sequence_res.height()*0.5);
rect.translate(rect.width()*0.5, rect.height()*0.5);
NodeInput pos(this, ShapeNodeBase::kPositionInput);
NodeInput sz(this, ShapeNodeBase::kSizeInput);
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 1), rect.y()));
}
void ShapeNodeBase::GizmoDragMove(double x, double y, const Qt::KeyboardModifiers &modifiers)
{
DraggableGizmo *gizmo = static_cast<DraggableGizmo*>(sender());
+2
View File
@@ -39,6 +39,8 @@ public:
virtual void UpdateGizmoPositions(const NodeValueRow &row, const NodeGlobals &globals) override;
void SetRect(QRectF rect, const VideoParams &sequence_res, MultiUndoCommand *command);
static const QString kPositionInput;
static const QString kSizeInput;
static const QString kColorInput;
+27 -29
View File
@@ -50,22 +50,22 @@ void AddTool::MousePress(TimelineViewMouseEvent *event)
Track::Type add_type = Track::kNone;
switch (Core::instance()->GetSelectedAddableObject()) {
case olive::Tool::kAddableBars:
case olive::Tool::kAddableSolid:
case olive::Tool::kAddableTitle:
case olive::Tool::kAddableShape:
case Tool::kAddableBars:
case Tool::kAddableSolid:
case Tool::kAddableTitle:
case Tool::kAddableShape:
add_type = Track::kVideo;
break;
case olive::Tool::kAddableTone:
case Tool::kAddableTone:
add_type = Track::kAudio;
break;
case olive::Tool::kAddableSubtitle:
case Tool::kAddableSubtitle:
add_type = Track::kSubtitle;
break;
case olive::Tool::kAddableEmpty:
case Tool::kAddableEmpty:
// Leave as "none", which means this block can be placed on any track
break;
case olive::Tool::kAddableCount:
case Tool::kAddableCount:
// Return so we do nothing
return;
}
@@ -103,7 +103,15 @@ void AddTool::MouseRelease(TimelineViewMouseEvent *event)
command->add_child(subtitle_section_command);
}
CreateAddableClip(command, parent()->sequence(), ghost_->GetTrack(), ghost_->GetAdjustedIn(), ghost_->GetAdjustedLength());
Sequence *s = parent()->sequence();
// If we want to set a manual rect for something, we can do so here
//
//VideoParams svp = s->GetVideoParams();
//QRectF r(0, 0, svp.width(), svp.height());
//r.adjust(svp.width()/10, svp.height()/10, -svp.width()/10, -svp.height()/10);
CreateAddableClip(command, s, ghost_->GetTrack(), ghost_->GetAdjustedIn(), ghost_->GetAdjustedLength());
Core::instance()->undo_stack()->push(command);
}
@@ -137,31 +145,27 @@ Node *AddTool::CreateAddableClip(MultiUndoCommand *command, Sequence *sequence,
Node *node_to_add = nullptr;
switch (Core::instance()->GetSelectedAddableObject()) {
case olive::Tool::kAddableEmpty:
case Tool::kAddableEmpty:
// Empty, nothing to be done
break;
case olive::Tool::kAddableSolid:
{
case Tool::kAddableSolid:
node_to_add = new SolidGenerator();
break;
}
case olive::Tool::kAddableShape:
case Tool::kAddableShape:
node_to_add = new ShapeNode();
break;
case olive::Tool::kAddableTitle:
{
case Tool::kAddableTitle:
node_to_add = new TextGeneratorV3();
break;
}
case olive::Tool::kAddableBars:
case olive::Tool::kAddableTone:
case Tool::kAddableBars:
case Tool::kAddableTone:
// Not implemented yet
qWarning() << "Unimplemented add object:" << Core::instance()->GetSelectedAddableObject();
break;
case olive::Tool::kAddableSubtitle:
case Tool::kAddableSubtitle:
// The block itself is the node we want
break;
case olive::Tool::kAddableCount:
case Tool::kAddableCount:
// Invalid value, do nothing
break;
}
@@ -173,14 +177,8 @@ Node *AddTool::CreateAddableClip(MultiUndoCommand *command, Sequence *sequence,
command->add_child(new NodeSetPositionCommand(node_to_add, clip, extra_node_offset));
if (!rect.isNull()) {
if (ShapeNodeBase *snb = dynamic_cast<ShapeNodeBase*>(node_to_add)) {
NodeInput pos(snb, ShapeNodeBase::kPositionInput);
NodeInput sz(snb, ShapeNodeBase::kSizeInput);
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 0), rect.width()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(sz, 1), rect.height()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 0), rect.x()));
command->add_child(new NodeParamSetStandardValueCommand(NodeKeyframeTrackReference(pos, 1), rect.y()));
if (ShapeNodeBase *shape = dynamic_cast<ShapeNodeBase*>(node_to_add)) {
shape->SetRect(rect, sequence->GetVideoParams(), command);
}
}
}
+8 -6
View File
@@ -38,6 +38,7 @@
#include "config/config.h"
#include "core.h"
#include "node/block/gap/gap.h"
#include "node/generator/shape/shapenodebase.h"
#include "node/project/project.h"
#include "render/rendermanager.h"
#include "task/taskmanager.h"
@@ -480,7 +481,7 @@ void ViewerWidget::UpdateAudioProcessor()
}
}
void ViewerWidget::CreateAddableAt(QRectF f)
void ViewerWidget::CreateAddableAt(const QRectF &f)
{
if (Sequence *s = dynamic_cast<Sequence*>(GetConnectedNode())) {
Track::Type type = Track::kVideo;
@@ -510,12 +511,13 @@ void ViewerWidget::CreateAddableAt(QRectF f)
}
}
// Normalize around center of sequence
f.translate(-s->GetVideoParams().width()*0.5, -s->GetVideoParams().height()*0.5);
f.translate(f.width()*0.5, f.height()*0.5);
MultiUndoCommand *command = new MultiUndoCommand();
Node *clip = AddTool::CreateAddableClip(command, s, Track::Reference(type, track_index), in, length, f);
Node *clip = AddTool::CreateAddableClip(command, s, Track::Reference(type, track_index), in, length);
if (ShapeNodeBase *shape = dynamic_cast<ShapeNodeBase*>(clip)) {
shape->SetRect(f, s->GetVideoParams(), command);
}
Core::instance()->undo_stack()->pushIfHasChildren(command);
SetGizmos(clip);
}
+1 -1
View File
@@ -325,7 +325,7 @@ private slots:
void UpdateAudioProcessor();
void CreateAddableAt(QRectF f);
void CreateAddableAt(const QRectF &f);
};