MainWindow.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 = QFlag(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. // TODO Remove this function, since m_shift can get stuck down.
  107. // [[deprecated]]
  108. bool isShiftPressed()
  109. {
  110. return m_keyMods.m_shift;
  111. }
  112. static void saveWidgetState( QWidget * _w, QDomElement & _de );
  113. static void restoreWidgetState( QWidget * _w, const QDomElement & _de );
  114. public slots:
  115. void resetWindowTitle();
  116. void emptySlot();
  117. void createNewProject();
  118. void openProject();
  119. bool saveProject();
  120. bool saveProjectAs();
  121. bool saveProjectAsNewVersion();
  122. void saveProjectAsDefaultTemplate();
  123. void showSettingsDialog();
  124. void aboutLMMS();
  125. void help();
  126. void toggleAutomationEditorWin();
  127. void togglePatternEditorWin(bool forceShow = false);
  128. void toggleSongEditorWin();
  129. void toggleProjectNotesWin();
  130. void toggleMicrotunerWin();
  131. void toggleMixerWin();
  132. void togglePianoRollWin();
  133. void toggleControllerRack();
  134. void toggleFullscreen();
  135. void updatePlayPauseIcons();
  136. void updateUndoRedoButtons();
  137. void undo();
  138. void redo();
  139. void autoSave();
  140. private slots:
  141. void onExportProjectMidi();
  142. protected:
  143. void closeEvent( QCloseEvent * _ce ) override;
  144. void focusOutEvent( QFocusEvent * _fe ) override;
  145. void keyPressEvent( QKeyEvent * _ke ) override;
  146. void keyReleaseEvent( QKeyEvent * _ke ) override;
  147. void timerEvent( QTimerEvent * _ev ) override;
  148. private:
  149. MainWindow();
  150. MainWindow( const MainWindow & );
  151. virtual ~MainWindow();
  152. void finalize();
  153. void toggleWindow( QWidget *window, bool forceShow = false );
  154. void refocus();
  155. void exportProject(bool multiExport = false);
  156. void handleSaveResult(QString const & filename, bool songSavedSuccessfully);
  157. bool guiSaveProject();
  158. bool guiSaveProjectAs( const QString & filename );
  159. QMdiArea * m_workspace;
  160. QWidget * m_toolBar;
  161. QGridLayout * m_toolBarLayout;
  162. struct keyModifiers
  163. {
  164. keyModifiers() :
  165. m_ctrl( false ),
  166. m_shift( false ),
  167. m_alt( false )
  168. {
  169. }
  170. bool m_ctrl;
  171. bool m_shift;
  172. bool m_alt;
  173. } m_keyMods;
  174. QMenu * m_toolsMenu;
  175. QAction * m_undoAction;
  176. QAction * m_redoAction;
  177. QList<PluginView *> m_tools;
  178. QBasicTimer m_updateTimer;
  179. QTimer m_autoSaveTimer;
  180. int m_autoSaveInterval;
  181. friend class GuiApplication;
  182. QMenu * m_viewMenu;
  183. ToolButton * m_metronomeToggle;
  184. SessionState m_session;
  185. bool maximized;
  186. private slots:
  187. void browseHelp();
  188. void showTool( QAction * _idx );
  189. void updateViewMenu( void );
  190. void updateConfig( QAction * _who );
  191. void onToggleMetronome();
  192. void onExportProject();
  193. void onExportProjectTracks();
  194. void onImportProject();
  195. void onSongStopped();
  196. void onSongModified();
  197. void onProjectFileNameChanged();
  198. signals:
  199. void periodicUpdate();
  200. void initProgress(const QString &msg);
  201. } ;
  202. #endif