starDict dialog in qml
[mdictionary] / src / plugins / stardict / StarDialog.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 StarDialog.h
23     \brief Implementation of stardict plugin's dialogs.
24
25     \author Mateusz Półrola <mateusz.polrola@gmail.com>
26 */
27
28 #ifndef STARDIALOG_H
29 #define STARDIALOG_H
30
31 #include <QDialog>
32 #include "../../include/settings.h"
33 #include <QtGui>
34 #include <QDeclarativeView>
35 #include "StarDictPlugin.h"
36
37
38 /*!
39     This class can create dialogs for adding a new dictionary or changing settings
40     of an existing one, based on dialog type passed to contructor.
41     When adding a new dictionary dialog contains a button to browse file system and
42     select a dictionary file. When changing settings dialog displays basic
43     information about dictionary i. e. name, languages and license info.
44     All contents of a dialog are in a scroll area.
45 */
46 class StarDialog : public QDialog
47 {
48     Q_OBJECT
49 public:
50     /*!
51         Describes type of dialog. New means that dialog contains widgets to browse
52         file system and select dictionary file. Change means that dialog displays
53         information about dictionary.
54         In both types dialog provides widgets to create or delete cache and remove
55         or keep accents.
56     */
57     enum StarDialogType {New, Change};
58
59     //! Constructor
60     /*!
61         Creates new StarDict dialog
62         \param plugin if created dialog is of type Change it must be set to
63             point to plugin whose settings will be changed
64         \param type describes type of created dialog
65         \param parent parent widget of created dialog
66     */
67     explicit StarDialog(StarDictPlugin* plugin = 0,
68                         StarDialogType type = New,
69                         QWidget* parent = 0);
70
71     /*!
72         After acceptance of dialog this method returns plugin's settings based on
73         user's choices in dialog.
74         \returns settings of plugin
75     */
76     Settings* getSettings();
77
78 Q_SIGNALS:
79     //! Requests to show notification
80     void notify(Notify::NotifyType, QString);
81
82     void setInfo(QVariant info);
83     void setButtonText(QVariant text);
84     void setNew(QVariant text);
85     void setPath(QVariant path);
86
87 public Q_SLOTS:
88     /*!
89         Reimplemented accept method, to check if all necessary fields in
90         dialog are correct e. g. dictionary file path
91         and saves new settings
92     */
93     void accept();
94
95
96
97 private Q_SLOTS:
98     void resizeEvent(QResizeEvent *e);
99
100     //! displays dialog to browse and select file
101     void selectFile();
102
103     void heightChange(int height);
104
105 private:
106     QVBoxLayout* mainLayout;
107     QDeclarativeView *view;
108     int lastHeight;
109
110     //! create a user interface
111     void initializeUI();
112
113     //! saves new settings after acceptance of dialog
114     void saveSettings();
115
116     //! check that files is compressed
117     bool checkFiles();
118
119     QLabel* infoLabel;
120     QPushButton* browseButton;
121     QHBoxLayout* browseLayout;
122
123     QPushButton* confirmButton;
124     QString _dictionaryFilePath;
125     QScrollArea* scrollArea;
126     QWidget* widget;
127     QHBoxLayout* layout;
128     QVBoxLayout* mainVerticalLayout;
129     bool _isCompressed;
130     QString _dictName;
131
132     Settings* _settings;
133
134     StarDictPlugin* plugin;
135     StarDialogType type;
136 };
137
138 #endif // STARDIALOG_H