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 setRectNoUndo(const QString &name, const QRectF &rect);
101 Q_INVOKABLE void setGradient(QString name, const QStringList &gradient);
102 QString path() const { return m_path; }
103 Q_INVOKABLE void loadPresets();
104 QStringList presets() const { return m_presets; }
106 Q_INVOKABLE int savePreset(const QStringList &propertyNames, const QString &name = QString());
107 Q_INVOKABLE void deletePreset(const QString &name);
108 Q_INVOKABLE void analyze(bool isAudio = false, bool deferJob = true);
109 Q_INVOKABLE static int framesFromTime(const QString &time);
110 Q_INVOKABLE void getHash();
111 Mlt::Producer &producer() { return m_producer; }
112 int in();
113 int out();
114 Mlt::Service &service() { return m_service; }
115 int animateIn();
116 void setAnimateIn(int value);
117 int animateOut();
118 void setAnimateOut(int value);
119 void clearAnimateInOut();
120 int duration();
121 Q_INVOKABLE void resetProperty(const QString &name);
122 Q_INVOKABLE void clearSimpleAnimation(const QString &name);
123 Mlt::Animation getAnimation(const QString &name);
124 Q_INVOKABLE int keyframeCount(const QString &name);
125 mlt_keyframe_type getKeyframeType(Mlt::Animation &animation,
126 int position,
127 mlt_keyframe_type defaultType);
128 Q_INVOKABLE int getKeyFrameType(const QString &name, int keyIndex);
129 Q_INVOKABLE void setKeyFrameType(const QString &name, int keyIndex, int type);
130 Q_INVOKABLE int getNextKeyframePosition(const QString &name, int position);
131 Q_INVOKABLE int getPrevKeyframePosition(const QString &name, int position);
132 Q_INVOKABLE bool isAtLeastVersion(const QString &version);
133 Q_INVOKABLE static void deselect();
134 bool allowTrim() const;
135 bool allowAnimateIn() const;
136 bool allowAnimateOut() const;
137 Q_INVOKABLE void crop(const QRectF &rect);
138 QString objectNameOrService();
139
140 Q_INVOKABLE void copyParameters();
141 Q_INVOKABLE void pasteParameters(const QStringList &propertyNames);
142
143 // Functions for undo/redo
144 void startUndoTracking();
145 void stopUndoTracking();
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