5 #include "qui/ThresholdWidget.hpp"
9 // This is completely and totally derived from the Qt example
11 ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max)
14 basepair_spinner.setWhatsThis("How many base pairs need to be conserved in the window size");
18 connect(&basepair_spinner, SIGNAL(valueChanged(int)),
19 this, SLOT(setBasepairThreshold(int)));
21 basepair_spinner.setValue(min);
22 updatePercentThreshold();
24 QHBoxLayout *layout = new QHBoxLayout;
25 layout->addWidget(new QLabel("Threshold"));
26 layout->addWidget(&basepair_spinner);
27 layout->addWidget(&window_size_label);
28 layout->addWidget(&percent_label);
32 void ThresholdWidget::setRange(int min, int max)
34 basepair_spinner.setRange(min, max);
35 cur_bp_threshold = min;
36 basepair_spinner.setValue(min);
40 window_size_label.setText("/"+num);
41 updatePercentThreshold();
44 double ThresholdWidget::min_ratio() const
46 double ratio=((double)basepair_spinner.minimum()/
47 (double)basepair_spinner.maximum());
52 double ThresholdWidget::ratio() const
54 return ((float)threshold())/((float)basepair_spinner.maximum());
57 void ThresholdWidget::setBasepairThreshold(int threshold)
59 if (cur_bp_threshold!= threshold)
61 cur_bp_threshold = threshold;
62 cur_percent_threshold = (int)(roundl(ratio() * 100));
63 basepair_spinner.setValue(threshold);
64 updatePercentThreshold();
65 emit thresholdChanged(threshold);
69 void ThresholdWidget::updatePercentThreshold()
71 int min_percent = (int)fmaxl(0.0, roundl(ratio()*100));
73 label.setNum(min_percent);
75 percent_label.setText(label);
78 int ThresholdWidget::threshold() const
80 return cur_bp_threshold;