QtEditorApplication.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #pragma once
  9. #if !defined(Q_MOC_RUN)
  10. #include <QAbstractNativeEventFilter>
  11. #include <QColor>
  12. #include <QMap>
  13. #include <QTranslator>
  14. #include <QSet>
  15. #include <unordered_map>
  16. #include <AzCore/PlatformDef.h>
  17. #include <AzCore/UserSettings/UserSettingsProvider.h>
  18. #include <IEditor.h>
  19. #include <AzQtComponents/Application/AzQtApplication.h>
  20. #endif
  21. class QFileInfo;
  22. typedef QList<QFileInfo> QFileInfoList;
  23. class QByteArray;
  24. namespace AzQtComponents
  25. {
  26. class O3DEStylesheet;
  27. }
  28. enum EEditorNotifyEvent;
  29. // This contains the main "QApplication"-derived class for the editor itself.
  30. // it performs the message hooking and other functions to allow CryEdit to function.
  31. namespace Editor
  32. {
  33. typedef void(* ScanDirectoriesUpdateCallBack)(void);
  34. /*!
  35. \param directoryList A list of directories to search. ScanDirectories will also search the subdirectories of each of these.
  36. \param filters A list of filename filters. Supports * and ? wildcards. The filters will not apply to the directory names.
  37. \param files Any file that is found and matches any of the filters will be added to files.
  38. \param updateCallback An optional callback function that will be called once for every directory and subdirectory that is scanned.
  39. */
  40. void ScanDirectories(QFileInfoList& directoryList, const QStringList& filters, QFileInfoList& files, ScanDirectoriesUpdateCallBack updateCallback = nullptr);
  41. class EditorQtApplication
  42. : public AzQtComponents::AzQtApplication
  43. , public QAbstractNativeEventFilter
  44. , public IEditorNotifyListener
  45. , public AZ::UserSettingsOwnerRequestBus::Handler
  46. {
  47. Q_OBJECT
  48. Q_PROPERTY(QSet<int> pressedKeys READ pressedKeys)
  49. Q_PROPERTY(int pressedMouseButtons READ pressedMouseButtons)
  50. public:
  51. // Call this before creating this object:
  52. static void InstallQtLogHandler();
  53. EditorQtApplication(int& argc, char** argv);
  54. virtual ~EditorQtApplication();
  55. void Initialize();
  56. void LoadSettings();
  57. void UnloadSettings();
  58. // AZ::UserSettingsOwnerRequestBus::Handler
  59. void SaveSettings() override;
  60. ////
  61. static EditorQtApplication* instance();
  62. static EditorQtApplication* newInstance(int& argc, char** argv);
  63. static bool IsActive();
  64. bool isMovingOrResizing() const;
  65. // IEditorNotifyListener:
  66. void OnEditorNotifyEvent(EEditorNotifyEvent event) override;
  67. const QColor& GetColorByName(const QString& colorName);
  68. void EnableOnIdle(bool enable = true);
  69. bool OnIdleEnabled() const;
  70. bool eventFilter(QObject* object, QEvent* event) override;
  71. QSet<int> pressedKeys() const { return m_pressedKeys; }
  72. int pressedMouseButtons() const { return m_pressedButtons; }
  73. public Q_SLOTS:
  74. void setIsMovingOrResizing(bool isMovingOrResizing);
  75. signals:
  76. void skinChanged();
  77. protected:
  78. bool m_isMovingOrResizing = false;
  79. private:
  80. static QColor InterpolateColors(QColor a, QColor b, float factor);
  81. void RefreshStyleSheet();
  82. void InstallFilters();
  83. void UninstallFilters();
  84. void maybeProcessIdle();
  85. AzQtComponents::O3DEStylesheet* m_stylesheet;
  86. // Translators
  87. void InstallEditorTranslators();
  88. void UninstallEditorTranslators();
  89. QTranslator* CreateAndInitializeTranslator(const QString& filename, const QString& directory);
  90. void DeleteTranslator(QTranslator*& translator);
  91. QTranslator* m_editorTranslator = nullptr;
  92. QTranslator* m_assetBrowserTranslator = nullptr;
  93. AZ::UserSettingsProvider m_localUserSettings;
  94. Qt::MouseButtons m_pressedButtons = Qt::NoButton;
  95. QSet<int> m_pressedKeys;
  96. bool m_activatedLocalUserSettings = false;
  97. bool m_applicationActive = false;
  98. };
  99. } // namespace editor