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