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

View file

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