/* 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 #include #include "archivebrowser.h" #include "archivebrowsermodel.h" #include "smtreeview.h" #include "smglobals.h" #include "delegates.h" ArchiveBrowser::ArchiveBrowser(QWidget *parent) : QWidget(parent){ //prep mModel = static_cast(SmGlobals::instance()->model("BrowserModel")); mProxy = new QSortFilterProxyModel; mProxy->setSourceModel(mModel); mTree = new SmTreeView; mTree->setModel(mProxy); mTree->setColumnHidden(ArchiveBrowserModel::GenericId, true); mTree->setColumnHidden(ArchiveBrowserModel::NodeType, true); mTree->setSortingEnabled(true); mTree->setItemDelegateForColumn(ArchiveBrowserModel::TotalSize, new SizeDelegate(this)); mTree->setItemDelegateForColumn(ArchiveBrowserModel::FileType, new FileTypeDelegate(this)); mTree->setSelectionMode(QAbstractItemView::ExtendedSelection); //connect connect(mTree->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(browserSelectionChanged(QItemSelection,QItemSelection))); //make widget QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(mTree); setLayout(mainLayout); } void ArchiveBrowser::browserSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { Q_UNUSED(selected); Q_UNUSED(deselected); QModelIndexList sel = mTree->selectionModel()->selectedRows(); qint64 size = 0; int selItems = 0; foreach(QModelIndex idx, sel){ size += idx.data(ArchiveBrowserModel::TotalSizeRole).toDouble(); ++selItems; } emit sizeChanged(size); emit itemCountChanged(selItems); }