00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <qvbox.h>
00018 #include <qaccel.h>
00019 #include <qinputdialog.h>
00020 #include <qstring.h>
00021 #include <qtextview.h>
00022 #include <qdir.h>
00023
00024
00025 #include <iostream>
00026 #include <set>
00027 #include <fstream>
00028
00029
00030 #include "trapperview.h"
00031 #include "trapperdoc.h"
00032 #include "trapper.h"
00033 #include "showmodesdlg.h"
00034 #include "trapperconf.h"
00035 #include "trapperparser.h"
00036
00037 #include "filenew.xpm"
00038 #include "fileopen.xpm"
00039 #include "filesave.xpm"
00040 #include "editselectall.xpm"
00041
00042
00043 #include "zoom_in.xpm"
00044 #include "zoom_out.xpm"
00045 #include "zoom_in_x.xpm"
00046 #include "zoom_out_x.xpm"
00047 #include "zoom_in_y.xpm"
00048 #include "zoom_out_y.xpm"
00049 #include "dbflush.xpm"
00050 #include "dragbutton.xpm"
00051 #include "pointerbutton.xpm"
00052
00053 TrapperApp::TrapperApp()
00054 {
00055 qDebug("in TrapperApp::TrapperApp()");
00056 setCaption(tr("Trapper " "0.9" ) );
00057 dbenv = new DbEnv( DB_CXX_NO_EXCEPTIONS );
00058
00059 dbenv->set_cachesize(0, 1000000, 0);
00060
00061 printer = new QPrinter;
00062 untitledCount=0;
00063 pDocList = new QList<TrapperDoc>();
00064 pDocList->setAutoDelete(true);
00065
00066
00067
00068 initView();
00069 initActions();
00070 initMenuBar();
00071 initToolBar();
00072 initStatusBar();
00073 resize( 450, 400 );
00074
00075 viewToolBar->setOn(true);
00076 viewStatusBar->setOn(true);
00077
00078 projectDir = QString::null;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 connect(pWorkspace, SIGNAL(windowActivated(QWidget*)), this, SLOT(slotActivatedWindow(QWidget*)));
00089
00090
00091 }
00092
00093 TrapperApp::~TrapperApp()
00094 {
00095 delete printer;
00096 dbenv->close(0);
00097 }
00098
00099 void TrapperApp::initActions()
00100 {
00101 QPixmap openIcon, saveIcon, newIcon, selectAllIcon, zoomPlusIcon, zoomMinusIcon,
00102 zoomPlusIconX, zoomPlusIconY, zoomMinusIconX, zoomMinusIconY, flushIcon, dragIcon, pointerIcon;
00103
00104 newIcon = QPixmap(filenew);
00105 openIcon = QPixmap(fileopen);
00106 saveIcon = QPixmap(filesave);
00107 selectAllIcon = QPixmap( editselectall );
00108 zoomPlusIcon = QPixmap( zoom_in );
00109 zoomPlusIconX = QPixmap( zoom_in_x );
00110 zoomPlusIconY = QPixmap( zoom_in_y );
00111 zoomMinusIcon = QPixmap( zoom_out );
00112 zoomMinusIconX = QPixmap( zoom_out_x);
00113 zoomMinusIconY = QPixmap( zoom_out_y);
00114 flushIcon = QPixmap( dbflush );
00115 pointerIcon = QPixmap(pointerbutton);
00116 dragIcon = QPixmap(dragbutton);
00117
00118 fileNew = new QAction(tr("New Project"), newIcon, tr("&New"), QAccel::stringToKey(tr("Ctrl+N")), this);
00119 fileNew->setStatusTip(tr("Creates a new project"));
00120 fileNew->setWhatsThis(tr("New Project\n\nCreates a new project"));
00121 connect(fileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
00122
00123 fileOpen = new QAction(tr("Open Contig"), openIcon, tr("&Open..."), QAccel::stringToKey(tr("Ctrl+O")), this);
00124 fileOpen->setStatusTip(tr("Opens an existing contig or creates a new one"));
00125 fileOpen->setWhatsThis(tr("Open Contig\n\nOpens an existing contig or creates a new one. To create a new contig, simply create a new directory in the file dialog and choose it"));
00126 connect(fileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
00127
00128 fileSave = new QAction(tr("Save File"), saveIcon, tr("&Save"), QAccel::stringToKey(tr("Ctrl+S")), this);
00129 fileSave->setStatusTip(tr("Saves the actual document"));
00130 fileSave->setWhatsThis(tr("Save File.\n\nSaves the actual document"));
00131 connect(fileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
00132
00133 fileSaveAs = new QAction(tr("Save File As"), tr("Save &as..."), 0, this);
00134 fileSaveAs->setStatusTip(tr("Saves the actual document under a new filename"));
00135 fileSaveAs->setWhatsThis(tr("Save As\n\nSaves the actual document under a new filename"));
00136 connect(fileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSave()));
00137
00138 fileClose = new QAction(tr("Close Project"), tr("&Close"), QAccel::stringToKey(tr("Ctrl+W")), this);
00139 fileClose->setStatusTip(tr("Closes the actual project"));
00140 fileClose->setWhatsThis(tr("Close Project\n\nCloses the actual project"));
00141 connect(fileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
00142
00143 filePrint = new QAction(tr("Print File"), tr("&Print"), QAccel::stringToKey(tr("Ctrl+P")), this);
00144 filePrint->setStatusTip(tr("Prints out the actual document"));
00145 filePrint->setWhatsThis(tr("Print File\n\nPrints out the actual document"));
00146 connect(filePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
00147
00148 fileQuit = new QAction(tr("Exit"), tr("E&xit"), QAccel::stringToKey(tr("Ctrl+Q")), this);
00149 fileQuit->setStatusTip(tr("Quits the application"));
00150 fileQuit->setWhatsThis(tr("Exit\n\nQuits the application"));
00151 connect(fileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
00152
00153 fileFlush = new QAction(tr("Flush"), flushIcon, tr("&Flush"), QAccel::stringToKey(tr("Ctrl+F")), this);
00154 fileFlush->setStatusTip(tr("Flushes cached data"));
00155 fileFlush->setWhatsThis(tr("Flush\n\nFlushes cached data to database"));
00156 connect(fileFlush, SIGNAL(activated()), this, SLOT(slotFileFlush()));
00157
00158 editCut = new QAction(tr("Cut"), tr("Cu&t"), QAccel::stringToKey(tr("Ctrl+X")), this);
00159 editCut->setStatusTip(tr("Cuts the selected section and puts it to the clipboard"));
00160 editCut->setWhatsThis(tr("Cut\n\nCuts the selected section and puts it to the clipboard"));
00161 connect(editCut, SIGNAL(activated()), this, SLOT(slotEditCut()));
00162
00163 editCopy = new QAction(tr("Copy"), tr("&Copy"), QAccel::stringToKey(tr("Ctrl+C")), this);
00164 editCopy->setStatusTip(tr("Copies the selected section to the clipboard"));
00165 editCopy->setWhatsThis(tr("Copy\n\nCopies the selected section to the clipboard"));
00166 connect(editCopy, SIGNAL(activated()), this, SLOT(slotEditCopy()));
00167
00168 editUndo = new QAction(tr("Undo last move"), tr("&Undo last move"), QAccel::stringToKey(tr("Ctrl+Z")), this);
00169 editUndo->setStatusTip(tr("Reverts the last move"));
00170 editUndo->setWhatsThis(tr("Undo\n\nReverts the last read moving action"));
00171 connect(editUndo, SIGNAL(activated()), this, SLOT(slotEditUndo()));
00172
00173 editPaste = new QAction(tr("Paste"), tr("&Paste"), QAccel::stringToKey(tr("Ctrl+V")), this);
00174 editPaste->setStatusTip(tr("Pastes the clipboard contents to actual position"));
00175 editPaste->setWhatsThis(tr("Paste\n\nPastes the clipboard contents to actual position"));
00176 connect(editPaste, SIGNAL(activated()), this, SLOT(slotEditPaste()));
00177
00178 editSelectAll = new QAction(tr("Select All"), selectAllIcon, tr("Select &All"), QAccel::stringToKey(tr("Ctrl+A")), this);
00179 editSelectAll->setStatusTip(tr("Selects all reads"));
00180 editSelectAll->setWhatsThis(tr("Select All\n\nSelects all reads"));
00181 connect(editSelectAll, SIGNAL(activated()), this, SLOT(slotEditSelectAll()));
00182
00183 editSelectBetween = new QAction(tr("Select Between rows"), tr("Select &Between rows"), 0, this);
00184 editSelectBetween->setStatusTip(tr("Selects all reads between two rows"));
00185 editSelectBetween->setWhatsThis(tr("Select Between rows\n\nSelects all reads between two rows"));
00186 connect(editSelectBetween, SIGNAL(activated()), this, SLOT(slotEditSelectBetween()));
00187
00188 editFindRead = new QAction(tr("Find Read"), tr("Find Read"), 0, this);
00189 editFindRead->setStatusTip(tr("Selects a specific read"));
00190 editFindRead->setWhatsThis(tr("Find Read\n\nSelects a specific read"));
00191 connect(editFindRead, SIGNAL(activated()), this, SLOT(slotEditFindRead()));
00192
00193 viewToolBar = new QAction(tr("Toolbar"), tr("Tool&bar"), 0, this, 0, true);
00194 viewToolBar->setStatusTip(tr("Enables/disables the toolbar"));
00195 viewToolBar->setWhatsThis(tr("Toolbar\n\nEnables/disables the toolbar"));
00196 connect(viewToolBar, SIGNAL(toggled(bool)), this, SLOT(slotViewToolBar(bool)));
00197
00198 viewStatusBar = new QAction(tr("Statusbar"), tr("&Statusbar"), 0, this, 0, true);
00199 viewStatusBar->setStatusTip(tr("Enables/disables the statusbar"));
00200 viewStatusBar->setWhatsThis(tr("Statusbar\n\nEnables/disables the statusbar"));
00201 connect(viewStatusBar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
00202
00203 windowNewWindow = new QAction(tr("New Wiew"), tr("&New Wiew"), 0, this);
00204 windowNewWindow->setStatusTip(tr("Opens a new view for the current document"));
00205 windowNewWindow->setWhatsThis(tr("New Wiew\n\nOpens a new view for the current document"));
00206 connect(windowNewWindow, SIGNAL(activated()), this, SLOT(slotWindowNewWindow()));
00207
00208 windowCascade = new QAction(tr("Cascade"), tr("&Cascade"), 0, this);
00209 windowCascade->setStatusTip(tr("Cascades all windows"));
00210 windowCascade->setWhatsThis(tr("Cascade\n\nCascades all windows"));
00211 connect(windowCascade, SIGNAL(activated()), pWorkspace, SLOT(cascade()));
00212
00213 windowTile = new QAction(tr("Tile"), tr("&Tile"), 0, this);
00214 windowTile->setStatusTip(tr("Tiles all windows"));
00215 windowTile->setWhatsThis(tr("Tile\n\nTiles all windows"));
00216 connect(windowTile, SIGNAL(activated()), pWorkspace, SLOT(tile()));
00217
00218 windowAction = new QActionGroup(this, 0, false);
00219 windowAction->add(windowNewWindow);
00220 windowAction->add(windowCascade);
00221 windowAction->add(windowTile);
00222
00223 normalModeAction = new QAction(tr("Normal mode"), pointerIcon, tr("Normal mode"), 0, this);
00224 normalModeAction->setStatusTip(tr("Sets mode to normal"));
00225 normalModeAction->setWhatsThis(tr("Normal mode\n\nFor selection of reads, normal moving etc"));
00226 normalModeAction->setToggleAction(true);
00227 normalModeAction->setOn(true);
00228 connect(normalModeAction, SIGNAL(activated()), this, SLOT(slotNormalMode()));
00229
00230 dragModeAction = new QAction(tr("Drag mode"), dragIcon, tr("Drag mode"), 0, this);
00231 dragModeAction->setStatusTip(tr("Sets mode to drag mode"));
00232 dragModeAction->setWhatsThis(tr("Drag mode\n\nFor moving reads between contigs, and sideways moving"));
00233 dragModeAction->setToggleAction(true);
00234 connect(dragModeAction, SIGNAL(activated()), this, SLOT(slotDragMode()));
00235
00236 modeActionGroup = new QActionGroup(this, 0, true);
00237 modeActionGroup->add(normalModeAction);
00238 modeActionGroup->add(dragModeAction);
00239
00240 helpAboutApp = new QAction(tr("About"), tr("&About..."), 0, this);
00241 helpAboutApp->setStatusTip(tr("About the application"));
00242 helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
00243 connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 importNewAction = new QAction(tr("Import project"), tr("&Import project"), 0, this);
00256 importNewAction->setStatusTip(tr("Imports project data"));
00257 importNewAction->setWhatsThis(tr("Imports project data"));
00258 connect(importNewAction, SIGNAL(activated()), this, SLOT(slotNewImport()));
00259
00260 importChromatAction = new QAction(tr("Import Chromatograms"), tr("Import Chromatograms"), 0, this);
00261 importChromatAction->setStatusTip(tr("Imports chromatogram data"));
00262 importChromatAction->setWhatsThis(tr("Imports chromatogram data"));
00263 connect(importChromatAction, SIGNAL(activated()), this, SLOT(slotChromatImport()));
00264
00265 importMateAction = new QAction(tr("Import Mate pairs"), tr("Import Mate Pairs"), 0, this);
00266 importMateAction->setStatusTip(tr("Imports mate pair data"));
00267 importMateAction->setWhatsThis(tr("Imports mate pair data"));
00268 connect(importMateAction, SIGNAL(activated()), this, SLOT(slotMateImport()));
00269
00270 importPhdAction = new QAction(tr("Import phd data"), tr("Import phd data"), 0, this);
00271 importPhdAction->setStatusTip(tr("Imports phd data"));
00272 importPhdAction->setWhatsThis(tr("Imports phd data"));
00273 connect(importPhdAction, SIGNAL(activated()), this, SLOT(slotPhdImport()));
00274
00275 exportAction = new QAction(tr("Export"), tr("&Export"), 0, this);
00276 exportAction->setStatusTip(tr("Exports data"));
00277 exportAction->setWhatsThis(tr("Exports data"));
00278 connect(exportAction, SIGNAL(activated()), this, SLOT(slotExport()));
00279
00280 zoomInAction = new QAction(tr("Zoom in"), zoomPlusIcon, tr("Zoom in"), Key_Plus, this);
00281 zoomInAction->setStatusTip(tr("Zooms in"));
00282 zoomInAction->setWhatsThis(tr("Zooms in"));
00283 connect(zoomInAction, SIGNAL(activated()), this, SLOT(slotZoomIn()));
00284
00285 zoomInXAction = new QAction(tr("Zoom in X"), zoomPlusIconX, tr("Zoom in X"),CTRL + Key_Plus, this);
00286 zoomInXAction->setStatusTip(tr("Zooms in X"));
00287 zoomInXAction->setWhatsThis(tr("Zooms in X direction"));
00288 connect(zoomInXAction, SIGNAL(activated()), this, SLOT(slotZoomInX()));
00289
00290 zoomInYAction = new QAction(tr("Zoom in Y"), zoomPlusIconY, tr("Zoom in Y"), CTRL + ALT + Key_Plus, this);
00291 zoomInYAction->setStatusTip(tr("Zooms in Y"));
00292 zoomInYAction->setWhatsThis(tr("Zooms in Y direction"));
00293 connect(zoomInYAction, SIGNAL(activated()), this, SLOT(slotZoomInY()));
00294
00295 zoomOutAction = new QAction(tr("Zoom out"), zoomMinusIcon, tr("&Zoom out"), Key_Minus, this);
00296 zoomOutAction->setStatusTip(tr("Zooms out"));
00297 zoomOutAction->setWhatsThis(tr("Zooms out"));
00298 connect(zoomOutAction, SIGNAL(activated()), this, SLOT(slotZoomOut()));
00299
00300 zoomOutXAction = new QAction(tr("Zoom out X"), zoomMinusIconX, tr("Zoom out X"), CTRL + Key_Minus, this);
00301 zoomOutXAction->setStatusTip(tr("Zooms out X"));
00302 zoomOutXAction->setWhatsThis(tr("Zooms out in X direction"));
00303 connect(zoomOutXAction, SIGNAL(activated()), this, SLOT(slotZoomOutX()));
00304
00305 zoomOutYAction = new QAction(tr("Zoom out Y"), zoomMinusIconY, tr("Zoom out Y"), CTRL + ALT + Key_Minus, this);
00306 zoomOutYAction->setStatusTip(tr("Zooms out Y"));
00307 zoomOutYAction->setWhatsThis(tr("Zooms out in Y direction"));
00308 connect(zoomOutYAction, SIGNAL(activated()), this, SLOT(slotZoomOutY()));
00309
00310 enlargeAction = new QAction(tr("Enlarge"), tr("&Enlarge"), 0, this);
00311 enlargeAction->setStatusTip(tr("Adds more viewable rows"));
00312 enlargeAction->setWhatsThis(tr("Enlarges view, so that more rows and columns can be displayed"));
00313 connect(enlargeAction, SIGNAL(activated()), this, SLOT(slotEnlarge()));
00314
00315 shrinkAction = new QAction(tr("Shrink"), tr("&Shrink"), 0, this);
00316 shrinkAction->setStatusTip(tr("Removes viewable rows. Does not affect data."));
00317 shrinkAction->setWhatsThis(tr("Shrinks view, displaying fewer rows and columns. Does not affect data."));
00318 connect(shrinkAction, SIGNAL(activated()), this, SLOT(slotShrink()));
00319
00320 showStatisticsAction = new QAction(tr("Show statistics"), tr("Show statistics"), 0, this);
00321 showStatisticsAction->setStatusTip(tr("Show statistics about contig"));
00322 showStatisticsAction->setWhatsThis(tr("Show underlying berkeley db statistics for this contig"));
00323 connect(showStatisticsAction, SIGNAL(activated()), this, SLOT(slotShowStatistics()));
00324
00325 configureViewModesAction = new QAction(tr("Configure view modes"), tr("&Configure modes"), 0, this);
00326 configureViewModesAction->setStatusTip(tr("Configure view modes"));
00327 configureViewModesAction->setWhatsThis(tr("Configure view modes"));
00328 connect(configureViewModesAction, SIGNAL(activated()), this, SLOT(slotConfigureViewModes()));
00329
00330
00331 }
00332
00333 void TrapperApp::initMenuBar()
00334 {
00335
00336
00337
00338
00339
00340 pFileMenu=new QPopupMenu();
00341
00342 fileOpen->addTo(pFileMenu);
00343 fileClose->addTo(pFileMenu);
00344
00345
00346
00347
00348
00349
00350 pFileMenu->insertSeparator();
00351 fileQuit->addTo(pFileMenu);
00352
00353
00354
00355
00356
00357
00358 pEditMenu=new QPopupMenu();
00359 editUndo->addTo(pEditMenu);
00360
00361 editCut->addTo(pEditMenu);
00362 editCopy->addTo(pEditMenu);
00363 editPaste->addTo(pEditMenu);
00364 editSelectAll->addTo(pEditMenu);
00365 editSelectBetween->addTo(pEditMenu);
00366 editFindRead->addTo(pEditMenu);
00367
00368
00369
00370 pViewMenu=new QPopupMenu();
00371 pViewMenu->setCheckable(true);
00372 viewToolBar->addTo(pViewMenu);
00373 viewStatusBar->addTo(pViewMenu);
00374
00375 zoomInAction->addTo(pViewMenu);
00376 zoomOutAction->addTo(pViewMenu);
00377 zoomInXAction->addTo(pViewMenu);
00378 zoomOutXAction->addTo(pViewMenu);
00379 zoomInYAction->addTo(pViewMenu);
00380 zoomOutYAction->addTo(pViewMenu);
00381 enlargeAction->addTo(pViewMenu);
00382 shrinkAction->addTo(pViewMenu);
00383 showStatisticsAction->addTo(pViewMenu);
00384
00385
00386
00387
00388
00389 pToolsMenu=new QPopupMenu();
00390
00391 importNewAction->addTo(pToolsMenu);
00392 importChromatAction->addTo(pToolsMenu);
00393 importMateAction->addTo(pToolsMenu);
00394 importPhdAction->addTo(pToolsMenu);
00395 modeActionGroup->addTo(pToolsMenu);
00396 exportAction->addTo(pToolsMenu);
00397
00398
00399
00400 pWindowMenu = new QPopupMenu(this);
00401 pWindowMenu->setCheckable(true);
00402 connect(pWindowMenu, SIGNAL(aboutToShow()), this, SLOT(windowMenuAboutToShow()));
00403
00404
00405
00406 pHelpMenu=new QPopupMenu();
00407
00408 helpAboutApp->addTo(pHelpMenu);
00409 pHelpMenu->insertSeparator();
00410 pHelpMenu->insertItem(tr("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1);
00411
00412 menuBar()->insertItem(tr("&Contig"), pFileMenu);
00413 menuBar()->insertItem(tr("&Edit"), pEditMenu);
00414 menuBar()->insertItem(tr("&View"), pViewMenu);
00415 menuBar()->insertItem(tr("&Window"), pWindowMenu);
00416 menuBar()->insertItem(tr("&Tools"), pToolsMenu);
00417 menuBar()->insertItem(tr("&Help"), pHelpMenu);
00418
00419 }
00420
00421 void TrapperApp::initToolBar()
00422 {
00423
00424
00425 fileToolbar = new QToolBar(this, "file operations");
00426
00427 fileOpen->addTo(fileToolbar);
00428
00429
00430 editSelectAll->addTo(fileToolbar);
00431 zoomInAction->addTo(fileToolbar);
00432 zoomOutAction->addTo(fileToolbar);
00433 zoomInXAction->addTo(fileToolbar);
00434 zoomOutXAction->addTo(fileToolbar);
00435 zoomInYAction->addTo(fileToolbar);
00436 zoomOutYAction->addTo(fileToolbar);
00437
00438 fileToolbar->addSeparator();
00439 modeActionGroup->addTo(fileToolbar);
00440 fileToolbar->addSeparator();
00441 QWhatsThis::whatsThisButton(fileToolbar);
00442 }
00443
00444 void TrapperApp::initStatusBar()
00445 {
00446
00447
00448 statusBar()->message(tr("Ready."));
00449 }
00450
00451 void TrapperApp::initView()
00452 {
00453
00454
00455 QVBox* view_back = new QVBox( this );
00456 view_back->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00457 pWorkspace = new QWorkspace( view_back );
00458 setCentralWidget(view_back);
00459 }
00460
00461 void TrapperApp::createClient(TrapperDoc* doc, QString modeView )
00462 {
00463
00464 TrapperView* w = new TrapperView(doc, pWorkspace, modeView, modeView);
00465 w->installEventFilter(this);
00466 doc->addView(w);
00467 connect( w, SIGNAL( message( const QString& ) ), statusBar(), SLOT( message( const QString& ) ) );
00468
00469
00470 connect( w, SIGNAL( createView( QString ) ), this, SLOT( slotCreateClient( QString ) ) );
00471 if ( pWorkspace->windowList().isEmpty() )
00472 w->showMaximized();
00473 else
00474 w->show();
00475 }
00476
00477 void TrapperApp::slotCreateClient( QString modeView )
00478 {
00479 cerr<<"I suspect I never get called...???"<<endl;
00480 statusBar()->message(tr("Opening new view ..."));
00481
00482 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00483 if( m )
00484 {
00485 TrapperDoc* doc = m->getDocument();
00486 createClient( doc, modeView );
00487 }
00488 statusBar()->message(tr("Ready."));
00489 }
00490
00491 void TrapperApp::openDocumentFile(const char* file)
00492 {
00493 statusBar()->message(tr("Opening file..."));
00494
00495 TrapperDoc* doc;
00496
00497 for(doc=pDocList->first(); doc > 0; doc=pDocList->next()) {
00498
00499
00500 if(doc->pathName() == file) {
00501 TrapperView* view=doc->firstView();
00502 view->setFocus();
00503 return;
00504 }
00505 }
00506 doc = new TrapperDoc(dbenv);
00507 pDocList->append(doc);
00508 doc->newDocument();
00509
00510
00511
00512 QString fileName;
00513 if(!file)
00514 {
00515 untitledCount+=1;
00516 fileName=QString(tr("%1/Untitled%2")).arg(projectDir).arg(untitledCount);
00517
00518
00519
00520 }
00521 else
00522 {
00523 fileName = file;
00524 }
00525
00526 if(!doc->openDocument(fileName))
00527 {
00528 QMessageBox::critical(this, tr("Error !"),tr("Could not open document !"));
00529 delete doc;
00530 return;
00531 }
00532
00533
00534
00535
00536
00537
00538 createClient(doc, QString("closeup"));
00539
00540 statusBar()->message(tr("Ready."));
00541 }
00542
00543 bool TrapperApp::queryExit()
00544 {
00545 int exit=QMessageBox::information(this, tr("Quit..."),
00546 tr("Do your really want to quit?"),
00547 QMessageBox::Ok, QMessageBox::Cancel);
00548
00549 if (exit==1)
00550 {}
00551 else
00552 {}
00553 ;
00554
00555 return (exit==1);
00556 }
00557
00558 bool TrapperApp::eventFilter(QObject* object, QEvent* event)
00559 {
00560 if((event->type() == QEvent::Close) && ((TrapperApp*)object!=this) ) {
00561
00562 QCloseEvent* e = (QCloseEvent*)event;
00563 TrapperView* pView = (TrapperView*)object;
00564 TrapperDoc* pDoc = pView->getDocument();
00565 if(pDoc->canCloseFrame(pView)) {
00566 pDoc->removeView(pView);
00567 if( !pDoc->firstView() ) {
00568 pDocList->remove(pDoc);
00569 }
00570
00571 e->accept();
00572
00573 }
00574 else {
00575 e->ignore();
00576 }
00577 return true;
00578 }
00579 else if ( (event->type() == QEvent::KeyPress) ) {
00580 QKeyEvent* e = (QKeyEvent*)event;
00581 int scrollfactor(10);
00582 if ( e->state() == Qt::ControlButton )
00583 scrollfactor *= 10;
00584
00585 if ( e->key() == Qt::Key_Up ) {
00586 scroll(0, -1*scrollfactor);
00587 e->accept();
00588 return true;
00589 }
00590 else if ( e->key() == Qt::Key_Down ) {
00591 scroll(0, 1*scrollfactor);
00592 e->accept();
00593 return true;
00594 }
00595 else if ( e->key() == Qt::Key_Left ) {
00596 scroll(-1*scrollfactor, 0);
00597 e->accept();
00598 return true;
00599 }
00600 else if ( e->key() == Qt::Key_Right ) {
00601 scroll(1*scrollfactor, 0);
00602 e->accept();
00603 return true;
00604 }
00605 else if ( e->key() == Qt::Key_Tab ) {
00606 pWorkspace->activateNextWindow();
00607 e->accept();
00608 return true;
00609 }
00610 else if ( e->key() == Qt::Key_Backtab ) {
00611 pWorkspace->activatePrevWindow();
00612 e->accept();
00613 return true;
00614 }
00615
00616 e->ignore();
00617 }
00618
00619
00620 return QWidget::eventFilter( object, event );
00621 }
00622
00623
00624
00625
00626
00627 void TrapperApp::slotFileNew()
00628 {
00629 statusBar()->message(tr("Creating new file..."));
00630
00631 openDocumentFile();
00632
00633 statusBar()->message(tr("Ready."));
00634 }
00635
00636 void TrapperApp::slotFileOpen()
00637 {
00638 statusBar()->message(tr("Opening file..."));
00639
00640 QString dirName = QFileDialog::getExistingDirectory(projectDir,this,"contig dir selection","Choose contig dir");
00641 if (!dirName.isEmpty())
00642 {
00643 QDir d(dirName), projdir(projectDir);
00644
00645 if ( !d.cdUp() || d!= projdir ) {
00646 QMessageBox::critical(this, tr("Error !"),tr("Contig directory must be a subdirectory of project directory!"));
00647
00648 }
00649 else {
00650 cerr << "opening contig dir=" << dirName<<endl;
00651 openDocumentFile(dirName);
00652 }
00653 }
00654 statusBar()->message(tr("Ready."));
00655 }
00656
00657
00658 void TrapperApp::slotFileSave()
00659 {
00660 statusBar()->message(tr("Saving file..."));
00661
00662 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00663 if( m )
00664 {
00665 TrapperDoc* doc = m->getDocument();
00666 if(doc->title().contains(tr("Untitled")))
00667 slotFileSaveAs();
00668 else
00669 if(!doc->saveDocument(doc->pathName()))
00670 QMessageBox::critical (this, tr("I/O Error !"), tr("Could not save the current document !"));
00671 }
00672
00673 statusBar()->message(tr("Ready."));
00674 }
00675
00676 void TrapperApp::slotFileSaveAs()
00677 {
00678 statusBar()->message(tr("Saving file under new filename..."));
00679 QString fn = QFileDialog::getSaveFileName(0, 0, this);
00680 if (!fn.isEmpty())
00681 {
00682 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00683 if( m )
00684 {
00685 TrapperDoc* doc = m->getDocument();
00686 if(!doc->saveDocument(fn))
00687 {
00688 QMessageBox::critical (this, tr("I/O Error !"), tr("Could not save the current document !"));
00689 return;
00690 }
00691 doc->changedViewList();
00692 }
00693 }
00694 statusBar()->message(tr("Ready."));
00695 }
00696 void TrapperApp::slotFileFlush()
00697 {
00698 statusBar()->message(tr("Flushing database caches..."));
00699
00700 for(TrapperDoc * doc=pDocList->first(); doc!= 0; doc=pDocList->next())
00701 {
00702 cerr<<"doc->pathName(): "<<doc->pathName()<<endl;
00703 list<string> type_list = GeneralMaker::listRegistered();
00704 for( list<string>::iterator it = type_list.begin(); it != type_list.end(); ++it ) {
00705 TrDb* db = doc->findTrDb( *it );
00706 if ( db ) {
00707 cerr<<"Syncing "<<*it<<endl;
00708 db->sync();
00709
00710 }
00711 }
00712 }
00713 statusBar()->message(tr("Ready."));
00714 }
00715
00716 void TrapperApp::slotFileClose()
00717 {
00718 cerr<<"Hello slotFileClose() "<<endl;
00719
00720 statusBar()->message(tr("Closing file..."));
00721
00722 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00723 if( m )
00724 {
00725 TrapperDoc* doc=m->getDocument();
00726 doc->closeDocument();
00727 }
00728
00729 statusBar()->message(tr("Ready."));
00730 cerr<<"Bye slotFileClose() "<<endl;
00731 }
00732
00733 void TrapperApp::slotFilePrint()
00734 {
00735 statusBar()->message(tr("Printing..."));
00736
00737 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00738 if ( m )
00739 m->print( printer );
00740
00741 statusBar()->message(tr("Ready."));
00742 }
00743
00744 void TrapperApp::slotFileQuit()
00745 {
00746 statusBar()->message(tr("Exiting application..."));
00747
00748 for(TrapperDoc * doc=pDocList->first(); doc > 0; doc=pDocList->next())
00749 {
00750 delete doc;
00751 }
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 qApp->quit();
00770
00771
00772
00773
00774
00775
00776
00777
00778 statusBar()->message(tr("Ready."));
00779 }
00780
00781 void TrapperApp::slotEditUndo()
00782 {
00783 statusBar()->message(tr("Reverting last move..."));
00784
00785 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00786 if ( m ) m->undo();
00787
00788 statusBar()->message(tr("Ready."));
00789 }
00790
00791 void TrapperApp::slotEditCut()
00792 {
00793 statusBar()->message(tr("Cutting selection..."));
00794
00795 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00796 if ( m ) m->cut();
00797
00798 statusBar()->message(tr("Ready."));
00799 }
00800
00801 void TrapperApp::slotEditCopy()
00802 {
00803 statusBar()->message(tr("Copying selection to clipboard..."));
00804
00805 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00806 if ( m ) m->copy();
00807
00808 statusBar()->message(tr("Ready."));
00809 }
00810
00811 void TrapperApp::slotEditPaste()
00812 {
00813 statusBar()->message(tr("Inserting clipboard contents..."));
00814
00815 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00816 if ( m ) m->paste();
00817 statusBar()->message(tr("Ready."));
00818 }
00819
00820 void TrapperApp::slotEditSelectAll()
00821 {
00822 statusBar()->message(tr("Selecting all reads..."));
00823
00824 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00825 if ( m ) m->selectAll();
00826 statusBar()->message(tr("Ready."));
00827 }
00828
00829 void TrapperApp::slotEditSelectBetween()
00830 {
00831 statusBar()->message(tr("Selecting all reads between rows..."));
00832
00833 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00834 if ( m ) m->selectBetween();
00835 statusBar()->message(tr("Ready."));
00836 }
00837
00838 void TrapperApp::slotEditFindRead()
00839 {
00840 statusBar()->message(tr("Finding read..."));
00841
00842 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00843 if ( m ) m->findRead();
00844 statusBar()->message(tr("Ready."));
00845 }
00846
00847 void TrapperApp::slotViewToolBar(bool toggle)
00848 {
00849 statusBar()->message(tr("Toggle toolbar..."));
00850
00851
00852 if (toggle== false)
00853 {
00854 fileToolbar->hide();
00855 }
00856 else
00857 {
00858 fileToolbar->show();
00859 };
00860 statusBar()->message(tr("Ready."));
00861 }
00862
00863 void TrapperApp::slotViewStatusBar(bool toggle)
00864 {
00865 statusBar()->message(tr("Toggle statusbar..."));
00866
00867
00868
00869 if (toggle == false)
00870 {
00871 statusBar()->hide();
00872 }
00873 else
00874 {
00875 statusBar()->show();
00876 }
00877 statusBar()->message(tr("Ready."));
00878 }
00879
00880 void TrapperApp::slotWindowNewWindow()
00881 {
00882 statusBar()->message(tr("Opening new document view..."));
00883
00884 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
00885 if ( m )
00886 {
00887 TrapperDoc* doc = m->getDocument();
00888 createClient(doc);
00889 }
00890 statusBar()->message(tr("Ready."));
00891 }
00892
00893 void TrapperApp::slotHelpAbout()
00894 {
00895 QMessageBox::about(this,tr("About..."),
00896 tr("Trapper\nVersion 0.1"
00897 "\n(c) 2003 - 2005 by Erik Arner, Martti Tammi, Erik Sjölund and Staffan Alveteg"));
00898 }
00899
00900 void TrapperApp::slotHelpManual()
00901 {
00902
00903
00904
00905
00906
00907 }
00908
00909 void TrapperApp::showAssistantErrors( const QString &err )
00910 {
00911
00912
00913 }
00914
00915 void TrapperApp::slotStatusHelpMsg(const QString &text)
00916 {
00917
00918
00919 statusBar()->message(text, 2000);
00920 }
00921
00922 void TrapperApp::windowMenuAboutToShow()
00923 {
00924 pWindowMenu->clear();
00925 windowNewWindow->addTo(pWindowMenu);
00926 windowCascade->addTo(pWindowMenu);
00927 windowTile->addTo(pWindowMenu);
00928
00929 if ( pWorkspace->windowList().isEmpty() )
00930 {
00931 windowAction->setEnabled(false);
00932 }
00933 else
00934 {
00935 windowAction->setEnabled(true);
00936 }
00937
00938 pWindowMenu->insertSeparator();
00939
00940 QWidgetList windows = pWorkspace->windowList();
00941 for ( int i = 0; i < int(windows.count()); ++i )
00942 {
00943 int id = pWindowMenu->insertItem(QString("&%1 ").arg(i+1)+windows.at(i)->caption(), this, SLOT( windowMenuActivated( int ) ) );
00944 pWindowMenu->setItemParameter( id, i );
00945 pWindowMenu->setItemChecked( id, pWorkspace->activeWindow() == windows.at(i) );
00946 }
00947 }
00948
00949 void TrapperApp::windowMenuActivated( int id )
00950 {
00951 QWidget* w = pWorkspace->windowList().at( id );
00952 if ( w )
00953 w->setFocus();
00954 }
00955
00956 void TrapperApp::slotZoomIn()
00957 {
00958 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00959 if( m )
00960 {
00961 m->zoomIn();
00962 }
00963 }
00964
00965 void TrapperApp::slotZoomInX()
00966 {
00967 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00968 if( m )
00969 {
00970 m->zoomInX();
00971 }
00972 }
00973
00974 void TrapperApp::slotZoomInY()
00975 {
00976 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00977 if( m )
00978 {
00979 m->zoomInY();
00980 }
00981 }
00982
00983 void TrapperApp::slotZoomOut()
00984 {
00985 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00986 if( m )
00987 {
00988 m->zoomOut();
00989 }
00990 }
00991
00992 void TrapperApp::slotZoomOutX()
00993 {
00994 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
00995 if( m )
00996 {
00997 m->zoomOutX();
00998 }
00999 }
01000
01001 void TrapperApp::slotZoomOutY()
01002 {
01003 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01004 if( m )
01005 {
01006 m->zoomOutY();
01007 }
01008 }
01009
01010 void TrapperApp::slotEnlarge()
01011 {
01012 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01013 if( m )
01014 {
01015 m->enlarge();
01016 }
01017 }
01018
01019 void TrapperApp::slotShrink()
01020 {
01021 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01022 if( m )
01023 {
01024 m->shrink();
01025 }
01026 }
01027
01028 void TrapperApp::slotImport()
01029 {
01030 statusBar()->message(tr("Importing data from an xml file..."));
01031 QString fn = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your xml file to import from");
01032 if (!fn.isEmpty()) {
01033 QFile f( fn );
01034 if ( !f.open( IO_ReadOnly ) ) {
01035 QMessageBox::warning(this,"","couldn't read file");
01036 }
01037
01038 QDomDocument domDoc("Trapper");
01039 if ( !domDoc.setContent( &f ) ) {
01040 f.close();
01041 QMessageBox::warning(this,"","couldn't read xml");
01042 return;
01043 }
01044 f.close();
01045
01046 QDomElement docElem = domDoc.documentElement();
01047
01048 for( QDomNode node1 = docElem.firstChild(); !node1.isNull() ; node1 = node1.nextSibling()) {
01049 if ( node1.isElement() && node1.nodeName() == "contig" ) {
01050 QDomElement elem1 = node1.toElement();
01051
01052 Q_ASSERT((elem1.hasAttribute("name")));
01053 QString contigName = elem1.attribute( "name");
01054
01055
01056 bool found = false;
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068 QStringList contigNamesAlreadyPresent = contigNamesInProjectDir();
01069 if ( contigNamesAlreadyPresent.contains( contigName ) ) {
01070 found = true;
01071 }
01072 if ( found ) {
01073 QString message;
01074 message = QString("The contig name \"%1\" was specified in the import file, but that contig is already present in the project dir. Skipping this one").arg(contigName);
01075 QMessageBox::warning(this,"",message);
01076 continue;
01077 }
01078 QString fName = projectDir + "/" + contigName;
01079 TrapperDoc * tdoc = new TrapperDoc(dbenv);
01080 tdoc->openDocument(fName);
01081 tdoc->import( elem1 );
01082 delete tdoc;
01083 tdoc = NULL;
01084 cerr << "reached after"<<endl;
01085
01086 }
01087
01088 }
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103 }
01104 statusBar()->message(tr("Ready."));
01105 }
01106
01107 void TrapperApp::slotNewImport()
01108 {
01109 statusBar()->message(tr("Importing data from an xml file..."));
01110 QString fn = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your xml file to import from");
01111 if (!fn.isEmpty()) {
01112 QFile f( fn );
01113 if ( !f.open( IO_ReadOnly ) ) {
01114 QMessageBox::warning(this,"","couldn't open file");
01115 return;
01116 }
01117
01118 TrapperParser handler(dbenv, projectDir);
01119 QXmlInputSource source( &f );
01120 QXmlSimpleReader reader;
01121 reader.setContentHandler( &handler );
01122
01123
01124 if (!reader.parse(source) ) {
01125 QMessageBox::warning(this,"","couldn't read file");
01126 return;
01127 }
01128
01129 }
01130 statusBar()->message(tr("Ready."));
01131 }
01132
01133 void TrapperApp::slotChromatImport()
01134 {
01135 statusBar()->message(tr("Importing chromatogram data..."));
01136
01137 QString chromatDirName = QFileDialog::getExistingDirectory(projectDir,this,"chromat dir selection","Choose chromatogram directory");
01138
01139 if (chromatDirName.isEmpty()) {
01140 return;
01141 }
01142
01143
01144
01145 QPtrList<TrapperDoc> docListNotAlreadyOpen;
01146 docListNotAlreadyOpen.setAutoDelete(true);
01147
01148 open_docs_not_already_open( docListNotAlreadyOpen );
01149
01150 for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01151 doc->importChromat(chromatDirName);
01152 }
01153 for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01154 doc->importChromat(chromatDirName);
01155 }
01156
01157
01158
01159 statusBar()->message(tr("Ready."));
01160 }
01161
01162 void TrapperApp::slotMateImport()
01163 {
01164 statusBar()->message(tr("Importing mate data..."));
01165
01166 QString matefile = QFileDialog::getOpenFileName(0, 0, this,"import from file dialog","Choose your mate pair file to import from");
01167
01168 if (matefile.isEmpty()) {
01169 return;
01170 }
01171
01172
01173
01174 QPtrList<TrapperDoc> docListNotAlreadyOpen;
01175 docListNotAlreadyOpen.setAutoDelete(true);
01176
01177 open_docs_not_already_open( docListNotAlreadyOpen );
01178
01179 for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01180 doc->importMates(matefile);
01181 }
01182 for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01183 doc->importMates(matefile);
01184 }
01185
01186
01187 statusBar()->message(tr("Ready."));
01188 }
01189
01190 void TrapperApp::slotPhdImport()
01191 {
01192 statusBar()->message(tr("Importing phd data..."));
01193
01194 QString phdDirName = QFileDialog::getExistingDirectory(projectDir,this,"phd dir selection","Choose phd directory");
01195
01196 if (phdDirName.isEmpty()) {
01197 return;
01198 }
01199
01200
01201
01202 QPtrList<TrapperDoc> docListNotAlreadyOpen;
01203 docListNotAlreadyOpen.setAutoDelete(true);
01204
01205 open_docs_not_already_open( docListNotAlreadyOpen );
01206
01207 for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01208 doc->importPhd(phdDirName);
01209 }
01210 for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01211 doc->importPhd(phdDirName);
01212 }
01213
01214
01215
01216 statusBar()->message(tr("Ready."));
01217 }
01218
01219 void TrapperApp::open_docs_not_already_open(QPtrList<TrapperDoc>& notOpenBefore)
01220 {
01221
01222 TrapperDoc* doc;
01223 set<QString> alreadyOpen;
01224
01225 for(doc=pDocList->first(); doc !=0; doc=pDocList->next()) {
01226
01227 alreadyOpen.insert(doc->pathName().section('/', -2));
01228 }
01229
01230
01231 QStringList contigs = contigNamesInProjectDir();
01232
01233 for ( QStringList::Iterator it = contigs.begin(); it != contigs.end(); ++it ) {
01234
01235
01236 if ( *it != "." && *it != ".." && alreadyOpen.find( *it ) == alreadyOpen.end() ) {
01237
01238
01239 TrapperDoc* tdoc = new TrapperDoc(dbenv);
01240 tdoc->newDocument();
01241 if ( !tdoc->openDocument(projectDir + "/" + *it ) ) {
01242 QMessageBox::critical(this, tr("Error !"),tr("Could not open document!"));
01243 delete tdoc;
01244 }
01245 else {
01246 notOpenBefore.append( tdoc );
01247 }
01248
01249 }
01250
01251
01252 }
01253
01254 }
01255
01256 void TrapperApp::map_reads_to_docs(str_doc_map& readmap, QPtrList<TrapperDoc>& notOpenBefore)
01257 {
01258 TrapperDoc* doc;
01259
01260 for(doc=pDocList->first(); doc !=0; doc=pDocList->next()) {
01261 Database::SecondaryIterator<ReadData> name_it( "name", doc, "ReadData" );
01262 assert(name_it.first() == 0);
01263 do {
01264 readmap.insert(make_pair(QString(name_it.answer()->name()), doc));
01265 }while( name_it.next() == 0 );
01266
01267
01268 }
01269 for(doc=notOpenBefore.first(); doc !=0; doc=notOpenBefore.next()) {
01270 Database::SecondaryIterator<ReadData> name_it( "name", doc, "ReadData" );
01271 assert(name_it.first() == 0);
01272 do {
01273 readmap.insert(make_pair(name_it.answer()->name(), doc));
01274
01275 }while( name_it.next() == 0 );
01276
01277
01278 }
01279
01280 }
01281
01282 void TrapperApp::slotExport()
01283 {
01284 statusBar()->message(tr("Exporting data to an xml file..."));
01285 QString fn = QFileDialog::getSaveFileName(0, "Trapper Xml (*.xml)", this,
01286 "export to file dialog",
01287 "Choose a filename to save the export data under");
01288 if (fn.isEmpty())
01289 {
01290 return;
01291 }
01292 if ( QFile::exists( fn ) &&
01293 QMessageBox::question(
01294 0,
01295 tr("Overwrite File? -- Trapper"),
01296 tr("A file called %1 already exists."
01297 "Do you want to overwrite it?")
01298 .arg( fn ),
01299 tr("&Yes"), tr("&No"),
01300 QString::null, 0, 1 ) ) {
01301
01302 return;
01303 }
01304
01305 exportToFile(fn);
01306 statusBar()->message(tr("Ready."));
01307 }
01308
01309 void TrapperApp::exportToFile(QString toXmlFile)
01310 {
01311 statusBar()->message(tr("Exporting project to file..."));
01312
01313
01314
01315 ofstream outFile(toXmlFile.ascii());
01316
01317
01318 outFile<<"<TRAPPER>\n";
01319 QPtrList<TrapperDoc> docListNotAlreadyOpen;
01320 docListNotAlreadyOpen.setAutoDelete(true);
01321
01322 open_docs_not_already_open( docListNotAlreadyOpen );
01323
01324
01325 for (TrapperDoc* doc = pDocList->first(); doc != 0; doc = pDocList->next() ) {
01326 doc->saveExport(outFile);
01327 }
01328 for (TrapperDoc* doc = docListNotAlreadyOpen.first(); doc != 0; doc = docListNotAlreadyOpen.next() ) {
01329 doc->saveExport(outFile);
01330 }
01331
01332
01333 outFile<<"</TRAPPER>\n";
01334
01335 outFile.close();
01336 statusBar()->message(tr("Ready."));
01337
01338 }
01339
01340 void TrapperApp::setDbHomeDir(QString dir)
01341 {
01342 QDir d(dir);
01343 if ( d.exists() )
01344 {
01345 projectDir = d.absPath();
01346 int ret;
01347
01348 if ((ret = dbenv->open(projectDir, DB_CREATE |
01349 DB_INIT_LOG | DB_INIT_LOCK | DB_INIT_MPOOL | DB_INIT_TXN | DB_RECOVER , 0)) != 0) {
01350 dbenv->err(ret, "environment open: %s", dir.ascii());
01351 exit( 1);
01352 }
01353 cerr<<"DB home dir set"<<endl;
01354 }
01355 else
01356 {
01357 QMessageBox::critical( 0,
01358 tr( "Critical Error" ),
01359 tr( "Db home dir \"%1\" doesn't exit" ).arg( dir ) );
01360
01361
01362 exit(1);
01363 }
01364
01365 }
01366
01367 QStringList TrapperApp::contigNamesInProjectDir()
01368 {
01369 QString contigName;
01370 QDir d( projectDir );
01371 Q_ASSERT( d.exists() );
01372 d.setFilter( QDir::Dirs | QDir::NoSymLinks );
01373 d.setSorting( QDir::Name );
01374 QStringList slist = d.entryList();
01375 return slist;
01376 }
01377
01378 void TrapperApp::slotShowStatistics()
01379 {
01380 statusBar()->message(tr("Opening statistics window ..."));
01381
01382 TrapperView* m = (TrapperView*)pWorkspace->activeWindow();
01383 if( m )
01384 {
01385 TrapperDoc* doc = m->getDocument();
01386 if ( doc )
01387 {
01388 QString statisticsText = doc->getStatistics();
01389 QTextEdit * statView = new QTextEdit( );
01390 statView->setReadOnly( true );
01391 statView->setText( statisticsText );
01392 statView->show();
01393 }
01394 }
01395 statusBar()->message(tr("Ready."));
01396 }
01397
01398 void TrapperApp::slotConfigureViewModes()
01399 {
01400 ShowModesDlg * dlg = new ShowModesDlg( this, QString::null );
01401
01402 if ( dlg->exec() == QDialog::Accepted )
01403 {}
01404 }
01405
01406
01407 void TrapperApp::setViewModeConfFile( QString filename )
01408 {
01409 viewmodefile.setName( filename );
01410
01411 if ( ! viewmodefile.open( IO_ReadWrite ) )
01412 {
01413 QMessageBox::critical( 0,
01414 tr( "Critical Error" ),
01415 tr( "Cannot open configuration file %1" ).arg( filename ) );
01416
01417
01418 exit(1);
01419 }
01420
01421 TrapperConf * conf = TrapperConf::instance();
01422 Q_CHECK_PTR( conf );
01423 conf->loadDom( &viewmodefile );
01424 }
01425
01426 void TrapperApp::scroll(int dx, int dy)
01427 {
01428
01429 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01430 if ( m ) m->scrollBy(dx, dy);
01431 }
01432 void TrapperApp::slotNormalMode()
01433 {
01434
01435 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01436 if ( m ) m->setDragMode(false);
01437
01438 }
01439
01440
01441 void TrapperApp::slotDragMode()
01442 {
01443 TrapperView* m = (TrapperView*) pWorkspace->activeWindow();
01444 if ( m ) m->setDragMode(true);
01445
01446 }
01447
01448 void TrapperApp::slotActivatedWindow(QWidget* w)
01449 {
01450 TrapperView* m = (TrapperView*) w;
01451 if ( m ) m->setDragMode(dragModeAction->isOn());
01452
01453 }
01454