summaryrefslogtreecommitdiffstats
path: root/src/qmlandroid/widget/qqmlandroidtextview.cpp
blob: e3afaf37261a9f2615e0e15eba3ed2837715873c (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "qqmlandroidtextview_p.h"
#include "qtqmlandroidfunctions_p.h"
#include "qqmlandroidcolor_p.h"

QT_BEGIN_NAMESPACE

QQmlAndroidTextView::QQmlAndroidTextView(QQmlAndroidView *parent) :
    QQmlAndroidView(parent), m_singleLine(false)
{
}

QString QQmlAndroidTextView::text() const
{
    return m_text;
}

void QQmlAndroidTextView::setText(const QString &text)
{
    if (m_text != text) {
        m_text = text;
        QtQmlAndroid::callTextMethod(instance(), "setText", text);
        emit textChanged();
    }
}

int QQmlAndroidTextView::textColor() const
{
    if (m_textColor.isNull())
        return QQmlAndroidColor::BLACK; // TODO
    return m_textColor;
}

void QQmlAndroidTextView::setTextColor(int color)
{
    if (color != textColor()) {
        m_textColor = color;
        QtQmlAndroid::callIntMethod(instance(), "setTextColor", color);
        emit textColorChanged();
    }
}

qreal QQmlAndroidTextView::textSize() const
{
    if (m_textSize.isNull())
        return -1;
    return m_textSize;
}

void QQmlAndroidTextView::setTextSize(qreal size)
{
    if (size != textSize()) {
        m_textSize = size;
        QtQmlAndroid::callRealMethod(instance(), "setTextSize", size);
        emit textSizeChanged();
    }
}

QString QQmlAndroidTextView::hint() const
{
    return m_hint;
}

void QQmlAndroidTextView::setHint(const QString &hint)
{
    if (m_hint != hint) {
        m_hint = hint;
        QtQmlAndroid::callTextMethod(instance(), "setHint", hint);
        emit hintChanged();
    }
}

bool QQmlAndroidTextView::isSingleLine() const
{
    return m_singleLine;
}

void QQmlAndroidTextView::setSingleLine(bool singleLine)
{
    if (m_singleLine != singleLine) {
        m_singleLine = singleLine;
        QtQmlAndroid::callBoolMethod(instance(), "setSingleLine", singleLine);
        emit singleLineChanged();
    }
}

int QQmlAndroidTextView::inputType() const
{
    if (m_inputType.isNull())
        return 0; // TODO
    return m_inputType;
}

void QQmlAndroidTextView::setInputType(int type)
{
    if (m_inputType.isNull() || m_inputType != type) {
        m_inputType = type;
        QtQmlAndroid::callIntMethod(instance(), "setInputType", type);
        emit inputTypeChanged();
    }
}

QAndroidJniObject QQmlAndroidTextView::onCreate()
{
    return QAndroidJniObject("android/widget/TextView",
                             "(Landroid/content/Context;)V",
                             ctx().object());
}

void QQmlAndroidTextView::onInflate(QAndroidJniObject &instance)
{
    QQmlAndroidView::onInflate(instance);

    if (!m_text.isNull())
        instance.callMethod<void>("setText", "(Ljava/lang/CharSequence;)V", QAndroidJniObject::fromString(m_text).object());
    if (!m_textColor.isNull())
        instance.callMethod<void>("setTextColor", "(I)V", m_textColor);
    if (!m_textSize.isNull())
        instance.callMethod<void>("setTextSize", "(F)V", m_textSize);
    if (!m_hint.isNull())
        instance.callMethod<void>("setHint", "(Ljava/lang/CharSequence;)V", QAndroidJniObject::fromString(m_hint).object());
    if (m_singleLine)
        instance.callMethod<void>("setSingleLine");
    if (!m_inputType.isNull())
        instance.callMethod<void>("setInputType", "(I)V", m_inputType);
}

QT_END_NAMESPACE