#include "ContextPanel.h" #include "ContextModel.h" #include "PropertyWidgets.h" #include "PropertiesPanel.h" #include #include #include #include #include #include #include #include ContextPanel::ContextPanel(QWidget* parent) : QWidget(parent) , m_context(nullptr) { this->setObjectName("ContextPanel"); this->setAttribute(Qt::WA_StyledBackground); m_layout = new QVBoxLayout(this); m_layout->setContentsMargins(0, 0, 0, 0); m_layout->setSpacing(0); // Title bar setup m_titleBar = new QWidget(this); m_titleBar->setObjectName("PaneTitleBar"); m_titleBar->setFixedHeight(22); auto* titleLayout = new QHBoxLayout(m_titleBar); titleLayout->setContentsMargins(5, 0, 5, 0); m_titleLabel = new QLabel("Context Panel", m_titleBar); m_titleLabel->setObjectName("TitleLabel"); titleLayout->addWidget(m_titleLabel); titleLayout->addStretch(); m_layout->addWidget(m_titleBar); m_treeView = new QTreeView(this); m_treeView->setObjectName("ContextTree"); m_treeView->setHeaderHidden(false); m_treeView->setDragEnabled(true); m_treeView->setAcceptDrops(true); m_treeView->setDropIndicatorShown(true); m_treeView->setDragDropMode(QAbstractItemView::DragDrop); m_model = new ContextModel(this); m_treeView->setModel(m_model); m_splitter = new QSplitter(Qt::Vertical, this); m_splitter->addWidget(m_treeView); m_propertiesPanel = new PropertiesPanel(m_splitter); m_splitter->addWidget(m_propertiesPanel); QList sizes; sizes << 400 << 600; m_splitter->setSizes(sizes); m_layout->addWidget(m_splitter); connect(m_treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ContextPanel::onSelectionChanged); auto* deleteShortcut = new QShortcut(QKeySequence::Delete, this); connect(deleteShortcut, &QShortcut::activated, [this]() { auto selectedIndexes = m_treeView->selectionModel()->selectedIndexes(); if (selectedIndexes.isEmpty() || !m_context) return; std::vector toRemove; for (const auto& idx : selectedIndexes) { if (idx.column() == 0) { toRemove.push_back(static_cast(idx.internalPointer())); } } for (auto* obj : toRemove) { m_context->RemoveObject(obj); } }); } ContextPanel::~ContextPanel() {} void ContextPanel::setContext(uLib::ObjectsContext* context) { m_context = context; m_model->setContext(context); m_treeView->expandAll(); } void ContextPanel::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { uLib::Object* target = nullptr; if (!selected.indexes().isEmpty()) { target = static_cast(selected.indexes().first().internalPointer()); } emit objectSelected(target); m_propertiesPanel->setObject(target); } void ContextPanel::selectObject(uLib::Object* obj) { if (!obj) { clearSelection(); return; } for (int i = 0; i < m_model->rowCount(); ++i) { QModelIndex idx = m_model->index(i, 0); if (idx.internalPointer() == obj) { QSignalBlocker blocker(m_treeView->selectionModel()); m_treeView->selectionModel()->select(idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); m_treeView->scrollTo(idx); m_propertiesPanel->setObject(obj); // Explicitly update properties too return; } } } void ContextPanel::clearSelection() { QSignalBlocker blocker(m_treeView->selectionModel()); m_treeView->selectionModel()->clearSelection(); m_propertiesPanel->setObject(nullptr); }