]> git.mar77i.info Git - bigintmandel/blob - bigintwidget.cpp
use gmp big ints rather than qreal
[bigintmandel] / bigintwidget.cpp
1
2 // bigintwidget.cpp
3
4 #include <QLayout>
5 #include <QMouseEvent>
6 #include <QtConcurrent/QtConcurrent>
7
8 #include "bigintwidget.h"
9
10 BigintWidget::BigintWidget(QWidget *parent)
11 : QWidget(parent),
12 fw(new QFutureWatcher<MandelResultCell>(this)),
13 meta(8192, QSize(1800, 1000)),
14 img_label(new QLabel(this)),
15 img_dirty(true)
16 {
17 connect(
18 fw,
19 &QFutureWatcher<MandelResultCell>::resultReadyAt,
20 this,
21 &BigintWidget::finished_cell
22 );
23 connect(
24 fw,
25 &QFutureWatcher<MandelResultCell>::finished,
26 this,
27 &BigintWidget::finished
28 );
29 fw->setFuture(QtConcurrent::mapped(meta.get_cells(), MandelMeta::iterate));
30 setLayout(new QVBoxLayout());
31 layout()->addWidget(img_label);
32 img_label->setMinimumSize(meta.get_size());
33 }
34
35 BigintWidget::~BigintWidget() {
36 fw->cancel();
37 fw->waitForFinished();
38 }
39
40 void BigintWidget::finished_cell(int num) {
41 meta.finished_cell(num, fw->resultAt(num));
42 img_dirty = true;
43 update();
44 }
45
46 void BigintWidget::finished() {
47 img_dirty = true;
48 update();
49 }
50
51 void BigintWidget::paintEvent(QPaintEvent *event) {
52 if (img_dirty) {
53 img_label->setPixmap(meta.get_pixmap());
54 img_dirty = false;
55 }
56 }
57
58 void BigintWidget::mousePressEvent(QMouseEvent *event) {
59 if (!fw->isFinished() || event->button() != Qt::MouseButton::LeftButton)
60 return;
61 QPoint pos = img_label->mapFromParent(event->pos());
62 if (pos.x() < 0 || pos.x() >= meta.get_width()
63 || pos.y() < 0 || pos.y() >= meta.get_height())
64 return;
65 meta.zoom2x(pos);
66 fw->setFuture(QtConcurrent::mapped(meta.get_cells(), MandelMeta::iterate));
67 img_dirty = true;
68 update();
69 }