Interactive Mandelbrot viewer with Qt and OpenGL.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB

#include <QVBoxLayout>
#include <QSlider>
#include <QLabel>
#include <iostream>
#include <QPushButton>
#include "../headers/MainWindow.h"
MainWindow::MainWindow(): outputWidget(OutputWidget(this)) {
buildUI();
}
void MainWindow::buildUI() {
3 years ago
resize(700, 700);
3 years ago
auto iterationsCaption = new QLabel("Iteration count: ");
auto iterationsLabel = new QLabel;
3 years ago
iterationsLabel->setFixedWidth(50);
iterationsLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
3 years ago
auto iterationsSlider = new QSlider(Qt::Horizontal);
iterationsSlider->setRange(5, 1000);
connect(
3 years ago
iterationsSlider,
&QSlider::valueChanged,
this,
[iterationsLabel, this](int value) -> void {
this->outputWidget.getMandelbrot().setIterations(value);
this->outputWidget.update();
iterationsLabel->setNum(value);
});
3 years ago
iterationsSlider->setValue(100);
auto saveInfo = new QLabel;
auto saveButton = new QPushButton("Save high resolution image");
connect(
saveButton,
&QPushButton::clicked,
this,
[this, saveInfo](){
saveInfo->setText("Receiving image...");
update();
this->outputWidget.saveToImage([saveInfo](){
saveInfo->setText("Saving...");
}, [saveInfo](bool success){
QString result = success ? "Success" : "Failure";
saveInfo->setText(result);
});
});
auto controls = new QGridLayout;
controls->addWidget(iterationsCaption, 1, 1);
controls->addWidget(iterationsLabel, 1, 2);
controls->addWidget(iterationsSlider, 1, 3);
controls->addWidget(saveInfo, 2, 1, 1, 2);
controls->addWidget(saveButton, 2, 3, 1, 1);
3 years ago
auto lyt = new QVBoxLayout(this);
lyt->addWidget(&outputWidget);
3 years ago
lyt->addLayout(controls);
}