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