#include <QHBoxLayout>
#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)
{
- basepair_spinner.setRange(min, max);
+ basepair_spinner.setWhatsThis("How many base pairs need to be conserved in the window size");
+
+ setRange(min, max);
connect(&basepair_spinner, SIGNAL(valueChanged(int)),
- this, SIGNAL(thresholdChanged(int)));
+ this, SLOT(setBasepairThreshold(int)));
+ connect(&percent_spinner, SIGNAL(valueChanged(int)),
+ this, SLOT(setPercentThreshold(int)));
basepair_spinner.setValue(min);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(&basepair_spinner);
+ layout->addWidget(&window_size_label);
+ layout->addWidget(&percent_spinner);
+ layout->addWidget(new QLabel("%"));
setLayout(layout);
}
-/*
-void ThresholdWidget::setMinimumThreshold(int min)
-{
- basepair_spinner->setMinimum(min);
-}
-int ThresholdWidget::getMinimumThreshold()
+void ThresholdWidget::setRange(int min, int max)
{
- return basepair_spinner->minimum();
-}
+ basepair_spinner.setRange(min, max);
+ cur_bp_threshold = min;
+ basepair_spinner.setValue(min);
-void ThresholdWidget::setMaximumThreshold(int max)
-{
- basepair_spinner->setMaximum(max);
+ 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);
}
-int ThresholdWidget::getMaximumThreshold()
-{
- return basepair_spinner->maximum();
-}
-*/
-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());
}
-void ThresholdWidget::setThreshold(int threshold)
+void ThresholdWidget::setBasepairThreshold(int threshold)
{
- if (basepair_spinner.value() != threshold)
+ if (cur_bp_threshold!= threshold)
{
+ cur_bp_threshold = threshold;
+ cur_percent_threshold = (int)(roundl(ratio() * 100));
basepair_spinner.setValue(threshold);
+ percent_spinner.setValue(cur_percent_threshold);
emit thresholdChanged(threshold);
}
}
-int ThresholdWidget::threshold() const
+void ThresholdWidget::setPercentThreshold(int percent_threshold)
{
- return basepair_spinner.value();
+ 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 ThresholdWidget::threshold() const
+{
+ return cur_bp_threshold;
+}
#ifndef _THRESHOLD_WIDGET_H_
#define _THRESHOLD_WIDGET_H_
+#include <QLabel>
#include <QSpinBox>
#include <QWidget>
Q_OBJECT
public:
- ThresholdWidget(QWidget *parent = 0, int min=21, int max=30);
+ ThresholdWidget(QWidget *parent = 0, int min=20, int max=30);
- //! return what percent of our maximum threshold we are.
- float percent() const;
+ //! return min_threshold/max_threshold
+ double min_ratio() const;
+ //! return current_threshold/maximum_threshold
+ double ratio() const;
//! return our current threshold
int threshold() const;
public slots:
- void setThreshold(int threshold);
+ void setBasepairThreshold(int threshold);
+ void setPercentThreshold(int percent_threshold);
+ //! set the min and max base pair range
void setRange(int min, int max);
signals:
+ //! the current number of base pairs needed for a window of conservation
void thresholdChanged(int new_threshold);
protected:
QSpinBox basepair_spinner;
+ QLabel window_size_label;
+ QSpinBox percent_spinner;
+ int cur_bp_threshold;
+ int cur_percent_threshold;
};
const int threshold_max_display_digits = 2;