Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / mdictionary / gui / WordListWidget.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21 /*! \file WordListwidget.h
22     \brief Displays list of words found in dictionaries
23
24     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
25 */
26
27 #ifndef WORDLISTWIDGET_H
28 #define WORDLISTWIDGET_H
29
30 #include <QtGui>
31 #include <QStringListModel>
32 #include "../backbone/backbone.h"
33 #include "WordListProxyStyle.h"
34
35 /*!
36     It allows user to select word to see its translation or to mark or unmark
37     it as "star" (add/remove from bookmarks). It inherits from QTreeView
38     to allow to display two columns, one with words and second with stars.
39     Star is normal checkable item. To get effect of star we need to set
40     style (WordListProxyStyle) for this widget.
41   */
42 class WordListWidget : public QTreeView {
43     Q_OBJECT
44 public:
45     explicit WordListWidget(QWidget *parent = 0);
46     ~WordListWidget();
47
48
49 Q_SIGNALS:
50     //! Requests to show translation which is described by passed translations
51     //! objects
52     void showTranslation(QList<Translation*>);
53
54
55     //! Requests to add selected word to bookmarks
56     void addBookmark(QList<Translation*>);
57
58     //! Requests to remove selected word from bookmarks
59     void removeBookmark(QList<Translation*>);
60
61
62 public Q_SLOTS:
63     //! Shows search results
64     /*!
65       \param hash of found words and its translations objects
66     */
67     void showSearchResults(QHash<QString, QList<Translation*> >);
68
69     //! Locks words list, while backbone is doing something in background
70     void lockList();
71
72     //! Unlocks words list
73     void unlockList();
74
75     //! clears list
76     void clear();
77
78 protected:
79     //! Reimplemented standard mouseReleaseEvent to check if user clicked on
80     //! a word or on its star to emit suitable signal
81     void mouseReleaseEvent(QMouseEvent *event);
82
83     //! Resizes the size of columns to assure that stars are always on right
84     //! side next to scroll bar
85     void resizeEvent(QResizeEvent *event);
86
87     //! Checks if user press return and if so displays translation of selected word
88     void keyPressEvent( QKeyEvent * event);
89
90 private Q_SLOTS:
91     //! Emits signal to show translation of clicked item. Signal is emitted
92     //! only when a word was clicked.
93     void wordClicked(QModelIndex index);
94
95     //! Emits signal to show add or remove word from bookmarks.
96     //! Signal is emitted only when a star was clicked.
97     void wordChecked(QModelIndex index);
98
99
100
101 private:
102     //! Adds word to model. Row is row in the model
103     void addWord(QString word, int row);
104
105     QStandardItemModel* model;
106
107     //! Describes width of a star checkbox in pixels
108     int checkBoxWidth;
109
110     //! Resizes sizes of colums after adding new words or after resize event.
111     void resizeColumns();
112
113     //! Association between words and their translations
114     QHash<QString, QList<Translation*> > searchResult;
115     WordListProxyStyle* proxyStyle;
116 };
117
118 #endif // WORDLISTWIDGET_H