ProjectManagerWindow.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <ProjectManagerWindow.h>
  13. #include <ScreenFactory.h>
  14. #include <AzQtComponents/Components/StyleManager.h>
  15. #include <AzCore/IO/Path/Path.h>
  16. #include <QDir>
  17. #include <Source/ui_ProjectManagerWindow.h>
  18. namespace O3DE::ProjectManager
  19. {
  20. ProjectManagerWindow::ProjectManagerWindow(QWidget* parent, const AZ::IO::PathView& engineRootPath)
  21. : QMainWindow(parent)
  22. , m_ui(new Ui::ProjectManagerWindowClass())
  23. {
  24. m_ui->setupUi(this);
  25. m_pythonBindings = AZStd::make_unique<PythonBindings>(engineRootPath);
  26. ConnectSlotsAndSignals();
  27. QDir rootDir = QString::fromUtf8(engineRootPath.Native().data(), aznumeric_cast<int>(engineRootPath.Native().size()));
  28. const auto pathOnDisk = rootDir.absoluteFilePath("Code/Tools/ProjectManager/Resources");
  29. const auto qrcPath = QStringLiteral(":/ProjectManagerWindow");
  30. AzQtComponents::StyleManager::addSearchPaths("projectmanagerwindow", pathOnDisk, qrcPath, engineRootPath);
  31. AzQtComponents::StyleManager::setStyleSheet(this, QStringLiteral("projectlauncherwindow:ProjectManagerWindow.qss"));
  32. BuildScreens();
  33. ChangeToScreen(ProjectManagerScreen::FirstTimeUse);
  34. }
  35. ProjectManagerWindow::~ProjectManagerWindow()
  36. {
  37. m_pythonBindings.reset();
  38. }
  39. void ProjectManagerWindow::BuildScreens()
  40. {
  41. // Basically just iterate over the ProjectManagerScreen enum creating each screen
  42. // Could add some fancy to do this but there are few screens right now
  43. ResetScreen(ProjectManagerScreen::FirstTimeUse);
  44. ResetScreen(ProjectManagerScreen::NewProjectSettings);
  45. ResetScreen(ProjectManagerScreen::GemCatalog);
  46. ResetScreen(ProjectManagerScreen::ProjectsHome);
  47. ResetScreen(ProjectManagerScreen::ProjectSettings);
  48. ResetScreen(ProjectManagerScreen::EngineSettings);
  49. }
  50. QStackedWidget* ProjectManagerWindow::GetScreenStack()
  51. {
  52. return m_ui->stackedScreens;
  53. }
  54. void ProjectManagerWindow::ChangeToScreen(ProjectManagerScreen screen)
  55. {
  56. int index = aznumeric_cast<int, ProjectManagerScreen>(screen);
  57. m_ui->stackedScreens->setCurrentIndex(index);
  58. }
  59. void ProjectManagerWindow::ResetScreen(ProjectManagerScreen screen)
  60. {
  61. int index = aznumeric_cast<int, ProjectManagerScreen>(screen);
  62. // Fine the old screen if it exists and get rid of it so we can start fresh
  63. QWidget* oldScreen = m_ui->stackedScreens->widget(index);
  64. if (oldScreen)
  65. {
  66. m_ui->stackedScreens->removeWidget(oldScreen);
  67. oldScreen->deleteLater();
  68. }
  69. // Add new screen
  70. QWidget* newScreen = BuildScreen(this, screen);
  71. m_ui->stackedScreens->insertWidget(index, newScreen);
  72. }
  73. void ProjectManagerWindow::ConnectSlotsAndSignals()
  74. {
  75. QObject::connect(m_ui->projectsMenu, &QMenu::aboutToShow, this, &ProjectManagerWindow::HandleProjectsMenu);
  76. QObject::connect(m_ui->engineMenu, &QMenu::aboutToShow, this, &ProjectManagerWindow::HandleEngineMenu);
  77. }
  78. void ProjectManagerWindow::HandleProjectsMenu()
  79. {
  80. ChangeToScreen(ProjectManagerScreen::ProjectsHome);
  81. }
  82. void ProjectManagerWindow::HandleEngineMenu()
  83. {
  84. ChangeToScreen(ProjectManagerScreen::EngineSettings);
  85. }
  86. } // namespace O3DE::ProjectManager