From: mar77i Date: Sun, 14 Apr 2024 12:45:12 +0000 (+0200) Subject: improve settingswidget X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=a4346c91675b28a370d8cdfed127cd1f40b93153;p=bigintmandel improve settingswidget --- diff --git a/bigintwidget.cpp b/bigintwidget.cpp index 6a5cfa2..d4289a1 100644 --- a/bigintwidget.cpp +++ b/bigintwidget.cpp @@ -96,6 +96,7 @@ void BigintWidget::finished_cell(int num) { } void BigintWidget::finished() { + settings_widget->set_finished(true); update_img(); } @@ -132,7 +133,10 @@ void BigintWidget::paintEvent(QPaintEvent *event) { void BigintWidget::mousePressEvent(QMouseEvent *event) { QSize size(settings.get_current().get_size()); - QPoint pos(img_label->mapFromParent(event->pos())); + QPoint pos(event->pos()); + QWidget *w; + for (w = img_label; w != this; w = w->parentWidget()) + pos = w->mapFromParent(pos); if (event->button() != Qt::MouseButton::LeftButton || !fw->isFinished() || pos.x() < 0 @@ -140,13 +144,10 @@ void BigintWidget::mousePressEvent(QMouseEvent *event) { || pos.y() < 0 || pos.y() >= size.height()) return; -/* settings.zoom(scroll_area->viewport()->size(), pos); fw->setFuture( QtConcurrent::mapped(settings.get_cells(), MandelSettings::iterate) ); -*/ - // paint a small circle at point pos update_img(); } @@ -164,9 +165,7 @@ void BigintWidget::export_img() { } void BigintWidget::exec_settings_widget() { - if (!fw->isFinished()) - return; - settings_widget->update_fields(settings.get_current()); + settings_widget->update_fields(settings.get_current(), fw->isFinished()); settings_widget->exec(); } diff --git a/colors.h b/colors.h index b6f8724..c0e3a6f 100644 --- a/colors.h +++ b/colors.h @@ -7,7 +7,7 @@ #include #include -static QVector colors = { +QVector colors = { "#3868b8", "#3468b4", "#3468b4", diff --git a/mandel.cpp b/mandel.cpp index a86c057..70910d3 100644 --- a/mandel.cpp +++ b/mandel.cpp @@ -54,8 +54,10 @@ static inline void setup_cells( } static inline QImage *setup_image(QImage *img, const QSize &size) { - delete img; - img = new QImage(size, QImage::Format_RGB888); + if(!img || img->size() != size) { + delete img; + img = new QImage(size, QImage::Format_RGB888); + } img->fill(Qt::GlobalColor::black); return img; } @@ -90,12 +92,7 @@ void MandelSettings::finished_cell(int num, const MandelResultCell &result) { cells[num].set_result(result); if (!img) return; - img->setPixelColor( - cells[num].get_pos(), - iter < current.get_max_iter() - ? colors[iter % colors.size()] - : Qt::GlobalColor::black - ); + img->setPixelColor(cells[num].get_pos(), cells[num].get_color()); } MandelResultCell MandelSettings::iterate(const MandelCell &cell) { @@ -136,7 +133,7 @@ void MandelCell::setup(const QPoint pos) { this->pos = pos; rpos0 = MpzPoint( center_f.get_x() + (pos.x() - size.width() / 2.), - center_f.get_y() + (pos.y() - size.height() / 2.) + center_f.get_y() - (pos.y() - size.height() / 2.) ); result = MandelResultCell(); } diff --git a/mandel.h b/mandel.h index b86784f..ffb9ff1 100644 --- a/mandel.h +++ b/mandel.h @@ -75,6 +75,8 @@ public: void reset(size_t max_iter, QSize size); }; +extern QVector colors; + class MandelCell { const MandelParams *params; QPoint pos; @@ -87,9 +89,16 @@ public: inline const QPoint get_pos() const { return pos; } inline const size_t get_iter() const { return result.iter; } inline const MpzPoint get_rpos0() const { return rpos0; } + inline const QColor get_color() const { + return result.iter < params->get_max_iter() + ? colors[result.iter % colors.size()] + : Qt::GlobalColor::black; + } void setup(const QPoint pos); - void set_result(const MandelResultCell &result) { this->result = result; } + inline void set_result(const MandelResultCell &result) { + this->result = result; + } MandelResultCell iterate() const; }; diff --git a/settingswidget.cpp b/settingswidget.cpp index 1dd5de9..a6d3c6e 100644 --- a/settingswidget.cpp +++ b/settingswidget.cpp @@ -43,12 +43,14 @@ SettingsWidget::SettingsWidget(QWidget *parent) apply_button, &QPushButton::clicked, this, - &QDialog::accept + &SettingsWidget::apply ); grid_layout->addWidget(apply_button, i, 1); } -void SettingsWidget::update_fields(const MandelParams ¶ms) { +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())); @@ -57,4 +59,12 @@ void SettingsWidget::update_fields(const MandelParams ¶ms) { 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(); } diff --git a/settingswidget.h b/settingswidget.h index 5621627..3e7470d 100644 --- a/settingswidget.h +++ b/settingswidget.h @@ -14,11 +14,20 @@ class SettingsWidget : public QDialog { Q_OBJECT QLineEdit *max_iter, *width, *height, *center_f_x, *center_f_y, *one; + bool is_finished; public: SettingsWidget(QWidget *parent = nullptr); - void update_fields(const MandelParams ¶ms); + void update_fields(const MandelParams ¶ms, const bool is_finished); inline const QString get_max_iter() const { return max_iter->text(); }; + + inline void set_finished(const bool is_finished) { + this->is_finished = is_finished; + max_iter->setReadOnly(!is_finished); + } + +public Q_SLOTS: + void apply(); }; #endif // SETTINGSWIDGET_H