Skip to content

Commit

Permalink
Add "Copy Current Filter" action
Browse files Browse the repository at this point in the history
  • Loading branch information
bmatherly committed Jan 11, 2025
1 parent 6b7de9b commit a788aef
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 8 deletions.
Binary file added icons/dark/32x32/edit-select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/light/32x32/edit-select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/oxygen/32x32/actions/edit-select.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions icons/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,12 @@
<file>oxygen/32x32/actions/edit-copy.png</file>
<file>oxygen/32x32/actions/edit-cut.png</file>
<file>oxygen/32x32/actions/edit-paste.png</file>
<file>oxygen/32x32/actions/edit-select.png</file>
<file>oxygen/32x32/actions/edit-select-all.png</file>
<file>light/32x32/edit-copy.png</file>
<file>light/32x32/edit-cut.png</file>
<file>light/32x32/edit-paste.png</file>
<file>light/32x32/edit-select.png</file>
<file>light/32x32/edit-select-all.png</file>
<file>oxygen/32x32/actions/format-indent-less.png</file>
<file>oxygen/32x32/actions/format-indent-more.png</file>
Expand Down Expand Up @@ -267,6 +269,7 @@
<file>dark/32x32/edit-copy.png</file>
<file>dark/32x32/edit-cut.png</file>
<file>dark/32x32/edit-paste.png</file>
<file>dark/32x32/edit-select.png</file>
<file>dark/32x32/edit-select-all.png</file>
<file>dark/32x32/format-indent-less.png</file>
<file>dark/32x32/format-indent-more.png</file>
Expand Down
11 changes: 11 additions & 0 deletions src/docks/filtersdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ void FiltersDock::setupActions()
addAction(action);
Actions.add("filtersCopyFiltersAction", action, windowTitle());

action = new QAction(tr("Copy Current Filter"), this);
action->setToolTip(tr("Copy current filter to the clipboard"));
icon = QIcon::fromTheme("edit-copy",
QIcon(":/icons/oxygen/32x32/actions/edit-select.png"));
action->setIcon(icon);
connect(action, &QAction::triggered, this, [ = ]() {
QmlApplication::singleton().copyCurrentFilter();
});
addAction(action);
Actions.add("filtersCopyCurrentFilterAction", action, windowTitle());

action = new QAction(tr("Paste Filters"), this);
action->setToolTip(tr("Paste the filters from the clipboard"));
icon = QIcon::fromTheme("edit-paste",
Expand Down
26 changes: 20 additions & 6 deletions src/mltcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,13 +1117,14 @@ static int indexOfFirstNonGpu(Producer &toProducer)
}

