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
22QT_BEGIN_NAMESPACE
23
24class 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(bool controlHasText READ controlHasText WRITE setControlHasText NOTIFY controlHasTextChanged FINAL)
36 Q_PROPERTY(bool placeholderHasText READ placeholderHasText WRITE setPlaceholderHasText NOTIFY placeholderHasTextChanged FINAL)
37 Q_PROPERTY(int horizontalPadding READ horizontalPadding WRITE setHorizontalPadding NOTIFY horizontalPaddingChanged FINAL)
38 QML_NAMED_ELEMENT(MaterialTextContainer)
39 QML_ADDED_IN_VERSION(6, 5)
40
41public:
42 explicit QQuickMaterialTextContainer(QQuickItem *parent = nullptr);
43
44 bool isFilled() const;
45 void setFilled(bool filled);
46
47 QColor fillColor() const;
48 void setFillColor(const QColor &fillColor);
49
50 QColor outlineColor() const;
51 void setOutlineColor(const QColor &outlineColor);
52
53 QColor focusedOutlineColor() const;
54 void setFocusedOutlineColor(const QColor &focusedOutlineColor);
55
56 qreal focusAnimationProgress() const;
57 void setFocusAnimationProgress(qreal progress);
58
59 qreal placeholderTextWidth() const;
60 void setPlaceholderTextWidth(qreal placeholderTextWidth);
61
62 bool controlHasActiveFocus() const;
63 void setControlHasActiveFocus(bool controlHasActiveFocus);
64
65 bool controlHasText() const;
66 void setControlHasText(bool controlHasText);
67
68 bool placeholderHasText() const;
69 void setPlaceholderHasText(bool placeholderHasText);
70
71 int horizontalPadding() const;
72 void setHorizontalPadding(int horizontalPadding);
73
74 void paint(QPainter *painter) override;
75
76signals:
77 void animateChanged();
78 void controlHasActiveFocusChanged();
79 void controlHasTextChanged();
80 void placeholderHasTextChanged();
81 void horizontalPaddingChanged();
82
83private:
84 bool shouldAnimateOutline() const;
85
86 QQuickItem *textControl() const;
87 void controlGotActiveFocus();
88 void controlLostActiveFocus();
89 void startFocusAnimation();
90
91 void maybeSetFocusAnimationProgress();
92
93 void componentComplete() override;
94
95 QColor m_fillColor;
96 QColor m_outlineColor;
97 QColor m_focusedOutlineColor;
98 qreal m_focusAnimationProgress = 0;
99 qreal m_placeholderTextWidth = 0;
100 bool m_filled = false;
101 bool m_controlHasActiveFocus = false;
102 bool m_controlHasText = false;
103 bool m_placeholderHasText = false;
104 int m_horizontalPadding = 0;
105};
106
107QT_END_NAMESPACE
108
109#endif // QQUICKMATERIALTEXTCONTAINER_P_H
110

source code of qtdeclarative/src/quickcontrols/material/impl/qquickmaterialtextcontainer_p.h