summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-06 15:51:54 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-06 15:51:54 +0000
commit6af9b265b0e9e3bc88d9e0bb61701aac64b2f8f1 (patch)
tree1205a69e562e1e61880345da052a38f245b8eb13
parentea9e5d0f1e02ca8c8859bbf59f2081b819f1d329 (diff)
downloadSheMov-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
-rw-r--r--filesystemfileproxy.cpp32
-rw-r--r--filesystemfileproxy.h1
-rw-r--r--filesystemwidget.cpp77
-rw-r--r--filesystemwidget.h9
-rw-r--r--fileview.cpp15
-rw-r--r--fileview.h5
-rw-r--r--shemov.pro4
-rw-r--r--shemoviconprovider.cpp4
8 files changed, 133 insertions, 14 deletions
diff --git a/filesystemfileproxy.cpp b/filesystemfileproxy.cpp
index 22f8868..2379226 100644
--- a/filesystemfileproxy.cpp
+++ b/filesystemfileproxy.cpp
@@ -7,8 +7,40 @@
#include <QModelIndex>
#include <QVariant>
+#include <QDirModel>
+#include <QDebug>
+#include <QFileInfo>
#include "filesystemfileproxy.h"
FilesystemFileProxy::FilesystemFileProxy(QObject *parent) : QSortFilterProxyModel(parent) {}
+bool FilesystemFileProxy::lessThan(const QModelIndex &left, const QModelIndex &right) const {
+ if(left.model()->headerData(left.column(), Qt::Horizontal).toString() == tr("Name")){
+ QDirModel *source = static_cast<QDirModel*>(sourceModel());
+ if(source->isDir(left) && source->isDir(right)){
+ return left.data().toString().toLower() < right.data().toString().toLower();
+ }
+ if(source->isDir(left)){
+ return true;
+ }
+ if(source->isDir(right)){
+ return false;
+ }
+ return left.data().toString().toLower() < right.data().toString().toLower();
+ }
+ if(left.model()->headerData(left.column(), Qt::Horizontal).toString() == tr("Size")){
+ QDirModel *source = static_cast<QDirModel*>(sourceModel());
+ QFileInfo lInfo = source->fileInfo(left);
+ QFileInfo rInfo = source->fileInfo(right);
+ if(lInfo.isDir() && rInfo.isDir()){
+ return lInfo.fileName().toLower() < rInfo.fileName().toLower();
+ }
+ if(lInfo.isDir() && !rInfo.isDir()){
+ return true;
+ }
+ return lInfo.size() < rInfo.size();
+ }
+ return QSortFilterProxyModel::lessThan(left, right);
+}
+
diff --git a/filesystemfileproxy.h b/filesystemfileproxy.h
index cb32a77..9f9609b 100644
--- a/filesystemfileproxy.h
+++ b/filesystemfileproxy.h
@@ -18,6 +18,7 @@ class FilesystemFileProxy : public QSortFilterProxyModel {
public:
FilesystemFileProxy(QObject *parent = 0);
~FilesystemFileProxy() {};
+ bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
};
#endif
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());
+ }
}
diff --git a/filesystemwidget.h b/filesystemwidget.h
index 380fa22..7ff4d02 100644
--- a/filesystemwidget.h
+++ b/filesystemwidget.h
@@ -15,6 +15,8 @@ class QTreeView;
class FilesystemDirProxy;
class FileView;
class QModelIndex;
+class FilesystemFileProxy;
+class QLineEdit;
class FilesystemWidget : public QWidget {
Q_OBJECT
@@ -23,13 +25,18 @@ class FilesystemWidget : public QWidget {
~FilesystemWidget() {};
public slots:
- void directoryChanged(const QModelIndex &index);
+ void directoryChanged(const QModelIndex &selected, const QModelIndex &);
+ void directoryEdited();
+ void fileViewActivated(const QModelIndex &index);
+ void parentDir();
private:
QDirModel *mModel;
QTreeView *mDirView;
FileView *mFileView;
FilesystemDirProxy *mDirProxy;
+ FilesystemFileProxy *mFileProxy;
+ QLineEdit *mDirEdit;
};
#endif
diff --git a/fileview.cpp b/fileview.cpp
index b402bd1..a09762d 100644
--- a/fileview.cpp
+++ b/fileview.cpp
@@ -8,6 +8,7 @@
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
+#include <QKeyEvent>
#include "fileview.h"
@@ -28,3 +29,17 @@ void FileView::contextMenuEvent(QContextMenuEvent *e){
contextMenu.exec(e->globalPos());
}
+void FileView::keyPressEvent(QKeyEvent *e){
+ switch(e->key()){
+ case Qt::Key_Right:
+ case Qt::Key_Asterisk:
+ e->accept();
+ break;
+ case Qt::Key_Backspace:
+ emit upDir();
+ e->accept();
+ break;
+ default:
+ QTreeView::keyPressEvent(e);
+ }
+}
diff --git a/fileview.h b/fileview.h
index 3382132..9a696ba 100644
--- a/fileview.h
+++ b/fileview.h
@@ -11,6 +11,7 @@
#include <QTreeView>
class QContextMenuEvent;
+class QKeyEvent;
class FileView : public QTreeView {
Q_OBJECT
@@ -18,8 +19,12 @@ class FileView : public QTreeView {
FileView(QWidget *parent = 0);
~FileView() {};
+ signals:
+ void upDir();
+
protected:
virtual void contextMenuEvent(QContextMenuEvent *e);
+ virtual void keyPressEvent(QKeyEvent *e);
};
#endif
diff --git a/shemov.pro b/shemov.pro
index 4b4d3d9..9436854 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -13,7 +13,7 @@ fileview.cpp \
shemov.cpp \
filesystemfileproxy.cpp \
helper.cpp \
-shemoviconprovider.cpp
+shemoviconprovider.cpp
HEADERS = listitem.h \
listmodel.h \
movieitem.h \
@@ -25,6 +25,6 @@ fileview.h \
shemov.h \
filesystemfileproxy.h \
helper.h \
-shemoviconprovider.h
+shemoviconprovider.h
LIBS += -lmagic
RESOURCES = shemov.qrc
diff --git a/shemoviconprovider.cpp b/shemoviconprovider.cpp
index f0ea01e..ed3febb 100644
--- a/shemoviconprovider.cpp
+++ b/shemoviconprovider.cpp
@@ -14,9 +14,9 @@
SheMovIconProvider::SheMovIconProvider() {};
QIcon SheMovIconProvider::icon(const QFileInfo &info) const {
- if(info.isDir()){
+ /*if(info.isDir()){
return QIcon(":/dildo.png");
- }
+ }*/
QString type = Helper::mimeType(info.absoluteFilePath());
if(type.toLower().startsWith("video")){
return QIcon(":/movie.svg");