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