-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatInput.qml
More file actions
215 lines (178 loc) · 6.69 KB
/
ChatInput.qml
File metadata and controls
215 lines (178 loc) · 6.69 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import qmlcomponents
FocusScope {
id: root
implicitWidth: 200
implicitHeight: chatInputLayout.height
property alias showSpeechVolumeButton: speechVolumeButton.visible
property QtObject chatController: null
property var chatChannelModel: null
property bool writeToLocalChat: false
property alias keepChatInputFocus: chatInputLayout.keepChatInputFocus
property alias currentChatInput: chatInput.text
property alias currentSpeechVolume: speechVolumeButton.speechVolume
property alias currentSpeechVolumeButtonState: speechVolumeButton.state
property alias currentChatInputSelectedText: chatInput.selectedText
function selectAll() {
chatInput.selectAll();
} //function selectAll
function deselect() {
chatInput.deselect();
} //function deselect
RowLayout {
id: chatInputLayout
anchors.left: parent.left
anchors.right: parent.right
spacing: TibiaStyle.chatGuiMargins
TibiaButton {
id: speechVolumeButton
Layout.preferredHeight: chatInput.height
Layout.preferredWidth: height
imageSource: "/images/icon-speech-say.png"
tooltipText: qsTrId("chat_adjust_speech_volume_tooltip")
hide: !writeToLocalChat
onHideChanged: { state = ""; }
property int speechVolume: 0
onClicked: {
if (state == "") {
state = "YELL_MODE";
} else if (state == "YELL_MODE") {
state = "WHISPER_MODE";
} else if (state == "WHISPER_MODE") {
state = "";
}
} //onClicked
state: ""
states: [
State {
name: "YELL_MODE"
PropertyChanges {
target: speechVolumeButton
imageSource: "/images/icon-speech-yell.png"
speechVolume: +1
} //PropertyChanges
}, //State "YELL_MODE"
State {
name: "WHISPER_MODE"
PropertyChanges {
target: speechVolumeButton
imageSource: "/images/icon-speech-whisper.png"
speechVolume: -1
} //PropertyChanges
} //State "WHISPER_MODE"
] //states
} //TibiaButton
TibiaTextField {
id: chatInput
Layout.fillWidth: true
maximumLength: TibiaStyle.chatInputMaxLength
color: writeToLocalChat ? TibiaStyle.textColors["Default"] : TibiaStyle.chatInputSpecialChannelColor
placeholderText: qsTrId("chat_placeholder_text")
KeyNavigation.tab: chatInput
Keys.onUpPressed: (event) => {
if(chatController && (event.modifiers & Qt.ShiftModifier)) {
chatInput.text = chatController.getOlderChatInputHistoryEntry();
return;
}
event.accepted = false;
} //Keys.onUpPressed
Keys.onDownPressed: (event) => {
if(chatController && (event.modifiers & Qt.ShiftModifier)) {
var historyEntry = chatController.getNewerChatInputHistoryEntry();
if(historyEntry.length == 0) {
chatController.addEntryToChatInputHistory(chatInput.text); //empty strings are not stored by the history
}
chatInput.text = historyEntry;
return;
}
event.accepted = false;
} //Keys.onUpPressed
Keys.onLeftPressed: (event) => {
if(event.modifiers == Qt.ShiftModifier) {
cursorPosition = Math.min(cursorPosition, selectionStart);
cursorPosition = Math.max(0, cursorPosition -1);
}
} //Keys.onLeftPressed
Keys.onRightPressed: (event) => {
if(event.modifiers == Qt.ShiftModifier) {
cursorPosition = Math.max(cursorPosition, selectionEnd);
cursorPosition = Math.min(length, cursorPosition +1);
}
} //Keys.onLeftPressed
onSelectedTextChanged: {
if((selectedText.length > 0) && (chatChannelModel != null)) {
//deselct chat channel selection
chatChannelModel.startNewSelection(0, 0);
}
} //onSelectedTextChanged
property bool keepChatInputFocusForModeOn: chatInputLayout.keepChatInputFocus
&& chatInputLayout.chatMode != 0 //check tibia::chat::EChatMode::CHAT_OFF
focus: true
Component.onCompleted: resetActiveFocusToTextFieldAsync()
onActiveFocusChanged: resetActiveFocusToTextFieldAsync()
onKeepChatInputFocusForModeOnChanged: resetActiveFocusToTextFieldAsync()
function resetActiveFocusToTextFieldAsync() {
Qt.callLater(function() {
chatInput.refreshActiveFocus();
});
} //function resetActiveFocusToTextFieldAsync
function refreshActiveFocus() {
if(!activeFocus && keepChatInputFocusForModeOn) {
chatInput.forceActiveFocus();
}
} //function refreshActiveFocus
MouseArea {
anchors.fill: parent
enabled: !chatInput.keepChatInputFocusForModeOn
onClicked: (mouse) => {
if (chatController) {
mouse.accepted = false;
chatController.onChatInputClicked();
}
} //onClicked
} //MouseArea
} //TibiaTextField
TibiaButton {
id: chatEnabledButton
Layout.preferredHeight: TibiaStyle.textFieldHeight
Layout.preferredWidth: TibiaStyle.buttonWidthBroad
function getButtonText() {
if (chatInputLayout.chatMode == 1) { //check tibia::chat::EChatMode::CHAT_ON
return qsTrId("chat_mode_on");
} else if (chatInputLayout.chatMode == 2) { //check tibia::chat::EchatMode::CHAT_TEMPORARY_ON
return qsTrId("chat_mode_temporary_on");
}
return qsTrId("chat_mode_off");
} //function getButtonText()
text: getButtonText()
tooltipText: qsTrId("chat_mode_button_tooltip")
onClicked: {
if (chatController) {
chatController.onChatModeButtonClicked();
}
} //onClicked
} //TibiaIconButton
//for values see tibia::chat::EChatMode
property int chatMode: chatController != null ? chatController.chatMode : 0
property bool keepChatInputFocus: true
KeyNavigation.tab: chatInputLayout
property bool keepChatInputFocusForModeOff: chatInputLayout.keepChatInputFocus
&& chatInputLayout.chatMode == 0 //check tibia::chat::EChatMode::CHAT_OFF
focus: true
Component.onCompleted: refreshActiveFocusModeOffAsync()
onActiveFocusChanged: refreshActiveFocusModeOffAsync()
onKeepChatInputFocusForModeOffChanged: refreshActiveFocusModeOffAsync()
function refreshActiveFocus() {
if(!activeFocus && keepChatInputFocusForModeOff) {
forceActiveFocus();
}
} //function refreshActiveFocus()
function refreshActiveFocusModeOffAsync() {
Qt.callLater(function() {
chatInputLayout.refreshActiveFocus();
});
}
} //RowLayout
} //FocusScope