From 08e403fb8f97d1352819f64d81eeda2c65148a40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ka=C5=BAmierczak?= Date: Thu, 24 Feb 2011 16:54:55 +0100 Subject: [PATCH] first (buggy) version of keyboard usage in qml list --- src/mdictionary/gui/MainWindow.cpp | 4 +-- src/mdictionary/gui/WordListWidget.cpp | 8 +++++ src/mdictionary/gui/WordListWidget.h | 3 ++ src/mdictionary/qml/ElementsListView.qml | 18 +++++++++++ src/mdictionary/qml/WordListWidget.qml | 49 ++++++++++++++++++++---------- 5 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/mdictionary/gui/MainWindow.cpp b/src/mdictionary/gui/MainWindow.cpp index f8582dd..a4942aa 100644 --- a/src/mdictionary/gui/MainWindow.cpp +++ b/src/mdictionary/gui/MainWindow.cpp @@ -258,9 +258,9 @@ void MainWindow::translationsReady() { #ifndef Q_WS_MAEMO_5 hideWelcomeScreen(); #endif - Q_EMIT showTranslation(backbone->xmls()); - wordListWidget->setFocus(); + WordListWidget* myWidget = qobject_cast(wordListWidget); + myWidget->setFocusOnElement(); #ifdef Q_WS_MAEMO_5 notifyManager->screenChanged(); #endif diff --git a/src/mdictionary/gui/WordListWidget.cpp b/src/mdictionary/gui/WordListWidget.cpp index af05ae0..37eae2f 100644 --- a/src/mdictionary/gui/WordListWidget.cpp +++ b/src/mdictionary/gui/WordListWidget.cpp @@ -80,6 +80,7 @@ WordListWidget::WordListWidget(QWidget *parent): connect(this, SIGNAL(setWordListState(QVariant)), rootObject, SLOT(setEnabled(QVariant))); connect(this, SIGNAL(setWordListEmpty(QVariant)), rootObject, SLOT(setWordListEmpty(QVariant))); + connect(this, SIGNAL(setFocusOnQML()), rootObject, SLOT(setFocus())); #endif @@ -100,6 +101,13 @@ WordListWidget::~WordListWidget() { delete proxyStyle; } +void WordListWidget::setFocusOnElement(){ + setFocus(); + qmlView->setFocus(); + Q_EMIT setFocusOnQML(); + qDebug()<hasFocus(); +} + void WordListWidget::addWord(QString word, int row) { QStandardItem* item = new QStandardItem(word); diff --git a/src/mdictionary/gui/WordListWidget.h b/src/mdictionary/gui/WordListWidget.h index 9177529..7128410 100644 --- a/src/mdictionary/gui/WordListWidget.h +++ b/src/mdictionary/gui/WordListWidget.h @@ -64,6 +64,7 @@ Q_SIGNALS: void setWordListState(QVariant state); void setWordListEmpty(QVariant state); + void setFocusOnQML(); public Q_SLOTS: @@ -84,6 +85,8 @@ public Q_SLOTS: void bookmarkModeActive(); + void setFocusOnElement(); + protected: #ifdef Q_WS_MAEMO_5 //! Reimplemented standard mouseReleaseEvent to check if user clicked on diff --git a/src/mdictionary/qml/ElementsListView.qml b/src/mdictionary/qml/ElementsListView.qml index c9a7561..fa53b93 100644 --- a/src/mdictionary/qml/ElementsListView.qml +++ b/src/mdictionary/qml/ElementsListView.qml @@ -30,4 +30,22 @@ ListView { currentIndex: 0 highlight: Rectangle { color: "lightsteelblue"; radius: 5; width: parent.parent.width } highlightMoveSpeed: 1000 + + function setFocus() { + console.log("juhu2") + forceActiveFocus() +// console.log(focus + " " + activeFocus) + } + + Keys.onPressed: { + console.log("woooo") + if (event.key == Qt.Key_Up && currentIndex < count){ + currentIndex = currentIndex + 1 + console.log("woooo222 " + currentIndex) + } else if (event.key == Qt.Key_Down && currentIndex > 0){ + currentIndex = currentIndex - 1 + console.log("woooo333 " + currentIndex) + } + } + } diff --git a/src/mdictionary/qml/WordListWidget.qml b/src/mdictionary/qml/WordListWidget.qml index cb972fa..145ad89 100644 --- a/src/mdictionary/qml/WordListWidget.qml +++ b/src/mdictionary/qml/WordListWidget.qml @@ -27,6 +27,7 @@ import Qt 4.7 Rectangle { function changeWordState(nr, state) { + console.log("LOOOOOL") wordList.currentIndex = nr wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked") @@ -34,6 +35,13 @@ Rectangle { function setEnabled(Boolean) { wordList.enabled = Boolean } function setWordListEmpty(Boolean) { wordList.empty = Boolean } + function setFocus() { + console.log("juhu") + wordList.setFocus() +// activeFocus = true + console.log(focus + "a " + activeFocus) + console.log(wordList.focus + "b " + wordList.activeFocus) + } signal wordSelected(string word); @@ -51,6 +59,10 @@ Rectangle { highlightResizeSpeed: 1000 property bool empty: false + onCurrentIndexChanged: { + console.log("111!!!WTF " + currentIndex) + } + delegate: Component{ id: wordListDelegate Item { @@ -65,7 +77,7 @@ Rectangle { MouseArea{ anchors.fill: parent onClicked: { - wordList.currentIndex = number + wordList.currentIndex = index// number rectangle1.wordSelected(word) } } @@ -74,14 +86,7 @@ Rectangle { Text { id: wordText anchors.verticalCenter: parent.verticalCenter - text: - { - if (word == "!@#$%"){ - qsTr("Can't find any matching words") - } else { - word - } - } + text: word } Checkbox{ @@ -95,13 +100,6 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter onChanged: rectangle1.changeWordState(number, selected) - visible: { - if (word == "!@#$%"){ - false - } else { - true - } - } } } @@ -115,6 +113,15 @@ Rectangle { text: qsTr("Can't find any matching words") } + Rectangle { + id: shadeDisable + anchors.centerIn: parent; + color: "grey"; + opacity: 0 + width: parent.width; + height: parent.height; + } + model: wordModel states: [ @@ -127,6 +134,16 @@ Rectangle { name: "non-empty" when: (wordList.empty == false); PropertyChanges { target: emptyText; visible: false} + }, + State { + name: "enabled" + when: (wordList.enabled == true); + PropertyChanges { target: shadeDisable; z: 30; opacity: 0.5 } + }, + State { + name: "disabled" + when: (wordList.enabled == false); + PropertyChanges { target: shadeDisable; z: 30; opacity: 0.0 } } ] } -- 1.7.9.5