mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 23:53:58 +02:00
Added ability to send recording voice message with Enter key.
This commit is contained in:
parent
fe5242d6d2
commit
b6743feec1
1 changed files with 30 additions and 16 deletions
|
@ -36,6 +36,12 @@ constexpr auto kMaxSamples =
|
||||||
|
|
||||||
constexpr auto kPrecision = 10;
|
constexpr auto kPrecision = 10;
|
||||||
|
|
||||||
|
enum class FilterType {
|
||||||
|
Continue,
|
||||||
|
ShowBox,
|
||||||
|
Cancel,
|
||||||
|
};
|
||||||
|
|
||||||
[[nodiscard]] auto Duration(int samples) {
|
[[nodiscard]] auto Duration(int samples) {
|
||||||
return samples / ::Media::Player::kDefaultFrequency;
|
return samples / ::Media::Player::kDefaultFrequency;
|
||||||
}
|
}
|
||||||
|
@ -627,7 +633,7 @@ void VoiceRecordBar::computeAndSetLockProgress(QPoint globalPos) {
|
||||||
void VoiceRecordBar::installClickOutsideFilter() {
|
void VoiceRecordBar::installClickOutsideFilter() {
|
||||||
const auto box = _recordingLifetime.make_state<QPointer<ConfirmBox>>();
|
const auto box = _recordingLifetime.make_state<QPointer<ConfirmBox>>();
|
||||||
const auto showBox = [=] {
|
const auto showBox = [=] {
|
||||||
if (*box || _send->underMouse()) {
|
if (*box) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto sure = [=](Fn<void()> &&close) {
|
auto sure = [=](Fn<void()> &&close) {
|
||||||
|
@ -642,40 +648,48 @@ void VoiceRecordBar::installClickOutsideFilter() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto computeResult = [=](not_null<QEvent*> e) {
|
const auto computeResult = [=](not_null<QEvent*> e) {
|
||||||
using Result = base::EventFilterResult;
|
using Type = FilterType;
|
||||||
if (!_lock->isLocked()) {
|
if (!_lock->isLocked()) {
|
||||||
return Result::Continue;
|
return Type::Continue;
|
||||||
}
|
}
|
||||||
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 key = static_cast<QKeyEvent*>(e.get())->key();
|
||||||
const auto isEsc = (key == Qt::Key_Escape);
|
const auto isEsc = (key == Qt::Key_Escape);
|
||||||
|
const auto isEnter = (key == Qt::Key_Enter
|
||||||
|
|| key == Qt::Key_Return);
|
||||||
if (noBox) {
|
if (noBox) {
|
||||||
if (isEsc && (_escFilter && _escFilter())) {
|
if (isEnter) {
|
||||||
return Result::Continue;
|
stop(true);
|
||||||
|
return Type::Cancel;
|
||||||
|
} else if (isEsc && (_escFilter && _escFilter())) {
|
||||||
|
return Type::Continue;
|
||||||
}
|
}
|
||||||
return Result::Cancel;
|
return Type::ShowBox;
|
||||||
}
|
}
|
||||||
const auto cancelOrConfirmBox = (isEsc
|
return (isEsc || isEnter) ? Type::Continue : Type::ShowBox;
|
||||||
|| (key == Qt::Key_Enter || key == Qt::Key_Return));
|
|
||||||
return cancelOrConfirmBox ? Result::Continue : Result::Cancel;
|
|
||||||
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
|
} else if (type == QEvent::ContextMenu || type == QEvent::Shortcut) {
|
||||||
return Result::Cancel;
|
return Type::ShowBox;
|
||||||
} else if (type == QEvent::MouseButtonPress) {
|
} else if (type == QEvent::MouseButtonPress) {
|
||||||
return (noBox && !_send->underMouse())
|
return (noBox && !_send->underMouse())
|
||||||
? Result::Cancel
|
? Type::ShowBox
|
||||||
: Result::Continue;
|
: Type::Continue;
|
||||||
}
|
}
|
||||||
return Result::Continue;
|
return Type::Continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto filterCallback = [=](not_null<QEvent*> e) {
|
auto filterCallback = [=](not_null<QEvent*> e) {
|
||||||
const auto result = computeResult(e);
|
using Result = base::EventFilterResult;
|
||||||
if (result == base::EventFilterResult::Cancel) {
|
switch(computeResult(e)) {
|
||||||
|
case FilterType::ShowBox: {
|
||||||
showBox();
|
showBox();
|
||||||
|
return Result::Cancel;
|
||||||
|
}
|
||||||
|
case FilterType::Continue: return Result::Continue;
|
||||||
|
case FilterType::Cancel: return Result::Cancel;
|
||||||
|
default: return Result::Continue;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto filter = base::install_event_filter(
|
auto filter = base::install_event_filter(
|
||||||
|
|
Loading…
Add table
Reference in a new issue