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