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