XPlor/app/xtreewidget.cpp

51 lines
1.5 KiB
C++
Raw Permalink Normal View History

2025-09-05 20:53:15 +00:00
#include "xtreewidget.h"
#include "qheaderview.h"
#include "qmenu.h"
#include "logmanager.h"
2026-01-01 22:18:51 -05:00
#include "xtreewidgetitem.h"
#include <QFileDialog>
2025-09-05 20:53:15 +00:00
XTreeWidget::XTreeWidget(QWidget *parent)
: QTreeWidget(parent) {
setContextMenuPolicy(Qt::CustomContextMenu);
setSelectionMode(QTreeWidget::SingleSelection);
setColumnCount(3);
header()->hide();
setMinimumWidth(350);
2026-01-01 22:18:51 -05:00
setSortingEnabled(false); // Preserve parse order instead of sorting alphabetically
2025-09-05 20:53:15 +00:00
setIconSize(QSize(16, 16));
header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
connect(this, &XTreeWidget::itemSelectionChanged, this, &XTreeWidget::ItemSelectionChanged);
connect(this, &XTreeWidget::customContextMenuRequested, this, &XTreeWidget::PrepareContextMenu);
}
void XTreeWidget::PrepareContextMenu(const QPoint &pos) {
auto activeItem = itemAt(pos);
if (!activeItem) { return; }
if (activeItem->text(0).isEmpty()) { return; }
QString activeText = activeItem->text(0);
QMenu *contextMenu = new QMenu(this);
QPoint pt(pos);
contextMenu->exec(mapToGlobal(pt));
delete contextMenu;
}
void XTreeWidget::ItemSelectionChanged() {
if (selectedItems().isEmpty()) { return; }
XTreeWidgetItem *selectedItem = dynamic_cast<XTreeWidgetItem*>(selectedItems().first());
if (!selectedItem) { return; }
if (selectedItem->text(0).isEmpty()) { return; }
QString selectedText = selectedItem->text(0);
2026-01-01 22:18:51 -05:00
emit ItemSelected(selectedText);
2025-09-05 20:53:15 +00:00
}