From 39da63b33c14cfa3f640a761fad1e27b79f9c91f Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Thu, 18 Dec 2025 09:40:45 -0500 Subject: truncate long paths in triage view and prevent the UI from moving when starting BASE --- examples/triage/fileinfo.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'examples/triage/fileinfo.cpp') diff --git a/examples/triage/fileinfo.cpp b/examples/triage/fileinfo.cpp index b6359fbf..e18c94d8 100644 --- a/examples/triage/fileinfo.cpp +++ b/examples/triage/fileinfo.cpp @@ -4,8 +4,12 @@ #include "copyablelabel.h" #include #include +#include +#include #include #include +#include +#include #include #include #include @@ -21,6 +25,26 @@ void FileInfoWidget::addCopyableField(const QString& name, const QVariant& value this->m_layout->addWidget(valueLabel, row++, column + 1); } +void FileInfoWidget::addCopyableFieldWithElide(const QString& name, const QVariant& value, int maxWidth) +{ + auto& [row, column] = this->m_fieldPosition; + + const auto fullText = value.toString(); + const auto font = getMonospaceFont(this); + const QFontMetrics fontMetrics(font); + const auto elidedText = fontMetrics.elidedText(fullText, Qt::ElideMiddle, maxWidth); + + const auto valueLabel = new CopyableLabel(elidedText, getThemeColor(AlphanumericHighlightColor)); + valueLabel->setFont(font); + valueLabel->setCopyText(fullText); + valueLabel->setToolTip(fullText + "\n\nClick to Copy"); + valueLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + valueLabel->setWordWrap(false); + + this->m_layout->addWidget(new QLabel(name), row, column); + this->m_layout->addWidget(valueLabel, row++, column + 1); +} + void FileInfoWidget::addField(const QString& name, const QVariant& value) { auto& [row, column] = this->m_fieldPosition; @@ -115,13 +139,19 @@ FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv) const auto file = bv->GetFile(); const auto filePath = file->GetOriginalFilename(); - this->addCopyableField("Path on disk: ", filePath.c_str()); + + // Calculate max path width as 50% of screen width + // Using screen width since the scroll area viewport isn't sized yet during construction + const int screenWidth = QGuiApplication::primaryScreen()->availableGeometry().width(); + const int maxPathWidth = screenWidth / 2; + + this->addCopyableFieldWithElide("Path on disk: ", filePath.c_str(), maxPathWidth); // If triage view is opened from a project, show both actual filepath and path relative to project if (const auto fileProjectRef = file->GetProjectFile()) { const auto projectFilePath = file->GetProjectFile()->GetPathInProject(); - this->addCopyableField("Path in project: ", projectFilePath.c_str()); + this->addCopyableFieldWithElide("Path in project: ", projectFilePath.c_str(), maxPathWidth); } const auto fileSize = QString::number(view->GetLength(), 16).prepend("0x"); -- cgit v1.3.1