]> git.mar77i.info Git - bigintmandel/commitdiff
make zoom_factor part of MandelSettings master
authormar77i <mar77i@protonmail.ch>
Mon, 13 May 2024 07:27:15 +0000 (09:27 +0200)
committermar77i <mar77i@protonmail.ch>
Mon, 13 May 2024 07:32:24 +0000 (09:32 +0200)
bigintmandelwidget.cpp
bigintmandelwidget.h
mandel.h
mandellabel.cpp
mandellabel.h
menubar.cpp
menubar.h

index 43c240f21b12bd65e65f6646cd9c91c55f7db20b..7859b2155d3cfe71991a722145d0c9f8830412b0 100644 (file)
@@ -15,6 +15,7 @@
 #include "bigintmandelwidget.h"
 #include "mandellabel.h"
 #include "menubar.h"
+#include "settingswidget.h"
 
 BigintMandelWidget::BigintMandelWidget(QWidget *parent)
 :   QWidget(parent),
@@ -84,6 +85,8 @@ void BigintMandelWidget::update_status_bar() {
     ss.setString(new QString());
     if (num_threads != -1)
         ss << "Calculating with " << num_threads << " threads ...";
+    else if (settings.get_zoom_factor() == -1)
+        ss << "Choose a zoom factor from the \"Zoom\" menu.";
     else
         ss << "Click the rendering to zoom.";
     status_bar->showMessage(*ss.string());
@@ -98,7 +101,7 @@ void BigintMandelWidget::start() {
             [](const MandelCell &cell){ return cell.iterate(); }
         )
     );
-    menu_bar->set_zoom_factor(-1);
+    settings.set_zoom_factor(-1);
     update();
 }
 
