Load saved muway and set to muways soft threshold.
[mussa.git] / qui / ThresholdWidget.cpp
index 2779a208251dba075ba598875b11e23bcf6da505..20fdbebaac9bf02bfc9fced140b1b87002b852d7 100644 (file)
@@ -1,4 +1,3 @@
-#include <QHBoxLayout>
 #include <QSlider>
 #include <QString>
 
@@ -9,56 +8,75 @@
 // This is completely and totally derived from the Qt example
 // LCDRange.cpp
 ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max) 
-  : QWidget(parent)
+  : QWidget(parent),
+    layout(0),
+    cur_bp_threshold(0),
+    basepair_spinner(0),
+    window_size_label(0),
+    percent_label(0)
 {
-  basepair_spinner.setWhatsThis("How many base pairs need to be conserved in the window size");
+  setupWidgets();
+  basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
 
   setRange(min, max);
 
-  connect(&basepair_spinner, SIGNAL(valueChanged(int)), 
+  connect(basepair_spinner, SIGNAL(valueChanged(int)), 
           this, SLOT(setBasepairThreshold(int)));
-  connect(&percent_spinner, SIGNAL(valueChanged(int)),
-          this, SLOT(setPercentThreshold(int)));
 
-  basepair_spinner.setValue(min);
+  basepair_spinner->setValue(min);
+  updatePercentThreshold();
 
-  QHBoxLayout *layout = new QHBoxLayout;
-  layout->addWidget(&basepair_spinner);
-  layout->addWidget(&window_size_label);
-  layout->addWidget(&percent_spinner);
-  layout->addWidget(new QLabel("%"));
+  layout->addWidget(new QLabel("Threshold"));
+  layout->addWidget(basepair_spinner);
+  layout->addWidget(window_size_label);
+  layout->addWidget(percent_label);
   setLayout(layout);
 }
 
+void ThresholdWidget::setupWidgets()
+{
+  layout = new QHBoxLayout(this);
+  basepair_spinner = new QSpinBox(this);
+  window_size_label = new QLabel(this);
+  percent_label = new QLabel(this);
+}
+  
 void ThresholdWidget::setRange(int min, int max)
 {
-  basepair_spinner.setRange(min, max);
-  cur_bp_threshold = min;
-  basepair_spinner.setValue(min);
+  basepair_spinner->setRange(min, max);
+  if (cur_bp_threshold < min || cur_bp_threshold > max)
+  {
+    cur_bp_threshold = min;
+    basepair_spinner->setValue(min);
+  }
 
   QString num;
   num.setNum(max);
-  window_size_label.setText("/"+num);
-  int min_percent =(int)fmaxl(0.0, roundl(min_ratio()*100));
-  cur_percent_threshold = min_percent;
-  percent_spinner.setRange( min_percent, 100);
-  if (min_percent != 0.0) {
-    percent_spinner.setSingleStep((int)(roundl(1.0/(double)(max)*100.0)));
-  }
-  percent_spinner.setValue(min_percent);
+  window_size_label->setText("/"+num);
+  updatePercentThreshold();
+}
+
+bool ThresholdWidget::isReadOnly() const
+{
+  return basepair_spinner->isReadOnly();
+}
+
+void ThresholdWidget::setReadOnly(bool read_only)
+{
+  basepair_spinner->setReadOnly(read_only);
 }
 
 double ThresholdWidget::min_ratio() const
 {
-  double ratio=((double)basepair_spinner.minimum()/
-                (double)basepair_spinner.maximum());
+  double ratio=((double)basepair_spinner->minimum()/
+                (double)basepair_spinner->maximum());
 
   return ratio;
 }
 
 double ThresholdWidget::ratio() const
 {
-  return ((float)threshold())/((float)basepair_spinner.maximum()); 
+  return ((float)threshold())/((float)basepair_spinner->maximum()); 
 }
 
 void ThresholdWidget::setBasepairThreshold(int threshold)
@@ -67,26 +85,33 @@ void ThresholdWidget::setBasepairThreshold(int threshold)
   {
     cur_bp_threshold = threshold;
     cur_percent_threshold = (int)(roundl(ratio() * 100));
-    basepair_spinner.setValue(threshold);
-    percent_spinner.setValue(cur_percent_threshold);
+    basepair_spinner->setValue(threshold);
+    updatePercentThreshold();
     emit thresholdChanged(threshold);
   }
 }
 
-void ThresholdWidget::setPercentThreshold(int percent_threshold)
+void ThresholdWidget::updatePercentThreshold()
 {
-  if (cur_percent_threshold != percent_threshold)
-  {
-    cur_percent_threshold = percent_threshold;
-    long t=roundl(basepair_spinner.maximum()*((float)percent_threshold/100.0));
-    cur_bp_threshold = (int)t;
-    percent_spinner.setValue(percent_threshold);
-    basepair_spinner.setValue(cur_bp_threshold);
-    emit thresholdChanged(cur_bp_threshold);
-  }
+  int min_percent = (int)fmaxl(0.0, roundl(ratio()*100));
+  QString label;
+  label.setNum(min_percent);
+  label += "%";
+  percent_label->setText(label);
 }
 
 int ThresholdWidget::threshold() const
 {
   return cur_bp_threshold;
 }
+
+void ThresholdWidget::reset(int min, int max, int threshold)
+{
+  
+  cur_bp_threshold = threshold;
+  cur_percent_threshold = (int)(roundl(ratio() * 100));
+  setRange(min, max);
+  basepair_spinner->setValue(threshold);
+  updatePercentThreshold();
+  
+}