1f9b284de2
Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com> # Conflicts: # Code/Editor/Plugins/ComponentEntityEditorPlugin/ComponentEntityEditorPlugin_precompiled.h # Code/Editor/Plugins/EditorCommon/EditorCommon_precompiled.h # Code/Editor/Plugins/EditorCommon/stdafx.cpp # Code/Editor/Plugins/FFMPEGPlugin/FFMPEGPlugin_precompiled.h # Code/Editor/Plugins/PerforcePlugin/PerforcePlugin_precompiled.h # Code/Editor/Plugins/ProjectSettingsTool/ProjectSettingsTool_precompiled.h # Code/Framework/AzToolsFramework/AzToolsFramework/AzToolsFramework_precompiled.h # Code/Tools/AssetProcessor/native/precompiled.h # Code/Tools/Standalone/StandaloneTools_precompiled.h # Gems/AssetMemoryAnalyzer/Code/Source/AssetMemoryAnalyzer_precompiled.h # Gems/Atom/Asset/ImageProcessingAtom/Code/Source/ImageProcessing_precompiled.h # Gems/Atom/RHI/DX12/Code/Source/RHI/Atom_RHI_DX12_precompiled.h # Gems/Atom/RHI/Metal/Code/Include/Platform/Mac/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Include/Platform/iOS/Atom_RHI_Metal_precompiled_Platform.h # Gems/Atom/RHI/Metal/Code/Source/Atom_RHI_Metal_precompiled.h # Gems/Atom/RHI/Metal/Code/atom_rhi_metal_common_files.cmake # Gems/Atom/RHI/Null/Code/Source/Atom_RHI_Null_precompiled.h # Gems/Atom/RHI/Null/Code/atom_rhi_null_common_files.cmake # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Android/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Linux/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Mac/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Include/Platform/Windows/Atom_RHI_Vulkan_precompiled_Platform.h # Gems/Atom/RHI/Vulkan/Code/Source/Atom_RHI_Vulkan_precompiled.h # Gems/Atom/RHI/Vulkan/Code/Source/RHI/SwapChain.cpp # Gems/Atom/RHI/Vulkan/Code/atom_rhi_vulkan_common_files.cmake # Gems/AtomLyIntegration/AtomFont/Code/Include/AtomLyIntegration/AtomFont/AtomFont_precompiled.h # Gems/Blast/Code/Source/StdAfx.cpp # Gems/Camera/Code/Source/Camera_precompiled.h # Gems/EMotionFX/Code/Source/EMotionFX_precompiled.h # Gems/FastNoise/Code/Source/FastNoise_precompiled.h # Gems/Gestures/Code/Source/Gestures_precompiled.h # Gems/GradientSignal/Code/Source/GradientSignal_precompiled.h # Gems/GraphCanvas/Code/precompiled.h # Gems/ImGui/Code/Source/ImGui_precompiled.h # Gems/InAppPurchases/Code/Source/InAppPurchases_precompiled.h # Gems/LmbrCentral/Code/Source/LmbrCentral_precompiled.h # Gems/LmbrCentral/Code/Tests/ShapeGeometryUtilTest.cpp # Gems/LyShine/Code/Editor/UiCanvasEditor_precompiled.h # Gems/LyShine/Code/Source/Animation/LyShine_precompiled.h # Gems/LyShine/Code/Source/LyShine_precompiled.h # Gems/LyShineExamples/Code/Source/LyShineExamples_precompiled.h # Gems/Maestro/Code/Source/Cinematics/Maestro_precompiled.h # Gems/Maestro/Code/Source/Maestro_precompiled.h # Gems/MessagePopup/Code/Source/MessagePopup_precompiled.h # Gems/Metastream/Code/Source/Metastream_precompiled.h # Gems/Microphone/Code/Source/Microphone_precompiled.h # Gems/Multiplayer/Code/Source/Multiplayer_precompiled.h # Gems/PhysX/Code/NumericalMethods/Source/NumericalMethods_precompiled.h # Gems/PhysX/Code/Source/PhysXUnsupported_precompiled.h # Gems/PhysX/Code/Source/PhysX_precompiled.h # Gems/PhysX/Code/physx_unsupported_files.cmake # Gems/PhysXDebug/Code/Source/PhysXDebugUnsupported_precompiled.h # Gems/PhysXDebug/Code/Source/PhysXDebug_precompiled.h # Gems/ScriptCanvas/Code/Editor/precompiled.h # Gems/ScriptCanvas/Code/Source/precompiled.h # Gems/ScriptCanvasDeveloper/Code/Source/precompiled.h # Gems/ScriptCanvasPhysics/Code/Source/ScriptCanvasPhysics_precompiled.h # Gems/ScriptEvents/Code/Source/precompiled.h # Gems/ScriptEvents/Code/Tests/Editor/EditorTests.cpp # Gems/ScriptedEntityTweener/Code/Source/ScriptedEntityTweener_precompiled.h # Gems/SliceFavorites/Code/Source/SliceFavorites_precompiled.h # Gems/StartingPointCamera/Code/Source/StartingPointCamera_precompiled.h # Gems/StartingPointInput/Code/Source/StartingPointInput_precompiled.h # Gems/StartingPointMovement/Code/Source/StartingPointMovement_precompiled.h # Gems/SurfaceData/Code/Source/SurfaceData_precompiled.h # Gems/TextureAtlas/Code/Source/TextureAtlas_precompiled.h # Gems/TickBusOrderViewer/Code/Source/TickBusOrderViewer_precompiled.h # Gems/Twitch/Code/Source/Twitch_precompiled.h # Gems/VirtualGamepad/Code/Source/VirtualGamepad_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBoxUnsupported_precompiled.h # Gems/WhiteBox/Code/Source/WhiteBox_precompiled.h
263 lines
10 KiB
C++
263 lines
10 KiB
C++
/*
|
|
* 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 "SliceFavoritesWidget.h"
|
|
#include "FavoriteDataModel.h"
|
|
|
|
#include <QFileDialog>
|
|
#include <QGraphicsOpacityEffect>
|
|
#include <QKeyEvent>
|
|
#include <QLabel>
|
|
#include <QMenu>
|
|
#include <QMessageBox>
|
|
#include <QPainter>
|
|
#include <QtCore/QPropertyAnimation>
|
|
#include <QtCore/QTimer>
|
|
#include <AzToolsFramework/AssetBrowser/AssetSelectionModel.h>
|
|
#include <AzToolsFramework/AssetEditor/AssetEditorBus.h>
|
|
|
|
#include <Source/ui_SliceFavoritesWidget.h>
|
|
|
|
Q_DECLARE_METATYPE(AZ::Uuid);
|
|
namespace SliceFavorites
|
|
{
|
|
SliceFavoritesWidget::SliceFavoritesWidget(FavoriteDataModel* dataModel, QWidget* pParent, Qt::WindowFlags flags)
|
|
: QWidget(pParent, flags)
|
|
, m_gui(new Ui::SliceFavoritesWidgetUI())
|
|
, m_dataModel(dataModel)
|
|
{
|
|
m_gui->setupUi(this);
|
|
|
|
m_gui->emptyLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
m_gui->treeView->setModel(dataModel);
|
|
m_gui->treeView->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
|
|
m_gui->treeView->setDragEnabled(true);
|
|
m_gui->treeView->setDropIndicatorShown(true);
|
|
m_gui->treeView->setDragDropMode(QAbstractItemView::DragDrop);
|
|
m_gui->treeView->setAcceptDrops(true);
|
|
m_gui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
m_gui->treeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
m_gui->treeView->setHeaderHidden(true);
|
|
|
|
connect(m_gui->treeView, &QTreeView::customContextMenuRequested, this, &SliceFavoritesWidget::OnOpenTreeContextMenu);
|
|
|
|
m_removeAction = new QAction(QObject::tr("Remove"), this);
|
|
m_removeAction->setShortcut(QKeySequence(Qt::Key_Delete));
|
|
m_gui->treeView->addAction(m_removeAction);
|
|
connect(m_removeAction, &QAction::triggered, this, &SliceFavoritesWidget::RemoveSelection);
|
|
|
|
connect(m_dataModel, &FavoriteDataModel::DataModelChanged, this, &SliceFavoritesWidget::UpdateWidget);
|
|
connect(m_dataModel, &FavoriteDataModel::ExpandIndex, m_gui->treeView, &QTreeView::setExpanded);
|
|
connect(m_dataModel, &FavoriteDataModel::DisplayWarning, this, [this](const QString& title, const QString& message)
|
|
{
|
|
QMessageBox::warning(this, title, message);
|
|
});
|
|
|
|
connect(m_gui->emptyLabel, &QLabel::customContextMenuRequested, this, &SliceFavoritesWidget::OnOpenTreeContextMenu);
|
|
|
|
UpdateWidget();
|
|
}
|
|
|
|
SliceFavoritesWidget::~SliceFavoritesWidget()
|
|
{
|
|
}
|
|
|
|
void SliceFavoritesWidget::UpdateWidget()
|
|
{
|
|
bool modelHasFavoritesOrFolders = m_dataModel->HasFavoritesOrFolders();
|
|
|
|
m_gui->emptyLabel->setText(modelHasFavoritesOrFolders ? "" : "Right click to add folders or use the Asset Browser to add slices as favorites");
|
|
m_gui->emptyLabel->setVisible(!modelHasFavoritesOrFolders);
|
|
}
|
|
|
|
void SliceFavoritesWidget::RemoveSelection()
|
|
{
|
|
const QItemSelection& currentSelection = m_gui->treeView->selectionModel()->selection();
|
|
|
|
if (currentSelection.indexes().size() > 0)
|
|
{
|
|
int numFoldersToRemove = 0;
|
|
int numFavoritesToRemove = 0;
|
|
|
|
m_dataModel->CountFoldersAndFavoritesFromIndices(currentSelection.indexes(), numFoldersToRemove, numFavoritesToRemove);
|
|
|
|
QString outputString = QStringLiteral("Are you sure you want to remove the following?\n%1 folders\n%2 favorites").arg(numFoldersToRemove).arg(numFavoritesToRemove);
|
|
|
|
QMessageBox msgBox(this);
|
|
msgBox.setText(tr("Confirm removal"));
|
|
msgBox.setInformativeText(outputString);
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
msgBox.setIcon(QMessageBox::NoIcon);
|
|
int result = msgBox.exec();
|
|
|
|
if (result == QMessageBox::Ok)
|
|
{
|
|
// Only delete the highest-level items from the current selection
|
|
// Their children will be automatically removed
|
|
AZStd::vector<QModelIndex> toDelete;
|
|
for (const auto& selectedIndex : currentSelection.indexes())
|
|
{
|
|
bool child = false;
|
|
for (const auto& potentialAncestor : currentSelection.indexes())
|
|
{
|
|
if (m_dataModel->IsDescendentOf(selectedIndex, potentialAncestor))
|
|
{
|
|
child = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!child)
|
|
{
|
|
toDelete.push_back(selectedIndex);
|
|
}
|
|
}
|
|
|
|
for (const auto& selectedIndex : toDelete)
|
|
{
|
|
if (selectedIndex.isValid())
|
|
{
|
|
m_dataModel->RemoveFavorite(selectedIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void SliceFavoritesWidget::AddNewFolder(const QModelIndex& currentIndex)
|
|
{
|
|
QModelIndex newFolderIndex = m_dataModel->AddNewFolder(currentIndex);
|
|
|
|
// Select the new folder and start editing it by default
|
|
m_gui->treeView->selectionModel()->select(newFolderIndex, QItemSelectionModel::ClearAndSelect);
|
|
m_gui->treeView->selectionModel()->setCurrentIndex(newFolderIndex, QItemSelectionModel::ClearAndSelect);
|
|
|
|
m_gui->treeView->edit(newFolderIndex);
|
|
}
|
|
|
|
void SliceFavoritesWidget::OnOpenTreeContextMenu(const QPoint& pos)
|
|
{
|
|
const QItemSelection& currentSelection = m_gui->treeView->selectionModel()->selection();
|
|
|
|
QMenu* contextMenu = new QMenu(m_gui->treeView);
|
|
contextMenu->setToolTipsVisible(true);
|
|
|
|
QModelIndex firstSelection = currentSelection.indexes().size() > 0 ? currentSelection.indexes().first() : QModelIndex();
|
|
|
|
QAction* renameAction = contextMenu->addAction("Rename", contextMenu, [this, &firstSelection]()
|
|
{
|
|
m_gui->treeView->edit(firstSelection);
|
|
});
|
|
renameAction->setEnabled(currentSelection.indexes().size() == 1);
|
|
renameAction->setToolTip(tr("Rename the favorite or folder, not the slice itself"));
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
QAction* folderAction = contextMenu->addAction("Add folder", contextMenu, [this, &firstSelection]()
|
|
{
|
|
AddNewFolder(firstSelection);
|
|
});
|
|
folderAction->setEnabled(CanAddNewFolder(currentSelection));
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
QAction* removeAction = contextMenu->addAction("Remove selected", contextMenu, [this]()
|
|
{
|
|
RemoveSelection();
|
|
});
|
|
removeAction->setEnabled(currentSelection.indexes().size() > 0);
|
|
|
|
int numFavoritesAndFolders = m_dataModel->GetNumFavoritesAndFolders();
|
|
|
|
QAction* clearAction = contextMenu->addAction("Remove all", contextMenu, [this]()
|
|
{
|
|
QMessageBox msgBox(this);
|
|
msgBox.setText(tr("Confirm removal"));
|
|
msgBox.setInformativeText(tr("Remove all favorites?"));
|
|
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
|
|
msgBox.setDefaultButton(QMessageBox::Cancel);
|
|
msgBox.setIcon(QMessageBox::NoIcon);
|
|
int result = msgBox.exec();
|
|
|
|
if (result == QMessageBox::Ok)
|
|
{
|
|
m_dataModel->ClearAll();
|
|
}
|
|
|
|
|
|
});
|
|
clearAction->setEnabled(numFavoritesAndFolders > 0);
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction("Import slice...", contextMenu, [this]()
|
|
{
|
|
AssetSelectionModel selection = AssetSelectionModel::AssetTypeSelection("Slice");
|
|
AzToolsFramework::EditorRequests::Bus::Broadcast(&AzToolsFramework::EditorRequests::BrowseForAssets, selection);
|
|
if (selection.IsValid())
|
|
{
|
|
auto product = azrtti_cast<const ProductAssetBrowserEntry*>(selection.GetResult());
|
|
if (product)
|
|
{
|
|
m_dataModel->AddFavorite(product);
|
|
}
|
|
}
|
|
});
|
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction("Import slice favorites...", contextMenu, [this]()
|
|
{
|
|
QString fileName = QFileDialog::getOpenFileName(this, "Import Favorites From...", QString(), tr("XML (*.xml)"), nullptr, QFileDialog::DontUseNativeDialog);
|
|
if (fileName.length() > 0)
|
|
{
|
|
int numImported = m_dataModel->ImportFavorites(fileName);
|
|
QString outputString = QStringLiteral("%1 favorites and folders successfully imported.").arg(numImported);
|
|
QMessageBox::information(this, "Import successful!", outputString);
|
|
}
|
|
});
|
|
|
|
QAction* exportAction = contextMenu->addAction("Export slice favorites...", contextMenu, [this]()
|
|
{
|
|
QString fileName = QFileDialog::getSaveFileName(nullptr, QString("Export Favorites To..."), "SliceFavorites.xml", QString("XML (*.xml)"));
|
|
if (fileName.length() > 0)
|
|
{
|
|
int numExported = m_dataModel->ExportFavorites(fileName);
|
|
QString outputString = QStringLiteral("%1 favorites and folders successfully exported.").arg(numExported);
|
|
QMessageBox::information(this, "Export successful!", outputString);
|
|
}
|
|
});
|
|
exportAction->setEnabled(numFavoritesAndFolders > 0);
|
|
|
|
contextMenu->exec(m_gui->treeView->mapToGlobal(pos));
|
|
delete contextMenu;
|
|
}
|
|
|
|
bool SliceFavoritesWidget::CanAddNewFolder(const QItemSelection& selected)
|
|
{
|
|
// We can add a folder if we have exactly one or fewer selected items
|
|
// we check item type later for appropriate types
|
|
bool allowAddFolder = (selected.size() <= 1);
|
|
|
|
for (const auto& selectedIndex : selected.indexes())
|
|
{
|
|
FavoriteData* favoriteData = m_dataModel->GetFavoriteDataFromModelIndex(selectedIndex);
|
|
if (favoriteData)
|
|
{
|
|
// We can only add folders to other folders, not to favorites themselves
|
|
allowAddFolder &= (favoriteData->m_type == FavoriteData::DataType_Folder);
|
|
}
|
|
}
|
|
|
|
return allowAddFolder;
|
|
}
|
|
}
|
|
#include <Source/moc_SliceFavoritesWidget.cpp>
|