fixed wordListWidget acting when word list is empty
authorMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 24 Feb 2011 12:09:54 +0000 (13:09 +0100)
committerMarcin Kaźmierczak <marcin@marcin-desktop.(none)>
Thu, 24 Feb 2011 12:09:54 +0000 (13:09 +0100)
src/mdictionary/gui/WordListModel.cpp
src/mdictionary/gui/WordListModel.h
src/mdictionary/gui/WordListWidget.cpp
src/mdictionary/gui/WordListWidget.h
src/mdictionary/qml/WordListWidget.qml

index 6a167a8..21990b6 100644 (file)
@@ -8,7 +8,7 @@ WordListModel::WordListModel(QObject *parent) :
     roles[IsBookmarkedRole] = "isBookmarked";
     roles[NumberRole] = "number";
     setRoleNames(roles);
-    isBookmarkModeActive = false;
+    _isBookmarkModeActive = false;
 
 }
 
@@ -39,7 +39,7 @@ void WordListModel::clear()
     if (!empty){
         endResetModel();
     }
-    isBookmarkModeActive = false;
+    _isBookmarkModeActive = false;
 }
 
 QVariant WordListModel::data(const QModelIndex &index, int role) const
@@ -133,7 +133,7 @@ int WordListModel::setDataPriv(int index, const QVariant &value, int role)
                 Q_EMIT addToBookmarks(word);
             } else {                
                 Q_EMIT removeFromBookmarks(word);
-                if (isBookmarkModeActive == true){
+                if (_isBookmarkModeActive == true){
                     beginRemoveRows(QModelIndex(), index, index + 1);
                     this->_translations.remove(_wordList[index]);
                     this->_wordInBookmarks.remove(_wordList[index]);
@@ -154,5 +154,5 @@ int WordListModel::setDataPriv(int index, const QVariant &value, int role)
 
 void WordListModel::setBookmarkModeActive(bool mode)
 {
-    isBookmarkModeActive = mode;
+    _isBookmarkModeActive = mode;
 }
index 11e8439..38771d3 100644 (file)
@@ -61,7 +61,7 @@ private:
     QHash<QString, bool > _wordInBookmarks;
     QList<QString> _wordList;
 
-    bool isBookmarkModeActive;
+    bool _isBookmarkModeActive;
 
 };
 
index da98e15..af05ae0 100644 (file)
@@ -35,7 +35,7 @@
 WordListWidget::WordListWidget(QWidget *parent):
     QTreeView(parent) {
 
-    isBookmarkModeActive = false;
+    _isBookmarkModeActive = false;
 
     //creating new model to store words and stars
 #ifdef Q_WS_MAEMO_5
@@ -79,6 +79,7 @@ WordListWidget::WordListWidget(QWidget *parent):
     connect(listModel, SIGNAL(removeFromBookmarks(QString)), this, SLOT(removeFromBookmarks(QString)));
 
     connect(this, SIGNAL(setWordListState(QVariant)), rootObject, SLOT(setEnabled(QVariant)));
+    connect(this, SIGNAL(setWordListEmpty(QVariant)), rootObject, SLOT(setWordListEmpty(QVariant)));
 
 #endif
 
@@ -181,17 +182,20 @@ void WordListWidget::showSearchResults(
     }
 
     if (result.count() == 0){
-        result.insert("!@#$%", QList<Translation*>());
-        wordsInBookmarks.insert("!@#$%", false);
+        //result.insert("!@#$%", QList<Translation*>());
+//        wordsInBookmarks.insert("!@#$%", false);
         Q_EMIT setWordListState(false);
+        Q_EMIT setWordListEmpty(true);
+    } else {
+        Q_EMIT setWordListEmpty(false);
     }
 
     if (listModel == 0){
         listModel = new WordListModel(this);
     }
 
-    listModel->setBookmarkModeActive(isBookmarkModeActive);
-    isBookmarkModeActive = false;
+    listModel->setBookmarkModeActive(_isBookmarkModeActive);
+    _isBookmarkModeActive = false;
     listModel->setTranslations(result, wordsInBookmarks);
 
 #endif
@@ -348,5 +352,5 @@ void WordListWidget::clear() {
 }
 
 void WordListWidget::bookmarkModeActive(){
-    isBookmarkModeActive = true;
+    _isBookmarkModeActive = true;
 }
index 9b293c9..9177529 100644 (file)
@@ -63,6 +63,7 @@ Q_SIGNALS:
     void removeBookmark(QList<Translation*>);
 
     void setWordListState(QVariant state);
+    void setWordListEmpty(QVariant state);
 
 
 public Q_SLOTS:
@@ -128,7 +129,7 @@ private:
     QHash<QString, QList<Translation*> > searchResult;
     WordListProxyStyle* proxyStyle;
 
-    bool isBookmarkModeActive;
+    bool _isBookmarkModeActive;
 
 #ifndef Q_WS_MAEMO_5
     QVBoxLayout* verticalLayout;
index 9670a14..cb972fa 100644 (file)
@@ -33,6 +33,7 @@ Rectangle {
     }
 
     function setEnabled(Boolean) { wordList.enabled = Boolean }
+    function setWordListEmpty(Boolean) { wordList.empty = Boolean }
 
     signal wordSelected(string word);
 
@@ -48,6 +49,7 @@ Rectangle {
 
         anchors.fill: parent
         highlightResizeSpeed: 1000
+        property bool empty: false
 
         delegate: Component{
             id: wordListDelegate
@@ -106,6 +108,26 @@ Rectangle {
 
         }
 
+        Text {
+            id: emptyText
+            anchors.top: parent.top
+            anchors.left: parent.left
+            text: qsTr("Can't find any matching words")
+        }
+
         model: wordModel
+
+        states: [
+            State {
+                name: "empty"
+                when: (wordList.empty == true);
+                PropertyChanges { target: emptyText; visible: true}
+            },
+            State {
+                name: "non-empty"
+                when: (wordList.empty == false);
+                PropertyChanges { target: emptyText; visible: false}
+            }
+        ]
     }
 }