]> git.sesse.net Git - kdenlive/blob - src/stopmotion/stopmotion.h
Bring back overlay & effects in stopmotion widget, rewrite of decklink capture to...
[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 "../blackmagic/capture.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(QWidget *parent);
66     ~StopmotionMonitor();
67     AbstractRender *abstractRender();
68     const QString name() const;
69     void setRender(MltDeviceCapture *render);
70
71 private:
72     MltDeviceCapture *m_captureDevice;
73
74 public slots:
75     virtual void stop();
76     virtual void start();
77
78 signals:
79     void stopCapture();
80 };
81
82
83 class StopmotionWidget : public QDialog, public Ui::Stopmotion_UI
84 {
85     Q_OBJECT
86
87 public:
88
89     /** @brief Build the stopmotion dialog.
90      * @param projectFolder The current project folder, where captured files will be stored.
91      * @param actions The actions for this widget that can have a keyboard shortcut.
92      * @param parent (optional) parent widget */
93     StopmotionWidget(MonitorManager *manager, KUrl projectFolder, QList< QAction* > actions, QWidget* parent = 0);
94     virtual ~StopmotionWidget();
95
96 protected:
97     virtual void closeEvent(QCloseEvent* e);
98
99 private:
100     /** @brief Current project folder (where the captured frames will be saved). */
101     KUrl m_projectFolder;
102
103     /** @brief Capture holder that will handle all video operation. */
104     MltDeviceCapture *m_captureDevice;
105
106     VideoPreviewContainer *m_videoBox;
107
108     /** @brief Holds the name of the current sequence.
109      * Files will be saved in project folder with name: sequence001.png */
110     QString m_sequenceName;
111
112     /** @brief Holds the frame number of the current sequence. */
113     int m_sequenceFrame;
114
115     QAction* m_captureAction;
116
117     /** @brief Holds the index of the frame to be displayed in the frame preview mode. */
118     int m_animatedIndex;
119
120     /** @brief Find all stopmotion sequences in current project folder. */
121     void parseExistingSequences();
122
123     /** @brief Select a frame in the list. */
124     void selectFrame(int ix);
125
126     /** @brief This widget will hold the frame preview. */
127     MyLabel* m_frame_preview;
128
129     /** @brief The list of files in the sequence to create thumbnails. */
130     QStringList m_filesList;
131
132     /** @brief Holds the state of the threaded thumbnail generation. */
133     QFuture<void> m_future;
134
135     /** @brief Get the frame number ix. */
136     QListWidgetItem* getFrameFromIndex(int ix);
137
138     /** @brief The action triggering display of last frame over current live video feed. */
139     QAction* m_showOverlay;
140
141     /** @brief The list of all frames path. */
142     QStringList m_animationList;
143     
144     /** @brief Tells if we are in animation (playback) mode. */
145     bool m_animate;
146     
147     /** @brief Timer for interval capture. */
148     QTimer m_intervalTimer;
149
150     MonitorManager *m_manager;
151
152     /** @brief The monitor is used to control the v4l capture device from the monitormanager class. */
153     StopmotionMonitor *m_monitor;
154
155     /** @brief Create the XML playlist. */
156     const QString createProducer(MltVideoProfile profile, const QString service, const QString resource);
157
158     /** @brief A new frame arrived, reload overlay. */
159     void reloadOverlay();
160
161
162 #ifdef QIMAGEBLITZ
163     int m_effectIndex;
164 #endif
165
166 public slots:
167     /** @brief Display the live feed from capture device.
168      @param isOn enable or disable the feature */
169     void slotLive(bool isOn = true);
170     void slotStopCapture();
171
172 private slots:
173
174     /** @brief Display the last captured frame over current live feed.
175      @param isOn enable or disable the feature */
176     void slotShowOverlay(bool isOn);
177
178     /** @brief Display the last captured frame over current live feed. */
179     void slotUpdateOverlay();
180
181     /** @brief User changed the capture name. */
182     void sequenceNameChanged(const QString& name);
183
184     /** @brief Grab a frame from current capture feed. */
185     void slotCaptureFrame();
186
187     /** @brief Display a previous frame in monitor. */
188     void slotShowFrame(const QString& path);
189
190     /** @brief Get full path for a frame in the sequence.
191      *  @param ix the frame number.
192      *  @param seqName (optional) the name of the sequence. */
193     QString getPathForFrame(int ix, QString seqName = QString());
194
195     /** @brief Add sequence to current project. */
196     void slotAddSequence();
197
198     /** @brief Display selected fram in monitor. */
199     void slotShowSelectedFrame();
200
201     /** @brief Start animation preview mode. */
202     void slotPlayPreview(bool animate);
203
204     /** @brief Simulate animation. */
205     void slotAnimate();
206
207     /** @brief Seek to previous or next captured frame.
208      *  @param forward set to true for next frame, false for previous one. */
209     void slotSeekFrame(bool forward);
210
211     /** @brief Display warning / error message from capture backend. */
212     void slotGotHDMIMessage(const QString& message);
213
214     /** @brief Create thumbnails for existing sequence frames. */
215     void slotCreateThumbs(QImage img, int ix);
216
217     /** @brief Prepare thumbnails creation. */
218     void slotPrepareThumbs();
219
220     /** @brief Called when user switches the video capture backend. */
221     void slotUpdateDeviceHandler();
222
223     /** @brief Show / hide sequence thumbnails. */
224     void slotShowThumbs(bool show);
225
226     /** @brief Show the config dialog */
227     void slotConfigure();
228
229     /** @brief Prepare to crete thumb for newly captured frame. */
230     void slotNewThumb(const QString path);
231
232     /** @brief Set the effect to be applied to overlay frame. */
233     void slotUpdateOverlayEffect(QAction* act);
234
235     /** @brief Switch between live view / currently selected frame. */
236     void slotSwitchLive();
237
238     /** @brief Delete current frame from disk. */
239     void slotRemoveFrame();
240     
241     /** @brief Enable / disable frame analysis (in color scopes). */
242     void slotSwitchAnalyse(bool isOn);
243
244     /** @brief Enable / disable horizontal mirror effect. */
245     void slotSwitchMirror(bool isOn);
246     
247     /** @brief Send a notification a few seconds before capturing. */
248     void slotPreNotify();
249
250 signals:
251     /** @brief Ask to add sequence to current project. */
252     void addOrUpdateSequence(const QString);
253
254     void doCreateThumbs(QImage, int);
255     void gotFrame(QImage);
256 };
257
258 #endif