MainWindow.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * MainWindow.h - declaration of class MainWindow, the main window of LMMS
  3. *
  4. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef MAIN_WINDOW_H
  25. #define MAIN_WINDOW_H
  26. #include <QtCore/QBasicTimer>
  27. #include <QtCore/QTimer>
  28. #include <QtCore/QList>
  29. #include <QMainWindow>
  30. #include <QThread>
  31. #include "ConfigManager.h"
  32. #include "SubWindow.h"
  33. class QAction;
  34. class QDomElement;
  35. class QGridLayout;
  36. class QMdiArea;
  37. class ConfigManager;
  38. class PluginView;
  39. class ToolButton;
  40. class MainWindow : public QMainWindow
  41. {
  42. Q_OBJECT
  43. public:
  44. QMdiArea* workspace()
  45. {
  46. return m_workspace;
  47. }
  48. QWidget* toolBar()
  49. {
  50. return m_toolBar;
  51. }
  52. int addWidgetToToolBar( QWidget * _w, int _row = -1, int _col = -1 );
  53. void addSpacingToToolBar( int _size );
  54. // wrap the widget with a window decoration and add it to the workspace
  55. EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);
  56. ///
  57. /// \brief Asks whether changes made to the project are to be saved.
  58. ///
  59. /// Opens a dialog giving the user the choice to (a) confirm his choice
  60. /// (such as opening a new file), (b) save the current project before
  61. /// proceeding or (c) cancel the process.
  62. ///
  63. /// Every function that replaces the current file (e.g. creates new file,
  64. /// opens another file...) must call this before and may only proceed if
  65. /// this function returns true.
  66. ///
  67. /// \param stopPlayback whether playback should be stopped upon prompting. If set to false, the caller should ensure that Engine::getSong()->stop() is called before unloading/loading a song.
  68. ///
  69. /// \return true if the user allows the software to proceed, false if they
  70. /// cancel the action.
  71. ///
  72. bool mayChangeProject(bool stopPlayback);
  73. // Auto save timer intervals. The slider in SetupDialog.cpp wants
  74. // minutes and the rest milliseconds.
  75. static const int DEFAULT_SAVE_INTERVAL_MINUTES = 2;
  76. static const int DEFAULT_AUTO_SAVE_INTERVAL = DEFAULT_SAVE_INTERVAL_MINUTES * 60 * 1000;
  77. static const int m_autoSaveShortTime = 10 * 1000; // 10s short loop
  78. void autoSaveTimerReset( int msec = ConfigManager::inst()->
  79. value( "ui", "saveinterval" ).toInt()
  80. * 60 * 1000 )
  81. {
  82. if( msec < m_autoSaveShortTime ) // No 'saveinterval' in .lmmsrc.xml
  83. {
  84. msec = DEFAULT_AUTO_SAVE_INTERVAL;
  85. }
  86. m_autoSaveTimer.start( msec );
  87. }
  88. int getAutoSaveTimerInterval()
  89. {
  90. return m_autoSaveTimer.interval();
  91. }
  92. enum SessionState
  93. {
  94. Normal,
  95. Recover
  96. };
  97. void setSession( SessionState session )
  98. {
  99. m_session = session;
  100. }
  101. SessionState getSession()
  102. {
  103. return m_session;
  104. }
  105. void sessionCleanup();
  106. void clearKeyModifiers();
  107. // TODO Remove this function, since m_shift can get stuck down.
  108. // [[deprecated]]
  109. bool isShiftPressed()
  110. {
  111. return m_keyMods.m_shift;
  112. }
  113. static void saveWidgetState( QWidget * _w, QDomElement & _de );
  114. static void restoreWidgetState( QWidget * _w, const QDomElement & _de );
  115. public slots:
  116. void resetWindowTitle();
  117. void emptySlot();
  118. void enterWhatsThisMode();
  119. void createNewProject();
  120. void createNewProjectFromTemplate( QAction * _idx );
  121. void openProject();
  122. bool saveProject();
  123. bool saveProjectAs();
  124. bool saveProjectAsNewVersion();
  125. void saveProjectAsDefaultTemplate();
  126. void showSettingsDialog();
  127. void aboutLMMS();
  128. void help();
  129. void toggleAutomationEditorWin();
  130. void toggleBBEditorWin( bool forceShow = false );
  131. void toggleSongEditorWin();
  132. void toggleProjectNotesWin();
  133. void toggleFxMixerWin();
  134. void togglePianoRollWin();
  135. void toggleControllerRack();
  136. void updatePlayPauseIcons();
  137. void updateUndoRedoButtons();
  138. void undo();
  139. void redo();
  140. void autoSave();
  141. protected:
  142. void closeEvent( QCloseEvent * _ce ) override;
  143. void focusOutEvent( QFocusEvent * _fe ) override;
  144. void keyPressEvent( QKeyEvent * _ke ) override;
  145. void keyReleaseEvent( QKeyEvent * _ke ) override;
  146. void timerEvent( QTimerEvent * _ev ) override;
  147. private:
  148. MainWindow();
  149. MainWindow( const MainWindow & );
  150. virtual ~MainWindow();
  151. void finalize();
  152. void toggleWindow( QWidget *window, bool forceShow = false );
  153. void refocus();
  154. QMdiArea * m_workspace;
  155. QWidget * m_toolBar;
  156. QGridLayout * m_toolBarLayout;
  157. QMenu * m_templatesMenu;
  158. QMenu * m_recentlyOpenedProjectsMenu;
  159. int m_custom_templates_count;
  160. struct keyModifiers
  161. {
  162. keyModifiers() :
  163. m_ctrl( false ),
  164. m_shift( false ),
  165. m_alt( false )
  166. {
  167. }
  168. bool m_ctrl;
  169. bool m_shift;
  170. bool m_alt;
  171. } m_keyMods;
  172. QMenu * m_toolsMenu;
  173. QAction * m_undoAction;
  174. QAction * m_redoAction;
  175. QList<PluginView *> m_tools;
  176. QBasicTimer m_updateTimer;
  177. QTimer m_autoSaveTimer;
  178. int m_autoSaveInterval;
  179. friend class GuiApplication;
  180. QMenu * m_viewMenu;
  181. ToolButton * m_metronomeToggle;
  182. SessionState m_session;
  183. private slots:
  184. void browseHelp();
  185. void fillTemplatesMenu();
  186. void openRecentlyOpenedProject( QAction * _action );
  187. void showTool( QAction * _idx );
  188. void updateRecentlyOpenedProjectsMenu();
  189. void updateViewMenu( void );
  190. void updateConfig( QAction * _who );
  191. void onToggleMetronome();
  192. signals:
  193. void periodicUpdate();
  194. void initProgress(const QString &msg);
  195. } ;
  196. #endif