scide: implement selectionLength for openDocument
[supercollider.git] / editors / sc-ide / widgets / main_window.hpp
blobfdd74864486173341f424c75df4590077d483d5c
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,
84 LookupReferences,
85 LookupDefinition,
86 LookupDocumentation,
88 // Settings
89 ShowSettings,
91 // Language
92 OpenDefinition,
93 FindReferences,
95 // Help
96 Help,
97 HelpForSelection,
99 // Server
100 ToggleServerRunning,
102 ActionCount
105 explicit MainWindow(Main *);
107 QAction *action( ActionRole );
109 bool quit();
111 void saveWindowState();
112 void restoreWindowState();
114 static MainWindow *instance() { return mInstance; }
116 static bool close( Document * );
117 static bool save( Document *, bool forceChoose = false );
118 static bool reload( Document * );
120 public Q_SLOTS:
121 void newSession();
122 void saveCurrentSessionAs();
123 void openSessionsDialog();
125 void newDocument();
126 void openDocument();
127 void saveDocument();
128 void saveDocumentAs();
129 void saveAllDocuments();
130 void reloadDocument();
131 void closeDocument();
132 void closeAllDocuments();
134 void showCmdLine();
135 void showFindTool();
136 void showReplaceTool();
137 void showGoToLineTool();
138 void hideToolBox();
140 void showSettings();
142 signals:
143 void evaluateCode( const QString &, bool silent = true );
145 public Q_SLOTS:
146 void showStatusMessage( QString const & string );
148 private Q_SLOTS:
149 void switchSession( Session *session );
150 void saveSession( Session *session );
151 void openHelp();
152 void openDocumentation();
153 void onInterpreterStateChanged( QProcess::ProcessState );
154 void onServerStatusReply(int ugens, int synths, int groups, int synthDefs, float avgCPU, float peakCPU);
155 void onServerRunningChanged( bool running, QString const & hostName, int port );
156 void onQuit();
157 void onCurrentDocumentChanged( Document * );
158 void onDocumentChangedExternally( Document * );
159 void onDocDialogFinished();
160 void updateRecentDocsMenu();
161 void onRecentDocAction( QAction * );
162 void onOpenSessionAction( QAction * );
163 void updateWindowTitle();
164 void toggleFullScreen();
165 void openDefinition();
166 void lookupDefinition();
167 void lookupDocumentation();
168 void findReferences();
169 void lookupReferences();
170 void toggleServerRunning();
171 void applySettings( Settings::Manager * );
172 void showSwitchSessionDialog();
174 protected:
175 virtual void closeEvent(QCloseEvent *event);
176 virtual void dragEnterEvent( QDragEnterEvent * );
177 virtual void dropEvent( QDropEvent * );
179 private:
180 void createActions();
181 void createMenus();
182 bool promptSaveDocs();
183 void updateSessionsMenu();
184 void updateClockWidget( bool isFullScreen );
185 void openSession( QString const & sessionName );
187 Main *mMain;
189 QAction * mActions[ActionCount];
190 QMenu * mRecentDocsMenu;
191 QMenu * mSessionsMenu;
193 MultiEditor *mEditors;
195 // Tools
196 ToolBox *mToolBox;
197 CmdLine *mCmdLine;
198 GoToLineTool *mGoToLineTool;
199 TextFindReplacePanel *mFindReplaceTool;
201 // Status bar
202 QStatusBar *mStatusBar;
203 StatusLabel *mLangStatus;
204 StatusLabel *mServerStatus;
205 StatusClockLabel *mClockLabel;
207 // Docks
208 PostDock * mPostDock;
209 DocumentsDock *mDocListDock;
211 QSignalMapper mCodeEvalMapper;
212 DocumentsDialog * mDocDialog;
214 static MainWindow *mInstance;
217 class StatusLabel : public QLabel
219 public:
220 StatusLabel(QWidget *parent = 0);
221 void setBackground(const QBrush &);
222 void setTextColor(const QColor &);
225 class StatusClockLabel : public StatusLabel
227 public:
228 StatusClockLabel (QWidget * parent = 0);
229 ~StatusClockLabel();
231 private:
232 void timerEvent(QTimerEvent *);
233 void updateTime();
234 int mTimerId;
237 } // namespace ScIDE
239 #endif