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