@@ -111,7 +114,7 @@ void BigintMandelWidget::mousePressEvent(QMouseEvent *event) {
     QSize size(settings.get_params().get_size());
     QPoint pos(event->pos());
     QWidget *w;
-    int zoom_factor = menu_bar->get_zoom_factor();
+    int zoom_factor = settings.get_zoom_factor();
     for (w = mandel_label; w != this; w = w->parentWidget())
         pos = w->mapFromParent(pos);
     if (event->button() != Qt::MouseButton::LeftButton
index 05cb151c7119d136244f0d3970778f082090b10a..ccc351842d741295bea9b82beb61bc4e562a8860 100644 (file)
 #include <QWidget>
 
 #include "mandel.h"
-#include "settingswidget.h"
 
 class MenuBar;
 class MandelLabel;
+class SettingsWidget;
 
 class BigintMandelWidget : public QWidget {
     Q_OBJECT
@@ -44,12 +44,9 @@ protected:
 public:
     explicit BigintMandelWidget(QWidget *parent = nullptr);
     ~BigintMandelWidget();
-    inline const MandelSettings *get_settings() const {
+    inline MandelSettings * const get_settings() {
         return &settings;
     }
-    inline const MenuBar *get_menu_bar() const {
-        return menu_bar;
-    }
 
 public Q_SLOTS:
     void reset();
index e2b72c9291914c63bc72658f9c4df4372d8fef0d..7ba05ddc9d2afb26806c7290153f6b5ad4a5f329 100644 (file)
--- a/mandel.h
+++ b/mandel.h
@@ -74,6 +74,7 @@ class MandelSettings {
     MandelParams params;
     QImage *img;
     QVector<MandelCell> cells;
+    int zoom_factor;
 
 public:
     explicit MandelSettings(quint64 max_iter, QSize size);
@@ -91,6 +92,12 @@ public:
     inline void set_size(const QSize &size) {
         params.set_size(size);
     }
+    inline int get_zoom_factor() const {
+        return zoom_factor;
+    }
+    inline void set_zoom_factor(int zoom_factor) {
+        this->zoom_factor = zoom_factor;
+    }
 
     void zoom(const QSize size, int zoom_factor, const QPoint pos);
     void finished_cell(int num, const MandelResultCell &cell);
index cf77420951254257ca5a2a31d60522037739273e..b2baf2551b0e68d25e90966f823e06819b3b03e8 100644 (file)
@@ -8,13 +8,11 @@
 #include <QPainter>
 
 #include "mandellabel.h"
-#include "menubar.h"
 #include "qevent.h"
 
 MandelLabel::MandelLabel(BigintMandelWidget *parent)
 :   QLabel(parent),
     settings(parent->get_settings()),
-    menu_bar(parent->get_menu_bar()),
     draw_progress(-1),
     zoom_rect_center(-1, -1) {
     setMouseTracking(true);
@@ -34,31 +32,31 @@ static inline QRect get_rect(QSize size, QPoint pos, int zoom_factor) {
 void MandelLabel::paintEvent(QPaintEvent *event) {
     QPixmap pixmap;
     QPainter qp;
-    int zoom_factor = menu_bar->get_zoom_factor();
+    int zoom_factor = settings->get_zoom_factor();
     bool draw_zoom_rect = (
         zoom_factor != -1
         && zoom_rect_center.x() != -1
         && zoom_rect_center.y() != -1
     );
     pixmap = settings->get_pixmap();
-    if (draw_progress != -1 || draw_zoom_rect)
+    if (draw_progress != -1 || draw_zoom_rect) {
         qp.begin(&pixmap);
-    if (draw_progress != -1) {
-        qp.setPen(Qt::GlobalColor::gray);
-        qp.drawLine(0, draw_progress, pixmap.width() - 1, draw_progress);
-    }
-    if (draw_zoom_rect) {
-        qp.setPen(Qt::GlobalColor::gray);
-        qp.drawRect(
-            get_rect(
-                pixmap.size(),
-                zoom_rect_center,
-                zoom_factor
-            )
-        );
-    }
-    if (draw_progress != -1 || draw_zoom_rect)
+        if (draw_progress != -1) {
+            qp.setPen(Qt::GlobalColor::gray);
+            qp.drawLine(0, draw_progress, pixmap.width() - 1, draw_progress);
+        }
+        if (draw_zoom_rect) {
+            qp.setPen(Qt::GlobalColor::gray);
+            qp.drawRect(
+                get_rect(
+                    pixmap.size(),
+                    zoom_rect_center,
+                    zoom_factor
+                )
+            );
+        }
         qp.end();
+    }
     resize(pixmap.size());
     setPixmap(pixmap);
     QLabel::paintEvent(event);
index 9a89abdcc9ba765b3b39928c849f7f021ca9422d..de82b5a3b943c4618e9f91bf2f222a88abcde8ab 100644 (file)
@@ -14,8 +14,9 @@
 #include "mandel.h"
 
 class MandelLabel : public QLabel {
-    const MandelSettings *settings;
-    const MenuBar *menu_bar;
+    Q_OBJECT
+
+    const MandelSettings * const settings;
     int draw_progress;
     QPoint zoom_rect_center;
 
index 8139ba6b3964befe08a8bef55266570c78f959bc..e61e363f45b815a005c404b44eb0e936881b79d3 100644 (file)
@@ -26,10 +26,10 @@ static inline QAction *zoom_action(
 
 MenuBar::MenuBar(BigintMandelWidget *parent)
 :   QMenuBar(parent),
+    settings(parent->get_settings()),
     file_menu(new QMenu("&File", parent)),
     calc_menu(new QMenu("&Calculation", parent)),
-    zoom_menu(new QMenu("&Zoom", parent)),
-    zoom_factor(-1) {
+    zoom_menu(new QMenu("&Zoom", parent)) {
     QKeySequence no_key;
     setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     load_action = file_menu->addAction(
index 87714420af481c49da31ec96a8cde2aab60fa17e..51e32a438e8084db8834d9ab4db06d596d9b0f8b 100644 (file)
--- a/menubar.h
+++ b/menubar.h
@@ -15,6 +15,7 @@
 class MenuBar : public QMenuBar {
     Q_OBJECT
 
+    MandelSettings * const settings;
     QMenu *file_menu;
     QAction *load_action, *save_action;
     QAction *export_action, *exit_action;
@@ -23,26 +24,22 @@ class MenuBar : public QMenuBar {
     QMenu *zoom_menu;
     QAction *no_action, *two_action, *four_action;
     QAction *eight_action, *sixteen_action;
-    int zoom_factor;
 
     inline void check_action() {
-        no_action->setChecked(zoom_factor == -1);
-        two_action->setChecked(zoom_factor == 2);
-        four_action->setChecked(zoom_factor == 4);
-        eight_action->setChecked(zoom_factor == 8);
-        sixteen_action->setChecked(zoom_factor == 16);
+        no_action->setChecked(settings->get_zoom_factor() == -1);
+        two_action->setChecked(settings->get_zoom_factor() == 2);
+        four_action->setChecked(settings->get_zoom_factor() == 4);
+        eight_action->setChecked(settings->get_zoom_factor() == 8);
+        sixteen_action->setChecked(settings->get_zoom_factor() == 16);
     }
 
 public:
     explicit MenuBar(BigintMandelWidget *parent);
-    inline int get_zoom_factor() const { return zoom_factor; }
-    inline void set_zoom_factor(int zoom_factor) {
-        this->zoom_factor = zoom_factor;
-        check_action();
-    }
 public Q_SLOTS:
     void change_zoom_factor() {
-        set_zoom_factor(static_cast<QAction*>(sender())->data().toInt());
+        settings->set_zoom_factor(
+            static_cast<QAction*>(sender())->data().toInt()
+        );
     }
 };