changeset 13396:a02705c67ec2

Modified file chooser code to fit the overall style.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 11 Apr 2011 14:49:35 +0200
parents 7e8c437b29cb
children 54756573cc1b
files gui//src/FilesDockWidget.cpp gui//src/FilesDockWidget.h
diffstat 2 files changed, 50 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- 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()));
 }
 
--- 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 <QDockWidget>
 
-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;
 };