MainWindow.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 openProject();
  125. bool saveProject();
  126. bool saveProjectAs();
  127. bool saveProjectAsNewVersion();
  128. void saveProjectAsDefaultTemplate();
  129. void showSettingsDialog();
  130. void aboutLMMS();
  131. void help();
  132. void toggleAutomationEditorWin();
  133. void toggleBBEditorWin( bool forceShow = false );
  134. void toggleSongEditorWin();
  135. void toggleProjectNotesWin();
  136. void toggleFxMixerWin();
  137. void togglePianoRollWin();
  138. void toggleControllerRack();
  139. void updatePlayPauseIcons();
  140. void updateUndoRedoButtons();
  141. void undo();
  142. void redo();
  143. void autoSave();
  144. private slots:
  145. void onExportProjectMidi();
  146. protected:
  147. void closeEvent( QCloseEvent * _ce ) override;
  148. void focusOutEvent( QFocusEvent * _fe ) override;
  149. void keyPressEvent( QKeyEvent * _ke ) override;
  150. void keyReleaseEvent( QKeyEvent * _ke ) override;
  151. void timerEvent( QTimerEvent * _ev ) override;
  152. private:
  153. MainWindow();
  154. MainWindow( const MainWindow & );
  155. virtual ~MainWindow();
  156. void finalize();
  157. void toggleWindow( QWidget *window, bool forceShow = false );
  158. void refocus();
  159. void exportProject(bool multiExport = false);
  160. void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
  161. bool guiSaveProject();
  162. bool guiSaveProjectAs( const QString & filename );
  163. QMdiArea * m_workspace;
  164. QWidget * m_toolBar;
  165. QGridLayout * m_toolBarLayout;
  166. struct keyModifiers
  167. {
  168. keyModifiers() :
  169. m_ctrl( false ),
  170. m_shift( false ),
  171. m_alt( false )
  172. {
  173. }
  174. bool m_ctrl;
  175. bool m_shift;
  176. bool m_alt;
  177. } m_keyMods;
  178. QMenu * m_toolsMenu;
  179. QAction * m_undoAction;
  180. QAction * m_redoAction;
  181. QList<PluginView *> m_tools;
  182. QBasicTimer m_updateTimer;
  183. QTimer m_autoSaveTimer;
  184. int m_autoSaveInterval;
  185. friend class GuiApplication;
  186. QMenu * m_viewMenu;
  187. ToolButton * m_metronomeToggle;
  188. SessionState m_session;
  189. private slots:
  190. void browseHelp();
  191. void showTool( QAction * _idx );
  192. void updateViewMenu( void );
  193. void updateConfig( QAction * _who );
  194. void onToggleMetronome();
  195. void onExportProject();
  196. void onExportProjectTracks();
  197. void onImportProject();
  198. void onSongStopped();
  199. void onSongModified();
  200. void onProjectFileNameChanged();
  201. signals:
  202. void periodicUpdate();
  203. void initProgress(const QString &msg);
  204. } ;
  205. #endif