Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / editors / sc-ide / widgets / main_window.hpp
blobae654ed06f5e57db08cafe167c87930ce0629544
1 /*
2 SuperCollider Qt IDE
3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef SCIDE_WIDGETS_MAIN_WINDOW_HPP_INCLUDED
22 #define SCIDE_WIDGETS_MAIN_WINDOW_HPP_INCLUDED
24 #include <QLabel>
25 #include <QMainWindow>
26 #include <QProcess>
27 #include <QSignalMapper>
28 #include <QStatusBar>
30 namespace ScIDE {
32 class Main;
33 class MultiEditor;
34 class ToolBox;
35 class TextFindReplacePanel;
36 class GoToLineTool;
37 class PostDock;
38 class DocumentsDock;
39 class CmdLine;
40 class Document;
41 class DocumentsDialog;
42 struct Session;
43 class StatusLabel;
44 class StatusClockLabel;
46 namespace Settings { class Manager; }
48 class MainWindow : public QMainWindow
50 Q_OBJECT
52 public:
54 enum ActionRole {
55 // File
56 Quit = 0,
57 DocNew,
58 DocOpen,
59 DocSave,
60 DocSaveAs,
61 DocSaveAll,
62 DocClose,
63 DocCloseAll,
64 DocReload,
65 ClearRecentDocs,
67 // Sessions
68 NewSession,
69 SaveSessionAs,
70 ManageSessions,
71 OpenSessionSwitchDialog,
73 // Edit
74 Find,
75 Replace,
77 // View
78 ShowCmdLine,
79 ShowGoToLineTool,
80 CloseToolBox,
81 ShowFullScreen,
82 ClearPostWindow,
83 FocusPostWindow,
85 LookupReferences,
86 LookupDefinition,
87 LookupDocumentation,
89 // Settings
90 ShowSettings,
92 // Language
93 OpenDefinition,
94 FindReferences,
96 // Help
97 Help,
98 HelpForSelection,
100 // Server
101 ServerToggleRunning,
102 ServerReboot,
103 ServerShowMeters,
104 ServerDumpNodeTree,
105 ServerDumpNodeTreeWithControls,
107 ActionCount
110 explicit MainWindow(Main *);
112 QAction *action( ActionRole );
114 bool quit();
116 void saveWindowState();
117 void restoreWindowState();
118 void focusCodeEditor();
120 static MainWindow *instance() { return mInstance; }
122 static bool close( Document * );
123 static bool save( Document *, bool forceChoose = false );
124 static bool reload( Document * );
126 public Q_SLOTS:
127 void newSession();
128 void saveCurrentSessionAs();
129 void openSessionsDialog();
131 void newDocument();
132 void openDocument();
133 void saveDocument();
134 void saveDocumentAs();
135 void saveAllDocuments();
136 void reloadDocument();
137 void closeDocument();
138 void closeAllDocuments();
140 void showCmdLine();
141 void showFindTool();
142 void showReplaceTool();
143 void showGoToLineTool();
144 void hideToolBox();
146 void showSettings();
148 signals:
149 void evaluateCode( const QString &, bool silent = true );
151 public Q_SLOTS:
152 void showStatusMessage( QString const & string );
154 private Q_SLOTS:
155 void switchSession( Session *session );
156 void saveSession( Session *session );
157 void openHelp();
158 void openDocumentation();
159 void onInterpreterStateChanged( QProcess::ProcessState );
160 void onServerStatusReply(int ugens, int synths, int groups, int synthDefs, float avgCPU, float peakCPU);
161 void onServerRunningChanged( bool running, QString const & hostName, int port );
162 void onQuit();
163 void onCurrentDocumentChanged( Document * );
164 void onDocumentChangedExternally( Document * );
165 void onDocDialogFinished();
166 void updateRecentDocsMenu();
167 void onRecentDocAction( QAction * );
168 void onOpenSessionAction( QAction * );
169 void updateWindowTitle();
170 void toggleFullScreen();
171 void openDefinition();
172 void lookupDefinition();
173 void lookupDocumentation();
174 void findReferences();
175 void lookupReferences();
176 void serverToggleRunning();
177 void serverReboot();
178 void serverDumpNodeTree();
179 void serverDumpNodeTreeWithControls();
180 void serverShowMeters();
181 void applySettings( Settings::Manager * );
182 void showSwitchSessionDialog();
184 protected:
185 virtual void closeEvent(QCloseEvent *event);
186 virtual void dragEnterEvent( QDragEnterEvent * );
187 virtual void dropEvent( QDropEvent * );
189 private:
190 void createActions();
191 void createMenus();
192 bool promptSaveDocs();
193 void updateSessionsMenu();
194 void updateClockWidget( bool isFullScreen );
195 void openSession( QString const & sessionName );
197 Main *mMain;
199 QAction * mActions[ActionCount];
200 QMenu * mRecentDocsMenu;
201 QMenu * mSessionsMenu;
203 MultiEditor *mEditors;
205 // Tools
206 ToolBox *mToolBox;
207 CmdLine *mCmdLine;
208 GoToLineTool *mGoToLineTool;
209 TextFindReplacePanel *mFindReplaceTool;
211 // Status bar
212 QStatusBar *mStatusBar;
213 StatusLabel *mLangStatus;
214 StatusLabel *mServerStatus;
215 StatusClockLabel *mClockLabel;
217 // Docks
218 PostDock * mPostDock;
219 DocumentsDock *mDocListDock;
221 QSignalMapper mCodeEvalMapper;
222 DocumentsDialog * mDocDialog;
224 static MainWindow *mInstance;
227 class StatusLabel : public QLabel
229 public:
230 StatusLabel(QWidget *parent = 0);
231 void setBackground(const QBrush &);
232 void setTextColor(const QColor &);
235 class StatusClockLabel : public StatusLabel
237 public:
238 StatusClockLabel (QWidget * parent = 0);
239 ~StatusClockLabel();
241 private:
242 void timerEvent(QTimerEvent *);
243 void updateTime();
244 int mTimerId;
247 } // namespace ScIDE
249 #endif