Changed repo structure
[mdictionary] / src / mdictionary / gui / WordListWidget.h
diff --git a/src/mdictionary/gui/WordListWidget.h b/src/mdictionary/gui/WordListWidget.h
new file mode 100644 (file)
index 0000000..cc6d72e
--- /dev/null
@@ -0,0 +1,108 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+//! \file WordListwidget.h
+//! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
+
+#ifndef WORDLISTWIDGET_H
+#define WORDLISTWIDGET_H
+
+#include <QtGui>
+#include <QStringListModel>
+#include "../backbone/backbone.h"
+
+//! Displays list of words found in dictionaries
+/*!
+    It allows user to select word to see its translation or to mark or unmark
+    it as "star" (add/remove from bookmarks). It inherits from QTreeView
+    to allow to display two columns, one with words and second with stars.
+    Star is normal checkable item. To get effect of star we need to set
+    style (WordListProxyStyle) for this widget.
+  */
+class WordListWidget : public QTreeView {
+    Q_OBJECT
+public:
+    explicit WordListWidget(QWidget *parent = 0);
+
+
+Q_SIGNALS:
+    //! Requests to show translation which is described by passed translations
+    //! objects
+    void showTranslation(QList<Translation*>);
+
+
+    //! Requests to add selected word to bookmarks
+    void addBookmark(QList<Translation*>);
+
+    //! Requests to remove selected word from bookmarks
+    void removeBookmark(QList<Translation*>);
+
+
+public Q_SLOTS:
+    //! Shows search results
+    /*!
+      \param hash of found words and its translations objects
+    */
+    void showSearchResults(QHash<QString, QList<Translation*> >);
+
+    //! Locks words list, while backbone is doing something in background
+    void lockList();
+
+    //! Unlocks words list
+    void unlockList();
+
+protected:
+    //! Reimplemented standard mouseReleaseEvent to check if user clicked on
+    //! word or on its star to emit suitable signal
+    void mouseReleaseEvent(QMouseEvent *event);
+
+    //! Resizes the size of columns to assure that stars are always on right
+    //! side next to scroll bar
+    void resizeEvent(QResizeEvent *event);
+
+private Q_SLOTS:
+    //! Emits signal to show translation of clicked item. Signal is emitted
+    //! only when word was clicked.
+    void wordClicked(QModelIndex index);
+
+    //! Emits signal to show add or remove word from bookmarks.
+    //! Signal is emitted only when star was clicked.
+    void wordChecked(QModelIndex index);
+
+    //! clears list
+    void clear();
+
+private:
+    //! Adds word to model. Row is row in the model
+    void addWord(QString word, int row);
+
+    QStandardItemModel* model;
+
+    //! Describes width of star checkbox in pixels
+    int checkBoxWidth;
+
+    //! Resizes sizes of colums after adding new words or after resize event.
+    void resizeColumns();
+
+    //! Association between words and their translations
+    QHash<QString, QList<Translation*> > searchResult;
+};
+
+#endif // WORDLISTWIDGET_H