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