aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols/material/impl/qquickmaterialplaceholdertext_p.h
blob: bf851d367a538bf11c814cd732716168f929bf42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QQUICKMATERIALPLACEHOLDERTEXT_P_H
#define QQUICKMATERIALPLACEHOLDERTEXT_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <QtCore/private/qglobal_p.h>
#include <QtGui/qcolor.h>
#include <QtQuickControls2Impl/private/qquickplaceholdertext_p.h>

#include <QtCore/qpointer.h>

QT_BEGIN_NAMESPACE

class QParallelAnimationGroup;

class QQuickMaterialPlaceholderText : public QQuickPlaceholderText
{
    Q_OBJECT
    Q_PROPERTY(bool filled READ isFilled WRITE setFilled NOTIFY filledChanged FINAL)
    Q_PROPERTY(bool controlHasActiveFocus READ controlHasActiveFocus
        WRITE setControlHasActiveFocus NOTIFY controlHasActiveFocusChanged FINAL)
    Q_PROPERTY(bool controlHasText READ controlHasText WRITE setControlHasText NOTIFY controlHasTextChanged FINAL)
    Q_PROPERTY(int largestHeight READ largestHeight NOTIFY largestHeightChanged FINAL)
    Q_PROPERTY(qreal verticalPadding READ verticalPadding WRITE setVerticalPadding NOTIFY verticalPaddingChanged FINAL)
    Q_PROPERTY(qreal controlImplicitBackgroundHeight READ controlImplicitBackgroundHeight
        WRITE setControlImplicitBackgroundHeight NOTIFY controlImplicitBackgroundHeightChanged FINAL)
    Q_PROPERTY(qreal controlHeight READ controlHeight WRITE setControlHeight FINAL)
    QML_NAMED_ELEMENT(FloatingPlaceholderText)
    QML_ADDED_IN_VERSION(6, 5)

public:
    explicit QQuickMaterialPlaceholderText(QQuickItem *parent = nullptr);

    bool isFilled() const;
    void setFilled(bool filled);

    int largestHeight() const;

    bool controlHasActiveFocus() const;
    void setControlHasActiveFocus(bool controlHasActiveFocus);

    bool controlHasText() const;
    void setControlHasText(bool controlHasText);

    qreal controlImplicitBackgroundHeight() const;
    void setControlImplicitBackgroundHeight(qreal controlImplicitBackgroundHeight);

    qreal controlHeight() const;
    void setControlHeight(qreal controlHeight);

    qreal verticalPadding() const;
    void setVerticalPadding(qreal verticalPadding);

signals:
    void filledChanged();
    void largestHeightChanged();
    void controlHasActiveFocusChanged();
    void controlHasTextChanged();
    void controlImplicitBackgroundHeightChanged();
    void verticalPaddingChanged();

private slots:
    void adjustTransformOrigin();

private:
    bool shouldFloat() const;
    bool shouldAnimate() const;

    void updateY();
    qreal normalTargetY() const;
    qreal floatingTargetY() const;

    void controlGotActiveFocus();
    void controlLostActiveFocus();

    void maybeSetFocusAnimationProgress();

    void componentComplete() override;

    bool m_filled = false;
    bool m_controlHasActiveFocus = false;
    bool m_controlHasText = false;
    int m_largestHeight = 0;
    qreal m_verticalPadding = 0;
    qreal m_controlImplicitBackgroundHeight = 0;
    qreal m_controlHeight = 0;
    QPointer<QParallelAnimationGroup> m_focusInAnimation;
    QPointer<QParallelAnimationGroup> m_focusOutAnimation;
};

QT_END_NAMESPACE

#endif // QQUICKMATERIALPLACEHOLDERTEXT_P_H