]> git.mar77i.info Git - bigintmandel/commitdiff
improve settingswidget
authormar77i <mar77i@protonmail.ch>
Sun, 14 Apr 2024 12:45:12 +0000 (14:45 +0200)
committermar77i <mar77i@protonmail.ch>
Sun, 14 Apr 2024 12:45:12 +0000 (14:45 +0200)
bigintwidget.cpp
colors.h
mandel.cpp
mandel.h
settingswidget.cpp
settingswidget.h

index 6a5cfa2410a8324e815461f63aee746e2cd96fcf..d4289a110c428db4abcffc4189f647b726aa57ee 100644 (file)
@@ -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();
 }
 
index b6f8724450e70f1fbbceb9e7c80639f63744afd3..c0e3a6f393517a55a8e1347b7f19a86972c3a0cd 100644 (file)
--- a/colors.h
+++ b/colors.h
@@ -7,7 +7,7 @@
 #include <QVector>
 #include <QColor>
 
-static QVector<QColor> colors = {
+QVector<QColor> colors = {
     "#3868b8",
     "#3468b4",
     "#3468b4",
index a86c057af9426b8cb0acac809351c776b678334f..70910d35d434b58ce43e9f9842607257128fd45e 100644 (file)
@@ -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();
 }
index b86784f6e07463df3002db39baa642b6b899d79f..ffb9ff1e50b1f451c11d95911eb43d5edc906213 100644 (file)
--- a/mandel.h
+++ b/mandel.h
@@ -75,6 +75,8 @@ public:
     void reset(size_t max_iter, QSize size);
 };
 
+extern QVector<QColor> 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;
 };
 
index 1dd5de9c91ebcf3527b7a517c8aa3ac4a651d134..a6d3c6e18d21679a7dd6c2d332b6de1f342bc916 100644 (file)
@@ -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 &params) {
+void SettingsWidget::update_fields(
+    const MandelParams &params, 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 &params) {
     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();
 }
index 5621627b3ae23f38e3f8043c918ee128dcd38582..3e7470dca1d85f11f474465c26f60fab2d252d8f 100644 (file)
@@ -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 &params);
+    void update_fields(const MandelParams &params, 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