#include <QPushButton>
#include <QtConcurrent/QtConcurrent>
-#include "menubar.h"
#include "bigintmandelwidget.h"
+#include "mandellabel.h"
+#include "menubar.h"
static inline void start_calculation(
QFutureWatcher<MandelResultCell> *fw, QVector<MandelCell> cells
settings(128, QSize(502, 334)),
menu_bar(new MenuBar(this)),
scroll_area(new QScrollArea(this)),
- img_label(new QLabel(this)),
- img_dirty(true),
+ mandel_label(new MandelLabel(this)),
status_bar(new QStatusBar(this)),
- settings_widget(new SettingsWidget(this)),
- draw_progress(-1)
+ settings_widget(new SettingsWidget(this))
{
- scroll_area->setWidget(img_label);
+ scroll_area->setWidget(mandel_label);
connect(
settings_widget,
&QDialog::accepted,
layout()->addWidget(scroll_area);
status_bar->setSizeGripEnabled(false);
layout()->addWidget(status_bar);
- img_label->resize(settings.get_params().get_size());
+ mandel_label->resize(settings.get_params().get_size());
}
BigintMandelWidget::~BigintMandelWidget() {
void BigintMandelWidget::finished_cell(int num) {
int y = num / settings.get_params().get_size().width();
- if (y > draw_progress)
- draw_progress = y;
+ mandel_label->set_draw_progress(y);
settings.finished_cell(num, fw->resultAt(num));
- update_img();
+ update();
}
void BigintMandelWidget::finished() {
- draw_progress = -1;
+ mandel_label->set_draw_progress(-1);
settings_widget->set_finished(true);
- update_img();
-}
-
-static inline QPixmap enhance_pixmap(QPixmap pixmap, int draw_progress) {
- QPainter qp;
- if (draw_progress > -1) {
- qp.begin(&pixmap);
- qp.setPen(Qt::GlobalColor::gray);
- qp.drawLine(0, draw_progress, pixmap.width() - 1, draw_progress);
- qp.end();
- }
- return pixmap;
-}
-
-static inline void calculating_status(
- QStatusBar *status_bar, int &prev_num_threads
-) {
- QTextStream ss(new QString());
- int num_threads = QThreadPool::globalInstance()->activeThreadCount();
- if (prev_num_threads == num_threads)
- return;
- ss << "Calculating with " << num_threads << " threads ...";
- status_bar->showMessage(ss.readAll());
- prev_num_threads = num_threads;
-}
-
-static inline void finished_status(QStatusBar *status_bar) {
- status_bar->showMessage("Click the rendering to zoom.");
+ update();
}
-void BigintMandelWidget::paintEvent(QPaintEvent *event) {
+void BigintMandelWidget::update_status_bar() {
+ QTextStream ss;
static int prev_num_threads = -1;
- if (!img_dirty)
- return;
- img_label->setPixmap(enhance_pixmap(settings.get_pixmap(), draw_progress));
- img_label->resize(img_label->pixmap().size());
- img_dirty = false;
+ int num_threads;
if (fw->isFinished())
- finished_status(status_bar);
- else {
- calculating_status(status_bar, prev_num_threads);
- prev_num_threads = -1;
- }
+ num_threads = -1;
+ else
+ num_threads = QThreadPool::globalInstance()->activeThreadCount();
+ if (num_threads == prev_num_threads)
+ return;
+ ss.setString(new QString());
+ if (num_threads != -1)
+ ss << "Calculating with " << num_threads << " threads ...";
+ else
+ ss << "Click the rendering to zoom.";
+ status_bar->showMessage(*ss.string());
+ prev_num_threads = num_threads;
}
void BigintMandelWidget::mousePressEvent(QMouseEvent *event) {
QSize size(settings.get_params().get_size());
QPoint pos(event->pos());
QWidget *w;
- for (w = img_label; w != this; w = w->parentWidget())
+ for (w = mandel_label; w != this; w = w->parentWidget())
pos = w->mapFromParent(pos);
if (event->button() != Qt::MouseButton::LeftButton
|| !fw->isFinished()
return;
settings.zoom(get_ideal_size(), menu_bar->get_zoom_factor(), pos);
start_calculation(fw, settings.get_cells());
- update_img();
-}
-
-void BigintMandelWidget::update_img() {
- img_dirty = true;
update();
}
fw->waitForFinished();
settings.reset(128, get_ideal_size());
start_calculation(fw, settings.get_cells());
- update_img();
+ update();
}
void BigintMandelWidget::settings_widget_accepted() {
settings.set_max_iter(settings_widget->get_max_iter().toULongLong());
start_calculation(fw, settings.get_cells());
- update_img();
+ update();
}
void BigintMandelWidget::load_data() {
if (file_name.endsWith(".qcompress"))
qba = qUncompress(qba);
settings.from_json(QJsonDocument::fromJson(qba).object());
- update_img();
+ update();
}
void BigintMandelWidget::save_data() {
file.write(qba);
file.close();
}
+
+void BigintMandelWidget::update() {
+ update_status_bar();
+ QWidget::update();
+}
MpzPoint rpos;
public:
MandelResultCell() : iter(0) {}
- MandelResultCell(size_t iter, MpzPoint rpos) : iter(iter), rpos(rpos) {}
+ explicit MandelResultCell(size_t iter, MpzPoint rpos)
+ : iter(iter), rpos(rpos) {}
inline const size_t get_iter() const { return iter; }
inline const MpzPoint get_rpos() const { return rpos; }
};
public:
// required by the MandelSettings constructor
MandelParams();
- MandelParams(
+ explicit MandelParams(
size_t max_iter,
QSize size,
MpzPoint center_f,
QVector<MandelCell> cells;
public:
- MandelSettings(size_t max_iter, QSize size);
+ explicit MandelSettings(size_t max_iter, QSize size);
inline QPixmap get_pixmap() const { return QPixmap::fromImage(*img); }
inline const QVector<MandelCell> get_cells() const { return cells; }
inline const MandelParams &get_params() const { return params; }
public:
MandelCell(const MandelParams *params);
- MandelCell(
+ explicit MandelCell(
const MandelParams *params,
const QPoint pos,
const MpzPoint rpos0,