From 5bfe89f71957910975ae576cf968cf1ec32db49e Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Sun, 27 Dec 2020 16:47:34 +1100 Subject: URL bar now has 'select all' behaviour on mouse release --- src/widgets/searchbar.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/widgets/searchbar.cpp') diff --git a/src/widgets/searchbar.cpp b/src/widgets/searchbar.cpp index 807a979..90537a1 100644 --- a/src/widgets/searchbar.cpp +++ b/src/widgets/searchbar.cpp @@ -30,3 +30,25 @@ void SearchBar::keyReleaseEvent(QKeyEvent *event) QLineEdit::keyReleaseEvent(event); } } + +void SearchBar::focusInEvent(QFocusEvent *event) +{ + QLineEdit::focusInEvent(event); + + // Allows only one "select all" on mouse release + // until next focus event. + this->selectall_flag = (event->reason() == Qt::MouseFocusReason); +} + +void SearchBar::mouseReleaseEvent(QMouseEvent *event) +{ + QLineEdit::mouseReleaseEvent(event); + + // Select all text if the bar was just focused and + // user did not select anything. + if (this->selectall_flag && QLineEdit::selectionLength() < 1) + { + QLineEdit::selectAll(); + } + this->selectall_flag = false; +} -- cgit v1.2.3