From: Diane Trout Date: Wed, 29 Mar 2006 05:28:51 +0000 (+0000) Subject: Move zoom spinbox into its own widget X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=commitdiff_plain;h=537fc2762517268d1949565b9ba011e42de65ab6;p=mussa.git Move zoom spinbox into its own widget and use doubles indicating the actual bp/pix instead of an int = bp/pix*100 --- diff --git a/alg/glseqbrowser.cpp b/alg/glseqbrowser.cpp index 36ab95e..fafe690 100644 --- a/alg/glseqbrowser.cpp +++ b/alg/glseqbrowser.cpp @@ -78,7 +78,6 @@ void GlSeqBrowser::processSelection(GLuint hits, GLuint buffer[], GLuint bufsize selected_paths.clear(); selected_tracks.clear(); - std::cout << "hits = " << hits << std::endl; ptr = (GLuint *) buffer; if (hits > 0) selectedMode = true; @@ -243,33 +242,35 @@ float GlSeqBrowser::viewportWidth() const return cur_ortho.right - cur_ortho.left; } -int GlSeqBrowser::zoomOut() +double GlSeqBrowser::zoomOut() { if (right() - left() > 0) { cur_ortho.left = left(); cur_ortho.right = right(); - zoom_level = (int)(( (right() - left()) / viewport_size.x) * 100); + zoom_level = (right() - left()) / (double)viewport_size.x; return zoom_level; } else { // made up number representing 50 bp / pixel - return 5000; + return 50.0; } } -int GlSeqBrowser::zoomToSequence() + +double GlSeqBrowser::zoomToSequence() { // (experimentally determined zoom level) - const int friendly_zoom = 7; + const double friendly_zoom = 0.10; setZoom(friendly_zoom); return friendly_zoom; } -void GlSeqBrowser::setZoom(int new_zoom) + +void GlSeqBrowser::setZoom(double new_zoom) { update_viewport(viewport_center, new_zoom); zoom_level = new_zoom; } -int GlSeqBrowser::zoom() const +double GlSeqBrowser::zoom() const { return zoom_level; } @@ -388,13 +389,13 @@ void GlSeqBrowser::centerOnPath(const vector& paths) } } -void GlSeqBrowser::update_viewport(float center, int new_zoom) +void GlSeqBrowser::update_viewport(float center, double new_zoom) { // limit how close we can get - if (new_zoom < 1) { - new_zoom = 1; + if (new_zoom < 0.01) { + new_zoom = 0.01; } - float new_width = (((float)new_zoom / 100.0) * (float)viewport_size.x); + double new_width = (new_zoom * (float)viewport_size.x); cur_ortho.left = center-new_width/2.0; cur_ortho.right = center+new_width/2.0; } diff --git a/alg/glseqbrowser.hpp b/alg/glseqbrowser.hpp index fe5423c..a662010 100644 --- a/alg/glseqbrowser.hpp +++ b/alg/glseqbrowser.hpp @@ -42,16 +42,15 @@ public: float viewportWidth() const; //! zoom out far enough to show the full size of the sequence - int zoomOut(); + double zoomOut(); //! zoom in to a reasonable sequence view - int zoomToSequence(); - //! 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 + double zoomToSequence(); + //! set the current zoom level in (base pairs / pix ) + /*! its a double as zoom levels of [0.01, 1.0] make nice sequence views */ - void setZoom(int zoom_level); + void setZoom(double zoom_level); //! returns the current zoom level - int zoom() const; + double zoom() const; void setColorMapper(AnnotationColors& cm); AnnotationColors& colorMapper(); @@ -125,7 +124,7 @@ private: /*! depending on the size of our canvas, our zoom level and * how far we've been offset */ - void update_viewport(float center, int new_zoom); + void update_viewport(float center, double new_zoom); //! determine where all the tracks should be placed void update_layout(); @@ -152,7 +151,7 @@ private: point viewport_size; //! the center of our current viewport (world coord) (used for scrollbar) float viewport_center; - int zoom_level; + double zoom_level; AnnotationColors color_mapper; //! container of all the GlSequences loaded into our scene std::vector track_container; diff --git a/mussagl.pro b/mussagl.pro index 3ad99c3..8006289 100644 --- a/mussagl.pro +++ b/mussagl.pro @@ -15,6 +15,7 @@ HEADERS += mussa_exceptions.hpp \ qui/MussaWindow.hpp \ qui/MussaAlignedWindow.hpp \ qui/ThresholdWidget.hpp \ + qui/ZoomWidget.hpp \ qui/ImageScaler.hpp \ qui/ImageSaveDialog.hpp \ qui/IntAction.hpp \ @@ -44,6 +45,7 @@ SOURCES += mussagl.cpp \ qui/MussaWindow.cpp \ qui/MussaAlignedWindow.cpp \ qui/ThresholdWidget.cpp \ + qui/ZoomWidget.cpp \ qui/ImageScaler.cpp \ qui/ImageSaveDialog.cpp \ qui/IntAction.cpp \ diff --git a/qui/MussaWindow.cpp b/qui/MussaWindow.cpp index 6565aef..5c16091 100644 --- a/qui/MussaWindow.cpp +++ b/qui/MussaWindow.cpp @@ -23,9 +23,8 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : motif_editor(0), browser(this), mussaViewTB("Path Views"), - zoomBox(), + zoom(), threshold(), - zoomLabel(), closeAction(0) // initialize one of the pointers to null as a saftey flag { setupActions(); @@ -41,18 +40,10 @@ MussaWindow::MussaWindow(Mussa *analysis_, QWidget *parent) : connect(this, SIGNAL(changedAnnotations()), &browser, SLOT(update())); mussaViewTB.addAction(toggleMotifsAction); + mussaViewTB.addWidget(&zoom); - zoomLabel.setPixmap(QIcon(":/icons/viewmag.png").pixmap(16, 16)); - zoomLabel.setToolTip(tr("Zoom")); - zoomLabel.setWhatsThis(tr("Zoom magnification factor")); - mussaViewTB.addWidget(&zoomLabel); - - zoomBox.setToolTip(tr("Zoom")); - zoomBox.setWhatsThis(tr("Zoom magnification factor")); - zoomBox.setRange(1,10000000); - mussaViewTB.addWidget(&zoomBox); - connect(&zoomBox, SIGNAL(valueChanged(int)), - &browser, SLOT(setZoom(int))); + connect(&zoom, SIGNAL(valueChanged(double)), + &browser, SLOT(setZoom(double))); // threshold range is set in updateAnalysis @@ -383,7 +374,7 @@ void MussaWindow::updateAnalysis() updateLinks(); browser.zoomOut(); cout << "browser zoom " << browser.zoom() << endl; - zoomBox.setValue(browser.zoom()); + zoom.setValue(browser.zoom()); } void MussaWindow::updateAnnotations() diff --git a/qui/MussaWindow.hpp b/qui/MussaWindow.hpp index 96dd3d2..b1dc329 100644 --- a/qui/MussaWindow.hpp +++ b/qui/MussaWindow.hpp @@ -13,6 +13,8 @@ #include "qui/mussa_setup_dialog/MussaSetupDialog.hpp" #include "qui/seqbrowser/SequenceBrowserWidget.hpp" #include "qui/ThresholdWidget.hpp" +#include "qui/ZoomWidget.hpp" + class QAction; class QLabel; @@ -72,10 +74,8 @@ protected: // display our wonderful mussa output SequenceBrowserWidget browser; QToolBar mussaViewTB; - QSpinBox zoomBox; + ZoomWidget zoom; ThresholdWidget threshold; - QLabel zoomLabel; - QAction *aboutAction; QAction *closeAction; diff --git a/qui/ZoomWidget.cpp b/qui/ZoomWidget.cpp new file mode 100644 index 0000000..c646df1 --- /dev/null +++ b/qui/ZoomWidget.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "qui/ZoomWidget.hpp" +#include +using namespace std; + +ZoomWidget::ZoomWidget(QWidget *parent) + : QWidget(parent), + max_zoom_size(10000) +{ + zoom.setRange(0.01, max_zoom_size); + zoom.setSingleStep(0.1); + connect(&zoom, SIGNAL(valueChanged(double)), this, SLOT(setValue(double))); + + QLabel *zoomLabel = new QLabel(); + zoomLabel->setPixmap(QIcon(":/icons/viewmag.png").pixmap(16, 16)); + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(zoomLabel); + layout->addWidget(&zoom); + setLayout(layout); + + setToolTip(tr("Zoom")); + setWhatsThis(tr("Zoom magnification factor (base pairs per pixel)")); +} + +void ZoomWidget::setValue(double value) +{ + if (cur_value != value) + { + cur_value = value; + zoom.setValue(cur_value); + emit valueChanged(cur_value); + } +} + +void ZoomWidget::setRange(double min, double max) +{ + zoom.setRange(min, max); +} + +void ZoomWidget::setSingleStep(double val) +{ + zoom.setSingleStep(val); +} + +double ZoomWidget::singleStep() const +{ + return zoom.singleStep(); +} + +double ZoomWidget::minimum() const +{ + return zoom.minimum(); +} + +double ZoomWidget::maximum() const +{ + return zoom.maximum(); +} + diff --git a/qui/ZoomWidget.hpp b/qui/ZoomWidget.hpp new file mode 100644 index 0000000..259e308 --- /dev/null +++ b/qui/ZoomWidget.hpp @@ -0,0 +1,35 @@ +#ifndef _ZOOMWIDGET_H_ +#define _ZOOMWIDGET_H_ + +#include +#include + +class ZoomWidget : public QWidget +{ + Q_OBJECT + +public: + ZoomWidget(QWidget *parent = 0); + //! set the range + void setRange(double min, double max); + double minimum() const; + double maximum() const; + //! set value used when incrementing the spinner + void setSingleStep(double val); + //! get the value used to incrementing the spinner + double singleStep() const; + +public slots: + void setValue(double); + +signals: + //! the current number of base pairs needed for a window of conservation + void valueChanged(double); + +protected: + QDoubleSpinBox zoom; + + double cur_value; + const double max_zoom_size; + }; +#endif diff --git a/qui/seqbrowser/SequenceBrowser.cpp b/qui/seqbrowser/SequenceBrowser.cpp index b95e7bc..90794e8 100644 --- a/qui/seqbrowser/SequenceBrowser.cpp +++ b/qui/seqbrowser/SequenceBrowser.cpp @@ -48,7 +48,7 @@ void SequenceBrowser::setViewportCenter(float x) } } -void SequenceBrowser::setZoom(int new_zoom) +void SequenceBrowser::setZoom(double new_zoom) { if (new_zoom != GlSeqBrowser::zoom()) { GlSeqBrowser::setZoom(new_zoom); diff --git a/qui/seqbrowser/SequenceBrowser.hpp b/qui/seqbrowser/SequenceBrowser.hpp index ac12e26..85910bc 100644 --- a/qui/seqbrowser/SequenceBrowser.hpp +++ b/qui/seqbrowser/SequenceBrowser.hpp @@ -36,7 +36,7 @@ public slots: //! set the center of the current viewport void setViewportCenter(float x); //! set our magnification level - void setZoom(int); + void setZoom(double); signals: //! emited when someone adds to our list of tracks diff --git a/qui/seqbrowser/SequenceBrowserWidget.cpp b/qui/seqbrowser/SequenceBrowserWidget.cpp index 39da328..fc21e98 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.cpp +++ b/qui/seqbrowser/SequenceBrowserWidget.cpp @@ -138,24 +138,26 @@ void SequenceBrowserWidget::promptSaveBrowserPixmap() cout << "Result: " << result << "\n"; } -int SequenceBrowserWidget::zoom() +double SequenceBrowserWidget::zoom() { return scrollable_browser.browser().zoom(); } -void SequenceBrowserWidget::zoomOut() +double SequenceBrowserWidget::zoomOut() { - scrollable_browser.browser().zoomOut(); + double zoom_level = scrollable_browser.browser().zoomOut(); scrollable_browser.updateScrollBar(); + return zoom_level; } -void SequenceBrowserWidget::zoomToSequence() +double SequenceBrowserWidget::zoomToSequence() { - scrollable_browser.browser().zoomToSequence(); + double zoom_level = scrollable_browser.browser().zoomToSequence(); scrollable_browser.updateScrollBar(); + return zoom_level; } -void SequenceBrowserWidget::setZoom(int z) +void SequenceBrowserWidget::setZoom(double z) { scrollable_browser.browser().setZoom(z); } diff --git a/qui/seqbrowser/SequenceBrowserWidget.hpp b/qui/seqbrowser/SequenceBrowserWidget.hpp index 71dc6f1..306e3f8 100644 --- a/qui/seqbrowser/SequenceBrowserWidget.hpp +++ b/qui/seqbrowser/SequenceBrowserWidget.hpp @@ -19,7 +19,7 @@ public: SequenceBrowserWidget(QWidget *parent=0); //! return current zoom size - int zoom(); + double zoom(); //! reset all of our stored data back to the empty state void clear(); @@ -44,11 +44,11 @@ public: public slots: //! set the zoom level of our browser - void setZoom(int); + void setZoom(double); //! zoom to fit the whole scene on the screen - void zoomOut(); + double zoomOut(); //! zoom to sequence - void zoomToSequence(); + double zoomToSequence(); void updatePosition(); //! ask the user where to save an image of the current browser view