| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #include "gui/reusable/locationlineedit.h" |
| 4 | |
| 5 | #include "network-web/googlesuggest.h" |
| 6 | |
| 7 | #include <QMouseEvent> |
| 8 | |
| 9 | LocationLineEdit::LocationLineEdit(QWidget* parent) |
| 10 | : BaseLineEdit(parent), m_mouseSelectsAllText(true), m_googleSuggest(new GoogleSuggest(this, this)) { |
| 11 | setPlaceholderText(tr("Website address goes here")); |
| 12 | connect(this, &LocationLineEdit::submitted, m_googleSuggest, &GoogleSuggest::preventSuggest); |
| 13 | } |
| 14 | |
| 15 | LocationLineEdit::~LocationLineEdit() {} |
| 16 | |
| 17 | void LocationLineEdit::focusOutEvent(QFocusEvent* event) { |
| 18 | BaseLineEdit::focusOutEvent(event); |
| 19 | |
| 20 | // User now left text box, when he enters it again and clicks, |
| 21 | // then all text should be selected. |
| 22 | m_mouseSelectsAllText = true; |
| 23 | } |
| 24 | |
| 25 | void LocationLineEdit::mousePressEvent(QMouseEvent* event) { |
| 26 | if (m_mouseSelectsAllText) { |
| 27 | event->ignore(); |
| 28 | selectAll(); |
| 29 | |
| 30 | // User clicked and all text was selected. |
| 31 | m_mouseSelectsAllText = false; |
| 32 | } |
| 33 | else { |
| 34 | BaseLineEdit::mousePressEvent(event); |
| 35 | } |
| 36 | } |