/
NeoChapay
/
telegraf
Обзор
Документация
Войти
/
NeoChapay
/
telegraf
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
qml/components/VoiceNoteOverlay.qml
203 строки
7 KB
mbarashkov
Поправил локализацию после вывода в компоненты
10 ноя 2024, 16:31
10 ноя 2024, 16:31
dcfd389
Код
Авторство
О чём код?
import QtQuick 2.6 import Sailfish.Silica 1.0 import ru.telegrafaurora.telegraf 1.0 import "../components" import "../js/twemoji.js" as Emoji import "../js/debug.js" as Debug Item { anchors.fill: parent property var attachmentOptionsFlickableIsNeeded; property int recordingState: telegrafUtils.getVoiceNoteRecordingState(); property int recordingDuration: 0; property bool recordingDone: false; property var voiceNoteOverlayLoaderActive; property var attachmentPreviewRow; function handleRecordingState() { switch (recordingState) { case TelegrafUtilities.Unavailable: recordingStateLabel.text = qsTr("Unavailable"); break; case TelegrafUtilities.Ready: recordingStateLabel.text = qsTr("Ready"); break; case TelegrafUtilities.Starting: recordingStateLabel.text = qsTr("Starting"); break; case TelegrafUtilities.Recording: recordingStateLabel.text = qsTr("Recording"); break; case TelegrafUtilities.Stopping: recordingStateLabel.text = qsTr("Stopping"); break; } } function getTwoDigitString(numberToBeConverted) { var numberString = "00"; if (numberToBeConverted > 0 && numberToBeConverted < 10) { numberString = "0" + String(numberToBeConverted); } if (numberToBeConverted >= 10) { numberString = String(numberToBeConverted); } return numberString; } function handleRecordingDuration() { var minutes = Math.floor(recordingDuration / 60); var seconds = recordingDuration % 60; recordingDurationLabel.text = getTwoDigitString(minutes) + ":" + getTwoDigitString(seconds); } Component.onCompleted: { handleRecordingState(); handleRecordingDuration(); } Connections { target: telegrafUtils onVoiceNoteDurationChanged: { Debug.log("New duration received: " + duration); recordingDuration = Math.round(duration / 1000); handleRecordingDuration(); } onVoiceNoteRecordingStateChanged: { Debug.log("New state received: " + state); recordingState = state; handleRecordingState(); } } Rectangle { id: stickerPickerOverlayBackground anchors.fill: parent color: Theme.overlayBackgroundColor opacity: Theme.opacityHigh } Flickable { id: voiceNoteFlickable anchors.fill: parent anchors.margins: Theme.paddingMedium Behavior on opacity { NumberAnimation {} } contentHeight: voiceNoteColumn.height clip: true Column { id: voiceNoteColumn spacing: Theme.paddingMedium width: voiceNoteFlickable.width InfoLabel { text: qsTr("Record a Voice Note") } Label { wrapMode: Text.Wrap width: parent.width - ( 2 * Theme.horizontalPageMargin ) horizontalAlignment: Text.AlignHCenter text: qsTr("Press the button to start recording") font.pixelSize: Theme.fontSizeMedium anchors { horizontalCenter: parent.horizontalCenter } } Item { width: Theme.iconSizeExtraLarge height: Theme.iconSizeExtraLarge anchors { horizontalCenter: parent.horizontalCenter } Rectangle { color: Theme.primaryColor opacity: Theme.opacityOverlay width: Theme.iconSizeExtraLarge height: Theme.iconSizeExtraLarge anchors.centerIn: parent radius: width / 2 } Rectangle { id: recordButton color: "red" width: Theme.iconSizeExtraLarge * 0.6 height: Theme.iconSizeExtraLarge * 0.6 anchors.centerIn: parent radius: width / 2 MouseArea { anchors.fill: parent onClicked: { recordButton.visible = false; recordingDone = false; recordingDuration = 0; handleRecordingDuration(); telegrafUtils.startRecordingVoiceNote(); } } } Rectangle { id: stopButton visible: !recordButton.visible color: Theme.overlayBackgroundColor width: Theme.iconSizeExtraLarge * 0.4 height: Theme.iconSizeExtraLarge * 0.4 anchors.centerIn: parent MouseArea { anchors.fill: parent onClicked: { recordButton.visible = true; telegrafUtils.stopRecordingVoiceNote(); recordingDone = true; } } } } Label { id: recordingStateLabel wrapMode: Text.Wrap width: parent.width - ( 2 * Theme.horizontalPageMargin ) horizontalAlignment: Text.AlignHCenter font.pixelSize: Theme.fontSizeMedium anchors { horizontalCenter: parent.horizontalCenter } } Label { id: recordingDurationLabel wrapMode: Text.Wrap width: parent.width - ( 2 * Theme.horizontalPageMargin ) horizontalAlignment: Text.AlignHCenter font.pixelSize: Theme.fontSizeMedium anchors { horizontalCenter: parent.horizontalCenter } } Button { visible: recordingDone anchors { horizontalCenter: parent.horizontalCenter } text: qsTr("Use recording") onClicked: { attachmentOptionsFlickableIsNeeded = false; attachmentPreviewRow.isVoiceNote = true; attachmentPreviewRow.attachmentDescription = qsTr("Voice Note (%1)").arg(recordingDurationLabel.text); controlSendButton(); voiceNoteOverlayLoaderActive = false; } } } } }