File indexing completed on 2024-06-16 04:38:06
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2013 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 FRAMEBAR_H 0021 #define FRAMEBAR_H 0022 0023 #include "src/presentation/observer.h" 0024 #include "src/presentation/frontends/selection.h" 0025 0026 #include <QScrollArea> 0027 0028 #include <vector> 0029 0030 class ThumbView; 0031 class FramePreferencesMenu; 0032 0033 class QWidget; 0034 class QDragEnterEvent; 0035 class QDragMoveEvent; 0036 class QDropEvent; 0037 class QObject; 0038 class QResizeEvent; 0039 class QTimer; 0040 0041 /** 0042 * The framebar widget for viewing the animation model. 0043 * 0044 * @author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad 0045 */ 0046 class FrameBar : public QScrollArea, public Observer, public Selection { 0047 Q_OBJECT 0048 public: 0049 /** 0050 * Creates and sets up the framebar. 0051 * @param parent the parent widget 0052 */ 0053 FrameBar(QWidget *parent = 0); 0054 0055 /** 0056 * Cleans up after the framebar. 0057 */ 0058 ~FrameBar(); 0059 0060 /** 0061 * Receives notification when a frame is added. 0062 */ 0063 void updateAdd(int scene, int index, int numFrames); 0064 0065 /** 0066 * Function to receive notification when one or more frames are deleted. 0067 * @param fromFrame the first frame in the selection 0068 * @param toFrame the last frame in the selection 0069 */ 0070 void updateRemove(int scene, int fromFrame, int toFrame); 0071 0072 /** 0073 *Function to receive notification when one or more frames are moved. 0074 */ 0075 void updateMove(int fromScene, int fromFrame, int count, 0076 int toScene, int toFrame); 0077 0078 /** 0079 * Function to receive notification when the model is erased. 0080 */ 0081 void updateClear(); 0082 0083 /** 0084 * Function to receive notification when a new scene is added to the 0085 * model. 0086 * @param index the index of the new scene. 0087 */ 0088 void updateNewScene(int index); 0089 0090 /** 0091 * Function to receive notification when a scene is removed from 0092 * the model. 0093 * @param sceneNumber the scene which has been removed from the model. 0094 */ 0095 void updateRemoveScene(int sceneNumber); 0096 0097 /** 0098 * Function which receives notification when a scene in the animation 0099 * has been moved and moves the icons in the framebar accordingly. 0100 * @param sceneNumber the scene which have been moved. 0101 * @param movePosition the position the scene has been moved to. 0102 */ 0103 void updateMoveScene(int sceneNumber, int movePosition); 0104 0105 /** 0106 * Function which receives notification when a scene is selected as the 0107 * active scene in the animationmodel. 0108 * @param sceneNumber the new scene to be set as the active scene in the 0109 * framebar. 0110 * @param framePaths paths to the pictures in the scene. 0111 * @param frontend the frontend for getting a progressbar when adding 0112 * opening the new active scene. 0113 */ 0114 void updateNewActiveScene(int sceneNumber); 0115 0116 /** 0117 * Updates the framebar when an external program has altered the disk files. 0118 * @param sceneNumber The scene containing the changed frame. 0119 * @param frameNumber the frame whose disk representation has been changed. 0120 */ 0121 void updateAnimationChanged(int sceneNumber, int frameNumber); 0122 0123 /** 0124 * Updates the framebar when the sounds attached to the specified frame 0125 * change. 0126 * @param sceneNumber The scene to which the changed frame belongs. 0127 * @param frameNumber The frame number within the scene 0128 */ 0129 void updateSoundChanged(int sceneNumber, int frameNumber); 0130 0131 /** 0132 * Set whether the user is engaged selecting several frames or not (pressing 0133 * shift). 0134 * @param selecting true if the user is currently selecting multiple pictures 0135 */ 0136 void setSelecting(bool selecting); 0137 0138 /** 0139 * Returns true if the user is currently selecting several thumbviews. 0140 * @return true if the user is currently selecting several thumbviews. 0141 */ 0142 bool isSelecting() const; 0143 0144 /** 0145 * Sets a selection of frames between (including) this frame and the activeFrame. 0146 * @todo change name to setSelectionFrame 0147 * @param selectionFrame the other border frame of the selection in addition to activeFrame 0148 */ 0149 void setSelection(int selectionFrame); 0150 0151 /** 0152 * Returns The frame number of the anchor of the selection. 0153 * @return The anchor of the current selection, or returns the same value 0154 * as {@ref getActiveFrame} if there is no selection. 0155 */ 0156 int getSelectionAnchor() const; 0157 0158 /** 0159 * Returns the current active frame. 0160 */ 0161 int getActiveFrame() const; 0162 0163 /** 0164 * Returns the current active scene. 0165 */ 0166 int getActiveScene() const; 0167 0168 /** 0169 * Registers the frame preferences menu in the framebar. 0170 * @param preferencesMenu the frame preferences menu. 0171 */ 0172 void setPreferencesMenu(FramePreferencesMenu *preferencesMenu); 0173 0174 /** 0175 * Displays the frame preferences for the active frame. 0176 */ 0177 void showPreferencesMenu(); 0178 0179 /** 0180 * Retrieves the value of the movingScene property specifying which scene 0181 * is currently being moved in the framebar. 0182 * @return the value of the movingScene property. 0183 */ 0184 int getMovingScene() const; 0185 0186 /** 0187 * Sets the value of the movingScene property specifying which scene 0188 * is currently being moved in the framebar. 0189 * @param movingScene the new value of the movingScene property. 0190 */ 0191 void setMovingScene(int movingScene); 0192 0193 int getFrameWidth() const; 0194 int getFrameHeight() const; 0195 int getSpace() const; 0196 0197 protected: 0198 /** 0199 * Overloaded event function for when a drag enter occurs in the framebar 0200 * @param event information about the dragEnterEvent 0201 */ 0202 void dragEnterEvent(QDragEnterEvent *event); 0203 0204 /** 0205 * Overloaded event function for when a drop event occurs in the framebar. 0206 * @param event information about the dropEvent 0207 */ 0208 void dropEvent(QDropEvent *event); 0209 0210 void dragMoveEvent(QDragMoveEvent *event); 0211 0212 void resizeEvent(QResizeEvent *event); 0213 0214 public slots: 0215 void updateNewActiveFrame(int scene, int frame); 0216 /** 0217 * Move the active frame and selection to the selection before the current 0218 * anchor. Make the selection just this single frame. 0219 */ 0220 void selectPreviousFrame(); 0221 void selectNextFrame(); 0222 /** 0223 * Move the selection, not the active frame, thus extending/diminishing the 0224 * selection. 0225 */ 0226 void moveSelectionToPreviousFrame(); 0227 void moveSelectionToNextFrame(); 0228 void selectPreviousScene(); 0229 void selectNextScene(); 0230 void fileChanged(const QString &path); 0231 void setThumbImage(ThumbView* thumb, const char* imagePath); 0232 void setSelection(int scene, int selectionFrame, int activeFrame); 0233 0234 signals: 0235 //The signals in the framebar is used for signaling small widget, 0236 //who are deemed to insignificant to be observers, of changes in 0237 //the framebar/model. A bit hacky and should be in it's own widget. 0238 void newActiveFrame( const QString & ); 0239 void newActiveFrame(int scene, int frame); 0240 void modelSizeChanged( int modelSize ); 0241 void newMaximumValue(int value); 0242 0243 private slots: 0244 void scroll(); 0245 0246 private: 0247 static const int FRAME_HEIGHT = 88; 0248 static const int FRAME_WIDTH = 117; 0249 static const int SPACE = 2; 0250 0251 /** Vector of thumbviews to keep track of the pictures in the framebar*/ 0252 vector<ThumbView*>thumbViews; 0253 0254 /** The active frame in the framebar*/ 0255 int activeFrame; 0256 0257 /** The active scene in the framebar */ 0258 int activeScene; 0259 0260 /** 0261 * The number of thumbnails we are showing for frames in the active scene. 0262 * If this is different to the number of frames in the actual scene, we 0263 * need to resynchronize. 0264 */ 0265 int activeSceneSize; 0266 0267 /** The scene which are being moved when dragging a scene */ 0268 int movingScene; 0269 0270 /** 0271 * The anchor in a selection. 0272 * If only one frame is selected selectionFrame == activeFrame 0273 */ 0274 int selectionFrame; 0275 0276 /** Direction to scroll when dragging. 0277 * -1 = scroll negative, 0 = no scroll, 1 = scroll positive */ 0278 int scrollDirection; 0279 0280 int lowerScrollAreaX; 0281 int upperScrollAreaX; 0282 0283 int lowerAccelScrollAreaX; 0284 int upperAccelScrollAreaX; 0285 0286 int minScrollAreaX; 0287 int maxScrollAreaX; 0288 0289 int minScrollAreaY; 0290 int maxScrollAreaY; 0291 0292 /** True if the user is currently holding down shift to select multiple frames */ 0293 bool selecting; 0294 0295 bool openingScene; 0296 0297 QTimer *scrollTimer; 0298 QScrollBar *scrollBar; 0299 0300 QWidget *mainWidget; 0301 0302 /** Pointer to the frame preferencesMenu */ 0303 FramePreferencesMenu *preferencesMenu; 0304 0305 /** Returns how many scene thumbnails there are */ 0306 int sceneThumbCount() const; 0307 0308 /** 0309 * Adds the frames in the framesvector to the framebar. 0310 * @param index The location to add the frames to. 0311 * @param numFrames The number of frames to be added. 0312 */ 0313 void addFrames(int index, int numFrames); 0314 0315 /** 0316 * Removes a selection of thumbviews from the framebar. 0317 * @param fromFrame the first thumbview to remove. 0318 * @param toFrame the last thumbview to remove. 0319 */ 0320 void removeFrames(int fromFrame, int toFrame); 0321 0322 /** 0323 * Move the frames from fromFrame (inclusive) to toFrame to movePosition. 0324 * @param fromFrame the first frame to move. 0325 * @param toFrame the last frame to move. 0326 * @param movePosition the position to move the frames to. 0327 */ 0328 void moveFrames(int fromFrame, int toFrame, int movePosition); 0329 0330 /** 0331 *Sets the thumbview frameNumber in the framebar to be the active frame. 0332 *@param frameNumber the number of the new active frame 0333 */ 0334 void setActiveFrame(int frameNumber); 0335 0336 /** 0337 * Creates a new scene and adds it to the framebar. 0338 * @param index the location the new scene should be added at. 0339 */ 0340 void newScene(int index); 0341 0342 /** 0343 * Removes the scene with index sceneNumber from the framebar. 0344 * @param sceneNumber the scene to be removed from the framebar. 0345 */ 0346 void removeScene(int sceneNumber); 0347 0348 /** 0349 * Moves a scene in the framebar. 0350 * @param sceneNumber the scene that are moved. 0351 * @param movePosition the position the scene are moved to. 0352 */ 0353 void moveScene(int sceneNumber, int movePosition); 0354 0355 /** 0356 * Sets a new scene as the active scene in the framebar and opens it. 0357 * @param sceneNumber the scene to set as the active scene. 0358 * @param framePaths the paths to the frames in the scene. 0359 * @param frontend the frontend for getting a progressbar when adding the 0360 * frames to the scene. 0361 */ 0362 void setActiveScene(int sceneNumber); 0363 0364 /** 0365 * Gets the thumbnail of the specified frame in the active scene, creating 0366 * it if necessary. 0367 * @param index The index of the frame within the active scene. 0368 * @param fix True to correct the position, number and sound indicator. 0369 */ 0370 ThumbView* getFrameThumb(int index, bool fix = false); 0371 0372 /** 0373 * Gets the thumbnail of the specified scene, creating it if necessary. 0374 * @param index The scene number. 0375 * @param fix True to correct the position and number. 0376 */ 0377 ThumbView* getSceneThumb(int index, bool fix = false); 0378 0379 /** Sets the size of the frame bar to accommodate all the thumbnails. */ 0380 void fixSize(); 0381 /** Deletes all the thumbnails. */ 0382 void clear(); 0383 /** 0384 * Resynchronizes the thumbnails with the domain facade, and puts the 0385 * active frame, active scene and selection frame within bounds. 0386 */ 0387 void resync(); 0388 /** 0389 * Deletes the specified frames from the active scene. 0390 */ 0391 void deleteFrames(int fromFrame, int frameCount); 0392 /** 0393 * Sets {@ref activeScene} to -1, deleting all the frame thumbnails in the 0394 * previously-set active scene and closing the scene thumbnail. 0395 */ 0396 void closeActiveScene(); 0397 /** 0398 * Inserts frames into the active scene. 0399 */ 0400 void insertFrames(int index, int numFrames); 0401 /** 0402 * Sets the current selection. 0403 */ 0404 void setActiveFrameAndSelection(int af, int sf); 0405 /** 0406 * Scrolls the framebar to include the currently active frame. 0407 */ 0408 void doScroll(); 0409 void doActiveFrameNotifications(); 0410 void fixPreferencesMenu(); 0411 /** 0412 * Changes the selection highlight without fixing any damaged frames. 0413 * Set both {@ af} and {@sf} to {@c -1} to remove the selection. 0414 */ 0415 void changeSelectionHighlight(int af, int sf); 0416 int getFrameThumbIndex(int index); 0417 /** 0418 * Sets the frames in the current scene from index {@a start} to index 0419 * {@a end} (not including the one at {@end}) to be highlighted or not, 0420 * depending on the value of {@set}. 0421 * @param start The first index to have its highlight set. 0422 * @param end The first index not to have its highlight set. 0423 * @param set {@c true} to set the highlight on, {@c false} to set it off. 0424 * @pre {@a start} must be no greater than {@a end}. 0425 */ 0426 void highlight(int start, int end, bool set); 0427 }; 0428 0429 #endif