import Qt 4.7 Rectangle { id: searchBarWidget SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } color : myPalette.window; property alias enableLineEdit: inputSearchText.enabled; property int focusIndex:-1; function setButtonText(string) { searchButton.setText(string) } function setEnableHistoryPrev(Boolean) { historyPrevToolButton.enabled = Boolean } function setEnableHistoryNext(Boolean) { historyNextToolButton.enabled = Boolean } function setEnableHistoryShow(Boolean) { historyShowToolButton.enabled = Boolean } function setEnableLineEdit(Boolean) { enableLineEdit = Boolean } function clear() { inputSearchText.setText("") } function setLineEditText(string) { inputSearchText.setText(string) } function setCompleterText(string) { inputSearchText.setCompleter(string) } function setFocus(){ if(focusIndex==0){ inputSearchText.setFocus(); if(!inputSearchText.enabled) focusIndex++; } if(focusIndex==1) clearButton.focus=true; if(focusIndex==2){ searchButton.focus = true if(!searchButton.enabled) focusIndex++; } if(focusIndex==3){ historyPrevToolButton.focus = true if(!historyPrevToolButton.enabled) focusIndex++; } if(focusIndex==4){ historyShowToolButton.focus = true if(!historyShowToolButton.enabled) focusIndex++; } if(focusIndex==5){ historyNextToolButton.focus = true if(!historyNextToolButton.enabled) focusIndex++; } if (focusIndex>5){ nextFocus(); focusIndex=-1; focus=true; } } function focusOff(){ focus=true; focusIndex=-1;} signal nextFocus(); signal checkFocus(); signal searchButtonClicked(string text); signal historyNextToolButtonClicked; signal historyShowToolButtonClicked; signal historyPrevToolButtonClicked; signal textChange(string text); signal nextCompleter(); signal prevCompleter(); Keys.onTabPressed: { focusIndex++; setFocus(); } MyTextLineEdit{ id: inputSearchText width: (searchBarWidget.width - (searchBarWidget.height*3.5 + searchButton.width + 9)); height: searchBarWidget.height -1; anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter onEnterPressed: searchBarWidget.searchButtonClicked(text); useCompleter: true; IconButton { id: clearButton; width: inputSearchText.height-6; height: inputSearchText.height-6; anchors.rightMargin: 4 anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter enabled: true; pathToIcon: "qrc:/button/go-clear.png"; onClicked: clear(); onActiveFocusChanged:searchBarWidget.checkFocus(); } onTextChange: searchBarWidget.textChange(text) onNextCompleter: searchBarWidget.nextCompleter(); onPrevCompleter: searchBarWidget.prevCompleter(); onIsFocused: searchBarWidget.focusIndex=0; onCheckFocus: searchBarWidget.checkFocus(); } Item { id: buttonsBox width: searchBarWidget.height*3.5 + searchButton.width + 9 height: searchBarWidget.height anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter Button { id: searchButton width: 100 height: searchBarWidget.height; anchors.rightMargin: 3 anchors.right: historyPrevToolButton.left anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Search") onClicked:{ searchBarWidget.searchButtonClicked(inputSearchText.textInLineEdit); inputSearchText.hideCompleter(); } onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { id: historyNextToolButton; width: searchBarWidget.height height: searchBarWidget.height anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter enabled: true; pathToIcon: "qrc:/button/go-next.png"; onClicked: searchBarWidget.historyNextToolButtonClicked(); onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { id: historyShowToolButton; width: searchBarWidget.height height: searchBarWidget.height anchors.rightMargin: 3 anchors.right: historyNextToolButton.left anchors.verticalCenter: parent.verticalCenter enabled: true; pathToIcon: "qrc:/button/go-show.png"; onClicked: searchBarWidget.historyShowToolButtonClicked(); onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { id: historyPrevToolButton; width: searchBarWidget.height height: searchBarWidget.height anchors.rightMargin: 3 anchors.right: historyShowToolButton.left anchors.verticalCenter: parent.verticalCenter enabled: true; pathToIcon: "qrc:/button/go-previous.png"; onClicked: searchBarWidget.historyPrevToolButtonClicked(); onActiveFocusChanged:searchBarWidget.checkFocus(); } } }