summaryrefslogtreecommitdiffstats
path: root/filestreewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r--filestreewidget.cpp45
1 files changed, 44 insertions, 1 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp
index 8d9a435..7af3f6f 100644
--- a/filestreewidget.cpp
+++ b/filestreewidget.cpp
@@ -12,20 +12,63 @@
#include "filestreewidget.h"
#include "smmodelsingleton.h"
#include "filestreemodel.h"
+#include "seriestreemodel.h"
-FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent){
+FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSize(0){
//the view
mView = new FilesTreeView;
+ mView->setSelectionMode(QAbstractItemView::ExtendedSelection);
mModel = static_cast<FilesTreeModel*>(SmModelSingleton::instance()->model("FilesModel"));
mProxy = new FilesTreeSortModel(this);
mProxy->setSourceModel(mModel);
mView->setModel(mProxy);
mView->setSortingEnabled(true);
+ QItemSelectionModel *selModel = mView->selectionModel();
+ connect(selModel, SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(fileSelectionChanged(QModelIndex,QModelIndex)));
+ connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged(QItemSelection,QItemSelection)));
//layout
QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(mView);
setLayout(mainLayout);
+
+ //series model
+ mSeriesModel = static_cast<SeriesTreeModel*>(SmModelSingleton::instance()->model("SeriesModel"));
+}
+
+void FilesTreeWidget::fileSelectionChanged(const QModelIndex &current, const QModelIndex &previous){
+ Q_UNUSED(previous);
+ int seriesPartId = current.data(FilesTreeModel::SeriesPartIdRole).toInt();
+ int seriesId = mSeriesModel->seriesIdByPartId(seriesPartId);
+ int filePart = current.data(FilesTreeModel::PartNoRole).toInt();
+ QModelIndex seriesIdx = mSeriesModel->findValue(seriesId, QModelIndex(), SeriesTreeModel::SeriesId);
+ if(seriesIdx.isValid()){
+ QModelIndex seriesPartIdx = mSeriesModel->findValue(seriesPartId, seriesIdx, SeriesTreeModel::SeriesPartId);
+ QString seriesNumber = QString::number(seriesPartIdx.data(SeriesTreeModel::SeriesPartRole).toInt());
+ QString msg;
+ if(filePart != 0){
+ msg = QString(tr("%1 %2 (%3)")).arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber).arg(filePart);
+ }else{
+ msg = QString(tr("%1 %2")).arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber);
+ }
+ emit statusMessage(msg);
+ }
+}
+
+void FilesTreeWidget::fileSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected){
+ QModelIndexList sel = selected.indexes();
+ QModelIndexList desel = deselected.indexes();
+ foreach(QModelIndex i, sel){
+ if(i.column() == 0){
+ mSelectedSize += i.data(FilesTreeModel::SizeRole).toLongLong();
+ }
+ }
+ foreach(QModelIndex i, desel){
+ if(i.column() == 0){
+ mSelectedSize -= i.data(FilesTreeModel::SizeRole).toLongLong();
+ }
+ }
+ emit sizeChanged(mSelectedSize);
}
FilesTreeView::FilesTreeView(QWidget *parent) : QTreeView(parent){}