Add keyboard support to comboBox, HistoryList. Fix some issues with keyboard support.
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Mon, 28 Feb 2011 16:02:22 +0000 (17:02 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Mon, 28 Feb 2011 16:02:22 +0000 (17:02 +0100)
src/include/ComboBoxModel.cpp
src/include/ComboBoxModel.h
src/mdictionary/gui/HistoryListDialog.cpp
src/mdictionary/gui/MainWindow.cpp
src/mdictionary/qml/ComboBox.qml
src/mdictionary/qml/DictManagerWidget.qml
src/mdictionary/qml/HistoryListDialog.qml
src/mdictionary/qml/WordListWidget.qml

index 56963e1..35b1f87 100644 (file)
@@ -89,3 +89,8 @@ void ComboBoxModel::addItem(QString item)
     _contents << item;
     endInsertRows();
 }
+
+QString ComboBoxModel::valueOnPosition(int index)
+{
+    return _contents[index];
+}
index ad568fb..8f91c37 100644 (file)
@@ -63,6 +63,9 @@ public:
     void setSelectedItem(QString item);
     void setSelectedIndex(int index);
 
+public Q_SLOTS:
+    QString valueOnPosition(int index);
+
 private:
     void setContents(QList<QString> contents);
     void addItem(QString item);
index 804f907..e5bb27c 100644 (file)
@@ -55,6 +55,8 @@ HistoryListDialog::HistoryListDialog(QStringList words, QWidget *parent):
 
     QGraphicsObject *rootObject = view->rootObject();
 
+    view->setFocus();
+
     connect(rootObject,SIGNAL(selectedRow(int)),
             this,SLOT(itemClicked(int)));
 
index a4942aa..491b12b 100644 (file)
@@ -235,7 +235,9 @@ void MainWindow::wordListReady() {
             setExactSearch(false);
         }
     }
-    wordListWidget->setFocus();
+    WordListWidget* myWidget = qobject_cast<WordListWidget *>(wordListWidget);
+    myWidget->setFocusOnElement();
+//    wordListWidget->setFocus();
 }
 
 bool MainWindow::checkExactSearch(
index 5ceb5b5..56a0a40 100644 (file)
@@ -27,18 +27,10 @@ Rectangle {
 
     signal valueSelected(string selected);
 
-   /* Keys.onPressed: {
-        console.log("tu ----");
-        if (event.key == Qt.Key_Escape)
-            rectangle1.expanded=false;
-        else if (event.key == Qt.Key_Space)
+   Keys.onPressed: {
+        if (event.key == Qt.Key_Space)
             rectangle1.expanded=true;
-        else if (event.key == Qt.Key_Return){
-            rectangle1.expanded=false;
-            console.log("tu enter "+list1.content);
-        }
     }
-    */
 
     Text {
         id: text1
@@ -96,6 +88,17 @@ Rectangle {
         visible: false
         property string selected: rectangle1.startValue
 
+        Keys.onPressed: {
+
+            if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                selectedValue(currentIndex, model.valueOnPosition(currentIndex))
+            }
+            if (event.key == Qt.Key_Escape){
+                rectangle1.show(!rectangle1.expanded)
+                event.accepted = true
+            }
+        }
+
         function selectedValue(nr, value) {
             currentIndex = nr
             selected = value
index a512f2a..d15be32 100644 (file)
@@ -60,6 +60,10 @@ Rectangle {
         highlightResizeSpeed: 1000
 
         Keys.onPressed: {
+            if ((currentIndex < 0 || currentIndex >= count) && (event.key == Qt.Key_Up || event.key == Qt.Key_Down)){
+                currentIndex = 0
+            }
+
             if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
                 itemActivated(currentIndex)
             }
index feb7ad9..7b9ddc0 100644 (file)
@@ -3,6 +3,9 @@ import Qt 4.7
 Rectangle {
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
     color : myPalette.window;
+    function setFocus() {
+        historyList.setFocus()
+    }
 
     signal selectedRow(int nr)
 
@@ -26,6 +29,17 @@ Rectangle {
         anchors.bottom: parent.bottom
         anchors.top: parent.top
         highlightResizeSpeed: 1000
+
+        Keys.onPressed: {
+            if ((currentIndex < 0 || currentIndex >= count) && (event.key == Qt.Key_Up || event.key == Qt.Key_Down)){
+                currentIndex = 0
+            }
+
+            if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                selectedRow(currentIndex)
+            }
+        }
+
         delegate: Component{
             id: historyListDelegate
             Item {
index 4cd5f97..e4168f9 100644 (file)
@@ -59,6 +59,9 @@ Rectangle {
         property bool empty: false
 
         Keys.onPressed: {
+            if ((currentIndex < 0 || currentIndex >= count) && (event.key == Qt.Key_Up || event.key == Qt.Key_Down)){
+                currentIndex = 0
+            }
             if (event.key == Qt.Key_Space && currentIndex >= 0){
                 rectangle1.changeWordStateByIndex();
             } else if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){