From: mar77i Date: Mon, 13 May 2024 07:27:15 +0000 (+0200) Subject: make zoom_factor part of MandelSettings X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=bigintmandel make zoom_factor part of MandelSettings --- diff --git a/bigintmandelwidget.cpp b/bigintmandelwidget.cpp index 43c240f..7859b21 100644 --- a/bigintmandelwidget.cpp +++ b/bigintmandelwidget.cpp @@ -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 diff --git a/bigintmandelwidget.h b/bigintmandelwidget.h index 05cb151..ccc3518 100644 --- a/bigintmandelwidget.h +++ b/bigintmandelwidget.h @@ -15,10 +15,10 @@ #include #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(); diff --git a/mandel.h b/mandel.h index e2b72c9..7ba05dd 100644 --- a/mandel.h +++ b/mandel.h @@ -74,6 +74,7 @@ class MandelSettings { MandelParams params; QImage *img; QVector 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); diff --git a/mandellabel.cpp b/mandellabel.cpp index cf77420..b2baf25 100644 --- a/mandellabel.cpp +++ b/mandellabel.cpp @@ -8,13 +8,11 @@ #include #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); diff --git a/mandellabel.h b/mandellabel.h index 9a89abd..de82b5a 100644 --- a/mandellabel.h +++ b/mandellabel.h @@ -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; diff --git a/menubar.cpp b/menubar.cpp index 8139ba6..e61e363 100644 --- a/menubar.cpp +++ b/menubar.cpp @@ -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( diff --git a/menubar.h b/menubar.h index 8771442..51e32a4 100644 --- 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(sender())->data().toInt()); + settings->set_zoom_factor( + static_cast(sender())->data().toInt() + ); } };