diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.cpp b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.cpp index 017f59cdc3..158e45d6e2 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.cpp +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.cpp @@ -20,7 +20,7 @@ #include OutlinerTreeView::OutlinerTreeView(QWidget* pParent) - : QTreeView(pParent) + : AzQtComponents::StyledTreeView(pParent) , m_queuedMouseEvent(nullptr) , m_draggingUnselectedItem(false) { @@ -135,16 +135,12 @@ void OutlinerTreeView::startDrag(Qt::DropActions supportedActions) if (!selectionModel()->isSelected(index)) { - startCustomDrag({ index }, supportedActions); + StartCustomDrag({ index }, supportedActions); return; } } - if (!selectionModel()->selectedIndexes().empty()) - { - startCustomDrag(selectionModel()->selectedIndexes(), supportedActions); - return; - } + StyledTreeView::startDrag(supportedActions); } void OutlinerTreeView::dragMoveEvent(QDragMoveEvent* event) @@ -336,14 +332,14 @@ void OutlinerTreeView::processQueuedMousePressedEvent(QMouseEvent* event) QTreeView::mousePressEvent(&mousePressedEvent); } -void OutlinerTreeView::startCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions) +void OutlinerTreeView::StartCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions) { m_draggingUnselectedItem = true; //sort by container entity depth and order in hierarchy for proper drag image and drop order QModelIndexList indexListSorted = indexList; AZStd::unordered_map> locations; - for (auto index : indexListSorted) + for (const auto& index : indexListSorted) { AZ::EntityId entityId(index.data(OutlinerListModel::EntityIdRole).value()); AzToolsFramework::GetEntityLocationInHierarchy(entityId, locations[entityId]); @@ -356,74 +352,7 @@ void OutlinerTreeView::startCustomDrag(const QModelIndexList& indexList, Qt::Dro return AZStd::lexicographical_compare(locationsE1.begin(), locationsE1.end(), locationsE2.begin(), locationsE2.end()); }); - //get the data for the unselected item(s) - QMimeData* mimeData = model()->mimeData(indexListSorted); - if (mimeData) - { - //initiate drag/drop for the item - QDrag* drag = new QDrag(this); - drag->setPixmap(QPixmap::fromImage(createDragImage(indexListSorted))); - drag->setMimeData(mimeData); - Qt::DropAction defDropAction = Qt::IgnoreAction; - if (defaultDropAction() != Qt::IgnoreAction && (supportedActions & defaultDropAction())) - { - defDropAction = defaultDropAction(); - } - else if (supportedActions & Qt::CopyAction && dragDropMode() != QAbstractItemView::InternalMove) - { - defDropAction = Qt::CopyAction; - } - drag->exec(supportedActions, defDropAction); - } -} - -QImage OutlinerTreeView::createDragImage(const QModelIndexList& indexList) -{ - //generate a drag image of the item icon and text, normally done internally, and inaccessible - QRect rect(0, 0, 0, 0); - for (auto index : indexList) - { - if (index.column() != 0) - { - continue; - } - QRect itemRect = visualRect(index); - rect.setHeight(rect.height() + itemRect.height()); - rect.setWidth(AZStd::GetMax(rect.width(), itemRect.width())); - } - - QImage dragImage(rect.size(), QImage::Format_ARGB32_Premultiplied); - - QPainter dragPainter(&dragImage); - dragPainter.setCompositionMode(QPainter::CompositionMode_Source); - dragPainter.fillRect(dragImage.rect(), Qt::transparent); - dragPainter.setCompositionMode(QPainter::CompositionMode_SourceOver); - dragPainter.setOpacity(0.35f); - dragPainter.fillRect(rect, QColor("#222222")); - dragPainter.setOpacity(1.0f); - - int imageY = 0; - for (auto index : indexList) - { - if (index.column() != 0) - { - continue; - } - - QRect itemRect = visualRect(index); - dragPainter.drawPixmap(QPoint(0, imageY), - model()->data(index, Qt::DecorationRole).value().pixmap(QSize(16, 16))); - dragPainter.setPen( - model()->data(index, Qt::ForegroundRole).value().color()); - dragPainter.setFont( - font()); - dragPainter.drawText(QRect(20, imageY, rect.width() - 20, rect.height()), - model()->data(index, Qt::DisplayRole).value()); - imageY += itemRect.height(); - } - - dragPainter.end(); - return dragImage; + StyledTreeView::StartCustomDrag(indexListSorted, supportedActions); } #include diff --git a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.hxx b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.hxx index fe7a494be4..b597b70092 100644 --- a/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.hxx +++ b/Code/Editor/Plugins/ComponentEntityEditorPlugin/UI/Outliner/OutlinerTreeView.hxx @@ -15,7 +15,8 @@ #include #include -#include + +#include #endif #pragma once @@ -31,7 +32,7 @@ class OutlinerTreeViewModel; //! allow for dragging and dropping of entities from the outliner into the property editor //! of other entities. If the selection updates instantly, this would never be possible. class OutlinerTreeView - : public QTreeView + : public AzQtComponents::StyledTreeView { Q_OBJECT; public: @@ -66,9 +67,7 @@ private: void processQueuedMousePressedEvent(QMouseEvent* event); - void startCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions); - - QImage createDragImage(const QModelIndexList& indexList); + void StartCustomDrag(const QModelIndexList& indexList, Qt::DropActions supportedActions) override; void DrawLayerUI(QPainter* painter, const QRect& rect, const QModelIndex& index) const;