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 "monitor/abstractmonitor.h" |
30 | |
31 | class MltDeviceCapture; |
32 | class MonitorManager; |
33 | class MltVideoProfile; |
34 | |
35 | class MyLabel : public QLabel |
36 | { |
37 | Q_OBJECT |
38 | public: |
39 | explicit MyLabel(QWidget* parent = 0); |
40 | void setImage(const QImage &img); |
41 | |
42 | protected: |
43 | void paintEvent(QPaintEvent* event); |
44 | void wheelEvent(QWheelEvent* event); |
45 | void mousePressEvent(QMouseEvent*); |
46 | |
47 | private: |
48 | QImage m_img; |
49 | |
50 | signals: |
51 | /** @brief Seek to next or previous frame. |
52 | * @param forward set to true to go to next frame, fals to go to previous frame */ |
53 | void seek(bool forward); |
54 | |
55 | /** @brief Switch to live view. */ |
56 | void switchToLive(); |
57 | }; |
58 | |
59 | |
60 | class StopmotionMonitor : public AbstractMonitor |
61 | { |
62 | Q_OBJECT |
63 | public: |
64 | StopmotionMonitor(MonitorManager *manager, QWidget *parent); |
65 | ~StopmotionMonitor(); |
66 | AbstractRender *abstractRender(); |
67 | Kdenlive::MonitorId id() const; |
68 | void setRender(MltDeviceCapture *render); |
69 | |
70 | private: |
71 | MltDeviceCapture *m_captureDevice; |
72 | |
73 | public slots: |
74 | void stop(); |
75 | void start(); |
76 | void slotPlay(); |
77 | void slotMouseSeek(int eventDelta, bool fast); |
78 | void slotSwitchFullScreen(); |
79 | |
80 | signals: |
81 | void stopCapture(); |
82 | }; |
83 | |
84 | |
85 | class StopmotionWidget : public QDialog, public Ui::Stopmotion_UI |
86 | { |
87 | Q_OBJECT |
88 | |
89 | public: |
90 | |
91 | /** @brief Build the stopmotion dialog. |
92 | * @param projectFolder The current project folder, where captured files will be stored. |
93 | * @param actions The actions for this widget that can have a keyboard shortcut. |
94 | * @param parent (optional) parent widget */ |
95 | StopmotionWidget(MonitorManager *manager, const KUrl &projectFolder, const QList< QAction* > &actions, QWidget* parent = 0); |
96 | virtual ~StopmotionWidget(); |
97 | |
98 | protected: |
99 | virtual void closeEvent(QCloseEvent* e); |
100 | |
101 | private: |
102 | /** @brief Current project folder (where the captured frames will be saved). */ |
103 | KUrl m_projectFolder; |
104 | |
105 | /** @brief Capture holder that will handle all video operation. */ |
106 | MltDeviceCapture *m_captureDevice; |
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 This widget will hold the frame preview. */ |
124 | MyLabel* m_frame_preview; |
125 | |
126 | /** @brief The list of files in the sequence to create thumbnails. */ |
127 | QStringList m_filesList; |
128 | |
129 | /** @brief Holds the state of the threaded thumbnail generation. */ |
130 | QFuture<void> m_future; |
131 | |
132 | /** @brief Get the frame number ix. */ |
133 | QListWidgetItem* getFrameFromIndex(int ix); |
134 | |
135 | /** @brief The action triggering display of last frame over current live video feed. */ |
136 | QAction* m_showOverlay; |
137 | |
138 | /** @brief The list of all frames path. */ |
139 | QStringList m_animationList; |
140 | |
141 | /** @brief Tells if we are in animation (playback) mode. */ |
142 | bool m_animate; |
143 | |
144 | /** @brief Timer for interval capture. */ |
145 | QTimer m_intervalTimer; |
146 | |
147 | MonitorManager *m_manager; |
148 | |
149 | /** @brief The monitor is used to control the v4l capture device from the monitormanager class. */ |
150 | StopmotionMonitor *m_monitor; |
151 | |
152 | /** @brief Create the XML playlist. */ |
153 | const QString createProducer(const MltVideoProfile &profile, const QString &service, const QString &resource); |
154 | |
155 | /** @brief A new frame arrived, reload overlay. */ |
156 | void reloadOverlay(); |
157 | |
158 | /** @brief Holds the index of the effect to be applied to the video feed. */ |
159 | int m_effectIndex; |
160 | |
161 | |
162 | public slots: |
163 | /** @brief Display the live feed from capture device. |
164 | @param isOn enable or disable the feature */ |
165 | void slotLive(bool isOn = true); |
166 | void slotStopCapture(); |
167 | |
168 | private slots: |
169 | |
170 | /** @brief Display the last captured frame over current live feed. |
171 | @param isOn enable or disable the feature */ |
172 | void slotShowOverlay(bool isOn); |
173 | |
174 | /** @brief Display the last captured frame over current live feed. */ |
175 | void slotUpdateOverlay(); |
176 | |
177 | /** @brief User changed the capture name. */ |
178 | void sequenceNameChanged(const QString& name); |
179 | |
180 | /** @brief Grab a frame from current capture feed. */ |
181 | void slotCaptureFrame(); |
182 | |
183 | /** @brief Display a previous frame in monitor. */ |
184 | void slotShowFrame(const QString& path); |
185 | |
186 | /** @brief Get full path for a frame in the sequence. |
187 | * @param ix the frame number. |
188 | * @param seqName (optional) the name of the sequence. */ |
189 | QString getPathForFrame(int ix, QString seqName = QString()); |
190 | |
191 | /** @brief Add sequence to current project. */ |
192 | void slotAddSequence(); |
193 | |
194 | /** @brief Display selected fram in monitor. */ |
195 | void slotShowSelectedFrame(); |
196 | |
197 | /** @brief Start animation preview mode. */ |
198 | void slotPlayPreview(bool animate); |
199 | |
200 | /** @brief Simulate animation. */ |
201 | void slotAnimate(); |
202 | |
203 | /** @brief Seek to previous or next captured frame. |
204 | * @param forward set to true for next frame, false for previous one. */ |
205 | void slotSeekFrame(bool forward); |
206 | |
207 | /** @brief Display warning / error message from capture backend. */ |
208 | void slotGotHDMIMessage(const QString& message); |
209 | |
210 | /** @brief Create thumbnails for existing sequence frames. */ |
211 | void slotCreateThumbs(const QImage &img, int ix); |
212 | |
213 | /** @brief Prepare thumbnails creation. */ |
214 | void slotPrepareThumbs(); |
215 | |
216 | /** @brief Called when user switches the video capture backend. */ |
217 | void slotUpdateDeviceHandler(); |
218 | |
219 | /** @brief Show / hide sequence thumbnails. */ |
220 | void slotShowThumbs(bool show); |
221 | |
222 | /** @brief Show the config dialog */ |
223 | void slotConfigure(); |
224 | |
225 | /** @brief Prepare to crete thumb for newly captured frame. */ |
226 | void slotNewThumb(const QString &path); |
227 | |
228 | /** @brief Set the effect to be applied to overlay frame. */ |
229 | void slotUpdateOverlayEffect(QAction* act); |
230 | |
231 | /** @brief Switch between live view / currently selected frame. */ |
232 | void slotSwitchLive(); |
233 | |
234 | /** @brief Delete current frame from disk. */ |
235 | void slotRemoveFrame(); |
236 | |
237 | /** @brief Enable / disable frame analysis (in color scopes). */ |
238 | void slotSwitchAnalyse(bool isOn); |
239 | |
240 | /** @brief Enable / disable horizontal mirror effect. */ |
241 | void slotSwitchMirror(bool isOn); |
242 | |
243 | /** @brief Send a notification a few seconds before capturing. */ |
244 | void slotPreNotify(); |
245 | |
246 | signals: |
247 | /** @brief Ask to add sequence to current project. */ |
248 | void addOrUpdateSequence(const QString &); |
249 | |
250 | void doCreateThumbs(const QImage&, int); |
251 | void gotFrame(const QImage&); |
252 | }; |
253 | |
254 | #endif |
255 | |