summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-08 15:40:49 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-07-08 15:40:49 +0000
commita12045635b23c80e3dd9f51212c6ea89c240b94e (patch)
tree1663feef335d9a5545b2085c03b55488d41d8216
parent1b18f70862f62f8783976407057ea5a5cf88bdac (diff)
downloadSheMov-a12045635b23c80e3dd9f51212c6ea89c240b94e.tar.gz
SheMov-a12045635b23c80e3dd9f51212c6ea89c240b94e.tar.bz2
SheMov-a12045635b23c80e3dd9f51212c6ea89c240b94e.zip
-added messagedialog
-worked on keyboard navigation and selecting items, items can now be selected like in mc git-svn-id: file:///var/svn/repos2/shemov/trunk@380 f440f766-f032-0410-8965-dc7d17de2ca0
-rw-r--r--filesystemwidget.cpp3
-rw-r--r--filesystemwidget.h1
-rw-r--r--fileview.cpp45
-rw-r--r--fileview.h13
-rw-r--r--messagedialog.cpp43
-rw-r--r--messagedialog.h34
-rw-r--r--shemov.cpp32
-rw-r--r--shemov.h10
-rw-r--r--shemov.pro6
9 files changed, 184 insertions, 3 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp
index 64fc530..6d711ce 100644
--- a/filesystemwidget.cpp
+++ b/filesystemwidget.cpp
@@ -49,7 +49,7 @@ FilesystemWidget::FilesystemWidget(QWidget *parent) : QWidget(parent) {
mFileView->setSortingEnabled(true);
mFileView->sortByColumn(0, Qt::AscendingOrder);
mFileView->setItemsExpandable(false);
- mFileView->setSelectionMode(QAbstractItemView::ExtendedSelection);
+ mFileView->setSelectionMode(QAbstractItemView::MultiSelection);
QWidget *fileWidget = new QWidget;
QHBoxLayout *directoryEdit = new QHBoxLayout;
@@ -149,5 +149,6 @@ void FilesystemWidget::parentDir(){
if(idx.parent().isValid()){
mDirView->setCurrentIndex(idx.parent());
}
+ mFileView->selectionModel()->clearSelection();
}
diff --git a/filesystemwidget.h b/filesystemwidget.h
index 7ff4d02..cef32c4 100644
--- a/filesystemwidget.h
+++ b/filesystemwidget.h
@@ -23,6 +23,7 @@ class FilesystemWidget : public QWidget {
public:
FilesystemWidget(QWidget *parent = 0);
~FilesystemWidget() {};
+ FileView *fileView() { return mFileView; };
public slots:
void directoryChanged(const QModelIndex &selected, const QModelIndex &);
diff --git a/fileview.cpp b/fileview.cpp
index 541d071..db34e0a 100644
--- a/fileview.cpp
+++ b/fileview.cpp
@@ -9,11 +9,47 @@
#include <QMenu>
#include <QAction>
#include <QKeyEvent>
+#include <QModelIndex>
+#include <QRegExp>
+#include <QDirModel>
+#include <QSortFilterProxyModel>
+#include <QDebug>
#include "fileview.h"
+#include "messagedialog.h"
FileView::FileView(QWidget *parent) : QTreeView(parent) {
setRootIsDecorated(false);
+ mMarkDialog = new MessageDialog(tr("Enter pattern to mark"), this);
+ connect(mMarkDialog, SIGNAL(accepted()), this, SLOT(doMark()));
+}
+
+void FileView::markFiles(){
+ mMarkDialog->show();
+}
+
+void FileView::unmarkFiles(){
+ selectionModel()->clearSelection();
+}
+
+void FileView::doMark(){
+ int rowCount = model()->rowCount(rootIndex());
+ QString sRegex = mMarkDialog->text();
+ if(rowCount && !sRegex.isEmpty()){
+ QRegExp re(sRegex);
+ QSortFilterProxyModel *proxy = static_cast<QSortFilterProxyModel*>(model());
+ QDirModel *model = static_cast<QDirModel*>(proxy->sourceModel());
+ for(int i = 0; i < rowCount; ++i){
+ QModelIndex cur = rootIndex().child(i, 0);
+ QModelIndex sCur = proxy->mapToSource(cur);
+ if(model->isDir(sCur)){
+ continue;
+ }
+ if(re.indexIn(cur.data().toString()) != -1){
+ selectionModel()->select(cur, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ }
+ }
+ }
}
void FileView::contextMenuEvent(QContextMenuEvent *e){
@@ -39,3 +75,12 @@ void FileView::keyPressEvent(QKeyEvent *e){
QTreeView::keyPressEvent(e);
}
}
+
+void FileView::resizeEvent(QResizeEvent *e){
+ if(e->size().width() != e->oldSize().width()){
+ int width = e->size().width();
+ int c1width = width / 2; // * 2;
+ setColumnWidth(0, c1width);
+ }
+}
+
diff --git a/fileview.h b/fileview.h
index 9a696ba..9c10347 100644
--- a/fileview.h
+++ b/fileview.h
@@ -12,6 +12,8 @@
class QContextMenuEvent;
class QKeyEvent;
+class QResizeEvent;
+class MessageDialog;
class FileView : public QTreeView {
Q_OBJECT
@@ -22,9 +24,20 @@ class FileView : public QTreeView {
signals:
void upDir();
+ public slots:
+ void markFiles();
+ void unmarkFiles();
+
+ private slots:
+ void doMark();
+
protected:
virtual void contextMenuEvent(QContextMenuEvent *e);
virtual void keyPressEvent(QKeyEvent *e);
+ virtual void resizeEvent(QResizeEvent *e);
+
+ private:
+ MessageDialog *mMarkDialog;
};
#endif
diff --git a/messagedialog.cpp b/messagedialog.cpp
new file mode 100644
index 0000000..c3261aa
--- /dev/null
+++ b/messagedialog.cpp
@@ -0,0 +1,43 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#include <QPushButton>
+#include <QString>
+#include <QLabel>
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+
+#include "messagedialog.h"
+
+MessageDialog::MessageDialog(const QString &message, QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){
+ mEdit = new QLineEdit;
+ mOk = new QPushButton(tr("Ok"));
+ mCancel = new QPushButton(tr("Cancel"));
+ QLabel *m = new QLabel(message);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(mOk);
+ buttonLayout->addWidget(mCancel);
+
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ mainLayout->addWidget(m);
+ mainLayout->addWidget(mEdit);
+ mainLayout->addLayout(buttonLayout);
+
+ mOk->setDefault(true);
+ connect(mOk, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(mCancel, SIGNAL(clicked()), this, SLOT(reject()));
+
+ setLayout(mainLayout);
+ setWindowTitle(tr("SheMov - Mark files"));
+}
+
+void MessageDialog::accept(){
+ mEdit->setFocus(Qt::ActiveWindowFocusReason);
+ QDialog::accept();
+}
diff --git a/messagedialog.h b/messagedialog.h
new file mode 100644
index 0000000..217feef
--- /dev/null
+++ b/messagedialog.h
@@ -0,0 +1,34 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#ifndef MESSAGEDIALOG_H
+#define MESSAGEDIALOG_H
+
+#include <QDialog>
+#include <QLineEdit>
+
+class QPushButton;
+class QString;
+
+class MessageDialog : public QDialog {
+ Q_OBJECT
+ public:
+ MessageDialog(const QString &message, QWidget *parent = 0, Qt::WindowFlags f = 0);
+ ~MessageDialog() {};
+ const QString text() const { return mEdit->text(); };
+
+ public slots:
+ void accept();
+
+ private:
+ QLineEdit *mEdit;
+ QPushButton *mOk;
+ QPushButton *mCancel;
+};
+
+#endif
+
diff --git a/shemov.cpp b/shemov.cpp
index ea84a7e..1a8a166 100644
--- a/shemov.cpp
+++ b/shemov.cpp
@@ -5,11 +5,17 @@
2 of the License, or (at your option) any later version.
*/
+#include <QApplication>
#include <QTabWidget>
#include <QVBoxLayout>
+#include <QAction>
+#include <QMenuBar>
+#include <QMenu>
+#include <QDebug>
#include "shemov.h"
#include "filesystemwidget.h"
+#include "fileview.h"
SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {
mFSWidget = new FilesystemWidget;
@@ -20,6 +26,9 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(mTab);
+ createActions();
+ createMenus();
+
QWidget *centralWidget = new QWidget;
centralWidget->setLayout(mainLayout);
setCentralWidget(centralWidget);
@@ -27,4 +36,27 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla
}
+void SheMov::createActions(){
+ qDebug() << "Creating Actions";
+ mQuitA = new QAction(tr("Quit"), this);
+ mQuitA->setShortcut(tr("CTRL+q"));
+ connect(mQuitA, SIGNAL(triggered()), qApp, SLOT(quit()));
+ mMarkFilesA = new QAction(tr("Mark files"), this);
+ mMarkFilesA->setShortcut(tr("CTRL++"));
+ connect(mMarkFilesA, SIGNAL(triggered()), mFSWidget->fileView(), SLOT(markFiles()));
+ mUnmarkFilesA = new QAction(tr("Unmark all files"), this);
+ mUnmarkFilesA->setShortcut(tr("CTRL+-"));
+ connect(mUnmarkFilesA, SIGNAL(triggered()), mFSWidget->fileView(), SLOT(unmarkFiles()));
+}
+
+void SheMov::createMenus(){
+ QMenu *fileMenu = new QMenu(tr("&File"), this);
+ fileMenu->addAction(mQuitA);
+ QMenu *editMenu = new QMenu(tr("&Edit"), this);
+ editMenu->addAction(mMarkFilesA);
+ editMenu->addAction(mUnmarkFilesA);
+
+ menuBar()->addMenu(fileMenu);
+ menuBar()->addMenu(editMenu);
+}
diff --git a/shemov.h b/shemov.h
index 2de2adc..aff8624 100644
--- a/shemov.h
+++ b/shemov.h
@@ -12,6 +12,7 @@
class QTabWidget;
class FilesystemWidget;
+class QAction;
class SheMov : public QMainWindow {
Q_OBJECT
@@ -20,6 +21,15 @@ class SheMov : public QMainWindow {
~SheMov() {};
private:
+ void createActions();
+ void createMenus();
+
+ //Actions
+ QAction *mQuitA;
+ QAction *mMarkFilesA;
+ QAction *mUnmarkFilesA;
+ //EndActions
+
QTabWidget *mTab;
FilesystemWidget *mFSWidget;
diff --git a/shemov.pro b/shemov.pro
index 9436854..36a93fd 100644
--- a/shemov.pro
+++ b/shemov.pro
@@ -13,7 +13,8 @@ fileview.cpp \
shemov.cpp \
filesystemfileproxy.cpp \
helper.cpp \
-shemoviconprovider.cpp
+shemoviconprovider.cpp \
+messagedialog.cpp
HEADERS = listitem.h \
listmodel.h \
movieitem.h \
@@ -25,6 +26,7 @@ fileview.h \
shemov.h \
filesystemfileproxy.h \
helper.h \
-shemoviconprovider.h
+shemoviconprovider.h \
+messagedialog.h
LIBS += -lmagic
RESOURCES = shemov.qrc