00001
00014 #ifdef HAVE_CONFIG_H
00015
00016 #include "config.h"
00017 #endif
00018
00019 #include "CanvasWindow.h"
00020
00021 #include "CanvasView.h"
00022 #include "Inspector.h"
00023 #include "QtFileDialog.h"
00024 #include "PlotTable.h"
00025 #include "PlotTableEvent.h"
00026 #include "PlotterEvent.h"
00027 #include "QtGroupView.h"
00028 #include "SaveAsImageEvent.h"
00029 #include "WindowController.h"
00030
00031 #include "datasrcs/NTupleController.h"
00032 #include "datasrcs/DataSourceController.h"
00033 #include "plotters/PlotterBase.h"
00034 #include "qtxml/QtXMLController.h"
00035
00036 #include <qapplication.h>
00037 #if QT_VERSION < 0x040000
00038 #include <qaction.h>
00039 #else
00040
00041 #include <QtGui/QCloseEvent>
00042 #include <QtCore/QCustomEvent>
00043 #include <QtGui/QHideEvent>
00044 #include <QtGui/QResizeEvent>
00045 #include <QtGui/QShowEvent>
00046 #include <q3action.h>
00047 #endif
00048
00049 #include <qmessagebox.h>
00050 #include <qfontdialog.h>
00051
00052 #include <algorithm>
00053
00054 #include <cassert>
00055
00056 using std::exception;
00057 using std::list;
00058 using std::string;
00059 using std::vector;
00060
00061 using namespace hippodraw;
00062
00063 PlotTable * CanvasWindow::s_plot_table = 0;
00064
00070 #if QT_VERSION < 0x040000
00071 CanvasWindow::CanvasWindow ( QWidget * parent,
00072 const char * name,
00073 Qt::WFlags fl )
00074 : CanvasWindowBase ( parent, name, fl ),
00075 #else
00076 CanvasWindow::CanvasWindow ( QWidget * parent )
00077 : CanvasWindowBase ( parent ),
00078 #endif
00079 m_file_dialog ( 0 ),
00080 m_prefix ( "HippoDraw - Canvas " ),
00081 m_filename ( "UNTITLED" ),
00082 m_changed (" - Not Saved " ),
00083 m_hasChanged ( false ),
00084 m_inhibit_close ( false ),
00085 m_allow_close ( false ),
00086 m_filenameExists ( false )
00087 {
00088
00089 #if QT_VERSION < 0x040000
00090 QCanvas * canvas = new QCanvas ();
00091 #else
00092 Q3Canvas * canvas = new Q3Canvas ();
00093 #endif
00094
00095 m_xml_controller = QtXMLController::instance ();
00096 m_canvas_view = new CanvasView ( canvas, this );
00097
00098 setCentralWidget ( m_canvas_view );
00099
00100 resize ( sizeHint () ) ;
00101
00102 setCaption ();
00103 m_file_dialog = new QtFileDialog ();
00104
00105 m_canvas_view -> initFitterSettings ( m_set_fitter );
00106 m_canvas_view -> initRecentFiles ( m_recent_files );
00107 m_canvas_view -> initDockWindows ( this );
00108
00109
00110 #if QT_VERSION < 0x040000
00111 #else
00112
00113 QMenu * fitter_menu = PopupMenu -> addMenu ( "Fitter" );
00114 QList < QAction * > actions = m_set_fitter -> actions ();
00115 QList < QAction * >::iterator first = actions.begin();
00116 while ( first != actions.end() ) {
00117 QAction * action = *first++;
00118 fitter_menu -> addAction ( action );
00119 }
00120 #endif
00121
00122 WindowController * controller = WindowController::instance ();
00123 controller->newWindow ( this );
00124 }
00125
00126
00129 CanvasWindow::CanvasWindow ( const CanvasWindow & )
00130 : CanvasWindowBase ( )
00131 {
00132 assert ( false );
00133 }
00134
00135 CanvasWindow::~CanvasWindow()
00136 {
00137 #if QT_VERSION < 0x040000
00138 QCanvas * canvas = m_canvas_view->canvas();
00139 #else
00140 Q3Canvas * canvas = m_canvas_view->canvas();
00141 #endif
00142
00143 delete canvas;
00144 }
00145
00146 void
00147 CanvasWindow::
00148 resetFontSize ()
00149 {
00150 QFont font = QApplication::font ();
00151 int size = font.pointSize ();
00152 if ( size > 10 ) {
00153 font.setPointSize ( 10 );
00154 QApplication::setFont ( font, true );
00155 }
00156 }
00157
00158 void
00159 CanvasWindow::
00160 customEvent ( QCustomEvent * event )
00161 {
00162 SaveAsImageEvent * image_event
00163 = dynamic_cast < SaveAsImageEvent * > ( event );
00164
00165 if ( image_event != 0 ) {
00166 const PlotterBase * plotter = image_event -> plotter ();
00167 const string & filename = image_event -> filename ();
00168 m_canvas_view -> savePlotAsImage ( plotter, filename );
00169 return;
00170 }
00171
00172 PlotterEvent * pe = dynamic_cast < PlotterEvent * > ( event );
00173 if ( pe != 0 ) {
00174 PlotterBase * plotter = pe -> plotter ();
00175 if ( plotter == 0 ) {
00176 setChanged ( true );
00177 setCaption ();
00178 }
00179 else {
00180 addDisplay ( plotter );
00181 }
00182 }
00183
00184 PlotTableEvent * ptevent = dynamic_cast < PlotTableEvent * > ( event );
00185 if ( ptevent != 0 ) {
00186 int type = ptevent -> type();
00187
00188 if ( type == PlotTableEvent::Copy ) {
00189 m_canvas_view -> addFromPasteboard ();
00190 return;
00191 }
00192
00193 if ( type == PlotTableEvent::Close ) {
00194 if ( m_browsed_canvas != 0 ) {
00195 delete m_browsed_canvas;
00196 }
00197 s_plot_table -> setBrowserMode ( false );
00198 return;
00199 }
00200 }
00201 }
00202
00203 void CanvasWindow::windowActivationChange ( bool oldActive )
00204 {
00205 QWidget::windowActivationChange ( oldActive );
00206
00207 if ( isActiveWindow () == true ) {
00208 WindowController * wc = WindowController::instance ();
00209 if ( wc -> currentCanvas ( ) != this ) {
00210 wc -> setCurrentCanvas ( this );
00211 updateActions ();
00212 m_canvas_view -> notifyObservers ();
00213 }
00214 }
00215 }
00216
00217 void
00218 CanvasWindow::
00219 setAllowClose ( bool yes )
00220 {
00221 m_allow_close = yes;
00222 }
00223
00227 bool CanvasWindow::allowClose ( )
00228 {
00229 if ( m_allow_close ||
00230 m_hasChanged == false ) return true;
00231
00232 bool _allowClose = true;
00233 const string & app_name = m_canvas_view -> applicationName ();
00234
00235 QString message ( "The document,\n" );
00236 message += m_filename.c_str();
00237 message += "\ncontains unsaved changes.\n\n"
00238 "Do you want to save the document before closing it?";
00239
00240 int retval
00241 = QMessageBox::information ( this,
00242 app_name.c_str(),
00243 message,
00244 "&Save", "&Discard", "Cancel");
00245
00246 switch (retval)
00247 {
00248 case 0:
00249 fileSave ();
00250 _allowClose = true;
00251 break;
00252
00253 case 1:
00254 _allowClose = true;
00255 break;
00256
00257 case 2:
00258 _allowClose = false;
00259 break;
00260
00261 default:
00262 _allowClose = false;
00263 break;
00264 }
00265
00266 return _allowClose;
00267 }
00268
00269 bool
00270 CanvasWindow::closeNoPrompt ( )
00271 {
00272 m_allow_close = true;
00273
00274 return QWidget::close ( true );
00275 }
00276
00277 void CanvasWindow::closeEvent ( QCloseEvent * e )
00278 {
00279 if ( m_allow_close ) {
00280 e -> accept ();
00281 WindowController::instance() -> aboutToClose ( this );
00282 return;
00283 }
00284
00285 if ( allowClose () == false ) {
00286 e->ignore ();
00287 return;
00288 }
00289
00290 if ( m_inhibit_close == true ) {
00291 const string & app_name = m_canvas_view -> applicationName ();
00292
00293 QString message ( "Closing the only document window will also\n"
00294 "terminate the application.\n\n"
00295 "Do you want to quit?" );
00296 int retval = QMessageBox::information ( this,
00297 app_name.c_str(),
00298 message,
00299 QMessageBox::Yes,
00300 QMessageBox::No |
00301 QMessageBox::Default |
00302 QMessageBox::Escape,
00303 Qt::NoButton );
00304
00305 switch (retval)
00306 {
00307 case QMessageBox::Yes:
00308 break;
00309
00310 case QMessageBox::No:
00311 e->ignore();
00312 return;
00313 break;
00314
00315 default:
00316 e->ignore();
00317 return;
00318 break;
00319 }
00320 }
00321
00322 e->accept ();
00323 WindowController::instance() -> aboutToClose ( this );
00324 }
00325
00326 void CanvasWindow::hideEvent ( QHideEvent * )
00327 {
00328 WindowController::instance () -> hasBeenHidden ();
00329 }
00330
00331 void CanvasWindow::showEvent ( QShowEvent * )
00332 {
00333 WindowController::instance () -> unHide ( this );
00334 }
00335
00336 void CanvasWindow::inhibitClose ( bool flag )
00337 {
00338 m_inhibit_close = flag;
00339 }
00340
00341 void CanvasWindow::setChanged ( bool flag )
00342 {
00343 WindowController * controller = WindowController::instance ();
00344 controller -> updateActions ();
00345 if ( m_hasChanged == flag ) return;
00346
00347 if ( flag == true ) {
00348 m_changed = " not saved";
00349 }
00350 else {
00351 m_changed = " saved";
00352 }
00353 m_hasChanged = flag;
00354 setCaption ();
00355 }
00356
00357 void CanvasWindow::updateActions ()
00358 {
00359 XmlController * controller = QtXMLController::instance ();
00360 bool no = controller -> isPasteboardEmpty ();
00361 m_editPasteAction -> setEnabled ( ! no );
00362
00363 const std::vector < const ViewBase * > & views
00364 = m_canvas_view->selectedViews ();
00365 bool yes = ! views.empty ();
00366
00367 m_fileSaveSelected->setEnabled ( yes );
00368 m_editCutAction->setEnabled ( yes );
00369 m_editCopyAction->setEnabled ( yes );
00370 m_editDeleteAction -> setEnabled ( yes );
00371 m_editUndoAction->setEnabled ( yes );
00372 m_viewLockAction->setEnabled ( yes );
00373 m_viewUnlockAction->setEnabled ( yes );
00374 m_group->setEnabled(yes);
00375
00376
00377 m_ungroup->setEnabled(false);
00378 if ( yes == false ) return;
00379
00380
00381
00382 if (views.size() == 1) {
00383 m_group->setEnabled(false);
00384 const QtGroupView * gv = dynamic_cast <const QtGroupView *> (*views.begin());
00385 if (gv) {
00386 m_ungroup->setEnabled(true);
00387 }
00388 }
00389
00390
00391 bool one_locked = false;
00392 bool one_unlocked = false;
00393 std::vector < const ViewBase * >:: const_iterator first = views.begin ();
00394 while ( first != views.end () ) {
00395 const QtView * view = dynamic_cast < const QtView * > ( *first++ );
00396
00397 if (!view) {
00398 m_group->setEnabled(false);
00399 return;
00400 }
00401
00402 bool locked = view->isActive ();
00403 one_locked |= locked;
00404 one_unlocked |= ! locked;
00405 }
00406 m_viewLockAction->setEnabled ( one_unlocked );
00407 m_viewUnlockAction->setEnabled ( one_locked );
00408 }
00409
00413 void
00414 CanvasWindow::
00415 filePrint()
00416 {
00417 m_canvas_view->print ();
00418 }
00419
00420 void CanvasWindow::editCopy ()
00421 {
00422 m_canvas_view->copySelectedToPasteboard ();
00423
00424 WindowController * controller = WindowController::instance ();
00425 controller -> updateActions();
00426 }
00427
00428 void
00429 CanvasWindow::
00430 editClear ()
00431 {
00432 QString message ( "The clear operation can not be undone.\n\n" );
00433 message.append ( "Are you sure you want to remove all canvas items?" );
00434 int retval
00435 = QMessageBox::warning ( this,
00436 "Warning",
00437 message,
00438 QMessageBox::Yes,
00439 QMessageBox::No );
00440 if ( retval != QMessageBox::Yes ) return;
00441
00442 clear ();
00443
00444 WindowController * controller = WindowController::instance ();
00445 controller -> updateActions();
00446 }
00447
00448 void CanvasWindow::editCut ()
00449 {
00450 m_canvas_view->deleteSelected ( true );
00451
00452 WindowController * controller = WindowController::instance ();
00453 controller -> updateActions();
00454 }
00455
00456 void CanvasWindow::editDelete ()
00457 {
00458 m_canvas_view->deleteSelected ( false );
00459
00460 WindowController * controller = WindowController::instance ();
00461 controller -> updateActions();
00462 }
00463
00464 void
00465 CanvasWindow::
00466 editReTile ()
00467 {
00468 m_canvas_view->reTile ();
00469 }
00470
00471 void
00472 CanvasWindow::
00473 editReTilePage ()
00474 {
00475 m_canvas_view->reTilePage ();
00476 }
00477
00478 void
00479 CanvasWindow::
00480 editUndo ()
00481 {
00482 m_canvas_view->restoreFromSelectCopy ();
00483
00484 m_canvas_view->notifyObservers();
00485 }
00486
00487 void CanvasWindow::editPaste ()
00488 {
00489 m_canvas_view->copyFromPasteboard ();
00490 WindowController * controller = WindowController::instance ();
00491 controller -> updateActions();
00492 }
00493
00494 void
00495 CanvasWindow::
00496 editSelectAll ()
00497 {
00498 m_canvas_view->setAllSelected ( true );
00499
00500 WindowController * controller = WindowController::instance ();
00501 controller -> updateActions();
00502 }
00503
00504 void
00505 CanvasWindow::
00506 fileNew ()
00507 {
00508 WindowController * controller = WindowController::instance ();
00509
00510
00511 controller->createInspector();
00512
00513 CanvasWindow * window = new CanvasWindow ();
00514
00515 window->setCaption ();
00516 window->show ();
00517 }
00518
00519 void
00520 CanvasWindow::
00521 fileBrowse ()
00522 {
00523 const string & filter = QtFileDialog::createBrowseFilter ();
00524
00525 QString filename
00526 #if QT_VERSION < 0x040000
00527 = QFileDialog::getOpenFileName ( QString::null,
00528 #else
00529 = Q3FileDialog::getOpenFileName ( QString::null,
00530 #endif
00531 filter.c_str(),
00532 this,
00533 "Browse",
00534 "Choose document file to browse" );
00535 if ( filename != QString::null ) {
00536 QString s = filename.stripWhiteSpace ();
00537 const string fn = s.latin1();
00538
00539 string::size_type pos = fn.find_last_of ( '.' );
00540 const string suffix = fn.substr ( pos );
00541
00542 if ( QtFileDialog::isDocSuffix ( suffix ) ) {
00543 #if QT_VERSION < 0x040000
00544 QCanvas * canvas = new QCanvas ();
00545 #else
00546 Q3Canvas * canvas = new Q3Canvas ();
00547 #endif
00548 CanvasView * m_browsed_canvas = new CanvasView ( canvas, this );
00549 m_browsed_canvas -> initFromFile ( fn );
00550 if ( s_plot_table == 0 ) {
00551 s_plot_table = new PlotTable ();
00552 }
00553 s_plot_table -> setBrowserMode ( true, this );
00554 s_plot_table -> setCanvas ( m_browsed_canvas );
00555 s_plot_table -> show ();
00556 }
00557 }
00558 }
00559
00560 void
00561 CanvasWindow::
00562 fileOpen ()
00563 {
00564 const string & filter = QtFileDialog::createOpenFilter ();
00565
00566 QString filename
00567 #if QT_VERSION < 0x040000
00568 = QFileDialog::getOpenFileName ( QString::null,
00569 #else
00570 = Q3FileDialog::getOpenFileName ( QString::null,
00571 #endif
00572 filter.c_str(),
00573 this,
00574 "Open",
00575 "Choose file to open" );
00576 if ( filename != QString::null ) {
00577 QString s = filename.stripWhiteSpace ();
00578 const string fn = s.latin1();
00579
00580 string suffix;
00581 string::size_type pos = fn.find_last_of ( '.' );
00582 if ( pos != string::npos ) {
00583 suffix = fn.substr ( pos );
00584 }
00585
00586 if ( QtFileDialog::isDocSuffix ( suffix ) ) {
00587
00588 WindowController * controller = WindowController::instance ();
00589
00590
00591 controller->createInspector();
00592
00593 CanvasWindow * window = new CanvasWindow ();
00594 try {
00595 window -> initFromFile ( fn );
00596 }
00597 catch ( exception & e ) {
00598 QString message ("Attempt to read file\n" );
00599 message +="`";
00600 message += filename;
00601 message += "' led to error:\n";
00602 message += e.what();
00603 QMessageBox::critical ( this,
00604 "File error",
00605 message,
00606 QMessageBox::Ok,
00607 0 );
00608 window -> setChanged ( false );
00609 window -> close ();
00610 }
00611 return;
00612 }
00613
00614 else if ( QtFileDialog::isTextSuffix ( suffix ) ) {
00615 m_file_dialog -> openTextTuple ( fn );
00616 m_canvas_view -> notifyObservers ();
00617 m_canvas_view -> addRecentFile (s, m_recent_files);
00618 return;
00619 }
00620 #ifdef HAVE_ROOT
00621 else if ( QtFileDialog::isRootSuffix ( suffix ) ) {
00622 m_file_dialog -> openRootTuple ( fn, this );
00623 m_canvas_view -> notifyObservers ();
00624 m_canvas_view -> addRecentFile (s, m_recent_files);
00625 return;
00626 }
00627 #endif
00628
00629 #ifdef HAVE_CFITSIO
00630 else if ( QtFileDialog::isFitsSuffix ( suffix ) ) {
00631 m_file_dialog -> openFitsTuple ( fn, this );
00632 m_canvas_view -> notifyObservers ();
00633 m_canvas_view -> addRecentFile (s, m_recent_files);
00634 return;
00635 }
00636 else {
00637 bool yes = QtFileDialog::isFitsFile ( fn );
00638 if ( yes ) {
00639 m_file_dialog -> openFitsTuple ( fn, this );
00640 m_canvas_view -> notifyObservers ();
00641 m_canvas_view -> addRecentFile (s, m_recent_files);
00642 return;
00643 }
00644 }
00645 #endif
00646
00647 m_file_dialog -> openTextTuple ( fn );
00648
00649 m_canvas_view -> notifyObservers ();
00650 m_canvas_view -> addRecentFile ( s, m_recent_files );
00651 }
00652 }
00653
00657 void
00658 CanvasWindow::
00659 initFromFile ( const std::string & filename )
00660 {
00661 m_canvas_view -> initFromFile ( filename );
00662 setTitleFileName ( filename );
00663 setChanged ( false );
00664
00665 show();
00666 }
00667
00668 void
00669 CanvasWindow::
00670 clear()
00671 {
00672 m_canvas_view->clear();
00673 }
00674
00675 void CanvasWindow::resizeEvent ( QResizeEvent * e )
00676 {
00677 m_canvas_view->resizeEvent ( e );
00678
00679 QWidget::resizeEvent ( e );
00680 }
00681
00682 void CanvasWindow::viewAddPage()
00683 {
00684 m_canvas_view->addPage ();
00685 }
00686
00687 bool CanvasWindow::areDataSourcesSaved ()
00688 {
00689 const vector < const ViewBase * > & views = m_canvas_view->views ();
00690 bool yes = m_xml_controller->areDataSourcesSaved ( views );
00691
00692 if ( yes == false ) {
00693 const string & app_name = m_canvas_view -> applicationName ();
00694
00695 QString menutext = m_exportTextTuple->menuText();
00696 QString message ("Document can not be saved.\n\n"
00697 "It uses data sources that were neither\n"
00698 "read from nor saved to a file.\n\n"
00699 "Use File menu: \"" );
00700 message += menutext;
00701 message += "\"\n"
00702 "to save the data sources first, or\n"
00703 "use the File menu: \"";
00704
00705 menutext = m_fileSaveAllAction->menuText();
00706 message += menutext;
00707 message += "\".";
00708
00709 QMessageBox::critical ( this,
00710 app_name.c_str(),
00711 message,
00712 QMessageBox::Ok,
00713 Qt::NoButton );
00714 }
00715
00716 return yes;
00717 }
00718
00719 void CanvasWindow::fileSave()
00720 {
00721 bool yes = areDataSourcesSaved ();
00722 if ( ! yes ) return;
00723
00724 if ( m_filenameExists )
00725 {
00726 if ( m_hasChanged )
00727 {
00728 QString message ( "Document file exists\n\n" );
00729 message.append ( "Over-write existing file?" );
00730 int retval
00731 = QMessageBox::warning ( this,
00732 "Warning",
00733 message,
00734 QMessageBox::Yes,
00735 QMessageBox::No );
00736 if ( retval != QMessageBox::Yes ) return;
00737 saveAs ( m_filename );
00738 }
00739 }
00740 else
00741 {
00742 fileSaveAs ();
00743 }
00744 }
00745
00746 std::string
00747 CanvasWindow::
00748 getSaveDocFilename ()
00749 {
00750 const string & filter = QtFileDialog:: createDocumentFilter ();
00751
00752 QString filename;
00753 while ( true ) {
00754 filename
00755 #if QT_VERSION < 0x040000
00756 = QFileDialog::getSaveFileName ( QString::null,
00757 #else
00758 = Q3FileDialog::getSaveFileName ( QString::null,
00759 #endif
00760 filter.c_str(),
00761 this,
00762 "save doc",
00763 "Save canvas to ..." );
00764
00765 if ( filename == QString::null ) return string();
00766
00767 const string & suffix = QtFileDialog:: getDocSuffix ();
00768 if ( filename.endsWith ( suffix.c_str() ) == false ) {
00769 filename += suffix.c_str();
00770 }
00771
00772 QFileInfo info ( filename );
00773 filename = info.absFilePath();
00774
00775 bool yes = info.exists ();
00776 if ( yes == false ) break;
00777
00778 string message ( "File exists. \n\n" );
00779 message += "Over write existing file?";
00780 int result = QMessageBox::warning ( this,
00781 "Warning",
00782 message.c_str (),
00783 QMessageBox::Yes,
00784 QMessageBox::No );
00785 if ( result == QMessageBox::Yes ) break;
00786 }
00787 string name = filename.latin1();
00788
00789 return name;
00790 }
00791 bool
00792 CanvasWindow::
00793 setFilenameFromDialog ()
00794 {
00795 m_filename = getSaveDocFilename ();
00796
00797 m_filenameExists = m_filename.empty () ? false : true;
00798
00799 return m_filenameExists;
00800 }
00801
00802 void CanvasWindow::fileSaveAs()
00803 {
00804 bool yes = areDataSourcesSaved ();
00805 if ( ! yes ) return;
00806
00807 bool ok = setFilenameFromDialog ();
00808 if ( ! ok ) return;
00809
00810 saveAs ( m_filename );
00811 }
00812
00813
00814 void
00815 CanvasWindow::
00816 fileSaveAll()
00817 {
00818 if ( m_filenameExists == false ) {
00819 fileSaveAllAs ();
00820 return;
00821 }
00822 saveAllAs ( m_filename );
00823 }
00824
00825 void
00826 CanvasWindow::
00827 fileSaveAllAs()
00828 {
00829 bool ok = setFilenameFromDialog ();
00830 if ( ! ok ) return;
00831 saveAllAs ( m_filename );
00832 }
00833
00836 void
00837 CanvasWindow::
00838 saveAllAs ( const std::string & filename )
00839 {
00840 const string & suffix = QtFileDialog:: getDocSuffix ();
00841 string::size_type pos = filename.find ( suffix );
00842 string prefix = filename.substr ( 0, pos );
00843 NTupleController * controller = NTupleController::instance ();
00844
00845 const string & data_suffix = QtFileDialog::getTextSuffix ();
00846 controller -> saveNTuples ( prefix, data_suffix );
00847 saveAs ( filename );
00848 }
00849
00850 void CanvasWindow::fileSaveSelectedImages ()
00851 {
00852 m_canvas_view->saveSelectedImages ();
00853 }
00854
00855 void CanvasWindow::fileSaveSelectedImages ( const std::string & filename )
00856 {
00857 m_canvas_view->saveSelectedImages(filename);
00858 }
00859
00860 void
00861 CanvasWindow::
00862 saveAs ( const std::string & filename )
00863 {
00864 m_canvas_view -> saveAs ( filename );
00865
00866 setTitleFileName ( filename );
00867 setChanged ( false );
00868 setCaption ();
00869 }
00870
00871 CanvasView *
00872 CanvasWindow::
00873 getCanvasView ()
00874 {
00875 return m_canvas_view;
00876 }
00877
00878 void
00879 CanvasWindow::
00880 fileExportTextTuple ()
00881 {
00882
00883 Inspector * inspector = m_canvas_view -> getInspector ();
00884 const string tuple_name = inspector -> getSelectedDataSourceName ();
00885
00886 string fn = QtFileDialog:: getExportTupleFilename ( this );
00887 if (fn.empty()==true) return;
00888
00889
00890 string::size_type pos = fn.find_last_of ( '.' );
00891 const string suffix = fn.substr ( pos );
00892
00893 if ( QtFileDialog:: isTextSuffix ( suffix ) ) {
00894 m_file_dialog -> saveTextTuple ( fn, this );
00895 m_canvas_view -> notifyObservers ();
00896 return;
00897 }
00898
00899 else if ( QtFileDialog::isFitsSuffix ( suffix ) ||
00900 QtFileDialog::isZippedFitsSuffix (suffix) ) {
00901 #ifdef HAVE_CFITSIO
00902 m_file_dialog -> saveFitsTuple ( fn, this );
00903 m_canvas_view -> notifyObservers ();
00904 #else
00905 m_canvas_view -> showFitsError ();
00906 #endif
00907 return;
00908 }
00909
00910 else {
00911 bool yes = QtFileDialog:: isFitsFile ( fn );
00912 if ( yes ) {
00913 #ifdef HAVE_CFITSIO
00914 m_file_dialog -> saveFitsTuple ( fn, this );
00915 m_canvas_view -> notifyObservers ();
00916 #else
00917 m_canvas_view -> showFitsError ();
00918 #endif
00919 return;
00920 }
00921 }
00922
00923
00924
00925 QString message = QString("The file type: %1\n").arg ( suffix.c_str() );
00926 message.append("is not supported.\n\n");
00927 message.append("Please use Text ntuple (.tnt)\n");
00928 message.append("or FITS file (.fits).");
00929
00930 QMessageBox::critical ( this,
00931 QString ("Unsupported file type"),
00932 message,
00933 QMessageBox::Ok,
00934 Qt::NoButton );
00935 }
00936
00937 void
00938 CanvasWindow::
00939 fileCreateNTuple ()
00940 {
00941 m_canvas_view -> createNTuple();
00942 }
00943
00944 void
00945 CanvasWindow::
00946 fileExit ()
00947 {
00948 bool ok = WindowController::instance () -> okToQuit();
00949
00950 if ( ok ) {
00951
00952 autosaveSettings();
00953 qApp->quit ();
00954 }
00955 }
00956
00957 void CanvasWindow::viewZoomIn()
00958 {
00959 m_canvas_view->viewZoomIn ();
00960 }
00961
00962 void CanvasWindow::viewZoomOut()
00963 {
00964 m_canvas_view->viewZoomOut ();
00965 }
00966
00967 void
00968 CanvasWindow::
00969 viewZoomReset()
00970 {
00971 m_canvas_view -> viewZoomReset ();
00972 }
00973
00974 void
00975 CanvasWindow::
00976 viewLock ()
00977 {
00978 m_canvas_view->setLocked ( true );
00979 updateActions ();
00980 }
00981
00982 void
00983 CanvasWindow::
00984 viewUnlock ()
00985 {
00986 m_canvas_view->setLocked ( false );
00987 updateActions ();
00988 }
00989
00993 void CanvasWindow::helpAbout()
00994 {
00995 m_canvas_view -> helpAbout ();
00996 }
00997
00998 void
00999 CanvasWindow::
01000 helpHelp ()
01001 {
01002 #ifndef HAVE_HELP
01003 const string & app_name = m_canvas_view -> applicationName ();
01004 QString message ( "The application was built without\n"
01005 "built-in help support" );
01006 QMessageBox::information ( this,
01007 app_name.c_str(),
01008 message,
01009 QMessageBox::Ok );
01010 return;
01011 #endif
01012
01013 WindowController * controller = WindowController::instance ();
01014 controller -> openAssistant ();
01015 }
01016
01017 void
01018 CanvasWindow::
01019 aboutQt ()
01020 {
01021 QMessageBox::aboutQt ( this );
01022 }
01023
01024 void CanvasWindow::setCaption ()
01025 {
01026 QString fn = m_filename.c_str();
01027 QWidget::setCaption ( m_prefix + fn + m_changed );
01028 }
01029
01030 void
01031 CanvasWindow::
01032 setTitleFileName ( const std::string & name )
01033 {
01034 m_filename = name;
01035 m_filenameExists = true;
01036 }
01037
01038 void
01039 CanvasWindow::
01040 addTextDisplay ( PlotterBase * plotter,
01041 const std::string & s )
01042 {
01043 m_canvas_view->addTextDisplay ( plotter, s );
01044 }
01045
01046 void
01047 CanvasWindow::
01048 addTextDisplay ( PlotterBase * plotter,
01049 const std::string & type,
01050 const std::string & text)
01051 {
01052 m_canvas_view->addTextDisplay ( plotter, type, text );
01053 }
01054
01055 std::pair<double, double>
01056 CanvasWindow::
01057 addTextDisplayAt ( PlotterBase * plotter,
01058 const std::string & type,
01059 const std::string & text,
01060 double xrel, double yrel )
01061 {
01062 return m_canvas_view->addTextDisplayAt( plotter, type, text, xrel, yrel );
01063 }
01064
01065 void
01066 CanvasWindow::
01067 addFuncDisplay ( PlotterBase * plotter, const std::string & s )
01068 {
01069 m_canvas_view->addFuncDisplay ( plotter, s );
01070 }
01071
01072 void CanvasWindow::addPlotDisplay ( PlotterBase * plotter, bool sel )
01073 {
01074 m_canvas_view->addPlotDisplay ( plotter, sel );
01075 }
01076
01077 void CanvasWindow::addDisplay ( PlotterBase * plotter )
01078 {
01079 m_canvas_view->addPlotDisplay ( plotter );
01080 }
01081
01084 void
01085 CanvasWindow::
01086 removeDisplay ( PlotterBase * plotter )
01087 {
01088 m_canvas_view->removeDisplay ( plotter );
01089 }
01090
01093 PlotterBase * CanvasWindow::selectedPlotter ()
01094 {
01095 return m_canvas_view->selectedPlotter ();
01096 }
01097
01098 const vector < const ViewBase * > & CanvasWindow::views ()
01099 {
01100 return m_canvas_view->views ();
01101 }
01102
01103 void
01104 CanvasWindow::
01105 fillPlotterList ( std::vector < PlotterBase * > & plotters )
01106 {
01107 m_canvas_view -> fillPlotterList ( plotters );
01108 }
01109
01110 QtView *
01111 CanvasWindow::
01112 getViewFor ( const PlotterBase * plotter ) const
01113 {
01114 return m_canvas_view->getViewFor ( plotter );
01115 }
01116
01117 void CanvasWindow::setIntervalEnabled ( bool yes )
01118 {
01119 m_canvas_view->setIntervalEnabled ( yes );
01120 }
01121
01122 void
01123 CanvasWindow::
01124 viewShowInspector ()
01125 {
01126 m_canvas_view -> showInspector ();
01127 }
01128
01129 void
01130 CanvasWindow::
01131 viewShowPlotTable ()
01132 {
01133 if ( s_plot_table == 0 ) {
01134 s_plot_table = new PlotTable ();
01135 }
01136 s_plot_table->setCanvas ( m_canvas_view );
01137 s_plot_table->show();
01138 }
01139
01140 void
01141 CanvasWindow::
01142 viewShowPickTable ()
01143 {
01144 m_canvas_view->viewShowPickTable();
01145
01146 m_pick -> toggle ();
01147 }
01148
01149 void
01150 CanvasWindow::
01151 savePlotAsImage ( const PlotterBase * plotter,
01152 const std::string & filename )
01153 {
01154 SaveAsImageEvent * event = new SaveAsImageEvent ( plotter, filename );
01155 QApplication::postEvent ( this, event );
01156 }
01157
01158 void
01159 CanvasWindow::
01160 saveAsImage ( const PlotterBase * plotter,
01161 const std::string & filename )
01162 {
01163 qApp -> lock ();
01164 m_canvas_view -> savePlotAsImage ( plotter, filename );
01165 qApp -> unlock ();
01166 }
01167
01168 void
01169 CanvasWindow::
01170 setAllSelected ( bool flag )
01171 {
01172 m_canvas_view->setAllSelected( flag );
01173 }
01174
01175 void
01176 CanvasWindow::
01177 setSelected ( QtView * view )
01178 {
01179 m_canvas_view->setSelectedItem( view );
01180 }
01181
01182 void
01183 CanvasWindow::
01184 previousView ( )
01185 {
01186 PlotterBase * currentPlotter = selectedPlotter();
01187 if (currentPlotter) {
01188 if ( ! ( currentPlotter->getCurrentRangeSaved () ) ) {
01189 m_canvas_view -> setCurrentRange();
01190 }
01191
01192 selectedPlotter() -> nextView (false );
01193 m_canvas_view -> canvas () -> update();
01194 }
01195 }
01196
01197 void
01198 CanvasWindow::
01199 nextView ( )
01200 {
01201 PlotterBase * currentPlotter = selectedPlotter();
01202 if (currentPlotter) {
01203 if ( !(currentPlotter->getCurrentRangeSaved()) ) {
01204 m_canvas_view->setCurrentRange();
01205 }
01206
01207 selectedPlotter() -> nextView ( true );
01208 m_canvas_view->canvas()->update();
01209 }
01210 }
01211
01212
01213 void
01214 CanvasWindow::
01215 setZoomMode ( bool on )
01216 {
01217 m_canvas_view -> setZoomMode ( on );
01218 }
01219
01220 const std::vector<double> &
01221 CanvasWindow::
01222 mouseEventData()
01223 {
01224 return m_canvas_view->mouseEventData();
01225 }
01226
01227 void
01228 CanvasWindow::
01229 settingPrinter()
01230 {
01231 m_canvas_view -> setPrinterSettings ();
01232 }
01233
01234 void
01235 CanvasWindow::
01236 settingCanvas()
01237 {
01238 m_canvas_view -> setup ();
01239 }
01240
01241 void
01242 CanvasWindow::
01243 settingFonts()
01244 {
01245 bool ok;
01246
01247
01248
01249 QFont font
01250 = QFontDialog::getFont ( &ok, QFont( "Helvetica [Cronyx]", 10), this);
01251
01252 m_canvas_view -> setFonts( font );
01253 }
01254
01255 void
01256 CanvasWindow::
01257 print ( const std::string & filename )
01258 {
01259 m_canvas_view -> print ( filename );
01260 }
01261
01262 void
01263 CanvasWindow::
01264 setPlotMatrix ( unsigned int columns, unsigned int rows )
01265 {
01266 m_canvas_view -> setPlotMatrix ( columns, rows );
01267 m_canvas_view -> reTile ();
01268 }
01269
01270 const QString &
01271 CanvasWindow::
01272 getAppKey ( ) const
01273 {
01274 return m_canvas_view -> getAppKey ();
01275 }
01276
01277 void
01278 CanvasWindow::
01279 setFitter ( QAction * action )
01280 {
01281 QString name = action -> menuText ();
01282 m_canvas_view -> setFitterDefault ( name );
01283 }
01284
01285 void
01286 CanvasWindow::
01287 setAddedSelected ( bool yes )
01288 {
01289 m_canvas_view -> setAddedSelected ( yes );
01290 }
01291
01292 void
01293 CanvasWindow::
01294 setCutMode ( QAction * action )
01295 {
01296 if ( action == m_cut1 )
01297 m_canvas_view -> setCutMode (1);
01298 else if ( action == m_cut2 )
01299 m_canvas_view -> setCutMode (2);
01300 else if ( action == m_cut3 )
01301 m_canvas_view -> setCutMode (3);
01302 else
01303 m_canvas_view -> setCutMode (0);
01304 }
01305
01306 NTuple *
01307 CanvasWindow::
01308 getPickTable () const
01309 {
01310 return m_canvas_view -> getPickTable();
01311 }
01312
01313 NTuple *
01314 CanvasWindow::
01315 getPickTable ( const PlotterBase * plotter ) const
01316 {
01317 return m_canvas_view -> getPickTable ( plotter );
01318 }
01319
01320 void
01321 CanvasWindow::
01322 groupView ()
01323 {
01324 m_canvas_view -> groupView ();
01325 updateActions();
01326 }
01327
01328 void
01329 CanvasWindow::
01330 ungroupView ()
01331 {
01332 m_canvas_view -> ungroupView ();
01333 updateActions();
01334 }
01335
01336 void
01337 CanvasWindow::
01338 openRecentFile(QAction * action )
01339 {
01340 QString filename = action -> menuText ();
01341
01342 const string fn = filename.latin1();
01343 string::size_type pos = fn.find_last_of ( '.' );
01344 const string suffix = fn.substr ( pos );
01345
01346
01347 if ( QtFileDialog::isTextSuffix ( suffix ) ) {
01348 QtFileDialog::openTextTuple ( fn );
01349 action -> setToggleAction ( false );
01350 action -> setToggleAction ( true );
01351 m_canvas_view -> notifyObservers ();
01352 return;
01353 }
01354
01355 if ( QtFileDialog::isFitsSuffix ( suffix ) ) {
01356 m_file_dialog ->openFitsTuple ( fn, this );
01357 action -> setToggleAction ( false );
01358 action -> setToggleAction ( true );
01359 m_canvas_view -> notifyObservers ();
01360 return;
01361 }
01362
01363 if ( QtFileDialog::isRootSuffix ( suffix ) ) {
01364 m_file_dialog ->openRootTuple ( fn, this );
01365 action -> setToggleAction ( false );
01366 action -> setToggleAction ( true );
01367 m_canvas_view -> notifyObservers ();
01368 return;
01369 }
01370
01371 m_file_dialog -> openTextTuple ( fn );
01372
01373
01374 action -> setToggleAction ( false );
01375 action -> setToggleAction ( true );
01376 m_canvas_view -> notifyObservers ();
01377 }
01378
01379 void
01380 CanvasWindow::autosaveSettings()
01381 {
01382 m_canvas_view -> autosaveSettings ( this );
01383 }