SharedPreviewer.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 <AzCore/IO/FileIO.h>
  9. #include <AzToolsFramework/API/EditorAssetSystemAPI.h>
  10. #include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
  11. #include <AzToolsFramework/AssetBrowser/AssetBrowserEntry.h>
  12. #include <AzToolsFramework/Thumbnails/Thumbnail.h>
  13. #include <SharedPreview/SharedPreviewUtils.h>
  14. #include <SharedPreview/SharedPreviewer.h>
  15. // Disables warning messages triggered by the Qt library
  16. // 4251: class needs to have dll-interface to be used by clients of class
  17. // 4800: forcing value to bool 'true' or 'false' (performance warning)
  18. AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option")
  19. #include <QResizeEvent>
  20. #include <QString>
  21. #include <SharedPreview/ui_SharedPreviewer.h>
  22. AZ_POP_DISABLE_WARNING
  23. namespace AZ
  24. {
  25. namespace LyIntegration
  26. {
  27. static constexpr int CharWidth = 6;
  28. SharedPreviewer::SharedPreviewer(QWidget* parent)
  29. : Previewer(parent)
  30. , m_ui(new Ui::SharedPreviewerClass())
  31. {
  32. m_ui->setupUi(this);
  33. }
  34. SharedPreviewer::~SharedPreviewer()
  35. {
  36. }
  37. void SharedPreviewer::Clear() const
  38. {
  39. }
  40. void SharedPreviewer::Display(const AzToolsFramework::AssetBrowser::AssetBrowserEntry* entry)
  41. {
  42. m_ui->m_previewWidget->SetThumbnailKey(entry->GetThumbnailKey());
  43. m_fileInfo = QString::fromUtf8(entry->GetName().c_str());
  44. UpdateFileInfo();
  45. }
  46. const QString& SharedPreviewer::GetName() const
  47. {
  48. return m_name;
  49. }
  50. void SharedPreviewer::resizeEvent([[maybe_unused]] QResizeEvent* event)
  51. {
  52. m_ui->m_previewWidget->setMaximumHeight(m_ui->m_previewWidget->width());
  53. UpdateFileInfo();
  54. }
  55. void SharedPreviewer::UpdateFileInfo() const
  56. {
  57. m_ui->m_fileInfoLabel->setText(SharedPreviewUtils::WordWrap(m_fileInfo, m_ui->m_fileInfoLabel->width() / CharWidth));
  58. }
  59. } // namespace LyIntegration
  60. } // namespace AZ
  61. #include <SharedPreview/moc_SharedPreviewer.cpp>