diff options
author | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-06 15:51:54 +0000 |
---|---|---|
committer | am <am@f440f766-f032-0410-8965-dc7d17de2ca0> | 2009-07-06 15:51:54 +0000 |
commit | 6af9b265b0e9e3bc88d9e0bb61701aac64b2f8f1 (patch) | |
tree | 1205a69e562e1e61880345da052a38f245b8eb13 /filesystemwidget.cpp | |
parent | ea9e5d0f1e02ca8c8859bbf59f2081b819f1d329 (diff) | |
download | SheMov-6af9b265b0e9e3bc88d9e0bb61701aac64b2f8f1.tar.gz SheMov-6af9b265b0e9e3bc88d9e0bb61701aac64b2f8f1.tar.bz2 SheMov-6af9b265b0e9e3bc88d9e0bb61701aac64b2f8f1.zip |
-implemented sorting in fileview
-implemented location bar
git-svn-id: file:///var/svn/repos2/shemov/trunk@378 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'filesystemwidget.cpp')
-rw-r--r-- | filesystemwidget.cpp | 77 |
1 files changed, 68 insertions, 9 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp index 3798dcc..45edccb 100644 --- a/filesystemwidget.cpp +++ b/filesystemwidget.cpp @@ -11,11 +11,17 @@ #include <QDir> #include <QSplitter> #include <QVBoxLayout> +#include <QHBoxLayout> +#include <QLineEdit> +#include <QLabel> +#include <QCompleter> +#include <QDebug> #include "filesystemwidget.h" #include "filesystemdirproxy.h" #include "fileview.h" #include "shemoviconprovider.h" +#include "filesystemfileproxy.h" FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mModel = new QDirModel; @@ -32,10 +38,35 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mDirView->setColumnHidden(2, true); mDirView->setColumnHidden(3, true); mDirView->setRootIsDecorated(false); + mDirView->setSelectionMode(QAbstractItemView::SingleSelection); mFileView = new FileView; - mFileView->setModel(mModel); - connect(mDirView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(directoryChanged(const QModelIndex &))); + mFileProxy = new FilesystemFileProxy; + mFileProxy->setSourceModel(mModel); + mFileView->setModel(mFileProxy); + mFileView->setSortingEnabled(true); + mFileView->sortByColumn(0, Qt::AscendingOrder); + + QWidget *fileWidget = new QWidget; + QHBoxLayout *directoryEdit = new QHBoxLayout; + QLabel *dirLabel = new QLabel(tr("&Directory")); + mDirEdit = new QLineEdit; + QCompleter *completer = new QCompleter(this); + completer->setModel(mModel); + completer->setCompletionMode(QCompleter::PopupCompletion); + mDirEdit->setCompleter(completer); + dirLabel->setBuddy(mDirEdit); + directoryEdit->addWidget(dirLabel); + directoryEdit->addWidget(mDirEdit); + QVBoxLayout *fwLayout = new QVBoxLayout; + fwLayout->addLayout(directoryEdit); + fwLayout->addWidget(mFileView); + fileWidget->setLayout(fwLayout); + + connect(mDirView->selectionModel(), SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(directoryChanged(const QModelIndex &, const QModelIndex &))); + connect(mFileView, SIGNAL(activated(const QModelIndex &)), this, SLOT(fileViewActivated(const QModelIndex &))); + connect(mFileView, SIGNAL(upDir()), this, SLOT(parentDir())); + connect(mDirEdit, SIGNAL(returnPressed()), this, SLOT(directoryEdited())); QSettings s; QString startDir = s.value("paths/start", QDir::homePath()).toString(); @@ -45,7 +76,6 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { mDirView->setCurrentIndex(proxyIndex); mDirView->setExpanded(proxyIndex, true); QModelIndex parent = proxyIndex.parent(); - mFileView->setRootIndex(startIndex); do { mDirView->setExpanded(parent, true); parent = parent.parent(); @@ -53,11 +83,11 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { } mFileView->resizeColumnToContents(0); - + QVBoxLayout *mainLayout = new QVBoxLayout; QSplitter *splitter = new QSplitter; splitter->addWidget(mDirView); - splitter->addWidget(mFileView); + splitter->addWidget(fileWidget); splitter->setStretchFactor(0, 1); splitter->setStretchFactor(1, 2); mainLayout->addWidget(splitter); @@ -65,11 +95,40 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) { setLayout(mainLayout); } -void FilesystemWidget::directoryChanged(const QModelIndex &index){ - QModelIndex real = mDirProxy->mapToSource(index); - if(!index.isValid()){ +void FilesystemWidget::directoryChanged(const QModelIndex &selected, const QModelIndex &deselected){ + QModelIndex real = mDirProxy->mapToSource(selected); + if(!real.isValid()){ + return; + } + mDirEdit->setText(mModel->filePath(real)); + QModelIndex oldSelected = mDirProxy->mapToSource(deselected); + mFileView->setCurrentIndex(mFileProxy->mapFromSource(oldSelected)); + mFileView->setRootIndex(mFileProxy->mapFromSource(real)); +} + +void FilesystemWidget::directoryEdited(){ + QString path = mDirEdit->text(); + if(path.isEmpty()){ return; } - mFileView->setRootIndex(real); + QModelIndex index = mModel->index(path); + if(index.isValid()){ + mDirView->setCurrentIndex(mDirProxy->mapFromSource(index)); + } +} + +void FilesystemWidget::fileViewActivated(const QModelIndex &idx){ + QModelIndex real = mFileProxy->mapToSource(idx); + if(mModel->isDir(real)){ + mDirView->setCurrentIndex(mDirProxy->mapFromSource(real)); + return; + } +} + +void FilesystemWidget::parentDir(){ + QModelIndex idx = mDirView->currentIndex(); + if(idx.parent().isValid()){ + mDirView->setCurrentIndex(idx.parent()); + } } |