diff options
Diffstat (limited to 'filestreewidget.cpp')
-rw-r--r-- | filestreewidget.cpp | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/filestreewidget.cpp b/filestreewidget.cpp index 1a17be5..6222d99 100644 --- a/filestreewidget.cpp +++ b/filestreewidget.cpp @@ -54,8 +54,7 @@ FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSi 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))); + connect(selModel, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(fileSelectionChanged())); connect(mView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(itemDoubleClicked(QModelIndex))); //layout @@ -70,7 +69,7 @@ FilesTreeWidget::FilesTreeWidget(QWidget *parent) : QWidget(parent), mSelectedSi void FilesTreeWidget::resetSize(){ mSelectedSize = 0; - emit sizeChanged(mSelectedSize); + emit selectedSize(mSelectedSize); } void FilesTreeWidget::moveToBurn(){ @@ -287,23 +286,27 @@ void FilesTreeWidget::suggest(){ mView->scrollTo(last, QAbstractItemView::PositionAtCenter); } -void FilesTreeWidget::fileSelectionChanged(const QModelIndex ¤t, 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(){ + QModelIndexList selected = mView->selectionModel()->selectedRows(); + qint64 selSize = 0; + QStringList selectedSeries; + foreach(QModelIndex idx, selected){ + selSize += idx.data(FilesTreeModel::SizeRole).toLongLong(); + int seriesPartId = idx.data(FilesTreeModel::SeriesPartIdRole).toInt(); + int seriesId = mSeriesModel->seriesIdByPartId(seriesPartId); + 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 seriesString = QString("%1 %2").arg(seriesIdx.data(SeriesTreeModel::NameRole).toString()).arg(seriesNumber); + if(!selectedSeries.contains(seriesString)){ + selectedSeries << seriesString; + } + } + } + emit selectedSize(selSize); + emit numSelected(selected.size()); + emit statusMessage(QString(tr("Series: %1")).arg(selectedSeries.join(","))); } void FilesTreeWidget::itemDoubleClicked(const QModelIndex &index){ @@ -334,22 +337,6 @@ void FilesTreeWidget::itemDoubleClicked(const QModelIndex &index){ } } -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), mHoverWin(new HoverWindow), mHoverPics(false){ setAttribute(Qt::WA_Hover); } |