| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKMATERIALTEXTCONTAINER_P_H |
| 5 | #define QQUICKMATERIALTEXTCONTAINER_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qpointer.h> |
| 19 | #include <QtCore/qpropertyanimation.h> |
| 20 | #include <QtCore/private/qglobal_p.h> |
| 21 | #include <QtGui/qcolor.h> |
| 22 | #include <QtQuick/qquickpainteditem.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuickMaterialTextContainer : public QQuickPaintedItem |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | Q_PROPERTY(bool filled READ isFilled WRITE setFilled FINAL) |
| 30 | Q_PROPERTY(bool controlHasActiveFocus READ controlHasActiveFocus |
| 31 | WRITE setControlHasActiveFocus NOTIFY controlHasActiveFocusChanged FINAL) |
| 32 | Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor FINAL) |
| 33 | Q_PROPERTY(QColor outlineColor READ outlineColor WRITE setOutlineColor FINAL) |
| 34 | Q_PROPERTY(QColor focusedOutlineColor READ focusedOutlineColor WRITE setFocusedOutlineColor FINAL) |
| 35 | Q_PROPERTY(qreal focusAnimationProgress READ focusAnimationProgress WRITE setFocusAnimationProgress FINAL) |
| 36 | Q_PROPERTY(qreal placeholderTextWidth READ placeholderTextWidth WRITE setPlaceholderTextWidth FINAL) |
| 37 | Q_PROPERTY(PlaceHolderHAlignment placeholderTextHAlign READ placeholderTextHAlign WRITE setPlaceholderTextHAlign FINAL) |
| 38 | Q_PROPERTY(bool controlHasText READ controlHasText WRITE setControlHasText NOTIFY controlHasTextChanged FINAL) |
| 39 | Q_PROPERTY(bool placeholderHasText READ placeholderHasText WRITE setPlaceholderHasText NOTIFY placeholderHasTextChanged FINAL) |
| 40 | Q_PROPERTY(int horizontalPadding READ horizontalPadding WRITE setHorizontalPadding NOTIFY horizontalPaddingChanged FINAL) |
| 41 | QML_NAMED_ELEMENT(MaterialTextContainer) |
| 42 | QML_ADDED_IN_VERSION(6, 5) |
| 43 | |
| 44 | public: |
| 45 | explicit QQuickMaterialTextContainer(QQuickItem *parent = nullptr); |
| 46 | |
| 47 | enum PlaceHolderHAlignment { |
| 48 | AlignLeft = Qt::AlignLeft, |
| 49 | AlignRight = Qt::AlignRight, |
| 50 | AlignHCenter = Qt::AlignHCenter, |
| 51 | AlignJustify = Qt::AlignJustify |
| 52 | }; |
| 53 | Q_ENUM(PlaceHolderHAlignment) |
| 54 | |
| 55 | bool isFilled() const; |
| 56 | void setFilled(bool filled); |
| 57 | |
| 58 | QColor fillColor() const; |
| 59 | void setFillColor(const QColor &fillColor); |
| 60 | |
| 61 | QColor outlineColor() const; |
| 62 | void setOutlineColor(const QColor &outlineColor); |
| 63 | |
| 64 | QColor focusedOutlineColor() const; |
| 65 | void setFocusedOutlineColor(const QColor &focusedOutlineColor); |
| 66 | |
| 67 | qreal focusAnimationProgress() const; |
| 68 | void setFocusAnimationProgress(qreal progress); |
| 69 | |
| 70 | qreal placeholderTextWidth() const; |
| 71 | void setPlaceholderTextWidth(qreal placeholderTextWidth); |
| 72 | |
| 73 | bool controlHasActiveFocus() const; |
| 74 | void setControlHasActiveFocus(bool controlHasActiveFocus); |
| 75 | |
| 76 | bool controlHasText() const; |
| 77 | void setControlHasText(bool controlHasText); |
| 78 | |
| 79 | bool placeholderHasText() const; |
| 80 | void setPlaceholderHasText(bool placeholderHasText); |
| 81 | |
| 82 | int horizontalPadding() const; |
| 83 | void setHorizontalPadding(int horizontalPadding); |
| 84 | |
| 85 | void paint(QPainter *painter) override; |
| 86 | |
| 87 | PlaceHolderHAlignment placeholderTextHAlign() const; |
| 88 | void setPlaceholderTextHAlign(PlaceHolderHAlignment placeHolderTextHAlign); |
| 89 | |
| 90 | signals: |
| 91 | void animateChanged(); |
| 92 | void controlHasActiveFocusChanged(); |
| 93 | void controlHasTextChanged(); |
| 94 | void placeholderHasTextChanged(); |
| 95 | void horizontalPaddingChanged(); |
| 96 | |
| 97 | private: |
| 98 | bool shouldAnimateOutline() const; |
| 99 | |
| 100 | QQuickItem *textControl() const; |
| 101 | void controlGotActiveFocus(); |
| 102 | void controlLostActiveFocus(); |
| 103 | |
| 104 | void updateFocusAnimation(bool createIfNeeded = false); |
| 105 | |
| 106 | void componentComplete() override; |
| 107 | |
| 108 | QColor m_fillColor; |
| 109 | QColor m_outlineColor; |
| 110 | QColor m_focusedOutlineColor; |
| 111 | qreal m_focusAnimationProgress = 0; |
| 112 | qreal m_placeholderTextWidth = 0; |
| 113 | bool m_filled = false; |
| 114 | bool m_controlHasActiveFocus = false; |
| 115 | bool m_controlHasText = false; |
| 116 | bool m_placeholderHasText = false; |
| 117 | int m_horizontalPadding = 0; |
| 118 | PlaceHolderHAlignment m_placeholderTextHAlign; |
| 119 | QPointer<QPropertyAnimation> m_focusAnimation; |
| 120 | }; |
| 121 | |
| 122 | QT_END_NAMESPACE |
| 123 | |
| 124 | #endif // QQUICKMATERIALTEXTCONTAINER_P_H |
| 125 |
