Mercurial > hg > octave-nkf
changeset 14681:66ff321cb62e gui
Integrated the editor to be docked with the other widgets.
* FilesDockWidget: Some code style corrections.
* MainWindow: Added a checkable menu entry for the editor and added file editor as dockable widget.
* FileEditor: Moved setting the object name to the interface.
* FileEditorInterface: Added routines to correctly handle closing and opening the dock widget.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 24 May 2012 13:20:27 +0200 |
parents | 628eeaf879f7 |
children | 9ea75ea686b5 |
files | gui/src/FilesDockWidget.cpp gui/src/FilesDockWidget.h gui/src/MainWindow.cpp gui/src/editor/FileEditor.cpp gui/src/editor/FileEditorInterface.h |
diffstat | 5 files changed, 47 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/FilesDockWidget.cpp +++ b/gui/src/FilesDockWidget.cpp @@ -25,7 +25,8 @@ #include <QProcess> #include <QDebug> -FilesDockWidget::FilesDockWidget (QWidget * parent):QDockWidget (parent) +FilesDockWidget::FilesDockWidget (QWidget *parent) + : QDockWidget (parent) { setObjectName ("FilesDockWidget"); setWindowTitle (tr ("Current Directory")); @@ -50,7 +51,7 @@ m_navigationToolBar->addAction (m_directoryUpAction); m_navigationToolBar->addWidget (m_currentDirectory); connect (m_directoryUpAction, SIGNAL (triggered ()), this, - SLOT (onUpDirectory ())); + SLOT (onUpDirectory ())); // TODO: Add other buttons for creating directories @@ -77,10 +78,10 @@ m_fileTreeView->setStatusTip (tr ("Doubleclick a file to open it.")); setCurrentDirectory (m_fileSystemModel->fileInfo (rootPathIndex). - absoluteFilePath ()); + absoluteFilePath ()); connect (m_fileTreeView, SIGNAL (doubleClicked (const QModelIndex &)), this, - SLOT (itemDoubleClicked (const QModelIndex &))); + SLOT (itemDoubleClicked (const QModelIndex &))); // Layout the widgets vertically with the toolbar on top QVBoxLayout * @@ -93,7 +94,7 @@ // TODO: Add right-click contextual menus for copying, pasting, deleting files (and others) connect (m_currentDirectory, SIGNAL (returnPressed ()), this, - SLOT (currentDirectoryEntered ())); + SLOT (currentDirectoryEntered ())); QCompleter * completer = new QCompleter (m_fileSystemModel, this); m_currentDirectory->setCompleter (completer); @@ -113,7 +114,7 @@ m_fileSystemModel->setRootPath (fileInfo.absolutePath ()); m_fileTreeView->setRootIndex (index); setCurrentDirectory (m_fileSystemModel->fileInfo (index). - absoluteFilePath ()); + absoluteFilePath ()); } // Otherwise attempt to open it. else @@ -148,7 +149,7 @@ dir.cdUp (); m_fileSystemModel->setRootPath (dir.absolutePath ()); m_fileTreeView->setRootIndex (m_fileSystemModel-> - index (dir.absolutePath ())); + index (dir.absolutePath ())); setCurrentDirectory (dir.absolutePath ()); } @@ -159,14 +160,14 @@ if (fileInfo.isDir ()) { m_fileTreeView->setRootIndex (m_fileSystemModel-> - index (fileInfo.absolutePath ())); + index (fileInfo.absolutePath ())); m_fileSystemModel->setRootPath (fileInfo.absolutePath ()); setCurrentDirectory (fileInfo.absoluteFilePath ()); } else { if (QFile::exists (fileInfo.absoluteFilePath ())) - emit openFile (fileInfo.absoluteFilePath ()); + emit openFile (fileInfo.absoluteFilePath ()); } }
--- a/gui/src/FilesDockWidget.h +++ b/gui/src/FilesDockWidget.h @@ -33,11 +33,11 @@ #include <QDockWidget> #include <QLineEdit> -class FilesDockWidget:public QDockWidget +class FilesDockWidget : public QDockWidget { Q_OBJECT public: - FilesDockWidget (QWidget * parent = 0); + FilesDockWidget (QWidget *parent = 0); public slots: /** Slot for handling a change in directory via double click. */
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -228,6 +228,7 @@ setCentralWidget (m_terminalView); m_fileEditor = new FileEditor (m_terminalView, this); + addDockWidget (Qt::BottomDockWidgetArea, m_fileEditor); QMenu *fileMenu = menuBar ()->addMenu (tr ("&File")); QAction *newFileAction @@ -284,6 +285,8 @@ showHistoryAction->setCheckable (true); QAction *showFileBrowserAction = windowMenu->addAction (tr ("File Browser")); showFileBrowserAction->setCheckable (true); + QAction *showEditorAction = windowMenu->addAction (tr ("Editor")); + showEditorAction->setCheckable (true); // Help menu QMenu *helpMenu = menuBar ()->addMenu (tr ("&Help")); @@ -324,6 +327,8 @@ connect (m_historyDockWidget, SIGNAL (activeChanged (bool)), showHistoryAction, SLOT (setChecked (bool))); connect (showFileBrowserAction, SIGNAL (toggled (bool)), m_filesDockWidget, SLOT (setShown (bool))); connect (m_filesDockWidget, SIGNAL (activeChanged (bool)), showFileBrowserAction, SLOT (setChecked (bool))); + connect (showEditorAction, SIGNAL (toggled (bool)), m_fileEditor, SLOT (setShown (bool))); + connect (m_fileEditor, SIGNAL (activeChanged (bool)), showEditorAction, SLOT (setChecked (bool))); //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ()));
--- a/gui/src/editor/FileEditor.cpp +++ b/gui/src/editor/FileEditor.cpp @@ -253,12 +253,13 @@ void FileEditor::construct () { + QWidget *widget = new QWidget (this); QSettings *settings = ResourceManager::instance ()->settings (); QStyle *style = QApplication::style (); - m_menuBar = new QMenuBar (this); - m_toolBar = new QToolBar (this); - m_tabWidget = new QTabWidget (this); + m_menuBar = new QMenuBar (widget); + m_toolBar = new QToolBar (widget); + m_tabWidget = new QTabWidget (widget); m_tabWidget->setTabsClosable (true); //m_longTitle = settings->value ("editor/longWindowTitle",true).toBool (); @@ -287,8 +288,8 @@ QIcon::fromTheme("edit-redo",style->standardIcon (QStyle::SP_ArrowRight)), tr("&Redo"), m_toolBar); - m_copyAction = new QAction (QIcon::fromTheme("edit-copy"), tr("&Copy"),m_toolBar); - m_cutAction = new QAction (QIcon::fromTheme("edit-cut"), tr("Cu&t"),m_toolBar); + m_copyAction = new QAction (QIcon::fromTheme ("edit-copy"), tr ("&Copy"), m_toolBar); + m_cutAction = new QAction (QIcon::fromTheme ("edit-cut"), tr ("Cu&t"), m_toolBar); QAction *pasteAction = new QAction (QIcon::fromTheme ("edit-paste"), tr ("&Paste"),m_toolBar); QAction *nextBookmarkAction = new QAction (tr ("&Next Bookmark"),m_toolBar); @@ -372,7 +373,8 @@ layout->addWidget (m_toolBar); layout->addWidget (m_tabWidget); layout->setMargin (0); - setLayout (layout); + widget->setLayout (layout); + setWidget (widget); connect (newAction, SIGNAL (triggered ()), this, SLOT (requestNewFile ())); connect (openAction, SIGNAL (triggered ()), this, SLOT (requestOpenFile ()));
--- a/gui/src/editor/FileEditorInterface.h +++ b/gui/src/editor/FileEditorInterface.h @@ -18,21 +18,24 @@ #ifndef FILEEDITORINTERFACE_H #define FILEEDITORINTERFACE_H -#include <QWidget> +#include <QDockWidget> class QTerminal; class MainWindow; -class FileEditorInterface : public QWidget +class FileEditorInterface : public QDockWidget { Q_OBJECT public: FileEditorInterface (QTerminal *terminal, MainWindow *mainWindow) - : QWidget () + : QDockWidget ((QWidget*)mainWindow) // QDockWidget constructor is explicit, hence the cast. { + setObjectName ("FileEditor"); m_terminal = terminal; m_mainWindow = mainWindow; + + connect (this, SIGNAL (visibilityChanged (bool)), this, SLOT (handleVisibilityChanged (bool))); } virtual ~FileEditorInterface () { } @@ -41,9 +44,25 @@ virtual void requestOpenFile () = 0; virtual void requestOpenFile (QString fileName) = 0; + signals: + void activeChanged (bool active); + protected: QTerminal* m_terminal; MainWindow* m_mainWindow; + + void closeEvent (QCloseEvent *event) + { + emit activeChanged (false); + QDockWidget::closeEvent (event); + } + + protected slots: + void handleVisibilityChanged (bool visible) + { + if (visible) + emit activeChanged (true); + } }; #endif // FILEEDITORINTERFACE_H