settings_widget(new SettingsWidget(this))
{
scroll_area->setWidget(img_label);
+ connect(
+ settings_widget,
+ &QDialog::accepted,
+ this,
+ &BigintWidget::settings_widget_accepted
+ );
connect(
fw,
&QFutureWatcher<MandelResultCell>::resultReadyAt,
void BigintWidget::finished_cell(int num) {
settings.finished_cell(num, fw->resultAt(num));
- img_dirty = true;
- update();
+ update_img();
}
void BigintWidget::finished() {
- img_dirty = true;
- update();
+ update_img();
}
static inline void calculating_status(
void BigintWidget::paintEvent(QPaintEvent *event) {
static int prev_num_threads = -1;
- if (img_dirty) {
- img_label->setPixmap(settings.get_pixmap());
- img_label->resize(img_label->pixmap().size());
- img_dirty = false;
- if (fw->isFinished())
- finished_status(status_bar);
- else {
- calculating_status(status_bar, prev_num_threads);
- prev_num_threads = -1;
- }
+ if (!img_dirty)
+ return;
+ img_label->setPixmap(settings.get_pixmap());
+ img_label->resize(img_label->pixmap().size());
+ img_dirty = false;
+ if (fw->isFinished())
+ finished_status(status_bar);
+ else {
+ calculating_status(status_bar, prev_num_threads);
+ prev_num_threads = -1;
}
}
void BigintWidget::mousePressEvent(QMouseEvent *event) {
- if (!fw->isFinished() || event->button() != Qt::MouseButton::LeftButton)
- return;
QSize size(settings.get_current().get_size());
- QPoint pos = img_label->mapFromParent(event->pos());
- if (pos.x() < 0 || pos.x() >= size.width()
- || pos.y() < 0 || pos.y() >= size.height())
+ QPoint pos(img_label->mapFromParent(event->pos()));
+ if (event->button() != Qt::MouseButton::LeftButton
+ || !fw->isFinished()
+ || pos.x() < 0
+ || pos.x() >= size.width()
+ || pos.y() < 0
+ || pos.y() >= size.height())
return;
- settings.zoom(pos);
+/*
+ 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();
+}
+
+void BigintWidget::update_img() {
img_dirty = true;
update();
}
}
void BigintWidget::exec_settings_widget() {
+ if (!fw->isFinished())
+ return;
settings_widget->update_fields(settings.get_current());
settings_widget->exec();
}
void BigintWidget::reset() {
QSize size(scroll_area->viewport()->size());
- qDebug() << "size" << size;
fw->cancel();
fw->waitForFinished();
settings.reset(128, size);
fw->setFuture(
QtConcurrent::mapped(settings.get_cells(), MandelSettings::iterate)
);
- img_dirty = true;
- update();
+ update_img();
+}
+
+void BigintWidget::settings_widget_accepted() {
+ settings.set_max_iter(settings_widget->get_max_iter().toULongLong());
+ fw->setFuture(
+ QtConcurrent::mapped(settings.get_cells(), MandelSettings::iterate)
+ );
+ update_img();
}
public:
BigintWidget(QWidget *parent = nullptr);
~BigintWidget();
- void finished_cell(int num);
- void finished();
void paintEvent(QPaintEvent *event);
void mousePressEvent(QMouseEvent *event);
+ void update_img();
+
+public Q_SLOT:
+ void reset();
void export_img();
void exec_settings_widget();
- void reset();
+ void settings_widget_accepted();
+ void finished_cell(int num);
+ void finished();
};
#endif // BIGINTWIDGET_H
i->setup(pos);
}
+static inline QImage *setup_image(QImage *img, const QSize &size) {
+ delete img;
+ img = new QImage(size, QImage::Format_RGB888);
+ img->fill(Qt::GlobalColor::black);
+ return img;
+}
+
MandelSettings::MandelSettings(size_t max_iter, const QSize size)
: img(nullptr)
{
reset(max_iter, size);
}
-void MandelSettings::zoom(QPoint pos) {
- QVector<MandelCell>::iterator i;
+void MandelSettings::zoom(const QSize size, const QPoint pos) {
MpzPoint p = cells[img->width() * pos.y() + pos.x()].get_rpos0();
+ bool resize_img = size != current.get_size();
current = MandelParams(
current.get_max_iter(),
- current.get_size(),
+ size,
MpzPoint(p.get_x() * 2, p.get_y() * 2),
current.get_one() * 2
);
+ if (resize_img)
+ img = setup_image(img, size);
img->fill(Qt::GlobalColor::black);
setup_cells(cells, ¤t);
}
+void MandelSettings::set_max_iter(size_t max_iter) {
+ current.set_max_iter(max_iter);
+}
+
void MandelSettings::finished_cell(int num, const MandelResultCell &result) {
size_t iter = result.get_iter();
cells[num].set_result(result);
one = mpz_class(ione + 1);
center_f = MpzPoint(one * -3 / 4, 0);
current = MandelParams(max_iter, size, center_f, one);
- delete img;
- img = new QImage(size, QImage::Format_RGB888);
- img->fill(Qt::GlobalColor::black);
+ img = setup_image(img, size);
setup_cells(cells, ¤t);
}
MandelParams(const MandelParams &other);
const size_t get_max_iter() const { return max_iter; }
+ void set_max_iter(const size_t max_iter) { this->max_iter = max_iter; }
const QSize get_size() const { return size; }
const MpzPoint get_center_f() const { return center_f; }
const mpz_class get_one() const { return one; }
const QVector<MandelCell> get_cells() const { return cells; }
const MandelParams get_current() const { return current; }
- void zoom(QPoint pos);
+ void zoom(const QSize size, const QPoint pos);
+ void set_max_iter(size_t max_iter);
void finished_cell(int num, const MandelResultCell &cell);
static MandelResultCell iterate(const MandelCell &cell);
void save_img(QString file_name);
#include <QPushButton>
#include <QLabel>
#include <QLayout>
+#include <QIntValidator>
#include "settingswidget.h"
-static QStringList labels = { "width", "height", "x", "y", "one" };
SettingsWidget::SettingsWidget(QWidget *parent)
: QDialog(parent),
+ max_iter(new QLineEdit("", this)),
width(new QLineEdit("", this)),
height(new QLineEdit("", this)),
- x(new QLineEdit("", this)),
- y(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<QLineEdit*> 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);
- QList<QLineEdit*> line_edits = { width, height, x, y, one };
int i;
setLayout(grid_layout);
for (i = 0; i < line_edits.size(); i++) {
grid_layout->addWidget(new QLabel(labels[i], this), i, 0);
- line_edits[i]->setReadOnly(true);
+ 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);
}
grid_layout->addWidget(apply_button, i, 1);
}
-void SettingsWidget::update_fields(const MandelParams params) {
+void SettingsWidget::update_fields(const MandelParams ¶ms) {
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()));
- x->setText(QString::fromStdString(center_f.get_x().get_str()));
- y->setText(QString::fromStdString(center_f.get_y().get_str()));
+ 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()));
}
class SettingsWidget : public QDialog {
Q_OBJECT
- QLineEdit *width, *height, *x, *y, *one;
+ QLineEdit *max_iter, *width, *height, *center_f_x, *center_f_y, *one;
public:
SettingsWidget(QWidget *parent = nullptr);
- void update_fields(const MandelParams params);
+ void update_fields(const MandelParams ¶ms);
+ inline const QString get_max_iter() const { return max_iter->text(); };
};
#endif // SETTINGSWIDGET_H