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 MainWindow.h
22 \brief Implements interface for GUI
24 \author Mateusz Półrola <mateusz.polrola@comarch.pl>
30 #include <QMainWindow>
31 #include "../../include/GUIInterface.h"
32 #include "../../include/settings.h"
33 #include "../backbone/backbone.h"
34 #include "TranslationWidget.h"
35 #include "WordListWidget.h"
36 #include "SearchBarWidget.h"
37 #include "MenuWidget.h"
38 #include "DictManagerWidget.h"
39 #include "SettingsWidget.h"
40 #include "HistoryListDialog.h"
41 #include "BookmarksWidget.h"
42 #include "WelcomeScreenWidget.h"
43 #include "AboutWidget.h"
44 #include "NotifyManager.h"
48 Creates all of GUI subcomponents, and connects all GUI interface signals
49 with suitable backbone signals and slots.
50 Only this class has direct access to backbone object.
51 It manages all requests of subcomponents e. g. searching for a given word,
52 displaying history, removing a dictionary.
53 It also provides data from backbone to subcomponents e. g. result of search.
55 class MainWindow : public GUIInterface
62 \param backbone backbone object which will be doing all searches and returning data
63 \param parent parent widget of this window
65 MainWindow(Backbone* backbone, QWidget *parent = 0);
68 //! Returns all loaded dictionaries with information if they are
71 \return Hash of pointers to a dictionary and boolean flag indicating if
72 a dictionary is active
74 QHash<CommonDictInterface*, bool> getDictionaries();
76 //! Returns all loaded plugins
78 \return List of pointers to plugins
80 QList<CommonDictInterface*> getPlugins();
82 //! Indicates if GUI is in exact search mode.
83 /*! When GUI is in exact search mode it searches for a word, and if it
84 finds exactly matching translation it displays matching words list
85 and then directly displays translation of first exactly matched word.
86 This mode is used for browsing search history and searching words
87 from application arguments.
88 \returns flag indicating if GUI is in exact search mode
90 \sa setExactSearchString()
92 bool isInExactSearch();
95 //! Returns current application settings.
97 \returns Settings object containing current application settings
102 //! Sets new settings.
104 \param Settings object containing new application settings
106 void setSettings(Settings*);
110 //! Searches in exact mode for a given word
112 GUI will be automatically set into exact search mode, and after search or
113 when user breaks the search it will be unset from exact search mode.
114 \param word which will be searched for in dictionaries
117 void searchExact(QString);
120 //! Searches for a given word
122 It sets passed word in line edit of a search bar and searches for a given word.
123 \param word which will be searched for in dictionaries
127 void search(QString);
129 //! Starts searching for a given word after 500 ms delay
131 After time's up it sets passed word in line edit of search bar and searches
133 \param word which will be searched for in dictionaries
138 void searchDelay(QString);
140 //! Sets string for exact search
142 Sets string for which current search is ongoing, is used to find exact
143 word when GUI is in search exact mode.
145 void setExactSearchString(QString);
147 //! Sets GUI exact search mode.
148 /*! When GUI is in exact search mode it searches for word, and if it
149 finds exactly matching translation it displays matching words list
150 and then directly displays translation of first exactly matched word.
151 This mode is used for browsing search history and searching words
152 from application arguments.
153 \param exactSearch flag indicating if GUI is in exact search mode
154 \sa isInExactSearch()
155 \sa setExactSearchString()
157 void setExactSearch(bool exactSearch);
160 //! Gets word list from backbone and prepares received list to display
162 Checks if received list is empty, in that case it displays suitable
163 information. Otherwise it merges results of the same key word and emits
164 signal to display word list.
165 If GUI is in exact search mode it will search for an exact word in received
166 list and if any of found words match exactly the word passed to
167 searchExact() method.
168 \sa isInExactSearch()
170 \sa showTranslation()
171 \sa setExactSearchString()
173 void wordListReady();
175 //! Gets translation strings from backbone and emits signal to display them
176 void translationsReady();
178 //! Adds key words from given translations to history
180 By default this slot is connected to searchTranslations signal, and
181 passed translation list contains only translations with the same key, so
182 only one word is added to history.
183 \param list of translations with key words
184 \sa searchTranslations()
186 void addToHistory(QList<Translation*>);
188 //! Shows history dialog
190 In maemo it shows dialog with history.
191 In desktop it shows popup containing history, whose bottom edge is on the
192 same height as passed point.
193 \param point on screen where popup has to show
195 void showHistory(QPoint);
197 //! Shows translation of next word in history
199 It will work only if there is next word available in history.
200 Translation of a word is searched for with searchDelay() function.
201 On maemo search is in normal mode, on desktop in exact search mode.
207 //! Shows translation of previous word in history
209 It will work only if there is previous word available in history.
210 Translation of a word is searched for with searchDelay() function.
211 On maemo search is in normal mode, on desktop in exact search mode.
218 //! Shows notification to user
220 It shows different types of notifications such as information, warnings and errors.
221 In maemo they are represented as notes, on desktop as message boxes.
222 \param type type of notification
223 \param message notification message
225 void showNotification(Notify::NotifyType type, QString message);
234 //! When user breaks searching it makes sure that exact search mode will be
236 void searchingInterrupted();
238 //! Asks for confirmation when user clicks on "delete all bookmarks"
239 void removeBookmarks();
243 When user wants to close application, we first send signal to stop all
246 void closeEvent(QCloseEvent *);
253 void initializeSearchWidgets();
254 void initializeMenu();
255 void initializeMenuWidgets();
257 void hideWelcomeScreen();
259 bool checkExactSearch(QHash<QString, QList<Translation*> > searchResult,
260 QList<Translation*> &found);
262 SearchBarWidget* searchBarWidget;
263 QWidget* translationWidget;
264 QWidget* wordListWidget;
265 MenuWidget* menuWidget;
266 DictManagerWidget* dictManagerWidget;
267 SettingsWidget* settingsWidget;
268 BookmarksWidget* bookmarksWidget;
269 QWidget* welcomeScreenWidget;
270 AboutWidget* aboutWidget;
272 QVBoxLayout* mainLayout;
273 NotifyManager* notifyManager;
277 QAction* dictionariesAction;
278 QAction* bookmarksShowAllAction;
279 QAction* bookmarksRemoveAllAction;
280 QAction* settingsAction;
281 QAction* aboutAction;
285 QString searchString;
288 void connectBackbone();
289 void connectSearchBar();
290 void connectWordList();
291 void connectTranslationWidget();
292 void connectDictManager();
294 void connectBookmarksWidget();
297 #endif // MAINWINDOW_H