File indexing completed on 2024-05-12 16:23:34

0001 /***************************************************************************
0002  *   Copyright (C) 2005-2014 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 
0021 #ifndef QTGUI_H
0022 #define QTGUI_H
0023 
0024 #include "src/domain/undo/undoredoobserver.h"
0025 
0026 #include <QObject>
0027 #include <QMainWindow>
0028 
0029 class FrameBar;
0030 class FrameView;
0031 class FlexibleSpinBox;
0032 class CameraHandler;
0033 class EditMenuHandler;
0034 class RunAnimationHandler;
0035 class ModelHandler;
0036 class SoundHandler;
0037 class FramePreferencesMenu;
0038 class PreferencesMenu;
0039 class ToolsMenu;
0040 class LanguageHandler;
0041 class EditObserver;
0042 
0043 class QApplication;
0044 class QKeyEvent;
0045 class QMouseEvent;
0046 class QDragEnterEvent;
0047 class QDropEvent;
0048 class QAction;
0049 class QMenu;
0050 class QLabel;
0051 class QVBoxLayout;
0052 class QHBoxLayout;
0053 class QPushButton;
0054 class QFileSystemWatcher;
0055 
0056 /**
0057  *The main window class for the stopmotion application.
0058  *This class sets up the main GUI and connects the buttons.
0059  *
0060  *@author Bjoern Erik Nilsen & Fredrik Berg Kjoelstad
0061 */
0062 class MainWindowGUI : public QMainWindow, public UndoRedoObserver {
0063     Q_OBJECT
0064 public:
0065     enum {SAVE, SAVE_AS, UNDO, REDO, CUT, COPY, PASTE, GOTO};
0066 
0067     /**
0068      * Sets up the program main GUI and connect the widgets and handlers.
0069      * @param stApp the application class for changing translator
0070      * on runtime.
0071      */
0072     MainWindowGUI(QApplication *stApp);
0073     ~MainWindowGUI();
0074 
0075     /**
0076      * Finish constructing the UI. The preferences must be loaded before calling this.
0077      */
0078     void ConstructUI();
0079 
0080     /**
0081      * Overloaded mouse listener. Closes the embedded menues when the user
0082      * clicks inside the main window.
0083      * @param e information about the event.
0084      */
0085     void mousePressEvent ( QMouseEvent * e );
0086 
0087     /**
0088      * Overloaded event listener which receives information when a keyboard key is
0089      * pressed.
0090      * @param k information about the key event.
0091      */
0092     void keyPressEvent( QKeyEvent *k );
0093 
0094     void updateCanUndo(bool newCanUndo);
0095     void updateCanRedo(bool newCanRedo);
0096 
0097 private:
0098     QApplication *stApp;
0099     QWidget *centerWidget;
0100     QVBoxLayout *centerWidgetLayout;
0101     QWidget *bottomWidget;
0102     QVBoxLayout *bottomWidgetLayout;
0103     QWidget *workArea;
0104     QHBoxLayout *workAreaLayout;
0105     FrameBar *frameBar;
0106     FrameView *frameView;
0107     QWidget *gotoMenuWidget;
0108     QHBoxLayout *gotoMenuWidgetLayout;
0109     QFileSystemWatcher *fileWatcher;
0110     EditObserver *editObserver;
0111 
0112     //Actions
0113     QAction *newAct;
0114     QAction *openAct;
0115     QAction *mostRecentAct;
0116     QAction *secondMostRecentAct;
0117     QAction *thirdMostRecentAct;
0118     QAction *saveAct;
0119     QAction *saveAsAct;
0120     QAction *videoAct;
0121     QAction *cinerellaAct;
0122     QAction *quitAct;
0123     QAction *undoAct;
0124     QAction *redoAct;
0125     QAction *cutAct;
0126     QAction *copyAct;
0127     QAction *pasteAct;
0128     QAction *gotoFrameAct;
0129     QAction *configureAct;
0130     QAction *whatsthisAct;
0131     QAction *aboutAct;
0132     QAction *helpAct;
0133 
0134     //Menus
0135     QMenu *fileMenu;
0136     QMenu *exportMenu;
0137     QMenu *mostRecentMenu;
0138     QMenu *editMenu;
0139     QMenu *settingsMenu;
0140     QMenu *languagesMenu;
0141     QMenu *helpMenu;
0142     ToolsMenu *toolsMenu;
0143     FramePreferencesMenu *framePreferencesMenu;
0144     PreferencesMenu *preferencesMenu;
0145 
0146     //MenuFrame *gotoMenu;
0147     QPushButton *gotoMenuCloseButton;
0148 
0149     //Widgets
0150     QLabel *numberDisplay;
0151     FlexibleSpinBox *gotoSpinner;
0152     QLabel *gotoFrameLabel;
0153 
0154     //Handlers
0155     ModelHandler *modelHandler;
0156     SoundHandler *soundHandler;
0157     CameraHandler *cameraHandler;
0158     EditMenuHandler *editMenuHandler;
0159     LanguageHandler *languageHandler;
0160     RunAnimationHandler *runAnimationHandler;
0161 
0162     QString lastVisitedDir;
0163 
0164     enum SaveDialogResult {
0165         saveDialogSave,
0166         saveDialogDiscard,
0167         saveDialogCancel
0168     };
0169 
0170     /**
0171      * Creates the handlers for handling user requests.
0172      * @param stApp the application class for changing translator
0173      * on runtime.
0174      */
0175     void createHandlers(QApplication *stApp);
0176 
0177     /**
0178      * Begins monitoring the workspace directory for interesting changes.
0179      */
0180     void setupDirectoryMonitoring();
0181 
0182     /**
0183      * Creates key accelerators (keyboard shortcuts)
0184      *
0185      * More can be found in the function ToolsMenu::createAccelerators().
0186      */
0187     void createAccelerators();
0188 
0189     /**
0190      * Creates the actions from which the menus are created.
0191      */
0192     void createActions();
0193 
0194     /**
0195      * Creates and sets up the menu and the toolbar.
0196      */
0197      void createMenus();
0198 
0199     /**
0200      * Creates the preferences menu.
0201      * @param parent
0202      */
0203     void makePreferencesMenu(QVBoxLayout *layout);
0204 
0205     /**
0206      *Creates and sets up the frameview.
0207      *@param parent the widget the frameview will be inserted into.
0208      */
0209     void makeViews(QHBoxLayout *layout);
0210 
0211     /**
0212      *Creates and sets up the toolsmenu.
0213      *@param parent the widget the toolsmenu will be inserted into.
0214      */
0215     void makeToolsMenu(QHBoxLayout *layout);
0216 
0217     /**
0218      * Creates and sets up the menu for going to a specified framenumber.
0219      * @param parent the widget the gotomenu will be inserted into.
0220      */
0221     void makeGotoMenu(QVBoxLayout *layout);
0222 
0223     /**
0224      * Sets up the statusbar with custom widgets.
0225      */
0226     void makeStatusBar();
0227 
0228     /**
0229      *Overloaded event listener for when when a drag enters the application.
0230      *@param event information about the dragEnterEvent
0231      */
0232     void dragEnterEvent ( QDragEnterEvent * event);
0233 
0234     /**
0235      *Overloaded event listener for when a drop event occur in the application.
0236      *@param event information about the dropEvent
0237      */
0238     void dropEvent(QDropEvent *event);
0239 
0240     /**
0241      * Overloaded event listener which receives information when a keyboard key is
0242      * released
0243      * @param k information about the key event.
0244      */
0245     void keyReleaseEvent ( QKeyEvent * k );
0246 
0247     /**
0248      * Retranslates the tooltip and whatsthis text.
0249      *
0250      * This function is called from retranslateStrings.
0251      */
0252     void retranslateHelpText();
0253 
0254     /**
0255      * Updates the most recent menu.
0256      */
0257     void updateMostRecentMenu();
0258 
0259     /**
0260      * Sets the title to the project name and an indicator for whether the
0261      * project is saved or not.
0262      * @param modified Whether or not the project is different from the most
0263      * recently saved project.
0264      */
0265     void setTitle(bool modified);
0266 
0267     /**
0268      * If the project has unsaved changes, asks the user if the project should
0269      * be saved. If so, saves it.
0270      * @return The user's response. {@ref SaveDialogDiscard} is returned if
0271      * there were found to be no changes.
0272      */
0273     SaveDialogResult saveIfNecessary();
0274     void doOpenProject(const char* projectFile);
0275 
0276 public slots:
0277 
0278     /**
0279      * Opens a saved project.
0280      * @param projectFile the project to open
0281      */
0282     void openProject(const char *projectFile);
0283 
0284 private slots:
0285 
0286     /**
0287      * Retranslates the strings.
0288      *
0289      * This function is called after a new translator has been installed so that
0290      * the program strings are retranslated to the new language.
0291      */
0292     void retranslateStrings();
0293 
0294     /**
0295      * Creates a new project.
0296      */
0297     void newProject();
0298 
0299     /**
0300      * Opens a project.
0301      */
0302     void openProject();
0303 
0304     /**
0305      * Opens a project.
0306      */
0307     void openMostRecent();
0308     void openSecondMostRecent();
0309     void openThirdMostRecent();
0310 
0311     /**
0312      * Saves the project to the last saved file.
0313      * @return {@c false} if a filename was required but the user cancelled;
0314      * in this case the project was not saved.
0315      */
0316     bool saveProject();
0317 
0318     /**
0319      * Saves the project to a given filename from the user.
0320      * @return {@c false} if the user cancelled; in this case the project was
0321      * not saved.
0322      */
0323     bool saveProjectAs();
0324 
0325     /**
0326      * Brings up an about dialog with information about the application.
0327      */
0328     void showAboutDialog();
0329 
0330     /**
0331      * Brings up an help dialog with the stopmotion user manual.
0332      */
0333     void showHelpDialog();
0334 
0335     /**
0336      * Brings up a preferences menu where the user can set preferences for the
0337      * application.
0338      */
0339     void showPreferencesMenu();
0340 
0341     /**
0342      * Exports the current project to a video file chosen by the user. It uses the
0343      * registered video encoder -- if registered -- to export.
0344      */
0345     void exportToVideo();
0346 
0347     /**
0348      * Exports the current project to a valid Cinerella project.
0349      */
0350     void exportToCinerella();
0351 
0352     void whatsThis();
0353 
0354     /**
0355      * Notification that the framebar's active frame has changed.
0356      */
0357     void updateNewActiveFrame(int scene, int frame);
0358 
0359     /**
0360      * Notification that the clipboard contents have changed.
0361      */
0362     void updatePasteEnabled();
0363     void createMostRecentMenu();
0364 
0365 public slots:
0366     /**
0367      * This slot is notified when the size of the model changes so that menuframe
0368      * menu options can be adjusted (activated/deactivated, etc).
0369      * @param modelSize the new size of the model.
0370      */
0371     void modelSizeChanged( int modelSize );
0372 
0373     /**
0374      * Sets different buttons such as undo, save as and copy to be enabled.
0375      */
0376     void activateMenuOptions();
0377 };
0378 
0379 #endif