# HG changeset patch # User Jacob Dawid # Date 1302526175 -7200 # Node ID a02705c67ec282befcbd68f9953442994b28abd4 # Parent 7e8c437b29cbae71ef985b222cd8a5104520aa12 Modified file chooser code to fit the overall style. diff -r 7e8c437b29cb -r a02705c67ec2 gui//src/FilesDockWidget.cpp --- a/gui//src/FilesDockWidget.cpp Mon Apr 11 14:39:26 2011 +0200 +++ b/gui//src/FilesDockWidget.cpp Mon Apr 11 14:49:35 2011 +0200 @@ -7,70 +7,64 @@ { setWidget(new QWidget(this)); - // Create a toolbar - toolbar = new QToolBar ("", widget()); - toolbar->setAllowedAreas (Qt::TopToolBarArea); - toolbar->setMovable (false); - toolbar->setIconSize (QSize (20,20)); + // Create a toolbar + toolbar = new QToolBar("", widget()); + toolbar->setAllowedAreas(Qt::TopToolBarArea); + toolbar->setMovable(false); + toolbar->setIconSize(QSize (20,20)); - // Add a button to the toolbar with the QT standard icon for up-directory - // TODO: Maybe change this to be an up-directory icon that is OS specific??? - QStyle *style = QApplication::style(); - dirIcon = style->standardIcon(QStyle::SP_FileDialogToParent); - dirAction = new QAction (dirIcon, "", toolbar); - - toolbar->addAction (dirAction); - connect(dirAction, SIGNAL(triggered()), this, SLOT(onUpDirectory())); - - // TODO: Add other buttons for creating directories + // Add a button to the toolbar with the QT standard icon for up-directory + // TODO: Maybe change this to be an up-directory icon that is OS specific??? + QStyle *style = QApplication::style(); + dirIcon = style->standardIcon(QStyle::SP_FileDialogToParent); + dirAction = new QAction(dirIcon, "", toolbar); - // Create the QFileSystemModel starting in the home directory - QString homePath = QDir::homePath (); - // TODO: This should occur after Octave has been initialized and the startup directory of Octave is established + toolbar->addAction(dirAction); + connect(dirAction, SIGNAL(triggered()), this, SLOT(onUpDirectory())); + + // TODO: Add other buttons for creating directories - fileSystemModel = new QFileSystemModel(this); - fileSystemModel->setFilter (QDir::NoDotAndDotDot | QDir::AllEntries); - QModelIndex rootPathIndex = fileSystemModel->setRootPath (homePath); + // Create the QFileSystemModel starting in the home directory + QString homePath = QDir::homePath(); + // TODO: This should occur after Octave has been initialized and the startup directory of Octave is established - // Attach the model to the QTreeView and set the root index - fileTreeView = new QTreeView(widget()); - fileTreeView->setModel (fileSystemModel); - fileTreeView->setRootIndex (rootPathIndex); - fileTreeView->setSortingEnabled (true); + fileSystemModel = new QFileSystemModel(this); + fileSystemModel->setFilter(QDir::NoDotAndDotDot | QDir::AllEntries); + QModelIndex rootPathIndex = fileSystemModel->setRootPath(homePath); - connect( fileTreeView, SIGNAL(doubleClicked(const QModelIndex &) ), this, SLOT( itemDoubleClicked(const QModelIndex &) ) ); - // TODO: Maybe also add a keyPress event handler so users can navigate manually + // Attach the model to the QTreeView and set the root index + fileTreeView = new QTreeView(widget()); + fileTreeView->setModel(fileSystemModel); + fileTreeView->setRootIndex(rootPathIndex); + fileTreeView->setSortingEnabled(true); + connect(fileTreeView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(itemDoubleClicked(const QModelIndex &))); - // Layout the widgets vertically with the toolbar on top - layout = new QVBoxLayout(); - layout->setSpacing(0); - layout->addWidget(toolbar); - layout->addWidget(fileTreeView); + // Layout the widgets vertically with the toolbar on top + QVBoxLayout *layout = new QVBoxLayout(); + layout->setSpacing(0); + layout->addWidget(toolbar); + layout->addWidget(fileTreeView); widget()->setLayout(layout); - // TODO: Add right-click contextual menus for copying, pasting, deleting files (and others) + // TODO: Add right-click contextual menus for copying, pasting, deleting files (and others) } void FilesDockWidget::itemDoubleClicked(const QModelIndex &index) { - QFileInfo fileInfo = fileSystemModel->fileInfo (index); - if (fileInfo.isDir ()) - { - fileSystemModel->setRootPath (fileInfo.absolutePath ()); - fileTreeView->setRootIndex (index); - } - else - { + QFileInfo fileInfo = fileSystemModel->fileInfo(index); + if (fileInfo.isDir()) { + fileSystemModel->setRootPath(fileInfo.absolutePath()); + fileTreeView->setRootIndex(index); + } else { // TODO: Open the file appropriately based on the mime type } } void FilesDockWidget::onUpDirectory(void) { - // Move up an index node - QDir dir = QDir(fileSystemModel->filePath(fileTreeView->rootIndex())); - dir.cdUp(); - fileTreeView->setRootIndex(fileSystemModel->index(dir.absolutePath())); - + // Move up an index node + QDir dir = QDir(fileSystemModel->filePath(fileTreeView->rootIndex())); + dir.cdUp(); + fileTreeView->setRootIndex(fileSystemModel->index(dir.absolutePath())); } diff -r 7e8c437b29cb -r a02705c67ec2 gui//src/FilesDockWidget.h --- a/gui//src/FilesDockWidget.h Mon Apr 11 14:39:26 2011 +0200 +++ b/gui//src/FilesDockWidget.h Mon Apr 11 14:49:35 2011 +0200 @@ -27,51 +27,35 @@ #include "octave/cmd-hist.h" #include -class FilesDockWidget : public QDockWidget { +class FilesDockWidget : public QDockWidget { Q_OBJECT - public : FilesDockWidget(QWidget *parent = 0); - - void setDirectory (QString dir); + void setDirectory(QString dir); public slots: - /** - * Slot for handling a change in directory via double click - */ + /** Slot for handling a change in directory via double click. */ void itemDoubleClicked(const QModelIndex &index); - /** - * Slot for handling the up-directory button in the toolbar - */ - void onUpDirectory(void); + /** Slot for handling the up-directory button in the toolbar. */ + void onUpDirectory(); private: - // Layout widget for packing the toolbar and treeview widgets - QVBoxLayout *layout; // TODO: Add toolbar with buttons for navigating the path, creating dirs, etc - /** - * Toolbar for file and directory manipulation - */ + /** Toolbar for file and directory manipulation. */ QToolBar *toolbar; - /** - * Variables for the up-directory action. - */ + /** Variables for the up-directory action. */ QIcon dirIcon; QAction *dirAction; QToolButton *upDirectoryButton; - /** - * The file system model. - */ + /** The file system model. */ QFileSystemModel *fileSystemModel; - /** - * The file system view. - */ + /** The file system view. */ QTreeView *fileTreeView; };