void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool fromClipboard,
bool includeDisabled)
bool includeDisabled, int filterIndex)
{
int in = fromProducer.get(kFilterInProperty) ? fromProducer.get_int(kFilterInProperty) :
fromProducer.get_in();
int out = fromProducer.get(kFilterOutProperty) ? fromProducer.get_int(
kFilterOutProperty) : fromProducer.get_out();
int count = fromProducer.filter_count();
int filterCount = 0;

// Get the index of the first non-GPU filter or link in toProducer
int firstNonGpuService = fromClipboard ? indexOfFirstNonGpu(toProducer) : -1;
Expand All @@ -1132,8 +1133,16 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
QScopedPointer<Mlt::Filter> fromFilter(fromProducer.filter(i));
if (fromFilter && fromFilter->is_valid() && !fromFilter->get_int("_loader")
&& !fromFilter->get_int(kShotcutHiddenProperty)
&& fromFilter->get("mlt_service")
&& (includeDisabled || !fromFilter->get_int("disable"))) {
&& fromFilter->get("mlt_service")) {

filterCount++;
if (filterIndex != -1 && filterIndex != (filterCount - 1)) {
continue;
}

if (!includeDisabled && fromFilter->get_int("disable")) {
continue;
}

// Determine if filter can be added
auto metadata = MAIN.filterController()->metadataForService(fromFilter.data());
Expand Down Expand Up @@ -1177,6 +1186,10 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
QScopedPointer<Mlt::Link> fromLink(fromChain.link(i));
if (fromLink && fromLink->is_valid() && fromLink->get("mlt_service")
&& !fromLink->get_int("_loader")) {
filterCount++;
if (filterIndex != -1 && filterIndex != (filterCount - 1)) {
continue;
}
Mlt::Link toLink(fromLink->get("mlt_service"));
if (toLink.is_valid()) {
toLink.inherit(*fromLink);
Expand All @@ -1190,14 +1203,15 @@ void Controller::copyFilters(Producer &fromProducer, Producer &toProducer, bool
}
}

void Controller::copyFilters(Mlt::Producer *producer)
void Controller::copyFilters(Mlt::Producer *producer, int filterIndex)
{
bool includeDisabled = filterIndex >= 0;
if (producer && producer->is_valid()) {
initFiltersClipboard();
copyFilters(*producer, *m_filtersClipboard, false, false);
copyFilters(*producer, *m_filtersClipboard, false, includeDisabled, filterIndex);
} else if (m_producer && m_producer->is_valid()) {
initFiltersClipboard();
copyFilters(*m_producer, *m_filtersClipboard, false, false);
copyFilters(*m_producer, *m_filtersClipboard, false, includeDisabled, filterIndex);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/mltcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ class Controller
void setUuid(Mlt::Properties &properties, QUuid uid) const;
QUuid ensureHasUuid(Mlt::Properties &properties) const;
static void copyFilters(Mlt::Producer &fromProducer, Mlt::Producer &toProducer,
bool fromClipboard = false, bool includeDisabled = true);
void copyFilters(Mlt::Producer *producer = nullptr);
bool fromClipboard = false, bool includeDisabled = true,
int filterIndex = -1);
void copyFilters(Mlt::Producer *producer = nullptr, int filterIndex = -1);
void pasteFilters(Mlt::Producer *producer = nullptr, Mlt::Producer *fromProducer = nullptr);
static void adjustFilters(Mlt::Producer &producer, int startIndex = 0);
static void adjustFilter(Mlt::Filter *filter, int in, int out, int inDelta, int outDelta,
Expand Down
15 changes: 15 additions & 0 deletions src/qml/views/filter/filterview.qml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ Rectangle {
}
}

Shotcut.Button {
id: copySelectedButton

implicitWidth: height
icon.name: 'edit-select'
icon.source: 'qrc:///icons/oxygen/32x32/actions/edit-select.png'
enabled: selectedIndex > Shotcut.Filter.NoCurrentFilter
opacity: enabled ? 1 : 0.5
onClicked: application.copyCurrentFilter()

Shotcut.HoverTip {
text: qsTr('Copy current filter')
}
}

Shotcut.Button {
id: pasteButton

Expand Down
14 changes: 14 additions & 0 deletions src/qmltypes/qmlapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ void QmlApplication::copyFilters()
emit QmlApplication::singleton().filtersCopied();
}

void QmlApplication::copyCurrentFilter()
{
int currentIndex = MAIN.filterController()->currentIndex();
if (currentIndex < 0) {
MAIN.showStatusMessage(tr("Select a filter to copy"));
return;
}
QScopedPointer<Mlt::Producer> producer(new Mlt::Producer(
MAIN.filterController()->attachedModel()->producer()));
MLT.copyFilters(producer.data(), currentIndex);
QGuiApplication::clipboard()->setText(MLT.filtersClipboardXML());
emit QmlApplication::singleton().filtersCopied();
}

void QmlApplication::pasteFilters()
{
QScopedPointer<Mlt::Producer> producer(new Mlt::Producer(
Expand Down
1 change: 1 addition & 0 deletions src/qmltypes/qmlapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class QmlApplication : public QObject
static QRect mainWinRect();
static bool hasFiltersOnClipboard();
Q_INVOKABLE static void copyFilters();
Q_INVOKABLE static void copyCurrentFilter();
Q_INVOKABLE static void pasteFilters();
Q_INVOKABLE static QString clockFromFrames(int frames);
Q_INVOKABLE static QString timeFromFrames(int frames);
Expand Down

0 comments on commit a788aef

Please sign in to comment.