cc6d72e0c21155d5306e720793a174cf3e1d5163
[mdictionary] / trunk / src / base / 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 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
23
24 #ifndef WORDLISTWIDGET_H
25 #define WORDLISTWIDGET_H
26
27 #include <QtGui>
28 #include <QStringListModel>
29 #include "../backbone/backbone.h"
30
31 //! Displays list of words found in dictionaries
32 /*!
33     It allows user to select word to see its translation or to mark or unmark
34     it as "star" (add/remove from bookmarks). It inherits from QTreeView
35     to allow to display two columns, one with words and second with stars.
36     Star is normal checkable item. To get effect of star we need to set
37     style (WordListProxyStyle) for this widget.
38   */
39 class WordListWidget : public QTreeView {
40     Q_OBJECT
41 public:
42     explicit WordListWidget(QWidget *parent = 0);
43
44
45 Q_SIGNALS:
46     //! Requests to show translation which is described by passed translations
47     //! objects
48     void showTranslation(QList<Translation*>);
49
50
51     //! Requests to add selected word to bookmarks
52     void addBookmark(QList<Translation*>);
53
54     //! Requests to remove selected word from bookmarks
55     void removeBookmark(QList<Translation*>);
56
57
58 public Q_SLOTS:
59     //! Shows search results
60     /*!
61       \param hash of found words and its translations objects
62     */
63     void showSearchResults(QHash<QString, QList<Translation*> >);
64
65     //! Locks words list, while backbone is doing something in background
66     void lockList();
67
68     //! Unlocks words list
69     void unlockList();
70
71 protected:
72     //! Reimplemented standard mouseReleaseEvent to check if user clicked on
73     //! word or on its star to emit suitable signal
74     void mouseReleaseEvent(QMouseEvent *event);
75
76     //! Resizes the size of columns to assure that stars are always on right
77     //! side next to scroll bar
78     void resizeEvent(QResizeEvent *event);
79
80 private Q_SLOTS:
81     //! Emits signal to show translation of clicked item. Signal is emitted
82     //! only when word was clicked.
83     void wordClicked(QModelIndex index);
84
85     //! Emits signal to show add or remove word from bookmarks.
86     //! Signal is emitted only when star was clicked.
87     void wordChecked(QModelIndex index);
88
89     //! clears list
90     void clear();
91
92 private:
93     //! Adds word to model. Row is row in the model
94     void addWord(QString word, int row);
95
96     QStandardItemModel* model;
97
98     //! Describes width of star checkbox in pixels
99     int checkBoxWidth;
100
101     //! Resizes sizes of colums after adding new words or after resize event.
102     void resizeColumns();
103
104     //! Association between words and their translations
105     QHash<QString, QList<Translation*> > searchResult;
106 };
107
108 #endif // WORDLISTWIDGET_H