Skip to content

Commit

Permalink
CommandPalette: support path effects
Browse files Browse the repository at this point in the history
and other related changed.

Ref: #214
  • Loading branch information
rodlie committed Jul 30, 2024
1 parent a965202 commit ef3b059
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
52 changes: 50 additions & 2 deletions src/app/GUI/effectactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,64 @@
#include "RasterEffects/rastereffectmenucreator.h"
#include "BlendEffects/blendeffectmenucreator.h"
#include "TransformEffects/transformeffectmenucreator.h"
#include "PathEffects/patheffectmenucreator.h"

void MainWindow::setupMenuEffects()
{
{ // path TODO
// adapt PathEffectsMenu::addPathEffectsToBoxActionMenu(menu);
{ // path
const auto menu1 = mEffectsMenu->addMenu(QIcon::fromTheme("preferences"), tr("Path Effects"));
const auto menu2 = mEffectsMenu->addMenu(QIcon::fromTheme("preferences"), tr("Fill Effects"));
const auto menu3 = mEffectsMenu->addMenu(QIcon::fromTheme("preferences"), tr("Outline Base Effects"));
const auto menu4 = mEffectsMenu->addMenu(QIcon::fromTheme("preferences"), tr("Outline Effects"));
const auto adder = [this,
menu1,
menu2,
menu3,
menu4](const QString& name,
const PathEffectMenuCreator::EffectCreator& creator) {
if (name.isEmpty()) { return; }
{
const auto act = menu1->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Path Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addPathEffect(creator());
});
}
{
const auto act = menu2->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Fill Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addFillPathEffect(creator());
});
}
{
const auto act = menu3->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Outline Base Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addOutlineBasePathEffect(creator());
});
}
{
const auto act = menu4->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Outline Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addOutlinePathEffect(creator());
});
}
};
PathEffectMenuCreator::forEveryEffect(adder);
}
{ // transform
const auto menu = mEffectsMenu->addMenu(QIcon::fromTheme("preferences"), tr("Transform Effects"));
const auto adder = [this, menu](const QString& name,
const TransformEffectMenuCreator::EffectCreator& creator) {
if (name.isEmpty()) { return; }
const auto act = menu->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Transform Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addTransformEffect(creator());
Expand All @@ -51,6 +97,7 @@ void MainWindow::setupMenuEffects()
const BlendEffectMenuCreator::EffectCreator& creator) {
if (name.isEmpty()) { return; }
const auto act = menu->addAction(QIcon::fromTheme("preferences"), name);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Blend Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addBlendEffect(creator());
Expand All @@ -66,6 +113,7 @@ void MainWindow::setupMenuEffects()
QString title = name;
if (!path.isEmpty()) { title.append(QString(" (%1)").arg(path));}
const auto act = menu->addAction(QIcon::fromTheme("preferences"), title);
act->setData(QString(name).prepend(tr("Add ")).append(tr(" (Raster Effect)")));
cmdAddAction(act);
connect(act, &QAction::triggered, this, [this, creator]() {
addRasterEffect(creator());
Expand Down
4 changes: 2 additions & 2 deletions src/core/BlendEffects/blendeffectmenucreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ struct CORE_EXPORT BlendEffectMenuCreator
const EffectCreator&)>;
static void forEveryEffect(const EffectAdder& add)
{
add(QObject::tr("Add Move Blend Effect"),
add(QObject::tr("Move"),
[]() { return enve::make_shared<MoveBlendEffect>(); });
add(QObject::tr("Add Targeted Blend Effect"),
add(QObject::tr("Targeted"),
[]() { return enve::make_shared<TargetedBlendEffect>(); });
}
};
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ set(
PathEffects/subpatheffect.h
PathEffects/sumpatheffect.h
PathEffects/zigzagpatheffect.h
PathEffects/patheffectmenucreator.h
Private/Tasks/complextask.h
Private/Tasks/execcontroller.h
Private/Tasks/gputaskexecutor.h
Expand Down
77 changes: 77 additions & 0 deletions src/core/PathEffects/patheffectmenucreator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
#
# Friction - https://friction.graphics
#
# Copyright (c) Friction contributors
#
# 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/>.
#
# See 'README.md' for more information.
#
*/

#ifndef PATHEFFECTMENUCREATOR_H
#define PATHEFFECTMENUCREATOR_H

#include "core_global.h"

#include <QString>
#include "PathEffects/dashpatheffect.h"
#include "PathEffects/displacepatheffect.h"
#include "PathEffects/duplicatepatheffect.h"
#include "PathEffects/linespatheffect.h"
#include "PathEffects/solidifypatheffect.h"
#include "PathEffects/spatialdisplacepatheffect.h"
#include "PathEffects/subdividepatheffect.h"
#include "PathEffects/subpatheffect.h"
#include "PathEffects/sumpatheffect.h"
#include "PathEffects/zigzagpatheffect.h"
#include <functional>
#include "smartPointers/selfref.h"

class PathEffect;

struct CORE_EXPORT PathEffectMenuCreator
{
template <typename T> using Func = std::function<T>;
template <typename T> using Creator = Func<qsptr<T>()>;
using EffectCreator = Creator<PathEffect>;
using EffectAdder = Func<void(const QString&,
const EffectCreator&)>;
static void forEveryEffect(const EffectAdder& add)
{
add(QObject::tr("Displace"),
[]() { return enve::make_shared<DisplacePathEffect>(); });
add(QObject::tr("Spatial Displace"),
[]() { return enve::make_shared<SpatialDisplacePathEffect>(); });
add(QObject::tr("Dash"),
[]() { return enve::make_shared<DashPathEffect>(); });
add(QObject::tr("Duplicate"),
[]() { return enve::make_shared<DuplicatePathEffect>(); });
add(QObject::tr("Sub-Path"),
[]() { return enve::make_shared<SubPathEffect>(); });
add(QObject::tr("Solidify"),
[]() { return enve::make_shared<SolidifyPathEffect>(); });
add(QObject::tr("Sum"),
[]() { return enve::make_shared<SumPathEffect>(); });
add(QObject::tr("Lines"),
[]() { return enve::make_shared<LinesPathEffect>(); });
add(QObject::tr("ZigZag"),
[]() { return enve::make_shared<ZigZagPathEffect>(); });
add(QObject::tr("Subdivide"),
[]() { return enve::make_shared<SubdividePathEffect>(); });
}
};

#endif // PATHEFFECTMENUCREATOR_H
10 changes: 5 additions & 5 deletions src/core/TransformEffects/transformeffectmenucreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ struct CORE_EXPORT TransformEffectMenuCreator
const EffectCreator&)>;
static void forEveryEffect(const EffectAdder& add)
{
add(QObject::tr("Add Track Effect"),
add(QObject::tr("Track"),
[]() { return enve::make_shared<TrackEffect>(); });
add(QObject::tr("Add Follow Path Effect"),
add(QObject::tr("Follow Path"),
[]() { return enve::make_shared<FollowPathEffect>(); });
add(QObject::tr("Add Follow Object Effect"),
add(QObject::tr("Follow Object"),
[]() { return enve::make_shared<FollowObjectEffect>(); });
add(QObject::tr("Add Follow Object Relative Effect"),
add(QObject::tr("Follow Object Relative"),
[]() { return enve::make_shared<FollowObjectRelativeEffect>(); });
add(QObject::tr("Add Parent Effect"),
add(QObject::tr("Parent"),
[]() { return enve::make_shared<ParentEffect>(); });
}
};
Expand Down

0 comments on commit ef3b059

Please sign in to comment.