]> git.sesse.net Git - kdenlive/blob - src/stopmotion/stopmotion.h
Cleanup: remove duplicate monitor code, allow fullscreen for record monitor
[kdenlive] / src / stopmotion / stopmotion.h
1 /***************************************************************************
2                           titlewidget.h  -  description
3                              -------------------
4     begin                : Feb 28 2008
5     copyright            : (C) 2008 by Marco Gittler
6     email                : g.marco@freenet.de
7  ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef STOPMOTION_H
19 #define STOPMOTION_H
20
21 #include "ui_stopmotion_ui.h"
22 #include "definitions.h"
23
24 #include <KUrl>
25 #include <QLabel>
26 #include <QFuture>
27 #include <QVBoxLayout>
28 #include <QTimer>
29 #include <abstractmonitor.h>
30
31 class MltDeviceCapture;
32 class MonitorManager;
33 class VideoPreviewContainer;
34 class MltVideoProfile;
35
36 class MyLabel : public QLabel
37 {
38     Q_OBJECT
39 public:
40     MyLabel(QWidget* parent = 0);
41     void setImage(QImage img);
42
43 protected:
44     virtual void paintEvent(QPaintEvent* event);
45     virtual void wheelEvent(QWheelEvent* event);
46     virtual void mousePressEvent(QMouseEvent*);
47
48 private:
49     QImage m_img;
50
51 signals:
52     /** @brief Seek to next or previous frame.
53      *  @param forward set to true to go to next frame, fals to go to previous frame */
54     void seek(bool forward);
55
56     /** @brief Switch to live view. */
57     void switchToLive();
58 };
59
60
61 class StopmotionMonitor : public AbstractMonitor
62 {
63     Q_OBJECT
64 public:
65     StopmotionMonitor(MonitorManager *manager, QWidget *parent);
66     ~StopmotionMonitor();
67     AbstractRender *abstractRender();
68     Kdenlive::MONITORID id() const;
69     void setRender(MltDeviceCapture *render);
70     void pause();
71     void unpause();
72
73 private:
74     MltDeviceCapture *m_captureDevice;
75
76 public slots:
77     void stop();
78     void start();
79     void slotPlay();
80     void slotMouseSeek(int eventDelta, bool fast);
81     void slotSwitchFullScreen();
82
83 signals:
84     void stopCapture();
85 };
86
87
88 class StopmotionWidget : public QDialog, public Ui::Stopmotion_UI
89 {
90     Q_OBJECT
91
92 public:
93
94     /** @brief Build the stopmotion dialog.
95      * @param projectFolder The current project folder, where captured files will be stored.
96      * @param actions The actions for this widget that can have a keyboard shortcut.
97      * @param parent (optional) parent widget */
98     StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent = 0);
99     virtual ~StopmotionWidget();
100
101 protected:
102     virtual void closeEvent(QCloseEvent* e);
103
104 private:
105     /** @brief Current project folder (where the captured frames will be saved). */
106     KUrl m_projectFolder;
107
108     /** @brief Capture holder that will handle all video operation. */
109     MltDeviceCapture *m_captureDevice;
110
111     VideoContainer *m_videoBox;
112
113     /** @brief Holds the name of the current sequence.
114      * Files will be saved in project folder with name: sequence001.png */
115     QString m_sequenceName;
116
117     /** @brief Holds the frame number of the current sequence. */
118     int m_sequenceFrame;
119
120     QAction* m_captureAction;
121
122     /** @brief Holds the index of the frame to be displayed in the frame preview mode. */
123     int m_animatedIndex;
124
125     /** @brief Find all stopmotion sequences in current project folder. */
126     void parseExistingSequences();
127
128     /** @brief Select a frame in the list. */
129     void selectFrame(int ix);
130
131     /** @brief This widget will hold the frame preview. */
132     MyLabel* m_frame_preview;
133
134     /** @brief The list of files in the sequence to create thumbnails. */
135     QStringList m_filesList;
136
137     /** @brief Holds the state of the threaded thumbnail generation. */
138     QFuture<void> m_future;
139
140     /** @brief Get the frame number ix. */
141     QListWidgetItem* getFrameFromIndex(int ix);
142
143     /** @brief The action triggering display of last frame over current live video feed. */
144     QAction* m_showOverlay;
145
146     /** @brief The list of all frames path. */
147     QStringList m_animationList;
148     
149     /** @brief Tells if we are in animation (playback) mode. */
150     bool m_animate;
151     
152     /** @brief Timer for interval capture. */
153     QTimer m_intervalTimer;
154
155     MonitorManager *m_manager;
156
157     /** @brief The monitor is used to control the v4l capture device from the monitormanager class. */
158     StopmotionMonitor *m_monitor;
159
160     /** @brief Create the XML playlist. */
161     const QString createProducer(MltVideoProfile profile, const QString &service, const QString &resource);
162
163     /** @brief A new frame arrived, reload overlay. */
164     void reloadOverlay();
165
166     /** @brief Holds the index of the effect to be applied to the video feed. */
167     int m_effectIndex;
168
169
170 public slots:
171     /** @brief Display the live feed from capture device.
172      @param isOn enable or disable the feature */
173     void slotLive(bool isOn = true);
174     void slotStopCapture();
175
176 private slots:
177
178     /** @brief Display the last captured frame over current live feed.
179      @param isOn enable or disable the feature */
180     void slotShowOverlay(bool isOn);
181
182     /** @brief Display the last captured frame over current live feed. */
183     void slotUpdateOverlay();
184
185     /** @brief User changed the capture name. */
186     void sequenceNameChanged(const QString& name);
187
188     /** @brief Grab a frame from current capture feed. */
189     void slotCaptureFrame();
190
191     /** @brief Display a previous frame in monitor. */
192     void slotShowFrame(const QString& path);
193
194     /** @brief Get full path for a frame in the sequence.
195      *  @param ix the frame number.
196      *  @param seqName (optional) the name of the sequence. */
197     QString getPathForFrame(int ix, QString seqName = QString());
198
199     /** @brief Add sequence to current project. */
200     void slotAddSequence();
201
202     /** @brief Display selected fram in monitor. */
203     void slotShowSelectedFrame();
204
205     /** @brief Start animation preview mode. */
206     void slotPlayPreview(bool animate);
207
208     /** @brief Simulate animation. */
209     void slotAnimate();
210
211     /** @brief Seek to previous or next captured frame.
212      *  @param forward set to true for next frame, false for previous one. */
213     void slotSeekFrame(bool forward);
214
215     /** @brief Display warning / error message from capture backend. */
216     void slotGotHDMIMessage(const QString& message);
217
218     /** @brief Create thumbnails for existing sequence frames. */
219     void slotCreateThumbs(QImage img, int ix);
220
221     /** @brief Prepare thumbnails creation. */
222     void slotPrepareThumbs();
223
224     /** @brief Called when user switches the video capture backend. */
225     void slotUpdateDeviceHandler();
226
227     /** @brief Show / hide sequence thumbnails. */
228     void slotShowThumbs(bool show);
229
230     /** @brief Show the config dialog */
231     void slotConfigure();
232
233     /** @brief Prepare to crete thumb for newly captured frame. */
234     void slotNewThumb(const QString &path);
235
236     /** @brief Set the effect to be applied to overlay frame. */
237     void slotUpdateOverlayEffect(QAction* act);
238
239     /** @brief Switch between live view / currently selected frame. */
240     void slotSwitchLive();
241
242     /** @brief Delete current frame from disk. */
243     void slotRemoveFrame();
244     
245     /** @brief Enable / disable frame analysis (in color scopes). */
246     void slotSwitchAnalyse(bool isOn);
247
248     /** @brief Enable / disable horizontal mirror effect. */
249     void slotSwitchMirror(bool isOn);
250     
251     /** @brief Send a notification a few seconds before capturing. */
252     void slotPreNotify();
253
254 signals:
255     /** @brief Ask to add sequence to current project. */
256     void addOrUpdateSequence(const QString &);
257
258     void doCreateThumbs(QImage, int);
259     void gotFrame(QImage);
260 };
261
262 #endif