1/***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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 2 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, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20#ifndef MONITOR_H
21#define MONITOR_H
22
23#include "abstractmonitor.h"
24
25#include "gentime.h"
26#include "renderer.h"
27#include "definitions.h"
28#include "timecodedisplay.h"
29#ifdef USE_OPENGL
30#include "monitor/videoglwidget.h"
31#endif
32
33#include <QLabel>
34#include <QDomElement>
35#include <QToolBar>
36
37#include <KIcon>
38
39class SmallRuler;
40class DocClipBase;
41class AbstractClipItem;
42class Transition;
43class ClipItem;
44class MonitorEditWidget;
45class Monitor;
46class MonitorManager;
47class QSlider;
48
49
50class Overlay : public QLabel
51{
52 Q_OBJECT
53public:
54 Overlay(QWidget* parent = 0);
55 void setOverlayText(const QString &, bool isZone = true);
56
57protected:
58 void mouseDoubleClickEvent ( QMouseEvent * event );
59 void mousePressEvent ( QMouseEvent * event );
60 void mouseReleaseEvent ( QMouseEvent * event );
61
62signals:
63 void editMarker();
64};
65
66class Monitor : public AbstractMonitor
67{
68 Q_OBJECT
69
70public:
71 Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QString profile = QString(), QWidget *parent = 0);
72 ~Monitor();
73 Render *render;
74 AbstractRender *abstractRender();
75 void resetProfile(const QString &profile);
76 void setCustomProfile(const QString &profile, const Timecode &tc);
77 void resetSize();
78 void pause();
79 void setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu = NULL, QAction *loopClip = NULL);
80 const QString sceneList();
81 DocClipBase *activeClip();
82 GenTime position();
83 void checkOverlay();
84 void updateTimecodeFormat();
85 void updateMarkers(DocClipBase *source);
86 void setMarkers(const QList <CommentedTime> &markers);
87 MonitorEditWidget *getEffectEdit();
88 QWidget *container();
89 void reloadProducer(const QString &id);
90 QFrame *m_volumePopup;
91 /** @brief Reimplemented from QWidget, updates the palette colors. */
92 void setPalette ( const QPalette & p);
93 /** @brief Returns a hh:mm:ss timecode from a frame number. */
94 QString getTimecodeFromFrames(int pos);
95 /** @brief Returns current project's fps. */
96 double fps() const;
97 /** @brief Get url for the clip's thumbnail */
98 QString getMarkerThumb(GenTime pos);
99
100protected:
101 void mousePressEvent(QMouseEvent * event);
102 void mouseReleaseEvent(QMouseEvent * event);
103 void mouseDoubleClickEvent(QMouseEvent * event);
104 void resizeEvent(QResizeEvent *event);
105
106 /** @brief Move to another position on mouse wheel event.
107 *
108 * Moves towards the end of the clip/timeline on mouse wheel down/back, the
109 * opposite on mouse wheel up/forward.
110 * Ctrl + wheel moves by a second, without Ctrl it moves by a single frame. */
111 void wheelEvent(QWheelEvent * event);
112 void mouseMoveEvent(QMouseEvent *event);
113 virtual QStringList mimeTypes() const;
114
115 /*virtual void dragMoveEvent(QDragMoveEvent * event);
116 virtual Qt::DropActions supportedDropActions() const;*/
117
118 //virtual void resizeEvent(QResizeEvent * event);
119 //virtual void paintEvent(QPaintEvent * event);
120
121private:
122 DocClipBase *m_currentClip;
123 SmallRuler *m_ruler;
124 Overlay *m_overlay;
125 int m_length;
126 bool m_dragStarted;
127 KIcon m_playIcon;
128 KIcon m_pauseIcon;
129 TimecodeDisplay *m_timePos;
130 QAction *m_playAction;
131 /** Has to be available so we can enable and disable it. */
132 QAction *m_loopClipAction;
133 QMenu *m_contextMenu;
134 QMenu *m_configMenu;
135 QMenu *m_playMenu;
136 QMenu *m_markerMenu;
137 QPoint m_DragStartPosition;
138 MonitorEditWidget *m_effectWidget;
139 /** Selected clip/transition in timeline. Used for looping it. */
140 AbstractClipItem *m_selectedClip;
141 /** true if selected clip is transition, false = selected clip is clip.
142 * Necessary because sometimes we get two signals, e.g. we get a clip and we get selected transition = NULL. */
143 bool m_loopClipTransition;
144
145#ifdef USE_OPENGL
146 VideoGLWidget *m_glWidget;
147 bool createOpenGlWidget(QWidget *parent, const QString &profile);
148#endif
149
150 GenTime getSnapForPos(bool previous);
151 Qt::WindowFlags m_baseFlags;
152 QToolBar *m_toolbar;
153 QWidget *m_volumeWidget;
154 QSlider *m_audioSlider;
155 QAction *m_editMarker;
156
157private slots:
158 void seekCursor(int pos);
159 void rendererStopped(int pos);
160 void slotExtractCurrentFrame();
161 void slotSetThumbFrame();
162 void slotSetSizeOneToOne();
163 void slotSetSizeOneToTwo();
164 void slotSaveZone();
165 void slotSeek();
166 void setClipZone(const QPoint &pos);
167 void slotSwitchMonitorInfo(bool show);
168 void slotSwitchDropFrames(bool show);
169 void slotGoToMarker(QAction *action);
170 void slotSetVolume(int volume);
171 void slotShowVolume();
172 void slotEditMarker();
173 void slotExtractCurrentZone();
174
175public slots:
176 void slotOpenFile(const QString &);
177 void slotSetClipProducer(DocClipBase *clip, QPoint zone = QPoint(), bool forceUpdate = false, int position = -1);
178 void updateClipProducer(Mlt::Producer *prod);
179 void refreshMonitor(bool visible);
180 void refreshMonitor();
181 void slotSeek(int pos);
182 void stop();
183 void start();
184 void slotPlay();
185 void slotPlayZone();
186 void slotLoopZone();
187 /** @brief Loops the selected item (clip or transition). */
188 void slotLoopClip();
189 void slotForward(double speed = 0);
190 void slotRewind(double speed = 0);
191 void slotRewindOneFrame(int diff = 1);
192 void slotForwardOneFrame(int diff = 1);
193 void saveSceneList(const QString &path, const QDomElement &info = QDomElement());
194 void slotStart();
195 void slotEnd();
196 void slotSetZoneStart();
197 void slotSetZoneEnd();
198 void slotZoneStart();
199 void slotZoneEnd();
200 void slotZoneMoved(int start, int end);
201 void slotSeekToNextSnap();
202 void slotSeekToPreviousSnap();
203 void adjustRulerSize(int length);
204 void setTimePos(const QString &pos);
205 QStringList getZoneInfo() const;
206 /** @brief Display the on monitor effect scene (to adjust geometry over monitor). */
207 void slotShowEffectScene(bool show = true, bool manuallyTriggered = false);
208 bool effectSceneDisplayed();
209
210 /** @brief Sets m_selectedClip to @param item. Used for looping it. */
211 void slotSetSelectedClip(AbstractClipItem *item);
212 void slotSetSelectedClip(ClipItem *item);
213 void slotSetSelectedClip(Transition *item);
214 void slotMouseSeek(int eventDelta, bool fast);
215 void slotSwitchFullScreen();
216
217signals:
218 void renderPosition(int);
219 void durationChanged(int);
220 void refreshClipThumbnail(const QString &, bool);
221 void adjustMonitorSize();
222 void zoneUpdated(const QPoint&);
223 void saveZone(Render *, const QPoint&, DocClipBase *);
224 /** @brief Editing transitions / effects over the monitor requires the renderer to send frames as QImage.
225 * This causes a major slowdown, so we only enable it if required */
226 void requestFrameForAnalysis(bool);
227 /** @brief Request a zone extraction (ffmpeg transcoding). */
228 void extractZone(const QString &id, const QPoint &zone);
229};
230
231#endif
232