Fixed bookmarks removing bug
[mdictionary] / src / mdictionary / gui / WordListWidget.cpp
index e44a839..40b30d1 100644 (file)
@@ -26,6 +26,7 @@
 #include "WordListWidget.h"
 #include "WordListProxyStyle.h"
 #include "../../include/translation.h"
+#include <QKeyEvent>
 
 
 WordListWidget::WordListWidget(QWidget *parent):
@@ -107,6 +108,8 @@ void WordListWidget::showSearchResults(
 
     model->sort(0);
     resizeColumns();    
+
+    setFocus();
 }
 
 void WordListWidget::wordClicked(QModelIndex index) {
@@ -136,6 +139,20 @@ void WordListWidget::wordChecked(QModelIndex index) {
     }
     else {
         Q_EMIT removeBookmark(searchResult[item.data().toString()]);
+
+        Translation* t;
+        bool onlyBookmarks = true;
+        foreach(t, searchResult[item.data().toString()]) {
+            if(t->isBookmark() == 1) {
+                onlyBookmarks = false;
+                t->setBookmark(0);
+            }
+        }
+
+        if(onlyBookmarks) {
+            searchResult.remove(item.data().toString());
+            model->removeRow(item.row());
+        }
     }
 }
 
@@ -177,6 +194,16 @@ void WordListWidget::resizeColumns() {
     setColumnWidth(1, checkBoxWidth);
 }
 
+void WordListWidget::keyPressEvent(QKeyEvent *event) {
+    QTreeView::keyPressEvent(event);
+
+    if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
+        if(selectedIndexes().count() == 0) return;
+
+        wordClicked(selectedIndexes().at(0));
+    }
+}
+
 void WordListWidget::lockList() {
     setEnabled(false);
 }