diff --git a/Code/Tools/ProjectManager/Resources/ProjectManager.qss b/Code/Tools/ProjectManager/Resources/ProjectManager.qss index 957b2b4fa6..eeed316cbc 100644 --- a/Code/Tools/ProjectManager/Resources/ProjectManager.qss +++ b/Code/Tools/ProjectManager/Resources/ProjectManager.qss @@ -568,17 +568,20 @@ QProgressBar::chunk { font-size: 12px; } +#gemRepoNoReposLabel { + font-size: 16px; +} + #gemRepoHeaderRefreshButton { background-color: transparent; qproperty-flat: true; qproperty-iconSize: 14px; } -#gemRepoHeaderAddButton { +#gemRepoAddButton { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #888888, stop: 1.0 #555555); qproperty-flat: true; - margin-right:30px; min-width:120px; max-width:120px; min-height:24px; @@ -588,11 +591,11 @@ QProgressBar::chunk { font-size:12px; font-weight:600; } -#gemRepoHeaderAddButton:hover { +#gemRepoAddButton:hover { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #999999, stop: 1.0 #666666); } -#gemRepoHeaderAddButton:pressed { +#gemRepoAddButton:pressed { background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #555555, stop: 1.0 #777777); } @@ -610,6 +613,14 @@ QProgressBar::chunk { background: #444444; } +#gemRepoAddDialogInstructionTitleLabel { + font-size:14px; +} + +#addGemRepoDialog #formFrame { + margin-left:0px; +} + /************** Gem Repo Inspector **************/ #gemRepoInspectorNameLabel { diff --git a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.cpp b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.cpp new file mode 100644 index 0000000000..1839948e80 --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.cpp @@ -0,0 +1,65 @@ +/* + * 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 + +namespace O3DE::ProjectManager +{ + GemRepoAddDialog::GemRepoAddDialog(QWidget* parent) + : QDialog(parent) + { + setWindowTitle(tr("Add a User Repository")); + setModal(true); + setObjectName("addGemRepoDialog"); + + QVBoxLayout* vLayout = new QVBoxLayout(); + vLayout->setContentsMargins(30, 30, 25, 10); + vLayout->setSpacing(0); + setLayout(vLayout); + + QLabel* instructionTitleLabel = new QLabel(tr("Enter a valid path to add a new user repository")); + instructionTitleLabel->setObjectName("gemRepoAddDialogInstructionTitleLabel"); + instructionTitleLabel->setAlignment(Qt::AlignLeft); + vLayout->addWidget(instructionTitleLabel); + + vLayout->addSpacing(10); + + QLabel* instructionContextLabel = new QLabel(tr("The path can be a Repository URL or a Local Path in your directory.")); + instructionContextLabel->setAlignment(Qt::AlignLeft); + vLayout->addWidget(instructionContextLabel); + + m_repoPath = new FormLineEditWidget(tr("Repository Path"), "", this); + m_repoPath->setFixedWidth(600); + vLayout->addWidget(m_repoPath); + + vLayout->addSpacing(40); + + QDialogButtonBox* dialogButtons = new QDialogButtonBox(); + dialogButtons->setObjectName("footer"); + vLayout->addWidget(dialogButtons); + + QPushButton* cancelButton = dialogButtons->addButton(tr("Cancel"), QDialogButtonBox::RejectRole); + cancelButton->setProperty("secondary", true); + QPushButton* applyButton = dialogButtons->addButton(tr("Add"), QDialogButtonBox::ApplyRole); + + connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject); + connect(applyButton, &QPushButton::clicked, this, &QDialog::accept); + } + + QString GemRepoAddDialog::GetRepoPath() + { + return m_repoPath->lineEdit()->text(); + } +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.h b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.h new file mode 100644 index 0000000000..4ca469098e --- /dev/null +++ b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoAddDialog.h @@ -0,0 +1,31 @@ +/* + * 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 + * + */ + +#pragma once + +#if !defined(Q_MOC_RUN) +#include +#endif + +namespace O3DE::ProjectManager +{ + QT_FORWARD_DECLARE_CLASS(FormLineEditWidget) + + class GemRepoAddDialog + : public QDialog + { + public: + explicit GemRepoAddDialog(QWidget* parent = nullptr); + ~GemRepoAddDialog() = default; + + QString GetRepoPath(); + + private: + FormLineEditWidget* m_repoPath = nullptr; + }; +} // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.cpp b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.cpp index c0b17904f8..9c432884e6 100644 --- a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.cpp +++ b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -21,6 +22,8 @@ #include #include #include +#include +#include namespace O3DE::ProjectManager { @@ -34,11 +37,135 @@ namespace O3DE::ProjectManager vLayout->setSpacing(0); setLayout(vLayout); + m_contentStack = new QStackedWidget(this); + + m_noRepoContent = CreateNoReposContent(); + m_contentStack->addWidget(m_noRepoContent); + + m_repoContent = CreateReposContent(); + m_contentStack->addWidget(m_repoContent); + + vLayout->addWidget(m_contentStack); + + Reinit(); + } + + void GemRepoScreen::Reinit() + { + m_gemRepoModel->clear(); + FillModel(); + + // If model contains any data show the repos + if (m_gemRepoModel->rowCount()) + { + m_contentStack->setCurrentWidget(m_repoContent); + } + else + { + m_contentStack->setCurrentWidget(m_noRepoContent); + } + + // Select the first entry after everything got correctly sized + QTimer::singleShot(200, [=]{ + QModelIndex firstModelIndex = m_gemRepoListView->model()->index(0,0); + m_gemRepoListView->selectionModel()->select(firstModelIndex, QItemSelectionModel::ClearAndSelect); + }); + } + + void GemRepoScreen::HandleAddRepoButton() + { + GemRepoAddDialog* repoAddDialog = new GemRepoAddDialog(this); + + if (repoAddDialog->exec() == QDialog::DialogCode::Accepted) + { + QString repoUrl = repoAddDialog->GetRepoPath(); + if (repoUrl.isEmpty()) + { + return; + } + + AZ::Outcome addGemRepoResult = PythonBindingsInterface::Get()->AddGemRepo(repoUrl); + if (addGemRepoResult.IsSuccess()) + { + Reinit(); + } + else + { + QMessageBox::critical(this, tr("Operation failed"), + QString("Failed to add gem repo: %1.
Error:
%2").arg(repoUrl, addGemRepoResult.GetError().c_str())); + } + } + } + + void GemRepoScreen::FillModel() + { + AZ::Outcome, AZStd::string> allGemRepoInfosResult = PythonBindingsInterface::Get()->GetAllGemRepoInfos(); + if (allGemRepoInfosResult.IsSuccess()) + { + // Add all available repos to the model + const QVector allGemRepoInfos = allGemRepoInfosResult.GetValue(); + for (const GemRepoInfo& gemRepoInfo : allGemRepoInfos) + { + m_gemRepoModel->AddGemRepo(gemRepoInfo); + } + } + else + { + QMessageBox::critical(this, tr("Operation failed"), QString("Cannot retrieve gem repos for engine.
Error:
%2").arg(allGemRepoInfosResult.GetError().c_str())); + } + } + + QFrame* GemRepoScreen::CreateNoReposContent() + { + QFrame* contentFrame = new QFrame(this); + + QVBoxLayout* vLayout = new QVBoxLayout(); + vLayout->setAlignment(Qt::AlignHCenter); + vLayout->setMargin(0); + vLayout->setSpacing(0); + contentFrame->setLayout(vLayout); + + vLayout->addStretch(); + + QLabel* noRepoLabel = new QLabel(tr("No repositories have been added yet."), this); + noRepoLabel->setObjectName("gemRepoNoReposLabel"); + vLayout->addWidget(noRepoLabel); + vLayout->setAlignment(noRepoLabel, Qt::AlignHCenter); + + vLayout->addSpacing(20); + + // Size hint for button is wrong so horizontal layout with stretch is used to center it QHBoxLayout* hLayout = new QHBoxLayout(); hLayout->setMargin(0); hLayout->setSpacing(0); + + hLayout->addStretch(); + + QPushButton* addRepoButton = new QPushButton(tr("Add Repository"), this); + addRepoButton->setObjectName("gemRepoAddButton"); + addRepoButton->setMinimumWidth(120); + hLayout->addWidget(addRepoButton); + + connect(addRepoButton, &QPushButton::clicked, this, &GemRepoScreen::HandleAddRepoButton); + + hLayout->addStretch(); + vLayout->addLayout(hLayout); + vLayout->addStretch(); + + return contentFrame; + } + + QFrame* GemRepoScreen::CreateReposContent() + { + QFrame* contentFrame = new QFrame(this); + + QHBoxLayout* hLayout = new QHBoxLayout(); + hLayout->setMargin(0); + hLayout->setSpacing(0); + contentFrame->setLayout(hLayout); + hLayout->addSpacing(60); QVBoxLayout* middleVLayout = new QVBoxLayout(); @@ -63,9 +190,13 @@ namespace O3DE::ProjectManager topMiddleHLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum)); - m_AddRepoButton = new QPushButton(tr("Add Repository"), this); - m_AddRepoButton->setObjectName("gemRepoHeaderAddButton"); - topMiddleHLayout->addWidget(m_AddRepoButton); + QPushButton* addRepoButton = new QPushButton(tr("Add Repository"), this); + addRepoButton->setObjectName("gemRepoAddButton"); + topMiddleHLayout->addWidget(addRepoButton); + + connect(addRepoButton, &QPushButton::clicked, this, &GemRepoScreen::HandleAddRepoButton); + + topMiddleHLayout->addSpacing(30); middleVLayout->addLayout(topMiddleHLayout); @@ -105,37 +236,7 @@ namespace O3DE::ProjectManager m_gemRepoInspector->setFixedWidth(240); hLayout->addWidget(m_gemRepoInspector); - Reinit(); - } - - void GemRepoScreen::Reinit() - { - m_gemRepoModel->clear(); - FillModel(); - - // Select the first entry after everything got correctly sized - QTimer::singleShot(200, [=]{ - QModelIndex firstModelIndex = m_gemRepoListView->model()->index(0,0); - m_gemRepoListView->selectionModel()->select(firstModelIndex, QItemSelectionModel::ClearAndSelect); - }); - } - - void GemRepoScreen::FillModel() - { - AZ::Outcome, AZStd::string> allGemRepoInfosResult = PythonBindingsInterface::Get()->GetAllGemRepoInfos(); - if (allGemRepoInfosResult.IsSuccess()) - { - // Add all available repos to the model - const QVector allGemRepoInfos = allGemRepoInfosResult.GetValue(); - for (const GemRepoInfo& gemRepoInfo : allGemRepoInfos) - { - m_gemRepoModel->AddGemRepo(gemRepoInfo); - } - } - else - { - QMessageBox::critical(this, tr("Operation failed"), tr("Cannot retrieve gem repos for engine.\n\nError:\n%2").arg(allGemRepoInfosResult.GetError().c_str())); - } + return contentFrame; } ProjectManagerScreen GemRepoScreen::GetScreenEnum() diff --git a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.h b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.h index f7d943fc2a..284118b978 100644 --- a/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.h +++ b/Code/Tools/ProjectManager/Source/GemRepo/GemRepoScreen.h @@ -16,6 +16,8 @@ QT_FORWARD_DECLARE_CLASS(QLabel) QT_FORWARD_DECLARE_CLASS(QPushButton) QT_FORWARD_DECLARE_CLASS(QHeaderView) QT_FORWARD_DECLARE_CLASS(QTableWidget) +QT_FORWARD_DECLARE_CLASS(QFrame) +QT_FORWARD_DECLARE_CLASS(QStackedWidget) namespace O3DE::ProjectManager { @@ -35,8 +37,17 @@ namespace O3DE::ProjectManager GemRepoModel* GetGemRepoModel() const { return m_gemRepoModel; } + public slots: + void HandleAddRepoButton(); + private: void FillModel(); + QFrame* CreateNoReposContent(); + QFrame* CreateReposContent(); + + QStackedWidget* m_contentStack = nullptr; + QFrame* m_noRepoContent; + QFrame* m_repoContent; QTableWidget* m_gemRepoHeaderTable = nullptr; QHeaderView* m_gemRepoListHeader = nullptr; @@ -46,6 +57,5 @@ namespace O3DE::ProjectManager QLabel* m_lastAllUpdateLabel; QPushButton* m_AllUpdateButton; - QPushButton* m_AddRepoButton; }; } // namespace O3DE::ProjectManager diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.cpp b/Code/Tools/ProjectManager/Source/PythonBindings.cpp index 284ed9dcec..9ae3cc2c87 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.cpp +++ b/Code/Tools/ProjectManager/Source/PythonBindings.cpp @@ -921,6 +921,13 @@ namespace O3DE::ProjectManager } } + AZ::Outcome PythonBindings::AddGemRepo(const QString& repoUri) + { + // o3de scripts need method added + (void)repoUri; + return AZ::Failure("Adding Gem Repo not implemented yet in o3de scripts."); + } + GemRepoInfo PythonBindings::GemRepoInfoFromPath(pybind11::handle path, pybind11::handle pyEnginePath) { /* Placeholder Logic */ diff --git a/Code/Tools/ProjectManager/Source/PythonBindings.h b/Code/Tools/ProjectManager/Source/PythonBindings.h index 3b766c3797..42f04ed6e6 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindings.h +++ b/Code/Tools/ProjectManager/Source/PythonBindings.h @@ -57,6 +57,7 @@ namespace O3DE::ProjectManager AZ::Outcome> GetProjectTemplates(const QString& projectPath = {}) override; // Gem Repos + AZ::Outcome AddGemRepo(const QString& repoUri) override; AZ::Outcome, AZStd::string> GetAllGemRepoInfos() override; private: diff --git a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h index ccf217d25b..92139f3df5 100644 --- a/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h +++ b/Code/Tools/ProjectManager/Source/PythonBindingsInterface.h @@ -160,6 +160,13 @@ namespace O3DE::ProjectManager // Gem Repos + /** + * A gem repo to engine. Registers this gem repo with the current engine. + * @param repoUri the absolute filesystem path or url to the gem repo manifest file. + * @return An outcome with the success flag as well as an error message in case of a failure. + */ + virtual AZ::Outcome AddGemRepo(const QString& repoUri) = 0; + /** * Get all available gem repo infos. Gathers all repos registered with the engine. * @return A list of gem repo infos. diff --git a/Code/Tools/ProjectManager/project_manager_files.cmake b/Code/Tools/ProjectManager/project_manager_files.cmake index f71ae290e7..544fa2537b 100644 --- a/Code/Tools/ProjectManager/project_manager_files.cmake +++ b/Code/Tools/ProjectManager/project_manager_files.cmake @@ -104,6 +104,8 @@ set(FILES Source/GemCatalog/GemSortFilterProxyModel.cpp Source/GemRepo/GemRepoScreen.h Source/GemRepo/GemRepoScreen.cpp + Source/GemRepo/GemRepoAddDialog.h + Source/GemRepo/GemRepoAddDialog.cpp Source/GemRepo/GemRepoInfo.h Source/GemRepo/GemRepoInfo.cpp Source/GemRepo/GemRepoInspector.h