File indexing completed on 2024-04-21 04:51:50
0001 /* 0002 SPDX-FileCopyrightText: 2018 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 This file is part of Kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #pragma once 0009 0010 #include "definitions.h" 0011 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 0012 #include "videowidget.h" 0013 #else // Qt6 0014 #include "glwidget.h" 0015 #endif 0016 #include <QImage> 0017 #include <QObject> 0018 #include <QUrl> 0019 0020 class TimecodeDisplay; 0021 0022 /** @class MonitorProxy 0023 @brief This class is a wrapper around the monitor / glwidget and handles communication 0024 with the qml overlay through its properties. 0025 */ 0026 class MonitorProxy : public QObject 0027 { 0028 Q_OBJECT 0029 // Q_PROPERTY(int consumerPosition READ consumerPosition NOTIFY consumerPositionChanged) 0030 Q_PROPERTY(int position MEMBER m_position WRITE setPosition NOTIFY positionChanged) 0031 Q_PROPERTY(QPoint profile READ profile NOTIFY profileChanged) 0032 Q_PROPERTY(int seekFinished MEMBER m_seekFinished NOTIFY seekFinishedChanged) 0033 Q_PROPERTY(int zoneIn READ zoneIn WRITE setZoneIn NOTIFY zoneChanged) 0034 Q_PROPERTY(int zoneOut READ zoneOut WRITE setZoneOut NOTIFY zoneChanged) 0035 Q_PROPERTY(int rulerHeight READ rulerHeight WRITE setRulerHeight NOTIFY rulerHeightChanged) 0036 Q_PROPERTY(QString markerComment MEMBER m_markerComment NOTIFY markerChanged) 0037 Q_PROPERTY(QColor markerColor MEMBER m_markerColor NOTIFY markerChanged) 0038 Q_PROPERTY(QString timecode READ timecode NOTIFY timecodeChanged) 0039 Q_PROPERTY(QString trimmingTC1 READ trimmingTC1 NOTIFY trimmingTC1Changed) 0040 Q_PROPERTY(QString trimmingTC2 READ trimmingTC2 NOTIFY trimmingTC2Changed) 0041 Q_PROPERTY(QList <int> audioStreams MEMBER m_audioStreams NOTIFY audioThumbChanged) 0042 Q_PROPERTY(QList <int> audioChannels MEMBER m_audioChannels NOTIFY audioThumbChanged) 0043 Q_PROPERTY(int clipBounds MEMBER m_boundsCount NOTIFY clipBoundsChanged) 0044 Q_PROPERTY(int overlayType READ overlayType WRITE setOverlayType NOTIFY overlayTypeChanged) 0045 Q_PROPERTY(double speed MEMBER m_speed NOTIFY speedChanged) 0046 Q_PROPERTY(QColor thumbColor1 READ thumbColor1 NOTIFY colorsChanged) 0047 Q_PROPERTY(QColor thumbColor2 READ thumbColor2 NOTIFY colorsChanged) 0048 Q_PROPERTY(QColor overlayColor READ overlayColor NOTIFY colorsChanged) 0049 Q_PROPERTY(bool autoKeyframe READ autoKeyframe NOTIFY autoKeyframeChanged) 0050 Q_PROPERTY(bool audioThumbFormat READ audioThumbFormat NOTIFY audioThumbFormatChanged) 0051 Q_PROPERTY(bool audioThumbNormalize READ audioThumbNormalize NOTIFY audioThumbNormalizeChanged) 0052 Q_PROPERTY(QStringList lastClips MEMBER m_lastClips NOTIFY lastClipsChanged) 0053 /** @brief Returns true if current clip in monitor has Audio and Video 0054 * */ 0055 Q_PROPERTY(bool clipHasAV MEMBER m_hasAV NOTIFY clipHasAVChanged) 0056 /** @brief Contains the name of clip currently displayed in monitor 0057 * */ 0058 Q_PROPERTY(QString clipName MEMBER m_clipName NOTIFY clipNameChanged) 0059 Q_PROPERTY(QString clipStream MEMBER m_clipStream NOTIFY clipStreamChanged) 0060 /** @brief Contains the name of clip currently displayed in monitor 0061 * */ 0062 Q_PROPERTY(int clipType MEMBER m_clipType NOTIFY clipTypeChanged) 0063 Q_PROPERTY(int clipId MEMBER m_clipId NOTIFY clipIdChanged) 0064 Q_PROPERTY(QStringList runningJobs MEMBER m_runningJobs NOTIFY runningJobsChanged) 0065 Q_PROPERTY(QList<int> jobsProgress MEMBER m_jobsProgress NOTIFY jobsProgressChanged) 0066 Q_PROPERTY(QStringList jobsUuids MEMBER m_jobsUuids NOTIFY jobsProgressChanged) 0067 0068 public: 0069 MonitorProxy(VideoWidget *parent); 0070 /** brief: Returns true if we are still in a seek operation 0071 * */ 0072 int rulerHeight() const; 0073 int overlayType() const; 0074 void setOverlayType(int ix); 0075 const QString trimmingTC1() const; 0076 const QString trimmingTC2() const; 0077 const QString timecode() const; 0078 int getPosition() const; 0079 /** @brief update position and end seeking if we reached the requested seek position. 0080 * returns true if the position was unchanged, false otherwise 0081 * */ 0082 Q_INVOKABLE bool setPosition(int pos); 0083 bool setPositionAdvanced(int pos, bool noAudioScrub); 0084 Q_INVOKABLE void seek(int delta, uint modifiers); 0085 Q_INVOKABLE QColor thumbColor1() const; 0086 Q_INVOKABLE QColor thumbColor2() const; 0087 Q_INVOKABLE QColor overlayColor() const; 0088 Q_INVOKABLE QByteArray getUuid() const; 0089 Q_INVOKABLE void selectClip(int ix); 0090 Q_INVOKABLE const QPoint clipBoundary(int ix); 0091 bool audioThumbFormat() const; 0092 bool audioThumbNormalize() const; 0093 void positionFromConsumer(int pos, bool playing); 0094 void setMarker(const QString &comment, const QColor &color); 0095 int zoneIn() const; 0096 int zoneOut() const; 0097 void setZoneIn(int pos); 0098 void setZoneOut(int pos); 0099 Q_INVOKABLE void setZone(int in, int out, bool sendUpdate = true); 0100 /** brief: Activate clip monitor if param is true, project monitor otherwise 0101 * */ 0102 Q_INVOKABLE void activateClipMonitor(bool isClipMonitor); 0103 void setZone(QPoint zone, bool sendUpdate = true); 0104 void resetZone(); 0105 QPoint zone() const; 0106 Q_INVOKABLE QString toTimecode(int frames) const; 0107 Q_INVOKABLE void startZoneMove(); 0108 Q_INVOKABLE void endZoneMove(); 0109 Q_INVOKABLE double fps() const; 0110 Q_INVOKABLE void switchAutoKeyframe(); 0111 Q_INVOKABLE bool autoKeyframe() const; 0112 Q_INVOKABLE void setWidgetKeyBinding(const QString &text = QString()) const; 0113 Q_INVOKABLE bool seekOnDrop() const; 0114 Q_INVOKABLE void addEffect(const QString &effectData, const QString &effectSource); 0115 Q_INVOKABLE void terminateJob(const QString &uuid); 0116 QPoint profile(); 0117 QImage extractFrame(const QString &path = QString(), int width = -1, int height = -1, bool useSourceProfile = false); 0118 void setClipProperties(int clipId, ClipType::ProducerType type, bool hasAV, const QString &clipName); 0119 void setAudioThumb(const QList <int> &streamIndexes = QList <int>(), const QList <int> &channels = QList <int>()); 0120 void setAudioStream(const QString &name); 0121 void setRulerHeight(int height); 0122 /** @brief Store a reference to the timecode display */ 0123 void setTimeCode(TimecodeDisplay *td); 0124 /** @brief Set position in frames to be displayed in the monitor overlay for preview tile one 0125 * @param frames Position in frames 0126 * @param isRelative Whether @p frames is the absoulute position (overwrite current) or an offset position (subtract from current) 0127 */ 0128 void setTrimmingTC1(int frames, bool isRelativ = false); 0129 /** @brief Set position in frames to be displayed in the monitor overlay for preview tile two 0130 * @see setTrimmingTC1 0131 */ 0132 void setTrimmingTC2(int frames, bool isRelativ = false); 0133 /** @brief When the producer changes, ensure we reset the stored position*/ 0134 void resetPosition(); 0135 /** @brief Used to display qml info about speed*/ 0136 void setSpeed(double speed); 0137 void setJobsProgress(const ObjectId &owner, const QStringList &jobNames, const QList<int> &jobProgress, const QStringList &jobUuids); 0138 0139 Q_SIGNALS: 0140 void positionChanged(int); 0141 void seekFinishedChanged(); 0142 void requestSeek(int pos, bool noAudioScrub); 0143 void zoneChanged(); 0144 void saveZone(const QPoint zone); 0145 void saveZoneWithUndo(const QPoint, const QPoint&); 0146 void markerChanged(); 0147 void rulerHeightChanged(); 0148 void addSnap(int); 0149 void removeSnap(int); 0150 void triggerAction(const QString &name); 0151 void overlayTypeChanged(); 0152 void seekNextKeyframe(); 0153 void seekPreviousKeyframe(); 0154 void addRemoveKeyframe(); 0155 void seekToKeyframe(); 0156 void clipHasAVChanged(); 0157 void clipNameChanged(); 0158 void clipStreamChanged(); 0159 void clipTypeChanged(); 0160 void clipIdChanged(); 0161 void audioThumbChanged(); 0162 void colorsChanged(); 0163 void audioThumbFormatChanged(); 0164 void audioThumbNormalizeChanged(); 0165 void profileChanged(); 0166 void autoKeyframeChanged(); 0167 void timecodeChanged(); 0168 void trimmingTC1Changed(); 0169 void trimmingTC2Changed(); 0170 void speedChanged(); 0171 void clipBoundsChanged(); 0172 void runningJobsChanged(); 0173 void jobsProgressChanged(); 0174 void addTimelineEffect(const QStringList &); 0175 void lastClipsChanged(); 0176 0177 private: 0178 VideoWidget *q; 0179 int m_position; 0180 int m_zoneIn; 0181 int m_zoneOut; 0182 bool m_hasAV; 0183 double m_speed; 0184 QList <int> m_audioStreams; 0185 QList <int> m_audioChannels; 0186 QString m_markerComment; 0187 QColor m_markerColor; 0188 QString m_clipName; 0189 QString m_clipStream; 0190 int m_clipType; 0191 int m_clipId; 0192 bool m_seekFinished; 0193 QPoint m_undoZone; 0194 TimecodeDisplay *m_td; 0195 int m_trimmingFrames1; 0196 int m_trimmingFrames2; 0197 QVector <QPoint> m_clipBounds; 0198 int m_boundsCount; 0199 QStringList m_runningJobs; 0200 QList<int> m_jobsProgress; 0201 QStringList m_jobsUuids; 0202 QVector<std::pair<int, QString>> m_lastClipsIds; 0203 QStringList m_lastClips; 0204 0205 public Q_SLOTS: 0206 void updateClipBounds(const QVector <QPoint>&bounds); 0207 void clipDeleted(int cid); 0208 void documentClosed(); 0209 void extractFrameToFile(int frame_position, const QStringList &pathInfo, bool addToProject = false, bool useSourceProfile = false); 0210 0211 private Q_SLOTS: 0212 void updateClipName(int id, const QString newName); 0213 };