FormLineEditWidget.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #endif
  12. QT_FORWARD_DECLARE_CLASS(QLineEdit)
  13. QT_FORWARD_DECLARE_CLASS(QLabel)
  14. QT_FORWARD_DECLARE_CLASS(QFrame)
  15. QT_FORWARD_DECLARE_CLASS(QMovie)
  16. QT_FORWARD_DECLARE_CLASS(QHBoxLayout)
  17. QT_FORWARD_DECLARE_CLASS(QVBoxLayout)
  18. QT_FORWARD_DECLARE_CLASS(QMouseEvent)
  19. namespace AzQtComponents
  20. {
  21. class StyledLineEdit;
  22. }
  23. namespace O3DE::ProjectManager
  24. {
  25. class FormLineEditWidget
  26. : public QWidget
  27. {
  28. Q_OBJECT
  29. public:
  30. enum class ValidationState
  31. {
  32. NotValidating,
  33. Validating,
  34. ValidationFailed,
  35. ValidationSuccess
  36. };
  37. FormLineEditWidget(
  38. const QString& labelText,
  39. const QString& valueText,
  40. const QString& placeholderText,
  41. const QString& errorText,
  42. QWidget* parent = nullptr);
  43. explicit FormLineEditWidget(const QString& labelText, const QString& valueText = "", QWidget* parent = nullptr);
  44. ~FormLineEditWidget() = default;
  45. //! Set the error message for to display when invalid.
  46. void setErrorLabelText(const QString& labelText);
  47. void setErrorLabelVisible(bool visible);
  48. //! Returns a pointer to the underlying LineEdit.
  49. QLineEdit* lineEdit() const;
  50. virtual void setText(const QString& text);
  51. void SetValidationState(ValidationState validationState);
  52. protected:
  53. QLabel* m_errorLabel = nullptr;
  54. QFrame* m_frame = nullptr;
  55. QHBoxLayout* m_frameLayout = nullptr;
  56. AzQtComponents::StyledLineEdit* m_lineEdit = nullptr;
  57. QVBoxLayout* m_mainLayout = nullptr;
  58. //Validation icons
  59. QMovie* m_processingSpinnerMovie = nullptr;
  60. QLabel* m_processingSpinner = nullptr;
  61. QLabel* m_validationErrorIcon = nullptr;
  62. QLabel* m_validationSuccessIcon = nullptr;
  63. ValidationState m_validationState = ValidationState::NotValidating;
  64. void refreshStyle();
  65. private slots:
  66. void flavorChanged();
  67. void onFocus();
  68. void onFocusOut();
  69. private:
  70. void mousePressEvent(QMouseEvent* event) override;
  71. };
  72. } // namespace O3DE::ProjectManager