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)));
20 connect(&percent_spinner, SIGNAL(valueChanged(int)),
21 this, SLOT(setPercentThreshold(int)));
23 basepair_spinner.setValue(min);
25 QHBoxLayout *layout = new QHBoxLayout;
26 layout->addWidget(&basepair_spinner);
27 layout->addWidget(&window_size_label);
28 layout->addWidget(&percent_spinner);
29 layout->addWidget(new QLabel("%"));
33 void ThresholdWidget::setRange(int min, int max)
35 basepair_spinner.setRange(min, max);
36 cur_bp_threshold = min;
37 basepair_spinner.setValue(min);
41 window_size_label.setText("/"+num);
42 int min_percent =(int)fmaxl(0.0, roundl(min_ratio()*100));
43 cur_percent_threshold = min_percent;
44 percent_spinner.setRange( min_percent, 100);
45 if (min_percent != 0.0) {
46 percent_spinner.setSingleStep((int)(roundl(1.0/(double)(max)*100.0)));
48 percent_spinner.setValue(min_percent);
51 double ThresholdWidget::min_ratio() const
53 double ratio=((double)basepair_spinner.minimum()/
54 (double)basepair_spinner.maximum());
59 double ThresholdWidget::ratio() const
61 return ((float)threshold())/((float)basepair_spinner.maximum());
64 void ThresholdWidget::setBasepairThreshold(int threshold)
66 if (cur_bp_threshold!= threshold)
68 cur_bp_threshold = threshold;
69 cur_percent_threshold = (int)(roundl(ratio() * 100));
70 basepair_spinner.setValue(threshold);
71 percent_spinner.setValue(cur_percent_threshold);
72 emit thresholdChanged(threshold);
76 void ThresholdWidget::setPercentThreshold(int percent_threshold)
78 if (cur_percent_threshold != percent_threshold)
80 cur_percent_threshold = percent_threshold;
81 long t=roundl(basepair_spinner.maximum()*((float)percent_threshold/100.0));
82 cur_bp_threshold = (int)t;
83 percent_spinner.setValue(percent_threshold);
84 basepair_spinner.setValue(cur_bp_threshold);
85 emit thresholdChanged(cur_bp_threshold);
89 int ThresholdWidget::threshold() const
91 return cur_bp_threshold;