| 44 | }; |
| 45 | |
| 46 | CFileStatsWindow::CFileStatsWindow(QWidget* parent, const FileStatistics& stats, CController& controller) : |
| 47 | QMainWindow{ nullptr } |
| 48 | { |
| 49 | setWindowTitle(tr("Statistics")); |
| 50 | |
| 51 | const QString statsText = tr("Files: %1\nFolders: %2\nOccupied space: %3\n%4"). |
| 52 | arg(stats.files).arg(stats.folders).arg(fileSizeToString(stats.occupiedSpace), fileSizeToString(stats.occupiedSpace, 'B', " ")); |
| 53 | |
| 54 | setCentralWidget(new QWidget); |
| 55 | auto* layout = new QVBoxLayout(centralWidget()); |
| 56 | |
| 57 | layout->addWidget(new QLabel{ tr("Statistics for the selected items(including subitems):") }); |
| 58 | layout->addWidget(new QLabel{ statsText }); |
| 59 | |
| 60 | layout->addWidget(new QLabel{ tr("Largest files (%1):").arg(stats.largestFiles.size()) }); |
| 61 | |
| 62 | _list = new QTreeWidget; |
| 63 | layout->addWidget(_list); |
| 64 | |
| 65 | auto* btnClose = new QPushButton(tr("Close")); |
| 66 | layout->addWidget(btnClose); |
| 67 | layout->setAlignment(btnClose, Qt::AlignRight); |
| 68 | QObject::connect(btnClose, &QPushButton::clicked, this, &QMainWindow::close); |
| 69 | |
| 70 | _list->setHeaderLabels({ |
| 71 | tr("Name"), |
| 72 | tr("Size"), |
| 73 | tr("Modification date"), |
| 74 | tr("Folder") |
| 75 | }); |
| 76 | _list->header()->setSectionResizeMode(QHeaderView::ResizeToContents); |
| 77 | _list->header()->setStretchLastSection(false); |
| 78 | _list->setSortingEnabled(true); |
| 79 | _list->sortByColumn(columns::Size, Qt::DescendingOrder); |
| 80 | |
| 81 | connect(_list, &QTreeWidget::itemActivated, this, [&controller, parent](QTreeWidgetItem* item) { |
| 82 | const QString path = item->data(columns::Name, Qt::UserRole).toString(); |
| 83 | controller.activePanel().goToItem(CFileSystemObject{ path }); |
| 84 | parent->activateWindow(); |
| 85 | }); |
| 86 | |
| 87 | fillFileList(stats); |
| 88 | |
| 89 | new QShortcut(QKeySequence{ "Esc" }, this, this, &QMainWindow::close); |
| 90 | } |
| 91 | |
| 92 | void CFileStatsWindow::fillFileList(const FileStatistics& stats) |
| 93 | { |
nothing calls this directly
no test coverage detected