/
erhoof
/
telegraf
Обзор
Документация
Войти
/
erhoof
/
telegraf
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
qml/components/VoiceNoteOverlay.qml
201 строка
6 KB
mbarashkov
Рефакторино части зависимостей qml
04 июн 2025, 13:53
04 июн 2025, 13:53
c8e186b
Код
Авторство
О чём код?
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 attachmentPreviewRow; signal close(); function handleRecordingState() { switch (recordingState) { case TelegrafUtils.Unavailable: recordingStateLabel.text = qsTr("Unavailable"); break; case TelegrafUtils.Ready: recordingStateLabel.text = qsTr("Ready"); break; case TelegrafUtils.Starting: recordingStateLabel.text = qsTr("Starting"); break; case TelegrafUtils.Recording: recordingStateLabel.text = qsTr("Recording"); break; case TelegrafUtils.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: { recordingDuration = Math.round(duration / 1000); handleRecordingDuration(); } onVoiceNoteRecordingStateChanged: { 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); close(); } } } } }