# HG changeset patch # User Jacob Dawid # Date 1337858427 -7200 # Node ID 66ff321cb62eea099c05625a084a279084218819 # Parent 628eeaf879f761b128eadda3c4c3a02aff293a71 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. diff -r 628eeaf879f7 -r 66ff321cb62e gui/src/FilesDockWidget.cpp --- a/gui/src/FilesDockWidget.cpp Thu May 24 12:08:53 2012 +0200 +++ b/gui/src/FilesDockWidget.cpp Thu May 24 13:20:27 2012 +0200 @@ -25,7 +25,8 @@ #include #include -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 ()); } } diff -r 628eeaf879f7 -r 66ff321cb62e gui/src/FilesDockWidget.h --- a/gui/src/FilesDockWidget.h Thu May 24 12:08:53 2012 +0200 +++ b/gui/src/FilesDockWidget.h Thu May 24 13:20:27 2012 +0200 @@ -33,11 +33,11 @@ #include #include -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. */ diff -r 628eeaf879f7 -r 66ff321cb62e gui/src/MainWindow.cpp --- a/gui/src/MainWindow.cpp Thu May 24 12:08:53 2012 +0200 +++ b/gui/src/MainWindow.cpp Thu May 24 13:20:27 2012 +0200 @@ -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 ())); diff -r 628eeaf879f7 -r 66ff321cb62e gui/src/editor/FileEditor.cpp --- a/gui/src/editor/FileEditor.cpp Thu May 24 12:08:53 2012 +0200 +++ b/gui/src/editor/FileEditor.cpp Thu May 24 13:20:27 2012 +0200 @@ -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 ())); diff -r 628eeaf879f7 -r 66ff321cb62e gui/src/editor/FileEditorInterface.h --- a/gui/src/editor/FileEditorInterface.h Thu May 24 12:08:53 2012 +0200 +++ b/gui/src/editor/FileEditorInterface.h Thu May 24 13:20:27 2012 +0200 @@ -18,21 +18,24 @@ #ifndef FILEEDITORINTERFACE_H #define FILEEDITORINTERFACE_H -#include +#include 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