implement zoom in terms of base pairs per pixel
authorDiane Trout <diane@caltech.edu>
Sun, 19 Mar 2006 01:10:17 +0000 (01:10 +0000)
committerDiane Trout <diane@caltech.edu>
Sun, 19 Mar 2006 01:10:17 +0000 (01:10 +0000)
Though the value we return from zoom is actually basepairs/pixels*100
(so i can use int).

I also implemented a zoomOut function that zooms far enough out to fit the
current scene on the display.

alg/glseqbrowser.cpp
alg/glseqbrowser.hpp
qui/MussaWindow.cpp
qui/seqbrowser/SequenceBrowserWidget.cpp
qui/seqbrowser/SequenceBrowserWidget.hpp

index 96496a2fd751102532a32e616ba846006e90a87e..386b5f6f5d4d4fd04c4da49002a8604dc2823a71 100644 (file)
@@ -19,7 +19,6 @@ GlSeqBrowser::GlSeqBrowser()
 
 GlSeqBrowser::GlSeqBrowser(const GlSeqBrowser& gt)
   : border_width(gt.border_width),
-    max_ortho(gt.max_ortho),
     cur_ortho(gt.cur_ortho),
     viewport_size(gt.viewport_size),
     viewport_center(gt.viewport_center),
@@ -244,6 +243,20 @@ float GlSeqBrowser::viewportWidth() const
   return cur_ortho.right - cur_ortho.left;
 }
 
+int GlSeqBrowser::zoomOut()
+{
+
+  if (right() - left() > 0) {
+    cur_ortho.left = left();
+    cur_ortho.right = right();
+    zoom_level = (int)(( (right() - left()) / viewport_size.x) * 100);
+    return zoom_level;
+  } else {
+    // made up number representing 50 bp / pixel
+    return 5000;
+  }
+}
+
 void GlSeqBrowser::setZoom(int new_zoom)
 {
   update_viewport(viewport_center, new_zoom);
@@ -305,7 +318,7 @@ void GlSeqBrowser::clear_links()
 }
 
 void 
-GlSeqBrowser::link(const vector<int>& path, const vector<bool>& rc, int length)
+GlSeqBrowser::link(const vector<int>& path, const vector<bool>& rc, int )
 {
   if (path.size() < 2) {
     // should i throw an error instead?
@@ -366,14 +379,13 @@ void GlSeqBrowser::centerOnPath(const vector<int>& paths)
 
 void GlSeqBrowser::update_viewport(float center, int new_zoom)
 {
-  float max_width = max_ortho.width();
-  // division by zero is a major bummer
+  // limit how close we can get
   if (new_zoom < 1) {
     new_zoom = 1;
   }
-  float new_max_width = max_width / new_zoom;
-  cur_ortho.left = center-new_max_width;
-  cur_ortho.right = center+new_max_width;
+  float new_width = (((float)new_zoom / 100.0) * (float)viewport_size.x);
+  cur_ortho.left = center-new_width/2.0;
+  cur_ortho.right = center+new_width/2.0;
 }
 
 void GlSeqBrowser::update_layout()
@@ -406,12 +418,12 @@ void GlSeqBrowser::update_layout()
     // nothing to do as we're empty
     return;
   }
-  max_ortho.right = max_base_pairs + border_width;
-  max_ortho.left = -border_width;
-  max_ortho.top = viewport_size.x;
-  max_ortho.bottom = 0;
-  cur_ortho = max_ortho;
+  cur_ortho.right = max_base_pairs + border_width;
+  cur_ortho.left = -border_width;
+  cur_ortho.top = viewport_size.x;
+  cur_ortho.bottom = 0;
   viewport_center = (cur_ortho.width()/2) + cur_ortho.left;
+  zoomOut();
 }
 
 void GlSeqBrowser::draw() const
index fb9e4906e52539648713e2904917e15fb6612c5a..36a17c821a89a875f78f4f07ce8ea3730565ba1b 100644 (file)
@@ -41,7 +41,14 @@ public:
   float viewportHeight() const;
   float viewportWidth() const;
 
+  //! zoom out far enough to show the full size of the sequence
+  int zoomOut();
+  //! set the current zoom level in (base pairs / pix ) * 100
+  /*! a zoomlevel of 1 is .01 base pairs per pixel or a rather exploded
+   *  100 pixels per base pair
+   */
   void setZoom(int zoom_level);
+  //! returns the current zoom level
   int zoom() const;
 
   void setColorMapper(AnnotationColors& cm);
@@ -137,8 +144,6 @@ private:
 
   //! number of pixels to reserve around the edges of our canvas
   const int border_width;
-  //! the maximum dimensions that our scene is taking up (world coord)
-  rect<float> max_ortho;
   //! the current viewable region (world coord)
   rect<float> cur_ortho;
   //! how many pixels our viewport is (screen coord)
index 8696913d407c88b73c96d7edafe7cc5da7bef166..d6b97a6b565fba1f467cf4992c0edc5e5f506b3c 100644 (file)
@@ -46,7 +46,7 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) :
 
   zoomBox.setToolTip(tr("Zoom"));
   zoomBox.setWhatsThis(tr("Zoom magnification factor"));
-  zoomBox.setRange(2,1000);
+  zoomBox.setRange(1,10000000);
   mussaViewTB.addWidget(&zoomBox);
   connect(&zoomBox, SIGNAL(valueChanged(int)), 
           &browser, SLOT(setZoom(int)));
@@ -326,6 +326,9 @@ void MussaWindow::updateAnalysis()
   const vector<Sequence>& seqs = analysis->sequences();
   browser.setSequences(seqs, analysis->colorMapper());
   updateLinks();
+  browser.zoomOut();
+  cout << "browser zoom " <<  browser.zoom() << endl;
+  zoomBox.setValue(browser.zoom());
 }
 
 void MussaWindow::updateLinks()
index 557174216724dac761c4519310a34302c00f5c7e..4a35f8bfa9d56b8f9d0f18c1b161e81ee0c8111e 100644 (file)
@@ -134,6 +134,16 @@ void SequenceBrowserWidget::promptSaveBrowserPixmap()
   cout << "Result: " << result << "\n";
 }
 
+int SequenceBrowserWidget::zoom()
+{
+  return scrollable_browser.browser().zoom();
+}
+
+void SequenceBrowserWidget::zoomOut()
+{
+  scrollable_browser.browser().zoomOut();
+}
+
 void SequenceBrowserWidget::setZoom(int z)
 {
   scrollable_browser.browser().setZoom(z);
index 55d55f931dec54398874439ee60d4784282df388..f19f6322ba0a5da11014beacf34ae319f1f497bc 100644 (file)
@@ -18,8 +18,9 @@ class SequenceBrowserWidget : public QSplitter
 public:
   SequenceBrowserWidget(QWidget *parent=0);
 
-  //SequenceBrowser& browser() { return scrollable_browser.browser(); }
+  //! return current zoom size
+  int zoom();
+
   //! reset all of our stored data back to the empty state
   void clear();
 
@@ -44,6 +45,8 @@ public:
 public slots:
   //! set the zoom level of our browser
   void setZoom(int);
+  //! zoom to fit the whole scene on the screen
+  void zoomOut();
 
   void updatePosition();
   //! ask the user where to save an image of the current browser view