]> git.mar77i.info Git - bigintmandel/blob - settingswidget.h
make zoom_factor part of MandelSettings
[bigintmandel] / settingswidget.h
1
2 /*
3 * settingswidget.h
4 *
5 * This file is covered by the LICENSE file in the root of this project.
6 */
7
8 #ifndef SETTINGSWIDGET_H
9 #define SETTINGSWIDGET_H
10
11 #include <QCheckBox>
12 #include <QDialog>
13 #include <QLineEdit>
14
15 #include "mandel.h"
16 #include "uint64validator.h"
17
18 template <typename T> class TypedLineEdit;
19
20 template <> class TypedLineEdit<quint64> : public QLineEdit {
21 public:
22 explicit TypedLineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {
23 setValidator(new UInt64Validator(this));
24 }
25 inline void set_value(const quint64 &value) {
26 setText(QString::number(value));
27 }
28 inline quint64 get_value() const { return text().toULongLong(); }
29 };
30
31 template <> class TypedLineEdit<int> : public QLineEdit {
32 public:
33 explicit TypedLineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {
34 setValidator(new QIntValidator(this));
35 }
36 inline void set_value(const int &value) {
37 setText(QString::number(value));
38 }
39 inline int get_value() const { return text().toInt(); }
40 };
41
42 template <> class TypedLineEdit<mpz_class> : public QLineEdit {
43 public:
44 explicit TypedLineEdit(QWidget *parent = nullptr) : QLineEdit(parent) {
45 QRegularExpression number_re("^-?\\d+$");
46 setValidator(new QRegularExpressionValidator(number_re, this));
47 }
48 inline void set_value(const mpz_class &value) {
49 setText(QString::fromStdString(value.get_str()));
50 }
51 inline mpz_class get_value() const {
52 return mpz_class(text().toStdString());
53 }
54 };
55
56 class SettingsWidget : public QDialog {
57 Q_OBJECT
58
59 MandelParams orig;
60 TypedLineEdit<quint64> *max_iter;
61 TypedLineEdit<int> *width, *height;
62 TypedLineEdit<mpz_class> *center_f_x, *center_f_y, *one;
63 QCheckBox *clear_image;
64 bool updating;
65
66 public:
67 explicit SettingsWidget(QWidget *parent = nullptr);
68 void update_params(const MandelParams &params);
69 void reset_params_fields();
70 bool are_params_fields_changed();
71 inline const quint64 get_max_iter() const {
72 return max_iter->get_value();
73 }
74 MandelParams get_params() const;
75 inline bool is_clear_image_checked() const {
76 return clear_image->isChecked();
77 }
78
79 public Q_SLOTS:
80 void update_form();
81 void reset_form();
82 };
83
84 #endif // SETTINGSWIDGET_H