enable clicking on country chooser by pressing space bar and enter key

This commit is contained in:
Reza Bakhshi Laktasaraei
2025-10-22 13:04:54 +03:30
committed by John Preston
parent 13862bd561
commit ce9c3b4ef8
2 changed files with 37 additions and 0 deletions
+36
View File
@@ -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);
}
+1
View File
@@ -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;