Updated comments
[mdictionary] / trunk / src / base / gui / WordListWidget.h
index 3112f72..9dc011f 100644 (file)
 
 //! Displays list of words found in dictionaries
 /*!
-    It allow user to select word to see it's translation or to mark it as "star"
+    It allow user to select word to see it's translation or to mark or unmark
+    it as "star" (add/remove from bookmarks). It inherit from QTreeView
+    to allow display two columns, one with words and second with stars.
+    Star is normal checkable item. To get effect of star we need to set
+    style (WordListProxyStyle) for this widget.
   */
-class WordListWidget : public QListWidget {
+class WordListWidget : public QTreeView {
     Q_OBJECT
 public:
     explicit WordListWidget(QWidget *parent = 0);
 
+
 Q_SIGNALS:
     //! Request to show translation which is described by passed translations
     //! objects
     void showTranslation(QList<Translation*>);
 
 
+    //! Request to add selected word to bookmarks
+    void addBookmark(QList<Translation*>);
+
+    //! Request to remove selected word from bookmarks
+    void removeBookmark(QList<Translation*>);
+
+
 public Q_SLOTS:
     //! Shows search results
     /*!
@@ -59,14 +71,36 @@ public Q_SLOTS:
     //! Unlocks words list
     void unlockList();
 
+protected:
+    //! Reimplemented standard mouseReleaseEvent to check if user clicked on
+    //! word on it's star to emit suitable signal
+    void mouseReleaseEvent(QMouseEvent *event);
+
+    //! Resize the size of columns to assure that stars are always on right
+    //! side next to scroll bar
+    void resizeEvent(QResizeEvent *event);
+
 private Q_SLOTS:
-    void wordClicked(QListWidgetItem* item);
-    void wordPressed(QListWidgetItem* item);
+    //! Emits signal to show translation of clicked item. Signal is emitted
+    //! only when word was clicked.
+    void wordClicked(QModelIndex index);
+
+    //! Emits signal to show add or remove word from bookmarks.
+    //! Signal is emitted only when star was clicked.
+    void wordChecked(QModelIndex index);
 
 private:
-    void addWord(QString word);
+    //! Adds word to model. Row is row in the model
+    void addWord(QString word, int row);
+
+    QStandardItemModel* model;
+    //! Describes width of star checkbox in pixels
+    int checkBoxWidth;
+
+    //! Resizes sizes of colums after adding new words or after resize event.
+    void resizeColumns();
 
-    Qt::CheckState itemState;
+    //! Association between words and their's translations
     QHash<QString, QList<Translation*> > searchResult;
 };