comparison gui/src/MainWindow.cpp @ 14599:97cb9286919c gui

Cleaned up code. * .hgsub: Removed IRC Widget. * gui.pro: Removed dependency on IRC Widget and removed files. * class FileEditorMdiSubWindow: Renamed to FileEditor. File editor windows are now independent windows, thus removed the extra close button. * MainWindow: Removed MDI Area and replaced it with the terminal instead. * BrowserWidget: Removed browser widget. * SettingsDialog: Rearranged settings for the editor, removed tab for shortcuts. * OctaveCallbackThread: Raised update intervals from 0,5s to 1s. * OctaveLink: Replaced signals names for triggering updates on the symbol table. * WorkspaceView: Adjusted connect statements to fit the new signal names.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 07 May 2012 00:53:54 +0200
parents fa52c6e84ae0
children 772ce0204b3f
comparison
equal deleted inserted replaced
14588:fa52c6e84ae0 14599:97cb9286919c
21 #include <QSettings> 21 #include <QSettings>
22 #include <QDesktopServices> 22 #include <QDesktopServices>
23 #include <QFileDialog> 23 #include <QFileDialog>
24 #include <QMessageBox> 24 #include <QMessageBox>
25 #include "MainWindow.h" 25 #include "MainWindow.h"
26 #include "FileEditorMdiSubWindow.h" 26 #include "FileEditor.h"
27 #include "SettingsDialog.h" 27 #include "SettingsDialog.h"
28 28
29 #define VERSION_STRING "Octave GUI (0.8.8)" 29 #define VERSION_STRING "Octave GUI (0.8.8)"
30 30
31 MainWindow::MainWindow (QWidget * parent):QMainWindow (parent) 31 MainWindow::MainWindow (QWidget * parent):QMainWindow (parent)
32 { 32 {
33 // We have to set up all our windows, before we finally launch octave.
33 construct (); 34 construct ();
34 OctaveLink::instance ()->launchOctave(); 35 OctaveLink::instance ()->launchOctave();
35 } 36 }
36 37
37 MainWindow::~MainWindow () 38 MainWindow::~MainWindow ()
38 { 39 {
39 } 40 }
40 41
41 void 42 void
42 MainWindow::handleOpenFileRequest (QString fileName) 43 MainWindow::openExistingFile (QString fileName)
43 { 44 {
44 reportStatusMessage (tr ("Opening file.")); 45 reportStatusMessage (tr ("Opening file.."));
45 QPixmap pixmap; 46 newEditorWindow(fileName);
46 if (pixmap.load (fileName)) 47 }
47 { 48
48 // ImageViewerMdiSubWindow *subWindow = new ImageViewerMdiSubWindow(pixmap, this); 49 void
49 // subWindow->setAttribute(Qt::WA_DeleteOnClose); 50 MainWindow::newFile ()
50 // m_centralMdiArea->addSubWindow(subWindow); 51 {
51 // subWindow->setWindowTitle(fileName); 52 newEditorWindow(QString());
52 } 53 }
53 else 54
54 { 55 void
55 openEditorFile(fileName); 56 MainWindow::newEditorWindow (QString fileName)
56 } 57 {
57 } 58 FileEditor *fileEditor = new FileEditor ();
58 59 fileEditor->setAttribute (Qt::WA_DeleteOnClose);
59 void
60 MainWindow::openEditor ()
61 {
62 openEditorFile(QString());
63 }
64 void
65 MainWindow::openEditorFile (QString fileName)
66 {
67 FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea);
68 subWindow->setAttribute (Qt::WA_DeleteOnClose);
69 // check whether lexer is already prepared and prepare it if not 60 // check whether lexer is already prepared and prepare it if not
70 if ( m_lexer == NULL ) 61 if ( m_lexer == NULL )
71 { 62 {
72 // this has to be done only once, not for each editor 63 // this has to be done only once, not for each editor
73 m_lexer = new LexerOctaveGui(); 64 m_lexer = new LexerOctaveGui();
95 { 86 {
96 m_lexerAPI->add(keywordList.at(i)); // add single strings to the API 87 m_lexerAPI->add(keywordList.at(i)); // add single strings to the API
97 } 88 }
98 m_lexerAPI->prepare(); // prepare API info ... this make take some time 89 m_lexerAPI->prepare(); // prepare API info ... this make take some time
99 } 90 }
100 subWindow->initEditor(m_terminalView, m_lexer, this); // init necessary informations for editor 91 fileEditor->initEditor(m_terminalView, m_lexer, this); // init necessary informations for editor
101 92
102 if ( fileName.isEmpty() ) 93 if ( fileName.isEmpty() )
103 subWindow->newFile (); 94 fileEditor->newFile ();
104 else 95 else
105 subWindow->loadFile (fileName); 96 fileEditor->loadFile (fileName);
106 } 97 }
107 98
108 99
109 void 100 void
110 MainWindow::reportStatusMessage (QString statusMessage) 101 MainWindow::reportStatusMessage (QString statusMessage)
111 { 102 {
112 m_statusBar->showMessage (statusMessage, 1000); 103 m_statusBar->showMessage (statusMessage, 1000);
113 }
114
115 void
116 MainWindow::openWebPage (QString url)
117 {
118 m_documentationWidget->load (QUrl (url));
119 }
120
121 void
122 MainWindow::openChat ()
123 {
124 if (!m_ircWidget)
125 {
126 m_ircWidget = new QIRCWidget ();
127 m_ircWidget->setWindowTitle ("Chat");
128 m_ircWidget->connectToServer ("irc.freenode.net", "Octave-GUI-User", "#octave");
129 }
130
131 if (!m_ircWidget->isVisible ())
132 {
133 m_ircWidget->setVisible (true);
134 m_ircWidget->raise ();
135 }
136 } 104 }
137 105
138 void 106 void
139 MainWindow::handleSaveWorkspaceRequest () 107 MainWindow::handleSaveWorkspaceRequest ()
140 { 108 {
165 void 133 void
166 MainWindow::handleCommandDoubleClicked (QString command) 134 MainWindow::handleCommandDoubleClicked (QString command)
167 { 135 {
168 m_terminalView->sendText(command); 136 m_terminalView->sendText(command);
169 m_terminalView->setFocus (); 137 m_terminalView->setFocus ();
170 }
171
172 void
173 MainWindow::alignMdiWindows ()
174 {
175 m_centralMdiArea->tileSubWindows ();
176 } 138 }
177 139
178 void 140 void
179 MainWindow::openBugTrackerPage () 141 MainWindow::openBugTrackerPage ()
180 { 142 {
239 201
240 QMessageBox::about (this, tr ("About Octave"), message); 202 QMessageBox::about (this, tr ("About Octave"), message);
241 } 203 }
242 204
243 void 205 void
244 MainWindow::showAboutQt ()
245 {
246 QMessageBox::aboutQt (this);
247 }
248
249 void
250 MainWindow::closeEvent (QCloseEvent * closeEvent) 206 MainWindow::closeEvent (QCloseEvent * closeEvent)
251 { 207 {
252 reportStatusMessage (tr ("Saving data and shutting down.")); 208 reportStatusMessage (tr ("Saving data and shutting down."));
253 writeSettings (); 209 writeSettings ();
254 m_closeApplication = true; // inform editor window that whole application is closed 210 m_closeApplication = true; // inform editor window that whole application is closed
255 OctaveLink::instance ()->terminateOctave(); 211 OctaveLink::instance ()->terminateOctave();
256 m_centralMdiArea->closeAllSubWindows(); // send close events to subwindows 212
257 // (editor files can be saved!)
258 QMainWindow::closeEvent (closeEvent); 213 QMainWindow::closeEvent (closeEvent);
259 } 214 }
260 215
261 void 216 void
262 MainWindow::readSettings () 217 MainWindow::readSettings ()
263 { 218 {
264 QSettings *settings = ResourceManager::instance ()->settings (); 219 QSettings *settings = ResourceManager::instance ()->settings ();
265 restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ()); 220 restoreGeometry (settings->value ("MainWindow/geometry").toByteArray ());
266 restoreState (settings->value ("MainWindow/windowState").toByteArray ()); 221 restoreState (settings->value ("MainWindow/windowState").toByteArray ());
267 m_centralMdiArea->restoreGeometry (settings->value ("MdiArea/geometry").toByteArray ());
268 emit settingsChanged (); 222 emit settingsChanged ();
269 } 223 }
270 224
271 void 225 void
272 MainWindow::writeSettings () 226 MainWindow::writeSettings ()
273 { 227 {
274 QSettings *settings = ResourceManager::instance ()->settings (); 228 QSettings *settings = ResourceManager::instance ()->settings ();
275 settings->setValue ("MainWindow/geometry", saveGeometry ()); 229 settings->setValue ("MainWindow/geometry", saveGeometry ());
276 settings->setValue ("MainWindow/windowState", saveState ()); 230 settings->setValue ("MainWindow/windowState", saveState ());
277 settings->setValue ("MdiArea/geometry", m_centralMdiArea->saveGeometry ());
278 } 231 }
279 232
280 void 233 void
281 MainWindow::construct () 234 MainWindow::construct ()
282 { 235 {
236 // TODO: Check this.
283 m_closeApplication = false; // flag for editor files when closed 237 m_closeApplication = false; // flag for editor files when closed
284 setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Octave)); 238 setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Octave));
285
286 m_ircWidget = 0;
287
288 // Initialize MDI area.
289 m_centralMdiArea = new QMdiArea (this);
290 m_centralMdiArea->setObjectName ("CentralMdiArea");
291 m_centralMdiArea->setViewMode (QMdiArea::TabbedView);
292 239
293 // Setup dockable widgets and the status bar. 240 // Setup dockable widgets and the status bar.
294 m_workspaceView = new WorkspaceView (this); 241 m_workspaceView = new WorkspaceView (this);
295 m_workspaceView->setStatusTip (tr ("View the variables in the active workspace.")); 242 m_workspaceView->setStatusTip (tr ("View the variables in the active workspace."));
296 m_historyDockWidget = new HistoryDockWidget (this); 243 m_historyDockWidget = new HistoryDockWidget (this);
297 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history.")); 244 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history."));
298 m_filesDockWidget = new FilesDockWidget (this); 245 m_filesDockWidget = new FilesDockWidget (this);
299 m_filesDockWidget->setStatusTip (tr ("Browse your files.")); 246 m_filesDockWidget->setStatusTip (tr ("Browse your files."));
300 m_statusBar = new QStatusBar (this); 247 m_statusBar = new QStatusBar (this);
301 248
302 // Documentation subwindow.
303 m_documentationWidget = new BrowserWidget (this);
304 m_documentationWidgetSubWindow = new NonClosableMdiSubWindow (this);
305 m_documentationWidgetSubWindow->setWidget (m_documentationWidget);
306 m_centralMdiArea->addSubWindow (m_documentationWidgetSubWindow, Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
307
308 m_documentationWidgetSubWindow->setObjectName ("DocumentationWidgetSubWindow");
309 m_documentationWidgetSubWindow->setWindowTitle (tr ("Documentation"));
310 m_documentationWidgetSubWindow
311 ->setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Documentation));
312 m_documentationWidgetSubWindow->setFocusProxy (m_documentationWidget);
313 m_documentationWidgetSubWindow->setStatusTip (tr ("Browse the Octave documentation for help."));
314 m_documentationWidgetSubWindow->setMinimumSize (300, 300);
315
316 // Octave Terminal subwindow. 249 // Octave Terminal subwindow.
317 m_terminalView = new QTerminal(this); 250 m_terminalView = new QTerminal(this);
318 m_terminalViewSubWindow = new NonClosableMdiSubWindow (this); 251 setCentralWidget (m_terminalView);
319 m_terminalViewSubWindow->setWidget (m_terminalView);
320 m_centralMdiArea->addSubWindow (m_terminalViewSubWindow, Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
321
322 m_terminalViewSubWindow->setObjectName ("OctaveTerminalSubWindow");
323 m_terminalViewSubWindow->setWindowTitle (tr ("Terminal"));
324 m_terminalViewSubWindow
325 ->setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Terminal));
326 m_terminalViewSubWindow->setFocusProxy (m_terminalView);
327 m_terminalViewSubWindow->setStatusTip (tr ("Enter your commands into the Octave terminal."));
328 m_terminalViewSubWindow->setMinimumSize (300, 300);
329 252
330 m_lexer = NULL; // initialise the empty lexer for the edtiors 253 m_lexer = NULL; // initialise the empty lexer for the edtiors
331 254
332 QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave")); 255 QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave"));
333 QAction *settingsAction = controlMenu->addAction (tr ("Settings")); 256 QAction *settingsAction = controlMenu->addAction (tr ("Settings"));
334 controlMenu->addSeparator (); 257 controlMenu->addSeparator ();
335 QAction *exitAction = controlMenu->addAction (tr ("Exit")); 258 QAction *exitAction = controlMenu->addAction (tr ("Exit"));
336 259
337 QMenu *interfaceMenu = menuBar ()->addMenu (tr ("Interface")); 260 QMenu *interfaceMenu = menuBar ()->addMenu (tr ("Interface"));
338 261
339 QAction *alignWindowsAction = interfaceMenu->addAction (tr ("Align Windows"));
340 interfaceMenu->addSeparator ();
341 QAction *showWorkspaceAction = interfaceMenu->addAction (tr ("Workspace")); 262 QAction *showWorkspaceAction = interfaceMenu->addAction (tr ("Workspace"));
342 showWorkspaceAction->setCheckable (true); 263 showWorkspaceAction->setCheckable (true);
343 264
344 QAction *showHistoryAction = interfaceMenu->addAction (tr ("History")); 265 QAction *showHistoryAction = interfaceMenu->addAction (tr ("History"));
345 showHistoryAction->setCheckable (true); 266 showHistoryAction->setCheckable (true);
355 QAction *saveWorkspaceAction = workspaceMenu->addAction (tr ("Save")); 276 QAction *saveWorkspaceAction = workspaceMenu->addAction (tr ("Save"));
356 workspaceMenu->addSeparator (); 277 workspaceMenu->addSeparator ();
357 QAction *clearWorkspaceAction = workspaceMenu->addAction (tr ("Clear")); 278 QAction *clearWorkspaceAction = workspaceMenu->addAction (tr ("Clear"));
358 279
359 QMenu *communityMenu = menuBar ()->addMenu (tr ("Community")); 280 QMenu *communityMenu = menuBar ()->addMenu (tr ("Community"));
360 QAction *openChatAction = communityMenu->addAction (tr ("Chat"));
361 communityMenu->addSeparator();
362 QAction *reportBugAction = communityMenu->addAction (tr ("Report Bug")); 281 QAction *reportBugAction = communityMenu->addAction (tr ("Report Bug"));
363 QAction *agoraAction = communityMenu->addAction (tr ("Agora")); 282 QAction *agoraAction = communityMenu->addAction (tr ("Agora"));
364 QAction *octaveForgeAction = communityMenu->addAction (tr ("Octave Forge")); 283 QAction *octaveForgeAction = communityMenu->addAction (tr ("Octave Forge"));
365 communityMenu->addSeparator (); 284 communityMenu->addSeparator ();
366 QAction *aboutOctaveAction = communityMenu->addAction (tr ("About Octave")); 285 QAction *aboutOctaveAction = communityMenu->addAction (tr ("About Octave"));
367 QAction *aboutQt = communityMenu->addAction (tr ("About Qt"));
368 286
369 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ())); 287 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ()));
370 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ())); 288 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ()));
371 connect (alignWindowsAction, SIGNAL (triggered ()), this, SLOT (alignMdiWindows ())); 289 connect (openEditorAction, SIGNAL (triggered ()), this, SLOT (newFile ()));
372 connect (openEditorAction, SIGNAL (triggered ()), this, SLOT (openEditor ()));
373 connect (openChatAction, SIGNAL (triggered ()), this, SLOT (openChat ()));
374 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ())); 290 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ()));
375 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ())); 291 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ()));
376 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ())); 292 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ()));
377 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ())); 293 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ()));
378 connect (aboutQt, SIGNAL (triggered ()), this, SLOT (showAboutQt ()));
379 294
380 connect (showWorkspaceAction, SIGNAL (toggled (bool)), m_workspaceView, SLOT (setShown (bool))); 295 connect (showWorkspaceAction, SIGNAL (toggled (bool)), m_workspaceView, SLOT (setShown (bool)));
381 connect (m_workspaceView, SIGNAL (activeChanged (bool)), showWorkspaceAction, SLOT (setChecked (bool))); 296 connect (m_workspaceView, SIGNAL (activeChanged (bool)), showWorkspaceAction, SLOT (setChecked (bool)));
382 connect (showHistoryAction, SIGNAL (toggled (bool)), m_historyDockWidget, SLOT (setShown (bool))); 297 connect (showHistoryAction, SIGNAL (toggled (bool)), m_historyDockWidget, SLOT (setShown (bool)));
383 connect (m_historyDockWidget, SIGNAL (activeChanged (bool)), showHistoryAction, SLOT (setChecked (bool))); 298 connect (m_historyDockWidget, SIGNAL (activeChanged (bool)), showHistoryAction, SLOT (setChecked (bool)));
386 301
387 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); 302 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ()));
388 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ())); 303 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ()));
389 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ())); 304 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ()));
390 305
391 connect (m_filesDockWidget, SIGNAL (openFile (QString)), this, SLOT (handleOpenFileRequest (QString))); 306 connect (m_filesDockWidget, SIGNAL (openFile (QString)), this, SLOT (openExistingFile (QString)));
392 connect (m_historyDockWidget, SIGNAL (information (QString)), this, SLOT (reportStatusMessage (QString))); 307 connect (m_historyDockWidget, SIGNAL (information (QString)), this, SLOT (reportStatusMessage (QString)));
393 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString))); 308 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString)));
394 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ())); 309 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ()));
395 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ())); 310 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ()));
396 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ())); 311 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ()));
397 312
398 setWindowTitle (QString (VERSION_STRING)); 313 setWindowTitle (QString (VERSION_STRING));
399 314
400 setCentralWidget (m_centralMdiArea);
401 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView); 315 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView);
402 addDockWidget (Qt::LeftDockWidgetArea, m_historyDockWidget); 316 addDockWidget (Qt::LeftDockWidgetArea, m_historyDockWidget);
403 addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget); 317 addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget);
404 setStatusBar (m_statusBar); 318 setStatusBar (m_statusBar);
405 319
406 readSettings (); 320 readSettings ();
407 updateTerminalFont(); 321 updateTerminalFont();
408 openWebPage ("http://www.gnu.org/software/octave/doc/interpreter/"); 322 }
409 } 323
410