/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #include #include #include #include #include #include #include #include namespace AssetProcessor { ProductDependencyTreeDelegate::ProductDependencyTreeDelegate(QObject* parent, QPointer panel) : QStyledItemDelegate(parent) , m_panel(panel) { } bool ProductDependencyTreeDelegate::editorEvent( QEvent* event, [[maybe_unused]] QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index) { if (event->type() == QEvent::MouseButtonPress) { QMouseEvent* mouseEvent = static_cast(event); const QWidget* widget = option.widget; QStyle* style; style = (widget ? widget->style() : QApplication::style()); // Currently, the icon area is the leftmost part of SE_ItemViewItemText, instead of SE_ItemViewItemDecoration. // As a workaround, I get the icon area by fetching TextRect and set width to be the same as height. QRect rect = style->subElementRect(QStyle::SE_ItemViewItemText, &option, widget); rect.setWidth(rect.height()); if (rect.contains(mouseEvent->pos())) { m_panel->GoToProduct((static_cast(index.internalPointer()))->GetData()->m_productName); } return true; } return false; } } // namespace AssetProcessor