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