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