forked from FelixdelasPozas/TrayWeather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigurationDialog.h
294 lines (242 loc) · 8.66 KB
/
ConfigurationDialog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/*
File: ConfigurationDialog.h
Created on: 13/11/2016
Author: Felix de las Pozas Alvarez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef CONFIGURATIONDIALOG_H_
#define CONFIGURATIONDIALOG_H_
// Project
#include <Utils.h>
// Qt
#include "ui_ConfigurationDialog.h"
#include <QDialog>
#include <QNetworkAccessManager>
// C++
#include <memory>
class QNetworkReply;
class QMouseEvent;
/** \class PreviewWidget
* \brief Implements a widget to show a pixmap and close when the mouse leaves it.
*
*/
class PreviewWidget
: public QWidget
{
Q_OBJECT
public:
/** \brief PreviewWidget class constructor.
* \param[in] image Image to show.
* \param[in] parent Raw pointer of the widget parent of this one.
*
*
*/
explicit PreviewWidget(QPixmap image, QWidget* parent = nullptr);
/** \brief PreviewWidget class virtual destructor.
*
*/
virtual ~PreviewWidget()
{};
protected:
virtual void leaveEvent(QEvent *e) override;
};
/** \class ConfigurationDialog
* \brief Implements the dialog to configure the settings.
*
*/
class ConfigurationDialog
: public QDialog
, private Ui_ConfigurationDialog
{
Q_OBJECT
public:
/** \brief LocationConfigDialog class constructor.
* \param[in] configuration application configuration.
* \param[in] parent pointer to the widget parent of this one.
* \param[in] flags window flags.
*/
ConfigurationDialog(const Configuration &configuration, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
/** \brief LocationConfigDialog class virtual destructor.
*
*/
virtual ~ConfigurationDialog()
{};
/** \brief Returns the configuration values.
* \param[out] configuration application configuration values.
*
*/
void getConfiguration(Configuration &configuration) const;
/** \brief Sets the temperature value to use for icon preview.
* \param[in] value Temperature value.
*
*/
void setCurrentTemperature(const int value);
protected:
virtual void showEvent(QShowEvent *e) override;
virtual void changeEvent(QEvent *e) override;
private slots:
/** \brief Manages replies from the network requests.
* \param[in] reply network reply object pointer.
*/
void replyFinished(QNetworkReply *reply);
/** \brief Request IP Geolocation.
*
*/
void requestGeolocation();
/** \brief Request forecast data to test OpenWeatherMap API key validity.
*
*/
void requestOpenWeatherMapAPIKeyTest() const;
/** \brief Disables/Enables geolocation from DNS IP instead of geolocation detected ip.
* \param[in] state DNS Checkbox state.
*
*/
void onDNSRequestStateChanged(int state);
/** \brief Helper method that enables/disables part of the UI depending on the state of the UI radio buttons.
*
*/
void onRadioChanged();
/** \brief Helper method that updates the coordinates labels when one changes.
*
*/
void onCoordinatesChanged();
/** \brief Updates the visual theme of the application when the user changes the theme value.
* \param[in] index Theme combo box index.
*
*/
void onThemeIndexChanged(int index);
/** \brief Opens a color dialog to let the user choose the color for the tray text.
*
*/
void onColorButtonClicked();
/** \brief Helper that checks the values of temperatures spinboxes.
* \param[in] value New value for modified spinbox.
*
*/
void onTemperatureValueChanged(int value);
/** \brief Helper that creates/removes the autostart registry entry depending on
* the value of the parameter.
* \param[in] value True to create and false to remove if it exists.
*
*/
void onAutostartValueChanged(int value);
/** \brief Updates the application translation when the user changes it.
* \param[in] index Current index of language combo box.
*
*/
void onLanguageChanged(int index);
/** \brief Updates the UI when the user changes the measurement units.
* \param[in] index Current index of units combo.
*
*/
void onUnitsValueChanged(int index);
/** \brief Updates the "Selected" property in the combo.
* \param[in] index Current index of the combo.
*
*/
void onUnitComboChanged(int index);
/** \brief Adds the selected tooltip field in the combo to the shown list.
*
*/
void onTooltipTextAdded();
/** \brief Removes the selected tooltip field from the shown list to the combo.
*
*/
void onTooltipTextDeleted();
/** \brief Moves the selected tooltip field up/down in the shown list.
*
*/
void onTooltipTextMoved();
/** \brief Updates the UI when the user moves the tooltip fields.
* \param[in] row Current selected row.
*/
void onTooltipFieldsRowChanged(int row);
/** \brief Show the icon theme summary.
*
*/
void onIconPreviewPressed();
/** \brief Show the temperature icon preview.
*
*/
void onFontPreviewPressed();
/** \brief Displays the font selector dialog and gets the result.
*
*/
void onFontSelectorPressed();
/** \brief Updates the UI when the user changes the icon theme.
* \param[in] idx Current index of icon theme combobox.
*
*/
void onIconThemeIndexChanged(int idx);
/** \brief Updates the temperature icon according to current settings.
*
*/
void updateTemperatureIcon();
/** \brief Updates UI when the icon type changes.
*
*/
void onIconTypeChanged(int);
/** \brief Shows the location finder dialog and gets the results.
*
*/
void onSearchButtonClicked();
signals:
void languageChanged(const QString &);
private:
/** \brief Helper method to fill the configuration values and initilize the UI.
* \param[in] configuration Configuration struct reference.
*
*/
void setConfiguration(const Configuration &configuration);
/** \brief Request DNS IP
*
*/
void requestDNSIPGeolocation();
/** \brief Helper method to connect UI signals to the slots.
*
*/
void connectSignals();
/** \brief Helper method to disconnect UI signals to the slots.
*
*/
void disconnectSignals();
/** \brief Helper method that draws the color interpolation of the range QLabel.
*
*/
void updateRange();
/** \brief Fills the language combo box with the available translations.
* \param[in] current Current language in configuration.
*
*/
void updateLanguageCombo(const QString ¤t);
/** \brief Updates the UI when the user adds/removes fields from the tooltip.
*
*/
void updateTooltipFieldsButtons();
/** \brief Fixes some layout problems that ocurr when changing language or app theme.
*
*/
void fixVisuals();
/** \brief Generates and returns a pixmap for the preview and the font preview button.
* \param[in] font QFont used to generate the pixmap.
*
*/
QPixmap generateTemperatureIconPixmap(QFont &font);
std::shared_ptr<QNetworkAccessManager> m_netManager; /** network manager. */
bool m_testedAPIKey; /** true if the OpenWeatherMap API key has been tested and is valid, false otherwise. */
QString m_DNSIP; /** DNS server IP. */
QFont m_font; /** temperature tray icon font. */
QPixmap m_pixmap; /** checkered pixmap for font preview. */
int m_temp; /** temperature used to generate icon preview if not given. */
bool m_validFont; /** true if current selected font can render the temperature, false otherwise. */
};
#endif // CONFIGURATIONDIALOG_H_