Added ability to play/pause recorded voice data with Space key.

This commit is contained in:
23rd 2020-11-11 20:27:02 +03:00 committed by John Preston
parent d2defabd4b
commit 7dac42b523

View file

@ -207,6 +207,8 @@ public:
rpl::producer<> stopRequests() const;
::Media::Capture::Result *data() const;
void playPause();
rpl::lifetime &lifetime();
private:
@ -556,6 +558,10 @@ bool ListenWrap::isInPlayer() const {
return isInPlayer(::Media::Player::instance()->getState(Type::Voice));
}
void ListenWrap::playPause() {
_playPauseButton->clicked(Qt::NoModifier, Qt::LeftButton);
}
QRect ListenWrap::computeWaveformRect(const QRect &centerRect) const {
const auto top = computeTopMargin(st::msgWaveformMax);
const auto left = (_playPauseSt.playOuter.width() + centerRect.height())
@ -1482,10 +1488,16 @@ void VoiceRecordBar::installListenStateFilter() {
}
switch(e->type()) {
case QEvent::KeyPress: {
const auto key = static_cast<QKeyEvent*>(e.get())->key();
const auto keyEvent = static_cast<QKeyEvent*>(e.get());
const auto key = keyEvent->key();
const auto isSpace = (key == Qt::Key_Space);
const auto isEsc = (key == Qt::Key_Escape);
const auto isEnter = (key == Qt::Key_Enter
|| key == Qt::Key_Return);
if (isSpace && !keyEvent->isAutoRepeat() && _listen) {
_listen->playPause();
return Result::Cancel;
}
if (isEnter) {
requestToSendWithOptions({});
return Result::Cancel;