Commit 2cbf0688 authored by Andreas Kempe's avatar Andreas Kempe

Zooming in on the set is now possible.

parent 1570954d
# Generated by YCM Generator at 2015-10-03 19:06:59.481209
# Generated by YCM Generator at 2015-10-03 23:38:10.236763
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
......@@ -51,7 +51,7 @@ flags = [
'-I/home/andkem/Program/imagemagick/include/ImageMagick-6',
'-I/home/andkem/Program/openmpi/include',
'-I/home/kempe/lib/include/ImageMagick-6',
'-I/tmp/tmpN4wYQP',
'-I/tmp/tmpROuNAP',
'-I/usr/include/qt5',
'-I/usr/include/qt5/QtCore',
'-I/usr/include/qt5/QtGui',
......
......@@ -11,7 +11,7 @@ find_package(Qt5Network)
# Source files
set(SERVER_SRC server/main.cpp server/mandel_render_srv.cpp)
set(CLIENT_SRC client/main.cpp client/main_window.cpp)
set(CLIENT_SRC client/main.cpp client/main_window.cpp client/mandel_view.cpp)
set(MANDELNET_SRC network/data_packet.cpp network/mandel_socket.cpp
network/mandel_tcp_server.cpp)
set(MANDELBROT_SRC mandelbrot/mandelbrot.cpp)
......
......@@ -5,20 +5,31 @@
#include <QVBoxLayout>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QScrollBar>
#include <Magick++.h>
#include <string>
#include <complex>
using namespace std;
main_window::main_window(unsigned int port, QWidget* parent) :
QWidget(parent), socket(nullptr), port(port)
QWidget(parent), socket(nullptr), port(port), drawing_rect(false)
{
mandel_image = new QImage;
QVBoxLayout* layout = new QVBoxLayout(this);
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 1064, 800);
view = new QGraphicsView(scene);
view = new mandel_view(scene);
view->setInteractive(true);
connect(view, &mandel_view::mouse_press, this, &main_window::handle_mouse_press);
connect(view, &mandel_view::mouse_move, this, &main_window::handle_mouse_move);
view->setMinimumSize(QSize(10, 10));
view->setMaximumSize(QSize(10, 10));
rect = new QGraphicsRectItem();
item = new QGraphicsPixmapItem();
item->setPixmap(QPixmap::fromImage(*mandel_image));
......@@ -79,6 +90,8 @@ main_window::main_window(unsigned int port, QWidget* parent) :
connect(diag_btns, &QDialogButtonBox::accepted, this, &main_window::handle_update_settings);
handle_update_settings();
QPushButton* settings_btn = new QPushButton("Settings", this);
layout->addWidget(settings_btn);
......@@ -98,6 +111,7 @@ main_window::~main_window()
{
delete mandel_image;
delete item;
delete rect;
}
void main_window::show_image()
......@@ -138,6 +152,49 @@ void main_window::show_settings_diag()
settings_dialog->exec();
}
void main_window::handle_mouse_press(QMouseEvent* event)
{
if (!drawing_rect)
{
scene->addItem(rect);
rect->setPos(QPointF(event->x(), event->y()));
rect->setRect(QRectF(0, 0, 1, 1));
drawing_rect = true;
}
else
{
scene->removeItem(rect);
drawing_rect = false;
// Instantiate a mandelbrot for calculating the new limits for the rendering.
mandelbrot calculator(render_settings);
complex<double> upper_left = calculator.get_pixel_coordinate(rect->x(), rect->y());
complex<double> lower_right = calculator.get_pixel_coordinate(rect->x() +
rect->rect().width(),
rect->y() +
rect->rect().height());
render_settings.re_max = real(lower_right);
render_settings.re_min = real(upper_left);
render_settings.im_max = imag(lower_right);
render_settings.im_min = imag(upper_left);
field_list[0]->setText(QString("%1").arg(render_settings.re_max));
field_list[1]->setText(QString("%1").arg(render_settings.re_min));
field_list[2]->setText(QString("%1").arg(render_settings.im_max));
field_list[3]->setText(QString("%1").arg(render_settings.im_min));
}
}
void main_window::handle_mouse_move(QMouseEvent* event)
{
if (drawing_rect)
rect->setRect(QRectF(0, 0, fabs(rect->x() - event->x()), fabs(rect->y() - event->y())));
}
void main_window::handle_new_connection()
{
socket = server->nextPendingConnection();
......@@ -197,5 +254,10 @@ void main_window::handle_update_settings()
delete mandel_image;
scene->setSceneRect(0, 0, render_settings.img_width, render_settings.img_height);
view->setMinimumSize(render_settings.img_width, render_settings.img_height);
view->setMaximumSize(render_settings.img_width, render_settings.img_height);
view->verticalScrollBar()->hide();
view->horizontalScrollBar()->hide();
mandel_image = new QImage(render_settings.img_width, render_settings.img_height, QImage::Format_RGB32);
}
......@@ -7,10 +7,12 @@
#include <QGraphicsPixmapItem>
#include <QLineEdit>
#include <QDialog>
#include <QMouseEvent>
#include <vector>
#include "mandel_tcp_server.h"
#include "mandel_socket.h"
#include "mandelbrot.h"
#include "mandel_view.h"
class main_window : public QWidget
{
......@@ -23,7 +25,7 @@ class main_window : public QWidget
QImage* mandel_image;
QGraphicsScene* scene;
QGraphicsView* view;
mandel_view* view;
QGraphicsPixmapItem* item;
mandel_tcp_server* server;
......@@ -36,11 +38,16 @@ class main_window : public QWidget
std::vector<QLineEdit*> field_list;
mandel_settings render_settings;
bool drawing_rect;
QGraphicsRectItem* rect;
public slots:
void show_image();
void send_img_render();
void handle_kill_renderer();
void show_settings_diag();
void handle_mouse_press(QMouseEvent* event);
void handle_mouse_move(QMouseEvent* event);
private slots:
void handle_new_connection();
......
#include "mandel_view.h"
#include <QMouseEvent>
mandel_view::mandel_view(QGraphicsScene* parent) :
QGraphicsView(parent)
{
}
mandel_view::~mandel_view()
{
}
void mandel_view::mousePressEvent(QMouseEvent* event)
{
emit mouse_press(event);
}
void mandel_view::mouseMoveEvent(QMouseEvent* event)
{
emit mouse_move(event);
}
#ifndef MANDEL_VIEW_H
#define MANDEL_VIEW_H
#include <QGraphicsView>
#include <QGraphicsScene>
class mandel_view : public QGraphicsView
{
Q_OBJECT
public:
mandel_view(QGraphicsScene* parent);
~mandel_view();
protected:
void mousePressEvent(QMouseEvent* event) override final;
void mouseMoveEvent(QMouseEvent* event) override final;
signals:
void mouse_press(QMouseEvent* event);
void mouse_move(QMouseEvent* event);
};
#endif
......@@ -96,8 +96,8 @@ void mandel_socket::decode_packet_data(QByteArray& incoming)
recv_buf.remove(0, payload_size + packet_header_size);
// If we still have data in the buffer we call ourselves to handle it.
if (recv_buf.size() > 0)
decode_packet_data(recv_buf);
// if (recv_buf.size() > 0)
// decode_packet_data(recv_buf);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment