Merge branch 'master' of ssh://drop.maemo.org/git/mdictionary
[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 //! \brief Implements word list widget
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #ifndef WORDLISTWIDGET_H
26 #define WORDLISTWIDGET_H
27
28 #include <QWidget>
29 #include <QtGui>
30 #include <QStringListModel>
31 #include "../backbone/backbone.h"
32 #include "SearchBarWidget.h"
33
34 //! Displays list of words found in dictionaries
35 /*!
36     It allow user to select word to see it's translation or to mark or unmark
37     it as "star" (add/remove from bookmarks). It inherit from QTreeView
38     to allow 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
47
48 Q_SIGNALS:
49     //! Request to show translation which is described by passed translations
50     //! objects
51     void showTranslation(QList<Translation*>);
52
53
54     //! Request to add selected word to bookmarks
55     void addBookmark(QList<Translation*>);
56
57     //! Request to remove selected word from bookmarks
58     void removeBookmark(QList<Translation*>);
59
60
61 public Q_SLOTS:
62     //! Shows search results
63     /*!
64       \param hash of found words and it's translations objects
65     */
66     void showSearchResults(QHash<QString, QList<Translation*> >);
67
68     //! Lock words list, while backbone is doing somethig in background
69     void lockList();
70
71     //! Unlocks words list
72     void unlockList();
73
74 protected:
75     //! Reimplemented standard mouseReleaseEvent to check if user clicked on
76     //! word on it's star to emit suitable signal
77     void mouseReleaseEvent(QMouseEvent *event);
78
79     //! Resize the size of columns to assure that stars are always on right
80     //! side next to scroll bar
81     void resizeEvent(QResizeEvent *event);
82
83 private Q_SLOTS:
84     //! Emits signal to show translation of clicked item. Signal is emitted
85     //! only when word was clicked.
86     void wordClicked(QModelIndex index);
87
88     //! Emits signal to show add or remove word from bookmarks.
89     //! Signal is emitted only when star was clicked.
90     void wordChecked(QModelIndex index);
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     //! Describes width of star checkbox in pixels
98     int checkBoxWidth;
99
100     //! Resizes sizes of colums after adding new words or after resize event.
101     void resizeColumns();
102
103     //! Association between words and their's translations
104     QHash<QString, QList<Translation*> > searchResult;
105 };
106
107 #endif // WORDLISTWIDGET_H