CuteLogger
Fast and simple logging solution for Qt based applications
qmlfilter.h
1/*
2 * Copyright (c) 2013-2024 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef FILTER_H
19#define FILTER_H
20
21#include <QObject>
22#include <QString>
23#include <QVariant>
24#include <QRectF>
25#include <QUuid>
26#include <QColor>
27#include <MltService.h>
28#include <MltProducer.h>
29#include <MltAnimation.h>
30
31#include "qmlmetadata.h"
32#include "shotcut_mlt_properties.h"
33
34class AbstractJob;
35class EncodeJob;
36class QUndoCommand;
37class FilterController;
38
39class QmlFilter : public QObject
40{
41 Q_OBJECT
42 Q_PROPERTY(bool isNew READ isNew CONSTANT)
43 Q_PROPERTY(QString path READ path CONSTANT)
44 Q_PROPERTY(QStringList presets READ presets NOTIFY presetsChanged)
45 Q_PROPERTY(int in READ in NOTIFY inChanged)
46 Q_PROPERTY(int out READ out NOTIFY outChanged)
47 Q_PROPERTY(int animateIn READ animateIn WRITE setAnimateIn NOTIFY animateInChanged)
48 Q_PROPERTY(int animateOut READ animateOut WRITE setAnimateOut NOTIFY animateOutChanged)
49 Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
50 Q_PROPERTY(bool blockSignals READ signalsBlocked WRITE blockSignals)
51
52public:
53 enum CurrentFilterIndex {
54 NoCurrentFilter = -1,
55 DeselectCurrentFilter = -2
56 };
57 Q_ENUM(CurrentFilterIndex)
58
59 explicit QmlFilter();
60 explicit QmlFilter(Mlt::Service &mltService, const QmlMetadata *metadata,
61 QObject *parent = nullptr);
62 ~QmlFilter();
63
64 bool isNew() const
65 {
66 return m_isNew;
67 }
68 void setIsNew(bool isNew)
69 {
70 m_isNew = isNew;
71 }
72
73 Q_INVOKABLE QString get(QString name, int position = -1);
74 Q_INVOKABLE QColor getColor(QString name, int position = -1);
75 Q_INVOKABLE double getDouble(QString name, int position = -1);
76 Q_INVOKABLE QRectF getRect(QString name, int position = -1);
77 Q_INVOKABLE void removeRectPercents(QString name);
78 Q_INVOKABLE QStringList getGradient(QString name);
79 Q_INVOKABLE void set(QString name, QString value, int position = -1);
80 Q_INVOKABLE void set(QString name, const QColor &value,
81 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
82 Q_INVOKABLE void set(QString name, double value,
83 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
84 Q_INVOKABLE void set(QString name, int value,
85 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
86 Q_INVOKABLE void set(QString name, bool value,
87 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
88 Q_INVOKABLE void set(QString name, double x, double y, double width, double height,
89 double opacity = 1.0,
90 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
91 Q_INVOKABLE void set(QString name, const QRectF &rect,
92 int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
93 Q_INVOKABLE void setGradient(QString name, const QStringList &gradient);
94 QString path() const
95 {
96 return m_path;
97 }
98 Q_INVOKABLE void loadPresets();
99 QStringList presets() const
100 {
101 return m_presets;
102 }
104 Q_INVOKABLE int savePreset(const QStringList &propertyNames, const QString &name = QString());
105 Q_INVOKABLE void deletePreset(const QString &name);
106 Q_INVOKABLE void analyze(bool isAudio = false, bool deferJob = true);
107 Q_INVOKABLE static int framesFromTime(const QString &time);
108 Q_INVOKABLE void getHash();
109 Mlt::Producer &producer()
110 {
111 return m_producer;
112 }
113 int in();
114 int out();
115 Mlt::Service &service()
116 {
117 return m_service;
118 }
119 int animateIn();
120 void setAnimateIn(int value);
121 int animateOut();
122 void setAnimateOut(int value);
123 void clearAnimateInOut();
124 int duration();
125 Q_INVOKABLE void resetProperty(const QString &name);
126 Q_INVOKABLE void clearSimpleAnimation(const QString &name);
127 Mlt::Animation getAnimation(const QString &name);
128 Q_INVOKABLE int keyframeCount(const QString &name);
129 mlt_keyframe_type getKeyframeType(Mlt::Animation &animation, int position,
130 mlt_keyframe_type defaultType);
131 Q_INVOKABLE int getNextKeyframePosition(const QString &name, int position);
132 Q_INVOKABLE int getPrevKeyframePosition(const QString &name, int position);
133 Q_INVOKABLE bool isAtLeastVersion(const QString &version);
134 Q_INVOKABLE static void deselect();
135 bool allowTrim() const;
136 bool allowAnimateIn() const;
137 bool allowAnimateOut() const;
138 Q_INVOKABLE void crop(const QRectF &rect);
139 QString objectNameOrService();
140
141 Q_INVOKABLE void copyParameters();
142 Q_INVOKABLE void pasteParameters(const QStringList &propertyNames);
143
144 // Functions for undo/redo
145 void startUndoTracking();
146 Q_INVOKABLE void startUndoParameterCommand(const QString &desc = QString());
147 void startUndoAddKeyframeCommand();
148 void startUndoRemoveKeyframeCommand();
149 void startUndoModifyKeyframeCommand(int paramIndex, int keyframeIndex);
150 void updateUndoCommand(const QString &name);
151 Q_INVOKABLE void endUndoCommand();
152
153public slots:
154 void preset(const QString &name);
155
156signals:
157 void presetsChanged();
158 void analyzeFinished(bool isSuccess);
159 void changed(QString name = QString());
160 void inChanged(int delta);
161 void outChanged(int delta);
162 void animateInChanged();
163 void animateOutChanged();
164 void animateInOutChanged();
165 void durationChanged();
166 void propertyChanged(QString name); // Use to let QML know when a specific property has changed
167
168private:
169 const QmlMetadata *m_metadata;
170 Mlt::Service m_service;
171 Mlt::Producer m_producer;
172 QString m_path;
173 bool m_isNew;
174 QStringList m_presets;
175 Mlt::Properties m_previousState;
176 int m_changeInProgress;
177
178 int keyframeIndex(Mlt::Animation &animation, int position);
179};
180
181class AnalyzeDelegate : public QObject
182{
183 Q_OBJECT
184public:
185 explicit AnalyzeDelegate(Mlt::Filter &filter);
186
187public slots:
188 void onAnalyzeFinished(AbstractJob *job, bool isSuccess);
189
190private:
191 QString resultsFromXml(const QString &fileName);
192 void updateFilter(Mlt::Filter &filter, const QString &results);
193 void updateJob(EncodeJob *job, const QString &results);
194
195 QUuid m_uuid;
196};
197
198#endif // FILTER_H