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 "qmlmetadata.h"
22#include "shotcut_mlt_properties.h"
23
24#include <MltAnimation.h>
25#include <MltProducer.h>
26#include <MltService.h>
27#include <QColor>
28#include <QObject>
29#include <QRectF>
30#include <QString>
31#include <QUuid>
32#include <QVariant>
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 { NoCurrentFilter = -1, DeselectCurrentFilter = -2 };
54 Q_ENUM(CurrentFilterIndex)
55
56 explicit QmlFilter();
57 explicit QmlFilter(Mlt::Service &mltService,
58 const QmlMetadata *metadata,
59 QObject *parent = nullptr);
60 ~QmlFilter();
61
62 bool isNew() const { return m_isNew; }
63 void setIsNew(bool isNew) { m_isNew = isNew; }
64
65 Q_INVOKABLE QString get(QString name, int position = -1);
66 Q_INVOKABLE QColor getColor(QString name, int position = -1);
67 Q_INVOKABLE double getDouble(QString name, int position = -1);
68 Q_INVOKABLE QRectF getRect(QString name, int position = -1);
69 Q_INVOKABLE void removeRectPercents(QString name);
70 Q_INVOKABLE QStringList getGradient(QString name);
71 Q_INVOKABLE void set(QString name, QString value, int position = -1);
72 Q_INVOKABLE void set(QString name,
73 const QColor &value,
74 int position = -1,
75 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
76 Q_INVOKABLE void set(QString name,
77 double value,
78 int position = -1,
79 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
80 Q_INVOKABLE void set(QString name,
81 int value,
82 int position = -1,
83 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
84 Q_INVOKABLE void set(QString name,
85 bool value,
86 int position = -1,
87 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
88 Q_INVOKABLE void set(QString name,
89 double x,
90 double y,
91 double width,
92 double height,
93 double opacity = 1.0,
94 int position = -1,
95 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
96 Q_INVOKABLE void set(QString name,
97 const QRectF &rect,
98 int position = -1,
99 mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
100 Q_INVOKABLE void setGradient(QString name, const QStringList &gradient);
101 QString path() const { return m_path; }
102 Q_INVOKABLE void loadPresets();
103 QStringList presets() const { return m_presets; }
105 Q_INVOKABLE int savePreset(const QStringList &propertyNames, const QString &name = QString());
106 Q_INVOKABLE void deletePreset(const QString &name);
107 Q_INVOKABLE void analyze(bool isAudio = false, bool deferJob = true);
108 Q_INVOKABLE static int framesFromTime(const QString &time);
109 Q_INVOKABLE void getHash();
110 Mlt::Producer &producer() { return m_producer; }
111 int in();
112 int out();
113 Mlt::Service &service() { return m_service; }
114 int animateIn();
115 void setAnimateIn(int value);
116 int animateOut();
117 void setAnimateOut(int value);
118 void clearAnimateInOut();
119 int duration();
120 Q_INVOKABLE void resetProperty(const QString &name);
121 Q_INVOKABLE void clearSimpleAnimation(const QString &name);
122 Mlt::Animation getAnimation(const QString &name);
123 Q_INVOKABLE int keyframeCount(const QString &name);
124 mlt_keyframe_type getKeyframeType(Mlt::Animation &animation,
125 int position,
126 mlt_keyframe_type defaultType);
127 Q_INVOKABLE int getKeyFrameType(const QString &name, int keyIndex);
128 Q_INVOKABLE void setKeyFrameType(const QString &name, int keyIndex, int type);
129 Q_INVOKABLE int getNextKeyframePosition(const QString &name, int position);
130 Q_INVOKABLE int getPrevKeyframePosition(const QString &name, int position);
131 Q_INVOKABLE bool isAtLeastVersion(const QString &version);
132 Q_INVOKABLE static void deselect();
133 bool allowTrim() const;
134 bool allowAnimateIn() const;
135 bool allowAnimateOut() const;
136 Q_INVOKABLE void crop(const QRectF &rect);
137 QString objectNameOrService();
138
139 Q_INVOKABLE void copyParameters();
140 Q_INVOKABLE void pasteParameters(const QStringList &propertyNames);
141
142 // Functions for undo/redo
143 void startUndoTracking();
144 void stopUndoTracking();
145 Q_INVOKABLE void startUndoParameterCommand(const QString &desc = QString());
146 void startUndoAddKeyframeCommand();
147 void startUndoRemoveKeyframeCommand();
148 void startUndoModifyKeyframeCommand(int paramIndex, int keyframeIndex);
149 void updateUndoCommand(const QString &name);
150 Q_INVOKABLE void endUndoCommand();
151
152public slots:
153 void preset(const QString &name);
154
155signals:
156 void presetsChanged();
157 void analyzeFinished(bool isSuccess);
158 void changed(QString name = QString());
159 void inChanged(int delta);
160 void outChanged(int delta);
161 void animateInChanged();
162 void animateOutChanged();
163 void animateInOutChanged();
164 void durationChanged();
165 void propertyChanged(QString name); // Use to let QML know when a specific property has changed
166
167private:
168 const QmlMetadata *m_metadata;
169 Mlt::Service m_service;
170 Mlt::Producer m_producer;
171 QString m_path;
172 bool m_isNew;
173 QStringList m_presets;
174 Mlt::Properties m_previousState;
175 int m_changeInProgress;
176
177 int keyframeIndex(Mlt::Animation &animation, int position);
178};
179
180class AnalyzeDelegate : public QObject
181{
182 Q_OBJECT
183public:
184 explicit AnalyzeDelegate(Mlt::Filter &filter);
185
186public slots:
187 void onAnalyzeFinished(AbstractJob *job, bool isSuccess);
188
189private:
190 QString resultsFromXml(const QString &fileName);
191 void updateFilter(Mlt::Filter &filter, const QString &results);
192 void updateJob(EncodeJob *job, const QString &results);
193
194 QUuid m_uuid;
195};
196
197#endif // FILTER_H