2
0

ProductDependencyTreeDelegate.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <native/ui/ProductDependencyTreeDelegate.h>
  9. #include <native/ui/ProductDependencyTreeItemData.h>
  10. #include <native/ui/ProductAssetDetailsPanel.h>
  11. #include <native/ui/ProductAssetTreeItemData.h>
  12. #include <QMouseEvent>
  13. #include <QApplication>
  14. #include <AzCore/Debug/Trace.h>
  15. #include <iostream>
  16. namespace AssetProcessor
  17. {
  18. ProductDependencyTreeDelegate::ProductDependencyTreeDelegate(QObject* parent, QPointer<ProductAssetDetailsPanel> panel)
  19. : QStyledItemDelegate(parent)
  20. , m_panel(panel)
  21. {
  22. }
  23. bool ProductDependencyTreeDelegate::editorEvent(
  24. QEvent* event, [[maybe_unused]] QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index)
  25. {
  26. if (event->type() == QEvent::MouseButtonPress)
  27. {
  28. QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
  29. const QWidget* widget = option.widget;
  30. QStyle* style;
  31. style = (widget ? widget->style() : QApplication::style());
  32. // Currently, the icon area is the leftmost part of SE_ItemViewItemText, instead of SE_ItemViewItemDecoration.
  33. // As a workaround, I get the icon area by fetching TextRect and set width to be the same as height.
  34. QRect rect = style->subElementRect(QStyle::SE_ItemViewItemText, &option, widget);
  35. rect.setWidth(rect.height());
  36. if (rect.contains(mouseEvent->pos()))
  37. {
  38. m_panel->GoToProduct((static_cast<ProductDependencyTreeItem*>(index.internalPointer()))->GetData()->m_productName);
  39. }
  40. return true;
  41. }
  42. return false;
  43. }
  44. } // namespace AssetProcessor