New xdxf dialog, one which provides methods to add new or change setting of existing...
[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 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 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     void setMenuWidget(MenuWidget *w) {menuWidget = w;}
53
54 protected:
55     void showEvent(QShowEvent *e);
56     void hideEvent(QHideEvent *e);
57
58 Q_SIGNALS:
59     //! Emitted when hiding widget, it will save states of dictionaries
60     /*!
61         \param list of only active dictionaries
62     */
63     void selectedDictionaries(QList<CommonDictInterface*>);
64
65     //! Emitted when user wants to add new dictionary
66     /*!
67         \param new dictionary returned by specific plugin dialog
68     */
69     void addDictionary(CommonDictInterface*);
70
71     //! Emitted when user wants to remove dictionary
72     /*!
73         \param dictionary which will be removed
74     */
75     void removeDictionary(CommonDictInterface*);
76
77
78 public Q_SLOTS:
79
80     #ifndef Q_WS_MAEMO_5
81         void save();
82     #endif
83
84 private Q_SLOTS:
85     /*! Shows "plugin select" dialog and then plugin specific "add new dictionary
86         dialog", which will return new CommonDictInterface* object, which is
87         later passed as parameter of addDictionary signal*/
88     void addNewDictButtonClicked();
89
90     /*! Passes dictionary selected from list as parameter of removeDictionary
91         signal */
92     void removeButtonClicked();
93
94     //! user select one of items
95     void itemSelected(QListWidgetItem*);
96
97     //! Shows plugin's settings dialog
98     void settingsButtonClicked();
99
100     //! Each change of state (that needs to be saved) should call this to
101     //! indicate state change
102     void changed();
103
104     //! saves changes
105     void saveChanges();
106
107 private:
108     void initalizeUI();
109     QPushButton* addNewDictButton;
110     QPushButton* removeDictButton;
111     QPushButton* settingsButton;
112
113     QVBoxLayout* verticalLayout;
114     QHBoxLayout* buttonGroup;
115     QListWidget* dictListWidget;
116
117     //holds association between items on list and CommonDictInterface objects
118     QHash<QListWidgetItem*, CommonDictInterface*> dictsHash;
119     GUIInterface* guiInterface;
120
121     bool _changed;
122
123     void refreshDictsList();
124
125     #ifndef Q_WS_MAEMO_5
126         QPushButton* closeButton;
127         bool _save;
128     #endif
129
130     MenuWidget* menuWidget;
131 };
132
133 #endif // DICTMANAGERWIDGET_H