mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-23 01:27:15 +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->setEscFilter([=]() -> bool {
|
||||
return _replyToId || (_nonEmptySelection && _list);
|
||||
});
|
||||
|
||||
_voiceRecordBar->startRecordingRequests(
|
||||
) | rpl::start_with_next([=] {
|
||||
|
|
|
@ -391,6 +391,10 @@ void VoiceRecordBar::visibilityAnimate(bool show, Fn<void()> &&callback) {
|
|||
_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) {
|
||||
std::move(
|
||||
bottom
|
||||
|
@ -412,6 +416,7 @@ void VoiceRecordBar::startRecording() {
|
|||
const auto shown = _recordingLifetime.make_state<bool>(false);
|
||||
|
||||
_recording = true;
|
||||
_controller->widget()->setInnerFocus();
|
||||
instance()->start();
|
||||
instance()->updated(
|
||||
) | rpl::start_with_next_error([=](const Update &update) {
|
||||
|
@ -429,7 +434,6 @@ void VoiceRecordBar::startRecording() {
|
|||
show();
|
||||
|
||||
_inField = true;
|
||||
_controller->widget()->setInnerFocus();
|
||||
|
||||
_send->events(
|
||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||
|
@ -645,11 +649,15 @@ void VoiceRecordBar::installClickOutsideFilter() {
|
|||
const auto type = e->type();
|
||||
const auto noBox = !(*box);
|
||||
if (type == QEvent::KeyPress) {
|
||||
const auto key = static_cast<QKeyEvent*>(e.get())->key();
|
||||
const auto isEsc = (key == Qt::Key_Escape);
|
||||
if (noBox) {
|
||||
if (isEsc && (_escFilter && _escFilter())) {
|
||||
return Result::Continue;
|
||||
}
|
||||
return Result::Cancel;
|
||||
}
|
||||
const auto key = static_cast<QKeyEvent*>(e.get())->key();
|
||||
const auto cancelOrConfirmBox = (key == Qt::Key_Escape
|
||||
const auto cancelOrConfirmBox = (isEsc
|
||||
|| (key == Qt::Key_Enter || key == Qt::Key_Return));
|
||||
return cancelOrConfirmBox ? Result::Continue : Result::Cancel;
|
||||
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
[[nodiscard]] rpl::producer<bool> lockShowStarts() const;
|
||||
|
||||
void setLockBottom(rpl::producer<int> &&bottom);
|
||||
void setEscFilter(Fn<bool()> &&callback);
|
||||
|
||||
[[nodiscard]] bool isRecording() const;
|
||||
[[nodiscard]] bool isLockPresent() const;
|
||||
|
@ -93,6 +94,8 @@ private:
|
|||
QRect _durationRect;
|
||||
QRect _messageRect;
|
||||
|
||||
Fn<bool()> _escFilter;
|
||||
|
||||
rpl::variable<bool> _recording = false;
|
||||
rpl::variable<bool> _inField = false;
|
||||
int _recordingSamples = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue