Added text selection on focus. Added basic check for text within url input field to decide is this something for search or for goto. Limited popup list height to do not cover virtual keyboard

This commit is contained in:
vladest 2017-09-20 17:02:54 +02:00
parent 56e6c8674a
commit 3376786288
2 changed files with 34 additions and 5 deletions

View file

@ -39,7 +39,7 @@ Rectangle {
id: searchEngine
name: "Google";
//icon: ":icons/sites/google.png"
searchUrlTemplate: "https://www.google.com/search?client=qupzilla&q=%s";
searchUrlTemplate: "https://www.google.com/search?client=hifibrowser&q={searchTerms}";
suggestionsUrlTemplate: "https://suggestqueries.google.com/complete/search?output=firefox&q=%s";
suggestionsUrl: "https://suggestqueries.google.com/complete/search?output=firefox&q=%s";
@ -73,11 +73,14 @@ Rectangle {
color: hifi.colors.baseGray;
function goTo(url) {
if (url.indexOf("http") !== 0) {
//must be valid attempt to open an site with dot
if (url.indexOf("http") <= 0 && url.indexOf(".") > 0) {
url = "http://" + url;
} else {
url = searchEngine.searchUrl(url)
}
webEngineView.url = url
event.accepted = true;
suggestionRequestTimer.stop()
addressBar.popup.close()
}
@ -125,6 +128,14 @@ Rectangle {
goTo(textAt(index))
}
popup.bottomPadding: keyboard.height
onFocusChanged: {
if (focus) {
addressBarInput.selectAll()
}
}
contentItem: QQControls.TextField {
id: addressBarInput
leftPadding: 26
@ -132,8 +143,25 @@ Rectangle {
text: addressBar.editText
placeholderText: qsTr("Enter URL")
font: addressBar.font
selectByMouse: true
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
onFocusChanged: {
if (focus) {
selectAll()
}
}
Keys.onDeletePressed: {
editText = ""
}
Keys.onPressed: {
if (event.key === Qt.Key_Return) {
goTo(editText)
event.accepted = true;
}
}
Image {
anchors.verticalCenter: parent.verticalCenter;
@ -167,6 +195,7 @@ Rectangle {
Keys.onPressed: {
if (event.key === Qt.Key_Return) {
goTo(editText)
event.accepted = true;
}
}
@ -177,7 +206,7 @@ Rectangle {
Layout.fillWidth: true
editText: webEngineView.url
onAccepted: webEngineView.url = editText
onAccepted: goTo(editText)
}
HifiControls.WebGlyphButton {

View file

@ -47,7 +47,6 @@ public:
QString searchUrlTemplate() const;
void setSearchUrlTemplate(const QString &searchUrl);
QUrl searchUrl(const QString &searchTerm) const;
QByteArray getPostData(const QString &searchTerm) const;
@ -89,6 +88,7 @@ public:
bool operator<(const OpenSearchEngine &other) const;
public slots:
QUrl searchUrl(const QString &searchTerm) const;
void requestSuggestions(const QString &searchTerm);
void requestSearchResults(const QString &searchTerm);