LayoutConfigDialog.cpp 2.9 KB

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