From: jakub Date: Fri, 25 Feb 2011 08:33:31 +0000 (+0100) Subject: add focus in qml X-Git-Url: http://vcs.maemo.org/git/?p=mdictionary;a=commitdiff_plain;h=b4b3cec1e6eb007baf2b8ea83bd21df90643675d add focus in qml --- diff --git a/data/gui.qrc b/data/gui.qrc index 2890e96..1f1cdb4 100644 --- a/data/gui.qrc +++ b/data/gui.qrc @@ -32,5 +32,8 @@ button/revert.png button/checkboxCheckedDis.png button/checkboxDis.png + button/buttonCenterFocus.png + button/buttonLeftFocus.png + button/buttonRFocus.png diff --git a/src/mdictionary/gui/SearchBarWidget.cpp b/src/mdictionary/gui/SearchBarWidget.cpp index 338b87a..da482d0 100644 --- a/src/mdictionary/gui/SearchBarWidget.cpp +++ b/src/mdictionary/gui/SearchBarWidget.cpp @@ -52,6 +52,7 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { view= new QDeclarativeView(); ctxt = view->rootContext(); + ctxt->setContextProperty("focusss",true); view->setSource(QUrl::fromLocalFile("/usr/share/mdictionary/qml/SearchBarWidget.qml")); view->setResizeMode(QDeclarativeView::SizeRootObjectToView); @@ -80,6 +81,10 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { this, SLOT(nextCompleter())); connect(rootObject, SIGNAL(prevCompleter()), this, SLOT(prevCompleter())); + connect(rootObject, SIGNAL(checkFocus()), + this, SLOT(checkFocus())); + connect(rootObject, SIGNAL(nextFocus()), + this, SLOT(nextFocus())); connect(this, SIGNAL(progresSetMax(QVariant)), rootObject2, SLOT(setMax(QVariant))); @@ -105,6 +110,8 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(this, SIGNAL(setCompleterText(QVariant)), rootObject, SLOT(setCompleterText(QVariant))); + connect(this, SIGNAL(focusOff()), + rootObject, SLOT(focusOff())); connect(busyTimer, SIGNAL(timeout()), this, SLOT(updateBusyTimer())); @@ -116,8 +123,6 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { connect(&delayTimer, SIGNAL(timeout()), this, SLOT(delaySearchTimeout())); - view->setFocus(); - #else initializeUI(); connect(searchPushButton, SIGNAL(clicked()), @@ -137,7 +142,7 @@ SearchBarWidget::SearchBarWidget(QWidget *parent) : QWidget(parent) { searchWordLineEdit->setFocus(); #endif - + setFocus(); busy = false; setEnabled(true); updateHistoryButtons(false,false,false); @@ -147,6 +152,16 @@ SearchBarWidget::~SearchBarWidget() { } +void SearchBarWidget::checkFocus(){ + qDebug()<<"focus:"<nextInFocusChain()->setFocus(); +} + void SearchBarWidget::textChange(QString text){ QLineEdit line; QString toSend=""; @@ -250,7 +265,6 @@ QIcon SearchBarWidget::generateIcon(QIcon original, qreal rotation) { } void SearchBarWidget::setFocus() { - qDebug()<<"test3"; #ifndef Q_WS_MAEMO_5 view->setFocus(); #else diff --git a/src/mdictionary/gui/SearchBarWidget.h b/src/mdictionary/gui/SearchBarWidget.h index 0e84bee..d19ce21 100644 --- a/src/mdictionary/gui/SearchBarWidget.h +++ b/src/mdictionary/gui/SearchBarWidget.h @@ -61,6 +61,7 @@ Q_SIGNALS: void progresSetValue(QVariant); void progresSetValue2(QVariant); void setCompleterText(QVariant); + void focusOff(); //! Requests to search for a list of words matching a word passed as //! a parameter @@ -135,6 +136,8 @@ public Q_SLOTS: void updateHistoryButtons(bool prev, bool next, bool list); void setFocus(); + void nextFocus(); + void checkFocus(); private Q_SLOTS: //! Clears search word line edit @@ -155,6 +158,7 @@ private Q_SLOTS: void prevCompleter(); + private: QVBoxLayout* mainLayout; diff --git a/src/mdictionary/gui/SettingsWidget.cpp b/src/mdictionary/gui/SettingsWidget.cpp index 4c37017..bb070f2 100644 --- a/src/mdictionary/gui/SettingsWidget.cpp +++ b/src/mdictionary/gui/SettingsWidget.cpp @@ -321,6 +321,7 @@ void SettingsWidget::changed() { #ifndef Q_WS_MAEMO_5 void SettingsWidget::save() { _save = true; + qDebug()<<"tuuu"; hide(); } #endif diff --git a/src/mdictionary/gui/TranslationView.cpp b/src/mdictionary/gui/TranslationView.cpp index d60a2f0..e54498a 100644 --- a/src/mdictionary/gui/TranslationView.cpp +++ b/src/mdictionary/gui/TranslationView.cpp @@ -49,6 +49,8 @@ TranslationView::TranslationView(QWidget *parent) : QWebView(parent) { connect(this, SIGNAL(setUrl(QVariant)), rootObject, SLOT(setUrl(QVariant))); + emit setUrl(QDir::homePath() + "/.mdictionary/" + "html.html"); + #else realParent = qobject_cast(parent); @@ -66,7 +68,8 @@ TranslationView::TranslationView(QWidget *parent) : QWebView(parent) { connect(searchSelectedAction, SIGNAL(triggered()), this, SIGNAL(search())); - connect(page(), SIGNAL(selectionChanged()), this, SLOT(selection())); + connect(page(), SIGNAL(selectionChanged()), + this, SLOT(selection())); #endif } diff --git a/src/mdictionary/qml/Button.qml b/src/mdictionary/qml/Button.qml index dd94a40..953fdbc 100644 --- a/src/mdictionary/qml/Button.qml +++ b/src/mdictionary/qml/Button.qml @@ -1,6 +1,6 @@ import Qt 4.7 -BorderImage { +Rectangle { id: button property alias textInButton: buttonText.text property bool checkable: false @@ -14,7 +14,14 @@ BorderImage { function setText(string) { textInButton = qsTr(string); } function press() { mouseArea.pressed } - border { left: 10; top: 10; right: 10; bottom: 10 } + + Keys.onReturnPressed: { + button.clicked(); + if(checkable){ + button.checked=!button.checked; + button.changeCheck(); + } + } MouseArea { id: mouseArea @@ -43,7 +50,7 @@ BorderImage { Image { id: image1 - width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 height: parent.height anchors.left: parent.left source: "qrc:/button/buttonLeft.png" @@ -60,13 +67,15 @@ BorderImage { anchors.left: image1.right anchors.leftMargin: -1 source: "qrc:/button/buttonCenter.png" - fillMode:Image.Stretch + //fillMode:Image.Stretch + fillMode: Image.TileHorizontally + } Image { id: image2 smooth: true - width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 height: parent.height anchors.right: parent.right source: "qrc:/button/buttonR.png" @@ -89,6 +98,15 @@ BorderImage { PropertyChanges { target: image1; source: "qrc:/button/buttonLeftDisabled.png" } PropertyChanges { target: image3; source: "qrc:/button/buttonCenterDisabled.png" } PropertyChanges { target: image2; source: "qrc:/button/buttonRightDisabled.png" } + }, + State { + name: "focused"; + when: (button.enabled && !mouseArea.pressed && button.focus) + + PropertyChanges { target: image1; source: "qrc:/button/buttonLeftFocus.png" } + PropertyChanges { target: image3; source: "qrc:/button/buttonCenterFocus.png" } + PropertyChanges { target: image2; source: "qrc:/button/buttonRFocus.png" } } + ] } diff --git a/src/mdictionary/qml/Checkbox.qml b/src/mdictionary/qml/Checkbox.qml index 7e96512..75046e3 100644 --- a/src/mdictionary/qml/Checkbox.qml +++ b/src/mdictionary/qml/Checkbox.qml @@ -32,6 +32,12 @@ Image { property string pathToCheckedDicImage: "qrc:/button/checkboxCheckedDis.png" property string pathToUncheckedDicImage: "qrc:/button/checkboxDis.png" signal changed + + Keys.onPressed: { + if (event.key == Qt.Key_Space) + selected=!selected + } + height: { var aspectRatio = sourceSize.height / sourceSize.width return checkbox.width * aspectRatio @@ -74,4 +80,21 @@ Image { } } } + + Rectangle{ + id: focusRectangle + color: "#000000" + border.color: "#000000" + opacity: 0; + radius: 1 + anchors.centerIn: parent + z:1; + } + + onFocusChanged: { + if(focus) + focusRectangle.opacity=0.5; + else + focusRectangle.opacity=0; + } } diff --git a/src/mdictionary/qml/FlickableWebView.qml b/src/mdictionary/qml/FlickableWebView.qml index edd448d..42818ef 100644 --- a/src/mdictionary/qml/FlickableWebView.qml +++ b/src/mdictionary/qml/FlickableWebView.qml @@ -72,10 +72,6 @@ Flickable { contentsScale: 1 pressGrabTime: 0 - Keys.onRightPressed: { - console.log("test"); - } - function doZoom(zoom,centerX,centerY) { var tempX = flickable.width/2 - parent.x*zoom; diff --git a/src/mdictionary/qml/IconButton.qml b/src/mdictionary/qml/IconButton.qml index 9be44f1..37825a7 100644 --- a/src/mdictionary/qml/IconButton.qml +++ b/src/mdictionary/qml/IconButton.qml @@ -33,17 +33,16 @@ Rectangle { Image { id: image1 - z: 1 smooth: true - width: (35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1 //(35*parent.height)/107 +1 height: parent.height anchors.left: parent.left source: "qrc:/button/buttonLeft.png" + fillMode:Image.Stretch } Image { id: image3 - z: 1 smooth: true height: parent.height anchors.right: image2.left @@ -51,18 +50,20 @@ Rectangle { anchors.left: image1.right anchors.leftMargin: -1 source: "qrc:/button/buttonCenter.png" + fillMode:Image.Stretch + //fillMode: Image.TileHorizontally } Image { id: image2 - z: 1 smooth: true - width: (35*parent.height)/107 +1 + width: (image1.sourceSize.width*parent.height)/image1.sourceSize.height +1//(35*parent.height)/107 +1 height: parent.height anchors.right: parent.right source: "qrc:/button/buttonR.png" + fillMode:Image.Stretch } @@ -80,6 +81,14 @@ Rectangle { PropertyChanges { target: image1; source: "qrc:/button/buttonLeftPushed.png" } PropertyChanges { target: image3; source: "qrc:/button/buttonCenterPushed.png" } PropertyChanges { target: image2; source: "qrc:/button/buttonRightPushed.png" } + }, + State { + name: "focused"; + when: (rectangle.enabled && !mouseArea.pressed && rectangle.focus) + + PropertyChanges { target: image1; source: "qrc:/button/buttonLeftFocus.png" } + PropertyChanges { target: image3; source: "qrc:/button/buttonCenterFocus.png" } + PropertyChanges { target: image2; source: "qrc:/button/buttonRFocus.png" } } ] } diff --git a/src/mdictionary/qml/MySpinBox.qml b/src/mdictionary/qml/MySpinBox.qml index 54fe47d..a30ecba 100644 --- a/src/mdictionary/qml/MySpinBox.qml +++ b/src/mdictionary/qml/MySpinBox.qml @@ -30,6 +30,10 @@ Rectangle { return value; } + function setFocus(){ + text_input1.focus=true; + } + TextInput { id: text_input1 x: 1 @@ -52,6 +56,15 @@ Rectangle { if(focus==false) text=stringToInt(text); } + Keys.onPressed: { + if (event.key == Qt.Key_Up) + text_input1.text=((stringToInt(text_input1.text)+singleStep)>maxValue)?(maxValue):(stringToInt(text_input1.text)+singleStep); + else if (event.key == Qt.Key_Down){ + text_input1.text=((stringToInt(text_input1.text)-singleStep)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)); @@ -33,7 +83,6 @@ Rectangle { anchors.left: parent.left anchors.verticalCenter: parent.verticalCenter onEnterPressed: searchBarWidget.searchButtonClicked(text); - focus: searchBarWidget.focus useCompleter: true; IconButton { id: clearButton; @@ -45,10 +94,13 @@ Rectangle { 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 { @@ -70,6 +122,7 @@ Rectangle { searchBarWidget.searchButtonClicked(inputSearchText.textInLineEdit); inputSearchText.hideCompleter(); } + onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { @@ -81,6 +134,7 @@ Rectangle { enabled: true; pathToIcon: "qrc:/button/go-next.png"; onClicked: searchBarWidget.historyNextToolButtonClicked(); + onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { @@ -93,6 +147,7 @@ Rectangle { enabled: true; pathToIcon: "qrc:/button/go-show.png"; onClicked: searchBarWidget.historyShowToolButtonClicked(); + onActiveFocusChanged:searchBarWidget.checkFocus(); } IconButton { @@ -105,6 +160,7 @@ Rectangle { enabled: true; pathToIcon: "qrc:/button/go-previous.png"; onClicked: searchBarWidget.historyPrevToolButtonClicked(); + onActiveFocusChanged:searchBarWidget.checkFocus(); } } } diff --git a/src/mdictionary/qml/SettingsWidget.qml b/src/mdictionary/qml/SettingsWidget.qml index b51f788..5f32049 100644 --- a/src/mdictionary/qml/SettingsWidget.qml +++ b/src/mdictionary/qml/SettingsWidget.qml @@ -7,6 +7,9 @@ Rectangle { SystemPalette { id: myPalette; colorGroup: SystemPalette.Active } color : myPalette.window; + focus: true; + property int focusIndex:-1; + signal historySizeValueChanged(int intiger); signal searchResulValueChanged(int intiger); @@ -40,6 +43,42 @@ Rectangle { function setCheckedDictionaries(bool){ dictionariesCheckBox.selected=bool; } + function setFocus(){ + if(focusIndex==0){ + searchSpinbox.setFocus(); + if(!searchSpinbox.enabled) + focusIndex++; + } + if(focusIndex==1){ + historySpinbox.setFocus(); + if(!historySpinbox.enabled) + focusIndex++; + } + if(focusIndex==2){ + bookmarkCheckBox.focus = true + if(!bookmarkCheckBox.enabled) + focusIndex++; + } + if(focusIndex==3){ + dictionariesCheckBox.focus = true + if(!dictionariesCheckBox.enabled) + focusIndex++; + } + if(focusIndex==4){ + saveButton.focus = true + if(!saveButton.enabled) + focusIndex++; + } + if(focusIndex>4){ + focusIndex=-1; + focus=true; + } + } + + Keys.onTabPressed: { + focusIndex++; + setFocus(); + } Text { id: textSearch @@ -107,6 +146,7 @@ Rectangle { anchors.left: textSearch.right anchors.leftMargin: 20 onValueChange: rectangle1.searchResulValueChanged(intiger); + onFocusChanged: if(focus) focusIndex=0; } MySpinBox { @@ -117,6 +157,7 @@ Rectangle { anchors.top: searchSpinbox.bottom anchors.topMargin: 10 onValueChange: rectangle1.historySizeValueChanged(intiger); + onFocusChanged: if(focus) focusIndex=1; } Checkbox { @@ -128,6 +169,7 @@ Rectangle { anchors.top: textSearchIn.bottom anchors.topMargin: 0 onChanged: rectangle1.bookmarksCheckBoxChanged(selected); + onFocusChanged: if(focus) focusIndex=2; } Checkbox { @@ -138,6 +180,7 @@ Rectangle { anchors.top: bookmarkCheckBox.bottom anchors.topMargin: 3 onChanged: rectangle1.dictionariesCheckBoxChanged(selected); + onFocusChanged: if(focus) focusIndex=3; } Button { @@ -149,6 +192,7 @@ Rectangle { anchors.right: parent.right anchors.rightMargin: 5 textInButton: qsTr("Save") - //onClicked: rectangle1.saveButtonClicked(); + onClicked: rectangle1.saveButtonClicked(); + onFocusChanged: if(focus) focusIndex=4; } } diff --git a/src/mdictionary/qml/TranslationView.qml b/src/mdictionary/qml/TranslationView.qml index c0a546a..79cd850 100644 --- a/src/mdictionary/qml/TranslationView.qml +++ b/src/mdictionary/qml/TranslationView.qml @@ -18,6 +18,7 @@ Rectangle { id: webView width:parent.width height:parent.height + url:"file:///home/jakub/test.html"; anchors { top: headerSpace.bottom; left: parent.left; right: parent.right; bottom: parent.bottom } }