MainWindow.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 "ConfigManager.h"
  31. #include "SubWindow.h"
  32. class QAction;
  33. class QDomElement;
  34. class QGridLayout;
  35. class QMdiArea;
  36. class ConfigManager;
  37. class PluginView;
  38. class ToolButton;
  39. class MainWindow : public QMainWindow
  40. {
  41. Q_OBJECT
  42. public:
  43. QMdiArea* workspace()
  44. {
  45. return m_workspace;
  46. }
  47. QWidget* toolBar()
  48. {
  49. return m_toolBar;
  50. }
  51. int addWidgetToToolBar( QWidget * _w, int _row = -1, int _col = -1 );
  52. void addSpacingToToolBar( int _size );
  53. // wrap the widget with a window decoration and add it to the workspace
  54. LMMS_EXPORT SubWindow* addWindowedWidget(QWidget *w, Qt::WindowFlags windowFlags=0);
  55. ///
  56. /// \brief Asks whether changes made to the project are to be saved.
  57. ///
  58. /// Opens a dialog giving the user the choice to (a) confirm his choice
  59. /// (such as opening a new file), (b) save the current project before
  60. /// proceeding or (c) cancel the process.
  61. ///
  62. /// Every function that replaces the current file (e.g. creates new file,
  63. /// opens another file...) must call this before and may only proceed if
  64. /// this function returns true.
  65. ///
  66. /// \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.
  67. ///
  68. /// \return true if the user allows the software to proceed, false if they
  69. /// cancel the action.
  70. ///
  71. bool mayChangeProject(bool stopPlayback);
  72. // Auto save timer intervals. The slider in SetupDialog.cpp wants
  73. // minutes and the rest milliseconds.
  74. static const int DEFAULT_SAVE_INTERVAL_MINUTES = 2;
  75. static const int DEFAULT_AUTO_SAVE_INTERVAL = DEFAULT_SAVE_INTERVAL_MINUTES * 60 * 1000;
  76. static const int m_autoSaveShortTime = 10 * 1000; // 10s short loop
  77. void autoSaveTimerReset( int msec = ConfigManager::inst()->
  78. value( "ui", "saveinterval" ).toInt()
  79. * 60 * 1000 )
  80. {
  81. if( msec < m_autoSaveShortTime ) // No 'saveinterval' in .lmmsrc.xml
  82. {
  83. msec = DEFAULT_AUTO_SAVE_INTERVAL;
  84. }
  85. m_autoSaveTimer.start( msec );
  86. }
  87. int getAutoSaveTimerInterval()
  88. {
  89. return m_autoSaveTimer.interval();
  90. }
  91. enum SessionState
  92. {
  93. Normal,
  94. Recover
  95. };
  96. void setSession( SessionState session )
  97. {
  98. m_session = session;
  99. }
  100. SessionState getSession()
  101. {
  102. return m_session;
  103. }
  104. void sessionCleanup();
  105. void clearKeyModifiers();
  106. bool isCtrlPressed()
  107. {
  108. return m_keyMods.m_ctrl;
  109. }
  110. bool isShiftPressed()
  111. {
  112. return m_keyMods.m_shift;
  113. }
  114. bool isAltPressed()
  115. {
  116. return m_keyMods.m_alt;
  117. }
  118. static void saveWidgetState( QWidget * _w, QDomElement & _de );
  119. static void restoreWidgetState( QWidget * _w, const QDomElement & _de );
  120. public slots:
  121. void resetWindowTitle();
  122. void emptySlot();
  123. void createNewProject();
  124. void createNewProjectFromTemplate( QAction * _idx );
  125. void openProject();
  126. bool saveProject();
  127. bool saveProjectAs();
  128. bool saveProjectAsNewVersion();
  129. void saveProjectAsDefaultTemplate();
  130. void showSettingsDialog();
  131. void aboutLMMS();
  132. void help();
  133. void toggleAutomationEditorWin();
  134. void toggleBBEditorWin( bool forceShow = false );
  135. void toggleSongEditorWin();
  136. void toggleProjectNotesWin();
  137. void toggleFxMixerWin();
  138. void togglePianoRollWin();
  139. void toggleControllerRack();
  140. void updatePlayPauseIcons();
  141. void updateUndoRedoButtons();
  142. void undo();
  143. void redo();
  144. void autoSave();
  145. private slots:
  146. void onExportProjectMidi();
  147. protected:
  148. virtual void closeEvent( QCloseEvent * _ce );
  149. virtual void focusOutEvent( QFocusEvent * _fe );
  150. virtual void keyPressEvent( QKeyEvent * _ke );
  151. virtual void keyReleaseEvent( QKeyEvent * _ke );
  152. virtual void timerEvent( QTimerEvent * _ev );
  153. private:
  154. MainWindow();
  155. MainWindow( const MainWindow & );
  156. virtual ~MainWindow();
  157. void finalize();
  158. void toggleWindow( QWidget *window, bool forceShow = false );
  159. void refocus();
  160. void exportProject(bool multiExport = false);
  161. void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
  162. bool guiSaveProject();
  163. bool guiSaveProjectAs( const QString & filename );
  164. QMdiArea * m_workspace;
  165. QWidget * m_toolBar;
  166. QGridLayout * m_toolBarLayout;
  167. QMenu * m_templatesMenu;
  168. QMenu * m_recentlyOpenedProjectsMenu;
  169. int m_custom_templates_count;
  170. struct keyModifiers
  171. {
  172. keyModifiers() :
  173. m_ctrl( false ),
  174. m_shift( false ),
  175. m_alt( false )
  176. {
  177. }
  178. bool m_ctrl;
  179. bool m_shift;
  180. bool m_alt;
  181. } m_keyMods;
  182. QMenu * m_toolsMenu;
  183. QAction * m_undoAction;
  184. QAction * m_redoAction;
  185. QList<PluginView *> m_tools;
  186. QBasicTimer m_updateTimer;
  187. QTimer m_autoSaveTimer;
  188. int m_autoSaveInterval;
  189. friend class GuiApplication;
  190. QMenu * m_viewMenu;
  191. ToolButton * m_metronomeToggle;
  192. SessionState m_session;
  193. private slots:
  194. void browseHelp();
  195. void fillTemplatesMenu();
  196. void openRecentlyOpenedProject( QAction * _action );
  197. void showTool( QAction * _idx );
  198. void updateRecentlyOpenedProjectsMenu();
  199. void updateViewMenu( void );
  200. void updateConfig( QAction * _who );
  201. void onToggleMetronome();
  202. void onExportProject();
  203. void onExportProjectTracks();
  204. void onImportProject();
  205. void onSongStopped();
  206. void onSongModified();
  207. void onProjectFileNameChanged();
  208. signals:
  209. void periodicUpdate();
  210. void initProgress(const QString &msg);
  211. } ;
  212. #endif