Load saved muway and set to muways soft threshold.
[mussa.git] / qui / ThresholdWidget.cpp
index a97f502938912e60e76228f4a5ecb034d45e9d6c..20fdbebaac9bf02bfc9fced140b1b87002b852d7 100644 (file)
-#include <QHBoxLayout>
-#include <QLCDNumber>
 #include <QSlider>
+#include <QString>
 
 #include "qui/ThresholdWidget.hpp"
+#include <iostream>
+#include <math.h>
 
 // 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.setRange(min, max);
+  setupWidgets();
+  basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
 
-  connect(&basepair_spinner, SIGNAL(valueChanged(int)), 
-          this, SIGNAL(thresholdChanged(int)));
+  setRange(min, max);
 
-  basepair_spinner.setValue(min);
+  connect(basepair_spinner, SIGNAL(valueChanged(int)), 
+          this, SLOT(setBasepairThreshold(int)));
 
-  QHBoxLayout *layout = new QHBoxLayout;
-  layout->addWidget(&basepair_spinner);
+  basepair_spinner->setValue(min);
+  updatePercentThreshold();
+
+  layout->addWidget(new QLabel("Threshold"));
+  layout->addWidget(basepair_spinner);
+  layout->addWidget(window_size_label);
+  layout->addWidget(percent_label);
   setLayout(layout);
 }
-/*
-void ThresholdWidget::setMinimumThreshold(int min)
+
+void ThresholdWidget::setupWidgets()
 {
-  basepair_spinner->setMinimum(min);
+  layout = new QHBoxLayout(this);
+  basepair_spinner = new QSpinBox(this);
+  window_size_label = new QLabel(this);
+  percent_label = new QLabel(this);
 }
-
-int ThresholdWidget::getMinimumThreshold()
+  
+void ThresholdWidget::setRange(int min, int max)
 {
-  return basepair_spinner->minimum();
+  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);
+  updatePercentThreshold();
 }
 
-void ThresholdWidget::setMaximumThreshold(int max)
+bool ThresholdWidget::isReadOnly() const
 {
-  basepair_spinner->setMaximum(max);
+  return basepair_spinner->isReadOnly();
 }
 
-int ThresholdWidget::getMaximumThreshold()
+void ThresholdWidget::setReadOnly(bool read_only)
 {
-  return basepair_spinner->maximum();
+  basepair_spinner->setReadOnly(read_only);
 }
-*/
-void ThresholdWidget::setRange(int min, int max)
+
+double ThresholdWidget::min_ratio() const
 {
-  basepair_spinner.setRange(min, max);
+  double ratio=((double)basepair_spinner->minimum()/
+                (double)basepair_spinner->maximum());
+
+  return ratio;
 }
 
-float ThresholdWidget::percent() const
+double ThresholdWidget::ratio() const
 {
-  return ((float)threshold())/((float)basepair_spinner.maximum()); 
+  return ((float)threshold())/((float)basepair_spinner->maximum()); 
 }
 
-void ThresholdWidget::setThreshold(int threshold)
+void ThresholdWidget::setBasepairThreshold(int threshold)
 {
 if (basepair_spinner.value() != threshold)
if (cur_bp_threshold!= threshold)
   {
-    basepair_spinner.setValue(threshold);
+    cur_bp_threshold = threshold;
+    cur_percent_threshold = (int)(roundl(ratio() * 100));
+    basepair_spinner->setValue(threshold);
+    updatePercentThreshold();
     emit thresholdChanged(threshold);
   }
 }
 
-int ThresholdWidget::threshold() const
+void ThresholdWidget::updatePercentThreshold()
 {
-  return basepair_spinner.value();
+  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();
+  
+}