LayoutConfigDialog.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 "EditorDefs.h"
  9. #include "LayoutConfigDialog.h"
  10. // AzQtComponents
  11. #include <AzQtComponents/Components/StyleManager.h>
  12. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  13. #include <ui_LayoutConfigDialog.h>
  14. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  15. class LayoutConfigModel
  16. : public QAbstractListModel
  17. {
  18. public:
  19. LayoutConfigModel(QObject* parent = nullptr);
  20. int rowCount(const QModelIndex& parent = {}) const override;
  21. int columnCount(const QModelIndex& parent = {}) const override;
  22. QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
  23. private:
  24. static const int kNumLayouts = 9;
  25. };
  26. LayoutConfigModel::LayoutConfigModel(QObject* parent)
  27. : QAbstractListModel(parent)
  28. {
  29. }
  30. int LayoutConfigModel::rowCount(const QModelIndex& parent) const
  31. {
  32. return parent.isValid() ? 0 : kNumLayouts;
  33. }
  34. int LayoutConfigModel::columnCount(const QModelIndex& parent) const
  35. {
  36. return parent.isValid() ? 0 : 1;
  37. }
  38. QVariant LayoutConfigModel::data(const QModelIndex& index, int role) const
  39. {
  40. if (!index.isValid() || index.column() > 0 || index.row() >= kNumLayouts)
  41. {
  42. return {};
  43. }
  44. switch (role)
  45. {
  46. case Qt::SizeHintRole:
  47. return QSize(38, 38);
  48. case Qt::DecorationRole:
  49. return QPixmap(QStringLiteral(":/layouts/layouts-%1.svg").arg(index.row()));
  50. }
  51. return {};
  52. }
  53. // CLayoutConfigDialog dialog
  54. CLayoutConfigDialog::CLayoutConfigDialog(QWidget* pParent /*=nullptr*/)
  55. : QDialog(pParent)
  56. , m_model(new LayoutConfigModel(this))
  57. , ui(new Ui::CLayoutConfigDialog)
  58. {
  59. m_layout = ET_Layout1;
  60. ui->setupUi(this);
  61. setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
  62. setFixedSize(size());
  63. ui->m_layouts->setModel(m_model);
  64. AzQtComponents::StyleManager::setStyleSheet(ui->m_layouts, "style:LayoutConfigDialog.qss");
  65. connect(ui->m_buttonBox, &QDialogButtonBox::accepted, this, &CLayoutConfigDialog::OnOK);
  66. connect(ui->m_buttonBox, &QDialogButtonBox::rejected, this, &CLayoutConfigDialog::reject);
  67. }
  68. CLayoutConfigDialog::~CLayoutConfigDialog()
  69. {
  70. }
  71. void CLayoutConfigDialog::SetLayout(EViewLayout layout)
  72. {
  73. m_layout = layout;
  74. ui->m_layouts->setCurrentIndex(m_model->index(static_cast<int>(layout), 0));
  75. }
  76. // CLayoutConfigDialog message handlers
  77. //////////////////////////////////////////////////////////////////////////
  78. void CLayoutConfigDialog::OnOK()
  79. {
  80. auto index = ui->m_layouts->currentIndex();
  81. auto oldLayout = m_layout;
  82. if (index.isValid())
  83. {
  84. m_layout = static_cast<EViewLayout>(index.row());
  85. }
  86. // If the layout has not been changed, the calling code
  87. // is not supposed to do anything. So let's simply reject in that case.
  88. done(m_layout == oldLayout ? QDialog::Rejected : QDialog::Accepted);
  89. }
  90. #include <moc_LayoutConfigDialog.cpp>