00001
00042 #include "aimainwindow.hpp"
00043
00044 using namespace AiFractals;
00045 using namespace AiGenerator;
00046
00047 AiMainWindow::AiMainWindow()
00048 :m_saveFile(),m_selectedFractalIndex(0),m_currentThreadsNumber(1),m_startedThreads(1),
00049 m_firstCompositionModeIndex(QPainter::CompositionMode_Source), m_othersCompositionModeIndex(QPainter::CompositionMode_Screen),
00050 m_viewX( .0 ), m_viewY( .0 ), m_zoom( 1. ),
00051 m_serialize( false )
00052 {
00053
00054
00055
00056 m_menuBar = new AiMenuBar( this );
00057
00058 m_toolbar = new AiToolBar(this);
00059
00060 m_statusbar = new AiStatusBar();
00061
00062 m_view = new AiViewerArea(this);
00063
00064 m_config = new AiConfig(this);
00065
00066 m_undoDialog = new AiUndoDialog( m_view->view()->stack, this );
00067
00068
00069
00070
00071
00072 this->connect( m_menuBar, SIGNAL(fileOpen()), this, SLOT(fileOpen()));
00073 this->connect( m_menuBar, SIGNAL(fileSave()), this, SLOT(fileSave()));
00074 this->connect( m_menuBar, SIGNAL(fileSaveAs()), this, SLOT(fileSaveAs()));
00075 this->connect( m_menuBar, SIGNAL(filePrint()), this, SLOT(filePrint()));
00076 this->connect( m_menuBar, SIGNAL(fileClear()), this, SLOT(fileClear()));
00077 this->connect( m_menuBar, SIGNAL(fileQuit()), this, SLOT(fileQuit()));
00078
00079
00080 this->connect( m_menuBar, SIGNAL(zoomZoomIn()), this, SLOT(zoomZoomIn()));
00081 this->connect( m_menuBar, SIGNAL(zoomZoomOut()), this, SLOT(zoomZoomOut()));
00082 this->connect( m_menuBar, SIGNAL(zoomFitInWindow()), this, SLOT(zoomFitInWindow()));
00083 this->connect( m_menuBar, SIGNAL(zoomFitToWindow()), this, SLOT(zoomFitToWindow()));
00084 this->connect( m_menuBar, SIGNAL(zoom1600p()), this, SLOT(zoom1600p()));
00085 this->connect( m_menuBar, SIGNAL(zoom800p()), this, SLOT(zoom800p()));
00086 this->connect( m_menuBar, SIGNAL(zoom400p()), this, SLOT(zoom400p()));
00087 this->connect( m_menuBar, SIGNAL(zoom200p()), this, SLOT(zoom200p()));
00088 this->connect( m_menuBar, SIGNAL(zoom100p()), this, SLOT(zoom100p()));
00089 this->connect( m_menuBar, SIGNAL(zoom50p()), this, SLOT(zoom50p()));
00090 this->connect( m_menuBar, SIGNAL(zoom25p()), this, SLOT(zoom25p()));
00091 this->connect( m_menuBar, SIGNAL(zoom12_5p()), this, SLOT(zoom12_5p()));
00092 this->connect( m_menuBar, SIGNAL(zoom6_25p()), this, SLOT(zoom6_25p()));
00093
00094
00095 this->connect( m_menuBar, SIGNAL(imageHorizontalMirror()), this, SLOT(imageHorizontalMirror()));
00096 this->connect( m_menuBar, SIGNAL(imageVerticalMirror()), this, SLOT(imageVerticalMirror()));
00097 this->connect( m_menuBar, SIGNAL(imageRotation90()), this, SLOT(imageRotation90()));
00098 this->connect( m_menuBar, SIGNAL(imageRotationNigative90()), this, SLOT(imageRotationNigative90()));
00099 this->connect( m_menuBar, SIGNAL(imageRotation180()), this, SLOT(imageRotation180()));
00100
00101
00102 this->connect( m_menuBar, SIGNAL(genRun()), this, SLOT(genRun()));
00103 this->connect( m_menuBar, SIGNAL(genStop()), this, SLOT(genStop()));
00104 this->connect( m_menuBar, SIGNAL(genThreadsNumbers()), this, SLOT(genThreadsNumbers()));
00105 this->connect( m_menuBar, SIGNAL(genChooseFractal()), this, SLOT(genChooseFractal()));
00106 this->connect( m_menuBar, SIGNAL(complexZone()), this, SLOT(complexZone()));
00107 this->connect( m_menuBar, SIGNAL(serialize()), this, SLOT(serialize()));
00108 this->connect( m_menuBar, SIGNAL(deserialize()), this, SLOT(deserialize()));
00109
00110
00111 this->connect( m_menuBar, SIGNAL(helpAbout()), this, SLOT(helpAbout()));
00112 this->connect( m_menuBar, SIGNAL(helpHelp()), this, SLOT(helpHelp()));
00113
00114
00115 this->connect( m_toolbar, SIGNAL(toolbox(bool)),this,SLOT(showToolbox(bool)));
00116 this->connect( m_toolbar, SIGNAL(fileOpen()), this, SLOT(fileOpen()));
00117 this->connect( m_toolbar, SIGNAL(fileSave()), this, SLOT(fileSave()));
00118 this->connect( m_toolbar, SIGNAL(fileClear()), this, SLOT(fileClear()));
00119 this->connect( m_toolbar, SIGNAL(zoomIn()), this, SLOT(zoomZoomIn()));
00120 this->connect( m_toolbar, SIGNAL(zoomOut()), this, SLOT(zoomZoomOut()));
00121 this->connect( m_toolbar, SIGNAL(mirrorH()), this, SLOT(imageHorizontalMirror()));
00122 this->connect( m_toolbar, SIGNAL(mirrorV()), this, SLOT(imageVerticalMirror()));
00123 this->connect( m_toolbar, SIGNAL(complexZone()), this, SLOT(complexZone()));
00124 this->connect( m_toolbar, SIGNAL(helpAbout()), this, SLOT(helpAbout()));
00125 this->connect( m_toolbar ,SIGNAL(complexRun()),this,SLOT(runGenerator()));
00126 this->connect( m_toolbar ,SIGNAL(complexStop()),this,SLOT(stopGenerator()));
00127 this->connect( m_toolbar ,SIGNAL(undo()),this,SLOT(undo()));
00128
00129
00130 this->connect(m_config ,SIGNAL(closed()),this,SLOT(checkedToolbox()));
00131 this->connect(m_config ,SIGNAL(zoomIn()),this,SLOT(zoomZoomIn()));
00132 this->connect(m_config ,SIGNAL(zoomOut()),this,SLOT(zoomZoomOut()));
00133 this->connect(m_config ,SIGNAL(zoomArea(bool)),this,SLOT(toolsZoomArea(bool)));
00134 this->connect(m_config ,SIGNAL(horizontalMirror()),this,SLOT(imageHorizontalMirror()));
00135 this->connect(m_config ,SIGNAL(verticalMirror()),this,SLOT(imageVerticalMirror()));
00136 this->connect(m_config ,SIGNAL(clear()),this,SLOT(fileClear()));
00137 this->connect(m_config ,SIGNAL(rotation(int)),this,SLOT(toolsRotation(int)));
00138 this->connect(m_config ,SIGNAL(refreshItems()),this,SLOT(refreshItems()));
00139 this->connect(m_config ,SIGNAL(debugFractal()),this,SLOT(debugFractal()));
00140 this->connect(m_config ,SIGNAL(currentIndexChanged(int)),this,SLOT(currentIndexChanged(int)));
00141 this->connect(m_config ,SIGNAL(currentThreads(int)),this,SLOT(currentThreads(int)));
00142 this->connect(m_config ,SIGNAL(firstCompositionMode(int)),this,SLOT(firstCompositionMode(int)));
00143 this->connect(m_config ,SIGNAL(othersCompositionMode(int)),this,SLOT(othersCompositionMode(int)));
00144 this->connect(m_config ,SIGNAL(runGenerator()),this,SLOT(runGenerator()));
00145 this->connect(m_config ,SIGNAL(stopGenerator()),this,SLOT(stopGenerator()));
00146
00147 this->connect(m_view ,SIGNAL(zoneZooming(int,int,int,int)),this,SLOT(zoneZooming(int,int,int,int)));
00148 this->connect(m_view ,SIGNAL(enabledChilds(bool)),this,SLOT(enabledChilds(bool)));
00149
00150 this->setMenuBar( m_menuBar );
00151 this->addToolBar( m_toolbar );
00152 this->setStatusBar( m_statusbar );
00153 this->setCentralWidget( m_view );
00154
00155
00156 this->enabledChilds( false );
00157
00158 m_config->resize(200,400);
00159 this->resize(500,400);
00160 }
00161
00162 void AiMainWindow::showToolbox(bool show)
00163 {
00164 m_config->setShown( show );
00165 }
00166
00167 void AiMainWindow::checkedToolbox()
00168 {
00169 m_toolbar->checkedToolbox( false );
00170 }
00171
00172 void AiMainWindow::fileOpen()
00173 {
00174 try
00175 {
00176
00177 if( !m_view->view()->emptyScreen() )
00178 {
00179 if( QMessageBox::Open != QMessageBox::warning(this, tr("Open...") , tr("The screen is not empty, you want really open another file in this screen ?"), QMessageBox::Open | QMessageBox::Cancel, QMessageBox::Cancel ) )
00180 {
00181 return;
00182 }
00183 }
00184
00185
00186 QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "", tr("Image File (*.png)"));
00187 m_view->view()->makeUpdate( fileName );
00188 if( !fileName.isNull() && !fileName.isEmpty() )
00189 {
00190 this->enabledChilds( true );
00191 }
00192 }
00193 catch(const std::exception & exception )
00194 {
00195 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00196 }
00197 }
00198
00199 void AiMainWindow::fileSave()
00200 {
00201 try
00202 {
00203
00204
00205 if( m_saveFile.isEmpty() )
00206 {
00207 m_saveFile = QFileDialog::getSaveFileName(this, tr("Save Image"), "", tr("Image File (*.png)"));
00208 }
00209
00210
00211 m_view->view()->saveAs( m_saveFile );
00212 }
00213 catch(const std::exception & exception )
00214 {
00215 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00216 }
00217 }
00218
00219 void AiMainWindow::fileSaveAs()
00220 {
00221 try
00222 {
00223
00224 m_saveFile = QFileDialog::getSaveFileName(this, tr("Save Image"), "", tr("Image File (*.png)")) ;
00225 m_view->view()->saveAs( m_saveFile );
00226 }
00227 catch(const std::exception & exception )
00228 {
00229 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00230 }
00231 }
00232
00233 void AiMainWindow::filePrint()
00234 {
00235 try
00236 {
00237
00238 m_view->view()->print();
00239 }
00240 catch(const std::exception & exception )
00241 {
00242 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00243 }
00244 }
00245
00246 void AiMainWindow::fileClear()
00247 {
00248 try
00249 {
00250
00251 if( !m_view->view()->emptyScreen() )
00252 {
00253 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Clear...") , tr("The screen is not empty, you want really clear this screen ?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00254 {
00255 return;
00256 }
00257 }
00258 m_view->view()->clear();
00259 this->enabledChilds( false );
00260 m_zoom = 1.;
00261 m_viewX = m_viewY = .0;
00262 }
00263 catch(const std::exception & exception )
00264 {
00265 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00266 }
00267 }
00268
00269 void AiMainWindow::fileQuit()
00270 {
00271 try
00272 {
00273 this->close();
00274 }
00275 catch(const std::exception & exception )
00276 {
00277 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00278 }
00279 }
00280
00281 void AiMainWindow::zoomZoomIn()
00282 {
00283 try
00284 {
00285 m_view->view()->scale(1.5,1.5);
00286 }
00287 catch(const std::exception & exception )
00288 {
00289 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00290 }
00291 }
00292
00293 void AiMainWindow::zoomZoomOut()
00294 {
00295 try
00296 {
00297 m_view->view()->scale(-.5,-.5);
00298 }
00299 catch(const std::exception & exception )
00300 {
00301 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00302 }
00303 }
00304
00305 void AiMainWindow::zoomFitInWindow()
00306 {
00307 try
00308 {
00309 m_view->view()->fillInWindow();
00310 }
00311 catch(const std::exception & exception )
00312 {
00313 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00314 }
00315 }
00316
00317 void AiMainWindow::zoomFitToWindow()
00318 {
00319 try
00320 {
00321 m_view->view()->fillToWindow();
00322 }
00323 catch(const std::exception & exception )
00324 {
00325 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00326 }
00327 }
00328
00329 void AiMainWindow::zoom1600p()
00330 {
00331 try
00332 {
00333 m_view->view()->clearScale();
00334 m_view->view()->scale(16.,16.);
00335 }
00336 catch(const std::exception & exception )
00337 {
00338 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00339 }
00340 }
00341
00342 void AiMainWindow::zoom800p()
00343 {
00344 try
00345 {
00346 m_view->view()->clearScale();
00347 m_view->view()->scale(8.,8.);
00348 }
00349 catch(const std::exception & exception )
00350 {
00351 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00352 }
00353 }
00354
00355 void AiMainWindow::zoom400p()
00356 {
00357 try
00358 {
00359 m_view->view()->clearScale();
00360 m_view->view()->scale(4.,4.);
00361 }
00362 catch(const std::exception & exception )
00363 {
00364 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00365 }
00366 }
00367
00368 void AiMainWindow::zoom200p()
00369 {
00370 try
00371 {
00372 m_view->view()->clearScale();
00373 m_view->view()->scale(2.,2.);
00374 }
00375 catch(const std::exception & exception )
00376 {
00377 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00378 }
00379 }
00380
00381 void AiMainWindow::zoom100p()
00382 {
00383 try
00384 {
00385 m_view->view()->clearScale();
00386 m_view->view()->scale(1.,1.);
00387 }
00388 catch(const std::exception & exception )
00389 {
00390 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00391 }
00392 }
00393
00394 void AiMainWindow::zoom50p()
00395 {
00396 try
00397 {
00398 m_view->view()->clearScale();
00399 m_view->view()->scale(.5,.5);
00400 }
00401 catch(const std::exception & exception )
00402 {
00403 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00404 }
00405 }
00406
00407 void AiMainWindow::zoom25p()
00408 {
00409 try
00410 {
00411 m_view->view()->clearScale();
00412 m_view->view()->scale(-.25,-.25);
00413 }
00414 catch(const std::exception & exception )
00415 {
00416 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00417 }
00418 }
00419
00420 void AiMainWindow::zoom12_5p()
00421 {
00422 try
00423 {
00424 m_view->view()->clearScale();
00425 m_view->view()->scale(0.125,.125);
00426 }
00427 catch(const std::exception & exception )
00428 {
00429 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00430 }
00431 }
00432
00433 void AiMainWindow::zoom6_25p()
00434 {
00435 try
00436 {
00437 m_view->view()->clearScale();
00438 m_view->view()->scale(.0625,.0625);
00439 }
00440 catch(const std::exception & exception )
00441 {
00442 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00443 }
00444 }
00445
00446 void AiMainWindow::imageHorizontalMirror()
00447 {
00448 try
00449 {
00450 m_view->view()->retate( 361. );
00451 }
00452 catch(const std::exception & exception )
00453 {
00454 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00455 }
00456 }
00457
00458 void AiMainWindow::imageVerticalMirror()
00459 {
00460 try
00461 {
00462 m_view->view()->retate( 362. );
00463 }
00464 catch(const std::exception & exception )
00465 {
00466 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00467 }
00468 }
00469
00470 void AiMainWindow::imageRotation90()
00471 {
00472 try
00473 {
00474 m_view->view()->retate( 90. );
00475 }
00476 catch(const std::exception & exception )
00477 {
00478 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00479 }
00480 }
00481
00482 void AiMainWindow::imageRotationNigative90()
00483 {
00484 try
00485 {
00486 m_view->view()->retate( -90. );
00487 }
00488 catch(const std::exception & exception )
00489 {
00490 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00491 }
00492 }
00493
00494 void AiMainWindow::imageRotation180()
00495 {
00496 try
00497 {
00498 m_view->view()->retate( 180. );
00499 }
00500 catch(const std::exception & exception )
00501 {
00502 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00503 }
00504 }
00505
00506 void AiMainWindow::genRun()
00507 {
00508 try
00509 {
00510
00511
00512 m_config->activeTab( 3 ) ;
00513 m_toolbar->checkedToolbox( true );
00514 m_config->setShown( true );
00515 }
00516 catch(const std::exception & exception )
00517 {
00518 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00519 }
00520 }
00521
00522 void AiMainWindow::genStop()
00523 {
00524 try
00525 {
00526 this->genRun();
00527 }
00528 catch(const std::exception & exception )
00529 {
00530 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00531 }
00532 }
00533
00534 void AiMainWindow::genThreadsNumbers()
00535 {
00536 try
00537 {
00538 this->genRun();
00539 }
00540 catch(const std::exception & exception )
00541 {
00542 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00543 }
00544 }
00545
00546 void AiMainWindow::genChooseFractal()
00547 {
00548 try
00549 {
00550
00551
00552 m_config->activeTab( 1 ) ;
00553 m_toolbar->checkedToolbox( true );
00554 m_config->setShown( true );
00555 }
00556 catch(const std::exception & exception )
00557 {
00558 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00559 }
00560 }
00561
00562 void AiMainWindow::complexZone()
00563 {
00564 try
00565 {
00566
00567
00568 m_config->activeTab( 2 ) ;
00569 m_toolbar->checkedToolbox( true );
00570 m_config->setShown( true );
00571 }
00572 catch(const std::exception & exception )
00573 {
00574 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00575 }
00576 }
00577
00578 void AiMainWindow::serialize()
00579 {
00580 try
00581 {
00582
00583 if( m_threads.size() > 0 )
00584 {
00585 if( m_threads[ 0 ]->isRunning() )
00586 {
00587 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Serialization...") , tr("GOD MODE stop all current threads, you want continue?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00588 {
00589 return;
00590 }
00591 else
00592 {
00593
00594 m_serialize = true;
00595
00596
00597
00598 for( int index = 0 ; index < m_threads.size() ; index++ )
00599 {
00600 m_threads[ index ]->stop();
00601 m_threads[ index ]->wait();
00602 }
00603
00604 }
00605 }
00606 }
00607 else
00608 {
00609 QMessageBox::warning(this, tr("Threads"), tr("No threads for using 'GOD MODE' =)!"), QMessageBox::Ok) ;
00610 return;
00611 }
00612
00613
00614 QString toFile = QFileDialog::getSaveFileName(this, tr("Serialization"), "", tr("File (*.adrabi)")) ;
00615 if( !toFile.isNull() && !toFile.isEmpty() )
00616 {
00617 QFile file( toFile );
00618 file.open(QIODevice::WriteOnly);
00619
00620
00621
00622 QDataStream stream( &file );
00623 stream.setVersion(QDataStream::Qt_4_6);
00624 stream << QTime::currentTime()
00625 << QDate::currentDate()
00626 << (m_threads.count());
00627
00628
00629
00630 for( int x = 0 ; x < m_threads.count() ; x++ )
00631 {
00632 AiZone * zone = m_threads[ x ]->getZone();
00633 zone->serialize( stream );
00634
00635 }
00636 }
00637
00638 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Threads...") , tr("You want clean all threads now?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00639 {
00640 return;
00641 }
00642
00643
00644 for( int index = 0 ; index < m_threads.size() ; index++ )
00645 {
00646 delete m_threads[ index ];
00647 }
00648 m_threads.clear();
00649 }
00650 catch(const std::exception & exception )
00651 {
00652 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00653 }
00654 }
00655
00656 void AiMainWindow::deserialize()
00657 {
00658 try
00659 {
00660
00661 if( m_threads.size() > 0 )
00662 {
00663 if( m_threads[ 0 ]->isRunning() )
00664 {
00665 QMessageBox::warning(this, tr("Threads"), tr("Current threads is running, please stop them before running a new deserialization!"), QMessageBox::Ok) ;
00666 return;
00667 }
00668 }
00669
00670 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Deserialization...") , tr("Make sure you are choosing right script and composition modes?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00671 {
00672 return;
00673 }
00674
00675 QString fileName = QFileDialog::getOpenFileName(this, tr("Deserialization..."), "", tr("File (*.adrabi)"));
00676 if( fileName.isNull() || fileName.isEmpty() )
00677 {
00678 return;
00679 }
00680
00681
00682
00683 for( int index = 0 ; index < m_threads.size() ; index++ )
00684 {
00685 m_threads[ index ]->stop();
00686 m_threads[ index ]->wait();
00687 }
00688
00689 for( int index = 0 ; index < m_threads.size() ; index++ )
00690 {
00691 delete m_threads[ index ];
00692 }
00693 m_threads.clear();
00694
00695
00696 QFile file( fileName );
00697 file.open(QIODevice::ReadOnly);
00698
00699 QDataStream stream( &file );
00700 stream.setVersion(QDataStream::Qt_4_6);
00701 QTime time; QDate date;
00702 stream >> time
00703 >> date
00704 >> m_startedThreads;
00705
00706
00707 this->m_statusbar->start();
00708
00709
00710 if( m_storage.count() > 0 )
00711 {
00712 m_storage.clear();
00713 }
00714 m_storage = QVector<QImage>( m_startedThreads );
00715
00716 for( int x = 0 ; x < m_startedThreads ; x++ )
00717 {
00718 AiZone zone (0,0,0,0,0,0,0,0,0,0,0,0,0);
00719 zone.deserialize( stream );
00720
00721
00722 AiThread * thread = new AiThread( this );
00723 thread->setZone( zone );
00724 thread->scriptFile( "scripts/" + m_config->item( m_selectedFractalIndex ) );
00725
00726 qRegisterMetaType<AiGenerator::AiZone*>("AiGenerator::AiZone");
00727 this->connect( thread, SIGNAL(completed(AiGenerator::AiZone*)) , this, SLOT(completed(AiGenerator::AiZone*)));
00728 this->connect( thread, SIGNAL(snapshot(AiGenerator::AiZone*)) , this, SLOT(snapshot(AiGenerator::AiZone*)));
00729
00730 if( x == 0 )
00731 {
00732
00733
00734
00735 this->connect(thread,SIGNAL(progressStatus(int)), m_statusbar, SLOT(setGenStatus(int)));
00736 m_zoom = zone.getZoom();
00737 m_viewX= zone.getViewX();
00738 m_viewY= zone.getViewY();
00739
00740
00741 m_config->setZoneWidth( zone.getZoneWidth() );
00742 m_config->setZoneHeight( zone.getZoneHeight());
00743 m_config->setZoneMinX( zone.getX() );
00744 m_config->setZoneMinY( zone.getY() );
00745 m_config->setImageWidth( zone.getImageWidth() );
00746 m_config->setImageHeight( zone.getImageHeight() );
00747 m_config->setIterations( zone.getIteration() );
00748 m_config->setThreadsNumber( m_startedThreads );
00749 }
00750
00751 m_threads.push_back( thread );
00752 }
00753
00754 for( int x = 0 ; x < m_threads.count() ; x++ )
00755 {
00756 m_threads[ x ]->start();
00757 }
00758
00759 m_statusbar->startGenerating();
00760 m_statusbar->setInfo( QString( "[Threads: %1 ]" ).arg( m_startedThreads ) );
00761
00762
00763 this->enabledChilds( false );
00764 this->toolsZoomArea( false );
00765 m_config->disableZoomArea();
00766
00767 }
00768 catch(const std::exception & exception )
00769 {
00770 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00771 }
00772 }
00773
00774 void AiMainWindow::helpHelp()
00775 {
00776 try
00777 {
00778 AiHelp * help = new AiHelp( );
00779 help->setAttribute(Qt::WA_QuitOnClose, false);
00780 help->show();
00781 }
00782 catch(const std::exception & exception )
00783 {
00784 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00785 }
00786 }
00787
00788 void AiMainWindow::helpAbout()
00789 {
00790 try
00791 {
00792 AiAbout * about = new AiAbout( );
00793 about->setModal( true );
00794 about->show();
00795 }
00796 catch(const std::exception & exception )
00797 {
00798 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00799 }
00800 }
00801
00802 void AiMainWindow::toolsZoomArea(bool enable)
00803 {
00804 try
00805 {
00806 m_view->view()->zooming( enable );
00807 }
00808 catch(const std::exception & exception )
00809 {
00810 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00811 }
00812 }
00813
00814 void AiMainWindow::toolsRotation(int value)
00815 {
00816 try
00817 {
00818 m_view->view()->retate( static_cast<qreal>( value ) );
00819 }
00820 catch(const std::exception & exception )
00821 {
00822 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00823 }
00824 }
00825
00826 void AiMainWindow::refreshItems()
00827 {
00828 try
00829 {
00830 QDir dir("scripts");
00831 if( !dir.exists() )
00832 {
00833
00834 dir.mkdir("scripts");
00835 }
00836
00837
00838 QFileInfoList entries = dir.entryInfoList(QStringList() << "*.js");
00839 QStringList list;
00840 for (int i = 0; i < entries.size(); ++i)
00841 {
00842 list << entries.at(i).fileName();
00843 }
00844 if( !list.empty() )
00845 {
00846 m_config->addItems( list );
00847 }
00848 else
00849 {
00850 QMessageBox::information(this, tr("Fractals scripts"), tr("Please add your fractals scripts in folder \"[AiFractals-dir]/scripts\" =)."));
00851 }
00852 }
00853 catch(const std::exception & exception )
00854 {
00855 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00856 }
00857 }
00858
00859 void AiMainWindow::currentIndexChanged ( int index )
00860 {
00861 try
00862 {
00863 m_selectedFractalIndex = index;
00864 }
00865 catch(const std::exception & exception )
00866 {
00867 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00868 }
00869 }
00870
00871 void AiMainWindow::debugFractal()
00872 {
00873 try
00874 {
00875 m_startedThreads = m_currentThreadsNumber;
00876
00877 if( (m_config->getImageWidth() == 0 || m_config->getImageHeight() == 0) )
00878 {
00879 QMessageBox::warning(this, tr("Config"), tr("Please, setup a fractal config!"), QMessageBox::Ok) ;
00880 this->complexZone();
00881 return;
00882 }
00883
00884 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Debug...") , tr("You want really debug this script ?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
00885 {
00886 return;
00887 }
00888
00889
00890 AiZone * zone = new AiZone(this,
00891 m_config->getZoneMinX(),
00892 m_config->getZoneMinY(),
00893 m_config->getZoneWidth(),
00894 m_config->getZoneHeight(),
00895 m_config->getImageWidth(),
00896 m_config->getImageHeight(),
00897 0,
00898 m_startedThreads,
00899 m_config->getIterations() ,
00900 m_zoom,
00901 m_viewX,
00902 m_viewY);
00903
00904 QScriptEngine engine;
00905 {
00906 QScriptValue qs_zone = engine.newQObject( zone );
00907 engine.globalObject().setProperty( "zone" , qs_zone );
00908 }
00909 QScriptEngineDebugger debugger(this);
00910 debugger.attachTo(&engine);
00911 debugger.standardWindow()->setWindowModality(Qt::ApplicationModal);
00912
00913
00914
00915 QString fileName("scripts/" + m_config->item( m_selectedFractalIndex ));
00916 QString script;
00917 {
00918 QFile file( fileName );
00919 file.open(QIODevice::ReadOnly);
00920 script = file.readAll();
00921 file.close();
00922 }
00923
00924 debugger.action(QScriptEngineDebugger::InterruptAction)->trigger();
00925 engine.evaluate(script, fileName);
00926
00927
00928
00929 m_view->view()->clear();
00930 m_view->view()->makeUpdate( zone->image(), true );
00931 this->enabledChilds( true );
00932
00933 delete zone;
00934 }
00935 catch(const std::exception & exception )
00936 {
00937 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
00938 }
00939 }
00940
00941 void AiMainWindow::currentThreads(int thread)
00942 {
00943 m_currentThreadsNumber = thread;
00944 }
00945
00946 void AiMainWindow::firstCompositionMode( int val )
00947 {
00948 m_firstCompositionModeIndex = forgeCompositionMode( val );
00949 }
00950
00951 void AiMainWindow::othersCompositionMode( int val )
00952 {
00953 m_othersCompositionModeIndex = forgeCompositionMode( val );
00954 }
00955
00956 void AiMainWindow::runGenerator()
00957 {
00958 try
00959 {
00960 m_startedThreads = m_currentThreadsNumber;
00961
00962 if( (m_config->getImageWidth() == 0 || m_config->getImageHeight() == 0) )
00963 {
00964 QMessageBox::warning(this, tr("Config"), tr("Please, setup a fractal config!"), QMessageBox::Ok) ;
00965 this->complexZone();
00966 return;
00967 }
00968
00969
00970 if( m_threads.size() > 0 )
00971 {
00972 if( m_threads[ 0 ]->isRunning() )
00973 {
00974 QMessageBox::warning(this, tr("Threads"), tr("Current threads is running, please stop them before running a new threads!"), QMessageBox::Ok) ;
00975 return;
00976 }
00977 }
00978
00979
00980 this->m_statusbar->start();
00981
00982
00983 for( int index = 0 ; index < m_threads.size() ; index++ )
00984 {
00985 delete m_threads[ index ];
00986 }
00987 m_threads.clear();
00988
00989
00990 if( m_storage.count() > 0 )
00991 {
00992 m_storage.clear();
00993 }
00994 m_storage = QVector<QImage>( m_startedThreads );
00995
00996
00997 for( int index = 0 ; index < m_startedThreads ; index++ )
00998 {
00999 AiThread *thread = new AiThread(this);
01000 thread->makeZone( m_config->getZoneMinX() ,
01001 m_config->getZoneMinY() ,
01002 m_config->getZoneWidth() ,
01003 m_config->getZoneHeight() ,
01004 m_config->getImageWidth() ,
01005 m_config->getImageHeight(),
01006 index ,
01007 m_startedThreads ,
01008 m_config->getIterations(),
01009 m_zoom,
01010 m_viewX,
01011 m_viewY);
01012 thread->scriptFile( "scripts/" + m_config->item( m_selectedFractalIndex ) );
01013
01014 qRegisterMetaType<AiGenerator::AiZone*>("AiGenerator::AiZone");
01015 this->connect( thread, SIGNAL(completed(AiGenerator::AiZone*)) , this, SLOT(completed(AiGenerator::AiZone*)));
01016 this->connect( thread, SIGNAL(snapshot(AiGenerator::AiZone*)) , this, SLOT(snapshot(AiGenerator::AiZone*)));
01017
01018 if( index == 0 )
01019 {
01020
01021
01022
01023 this->connect(thread,SIGNAL(progressStatus(int)), m_statusbar, SLOT(setGenStatus(int)));
01024 }
01025
01026 m_threads.push_back( thread );
01027 }
01028
01029 for( int index = 0 ; index < m_threads.size() ; index++ )
01030 {
01031 m_threads[ index ]->start();
01032 }
01033
01034 m_statusbar->startGenerating();
01035 m_statusbar->setInfo( QString( "[Threads: %1 ]" ).arg( m_startedThreads ) );
01036
01037
01038 this->enabledChilds( false );
01039 this->toolsZoomArea( false );
01040 m_config->disableZoomArea();
01041
01042 }
01043 catch(const std::exception & exception )
01044 {
01045 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
01046 }
01047 }
01048
01049 void AiMainWindow::stopGenerator()
01050 {
01051 try
01052 {
01053
01054 if( m_threads.size() > 0 )
01055 {
01056 if( m_threads[ 0 ]->isRunning() )
01057 {
01058 if( QMessageBox::Ok == QMessageBox::warning(this, tr("Threads"), tr("Current threads is running you want to stop them ?."), QMessageBox::Ok | QMessageBox::Cancel) )
01059 {
01060
01061 for( int index = 0 ; index < m_threads.size() ; index++ )
01062 {
01063 m_threads[ index ]->stop();
01064 m_threads[ index ]->wait();
01065 }
01066 }
01067 else
01068 {
01069 return;
01070 }
01071 }
01072 }
01073 m_statusbar->stopGenerating();
01074 }
01075 catch(const std::exception & exception )
01076 {
01077 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
01078 }
01079 }
01080
01081 void AiMainWindow::snapshot( AiGenerator::AiZone * zone )
01082 {
01083 try
01084 {
01085 QMutex mutex;
01086 mutex.lock();
01087 {
01088 m_storage.replace( zone->getStartPoint(), zone->image() );
01089
01090 static int count = 0;
01091 count++;
01092 if ( count == m_startedThreads && m_storage.size() > 0 )
01093 {
01094 QImage tmp;
01095
01096 if( m_view->view()->emptyScreen() && m_config->getImageWidth() > 0 && m_config->getImageHeight() > 0 )
01097 {
01098 tmp = QImage(m_config->getImageWidth(), m_config->getImageHeight(), QImage::Format_RGB32);
01099 tmp.fill(Qt::transparent);
01100 }
01101 else if( (m_config->getImageWidth() == 0 || m_config->getImageHeight() == 0) && m_storage.count() > 0 )
01102 {
01103 tmp = QImage( m_storage[0].width(), m_storage[0].height(), QImage::Format_RGB32);
01104 tmp.fill(Qt::transparent);
01105 }
01106 else
01107 {
01108 tmp = m_view->view()->image();
01109 }
01110
01111 QPainter painter( &tmp );
01112 for( int index = 0 ; index < m_storage.size() ; index++ )
01113 {
01114 if( index == 0 )
01115 {
01116
01117 painter.setCompositionMode( m_firstCompositionModeIndex );
01118 }
01119 else
01120 {
01121 painter.setCompositionMode( m_othersCompositionModeIndex );
01122 }
01123 painter.drawImage(0,0, m_storage[ index ] );
01124 }
01125 painter.end();
01126
01127 m_view->view()->makeUpdate( tmp, false );
01128 count = 0;
01129 }
01130 }
01131 mutex.unlock();
01132 }
01133 catch(const std::exception & exception )
01134 {
01135 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
01136 }
01137 }
01138
01139 void AiMainWindow::completed(AiGenerator::AiZone * zone )
01140 {
01141 try
01142 {
01143 QMutex mutex;
01144 mutex.lock();
01145 {
01146 m_storage.replace( zone->getStartPoint(), zone->image() );
01147
01148 static int count = 0;
01149 count++;
01150 if ( count == m_startedThreads && m_storage.size() > 0 )
01151 {
01152 QImage tmp;
01153
01154 if( m_view->view()->emptyScreen() && m_config->getImageWidth() > 0 && m_config->getImageHeight() > 0 )
01155 {
01156 tmp = QImage(m_config->getImageWidth(), m_config->getImageHeight(), QImage::Format_RGB32);
01157 tmp.fill(Qt::transparent);
01158 }
01159 else if( (m_config->getImageWidth() == 0 || m_config->getImageHeight() == 0) && m_storage.count() > 0 )
01160 {
01161 tmp = QImage( m_storage[0].width(), m_storage[0].height(), QImage::Format_RGB32);
01162 tmp.fill(Qt::transparent);
01163 }
01164 else
01165 {
01166 tmp = m_view->view()->image();
01167 }
01168
01169 QPainter painter( &tmp );
01170 for( int index = 0 ; index < m_storage.size() ; index++ )
01171 {
01172 if( index == 0 )
01173 {
01174
01175 painter.setCompositionMode( m_firstCompositionModeIndex );
01176 }
01177 else
01178 {
01179 painter.setCompositionMode( m_othersCompositionModeIndex );
01180 }
01181 painter.drawImage(0,0, m_storage[ index ] );
01182 }
01183 painter.end();
01184
01185 m_view->view()->makeUpdate( tmp, true );
01186 m_storage.clear();
01187
01188
01189 this->enabledChilds( true );
01190 m_statusbar->stopGenerating();
01191
01192
01193 count = 0;
01194
01195
01196 for( int index = 0 ; index < m_threads.size() ; index++ )
01197 {
01198 m_threads[ index ]->stop();
01199 m_threads[ index ]->wait();
01200 }
01201
01202
01203
01204 if( !m_serialize )
01205 {
01206
01207 for( int index = 0 ; index < m_threads.size() ; index++ )
01208 {
01209 delete m_threads[ index ];
01210 }
01211 m_threads.clear();
01212 }
01213
01214
01215 m_serialize = false;
01216
01217
01218
01219 this->m_statusbar->end();
01220 }
01221 }
01222 mutex.unlock();
01223
01224 }
01225 catch(const std::exception & exception )
01226 {
01227 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
01228 }
01229 }
01230
01231 void AiMainWindow::zoneZooming ( int startx, int starty, int endx, int endy )
01232 {
01233
01234 if( m_threads.size() > 0 )
01235 {
01236 if( m_threads[ 0 ]->isRunning() )
01237 {
01238 QMessageBox::warning(this, tr("Threads"), tr("Current threads is running, please stop them before running a new threads!"), QMessageBox::Ok) ;
01239 return;
01240 }
01241 }
01242
01243 if( QMessageBox::Yes != QMessageBox::warning(this, tr("Zooming...") , tr("Are you sure to zooming this area?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No ) )
01244 {
01245 return;
01246 }
01247
01248 int w = m_config->getImageWidth();
01249 int h = m_config->getImageHeight();
01250
01251 int minwh = w < h ? w : h;
01252
01253 m_viewX = m_viewX + ( m_zoom * ( startx < endx ? startx : endx ) / minwh );
01254 m_viewY = m_viewY + ( m_zoom * ( starty < endy ? starty : endy ) / minwh );
01255 double tmpX = static_cast<double>(abs( startx - endx )) / w ;
01256 double tmpY = static_cast<double>(abs( starty - endy )) / h ;
01257
01258 m_zoom = m_zoom * ( tmpX > tmpY ? tmpX : tmpY ) ;
01259
01260 this->runGenerator();
01261 }
01262
01263 void AiMainWindow::enabledChilds(bool e)
01264 {
01265 m_menuBar->enabledChilds( e );
01266 m_toolbar->enabledChilds( e );
01267 m_config->enabledChilds ( e );
01268 }
01269
01270 void AiMainWindow::undo()
01271 {
01272 if ( m_undoDialog->isHidden() )
01273 {
01274 m_undoDialog->show();
01275 }
01276 else
01277 {
01278 m_undoDialog->hide();
01279 }
01280 }
01281
01282
01283 QPainter::CompositionMode AiMainWindow::forgeCompositionMode( int index )
01284 {
01285 switch( index )
01286 {
01287 case 0 : return QPainter::CompositionMode_Clear;
01288 case 1 : return QPainter::CompositionMode_ColorBurn;
01289 case 2 : return QPainter::CompositionMode_ColorDodge;
01290 case 3 : return QPainter::CompositionMode_Darken;
01291 case 4 : return QPainter::CompositionMode_Destination;
01292 case 5 : return QPainter::CompositionMode_DestinationAtop;
01293 case 6 : return QPainter::CompositionMode_DestinationIn;
01294 case 7 : return QPainter::CompositionMode_DestinationOut;
01295 case 8 : return QPainter::CompositionMode_DestinationOver;
01296 case 9 : return QPainter::CompositionMode_Difference;
01297 case 10 : return QPainter::CompositionMode_Exclusion;
01298 case 11 : return QPainter::CompositionMode_HardLight;
01299 case 12 : return QPainter::CompositionMode_Lighten;
01300 case 13 : return QPainter::CompositionMode_Multiply;
01301 case 14 : return QPainter::CompositionMode_Overlay;
01302 case 15 : return QPainter::CompositionMode_Plus;
01303 case 16 : return QPainter::CompositionMode_Screen;
01304 case 17 : return QPainter::CompositionMode_SoftLight;
01305 case 18 : return QPainter::CompositionMode_Source;
01306 case 19 : return QPainter::CompositionMode_SourceAtop;
01307 case 20 : return QPainter::CompositionMode_SourceIn;
01308 case 21 : return QPainter::CompositionMode_SourceOut;
01309 case 22 : return QPainter::CompositionMode_SourceOver;
01310 case 23 : return QPainter::CompositionMode_Xor;
01311 default : return QPainter::CompositionMode_Plus;
01312
01313 }
01314 }
01315
01316 AiMainWindow::~AiMainWindow()
01317 {
01318 try
01319 {
01320
01321 for( int index = 0 ; index < m_threads.size() ; index++ )
01322 {
01323 m_threads[ index ]->stop();
01324 m_threads[ index ]->wait();
01325 delete m_threads[ index ];
01326 }
01327
01328 }
01329 catch(const std::exception & exception )
01330 {
01331 QMessageBox::critical(this, tr("Critical Error!"), tr("Please report this problem to adrabi[at]gmail[dot]com =)."));
01332 }
01333
01334 if( m_config != NULL )
01335 {
01336 delete m_config;
01337 }
01338 if( m_menuBar != NULL )
01339 {
01340 delete m_menuBar;
01341 }
01342 if( m_statusbar != NULL )
01343 {
01344 delete m_statusbar;
01345 }
01346 if( m_toolbar != NULL )
01347 {
01348 delete m_toolbar;
01349 }
01350 if( m_view != NULL )
01351 {
01352 delete m_view;
01353 }
01354 if( m_undoDialog != NULL )
01355 {
01356 delete m_undoDialog;
01357 }
01358 }