qml ComboBox component and GoogleDialog complete
[mdictionary] / src / plugins / google / GoogleDialog.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 GoogleDialog.h
23     \brief Implementation of google plugin's dialogs.
24
25     \author Mateusz Półrola <mateusz.polrola@gmail.com>
26     \author Jakub Jaszczynski <j.j.jaszczynski@gmail.com>
27 */
28
29 #ifndef GOOGLEDIALOG_H
30 #define GOOGLEDIALOG_H
31
32 #include <QDialog>
33 #include "../../include/settings.h"
34 #include "../../include/ComboBoxModel.h"
35 #include <QtGui>
36
37
38 #include <QDeclarativeView>
39 #include <QDeclarativeContext>
40 #include <QList>
41
42 #include "GooglePlugin.h"
43
44 /*!
45     This class can create dialogs for adding a new dictionary or changing settings
46      of an existing one, based on dialog type passed to constructor.
47      These types differ only in confirm button label.
48      Both provide comboboxes with available languages to choose.
49 */
50 class GoogleDialog : public QDialog
51 {
52     Q_OBJECT
53 public:
54     /*!
55       Describes type of dialog. New means that dialog confirm button has
56         "Add" label, Change means that dialog confirm button has "Save settings" label.
57     */
58     enum GoogleDialogType {New, Change};
59
60     //! Constructor
61     /*!
62         Creates new google dialog
63         \param plugin if created dialog is of type Change it must be set to
64             point to plugin whose settings will be changed
65         \param type describes type of created dialog
66         \param parent parent widget of created dialog
67     */
68     explicit GoogleDialog(GooglePlugin* plugin = 0,
69                           GoogleDialogType type = New,
70                           QWidget* parent = 0);
71
72     //! \returns settings of plugin
73     /*!
74         After acceptance of dialog this method returns plugin's settings based on
75          user's choices in dialog.
76     */
77     Settings* getSettings();
78
79 Q_SIGNALS:
80     //! requests to show notification
81     void notify(Notify::NotifyType, QString);
82
83 #ifndef Q_WS_MAEMO_5
84     void setInfo(QVariant info);
85     void setNew(QVariant text);
86     void setStartValues(QVariant from, QVariant to, QVariant fromIndex, QVariant toIndex);
87 #endif
88
89 public Q_SLOTS:
90 #ifdef Q_Ws_MAEMO_5
91     //! reimplemented accept method, to save new settings
92     void accept();
93 #endif
94
95 private Q_SLOTS:
96     //! assigns the language chosen from a list(langFromComboBox) to _langFrom
97     void langFromChanged(int);
98
99     //! assigns the language chosen from a list(langToComboBox) to _langTo
100     void langToChanged(int);
101
102     //! handles the "swap languages" button
103     void changeLangButtonClicked();
104
105
106 #ifndef Q_Ws_MAEMO_5
107     void saveButtonClicked(QString langFrom, QString langTo);
108 #endif
109
110 private:
111
112     void initializeUI();
113
114     //! saves new settings after acceptance of dialog
115 #ifdef Q_Ws_MAEMO_5
116     void saveSettings();
117 #else
118     void saveSettings(QString langFrom, QString langTo);
119
120     ComboBoxModel* model;
121     QVBoxLayout* mainLayout;
122     QDeclarativeView *view;
123     QDeclarativeContext* ctxt;
124 #endif
125
126     int lastHeight;
127
128     QLabel* infoLabel;
129     QLabel* langFromLabel;
130     QLabel* langToLabel;
131     QLabel* connectInfoLabel;
132     QPushButton* confirmButton;
133     QPushButton* changeLangButton;
134     QComboBox *langFromComboBox;
135     QComboBox *langToComboBox;
136     QVBoxLayout* verticalLayout;
137     QVBoxLayout* langLayout;
138     QFormLayout* langsFormLayout;
139     QHBoxLayout* changeLangLayout;
140     QString _langFrom;
141     QString _langTo;
142     int _actualLangTo;
143     int _actualLangFrom;
144
145     Settings* _settings;
146     GooglePlugin* plugin;
147     GoogleDialogType type;
148 };
149
150 #endif // GOOGLEDIALOG_H