diff options
-rw-r--r-- | archivetreeview.cpp | 19 | ||||
-rw-r--r-- | filestreemodel.cpp | 16 | ||||
-rw-r--r-- | filestreewidget.cpp | 34 | ||||
-rw-r--r-- | filestreewidget.h | 4 | ||||
-rw-r--r-- | shemov.cpp | 48 | ||||
-rw-r--r-- | shemov.h | 4 | ||||
-rw-r--r-- | smglobals.cpp | 2 | ||||
-rw-r--r-- | smtreemodel.cpp | 7 | ||||
-rw-r--r-- | smtreemodel.h | 19 |
9 files changed, 126 insertions, 27 deletions
diff --git a/archivetreeview.cpp b/archivetreeview.cpp index 2260052..49004e3 100644 --- a/archivetreeview.cpp +++ b/archivetreeview.cpp @@ -31,6 +31,7 @@ #include <QMessageBox> #include <QClipboard> #include <QApplication> +#include <QHeaderView> #include "archivetreeview.h" #include "smglobals.h" @@ -58,12 +59,7 @@ ArchiveTreeView::ArchiveTreeView(QWidget *parent) : QWidget(parent){ // files view mFilesWidget = new FilesTreeWidget; - QAbstractItemModel *filesModel = SmGlobals::instance()->model("FilesModel"); - mFilesModel = static_cast<FilesTreeModel*>(filesModel); - for(int i = 5; i < 12; ++i){ - mFilesWidget->filesTree()->setColumnHidden(i, true); - } - mFilesWidget->filesTree()->setColumnHidden(14, true); + mFilesModel = qobject_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); connect(mSeriesWidget, SIGNAL(filesReload()), mFilesWidget->filesTree(), SLOT(expandAll())); // actors and genre @@ -118,9 +114,7 @@ void ArchiveTreeView::setFileViewMode(int mode){ currentChanged(QItemSelection(), QItemSelection()); } mFilesWidget->filesTree()->expandAll(); - mFilesWidget->filesTree()->resizeColumnToContents(0); - mFilesWidget->filesTree()->resizeColumnToContents(1); - mFilesWidget->filesTree()->resizeColumnToContents(2); + mFilesWidget->filesTree()->header()->resizeSections(QHeaderView::ResizeToContents); constructWindowTitle(); } @@ -237,12 +231,7 @@ void ArchiveTreeView::currentChanged(const QItemSelection &selected, const QItem mFilesModel->setIds(selectedPartIds); mFilesWidget->filesTree()->expandAll(); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::FileName); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::PartNo); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::Quality); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::DvdNo); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::DisplayName); - mFilesWidget->filesTree()->resizeColumnToContents(FilesTreeModel::SizeDuration); + mFilesWidget->filesTree()->header()->resizeSections(QHeaderView::ResizeToContents); setMappingItems(selectedPartIds, mActorsModel, mActorsWidget); setMappingItems(selectedPartIds, mGenresModel, mGenresWidget); } diff --git a/filestreemodel.cpp b/filestreemodel.cpp index 35ae8bc..f47f8c3 100644 --- a/filestreemodel.cpp +++ b/filestreemodel.cpp @@ -16,6 +16,7 @@ #include <QDataStream> #include <QDesktopServices> #include <QDir> +#include <QFont> #include "filestreemodel.h" #include "smtreeitem.h" @@ -74,7 +75,7 @@ FilesTreeModel::~FilesTreeModel(){ const QString FilesTreeModel::modeName(int mode) const{ if(mode == -1){ - return mModeNames.value(mMode); + return QString(); } return mModeNames.value(mode); } @@ -139,6 +140,14 @@ QVariant FilesTreeModel::data(const QModelIndex &index, int role) const{ } return item->data(Quality); } + if(index.column() == FileType){ + return mFileTypes.value(item->data(FileType).toInt()); + } + if(index.column() == FullPath){ + if(item->data(DvdNo).toInt() > 0){ + return QString("(not available)"); + } + } return item->data(index.column()); } if(role == Qt::ToolTipRole){ @@ -185,6 +194,11 @@ QVariant FilesTreeModel::data(const QModelIndex &index, int role) const{ return QColor(Qt::green); } } + if(role == Qt::FontRole){ + if(index.column() == Md5Sum){ + return QFont("courier"); + } + } if(role == FileNameRole){ return item->data(FileName); } diff --git a/filestreewidget.cpp b/filestreewidget.cpp index b017d7d..4ed9662 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -21,6 +21,7 @@ #include <QSettings> #include <QEvent> #include <QSettings> +#include <QHeaderView> #include "filestreewidget.h" #include "smglobals.h" @@ -275,7 +276,16 @@ void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent), mHoverWin(new HoverWindow), mHover(false){ setAttribute(Qt::WA_Hover); - readConfig(); + +} + +void FilesTreeView::setModel(QAbstractItemModel *model){ + QTreeView::setModel(model); + for(int i = 0; i < header()->count(); ++i){ + header()->setSectionHidden(i, true); + } + readHeaderConfig(); + connect(header(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(sectionHasMoved(int,int,int))); } void FilesTreeView::readConfig(){ @@ -284,6 +294,27 @@ void FilesTreeView::readConfig(){ mHoverWin->setWindowOpacity(s.value("ui/hoveropacity", 10).toFloat() / 10.0); } +void FilesTreeView::readHeaderConfig(){ + QSettings s; + QByteArray headerPos = s.value("ui/headerpos").toByteArray(); + if(!headerPos.isEmpty()){ + header()->restoreState(headerPos); + } +} + +void FilesTreeView::writeHeaderConfig(){ + QSettings s; + s.setValue("ui/headerpos", header()->saveState()); +} + +void FilesTreeView::toggleHeader(QObject *action){ + QAction *a = qobject_cast<QAction*>(action); + Q_ASSERT(a); + int logicalIndex = a->data().toInt(); + QHeaderView *hv = header(); + hv->setSectionHidden(logicalIndex, !a->isChecked()); +} + void FilesTreeView::contextMenuEvent(QContextMenuEvent *event){ QMenu ctxMenu; foreach(QAction *a, actions()){ @@ -350,6 +381,7 @@ bool FilesTreeView::exitHover(bool exitVal){ FilesTreeSortModel::FilesTreeSortModel(QObject *parent) : QSortFilterProxyModel(parent) {} +// left + right are from the sourceModel() !!!! bool FilesTreeSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const{ if(left.parent() == QModelIndex()){ return false; diff --git a/filestreewidget.h b/filestreewidget.h index 7c5243d..ae8e27b 100644 --- a/filestreewidget.h +++ b/filestreewidget.h @@ -63,9 +63,13 @@ class FilesTreeView : public QTreeView { Q_OBJECT public: explicit FilesTreeView(QWidget *parent = 0); + virtual void setModel(QAbstractItemModel *model); public slots: void readConfig(); + void readHeaderConfig(); + void writeHeaderConfig(); + void toggleHeader(QObject *action); protected: virtual void contextMenuEvent(QContextMenuEvent *event); @@ -28,11 +28,13 @@ #include <QFileSystemModel> #include <QToolBar> #include <QIcon> +#include <QHeaderView> #include <sys/vfs.h> #include "shemov.h" #include "filesystemwidget.h" +#include "filestreewidget.h" #include "fileview.h" #include "configurationdialog.h" #include "statisticsdialog.h" @@ -103,6 +105,7 @@ SheMov::SheMov(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, fla mFSWidget->readSettings(); readSettings(); mFSWidget->fileView()->setFocus(Qt::ActiveWindowFocusReason); + mATree->filesWidget()->filesTree()->header()->resizeSections(QHeaderView::ResizeToContents); } void SheMov::closeEvent(QCloseEvent *event){ @@ -166,6 +169,8 @@ void SheMov::tabChanged(int newTab){ mShowArchivedA->setEnabled(false); mShowLocalA->setEnabled(false); mShowNoCoverDialogA->setEnabled(false); + mFilesTreeHeadersGroup->setEnabled(false); + mTreeHeaderMenu->setEnabled(false); } if(newTab == 1){ setWindowTitle(mATree->windowTitle()); @@ -175,6 +180,8 @@ void SheMov::tabChanged(int newTab){ mShowArchivedA->setEnabled(true); mShowLocalA->setEnabled(true); mShowNoCoverDialogA->setEnabled(true); + mFilesTreeHeadersGroup->setEnabled(true); + mTreeHeaderMenu->setEnabled(true); } updateSelectionCount(QItemSelection(), QItemSelection()); } @@ -418,6 +425,22 @@ void SheMov::createActions(){ mShowNoCoverDialogA = new QAction(QIcon(":/higheels.png"), tr("List movies without cover..."), this); connect(mShowNoCoverDialogA, SIGNAL(triggered()), mATree, SLOT(showNoCoverDialog())); + //Tree view headers + FilesTreeModel *filesModel = static_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); + QHash<QString, int> headerData = filesModel->headerData(); + QSignalMapper *headerMapper = new QSignalMapper(this); + mFilesTreeHeadersGroup = new QActionGroup(this); + mFilesTreeHeadersGroup->setExclusive(false); + for(QHash<QString, int>::const_iterator it = headerData.constBegin(); it != headerData.constEnd(); ++it){ + QAction *a = new QAction(it.key(), this); + a->setCheckable(true); + a->setData(it.value()); + mFilesTreeHeadersGroup->addAction(a); + headerMapper->setMapping(a, a); + connect(a, SIGNAL(triggered()), headerMapper, SLOT(map())); + } + connect(headerMapper, SIGNAL(mapped(QObject*)), mATree->filesWidget()->filesTree(), SLOT(toggleHeader(QObject*))); + //Tree FileWidget actions mMoveToBurnA = new QAction(tr("Move to burn directory"), this); connect(mMoveToBurnA, SIGNAL(triggered()), mATree->filesWidget(), SLOT(moveToBurn())); @@ -514,6 +537,14 @@ void SheMov::createMenus(){ mTreeViewMenu->addAction(mShowLocalA); mTreeViewMenu->addAction(mShowArchivedA); menuBar()->addMenu(mTreeViewMenu); + QAction *sep14 = new QAction(this); + sep14->setSeparator(true); + mTreeViewMenu->addAction(sep14); + mTreeHeaderMenu = new QMenu(tr("Show headers"), this); + foreach(QAction *a, mFilesTreeHeadersGroup->actions()){ + mTreeHeaderMenu->addAction(a); + } + mTreeViewMenu->addMenu(mTreeHeaderMenu); QMenu *helpMenu = new QMenu(tr("&Help"), this); helpMenu->addAction(mAboutShemovA); @@ -691,6 +722,14 @@ void SheMov::writeSettings(){ s.setValue("ui/selectedtab", mTab->currentIndex()); FilesTreeModel *filesModel = static_cast<FilesTreeModel*>(SmGlobals::instance()->model("FilesModel")); s.setValue("ui/filestreemode", filesModel->mode()); + QList<QVariant> visibleHeaders; + foreach(QAction *a, mFilesTreeHeadersGroup->actions()){ + if(a->isChecked()){ + visibleHeaders << a->data(); + } + } + s.setValue("ui/visibleheaders", visibleHeaders); + mATree->filesWidget()->filesTree()->writeHeaderConfig(); } void SheMov::readSettings(){ @@ -736,6 +775,15 @@ void SheMov::readSettings(){ mMountDvdA->setChecked(false); } } + QList<QVariant> visibleHeadersDefault = QList<QVariant>() << 0 << 1 << 2 << 3 << 4 << 13; + QList<QVariant> visibleHeaders = s.value("ui/visibleheaders", visibleHeadersDefault).toList(); + foreach(QVariant h, visibleHeaders){ + foreach(QAction *a, mFilesTreeHeadersGroup->actions()){ + if(a->data() == h){ + a->trigger(); + } + } + } } void SheMov::checkConsistency(){ @@ -27,7 +27,7 @@ class SheMov : public QMainWindow { Q_OBJECT public: SheMov(QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~SheMov() {}; + ~SheMov() {} protected: virtual void closeEvent(QCloseEvent *event); @@ -134,6 +134,7 @@ class SheMov : public QMainWindow { QActionGroup *mOpenWithGroupFS; QActionGroup *mOpenWithGroupAV; QActionGroup *mCleanupGroup; + QActionGroup *mFilesTreeHeadersGroup; //EndActions QSignalMapper *mRenameMapper; @@ -146,6 +147,7 @@ class SheMov : public QMainWindow { QMenu *mOpenWithMenuAV; QMenu *mRenameMenu; QMenu *mTreeViewMenu; + QMenu *mTreeHeaderMenu; QAction *mEditFSMenuA; //widgets + dialogs diff --git a/smglobals.cpp b/smglobals.cpp index 6b32527..9b4837c 100644 --- a/smglobals.cpp +++ b/smglobals.cpp @@ -57,7 +57,7 @@ QAbstractItemModel *SmGlobals::model(const QString &which){ } }else if(which == "FilesModel"){ if(!mModels.contains(which)){ - QStringList headers = QStringList() << tr("Name") << tr("Part") << tr("Size") << tr("Qual.") << tr("Dvd") << tr("Full Path") << tr("Size") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID") << tr("Seriespart") << tr("Display name") << tr("Dur./Size") << tr("Series name"); + QStringList headers = QStringList() << tr("Name") << tr("Part") << tr("Size") << tr("Qual.") << tr("Dvd") << tr("Full Path") << tr("Size (int)") << tr("Type") << tr("Md5 sum") << tr("Series part ID") << tr("File ID") << tr("Seriespart") << tr("Display name") << tr("Dur./Size") << tr("Series name"); FilesTreeModel *model = new FilesTreeModel(headers); mModels.insert(which, model); } diff --git a/smtreemodel.cpp b/smtreemodel.cpp index a39f718..2712cef 100644 --- a/smtreemodel.cpp +++ b/smtreemodel.cpp @@ -12,6 +12,9 @@ SmTreeModel::SmTreeModel(const QStringList &headers, QObject *parent) : QAbstractItemModel(parent), mRootItem(0){ mHeaders = headers; + for(int i = 0; i < mHeaders.size(); ++i){ + mHeaderData.insert(mHeaders.at(i), i); + } mRootItem = new SmTreeItem(headers.count()); } @@ -69,6 +72,10 @@ QVariant SmTreeModel::headerData(int section, Qt::Orientation orientation, int r return QVariant(); } +const QHash<QString, int> SmTreeModel::headerData() const{ + return mHeaderData; +} + bool SmTreeModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role){ if((orientation == Qt::Horizontal) && (role == Qt::DisplayRole)){ mRootItem->setData(section, value); diff --git a/smtreemodel.h b/smtreemodel.h index 3eae432..73abe64 100644 --- a/smtreemodel.h +++ b/smtreemodel.h @@ -10,6 +10,7 @@ #include <QAbstractItemModel> #include <QStringList> +#include <QHash> class SmTreeItem; @@ -20,17 +21,18 @@ class SmTreeModel : public QAbstractItemModel { virtual ~SmTreeModel(); // counts - int rowCount(const QModelIndex &parent) const; - int columnCount(const QModelIndex &parent) const; + virtual int rowCount(const QModelIndex &parent) const; + virtual int columnCount(const QModelIndex &parent) const; // index, parent and flags - QModelIndex index(int row, int column, const QModelIndex &parent) const; - QModelIndex parent(const QModelIndex &child) const; + virtual QModelIndex index(int row, int column, const QModelIndex &parent) const; + virtual QModelIndex parent(const QModelIndex &child) const; virtual Qt::ItemFlags flags(const QModelIndex &index) const; // headers + data - QVariant headerData(int section, Qt::Orientation orientation, int role) const; - bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role); + virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const; + virtual const QHash<QString, int> headerData() const; + virtual bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role); virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &index, const QVariant &value, int role); virtual QModelIndex find(const QVariant &value, int column = 0, const QModelIndex &parent = QModelIndex()) const; @@ -42,8 +44,8 @@ class SmTreeModel : public QAbstractItemModel { void reparent(const QModelIndex &idx, const QModelIndex &newParent); // row manipulation - bool insertRows(int row, int count, const QModelIndex &parent); - bool removeRows(int row, int count, const QModelIndex &parent); + virtual bool insertRows(int row, int count, const QModelIndex &parent); + virtual bool removeRows(int row, int count, const QModelIndex &parent); bool addRow(const QList<QVariant> &data, const QModelIndex &parent); protected: @@ -52,6 +54,7 @@ class SmTreeModel : public QAbstractItemModel { private: QStringList mHeaders; SmTreeItem *mRootItem; + QHash<QString, int> mHeaderData; }; #endif |