mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added ability to pass filter for Escape key to voice record bar.
This commit is contained in:
parent
914e40fb62
commit
fe5242d6d2
3 changed files with 17 additions and 3 deletions
|
@ -726,6 +726,9 @@ void HistoryWidget::initVoiceRecordBar() {
|
||||||
});
|
});
|
||||||
_voiceRecordBar->setLockBottom(std::move(scrollHeight));
|
_voiceRecordBar->setLockBottom(std::move(scrollHeight));
|
||||||
}
|
}
|
||||||
|
_voiceRecordBar->setEscFilter([=]() -> bool {
|
||||||
|
return _replyToId || (_nonEmptySelection && _list);
|
||||||
|
});
|
||||||
|
|
||||||
_voiceRecordBar->startRecordingRequests(
|
_voiceRecordBar->startRecordingRequests(
|
||||||
) | rpl::start_with_next([=] {
|
) | rpl::start_with_next([=] {
|
||||||
|
|
|
@ -391,6 +391,10 @@ void VoiceRecordBar::visibilityAnimate(bool show, Fn<void()> &&callback) {
|
||||||
_showAnimation.start(std::move(animationCallback), from, to, duration);
|
_showAnimation.start(std::move(animationCallback), from, to, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VoiceRecordBar::setEscFilter(Fn<bool()> &&callback) {
|
||||||
|
_escFilter = std::move(callback);
|
||||||
|
}
|
||||||
|
|
||||||
void VoiceRecordBar::setLockBottom(rpl::producer<int> &&bottom) {
|
void VoiceRecordBar::setLockBottom(rpl::producer<int> &&bottom) {
|
||||||
std::move(
|
std::move(
|
||||||
bottom
|
bottom
|
||||||
|
@ -412,6 +416,7 @@ void VoiceRecordBar::startRecording() {
|
||||||
const auto shown = _recordingLifetime.make_state<bool>(false);
|
const auto shown = _recordingLifetime.make_state<bool>(false);
|
||||||
|
|
||||||
_recording = true;
|
_recording = true;
|
||||||
|
_controller->widget()->setInnerFocus();
|
||||||
instance()->start();
|
instance()->start();
|
||||||
instance()->updated(
|
instance()->updated(
|
||||||
) | rpl::start_with_next_error([=](const Update &update) {
|
) | rpl::start_with_next_error([=](const Update &update) {
|
||||||
|
@ -429,7 +434,6 @@ void VoiceRecordBar::startRecording() {
|
||||||
show();
|
show();
|
||||||
|
|
||||||
_inField = true;
|
_inField = true;
|
||||||
_controller->widget()->setInnerFocus();
|
|
||||||
|
|
||||||
_send->events(
|
_send->events(
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
|
@ -645,11 +649,15 @@ void VoiceRecordBar::installClickOutsideFilter() {
|
||||||
const auto type = e->type();
|
const auto type = e->type();
|
||||||
const auto noBox = !(*box);
|
const auto noBox = !(*box);
|
||||||
if (type == QEvent::KeyPress) {
|
if (type == QEvent::KeyPress) {
|
||||||
|
const auto key = static_cast<QKeyEvent*>(e.get())->key();
|
||||||
|
const auto isEsc = (key == Qt::Key_Escape);
|
||||||
if (noBox) {
|
if (noBox) {
|
||||||
|
if (isEsc && (_escFilter && _escFilter())) {
|
||||||
|
return Result::Continue;
|
||||||
|
}
|
||||||
return Result::Cancel;
|
return Result::Cancel;
|
||||||
}
|
}
|
||||||
const auto key = static_cast<QKeyEvent*>(e.get())->key();
|
const auto cancelOrConfirmBox = (isEsc
|
||||||
const auto cancelOrConfirmBox = (key == Qt::Key_Escape
|
|
||||||
|| (key == Qt::Key_Enter || key == Qt::Key_Return));
|
|| (key == Qt::Key_Enter || key == Qt::Key_Return));
|
||||||
return cancelOrConfirmBox ? Result::Continue : Result::Cancel;
|
return cancelOrConfirmBox ? Result::Continue : Result::Cancel;
|
||||||
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
|
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
||||||
|
|
||||||
void setLockBottom(rpl::producer<int> &&bottom);
|
void setLockBottom(rpl::producer<int> &&bottom);
|
||||||
|
void setEscFilter(Fn<bool()> &&callback);
|
||||||
|
|
||||||
[[nodiscard]] bool isRecording() const;
|
[[nodiscard]] bool isRecording() const;
|
||||||
[[nodiscard]] bool isLockPresent() const;
|
[[nodiscard]] bool isLockPresent() const;
|
||||||
|
@ -93,6 +94,8 @@ private:
|
||||||
QRect _durationRect;
|
QRect _durationRect;
|
||||||
QRect _messageRect;
|
QRect _messageRect;
|
||||||
|
|
||||||
|
Fn<bool()> _escFilter;
|
||||||
|
|
||||||
rpl::variable<bool> _recording = false;
|
rpl::variable<bool> _recording = false;
|
||||||
rpl::variable<bool> _inField = false;
|
rpl::variable<bool> _inField = false;
|
||||||
int _recordingSamples = 0;
|
int _recordingSamples = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue