Fix bug with app crash on exit. Add keyboard support in wordList, DictTypeSelectDialo...
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Mon, 28 Feb 2011 14:22:33 +0000 (15:22 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Mon, 28 Feb 2011 14:22:33 +0000 (15:22 +0100)
13 files changed:
src/mdictionary/gui/DictManagerModel.cpp
src/mdictionary/gui/DictManagerModel.h
src/mdictionary/gui/DictManagerWidget.cpp
src/mdictionary/gui/DictManagerWidget.h
src/mdictionary/gui/DictTypeSelectDialog.cpp
src/mdictionary/gui/WordListModel.cpp
src/mdictionary/gui/WordListModel.h
src/mdictionary/gui/WordListWidget.cpp
src/mdictionary/gui/WordListWidget.h
src/mdictionary/qml/DictManagerWidget.qml
src/mdictionary/qml/DictTypeSelectDialog.qml
src/mdictionary/qml/ElementsListView.qml
src/mdictionary/qml/WordListWidget.qml

index 8e53a14..7b8807c 100644 (file)
@@ -151,6 +151,18 @@ void DictManagerModel::setModelProperty(int index, const QVariant value, QString
 
 }
 
+void DictManagerModel::setModelProperty(int index, QString role)
+{
+    if (role.contains("isSelected"))
+    {
+        if (index < 0 || index > _dictionaries.count() - 1)
+            return;
+
+        setDataPriv(index, !_dictionaries[_dictList[index]], IsSelectedRole);
+    }
+
+}
+
 void DictManagerModel::itemSelected(int index)
 {
     _currentIndex = index;
index 034867f..27bd9f3 100644 (file)
@@ -89,6 +89,14 @@ public Q_SLOTS:
       \param role role name
       */
     void setModelProperty(int index, const QVariant value, QString role);
+
+    //! Reverse value at role in index row of data.
+    /*!
+      \param index dictionary position in data list
+      \param role role name
+      */
+    void setModelProperty(int index, QString role);
+
     //! Set index of current selected dictionary
     /*!
       \param index dictionary position in data list
index 86459b7..1e5a73e 100644 (file)
@@ -133,6 +133,8 @@ void DictManagerWidget::initalizeUI() {
     connect(rootObject, SIGNAL(itemActivated(int)),
             this, SLOT(settingsButtonClicked()));
 
+    connect(this, SIGNAL(setFocusOnQML()), rootObject, SLOT(setFocus()));
+
     #endif
 
     #ifdef Q_WS_MAEMO_5
@@ -164,6 +166,7 @@ void DictManagerWidget::refreshDictsList() {
         model->clear();
         model->setDictionaries(dicts);
     }
+    setFocusOnElement();
 
     #endif
 
@@ -257,11 +260,9 @@ void DictManagerWidget::hideEvent(QHideEvent *e) {
 
 void DictManagerWidget::addNewDictButtonClicked() {
     #ifndef Q_WS_MAEMO_5
-    qDebug()<<"1 "<<_changed;
     if(!_changed || QMessageBox::question(this,
             tr("Save"), tr("Do you want to save changes?"),
             QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
-        qDebug()<<"2";
         _save = true;
         saveChanges();
         _save = false;
@@ -335,10 +336,14 @@ void DictManagerWidget::changed() {
 
 
 #ifndef Q_WS_MAEMO_5
-    void DictManagerWidget::save() {
-        _save = true;
-        hide();
-    }
+void DictManagerWidget::save() {
+    _save = true;
+    hide();
+}
+
+void DictManagerWidget::setFocusOnElement(){
+    Q_EMIT setFocusOnQML();
+}
 #endif
 
 
index 15befcb..5565265 100644 (file)
@@ -78,11 +78,17 @@ Q_SIGNALS:
     */
     void removeDictionary(CommonDictInterface*);
 
+#ifndef Q_WS_MAEMO_5
+    //! emits when dict manager gain focus
+    void setFocusOnQML();
+#endif
+
 
 public Q_SLOTS:
 
     #ifndef Q_WS_MAEMO_5
         void save();
+        void setFocusOnElement();
     #endif
 
 private Q_SLOTS:
index bf61dd2..abe5552 100644 (file)
@@ -52,6 +52,7 @@ DictTypeSelectDialog::DictTypeSelectDialog(QList<CommonDictInterface *> plugins,
             this, SLOT(pluginSelected(int)));
 
     qmlView->setResizeMode(QDeclarativeView::SizeRootObjectToView);
+//    qmlView->setFocus();
     verticalLayout->addWidget(qmlView);
 
 #endif
index 21990b6..5244664 100644 (file)
@@ -114,6 +114,17 @@ void WordListModel::setModelProperty(int index, const QVariant value, QString ro
     }
 }
 
+void WordListModel::setModelPropertyByIndex(int index, QString role)
+{
+    if (role.contains("isBookmarked"))
+    {
+        if (index < 0 || index > _translations.count() - 1)
+            return;
+
+        setDataPriv(index, !_wordInBookmarks[_wordList[index]], IsBookmarkedRole);
+    }
+}
+
 int WordListModel::setDataPriv(int index, const QVariant &value, int role)
 {
     if (index < 0 || index > _translations.count() - 1)
@@ -156,3 +167,8 @@ void WordListModel::setBookmarkModeActive(bool mode)
 {
     _isBookmarkModeActive = mode;
 }
+
+QString WordListModel::wordOnPosition(int index)
+{
+    return _wordList[index];
+}
index 38771d3..67ec197 100644 (file)
@@ -35,6 +35,8 @@ public:
     //! Clear model data and refresh UI
     void clear();
 
+    QString wordOnPosition(int index);
+
     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
 
 signals:
@@ -53,6 +55,13 @@ public slots:
       */
     void setModelProperty(int index, const QVariant value, QString role);
 
+    //! Reverse value at role in index row of data.
+    /*!
+      \param index word position in data list
+      \param role role name
+      */
+    void setModelPropertyByIndex(int index, QString role);
+
 private:
     int setDataPriv(int index, const QVariant &value, int role);
     void addWord(QString word, QList<Translation*> translations, bool isBookmarked);
index 37eae2f..acd9660 100644 (file)
@@ -75,6 +75,7 @@ WordListWidget::WordListWidget(QWidget *parent):
     verticalLayout->addWidget(qmlView);
 
     connect(rootObject, SIGNAL(wordSelected(QString)), this, SLOT(wordClicked(QString)));
+    connect(rootObject, SIGNAL(wordSelectedByIndex(int)), this, SLOT(wordClickedByIndex(int)));
     connect(listModel, SIGNAL(addToBookmarks(QString)), this, SLOT(addToBookmarks(QString)));
     connect(listModel, SIGNAL(removeFromBookmarks(QString)), this, SLOT(removeFromBookmarks(QString)));
 
@@ -97,15 +98,10 @@ WordListWidget::WordListWidget(QWidget *parent):
 
 
 WordListWidget::~WordListWidget() {
+#ifdef Q_WS_MAEMO_5
     if(proxyStyle)
         delete proxyStyle;
-}
-
-void WordListWidget::setFocusOnElement(){
-    setFocus();
-    qmlView->setFocus();
-    Q_EMIT setFocusOnQML();
-    qDebug()<<hasFocus()<<" "<<qmlView->hasFocus();
+#endif
 }
 
 void WordListWidget::addWord(QString word, int row) {
@@ -259,23 +255,7 @@ void WordListWidget::wordChecked(QModelIndex index) {
         }
     }
 }
-#else
-    void WordListWidget::wordClicked(QString word){
-        emit showTranslation(searchResult[word]);
-    }
-
-    void WordListWidget::addToBookmarks(QString word){
-        emit addBookmark(searchResult[word]);
-    }
-
-    void WordListWidget::removeFromBookmarks(QString word){
-        emit removeBookmark(searchResult[word]);
-    }
-
-#endif
 
-
-#ifdef Q_WS_MAEMO_5
 void WordListWidget::mouseReleaseEvent(QMouseEvent *event) {
 
     //firstly we normally handle this event
@@ -317,6 +297,29 @@ void WordListWidget::keyPressEvent(QKeyEvent *event) {
         wordClicked(selectedIndexes().at(0));
     }
 }
+#else
+    void WordListWidget::wordClicked(QString word){
+        emit showTranslation(searchResult[word]);
+    }
+
+    void WordListWidget::addToBookmarks(QString word){
+        emit addBookmark(searchResult[word]);
+    }
+
+    void WordListWidget::removeFromBookmarks(QString word){
+        emit removeBookmark(searchResult[word]);
+    }
+
+    void WordListWidget::wordClickedByIndex(int index){
+        emit showTranslation(searchResult[listModel->wordOnPosition(index)]);
+    }
+
+    void WordListWidget::setFocusOnElement(){
+        setFocus();
+        qmlView->setFocus();
+        Q_EMIT setFocusOnQML();
+    }
+
 #endif
 
 void WordListWidget::resizeColumns() {
index 7128410..f37d176 100644 (file)
@@ -64,7 +64,10 @@ Q_SIGNALS:
 
     void setWordListState(QVariant state);
     void setWordListEmpty(QVariant state);
+
+#ifndef Q_WS_MAEMO_5
     void setFocusOnQML();
+#endif
 
 
 public Q_SLOTS:
@@ -85,7 +88,9 @@ public Q_SLOTS:
 
     void bookmarkModeActive();
 
+#ifndef Q_WS_MAEMO_5
     void setFocusOnElement();
+#endif
 
 protected:
 #ifdef Q_WS_MAEMO_5
@@ -110,8 +115,20 @@ private Q_SLOTS:
     //! Signal is emitted only when a star was clicked.
     void wordChecked(QModelIndex index);
 #else
+    //! Emits signal to show translation of clicked item. Signal is emitted
+    //! only when a word was clicked.
     void wordClicked(QString word);
+
+    //! Emits signal to show translation of clicked item. Signal is emitted
+    //! only when a word was clicked.
+    void wordClickedByIndex(int index);
+
+    //! Emits signal to show add word from bookmarks.
+    //! Signal is emitted only when a star was clicked.
     void addToBookmarks(QString word);
+
+    //! Emits signal to show remove word from bookmarks.
+    //! Signal is emitted only when a star was clicked.
     void removeFromBookmarks(QString word);
 #endif
 
index df43918..bf9c2f0 100644 (file)
@@ -36,6 +36,10 @@ Rectangle {
         rectangle1.setEnableSettings(true)
     }
 
+    function setFocus() {
+        dictList.setFocus()
+    }
+
     signal addButtonClicked;
     signal removeButtonClicked;
     signal settingsButtonClicked;
@@ -54,6 +58,29 @@ Rectangle {
         anchors.bottom: buttonsBox.top
         anchors.bottomMargin: buttonsBox.height + buttonsBox.anchors.topMargin
         highlightResizeSpeed: 1000
+
+        Keys.onPressed: {
+            if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                itemActivated(currentIndex)
+            }
+            if ((event.key == Qt.Key_Delete) && currentIndex >= 0){
+                removeButtonClicked()
+            }
+            if (event.key == Qt.Key_S && event.modifiers == Qt.ControlModifier){
+                saveButtonClicked()
+            }
+            if (event.key == Qt.Key_T && event.modifiers == Qt.ControlModifier){
+                addButtonClicked()
+            }
+            if ((event.key == Qt.Key_Space) && currentIndex >= 0){
+                dictModel.setModelProperty(dictList.currentIndex, "isSelected")
+            }
+        }
+
+        onCurrentIndexChanged: {
+            dictModel.itemSelected(dictList.currentIndex)
+        }
+
         delegate: Component{
             id: dictListDelegate
             Item {
@@ -70,7 +97,6 @@ Rectangle {
                         dictList.currentIndex = number
                         rectangle1.setEnableRemove(true)
                         rectangle1.setEnableSettings(true)
-                        dictModel.itemSelected(dictList.currentIndex)
                     }
                     onDoubleClicked: {
                         rectangle1.itemActivated(dictList.currentIndex)
index ac20bfe..288b1a9 100644 (file)
@@ -27,12 +27,21 @@ import Qt 4.7
 Rectangle {
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
     signal selectedRow(int nr)
+    function setFocus() {
+        dictTypeList.setFocus()
+    }
 
     id: rectangle1
     color: myPalette.base
     anchors.fill: parent
 
     ElementsListView{
+        Keys.onPressed: {
+            if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                selectedRow(currentIndex)
+            }
+        }
+
         id: dictTypeList
         width: rectangle1.width
         height: rectangle1.height
index fa53b93..7181055 100644 (file)
@@ -32,20 +32,7 @@ ListView {
     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)
-        }
     }
 
 }
index 145ad89..742cf49 100644 (file)
@@ -27,23 +27,22 @@ import Qt 4.7
 Rectangle {
 
     function changeWordState(nr, state) {
-        console.log("LOOOOOL")
         wordList.currentIndex = nr
         wordModel.setModelProperty(wordList.currentIndex, state, "isBookmarked")
+    }
 
+    function changeWordStateByIndex() {
+        wordModel.setModelPropertyByIndex(wordList.currentIndex, "isBookmarked")
     }
 
     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);
+    signal wordSelectedByIndex(int nr);
 
     SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }
 
@@ -59,8 +58,12 @@ Rectangle {
         highlightResizeSpeed: 1000
         property bool empty: false
 
-        onCurrentIndexChanged: {
-            console.log("111!!!WTF " + currentIndex)
+        Keys.onPressed: {
+            if (event.key == Qt.Key_Space && currentIndex >= 0){
+                rectangle1.changeWordStateByIndex();
+            } else if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && currentIndex >= 0){
+                rectangle1.wordSelectedByIndex(currentIndex)
+            }
         }
 
         delegate: Component{
@@ -77,7 +80,7 @@ Rectangle {
                 MouseArea{
                     anchors.fill: parent
                     onClicked: {
-                        wordList.currentIndex = index// number
+                        wordList.currentIndex = index
                         rectangle1.wordSelected(word)
                     }
                 }