Apparently I lost a } in a Mac OS X specific section of the code. Sowwy. Fixed.
[mussa.git] / qui / MussaWindow.cpp
index 20c4a032e8dca3c8169188da8e860dcca98033d6..75da849d591416a25371c980e9454b8c46e737af 100644 (file)
 #include <QFileDialog>
 #include <QHBoxLayout>
 #include <QIcon>
+#include <QLibraryInfo>
 #include <QMenuBar>
 #include <QMessageBox>
+#include <QProcess>
 #include <QScrollBar>
 #include <QStatusBar>
 #include <QString>
 #include <QStringList>
+#include <QTextStream>
 #include <QUrl>
 #include <QWhatsThis>
 
@@ -66,16 +69,18 @@ MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) :
   saveBrowserPixmapAction(0),
   whatsThisAction(0),
   viewMussaAlignmentAction(0),
-  manualAssistant(0)
+  assistantProcess(0)
 {
   init_resources();
+  
+  default_dir.reset(new QDir(QDir::home().absolutePath()));
+  
   setupWidgets();
   setupActions();
   setupAssistant();
   setupMainMenu();
   
   setWindowIcon(QIcon(":/icons/mussa.png"));
-  default_dir.reset(new QDir(QDir::home().absolutePath()));
 
   setCentralWidget(browser);
   // well updatePosition isn't quite right as we really just need
@@ -87,6 +92,10 @@ MussaWindow::MussaWindow(MussaRef analysis_, QWidget *parent) :
   connect(zoom, SIGNAL(valueChanged(double)), 
           browser, SLOT(setZoom(double)));
   mussaViewTB->addWidget(zoom);
+  
+  // Mouse Wheel triggered zooming
+  connect(browser, SIGNAL(mouseWheelZoom(double)),
+          zoom, SLOT(setValue(double)));
 
   // threshold range is set in updateAnalysis  
   connect(threshold, SIGNAL(thresholdChanged(int)),
@@ -113,7 +122,18 @@ void MussaWindow::setAnalysis(MussaRef new_analysis)
   if (new_analysis != 0) {
     // only switch mussas if we loaded without error
     clear();
+    //std::cout << "analysis soft: " << analysis->get_soft_threshold()
+    //          << " new analysis soft: " << new_analysis->get_soft_threshold()
+    //          << "\n";
     analysis.swap(new_analysis);
+    //std::cout << "after swap soft thres: " << analysis->get_soft_threshold()
+    //          << "\n";
+    threshold->disconnect(this);
+    threshold->reset(analysis->get_threshold(),
+                     analysis->get_window(),
+                     analysis->get_soft_threshold());
+    connect(threshold, SIGNAL(thresholdChanged(int)),
+          this, SLOT(setSoftThreshold(int)));
     updateTitle();
     updateAnalysis();
   }
@@ -208,9 +228,11 @@ void MussaWindow::setupActions()
 
   //Save pixel map action
   saveBrowserPixmapAction = new QAction(tr("Save to image..."), this);
-  connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
-         browser, SLOT(promptSaveBrowserPixmap()));
-  saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
+  if (browser) {
+    connect(saveBrowserPixmapAction, (SIGNAL(triggered())),
+            browser, SLOT(promptSaveBrowserPixmap()));
+    saveBrowserPixmapAction->setIcon(QIcon(":/icons/image2.png"));
+  }
 
   viewMussaAlignmentAction = new QAction(tr("View sequence alignment"), this);
   connect(viewMussaAlignmentAction, SIGNAL(triggered()),
@@ -257,10 +279,10 @@ void MussaWindow::setupMainMenu()
 
   newMenu = menuBar()->addMenu(tr("&Edit"));
   newMenu->addAction(editMotifsAction);
-  newMenu->addAction(browser->getCopySelectedSequenceAsStringAction());
-  newMenu->addAction(browser->getCopySelectedSequenceAsFastaAction());
+  if (browser) newMenu->addAction(browser->getCopySelectedSequenceAsStringAction());
+  if (browser) newMenu->addAction(browser->getCopySelectedSequenceAsFastaAction());
   newMenu->addAction(createSubAnalysisAction);
-  newMenu->addAction(browser->getEditSequencePropertiesAction());
+  if (browser) newMenu->addAction(browser->getEditSequencePropertiesAction());
  
   newMenu = menuBar()->addMenu(tr("&View"));
   newMenu->addAction(viewMussaAlignmentAction);
@@ -273,10 +295,12 @@ void MussaWindow::setupMainMenu()
   newMenu->addAction(aboutAction);
 
   // add some extra features to the context menu
-  QMenu *popupMenu = browser->getPopupMenu();
-  if (popupMenu) {
-    popupMenu->addAction(viewMussaAlignmentAction);
-    popupMenu->addAction(createSubAnalysisAction);
+  if (browser) {
+    QMenu *popupMenu = browser->getPopupMenu();
+    if (popupMenu) {
+      popupMenu->addAction(viewMussaAlignmentAction);
+      popupMenu->addAction(createSubAnalysisAction);
+    }
   }
 }
 
@@ -293,6 +317,7 @@ void MussaWindow::setupWidgets()
 void MussaWindow::setupAssistant()
 {
 #if defined(QT_QTASSISTANT_FOUND)
+  /*
   QStringList manualAssistantArgs;
   manualAssistantArgs = QStringList();
   manualAssistantArgs << "-profile" << "./doc/manual/mussagl_manual.adp";
@@ -300,6 +325,7 @@ void MussaWindow::setupAssistant()
   manualAssistant->setArguments(manualAssistantArgs);
   connect(manualAssistant, SIGNAL(error(QString)),
          this, SLOT(assistantError(QString)));
+  */
 #endif
 }
   
@@ -312,6 +338,9 @@ void MussaWindow::about()
   msg += "Version: ";
   msg += mussa_version;
   msg += "\n";
+  msg += "Qt: ";
+  msg += qVersion();
+  msg += "\n";
   msg += "OpenGL: ";
   msg += (char *)glGetString(GL_VERSION);
   msg += "\n";
@@ -320,6 +349,11 @@ void MussaWindow::about()
 
 void MussaWindow::clear()
 {
+  if (motif_editor != 0) {
+    motif_editor->hide();
+    delete motif_editor;
+  }
+  
   aligned_windows.clear();
   browser->clear();
 }
@@ -455,13 +489,11 @@ bool MussaWindow::isClearingAnalysisSafe()
 
 void MussaWindow::editMotifs()
 {
-  if (motif_editor != 0) {
-    motif_editor->hide();
-    delete motif_editor;
+  if (not motif_editor) {
+    motif_editor = new MotifEditor(analysis);
+    connect(motif_editor, SIGNAL(changedMotifs()), 
+            this, SLOT(updateAnnotations()));
   }
-  motif_editor = new MotifEditor(analysis);
-  connect(motif_editor, SIGNAL(changedMotifs()), 
-          this, SLOT(updateAnnotations()));
   motif_editor->show();
 }
 
@@ -619,14 +651,21 @@ void MussaWindow::newMussaWindow()
 
 void MussaWindow::setSoftThreshold(int value)
 {
+  //std::cout << "Soft: " << analysis->get_soft_threshold()
+  //          << " Value: " << value << "\n";
   if (analysis->get_soft_threshold() != value) {
     threshold->setEnabled( false );
+    //std::cout << "Updating!!!!\n";
     analysis->set_soft_threshold(value);
     analysis->nway();
     updateLinks();
     update();
     threshold->setEnabled( true );
   }
+  //else
+  //{
+  //  std::cout << "NOT Updating!!!!\n";
+  //}
 }
 
 void MussaWindow::showMussaToolbar()
@@ -655,16 +694,32 @@ void MussaWindow::toggleMotifs()
 void MussaWindow::showManual()
 {
 #if defined(QT_QTASSISTANT_FOUND)
-  if (manualAssistant) { 
-    manualAssistant->openAssistant();
-  } else {
-    QMessageBox::warning(this,
-                         tr("Mussa Help Error"),
-                         tr("QtAssistant not setup correctly"),
-                         QMessageBox::Ok,
-                         QMessageBox::NoButton,
-                         QMessageBox::NoButton);
+  
+  // Only define the process once.
+  if (!assistantProcess)
+    assistantProcess = new QProcess(this);
+  
+  // No need to fire up the process again if it is already running.
+  if (assistantProcess->state() == QProcess::Running)
+    return;
+  
+  QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath)
+      + QLatin1String("/assistant");
+
+  assistantProcess->start(app, QStringList() << QLatin1String("-enableRemoteControl")
+                           << QLatin1String("-collectionFile") << QLatin1String("mussagl_manual.qhc"));
+  if (!assistantProcess->waitForStarted()) {
+      QMessageBox::critical(this, tr("Remote Control"),
+         tr("Could not start Qt Assistant from %1.").arg(app));
+      return;
   }
+
+  // show index page
+  QTextStream str(assistantProcess);
+  str << QLatin1String("SetSource qthelp://edu.caltech.woldlab.mussagl.1_0_0/doc/mussagl_manual.html;")
+      << QLatin1String("expandToc 0")
+      << QLatin1Char('\0') << endl;
+
 #else
   QUrl manual_url("http://woldlab.caltech.edu/~king/mussagl_manual/");
   if (not QDesktopServices::openUrl(manual_url)) {
@@ -721,6 +776,7 @@ void MussaWindow::updateAnalysis()
   // but it's possible for us to not have had a chance to set out sequences
   // yet.
   threshold->setRange(analysis->get_threshold(),analysis->get_window());
+  threshold->setBasepairThreshold(analysis->get_soft_threshold());
   updateLinks();
   browser->zoomOut();
   zoom->setValue(browser->zoom());