add focus in qml
[mdictionary] / src / mdictionary / gui / SearchBarWidget.cpp
index 338b87a..da482d0 100644 (file)
@@ -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:"<<QApplication::focusWidget();
+    if(focusWidget()!=QApplication::focusWidget())
+        emit focusOff();
+}
+
+void SearchBarWidget::nextFocus(){
+    parentWidget()->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