Fix bug with app crash on exit. Add keyboard support in wordList, DictTypeSelectDialo...
[mdictionary] / src / mdictionary / gui / DictManagerWidget.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
22 /*! \file DictManagerWidget.h
23     \brief Implements dictionaries management widget
24
25     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 */
27
28 #ifndef DICTMANAGERWIDGET_H
29 #define DICTMANAGERWIDGET_H
30
31 #include <QWidget>
32 #include <QtGui>
33 #include "../../include/GUIInterface.h"
34 #include "MenuWidget.h"
35 #include "DictManagerModel.h"
36 #include <QtDeclarative/QDeclarativeView>
37 #include <QtDeclarative/QDeclarativeContext>
38
39
40 /*!
41   Shows list of loaded dictionaries and their states (active/inactive).
42   It allows to change dicts states, add a new dict, remove selected one or
43   change settings of selected dict. All changes are saved automatically after
44   hiding of this widget.
45 */
46 class DictManagerWidget : public QDialog {
47     Q_OBJECT
48 public:
49     //! Constructor
50     /*!
51       \param parent parent of this widget, which must be a subclass of
52       GUIInterface, because it will use it to get info about loaded plugins
53       and dicts.
54     */
55     explicit DictManagerWidget(GUIInterface *parent = 0);
56
57 protected:
58     void showEvent(QShowEvent *e);
59     void hideEvent(QHideEvent *e);
60     void keyPressEvent(QKeyEvent *e);
61
62 Q_SIGNALS:
63     //! Emitted when hiding widget, it will save states of dictionaries
64     /*!
65         \param list of only active dictionaries
66     */
67     void selectedDictionaries(QList<CommonDictInterface*>);
68
69     //! Emitted when user wants to add a new dictionary
70     /*!
71         \param new dictionary returned by specific plugin dialog
72     */
73     void addDictionary(CommonDictInterface*);
74
75     //! Emitted when user wants to remove a dictionary
76     /*!
77         \param dictionary which will be removed
78     */
79     void removeDictionary(CommonDictInterface*);
80
81 #ifndef Q_WS_MAEMO_5
82     //! emits when dict manager gain focus
83     void setFocusOnQML();
84 #endif
85
86
87 public Q_SLOTS:
88
89     #ifndef Q_WS_MAEMO_5
90         void save();
91         void setFocusOnElement();
92     #endif
93
94 private Q_SLOTS:
95     /*! Shows "plugin select" dialog and then plugin specific "add a new dictionary"
96         dialog, which will return new CommonDictInterface* object, which is
97         later passed as a parameter of addDictionary signal*/
98     void addNewDictButtonClicked();
99
100     /*! Passes dictionary selected from a list as a parameter of removeDictionary
101         signal */
102     void removeButtonClicked();
103
104     //! user selects one of items
105     void itemSelected(QListWidgetItem*);
106
107     //! Shows plugin's settings dialog
108     void settingsButtonClicked();
109
110     //! Each change of state (that needs to be saved) should call this to
111     //! indicate state change
112     void changed();
113
114     //! saves changes
115     void saveChanges();
116
117 private:
118     void initalizeUI();
119     QPushButton* addNewDictButton;
120     QPushButton* removeDictButton;
121     QPushButton* settingsButton;
122
123     QVBoxLayout* verticalLayout;
124     QHBoxLayout* buttonGroup;
125     QListWidget* dictList;
126
127     //holds association between items on list and CommonDictInterface objects
128     QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
129     GUIInterface* guiInterface;
130
131     #ifndef Q_WS_MAEMO_5
132     QDeclarativeView* qmlView;
133     QDeclarativeContext* ctxt;
134     DictManagerModel* model;
135     #endif
136
137     bool _changed;
138
139     void refreshDictsList();
140
141     #ifndef Q_WS_MAEMO_5
142         QPushButton* closeButton;
143         bool _save;
144     #endif
145 };
146
147 #endif // DICTMANAGERWIDGET_H