PropertyGenericCtrl.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 "PropertyGenericCtrl.h"
  10. // Qt
  11. #include <QMessageBox>
  12. #include <QHBoxLayout>
  13. #include <QtWidgets/QLabel>
  14. #include <QLineEdit>
  15. #include <QStringListModel>
  16. #include <QToolButton>
  17. // CryCommon
  18. #include <CryCommon/ILocalizationManager.h>
  19. // Editor
  20. #include "SelectLightAnimationDialog.h"
  21. #include "SelectSequenceDialog.h"
  22. #include "QtViewPaneManager.h"
  23. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  24. #include <QtWidgets/QListView>
  25. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  26. GenericPopupPropertyEditor::GenericPopupPropertyEditor(QWidget *pParent, bool showTwoButtons)
  27. :QWidget(pParent)
  28. {
  29. m_valueLabel = new QLabel;
  30. QToolButton *mainButton = new QToolButton;
  31. mainButton->setAutoRaise(true);
  32. mainButton->setIcon(QIcon(QStringLiteral(":/stylesheet/img/UI20/browse-edit.svg")));
  33. connect(mainButton, &QToolButton::clicked, this, &GenericPopupPropertyEditor::onEditClicked);
  34. QHBoxLayout *mainLayout = new QHBoxLayout(this);
  35. mainLayout->addWidget(m_valueLabel, 1);
  36. mainLayout->addWidget(mainButton);
  37. mainLayout->setContentsMargins(0, 0, 0, 0);
  38. if (showTwoButtons)
  39. {
  40. QToolButton *button2 = new QToolButton;
  41. button2->setAutoRaise(true);
  42. button2->setIcon(QIcon(QStringLiteral(":/stylesheet/img/UI20/more.svg")));
  43. connect(button2, &QToolButton::clicked, this, &GenericPopupPropertyEditor::onButton2Clicked);
  44. mainLayout->insertWidget(1, button2);
  45. }
  46. }
  47. void GenericPopupPropertyEditor::SetValue(const QString &value, bool notify)
  48. {
  49. if (m_value != value)
  50. {
  51. m_value = value;
  52. m_valueLabel->setText(m_value);
  53. if (notify)
  54. emit ValueChanged(m_value);
  55. }
  56. }
  57. void GenericPopupPropertyEditor::SetPropertyType(PropertyType type)
  58. {
  59. m_propertyType = type;
  60. }
  61. void SequencePropertyEditor::onEditClicked()
  62. {
  63. CSelectSequenceDialog gtDlg(this);
  64. gtDlg.PreSelectItem(GetValue());
  65. if (gtDlg.exec() == QDialog::Accepted)
  66. SetValue(gtDlg.GetSelectedItem());
  67. }
  68. void SequenceIdPropertyEditor::onEditClicked()
  69. {
  70. CSelectSequenceDialog gtDlg;
  71. uint32 id = GetValue().toUInt();
  72. IAnimSequence *pSeq = GetIEditor()->GetMovieSystem()->FindSequenceById(id);
  73. if (pSeq)
  74. gtDlg.PreSelectItem(pSeq->GetName());
  75. if (gtDlg.exec() == QDialog::Accepted)
  76. {
  77. pSeq = GetIEditor()->GetMovieSystem()->FindLegacySequenceByName(gtDlg.GetSelectedItem().toUtf8().data());
  78. assert(pSeq);
  79. if (pSeq->GetId() > 0)
  80. {
  81. // This sequence is a new one with a valid ID.
  82. SetValue(QString::number(pSeq->GetId()));
  83. }
  84. else
  85. {
  86. // This sequence is an old one without an ID.
  87. QMessageBox::warning(this, tr("Old Sequence"), tr("This is an old sequence without an ID.\nSo it cannot be used with the new ID-based linking."));
  88. }
  89. }
  90. }
  91. void LocalStringPropertyEditor::onEditClicked()
  92. {
  93. std::vector<IVariable::IGetCustomItems::SItem> items;
  94. ILocalizationManager* pMgr = gEnv->pSystem->GetLocalizationManager();
  95. if (!pMgr)
  96. return;
  97. int nCount = pMgr->GetLocalizedStringCount();
  98. if (nCount <= 0)
  99. return;
  100. items.reserve(nCount);
  101. IVariable::IGetCustomItems::SItem item;
  102. SLocalizedInfoEditor sInfo;
  103. for (int i = 0; i < nCount; ++i)
  104. {
  105. if (pMgr->GetLocalizedInfoByIndex(i, sInfo))
  106. {
  107. item.desc = tr("English Text:\r\n");
  108. AZStd::wstring utf8TranslatedTextW;
  109. AZStd::to_wstring(utf8TranslatedTextW, sInfo.sUtf8TranslatedText);
  110. item.desc += QString::fromWCharArray(utf8TranslatedTextW.c_str());
  111. item.name = sInfo.sKey;
  112. items.push_back(item);
  113. }
  114. }
  115. CGenericSelectItemDialog gtDlg;
  116. const bool bUseTree = true;
  117. if (bUseTree)
  118. {
  119. gtDlg.SetMode(CGenericSelectItemDialog::eMODE_TREE);
  120. gtDlg.SetTreeSeparator("/");
  121. }
  122. gtDlg.SetItems(items);
  123. gtDlg.setWindowTitle(tr("Choose Localized String"));
  124. QString preselect = GetValue();
  125. if (!preselect.isEmpty() && preselect.at(0) == '@')
  126. preselect = preselect.mid(1);
  127. gtDlg.PreSelectItem(preselect);
  128. if (gtDlg.exec() == QDialog::Accepted)
  129. {
  130. preselect = "@";
  131. preselect += gtDlg.GetSelectedItem();
  132. SetValue(preselect);
  133. }
  134. }
  135. void LightAnimationPropertyEditor::onEditClicked()
  136. {
  137. // First, check if there is any light animation defined.
  138. bool bLightAnimationExists = false;
  139. IMovieSystem *pMovieSystem = GetIEditor()->GetMovieSystem();
  140. for (int i = 0; i < pMovieSystem->GetNumSequences(); ++i)
  141. {
  142. IAnimSequence *pSequence = pMovieSystem->GetSequence(i);
  143. if (pSequence->GetFlags() & IAnimSequence::eSeqFlags_LightAnimationSet)
  144. {
  145. bLightAnimationExists = pSequence->GetNodeCount() > 0;
  146. break;
  147. }
  148. }
  149. if (bLightAnimationExists) // If exists, show the selection dialog.
  150. {
  151. CSelectLightAnimationDialog dlg;
  152. dlg.PreSelectItem(GetValue());
  153. if (dlg.exec() == QDialog::Accepted)
  154. SetValue(dlg.GetSelectedItem());
  155. }
  156. else // If not, remind the user of creating one in TrackView.
  157. {
  158. QMessageBox::warning(this, tr("No Available Animation"), tr("There is no available light animation.\nPlease create one in TrackView, first."));
  159. }
  160. }
  161. ListEditWidget::ListEditWidget(QWidget *pParent /*= nullptr*/)
  162. :QWidget(pParent)
  163. {
  164. m_valueEdit = new QLineEdit;
  165. m_model = new QStringListModel(this);
  166. m_listView = new QListView;
  167. m_listView->setModel(m_model);
  168. m_listView->setMaximumHeight(50);
  169. m_listView->setVisible(false);
  170. QToolButton *expandButton = new QToolButton();
  171. expandButton->setCheckable(true);
  172. expandButton->setText("+");
  173. QToolButton *editButton = new QToolButton();
  174. editButton->setText("..");
  175. connect(editButton, &QAbstractButton::clicked, this, &ListEditWidget::OnEditClicked);
  176. connect(expandButton, &QAbstractButton::toggled, m_listView, &QWidget::setVisible);
  177. connect(m_model, &QAbstractItemModel::dataChanged, this, &ListEditWidget::OnModelDataChange);
  178. connect(m_valueEdit, &QLineEdit::editingFinished, this, [this](){SetValue(m_valueEdit->text(), true); } );
  179. QVBoxLayout *mainLayout = new QVBoxLayout(this);
  180. QHBoxLayout *topLayout = new QHBoxLayout;
  181. topLayout->addWidget(expandButton);
  182. topLayout->addWidget(m_valueEdit,1);
  183. topLayout->addWidget(editButton);
  184. mainLayout->addLayout(topLayout);
  185. mainLayout->addWidget(m_listView,1);
  186. mainLayout->setContentsMargins(1,1,1,1);
  187. }
  188. void ListEditWidget::SetValue(const QString &value, bool notify /*= true*/)
  189. {
  190. if (m_value != value)
  191. {
  192. m_value = value;
  193. m_valueEdit->setText(value);
  194. QStringList list = m_value.split(",", Qt::SkipEmptyParts);
  195. m_model->setStringList(list);
  196. if (notify)
  197. emit ValueChanged(m_value);
  198. }
  199. }
  200. void ListEditWidget::OnModelDataChange()
  201. {
  202. m_value = m_model->stringList().join(",");
  203. m_valueEdit->setText(m_value);
  204. emit ValueChanged(m_value);
  205. }
  206. QWidget* ListEditWidget::GetFirstInTabOrder()
  207. {
  208. return m_valueEdit;
  209. }
  210. QWidget* ListEditWidget::GetLastInTabOrder()
  211. {
  212. return m_listView;
  213. }
  214. #include <Controls/ReflectedPropertyControl/moc_PropertyGenericCtrl.cpp>