1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
21 /*! \file WordListwidget.h
22 \brief Displays list of words found in dictionaries
24 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
27 #ifndef WORDLISTWIDGET_H
28 #define WORDLISTWIDGET_H
31 #include <QStringListModel>
32 #include <QVBoxLayout>
33 #include "../backbone/backbone.h"
34 #include "WordListProxyStyle.h"
35 #include "WordListModel.h"
36 #include <QtDeclarative/QDeclarativeView>
37 #include <QtDeclarative/QDeclarativeContext>
40 It allows user to select word to see its translation or to mark or unmark
41 it as "star" (add/remove from bookmarks). It inherits from QTreeView
42 to allow to display two columns, one with words and second with stars.
43 Star is normal checkable item. To get effect of star we need to set
44 style (WordListProxyStyle) for this widget.
46 class WordListWidget : public QTreeView {
49 explicit WordListWidget(QWidget *parent = 0);
54 //! Requests to show translation which is described by passed translations
56 void showTranslation(QList<Translation*>);
59 //! Requests to add selected word to bookmarks
60 void addBookmark(QList<Translation*>);
62 //! Requests to remove selected word from bookmarks
63 void removeBookmark(QList<Translation*>);
65 void setWordListState(QVariant state);
69 //! Shows search results
71 \param hash of found words and its translations objects
73 void showSearchResults(QHash<QString, QList<Translation*> >);
75 //! Locks words list, while backbone is doing something in background
78 //! Unlocks words list
86 //! Reimplemented standard mouseReleaseEvent to check if user clicked on
87 //! a word or on its star to emit suitable signal
88 void mouseReleaseEvent(QMouseEvent *event);
90 //! Resizes the size of columns to assure that stars are always on right
91 //! side next to scroll bar
92 void resizeEvent(QResizeEvent *event);
94 //! Checks if user press return and if so displays translation of selected word
95 void keyPressEvent( QKeyEvent * event);
99 //! Emits signal to show translation of clicked item. Signal is emitted
100 //! only when a word was clicked.
101 void wordClicked(QModelIndex index);
103 //! Emits signal to show add or remove word from bookmarks.
104 //! Signal is emitted only when a star was clicked.
105 void wordChecked(QModelIndex index);
107 void wordClicked(QString word);
108 void addToBookmarks(QString word);
109 void removeFromBookmarks(QString word);
114 //! Adds word to model. Row is row in the model
115 void addWord(QString word, int row);
117 QStandardItemModel* model;
119 //! Describes width of a star checkbox in pixels
122 //! Resizes sizes of colums after adding new words or after resize event.
123 void resizeColumns();
125 //! Association between words and their translations
126 QHash<QString, QList<Translation*> > searchResult;
127 WordListProxyStyle* proxyStyle;
130 QVBoxLayout* verticalLayout;
131 QDeclarativeView* qmlView;
132 QDeclarativeContext* ctxt;
133 WordListModel* listModel;
137 #endif // WORDLISTWIDGET_H