From ae62750d9dd994c84b1771935fbd662f5f8986b2 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 14 Jul 2020 22:31:11 +1000 Subject: [PATCH] various: fix broken transition creation It's now possible to create transitions! But they're still broken in a multitude of other ways so plenty more work to do hahahahahahahahaha --- app/core.cpp | 12 +++- app/core.h | 17 ++++- app/node/block/transition/CMakeLists.txt | 3 + .../transition/crossdissolve/CMakeLists.txt | 22 ++++++ .../crossdissolve/crossdissolvetransition.cpp | 62 +++++++++++++++++ .../crossdissolve/crossdissolvetransition.h | 48 +++++++++++++ .../transition/diptocolor/CMakeLists.txt | 22 ++++++ .../diptocolor/diptocolortransition.cpp | 68 +++++++++++++++++++ .../diptocolor/diptocolortransition.h | 52 ++++++++++++++ app/node/block/transition/transition.cpp | 31 ++++++--- app/node/block/transition/transition.h | 5 ++ app/node/factory.cpp | 17 ++++- app/node/factory.h | 9 ++- app/node/node.cpp | 2 + app/node/node.h | 1 + app/panel/tool/tool.cpp | 1 + app/shaders/crossdissolve.frag | 3 +- app/shaders/diptoblack.frag | 24 +++---- app/widget/timelinewidget/tool/transition.cpp | 10 ++- app/widget/toolbar/toolbar.cpp | 22 +++++- app/widget/toolbar/toolbar.h | 17 +++++ 21 files changed, 415 insertions(+), 33 deletions(-) create mode 100644 app/node/block/transition/crossdissolve/CMakeLists.txt create mode 100644 app/node/block/transition/crossdissolve/crossdissolvetransition.cpp create mode 100644 app/node/block/transition/crossdissolve/crossdissolvetransition.h create mode 100644 app/node/block/transition/diptocolor/CMakeLists.txt create mode 100644 app/node/block/transition/diptocolor/diptocolortransition.cpp create mode 100644 app/node/block/transition/diptocolor/diptocolortransition.h diff --git a/app/core.cpp b/app/core.cpp index e8f34fcf4..d7014f408 100644 --- a/app/core.cpp +++ b/app/core.cpp @@ -281,16 +281,26 @@ const Tool::Item &Core::tool() const return tool_; } -const Tool::AddableObject &Core::selected_addable_object() const +const Tool::AddableObject &Core::GetSelectedAddableObject() const { return addable_object_; } +const QString &Core::GetSelectedTransition() const +{ + return selected_transition_; +} + void Core::SetSelectedAddableObject(const Tool::AddableObject &obj) { addable_object_ = obj; } +void Core::SetSelectedTransitionObject(const QString &obj) +{ + selected_transition_ = obj; +} + void Core::ClearOpenRecentList() { recent_projects_.clear(); diff --git a/app/core.h b/app/core.h index 9b3d25728..1ead89b5c 100644 --- a/app/core.h +++ b/app/core.h @@ -114,7 +114,12 @@ public: /** * @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; + const Tool::AddableObject& GetSelectedAddableObject() const; + + /** + * @brief Get the currently selected node that the transition tool should make (if the transition tool is active) + */ + const QString& GetSelectedTransition() const; /** * @brief Get current snapping value @@ -341,6 +346,11 @@ public slots: */ void SetSelectedAddableObject(const Tool::AddableObject& obj); + /** + * @brief Set the currently selected object that the add tool should make + */ + void SetSelectedTransitionObject(const QString& obj); + /** * @brief Clears the list of recently opened/saved projects */ @@ -456,6 +466,11 @@ private: */ Tool::AddableObject addable_object_; + /** + * @brief Currently selected transition + */ + QString selected_transition_; + /** * @brief Current snapping setting */ diff --git a/app/node/block/transition/CMakeLists.txt b/app/node/block/transition/CMakeLists.txt index 65f672588..4a380bc81 100644 --- a/app/node/block/transition/CMakeLists.txt +++ b/app/node/block/transition/CMakeLists.txt @@ -14,6 +14,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +add_subdirectory(crossdissolve) +add_subdirectory(diptocolor) + set(OLIVE_SOURCES ${OLIVE_SOURCES} node/block/transition/transition.h diff --git a/app/node/block/transition/crossdissolve/CMakeLists.txt b/app/node/block/transition/crossdissolve/CMakeLists.txt new file mode 100644 index 000000000..25c90ed8e --- /dev/null +++ b/app/node/block/transition/crossdissolve/CMakeLists.txt @@ -0,0 +1,22 @@ +# 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 . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + node/block/transition/crossdissolve/crossdissolvetransition.h + node/block/transition/crossdissolve/crossdissolvetransition.cpp + PARENT_SCOPE +) diff --git a/app/node/block/transition/crossdissolve/crossdissolvetransition.cpp b/app/node/block/transition/crossdissolve/crossdissolvetransition.cpp new file mode 100644 index 000000000..c6d471030 --- /dev/null +++ b/app/node/block/transition/crossdissolve/crossdissolvetransition.cpp @@ -0,0 +1,62 @@ +/*** + + 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 . + +***/ + +#include "crossdissolvetransition.h" + +OLIVE_NAMESPACE_ENTER + +CrossDissolveTransition::CrossDissolveTransition() +{ + +} + +Node *CrossDissolveTransition::copy() const +{ + return new CrossDissolveTransition(); +} + +QString CrossDissolveTransition::Name() const +{ + return tr("Cross Dissolve"); +} + +QString CrossDissolveTransition::id() const +{ + return QStringLiteral("org.olivevideoeditor.Olive.crossdissolve"); +} + +QList CrossDissolveTransition::Category() const +{ + return {kCategoryTransition}; +} + +QString CrossDissolveTransition::Description() const +{ + return tr("Smoothly transition between two clips."); +} + +ShaderCode CrossDissolveTransition::GetShaderCode(const QString &shader_id) const +{ + Q_UNUSED(shader_id) + + return ShaderCode(Node::ReadFileAsString(":/shaders/crossdissolve.frag"), QString()); +} + +OLIVE_NAMESPACE_EXIT diff --git a/app/node/block/transition/crossdissolve/crossdissolvetransition.h b/app/node/block/transition/crossdissolve/crossdissolvetransition.h new file mode 100644 index 000000000..ccd8877d3 --- /dev/null +++ b/app/node/block/transition/crossdissolve/crossdissolvetransition.h @@ -0,0 +1,48 @@ +/*** + + 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 . + +***/ + +#ifndef CROSSDISSOLVETRANSITION_H +#define CROSSDISSOLVETRANSITION_H + +#include "node/block/transition/transition.h" + +OLIVE_NAMESPACE_ENTER + +class CrossDissolveTransition : public TransitionBlock +{ +public: + CrossDissolveTransition(); + + virtual Node* copy() const override; + + virtual QString Name() const override; + virtual QString id() const override; + virtual QList Category() const override; + virtual QString Description() const override; + + //virtual void Retranslate() override; + + virtual ShaderCode GetShaderCode(const QString& shader_id) const override; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // CROSSDISSOLVETRANSITION_H diff --git a/app/node/block/transition/diptocolor/CMakeLists.txt b/app/node/block/transition/diptocolor/CMakeLists.txt new file mode 100644 index 000000000..7eb37f14d --- /dev/null +++ b/app/node/block/transition/diptocolor/CMakeLists.txt @@ -0,0 +1,22 @@ +# 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 . + +set(OLIVE_SOURCES + ${OLIVE_SOURCES} + node/block/transition/diptocolor/diptocolortransition.h + node/block/transition/diptocolor/diptocolortransition.cpp + PARENT_SCOPE +) diff --git a/app/node/block/transition/diptocolor/diptocolortransition.cpp b/app/node/block/transition/diptocolor/diptocolortransition.cpp new file mode 100644 index 000000000..816c75011 --- /dev/null +++ b/app/node/block/transition/diptocolor/diptocolortransition.cpp @@ -0,0 +1,68 @@ +/*** + + 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 . + +***/ + +#include "diptocolortransition.h" + +OLIVE_NAMESPACE_ENTER + +DipToColorTransition::DipToColorTransition() +{ + color_input_ = new NodeInput(QStringLiteral("color_in"), NodeParam::kColor, QVariant::fromValue(Color(0, 0, 0))); + AddInput(color_input_); +} + +Node *DipToColorTransition::copy() const +{ + return new DipToColorTransition(); +} + +QString DipToColorTransition::Name() const +{ + return tr("Dip To Color"); +} + +QString DipToColorTransition::id() const +{ + return QStringLiteral("org.olivevideoeditor.Olive.diptocolor"); +} + +QList DipToColorTransition::Category() const +{ + return {kCategoryTransition}; +} + +QString DipToColorTransition::Description() const +{ + return tr("Transition between clips by dipping to a color."); +} + +ShaderCode DipToColorTransition::GetShaderCode(const QString &shader_id) const +{ + Q_UNUSED(shader_id) + + return ShaderCode(Node::ReadFileAsString(":/shaders/diptoblack.frag"), QString()); +} + +void DipToColorTransition::ShaderJobEvent(NodeValueDatabase &value, ShaderJob &job) const +{ + job.InsertValue(color_input_, value); +} + +OLIVE_NAMESPACE_EXIT diff --git a/app/node/block/transition/diptocolor/diptocolortransition.h b/app/node/block/transition/diptocolor/diptocolortransition.h new file mode 100644 index 000000000..2c19443e1 --- /dev/null +++ b/app/node/block/transition/diptocolor/diptocolortransition.h @@ -0,0 +1,52 @@ +/*** + + 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 . + +***/ + +#ifndef DIPTOCOLORTRANSITION_H +#define DIPTOCOLORTRANSITION_H + +#include "node/block/transition/transition.h" + +OLIVE_NAMESPACE_ENTER + +class DipToColorTransition : public TransitionBlock +{ +public: + DipToColorTransition(); + + virtual Node* copy() const override; + + virtual QString Name() const override; + virtual QString id() const override; + virtual QList Category() const override; + virtual QString Description() const override; + + virtual ShaderCode GetShaderCode(const QString& shader_id) const override; + +protected: + virtual void ShaderJobEvent(NodeValueDatabase &value, ShaderJob& job) const override; + +private: + NodeInput* color_input_; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // DIPTOCOLORTRANSITION_H diff --git a/app/node/block/transition/transition.cpp b/app/node/block/transition/transition.cpp index 3f820fd47..aa8a77c0a 100644 --- a/app/node/block/transition/transition.cpp +++ b/app/node/block/transition/transition.cpp @@ -131,6 +131,8 @@ double TransitionBlock::GetInProgress(const rational &time) const void TransitionBlock::Hash(QCryptographicHash &hash, const rational &time) const { + Node::Hash(hash, time); + double all_prog = GetTotalProgress(time); double in_prog = GetInProgress(time); double out_prog = GetOutProgress(time); @@ -138,14 +140,6 @@ void TransitionBlock::Hash(QCryptographicHash &hash, const rational &time) const hash.addData(reinterpret_cast(&all_prog), sizeof(double)); hash.addData(reinterpret_cast(&in_prog), sizeof(double)); hash.addData(reinterpret_cast(&out_prog), sizeof(double)); - - if (out_block_input_->is_connected()) { - out_block_input_->get_connected_node()->Hash(hash, time); - } - - if (in_block_input_->is_connected()) { - in_block_input_->get_connected_node()->Hash(hash, time); - } } double TransitionBlock::GetInternalTransitionTime(const rational &time) const @@ -177,4 +171,25 @@ void TransitionBlock::BlockDisconnected(NodeEdgePtr edge) } } +NodeValueTable TransitionBlock::Value(NodeValueDatabase &value) const +{ + ShaderJob job; + + job.InsertValue(out_block_input(), value); + job.InsertValue(in_block_input(), value); + job.SetAlphaChannelRequired(true); + + ShaderJobEvent(value, job); + + NodeValueTable table = value.Merge(); + table.Push(NodeParam::kShaderJob, QVariant::fromValue(job), this); + return table; +} + +void TransitionBlock::ShaderJobEvent(NodeValueDatabase &value, ShaderJob &job) const +{ + Q_UNUSED(value) + Q_UNUSED(job) +} + OLIVE_NAMESPACE_EXIT diff --git a/app/node/block/transition/transition.h b/app/node/block/transition/transition.h index 62f4280b5..50d6ac204 100644 --- a/app/node/block/transition/transition.h +++ b/app/node/block/transition/transition.h @@ -49,6 +49,11 @@ public: virtual void Hash(QCryptographicHash& hash, const rational &time) const override; + virtual NodeValueTable Value(NodeValueDatabase &value) const override; + +protected: + virtual void ShaderJobEvent(NodeValueDatabase &value, ShaderJob& job) const; + private: double GetInternalTransitionTime(const rational& time) const; diff --git a/app/node/factory.cpp b/app/node/factory.cpp index ee2fe3892..7c389f443 100644 --- a/app/node/factory.cpp +++ b/app/node/factory.cpp @@ -24,6 +24,8 @@ #include "audio/volume/volume.h" #include "block/clip/clip.h" #include "block/gap/gap.h" +#include "block/transition/crossdissolve/crossdissolvetransition.h" +#include "block/transition/diptocolor/diptocolortransition.h" #include "generator/matrix/matrix.h" #include "generator/polygon/polygon.h" #include "generator/solid/solid.h" @@ -48,7 +50,7 @@ void NodeFactory::Initialize() // Add internal types for (int i=0;i(i))); + library_.append(CreateFromFactoryIndex(static_cast(i))); } /* @@ -63,7 +65,7 @@ void NodeFactory::Destroy() library_.clear(); } -Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item) +Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item, Node::CategoryID restrict_to) { Menu* menu = new Menu(parent); menu->setToolTipsVisible(true); @@ -71,6 +73,11 @@ Menu *NodeFactory::CreateMenu(QWidget* parent, bool create_none_item) for (int i=0;iCategory().contains(restrict_to)) { + // Skip this node + continue; + } + // Make sure nodes are up-to-date with the current translation n->Retranslate(); @@ -165,7 +172,7 @@ Node *NodeFactory::CreateFromID(const QString &id) return nullptr; } -Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id) +Node *NodeFactory::CreateFromFactoryIndex(const NodeFactory::InternalID &id) { switch (id) { case kClipBlock: @@ -204,6 +211,10 @@ Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id) return new StrokeFilterNode(); case kTextGenerator: return new TextGenerator(); + case kCrossDissolveTransition: + return new CrossDissolveTransition(); + case kDipToColorTransition: + return new DipToColorTransition(); case kInternalNodeCount: break; diff --git a/app/node/factory.h b/app/node/factory.h index b5c1b6f0f..6025070ef 100644 --- a/app/node/factory.h +++ b/app/node/factory.h @@ -50,6 +50,8 @@ public: kMerge, kStrokeFilter, kTextGenerator, + kCrossDissolveTransition, + kDipToColorTransition, // Count value kInternalNodeCount @@ -61,7 +63,7 @@ public: static void Destroy(); - static Menu* CreateMenu(QWidget *parent, bool create_none_item = false); + static Menu* CreateMenu(QWidget *parent, bool create_none_item = false, Node::CategoryID restrict_to = Node::kCategoryUnknown); static Node* CreateFromMenuAction(QAction* action); @@ -71,10 +73,11 @@ public: static Node* CreateFromID(const QString& id); -private: - static Node* CreateInternal(const InternalID& id); + static Node* CreateFromFactoryIndex(const InternalID& id); +private: static QList library_; + }; OLIVE_NAMESPACE_EXIT diff --git a/app/node/node.cpp b/app/node/node.cpp index 840406ed8..46d615b60 100644 --- a/app/node/node.cpp +++ b/app/node/node.cpp @@ -668,6 +668,8 @@ QString Node::GetCategoryName(const CategoryID &c) return tr("Generator"); case kCategoryChannels: return tr("Channel"); + case kCategoryTransition: + return tr("Transition"); case kCategoryUnknown: case kCategoryCount: break; diff --git a/app/node/node.h b/app/node/node.h index 11a69704f..eb3b272a2 100644 --- a/app/node/node.h +++ b/app/node/node.h @@ -70,6 +70,7 @@ public: kCategoryGeneral, kCategoryTimeline, kCategoryChannels, + kCategoryTransition, kCategoryCount }; diff --git a/app/panel/tool/tool.cpp b/app/panel/tool/tool.cpp index ac8b1162d..7822ece90 100644 --- a/app/panel/tool/tool.cpp +++ b/app/panel/tool/tool.cpp @@ -42,6 +42,7 @@ ToolPanel::ToolPanel(QWidget *parent) : connect(Core::instance(), &Core::SnappingChanged, t, &Toolbar::SetSnapping); connect(t, &Toolbar::AddableObjectChanged, Core::instance(), &Core::SetSelectedAddableObject); + connect(t, &Toolbar::SelectedTransitionChanged, Core::instance(), &Core::SetSelectedTransitionObject); Retranslate(); } diff --git a/app/shaders/crossdissolve.frag b/app/shaders/crossdissolve.frag index 22eb8e54f..2af4b17b4 100644 --- a/app/shaders/crossdissolve.frag +++ b/app/shaders/crossdissolve.frag @@ -19,8 +19,7 @@ void main(void) { } if (in_block_in_enabled) { - vec4 in_block_col = texture(in_block_in, ove_texcoord) * ove_tprog_all; - composite += in_block_col; + composite += texture(in_block_in, ove_texcoord) * ove_tprog_all; } fragColor = composite; diff --git a/app/shaders/diptoblack.frag b/app/shaders/diptoblack.frag index 064264506..b6e89dad3 100644 --- a/app/shaders/diptoblack.frag +++ b/app/shaders/diptoblack.frag @@ -4,7 +4,9 @@ uniform sampler2D out_block_in; uniform sampler2D in_block_in; uniform bool out_block_in_enabled; uniform bool in_block_in_enabled; +uniform vec4 color_in; +uniform float ove_tprog_all; uniform float ove_tprog_out; uniform float ove_tprog_in; @@ -13,20 +15,16 @@ in vec2 ove_texcoord; out vec4 fragColor; void main(void) { - vec4 out_block_col; - vec4 in_block_col; + if (out_block_in_enabled && in_block_in_enabled) { + vec4 out_block_col = mix(texture(out_block_in, ove_texcoord), color_in, ove_tprog_out); + vec4 in_block_col = mix(texture(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_in); - if (out_block_in_enabled) { - out_block_col = texture(out_block_in, ove_texcoord) * pow(ove_tprog_out, 2.0); + fragColor = out_block_col + in_block_col; + } else if (out_block_in_enabled) { + fragColor = mix(texture(out_block_in, ove_texcoord), color_in, ove_tprog_all); + } else if (in_block_in_enabled) { + fragColor = mix(texture(in_block_in, ove_texcoord), color_in, 1.0 - ove_tprog_all); } else { - out_block_col = vec4(0.0); + fragColor = vec4(0.0); } - - if (in_block_in_enabled) { - in_block_col = texture(in_block_in, ove_texcoord) * pow(ove_tprog_in, 2.0); - } else { - in_block_col = vec4(0.0); - } - - fragColor = out_block_col + in_block_col; } diff --git a/app/widget/timelinewidget/tool/transition.cpp b/app/widget/timelinewidget/tool/transition.cpp index 6592581e9..3b8f0ae40 100644 --- a/app/widget/timelinewidget/tool/transition.cpp +++ b/app/widget/timelinewidget/tool/transition.cpp @@ -20,6 +20,7 @@ #include "widget/timelinewidget/timelinewidget.h" +#include "node/block/transition/crossdissolve/crossdissolvetransition.h" #include "node/block/transition/transition.h" #include "node/factory.h" #include "widget/nodeview/nodeviewundo.h" @@ -111,7 +112,14 @@ void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event) if (ghost_) { if (!ghost_->AdjustedLength().isNull()) { - TransitionBlock* transition = static_cast(NodeFactory::CreateFromID("org.olivevideoeditor.Olive.crossdissolve")); + TransitionBlock* transition; + + if (Core::instance()->GetSelectedTransition().isEmpty()) { + // Fallback if the user hasn't selected one yet + transition = new CrossDissolveTransition(); + } else { + transition = static_cast(NodeFactory::CreateFromID(Core::instance()->GetSelectedTransition())); + } QUndoCommand* command = new QUndoCommand(); diff --git a/app/widget/toolbar/toolbar.cpp b/app/widget/toolbar/toolbar.cpp index c04a4661c..62bb3f5ab 100644 --- a/app/widget/toolbar/toolbar.cpp +++ b/app/widget/toolbar/toolbar.cpp @@ -25,8 +25,9 @@ #include #include -#include "widget/menu/menu.h" +#include "node/factory.h" #include "ui/icons/icons.h" +#include "widget/menu/menu.h" OLIVE_NAMESPACE_ENTER @@ -54,6 +55,9 @@ Toolbar::Toolbar(QWidget *parent) : btn_snapping_toggle_ = CreateNonToolButton(); connect(btn_snapping_toggle_, &QPushButton::clicked, this, &Toolbar::SnappingButtonClicked); + // Connect transition button to menu signal + connect(btn_transition_tool_, &QPushButton::clicked, this, &Toolbar::TransitionButtonClicked); + // Connect add button to menu signal connect(btn_add_, &QPushButton::clicked, this, &Toolbar::AddButtonClicked); @@ -181,9 +185,25 @@ void Toolbar::AddButtonClicked() m.exec(QCursor::pos()); } +void Toolbar::TransitionButtonClicked() +{ + Menu* m = NodeFactory::CreateMenu(this, false, Node::kCategoryTransition); + + connect(m, &QMenu::triggered, this, &Toolbar::TransitionMenuItemTriggered); + + m->exec(QCursor::pos()); + + delete m; +} + void Toolbar::AddMenuItemTriggered(QAction* a) { emit AddableObjectChanged(static_cast(a->data().toInt())); } +void Toolbar::TransitionMenuItemTriggered(QAction *a) +{ + emit SelectedTransitionChanged(NodeFactory::GetIDFromMenuAction(a)); +} + OLIVE_NAMESPACE_EXIT diff --git a/app/widget/toolbar/toolbar.h b/app/widget/toolbar/toolbar.h index 2f315e738..74c48167d 100644 --- a/app/widget/toolbar/toolbar.h +++ b/app/widget/toolbar/toolbar.h @@ -113,6 +113,11 @@ signals: */ void AddableObjectChanged(const Tool::AddableObject& obj); + /** + * @brief Emitted when the selected transition is changed from the transition tool menu + */ + void SelectedTransitionChanged(const QString& id); + private: /** * @brief Reset all strings based on the currently selected language @@ -210,11 +215,23 @@ private slots: */ void AddButtonClicked(); + /** + * @brief Receiver for the transition button + * + * The transition button pops up a list for which transition to create. + */ + void TransitionButtonClicked(); + /** * @brief Receiver for the menu created by AddButtonClicked() */ void AddMenuItemTriggered(QAction* a); + /** + * @brief Receiver for the menu created by TransitionButtonClicked() + */ + void TransitionMenuItemTriggered(QAction* a); + }; OLIVE_NAMESPACE_EXIT