Mercurial > hg > octave-lyh
comparison gui/src/MainWindow.cpp @ 14670:7fbea449737d gui
Restructured menus, added toolbar and current directory line edit.
* MainWindow (construct): Restructured menus, added toolbar and current working directory line edit.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Tue, 22 May 2012 13:04:24 +0200 |
parents | 7605e7136b50 |
children | 7b607001d571 |
comparison
equal
deleted
inserted
replaced
14669:7605e7136b50 | 14670:7fbea449737d |
---|---|
17 | 17 |
18 #include <QMenuBar> | 18 #include <QMenuBar> |
19 #include <QMenu> | 19 #include <QMenu> |
20 #include <QAction> | 20 #include <QAction> |
21 #include <QSettings> | 21 #include <QSettings> |
22 #include <QStyle> | |
23 #include <QToolBar> | |
22 #include <QDesktopServices> | 24 #include <QDesktopServices> |
23 #include <QFileDialog> | 25 #include <QFileDialog> |
24 #include <QMessageBox> | 26 #include <QMessageBox> |
27 #include <QIcon> | |
28 | |
25 #include "MainWindow.h" | 29 #include "MainWindow.h" |
26 #include "FileEditor.h" | 30 #include "FileEditor.h" |
27 #include "SettingsDialog.h" | 31 #include "SettingsDialog.h" |
28 | 32 |
29 MainWindow::MainWindow (QWidget * parent):QMainWindow (parent) | 33 MainWindow::MainWindow (QWidget * parent):QMainWindow (parent) |
33 OctaveLink::instance ()->launchOctave(); | 37 OctaveLink::instance ()->launchOctave(); |
34 } | 38 } |
35 | 39 |
36 MainWindow::~MainWindow () | 40 MainWindow::~MainWindow () |
37 { | 41 { |
42 OctaveLink::instance ()->terminateOctave(); | |
38 } | 43 } |
39 | 44 |
40 void | 45 void |
41 MainWindow::openExistingFile (QString fileName) | 46 MainWindow::openExistingFile (QString fileName) |
42 { | 47 { |
71 | 76 |
72 void | 77 void |
73 MainWindow::handleSaveWorkspaceRequest () | 78 MainWindow::handleSaveWorkspaceRequest () |
74 { | 79 { |
75 QString selectedFile = | 80 QString selectedFile = |
76 QFileDialog::getSaveFileName (this, tr ("Save Workspace"), | 81 QFileDialog::getSaveFileName (this, tr ("Save Workspace"), |
77 ResourceManager::instance ()->homePath ()); | 82 ResourceManager::instance ()->homePath ()); |
78 m_terminalView->sendText (QString ("save \'%1\'\n").arg (selectedFile)); | 83 m_terminalView->sendText (QString ("save \'%1\'\n").arg (selectedFile)); |
79 m_terminalView->setFocus (); | 84 m_terminalView->setFocus (); |
80 } | 85 } |
81 | 86 |
82 void | 87 void |
83 MainWindow::handleLoadWorkspaceRequest () | 88 MainWindow::handleLoadWorkspaceRequest () |
84 { | 89 { |
85 QString selectedFile = | 90 QString selectedFile = |
86 QFileDialog::getOpenFileName (this, tr ("Load Workspace"), | 91 QFileDialog::getOpenFileName (this, tr ("Load Workspace"), |
87 ResourceManager::instance ()->homePath ()); | 92 ResourceManager::instance ()->homePath ()); |
88 m_terminalView->sendText (QString ("load \'%1\'\n").arg (selectedFile)); | 93 m_terminalView->sendText (QString ("load \'%1\'\n").arg (selectedFile)); |
89 m_terminalView->setFocus (); | 94 m_terminalView->setFocus (); |
90 } | 95 } |
91 | 96 |
92 void | 97 void |
197 } | 202 } |
198 | 203 |
199 void | 204 void |
200 MainWindow::construct () | 205 MainWindow::construct () |
201 { | 206 { |
207 QStyle *style = QApplication::style (); | |
202 // TODO: Check this. | 208 // TODO: Check this. |
203 m_closing = false; // flag for editor files when closed | 209 m_closing = false; // flag for editor files when closed |
204 setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Octave)); | 210 setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Octave)); |
205 | 211 |
206 // Setup dockable widgets and the status bar. | 212 // Setup dockable widgets and the status bar. |
210 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history.")); | 216 m_historyDockWidget->setStatusTip (tr ("Browse and search the command history.")); |
211 m_filesDockWidget = new FilesDockWidget (this); | 217 m_filesDockWidget = new FilesDockWidget (this); |
212 m_filesDockWidget->setStatusTip (tr ("Browse your files.")); | 218 m_filesDockWidget->setStatusTip (tr ("Browse your files.")); |
213 m_statusBar = new QStatusBar (this); | 219 m_statusBar = new QStatusBar (this); |
214 | 220 |
221 m_currentDirectoryLineEdit = new QLineEdit (QDir::currentPath (), this); | |
222 m_currentDirectoryLineEdit->setFixedWidth (300); | |
223 | |
224 m_currentDirectoryToolButton = new QToolButton (this); | |
225 m_currentDirectoryToolButton->setIcon (style->standardIcon (QStyle::SP_DirOpenIcon)); | |
226 | |
227 m_currentDirectoryUpToolButton = new QToolButton (this); | |
228 m_currentDirectoryUpToolButton->setIcon (style->standardIcon (QStyle::SP_FileDialogToParent)); | |
229 | |
215 // Octave Terminal subwindow. | 230 // Octave Terminal subwindow. |
216 m_terminalView = new QTerminal(this); | 231 m_terminalView = new QTerminal(this); |
217 setCentralWidget (m_terminalView); | 232 setCentralWidget (m_terminalView); |
218 | 233 |
219 m_lexer = NULL; // initialise the empty lexer for the edtiors | 234 m_lexer = NULL; // initialise the empty lexer for the edtiors |
220 | 235 |
221 QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave")); | 236 QMenu *fileMenu = menuBar ()->addMenu (tr ("&File")); |
222 QAction *settingsAction = controlMenu->addAction (tr ("Settings")); | 237 QAction *newFileAction |
223 controlMenu->addSeparator (); | 238 = fileMenu->addAction (QIcon::fromTheme ("document-new", |
224 QAction *exitAction = controlMenu->addAction (tr ("Exit")); | 239 style->standardIcon (QStyle::SP_FileIcon)), tr ("New File")); |
225 | 240 |
226 QMenu *interfaceMenu = menuBar ()->addMenu (tr ("Interface")); | 241 QAction *openFileAction |
227 | 242 = fileMenu->addAction (QIcon::fromTheme ("document-open", |
228 QAction *showWorkspaceAction = interfaceMenu->addAction (tr ("Workspace")); | 243 style->standardIcon (QStyle::SP_FileIcon)), tr ("Open File")); |
244 | |
245 QAction *settingsAction = fileMenu->addAction (tr ("Settings")); | |
246 fileMenu->addSeparator (); | |
247 QAction *exitAction = fileMenu->addAction (tr ("Exit")); | |
248 | |
249 QMenu *editMenu = menuBar ()->addMenu (tr ("&Edit")); | |
250 QAction *cutAction | |
251 = editMenu->addAction (QIcon::fromTheme ("edit-cut", | |
252 style->standardIcon (QStyle::SP_FileIcon)), tr ("Cut")); | |
253 | |
254 QAction *copyAction | |
255 = editMenu->addAction (QIcon::fromTheme ("edit-copy", | |
256 style->standardIcon (QStyle::SP_FileIcon)), tr ("Copy")); | |
257 | |
258 QAction *pasteAction | |
259 = editMenu->addAction (QIcon::fromTheme ("edit-paste", | |
260 style->standardIcon (QStyle::SP_FileIcon)), tr ("Paste")); | |
261 | |
262 QAction *undoAction | |
263 = editMenu->addAction (QIcon::fromTheme ("edit-undo", | |
264 style->standardIcon (QStyle::SP_FileIcon)), tr ("Undo")); | |
265 | |
266 QAction *redoAction | |
267 = editMenu->addAction (QIcon::fromTheme ("edit-redo", | |
268 style->standardIcon (QStyle::SP_FileIcon)), tr ("Redo")); | |
269 | |
270 //QMenu *debugMenu = menuBar ()->addMenu (tr ("De&bug")); | |
271 //QMenu *parallelMenu = menuBar ()->addMenu (tr ("&Parallel")); | |
272 | |
273 QMenu *desktopMenu = menuBar ()->addMenu (tr ("&Desktop")); | |
274 QAction *loadWorkspaceAction = desktopMenu->addAction (tr ("Load workspace")); | |
275 QAction *saveWorkspaceAction = desktopMenu->addAction (tr ("Save workspace")); | |
276 QAction *clearWorkspaceAction = desktopMenu->addAction (tr ("Clear workspace")); | |
277 | |
278 // Window menu | |
279 QMenu *windowMenu = menuBar ()->addMenu (tr ("&Window")); | |
280 QAction *showWorkspaceAction = windowMenu->addAction (tr ("Workspace")); | |
229 showWorkspaceAction->setCheckable (true); | 281 showWorkspaceAction->setCheckable (true); |
230 | 282 QAction *showHistoryAction = windowMenu->addAction (tr ("History")); |
231 QAction *showHistoryAction = interfaceMenu->addAction (tr ("History")); | |
232 showHistoryAction->setCheckable (true); | 283 showHistoryAction->setCheckable (true); |
233 | 284 QAction *showFileBrowserAction = windowMenu->addAction (tr ("File Browser")); |
234 QAction *showFileBrowserAction = interfaceMenu->addAction (tr ("File Browser")); | |
235 showFileBrowserAction->setCheckable (true); | 285 showFileBrowserAction->setCheckable (true); |
236 | 286 |
237 interfaceMenu->addSeparator (); | 287 // Help menu |
238 QAction *openEditorAction = interfaceMenu->addAction (tr ("Open New Editor Window")); | 288 QMenu *helpMenu = menuBar ()->addMenu (tr ("&Help")); |
239 | 289 QAction *reportBugAction = helpMenu->addAction (tr ("Report Bug")); |
240 QMenu *workspaceMenu = menuBar ()->addMenu (tr ("Workspace")); | 290 QAction *agoraAction = helpMenu->addAction (tr ("Visit Agora")); |
241 QAction *loadWorkspaceAction = workspaceMenu->addAction (tr ("Load")); | 291 QAction *octaveForgeAction = helpMenu->addAction (tr ("Visit Octave Forge")); |
242 QAction *saveWorkspaceAction = workspaceMenu->addAction (tr ("Save")); | 292 helpMenu->addSeparator (); |
243 workspaceMenu->addSeparator (); | 293 QAction *aboutOctaveAction = helpMenu->addAction (tr ("About Octave")); |
244 QAction *clearWorkspaceAction = workspaceMenu->addAction (tr ("Clear")); | 294 |
245 | 295 // Toolbars |
246 QMenu *communityMenu = menuBar ()->addMenu (tr ("Community")); | 296 |
247 QAction *reportBugAction = communityMenu->addAction (tr ("Report Bug")); | 297 QToolBar *mainToolBar = addToolBar ("Main"); |
248 QAction *agoraAction = communityMenu->addAction (tr ("Agora")); | 298 mainToolBar->addAction (newFileAction); |
249 QAction *octaveForgeAction = communityMenu->addAction (tr ("Octave Forge")); | 299 mainToolBar->addAction (openFileAction); |
250 communityMenu->addSeparator (); | 300 mainToolBar->addSeparator (); |
251 QAction *aboutOctaveAction = communityMenu->addAction (tr ("About Octave")); | 301 mainToolBar->addAction (cutAction); |
302 mainToolBar->addAction (copyAction); | |
303 mainToolBar->addAction (pasteAction); | |
304 mainToolBar->addAction (undoAction); | |
305 mainToolBar->addAction (redoAction); | |
306 mainToolBar->addSeparator (); | |
307 mainToolBar->addWidget (new QLabel (tr ("Current Directory:"))); | |
308 mainToolBar->addWidget (m_currentDirectoryLineEdit); | |
309 mainToolBar->addWidget (m_currentDirectoryToolButton); | |
310 mainToolBar->addWidget (m_currentDirectoryUpToolButton); | |
252 | 311 |
253 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ())); | 312 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ())); |
254 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ())); | 313 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ())); |
255 connect (openEditorAction, SIGNAL (triggered ()), this, SLOT (newFile ())); | 314 connect (newFileAction, SIGNAL (triggered ()), this, SLOT (newFile ())); |
256 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ())); | 315 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ())); |
257 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ())); | 316 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ())); |
258 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ())); | 317 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ())); |
259 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ())); | 318 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ())); |
260 | 319 |
287 m_lexer = new LexerOctaveGui (); | 346 m_lexer = new LexerOctaveGui (); |
288 | 347 |
289 // Editor font (default or from settings) | 348 // Editor font (default or from settings) |
290 QSettings *settings = ResourceManager::instance ()->settings (); | 349 QSettings *settings = ResourceManager::instance ()->settings (); |
291 m_lexer->setDefaultFont (QFont ( | 350 m_lexer->setDefaultFont (QFont ( |
292 settings->value ("editor/fontName","Courier").toString (), | 351 settings->value ("editor/fontName","Courier").toString (), |
293 settings->value ("editor/fontSize",10).toInt ())); | 352 settings->value ("editor/fontSize",10).toInt ())); |
294 | 353 |
295 // TODO: Autoindent not working as it should | 354 // TODO: Autoindent not working as it should |
296 m_lexer->setAutoIndentStyle (QsciScintilla::AiMaintain || | 355 m_lexer->setAutoIndentStyle (QsciScintilla::AiMaintain || |
297 QsciScintilla::AiOpening || | 356 QsciScintilla::AiOpening || |
298 QsciScintilla::AiClosing); | 357 QsciScintilla::AiClosing); |
300 // The API info that is used for auto completion | 359 // The API info that is used for auto completion |
301 // TODO: Where to store a file with API info (raw or prepared?)? | 360 // TODO: Where to store a file with API info (raw or prepared?)? |
302 // TODO: Also provide infos on octave-forge functions? | 361 // TODO: Also provide infos on octave-forge functions? |
303 // TODO: Also provide infos on function parameters? | 362 // TODO: Also provide infos on function parameters? |
304 // By now, use the keywords-list from syntax highlighting | 363 // By now, use the keywords-list from syntax highlighting |
305 m_lexerAPI = new QsciAPIs (m_lexer); | 364 m_lexerAPI = new QsciAPIs (m_lexer); |
306 | 365 |
307 QString keyword; | 366 QString keyword; |
308 QStringList keywordList; | 367 QStringList keywordList; |
309 keyword = m_lexer->keywords (1); // get whole string with all keywords | 368 keyword = m_lexer->keywords (1); // get whole string with all keywords |
310 keywordList = keyword.split (QRegExp ("\\s+")); // split into single strings | 369 keywordList = keyword.split (QRegExp ("\\s+")); // split into single strings |
311 int i; | 370 int i; |
312 for (i=0; i<keywordList.size(); i++) | 371 for (i=0; i<keywordList.size(); i++) |
313 { | 372 { |
314 m_lexerAPI->add (keywordList.at (i)); // add single strings to the API | 373 m_lexerAPI->add (keywordList.at (i)); // add single strings to the API |
315 } | 374 } |
316 m_lexerAPI->prepare (); // prepare API info ... this make take some time | 375 m_lexerAPI->prepare (); // prepare API info ... this make take some time |
317 | 376 |
318 readSettings (); | 377 readSettings (); |
319 updateTerminalFont(); | 378 updateTerminalFont(); |
320 } | 379 } |
321 | 380 |