mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
enable clicking on country chooser by pressing space bar and enter key
This commit is contained in:
committed by
John Preston
parent
13862bd561
commit
ce9c3b4ef8
@@ -103,6 +103,42 @@ void CountryInput::mousePressEvent(QMouseEvent *e) {
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInput::keyPressEvent(QKeyEvent* e) {
|
||||
if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return || e->key() == Qt::Key_Space) {
|
||||
auto object = Box<Ui::CountrySelectBox>();
|
||||
const auto box = base::make_weak(object.data());
|
||||
_show->showBox(std::move(object), Ui::LayerOption::CloseOther);
|
||||
box->entryChosen(
|
||||
) | rpl::start_with_next([=](
|
||||
const Ui::CountrySelectBox::Entry& entry) {
|
||||
if (box) {
|
||||
box->closeBox();
|
||||
}
|
||||
|
||||
const auto& list = Countries::Instance().list();
|
||||
const auto infoIt = ranges::find(
|
||||
list,
|
||||
entry.iso2,
|
||||
&Countries::Info::iso2);
|
||||
if (infoIt == end(list)) {
|
||||
return;
|
||||
}
|
||||
const auto info = *infoIt;
|
||||
const auto it = ranges::find(
|
||||
info.codes,
|
||||
entry.code,
|
||||
&Countries::CallingCodeInfo::callingCode);
|
||||
if (it != end(info.codes)) {
|
||||
chooseCountry(
|
||||
&info,
|
||||
std::distance(begin(info.codes), it));
|
||||
}
|
||||
}, lifetime());
|
||||
} else {
|
||||
RpWidget::keyPressEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
void CountryInput::enterEventHook(QEnterEvent *e) {
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void mouseMoveEvent(QMouseEvent *e) override;
|
||||
void mousePressEvent(QMouseEvent *e) override;
|
||||
void keyPressEvent(QKeyEvent* e) override;
|
||||
void enterEventHook(QEnterEvent *e) override;
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user