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/private/qglobal_p.h> |
19 | #include <QtGui/qcolor.h> |
20 | #include <QtQuick/qquickpainteditem.h> |
21 | |
22 | QT_BEGIN_NAMESPACE |
23 | |
24 | class QQuickMaterialTextContainer : public QQuickPaintedItem |
25 | { |
26 | Q_OBJECT |
27 | Q_PROPERTY(bool filled READ isFilled WRITE setFilled FINAL) |
28 | Q_PROPERTY(bool controlHasActiveFocus READ controlHasActiveFocus |
29 | WRITE setControlHasActiveFocus NOTIFY controlHasActiveFocusChanged FINAL) |
30 | Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor FINAL) |
31 | Q_PROPERTY(QColor outlineColor READ outlineColor WRITE setOutlineColor FINAL) |
32 | Q_PROPERTY(QColor focusedOutlineColor READ focusedOutlineColor WRITE setFocusedOutlineColor FINAL) |
33 | Q_PROPERTY(qreal focusAnimationProgress READ focusAnimationProgress WRITE setFocusAnimationProgress FINAL) |
34 | Q_PROPERTY(qreal placeholderTextWidth READ placeholderTextWidth WRITE setPlaceholderTextWidth FINAL) |
35 | Q_PROPERTY(PlaceHolderHAlignment placeholderTextHAlign READ placeholderTextHAlign WRITE setPlaceholderTextHAlign FINAL) |
36 | Q_PROPERTY(bool controlHasText READ controlHasText WRITE setControlHasText NOTIFY controlHasTextChanged FINAL) |
37 | Q_PROPERTY(bool placeholderHasText READ placeholderHasText WRITE setPlaceholderHasText NOTIFY placeholderHasTextChanged FINAL) |
38 | Q_PROPERTY(int horizontalPadding READ horizontalPadding WRITE setHorizontalPadding NOTIFY horizontalPaddingChanged FINAL) |
39 | QML_NAMED_ELEMENT(MaterialTextContainer) |
40 | QML_ADDED_IN_VERSION(6, 5) |
41 | |
42 | public: |
43 | explicit QQuickMaterialTextContainer(QQuickItem *parent = nullptr); |
44 | |
45 | enum PlaceHolderHAlignment { |
46 | AlignLeft = Qt::AlignLeft, |
47 | AlignRight = Qt::AlignRight, |
48 | AlignHCenter = Qt::AlignHCenter, |
49 | AlignJustify = Qt::AlignJustify |
50 | }; |
51 | Q_ENUM(PlaceHolderHAlignment) |
52 | |
53 | bool isFilled() const; |
54 | void setFilled(bool filled); |
55 | |
56 | QColor fillColor() const; |
57 | void setFillColor(const QColor &fillColor); |
58 | |
59 | QColor outlineColor() const; |
60 | void setOutlineColor(const QColor &outlineColor); |
61 | |
62 | QColor focusedOutlineColor() const; |
63 | void setFocusedOutlineColor(const QColor &focusedOutlineColor); |
64 | |
65 | qreal focusAnimationProgress() const; |
66 | void setFocusAnimationProgress(qreal progress); |
67 | |
68 | qreal placeholderTextWidth() const; |
69 | void setPlaceholderTextWidth(qreal placeholderTextWidth); |
70 | |
71 | bool controlHasActiveFocus() const; |
72 | void setControlHasActiveFocus(bool controlHasActiveFocus); |
73 | |
74 | bool controlHasText() const; |
75 | void setControlHasText(bool controlHasText); |
76 | |
77 | bool placeholderHasText() const; |
78 | void setPlaceholderHasText(bool placeholderHasText); |
79 | |
80 | int horizontalPadding() const; |
81 | void setHorizontalPadding(int horizontalPadding); |
82 | |
83 | void paint(QPainter *painter) override; |
84 | |
85 | PlaceHolderHAlignment placeholderTextHAlign() const; |
86 | void setPlaceholderTextHAlign(PlaceHolderHAlignment placeHolderTextHAlign); |
87 | |
88 | signals: |
89 | void animateChanged(); |
90 | void controlHasActiveFocusChanged(); |
91 | void controlHasTextChanged(); |
92 | void placeholderHasTextChanged(); |
93 | void horizontalPaddingChanged(); |
94 | |
95 | private: |
96 | bool shouldAnimateOutline() const; |
97 | |
98 | QQuickItem *textControl() const; |
99 | void controlGotActiveFocus(); |
100 | void controlLostActiveFocus(); |
101 | void startFocusAnimation(); |
102 | |
103 | void maybeSetFocusAnimationProgress(); |
104 | |
105 | void componentComplete() override; |
106 | |
107 | QColor m_fillColor; |
108 | QColor m_outlineColor; |
109 | QColor m_focusedOutlineColor; |
110 | qreal m_focusAnimationProgress = 0; |
111 | qreal m_placeholderTextWidth = 0; |
112 | bool m_filled = false; |
113 | bool m_controlHasActiveFocus = false; |
114 | bool m_controlHasText = false; |
115 | bool m_placeholderHasText = false; |
116 | int m_horizontalPadding = 0; |
117 | PlaceHolderHAlignment m_placeholderTextHAlign; |
118 | }; |
119 | |
120 | QT_END_NAMESPACE |
121 | |
122 | #endif // QQUICKMATERIALTEXTCONTAINER_P_H |
123 | |