TexturePreviewWidget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 <QWidget>
  11. #include <AzCore/Memory/SystemAllocator.h>
  12. #include <Editor/EditorCommon.h>
  13. #include <Editor/ImagePopup.h>
  14. #include <QEvent>
  15. #include <QTimer>
  16. #include <Processing/ImagePreview.h>
  17. #endif
  18. namespace Ui
  19. {
  20. class TexturePreviewWidget;
  21. }
  22. namespace ImageProcessingAtomEditor
  23. {
  24. enum PreviewMode
  25. {
  26. RGB = 0,
  27. RRR,
  28. GGG,
  29. BBB,
  30. Alpha,
  31. RGBA,
  32. Count
  33. };
  34. enum class RefreshMode
  35. {
  36. Convert, // Convert the whole image from beginning, takes longest time
  37. Mip, // Generate a new mip from from converted image
  38. Channel, // Generate a new channel image from converted image
  39. Repaint,
  40. };
  41. class TexturePreviewWidget
  42. : public QWidget
  43. , protected EditorInternalNotificationBus::Handler
  44. {
  45. Q_OBJECT
  46. public:
  47. AZ_CLASS_ALLOCATOR(TexturePreviewWidget, AZ::SystemAllocator);
  48. explicit TexturePreviewWidget(EditorTextureSetting& texureSetting, QWidget* parent = 0);
  49. ~TexturePreviewWidget();
  50. bool OnQtEvent(QEvent* event);
  51. public slots:
  52. void OnTiledChanged(bool checked);
  53. void OnPrevMip();
  54. void OnNextMip();
  55. void OnChangePreviewMode(int index);
  56. void UpdatePreview();
  57. void OnAlwaysRefresh();
  58. void OnRefreshPerClick();
  59. void OnRefreshClicked();
  60. protected:
  61. ////////////////////////////////////////////////////////////////////////
  62. //EditorInternalNotificationBus
  63. void OnEditorSettingsChanged(bool needRefresh, const AZStd::string& platform) override;
  64. ////////////////////////////////////////////////////////////////////////
  65. void resizeEvent(QResizeEvent* event) override;
  66. bool eventFilter(QObject* obj, QEvent* event) override;
  67. private:
  68. void SetUpResolutionInfo();
  69. void RefreshUI(bool fullRefresh = false);
  70. void RefreshPreviewImage(RefreshMode mode);
  71. void GenerateMipmap(int mip);
  72. void GenerateChannelImage(PreviewMode channel);
  73. void PaintPreviewImage();
  74. void SetImageLabelText(const QString& text, bool busyStatus = true);
  75. void RefreshWarning();
  76. AZStd::list<ResolutionInfo> m_resolutionInfos;
  77. QScopedPointer<Ui::TexturePreviewWidget> m_ui;
  78. EditorTextureSetting* m_textureSetting;
  79. int m_currentMipIndex = 0;
  80. bool m_previewTiled = false;
  81. float m_imageLabelSize = 0;
  82. AZStd::string m_platform;
  83. unsigned int m_mipCount = 1;
  84. ///////////////////////////////////////////
  85. // Preview window
  86. PreviewMode m_previewMode = PreviewMode::RGB;
  87. QScopedPointer<ImagePopup> m_previewPopup;
  88. AZStd::unique_ptr<ImageProcessingAtom::ImagePreview> m_previewConverter;
  89. ImageProcessingAtom::IImageObjectPtr m_previewImageRaw;
  90. QImage m_previewImages[PreviewMode::Count];
  91. QTimer* m_updateTimer;
  92. static const int s_updateInterval = 200;
  93. ////////////////////////////////////////////
  94. ////////////////////////////////////////////
  95. // Refresh button
  96. bool m_alwaysRefreshPreview = true;
  97. QAction* m_alwaysRefreshAction = nullptr;
  98. QAction* m_refreshPerClickAction = nullptr;
  99. QIcon m_refreshPerClickIcon;
  100. QIcon m_alwaysRefreshIcon;
  101. ////////////////////////////////////////////
  102. };
  103. } //namespace ImageProcessingAtomEditor