]> git.sesse.net Git - kdenlive/blob - src/monitor.h
Correctly update monitors on clip property change
[kdenlive] / src / monitor.h
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 <QLabel>
24
25 #include <KIcon>
26 #include <KAction>
27 #include <KRestrictedLine>
28 #include <QDomElement>
29
30 #include "gentime.h"
31 #include "ui_monitor_ui.h"
32 #include "timecodedisplay.h"
33 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
34 #include "videoglwidget.h"
35 #endif
36
37 class MonitorManager;
38 class Render;
39 class SmallRuler;
40 class DocClipBase;
41 class MonitorScene;
42 class AbstractClipItem;
43 class Transition;
44 class ClipItem;
45 class QGraphicsView;
46 class QGraphicsPixmapItem;
47
48 class MonitorRefresh : public QWidget
49 {
50     Q_OBJECT
51 public:
52     MonitorRefresh(QWidget *parent = 0);
53     virtual void paintEvent(QPaintEvent *event);
54     void setRenderer(Render* render);
55
56 private:
57     Render *m_renderer;
58 };
59
60 class Overlay : public QLabel
61 {
62     Q_OBJECT
63 public:
64     Overlay(QWidget* parent);
65     void setOverlayText(const QString &, bool isZone = true);
66
67 private:
68     bool m_isZone;
69 };
70
71 class Monitor : public QWidget
72 {
73     Q_OBJECT
74
75 public:
76     Monitor(QString name, MonitorManager *manager, QString profile = QString(), QWidget *parent = 0);
77     virtual ~Monitor();
78     Render *render;
79     void resetProfile(const QString profile);
80     QString name() const;
81     void resetSize();
82     bool isActive() const;
83     void pause();
84     void setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu = NULL, QAction *loopClip = NULL);
85     const QString sceneList();
86     DocClipBase *activeClip();
87     GenTime position();
88     void checkOverlay();
89     void updateTimecodeFormat();
90     void updateMarkers(DocClipBase *source);
91     MonitorScene *getEffectScene();
92
93 protected:
94     virtual void mousePressEvent(QMouseEvent * event);
95     virtual void mouseReleaseEvent(QMouseEvent * event);
96
97     /** @brief Move to another position on mouse wheel event.
98      *
99      * Moves towards the end of the clip/timeline on mouse wheel down/back, the
100      * opposite on mouse wheel up/forward.
101      * Ctrl + wheel moves by a second, without Ctrl it moves by a single frame. */
102     virtual void wheelEvent(QWheelEvent * event);
103     virtual void mouseMoveEvent(QMouseEvent *event);
104     virtual QStringList mimeTypes() const;
105     /*virtual void dragMoveEvent(QDragMoveEvent * event);
106     virtual Qt::DropActions supportedDropActions() const;*/
107
108     //virtual void resizeEvent(QResizeEvent * event);
109     //virtual void paintEvent(QPaintEvent * event);
110
111 private:
112     Ui::Monitor_UI m_ui;
113     QString m_name;
114     MonitorManager *m_monitorManager;
115     DocClipBase *m_currentClip;
116     SmallRuler *m_ruler;
117     Overlay *m_overlay;
118     bool m_isActive;
119     double m_scale;
120     int m_length;
121     bool m_dragStarted;
122     MonitorRefresh *m_monitorRefresh;
123     KIcon m_playIcon;
124     KIcon m_pauseIcon;
125     TimecodeDisplay *m_timePos;
126     QAction *m_playAction;
127     /** Has to be available so we can enable and disable it. */
128     QAction *m_loopClipAction;
129     QMenu *m_contextMenu;
130     QMenu *m_configMenu;
131     QMenu *m_playMenu;
132     QMenu *m_markerMenu;
133     QPoint m_DragStartPosition;
134     MonitorScene *m_effectScene;
135     QGraphicsView *m_effectView;
136     /** Selected clip/transition in timeline. Used for looping it. */
137     AbstractClipItem *m_selectedClip;
138     /** true if selected clip is transition, false = selected clip is clip.
139      *  Necessary because sometimes we get two signals, e.g. we get a clip and we get selected transition = NULL. */
140     bool m_loopClipTransition;
141 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
142     VideoGLWidget *m_glWidget;
143     bool createOpenGlWidget(QVBoxLayout *rendererBox, const QString profile);
144 #endif
145
146     GenTime getSnapForPos(bool previous);
147
148 private slots:
149     void seekCursor(int pos);
150     void rendererStopped(int pos);
151     void slotExtractCurrentFrame();
152     void slotSetThumbFrame();
153     void slotSetSizeOneToOne();
154     void slotSetSizeOneToTwo();
155     void slotSaveZone();
156     void slotSeek();
157     void setClipZone(QPoint pos);
158     void slotSwitchMonitorInfo(bool show);
159     void slotSwitchDropFrames(bool show);
160     void slotGoToMarker(QAction *action);
161
162 public slots:
163     void slotOpenFile(const QString &);
164     void slotSetXml(DocClipBase *clip, QPoint zone = QPoint(), const int position = -1);
165     void refreshMonitor(bool visible);
166     void refreshMonitor();
167     void slotSeek(int pos);
168     void stop();
169     void start();
170     void activateMonitor();
171     void slotPlay();
172     void slotPlayZone();
173     void slotLoopZone();
174     /** @brief Loops the selected item (clip or transition). */
175     void slotLoopClip();
176     void slotForward(double speed = 0);
177     void slotRewind(double speed = 0);
178     void slotRewindOneFrame(int diff = 1);
179     void slotForwardOneFrame(int diff = 1);
180     void saveSceneList(QString path, QDomElement info = QDomElement());
181     void slotStart();
182     void slotEnd();
183     void slotSetZoneStart();
184     void slotSetZoneEnd();
185     void slotZoneStart();
186     void slotZoneEnd();
187     void slotZoneMoved(int start, int end);
188     void slotSeekToNextSnap();
189     void slotSeekToPreviousSnap();
190     void adjustRulerSize(int length);
191     void setTimePos(const QString &pos);
192     QStringList getZoneInfo() const;
193     void slotEffectScene(bool show = true);
194     bool effectSceneDisplayed();
195
196     /** @brief Sets m_selectedClip to @param item. Used for looping it. */
197     void slotSetSelectedClip(AbstractClipItem *item);
198     void slotSetSelectedClip(ClipItem *item);
199     void slotSetSelectedClip(Transition *item);
200
201 signals:
202     void renderPosition(int);
203     void durationChanged(int);
204     void refreshClipThumbnail(const QString &);
205     void adjustMonitorSize();
206     void zoneUpdated(QPoint);
207     void saveZone(Render *, QPoint);
208     /** @brief  Editing transitions / effects over the monitor requires the renderer to send frames as QImage.
209      *      This causes a major slowdown, so we only enable it if required */
210     void requestFrameForAnalysis(bool);
211 };
212
213 #endif