Dekko
Loading...
Searching...
No Matches
MessageField.qml
1/* Copyright (C) 2016 - 2017 Dan Chapman <dpniel@ubuntu.com>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18import QtQuick 2.4
19import Lomiri.Components 1.3
20import Lomiri.Components.Themes.Ambiance 1.3
21import Dekko.Mail.API 1.0
22import Dekko.Mail.Stores.Composer 1.0
23import Dekko.Lomiri.Constants 1.0
25FocusScope {
26 id: root
27 property alias placeholderText: textArea.placeholderText
28 property alias text: textArea.text
29 property alias textDocument: textArea.textDocument
30 property alias __textArea: textArea
31
32 signal keyEventOccurred()
33 signal cursorPositionChanged()
34
35 function getCursorPosition() {
36 return textArea.positionToRectangle(textArea.cursorPosition)
37 }
38 height: textArea.height
39 anchors {
40// top: parent.top
41 left: parent.left
42 right: parent.right
43 leftMargin: Style.smallSpacing
44 rightMargin: Style.smallSpacing
45 }
46
47 TextArea {
48 id: textArea
49 anchors {
50 left: parent.left
51 top: parent.top
52 topMargin: Style.smallSpacing
53 right: parent.right
54 }
55 autoSize: true
56 maximumLineCount: 0
57 style: TextAreaStyle {
58 overlaySpacing: Style.smallSpacing
59 frameSpacing: Style.smallSpacing
60 background: Item{}
61 }
62 onCursorPositionChanged: root.cursorPositionChanged()
63 Keys.onReleased: keyEventOccurred()
64 onActiveFocusChanged: {
65 if (activeFocus) {
66 delayPositioning.start()
67 } else {
68 delayPositioning.stop()
69 }
70 }
71 }
72
73 Binding {
74 target: ComposerStore
75 property: "bodyDocument"
76 value: textArea.textDocument
77 }
78
79 // This timer is used to position the view after
80 // active focus has been gained so that the cursor doesn't get stuck down behind the keyboard
81 Timer {
82 id: delayPositioning
83 interval: 750
84 repeat: false
85 onTriggered: {
86 Log.logInfo("MessageField::delayPositioningTimer", "Repositiong view")
87 if (!QuickUtils.mouseAttached && !Qt.inputMethod.visible) {
88 // Hmm keyboards not up yet. Try again....
89 Log.logInfo("MessageField::delayPositioningTimer", "Keyboards not visible yet")
90 delayPositioning.start()
91 } else {
92 Log.logInfo("MessageField::delayPositioningTimer", "Ok let's position view")
93 root.keyEventOccurred()
94 }
95 }
96 }
97}
98