File indexing completed on 2024-06-09 04:52:45
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2016 by Linuxstopmotion contributors; * 0003 * see the AUTHORS file for details. * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef FRAMEVIEW_H 0021 #define FRAMEVIEW_H 0022 0023 #include <QObject> 0024 #include <QTimer> 0025 #include <QWidget> 0026 0027 #include "src/domain/animation/workspacefile.h" 0028 #include "src/presentation/imagecache.h" 0029 0030 class ImageGrabThread; 0031 class QResizeEvent; 0032 class QPaintEvent; 0033 class QPixmap; 0034 class ImageGrabber; 0035 class DomainFacade; 0036 0037 /** 0038 * Widget for viewing the frames in the animation and image about to be 0039 * captured. 0040 */ 0041 class FrameView : public QWidget { 0042 Q_OBJECT 0043 public: 0044 enum ImageMode { 0045 imageModeMix, 0046 imageModeDiff, 0047 imageModePlayback 0048 }; 0049 /** 0050 * Creates and initializes the frameview. 0051 * @param parent the parent widget. 0052 * @param name the name of this widget. 0053 * @param playbackSpeed which speed the playback has to be played in if 0054 * the playback mode is chosen 0055 */ 0056 FrameView(QWidget *parent=0, const char *name=0, int playbackSpeed = 10); 0057 0058 /** 0059 * Cleans up after the frameview. 0060 */ 0061 ~FrameView(); 0062 0063 void initCompleted(); 0064 0065 /** 0066 * Sets the viewing mode/type of effect used when displaying the video. 0067 * @param mode the type of effect to be showed on the video. The modes are:\n 0068 * 0: Image mixing/onion skinning\n 0069 * 1: Image differentiating\n 0070 * 2: Playback\n 0071 * @return true if the mode was successfully changed 0072 */ 0073 bool setViewMode(ImageMode mode); 0074 0075 void setMixCount(int mixCount); 0076 0077 /** 0078 * Returns the view mode. 0079 * @return the view mode. 0080 */ 0081 int getViewMode() const; 0082 0083 /** 0084 * Sets the speed for the playback. 0085 * @param playbackSpeed the speed to be set. 0086 */ 0087 void setPlaybackSpeed(int playbackSpeed); 0088 0089 /** 0090 * Gets the speed for playback. 0091 * @returns Frames per second. 0092 */ 0093 int getPlaybackSpeed() const; 0094 0095 signals: 0096 void cameraReady(); 0097 0098 public slots: 0099 /** 0100 * Turns on the webcamera/video import mode. 0101 */ 0102 bool on(); 0103 0104 /** 0105 * Turns off the webcamera/video import mode. 0106 */ 0107 void off(); 0108 0109 /** 0110 * Draws the next frame from the camera. 0111 */ 0112 void redraw(); 0113 0114 /** 0115 * Function for performing playbacks. Will call redraw with regular intervals. 0116 */ 0117 void nextPlayBack(); 0118 0119 /** 0120 * Receives notification when a new frame is selected. 0121 */ 0122 void updateNewActiveFrame(int scene, int frame); 0123 0124 /** 0125 * Receives notification when a frame is to be played. 0126 */ 0127 void updatePlayFrame(int scene, int frame); 0128 0129 /** 0130 * Receives notification when a frame has been edited outside of this 0131 * application. 0132 */ 0133 void fileChanged(const QString &path); 0134 0135 /** 0136 * Receives notification that the files in the workspace have changed. 0137 */ 0138 void workspaceCleared(); 0139 0140 protected: 0141 void resizeEvent(QResizeEvent *); 0142 void paintEvent(QPaintEvent *); 0143 0144 private: 0145 static const int alphaLut[5]; 0146 0147 QPixmap cameraOutput; 0148 ImageCache imageCache; 0149 0150 QTimer grabTimer; 0151 QTimer playbackTimer; 0152 ImageGrabThread *grabThread; 0153 ImageGrabber *grabber; 0154 WorkspaceFile capturedFile; 0155 0156 /** The facade cached away in this class for efficiency reasons */ 0157 DomainFacade *facade; 0158 0159 /** Is the frame view showing the camera output? */ 0160 bool isPlayingVideo; 0161 0162 ImageMode mode; 0163 int playbackSpeed; 0164 int activeScene; 0165 int activeFrame; 0166 int mixCount; 0167 int playbackModeFrame; 0168 0169 /** 0170 * Loads the new active frames picture into the frameview. 0171 * @param sceneNumber The scene that the active frame belongs to. 0172 * @param frameNumber The frame within the scene that is to be active. 0173 */ 0174 void setActiveFrame(int sceneNumber, int frameNumber); 0175 0176 /** 0177 * Draws the appropriate blend of frames and camera output based on the 0178 * current image mode. 0179 */ 0180 void drawOnionSkins(); 0181 }; 0182 0183 #endif