Skip to content

Commit

Permalink
Fixed mouse bug + more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ker2x committed Sep 4, 2013
1 parent 18b408a commit 14052db
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 81 deletions.
2 changes: 1 addition & 1 deletion buddhaGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int BuddhaGenerator::findPoint ( complex<double>& begin, double& centerDistance,
complex<double> tmp = begin;

// 64 - 512
#define FINDPOINTMAX 256
#define FINDPOINTMAX 256

calculated = 0;
do {
Expand Down
127 changes: 56 additions & 71 deletions controlWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ ControlWindow::ControlWindow ( ) {
connect( reBox, SIGNAL( valueChanged( double ) ), this, SLOT( sendValues( ) ) );
connect( imBox, SIGNAL( valueChanged( double ) ), this, SLOT( sendValues( ) ) );
connect( zoomBox, SIGNAL( valueChanged( double ) ), this, SLOT( sendValues( ) ) );
connect( minRbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( minGbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( minBbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxRbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxGbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxBbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( minRbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( minGbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( minBbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxRbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxGbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );
connect( maxBbox, SIGNAL( valueChanged( int ) ), this, SLOT( sendValues( ) ) );

}

Expand All @@ -133,48 +133,48 @@ void ControlWindow::createGraphBox ( ) {


iterationRedLabel = new QLabel( "Red iteration min/max:", graphBox );
minRbox = new QSpinBox(graphBox);
minRbox->setMinimum(0);
minRbox->setMaximum(INT_MAX);
minRbox->setAlignment(Qt::AlignCenter);
minRbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minRbox = new QSpinBox(graphBox);
minRbox->setMinimum(0);
minRbox->setMaximum(INT_MAX);
minRbox->setAlignment(Qt::AlignCenter);
minRbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minRbox->setValue(lowr);

maxRbox = new QSpinBox(graphBox);
maxRbox->setMinimum(0);
maxRbox->setMaximum(INT_MAX);
maxRbox->setAlignment(Qt::AlignCenter);
maxRbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxRbox = new QSpinBox(graphBox);
maxRbox->setMinimum(0);
maxRbox->setMaximum(INT_MAX);
maxRbox->setAlignment(Qt::AlignCenter);
maxRbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxRbox->setValue(highr);

iterationGreenLabel = new QLabel( "Green iteration min/max:", graphBox );
minGbox = new QSpinBox(graphBox);
minGbox->setMinimum(0);
minGbox->setMaximum(INT_MAX);
minGbox->setAlignment(Qt::AlignCenter);
minGbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minGbox = new QSpinBox(graphBox);
minGbox->setMinimum(0);
minGbox->setMaximum(INT_MAX);
minGbox->setAlignment(Qt::AlignCenter);
minGbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minGbox->setValue(lowg);

maxGbox = new QSpinBox(graphBox);
maxGbox->setMinimum(0);
maxGbox->setMaximum(INT_MAX);
maxGbox->setAlignment(Qt::AlignCenter);
maxGbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxGbox = new QSpinBox(graphBox);
maxGbox->setMinimum(0);
maxGbox->setMaximum(INT_MAX);
maxGbox->setAlignment(Qt::AlignCenter);
maxGbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxGbox->setValue(highg);

iterationBlueLabel = new QLabel( "Blue iteration min/max:", graphBox );
minBbox = new QSpinBox(graphBox);
minBbox->setMinimum(0);
minBbox->setMaximum(INT_MAX);
minBbox->setAlignment(Qt::AlignCenter);
minBbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minBbox = new QSpinBox(graphBox);
minBbox->setMinimum(0);
minBbox->setMaximum(INT_MAX);
minBbox->setAlignment(Qt::AlignCenter);
minBbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
minBbox->setValue(lowb);

maxBbox = new QSpinBox(graphBox);
maxBbox->setMinimum(0);
maxBbox->setMaximum(INT_MAX);
maxBbox->setAlignment(Qt::AlignCenter);
maxBbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxBbox = new QSpinBox(graphBox);
maxBbox->setMinimum(0);
maxBbox->setMaximum(INT_MAX);
maxBbox->setAlignment(Qt::AlignCenter);
maxBbox->setButtonSymbols( QAbstractSpinBox::PlusMinus );
maxBbox->setValue(highb);


Expand Down Expand Up @@ -210,26 +210,26 @@ void ControlWindow::createGraphBox ( ) {


QVBoxLayout *vbox = new QVBoxLayout ( );
QHBoxLayout *rHLayout = new QHBoxLayout( );
QHBoxLayout *gHLayout = new QHBoxLayout( );
QHBoxLayout *bHLayout = new QHBoxLayout( );
QHBoxLayout *rHLayout = new QHBoxLayout( );
QHBoxLayout *gHLayout = new QHBoxLayout( );
QHBoxLayout *bHLayout = new QHBoxLayout( );



vbox->addWidget( iterationRedLabel );
rHLayout->addWidget(minRbox);
rHLayout->addWidget(maxRbox);
vbox->addLayout(rHLayout);
rHLayout->addWidget(minRbox);
rHLayout->addWidget(maxRbox);
vbox->addLayout(rHLayout);

vbox->addWidget( iterationGreenLabel );
gHLayout->addWidget(minGbox);
gHLayout->addWidget(maxGbox);
vbox->addLayout(gHLayout);
gHLayout->addWidget(minGbox);
gHLayout->addWidget(maxGbox);
vbox->addLayout(gHLayout);

vbox->addWidget( iterationBlueLabel );
bHLayout->addWidget(minBbox);
bHLayout->addWidget(maxBbox);
vbox->addLayout(bHLayout);
bHLayout->addWidget(minBbox);
bHLayout->addWidget(maxBbox);
vbox->addLayout(bHLayout);

//vbox->addStretch(1);
vbox->addWidget( reLabel );
Expand All @@ -239,7 +239,7 @@ void ControlWindow::createGraphBox ( ) {
vbox->addWidget( zoomLabel );
vbox->addWidget( zoomBox );
//vbox->addStretch(1);
graphBox->setLayout( vbox );
graphBox->setLayout( vbox );


}
Expand Down Expand Up @@ -276,10 +276,10 @@ void ControlWindow::createRenderBox ( ) {
threadsLabel = new QLabel( "Threads:", renderBox );
threadsSlider = new QSlider( renderBox );
threadsSlider->setMinimum( 1 );
threadsSlider->setMaximum( QThread::idealThreadCount() );
threadsSlider->setMaximum( QThread::idealThreadCount() );
threadsSlider->setOrientation(Qt::Horizontal);
updateThreadLabel( QThread::idealThreadCount() );
threadsSlider->setValue( QThread::idealThreadCount() );
updateThreadLabel( QThread::idealThreadCount() );
threadsSlider->setValue( QThread::idealThreadCount() );

QVBoxLayout *vbox = new QVBoxLayout ( );
vbox->addWidget( contrastLabel );
Expand Down Expand Up @@ -411,7 +411,7 @@ void ControlWindow::handleStartButton ( ) {
emit startCalculation( );
renderWin->timer->start( sleepTime );

screenShotAct->setEnabled( true );
screenShotAct->setEnabled( true );

if ( renderWin->isHidden() )
renderWin->show();
Expand Down Expand Up @@ -460,13 +460,6 @@ void ControlWindow::modelToGUI ( ) {










// FUNCTIONS FOR THE INPUT WIDGETS

void ControlWindow::updateFpsLabel( ) {
Expand Down Expand Up @@ -503,7 +496,7 @@ void ControlWindow::setMaxBIteration(int value) {


void ControlWindow::setLightness ( int value ) {
lightness = value;
lightness = value;
//b->setLightness( (double) value / ( lightSlider->maximum() - value + 1 ) );
//qDebug() <<"Lightness: %d %lf\n", value,(double) value / ( lightSlider->maximum() - value ) );
lightLabel->setText( "Lightness [" + QString::number( lightness, 'd', 1 ) + "]" );
Expand All @@ -512,8 +505,8 @@ void ControlWindow::setLightness ( int value ) {
}

void ControlWindow::setContrast ( int value ) {
contrast = value;
contrastLabel->setText( "Contrast: [" + QString::number( contrast, 'd', 1 ) + "]" );
contrast = value;
contrastLabel->setText( "Contrast: [" + QString::number( contrast, 'd', 1 ) + "]" );
// ottengo un valore fra 0.0 e 2.0
//b->setContrast( (double) value / contrastSlider->maximum() * 2.0 );
b->setContrast( value );
Expand Down Expand Up @@ -573,11 +566,6 @@ void ControlWindow::showEvent( QShowEvent* ) {








// UTILITY FUNCTIONS


Expand Down Expand Up @@ -631,6 +619,3 @@ void ControlWindow::saveScreenshot ( ) {

emit screenshotRequest( fileName );
}



2 changes: 0 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
#include <iostream>
#include <QApplication>
#include "controlWindow.h"
//#include "options.h"

int main ( int argc, char** argv ) {
qDebug() << "main(), thread " << QThread::currentThreadId();
QApplication app(argc, argv);
ControlWindow control;
//Options options( &control, argc, argv );
control.show( );
int out = app.exec();
return out;
Expand Down
15 changes: 8 additions & 7 deletions renderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ void RenderWindow::paintEvent( QPaintEvent* ) {


void RenderWindow::mousePressEvent(QMouseEvent *event) {
qDebug() << "RenderWindow::mousePressEvent()";
begMouse = endMouse = event->pos();
qDebug() << "RenderWindow::mousePressEvent() " << begMouse;
}


Expand All @@ -142,7 +142,7 @@ void RenderWindow::mouseMoveEvent(QMouseEvent *event) {
if (event->buttons() & Qt::LeftButton) {
endMouse = event->pos();
if ( endMouse.x() > size().width() ) endMouse.setX( size().width() );
if ( endMouse.y() > size().height() ) endMouse.setY( size().height() );
if ( endMouse.y() > size().height() ) endMouse.setY( size().height() );
}

if ( event->buttons() & Qt::RightButton || event->buttons() & Qt::MidButton ) {
Expand All @@ -155,18 +155,18 @@ void RenderWindow::mouseMoveEvent(QMouseEvent *event) {


void RenderWindow::mouseReleaseEvent(QMouseEvent *event) {
qDebug() << "RenderWindow::mouseReleaseEvent()";
endMouse = event->pos();
qDebug() << "RenderWindow::mouseReleaseEvent()" << endMouse;

if ( endMouse == begMouse ) return;


if ( event->button() == Qt::LeftButton ) {

if ( endMouse.x() > size().width() ) endMouse.setX( size().width() );
if ( endMouse.y() > size().height() ) endMouse.setY( size().height() );
if ( endMouse.y() > size().height() ) endMouse.setY( size().height() );

// calcolo il nuovo zoom
double scalex = (double) width() / fabs( (float) (( endMouse - begMouse ).x()) );
double scalex = (double) width() / fabs( (float) (( endMouse - begMouse ).x()) );
double scaley = (double) height() / fabs( (float) (( endMouse - begMouse ).y()) );
double scale = min( scalex, scaley );

Expand All @@ -177,7 +177,8 @@ void RenderWindow::mouseReleaseEvent(QMouseEvent *event) {
// TODO ugly, this has been just set in the previous call
//parent->putValues( b->cre + dx / b->scale, b->cim - dy / b->scale, parent->getScale() );
parent->setCre( b->cre + dx / b->scale );
parent->setCim( b->cim + dy / b->scale );
//parent->setCim( b->cim + dy / b->scale );
parent->setCim( b->cim - dy / b->scale );
parent->modelToGUI();
parent->sendValues( true );
disabledDrawing = true;
Expand Down

0 comments on commit 14052db

Please sign in to comment.