GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
main-window.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013 John W. Eaton
4 Copyright (C) 2011-2013 Jacob Dawid
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_main_window_h)
25 #define octave_main_window_h 1
26 
27 // Qt includes
28 #include <QMainWindow>
29 #include <QThread>
30 #include <QTabWidget>
31 #include <QMdiArea>
32 #include <QStatusBar>
33 #include <QToolBar>
34 #include <QQueue>
35 #include <QMdiSubWindow>
36 #include <QCloseEvent>
37 #include <QToolButton>
38 #include <QComboBox>
39 #include <QSemaphore>
40 
41 // Editor includes
42 #include "file-editor-interface.h"
43 
44 // QTerminal includes
45 #include "QTerminal.h"
46 
47 // Own includes
48 #include "dialog.h"
49 #include "resource-manager.h"
50 #include "workspace-model.h"
51 #include "workspace-view.h"
52 #include "history-dock-widget.h"
53 #include "files-dock-widget.h"
54 #include "terminal-dock-widget.h"
56 #include "octave-qt-link.h"
57 #include "octave-dock-widget.h"
58 #include "find-files-dialog.h"
59 
60 /**
61  * \class MainWindow
62  *
63  * Represents the main window.
64  */
65 class main_window : public QMainWindow
66 {
67  Q_OBJECT
68 
69 public:
70 
71  typedef std::pair <std::string, std::string> name_pair;
72 
73  main_window (QWidget *parent = 0);
74 
75  ~main_window (void);
76 
77  bool command_window_has_focus (void) const;
78 
79  void focus_command_window (void);
80 
81 signals:
82  void settings_changed (const QSettings *);
83  void new_file_signal (const QString&);
84  void open_file_signal (const QString&);
85 
86  void show_doc_signal (const QString&);
87 
88  void insert_debugger_pointer_signal (const QString& file, int line);
89  void delete_debugger_pointer_signal (const QString& file, int line);
90  void update_breakpoint_marker_signal (bool insert, const QString& file,
91  int line);
92 
93  void copyClipboard_signal (void);
94  void pasteClipboard_signal (void);
95 
96  void set_widget_shortcuts_signal (bool);
97 
98 public slots:
99  void report_status_message (const QString& statusMessage);
100  void handle_save_workspace_request (void);
101  void handle_load_workspace_request (const QString& file = QString ());
103  void handle_clear_workspace_request (void);
104  void handle_clear_history_request (void);
105  void handle_rename_variable_request (const QString& old_name,
106  const QString& new_name);
107  void handle_undo_request (void);
108  void new_file (const QString& commands = QString ());
109  void open_file (const QString& file_name = QString ());
110  void open_online_documentation_page (void);
111  void display_release_notes (void);
112  void load_and_display_community_news (int serial = -1);
113  void display_community_news (const QString& news);
114  void open_bug_tracker_page (void);
115  void open_octave_packages_page (void);
116  void open_agora_page (void);
117  void open_contribute_page (void);
118  void open_developer_page (void);
119  void process_settings_dialog_request (const QString& desired_tab
120  = QString ());
121  void show_about_octave (void);
122  void notice_settings (const QSettings *settings);
123  void prepare_to_exit (void);
124  void exit (int status);
125  void reset_windows (void);
126 
127  void hide_warning_bar (void);
128  void show_gui_info (void);
129 
130  void change_directory (const QString& dir);
131  void browse_for_directory (void);
132  void set_current_working_directory (const QString& dir);
133  void change_directory_up (void);
134  void accept_directory_line_edit (void);
135 
136  void execute_command_in_terminal (const QString& dir);
137  void run_file_in_terminal (const QFileInfo& info);
138 
139  void handle_new_figure_request (void);
140 
141  void handle_enter_debugger (void);
142  void handle_exit_debugger (void);
143  void debug_continue (void);
144  void debug_step_into (void);
145  void debug_step_over (void);
146  void debug_step_out (void);
147  void debug_quit (void);
148 
149  void handle_insert_debugger_pointer_request (const QString& file, int line);
150  void handle_delete_debugger_pointer_request (const QString& file, int line);
151  void handle_update_breakpoint_marker_request (bool insert,
152  const QString& file, int line);
153 
154  void read_settings (void);
155  void set_window_layout (QSettings *settings);
156  void write_settings (void);
157  void connect_visibility_changed (void);
158 
159  void copyClipboard (void);
160  void pasteClipboard (void);
161 
162  void connect_uiwidget_links ();
163 
164  void handle_create_dialog (const QString& message, const QString& title,
165  const QString& icon, const QStringList& button,
166  const QString& defbutton,
167  const QStringList& role);
168 
169  void handle_create_listview (const QStringList& list, const QString& mode,
170  int width, int height,
171  const QIntList& initial,
172  const QString& name,
173  const QStringList& prompt,
174  const QString& ok_string,
175  const QString& cancel_string);
176 
177  void handle_create_inputlayout (const QStringList&, const QString&,
178  const QFloatList&, const QFloatList&,
179  const QStringList&);
180 
181  void handle_create_filedialog (const QStringList &filters,
182  const QString& title, const QString& filename,
183  const QString &dirname,
184  const QString& multimode);
185 
186  void handle_show_doc (const QString &file);
187 
188  // find files dialog
189  void find_files (const QString &startdir=QDir::currentPath ());
190  void find_files_finished (int);
191 
192  // setting global shortcuts
193  void set_global_shortcuts (bool enable);
194 
195  // handling the clipboard
196  void clipboard_has_changed (QClipboard::Mode);
197  void clear_clipboard ();
198 
199 
200 protected:
201  void closeEvent (QCloseEvent * closeEvent);
202 
203 private:
204 
205  void construct (void);
206 
207  void construct_octave_qt_link (void);
208 
209  void construct_menu_bar (void);
210  void construct_file_menu (QMenuBar *p);
211  void construct_new_menu (QMenu *p);
212  void construct_edit_menu (QMenuBar *p);
213  void construct_debug_menu_item (QMenu *p, const QString& item,
214  const QKeySequence& key);
215  QAction *construct_debug_menu_item (const char *icon_file,
216  const QString& item,
217  const QKeySequence& key);
218  void construct_debug_menu (QMenuBar *p);
219  QAction *construct_window_menu_item (QMenu *p, const QString& item,
220  bool checkable,
221  const QKeySequence& key);
222  void construct_window_menu (QMenuBar *p);
223  void construct_help_menu (QMenuBar *p);
224  void construct_documentation_menu (QMenu *p);
225 
226  void construct_news_menu (QMenuBar *p);
227 
228  void construct_warning_bar (void);
229  void construct_gui_info_button (void);
230 
231  void construct_tool_bar (void);
232 
233  void establish_octave_link (void);
234 
235  void save_workspace_callback (const std::string& file);
236 
237  void load_workspace_callback (const std::string& file);
238 
240 
241  void command_window_undo_callback (void);
242 
243  void clear_command_window_callback (void);
244 
245  void resize_command_window_callback (void);
246 
247  void clear_workspace_callback (void);
248 
249  void clear_history_callback (void);
250 
251  void execute_command_callback ();
252  void run_file_callback (const QFileInfo& info);
253 
254  void new_figure_callback (void);
255 
256  void change_directory_callback (const std::string& directory);
257 
258  void debug_continue_callback (void);
259 
260  void debug_step_into_callback (void);
261 
262  void debug_step_over_callback (void);
263 
264  void debug_step_out_callback (void);
265 
266  void debug_quit_callback (void);
267 
268  void exit_callback (void);
269 
270  void queue_command (QString command); // Data models.
271 
273 
274  // Toolbars.
275  QStatusBar *status_bar;
276 
277  // Subwindows.
285  {
287  list.append (static_cast<octave_dock_widget *> (command_window));
288  list.append (static_cast<octave_dock_widget *> (history_window));
289  list.append (static_cast<octave_dock_widget *> (file_browser_window));
290  list.append (static_cast<octave_dock_widget *> (doc_browser_window));
291 #ifdef HAVE_QSCINTILLA
292  list.append (static_cast<octave_dock_widget *> (editor_window));
293 #endif
294  list.append (static_cast<octave_dock_widget *> (workspace_window));
295  return list;
296  }
297 
299 
300  QToolBar *_main_tool_bar;
301 
304 
305  QMenu *_debug_menu;
306 
307  QAction *_debug_continue;
310  QAction *_debug_step_out;
311  QAction *_debug_quit;
312 
315  QAction *_open_action;
316 
317  QAction *_copy_action;
318  QAction *_paste_action;
320  QAction *_undo_action;
321 
323  QAction *_exit_action;
324 
325  // Toolbars.
327  static const int current_directory_width = 300;
328  static const int current_directory_max_visible = 16;
329  static const int current_directory_max_count = 16;
331 
332  // Find files dialog
334 
335  // release notes window
337 
339 
341 
342  QClipboard *_clipboard;
343 
344  // Flag for closing whole application.
345  bool _closing;
346 
347  // semaphore to synchronize execution signals and related callback
348  QStringList *_cmd_queue;
349  QSemaphore _cmd_processing;
351 };
352 
353 class news_reader : public QObject
354 {
355  Q_OBJECT
356 
357 public:
358 
359  news_reader (const QString& xbase_url, const QString& xpage,
360  int xserial = -1, bool xconnect_to_web = false)
361  : QObject (), base_url (xbase_url), page (xpage), serial (xserial),
362  connect_to_web (xconnect_to_web)
363  { }
364 
365 public slots:
366 
367  void process (void);
368 
369 signals:
370 
371  void display_news_signal (const QString& news);
372 
373  void finished (void);
374 
375 private:
376 
377  QString base_url;
378  QString page;
379  int serial;
381 };
382 
383 #endif // MAINWINDOW_H