Added welcome screen
[mdictionary] / trunk / src / base / gui / MainWindow.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 MainWindow.h
22 //! \brief Implements interface for GUI
23 //! \author Mateusz Półrola <mateusz.polrola@comarch.pl>
24
25 #ifndef MAINWINDOW_H
26 #define MAINWINDOW_H
27
28 #include <QMainWindow>
29 #include "../../includes/GUIInterface.h"
30 #include "../../includes/settings.h"
31 #include "../backbone/backbone.h"
32 #include "TranslationWidget.h"
33 #include "WordListWidget.h"
34 #include "SearchBarWidget.h"
35 #include "MenuWidget.h"
36 #include "DictManagerWidget.h"
37 #include "SettingsWidget.h"
38 #include "HistoryListDialog.h"
39 #include "BookmarksWidget.h"
40 #include "WelcomeScreenWidget.h"
41
42 namespace Ui {
43     class MainWindow;
44 }
45
46 //! Implements interface for GUI
47 /*!
48   Create all of GUI subcomponents, and connects all GUI interface signals with
49   suitable backbone signals and slots. Only this class has direct access to
50   backbone object. It manages all request of subcomponents e. g. searching of
51   given word, displaying history, removing dictionary.
52   It also provide data from backbone to subcomponents e. g. result of search.
53 */
54 class MainWindow : public GUIInterface
55 {
56     Q_OBJECT
57
58 public:
59     //! Constructor
60     /*!
61       \param backbone object which will doing all searches and returns data
62       \param parent parent widget of this window
63       */
64
65     explicit MainWindow(Backbone* backbone, QWidget *parent = 0);
66     ~MainWindow();
67
68     //! Returns all loaded dictionaries with infromation about that they are
69     //! active/inactive
70     /*!
71         \return Hash of pointers to dictionary and boolean flag indicating if
72         dictionary is active
73      */
74     QHash<CommonDictInterface*, bool> getDictionaries();
75
76     //! Returns all loaded plugins
77     /*!
78         \return List of pointers to plugins
79      */
80     QList<CommonDictInterface*> getPlugins();
81
82     //! Indicates if GUI is in exact search mode.
83     /*! When GUI is in exact search mode it search for word, and
84         if find exacly matching translation it directly displays it, whithout
85         displaying matching word list. This mode is used for browsing search
86         history and search words from application arguments.
87         \returns flag indicating if GUI is in exact search mode
88     */
89     bool exactSearch();
90
91     //! Sets GUI exact search mode.
92     /*! When GUI is in exact search mode it search for word, and
93         if find exacly matching translation it directly displays it, whithout
94         displaying matching word list. This mode is used for browsing search
95         history and search words from application arguments.
96         \param exactSearch flag indicating if GUI will be in exact search mode
97         \sa exactSearch()
98     */
99     void setExactSearch(bool);
100
101     Settings* settings();
102
103     void setSettings(Settings*);
104
105
106  public Q_SLOTS:
107     //! Search in exact mode for given word
108     /*!
109       GUI will be automaticaly set into exact search mode, and after search or
110       break will be unset from exact search mode.
111       \param word which will be searched in dictionaries
112       */
113     void searchExact(QString);
114
115
116     //! Gets word list from backbone and prepares received list to display
117     /*!
118       Checks if received list is empty, in that case displays suitable
119       information. If GUI is in exact search mode it will search for exact
120       word in received list, and if word is found it will emit signal to
121       display it's translation. Otherwise it will display list of matching
122       words and show suitable information.
123       \sa exactSearch()
124       \sa showTranslation()
125      */
126     void wordListReady();
127
128     //! Gets translation strings from backbone and emit signal to display them
129     void translationsReady();
130
131     //! Adds to history key words from given translations
132     /*!
133       By default this slot is connected to signal searchTranslations, and
134       passed translation list contains only translation with the same key, so
135       only one word is added to history.
136       \param list of translations with key words
137       \sa searchTranslations()
138       */
139     void addToHistory(QList<Translation*>);
140
141     //! Shows history dialog
142     void showHistory();
143
144     //! Shows translation of next word in history
145     /*!
146       It will work only if there is available next word in history.
147       Translation of word is searched with searchExact() function
148       \sa searchExact()
149       */
150     void historyNext();
151
152     //! Shows translation of previous word in history
153     /*!
154       It will work only if there is available previous word in history.
155       Translation of word is searched with searchExact() function
156       \sa searchExact()
157       */
158     void historyPrev();
159
160 private Q_SLOTS:
161     //! Sets string for which current search is ongoing, is used to find exact
162     //! word when GUI is in search exact mode.
163     void setSearchString(QString);
164
165     //! Disables menu when search is ongoing
166     void disableMenu();
167
168     //! Enables menu
169     void enableMenu();
170
171     //! When user break searching it make sure that exact search mode will be
172     //! disabled
173     void breakSearching();
174
175
176     void showAllBookmarks();
177
178
179 protected:
180     /*! When user wants to close application, we first sends signal to stop all
181         ongoing searches.
182     */
183     void closeEvent(QCloseEvent *);
184
185
186 private:
187     Backbone* backbone;
188     Ui::MainWindow *ui;
189
190     void initializeUI();
191
192
193     SearchBarWidget* searchBarWidget;
194     QWidget* translationWidget;
195     QWidget* wordListWidget;
196     MenuWidget* menuWidget;
197     QMenu* menu;
198     DictManagerWidget* dictManagerWidget;
199     SettingsWidget* settingsWidget;
200     BookmarksWidget* bookmarksWidget;
201     QWidget* welcomeScreenWidget;
202
203     #ifndef Q_WS_MAEMO_5
204         QSplitter* splitter;
205         QAction* dictionariesAction;
206         QAction* bookmarksAction;
207         QAction* settingsAction;
208         //QAction* aboutAction;
209     #endif
210
211     bool _exactSearch;
212     QString searchString;
213
214
215     void connectBackbone();
216     void connectSearchBar();
217     void connectWordList();
218     void connectTranslationWidget();
219     void connectDictManager();
220     void connectMenu();
221     void connectBookmarksWidget();
222 };
223
224 #endif // MAINWINDOW_H