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