// settingswidget.cpp #include #include #include #include #include "settingswidget.h" SettingsWidget::SettingsWidget(QWidget *parent) : QDialog(parent), max_iter(new QLineEdit("", this)), width(new QLineEdit("", this)), height(new QLineEdit("", this)), center_f_x(new QLineEdit("", this)), center_f_y(new QLineEdit("", this)), one(new QLineEdit("", this)) { static QStringList labels = { "max_iter", "width", "height", "x", "y", "one" }; static QList line_edits = { max_iter, width, height, center_f_x, center_f_y, one }; QPushButton *apply_button = new QPushButton("Apply"); QGridLayout *grid_layout = new QGridLayout(this); int i; setLayout(grid_layout); for (i = 0; i < line_edits.size(); i++) { grid_layout->addWidget(new QLabel(labels[i], this), i, 0); if (i == 0) line_edits[i]->setValidator( new QIntValidator(0, INT_MAX, line_edits[i]) ); else line_edits[i]->setReadOnly(true); line_edits[i]->setMinimumWidth(256); grid_layout->addWidget(line_edits[i], i, 1); } connect( apply_button, &QPushButton::clicked, this, &SettingsWidget::apply ); grid_layout->addWidget(apply_button, i, 1); } void SettingsWidget::update_fields( const MandelParams ¶ms, const bool is_finished ) { QSize size = params.get_size(); MpzPoint center_f = params.get_center_f(); max_iter->setText(QString::number(params.get_max_iter())); width->setText(QString::number(size.width())); height->setText(QString::number(size.height())); center_f_x->setText(QString::fromStdString(center_f.get_x().get_str())); center_f_y->setText(QString::fromStdString(center_f.get_y().get_str())); one->setText(QString::fromStdString(params.get_one().get_str())); set_finished(is_finished); } void SettingsWidget::apply() { if (is_finished) accept(); else reject(); }