MysticQtManager.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 required files
  9. #include "MysticQtManager.h"
  10. #include <MCore/Source/StringConversions.h>
  11. #include <QtGui/QIcon>
  12. #include <QDir>
  13. namespace MysticQt
  14. {
  15. // the global MysticQt manager
  16. MysticQtManager* gMysticQtManager = nullptr;
  17. //--------------------------------------------------
  18. // constructor
  19. MysticQtManager::MysticQtManager()
  20. {
  21. m_mainWindow = nullptr;
  22. }
  23. // destructor
  24. MysticQtManager::~MysticQtManager()
  25. {
  26. // get the number of icons and destroy them
  27. for (IconData* icon : m_icons)
  28. {
  29. delete icon;
  30. }
  31. m_icons.clear();
  32. }
  33. // constructor
  34. MysticQtManager::IconData::IconData(const char* filename)
  35. {
  36. m_fileName = filename;
  37. m_icon = new QIcon(QDir{ QString(GetMysticQt()->GetDataDir().c_str()) }.filePath(filename));
  38. }
  39. // destructor
  40. MysticQtManager::IconData::~IconData()
  41. {
  42. delete m_icon;
  43. }
  44. const QIcon& MysticQtManager::FindIcon(const char* filename)
  45. {
  46. // get the number of icons and iterate through them
  47. for (IconData* icon : m_icons)
  48. {
  49. if (AzFramework::StringFunc::Equal(icon->m_fileName.c_str(), filename, false /* no case */))
  50. {
  51. return *(icon->m_icon);
  52. }
  53. }
  54. // we haven't found it
  55. IconData* iconData = new IconData(filename);
  56. m_icons.emplace_back(iconData);
  57. return *(iconData->m_icon);
  58. }
  59. //--------------------------------------------------
  60. // initialize the MysticQt manager
  61. bool Initializer::Init(const char* appDir, const char* dataDir)
  62. {
  63. // create the gMCore object
  64. if (gMysticQtManager)
  65. {
  66. return true;
  67. }
  68. gMysticQtManager = new MysticQtManager();
  69. gMysticQtManager->SetAppDir(appDir);
  70. gMysticQtManager->SetDataDir(dataDir);
  71. return true;
  72. }
  73. // shutdown the MysticQt manager
  74. void Initializer::Shutdown()
  75. {
  76. // delete the manager
  77. delete gMysticQtManager;
  78. gMysticQtManager = nullptr;
  79. }
  80. } // namespace MysticQt