4 #include "qui/ThresholdWidget.hpp"
8 // This is completely and totally derived from the Qt example
10 ThresholdWidget::ThresholdWidget(QWidget *parent, int min, int max)
12 layout(new QHBoxLayout(this)),
13 basepair_spinner(new QSpinBox(this)),
14 window_size_label(new QLabel(this)),
15 percent_label(new QLabel(this))
17 basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
21 connect(basepair_spinner, SIGNAL(valueChanged(int)),
22 this, SLOT(setBasepairThreshold(int)));
24 basepair_spinner->setValue(min);
25 updatePercentThreshold();
27 layout->addWidget(new QLabel("Threshold"));
28 layout->addWidget(basepair_spinner);
29 layout->addWidget(window_size_label);
30 layout->addWidget(percent_label);
34 void ThresholdWidget::setRange(int min, int max)
36 basepair_spinner->setRange(min, max);
37 cur_bp_threshold = min;
38 basepair_spinner->setValue(min);
42 window_size_label->setText("/"+num);
43 updatePercentThreshold();
46 bool ThresholdWidget::isReadOnly() const
48 return basepair_spinner->isReadOnly();
51 void ThresholdWidget::setReadOnly(bool read_only)
53 basepair_spinner->setReadOnly(read_only);
56 double ThresholdWidget::min_ratio() const
58 double ratio=((double)basepair_spinner->minimum()/
59 (double)basepair_spinner->maximum());
64 double ThresholdWidget::ratio() const
66 return ((float)threshold())/((float)basepair_spinner->maximum());
69 void ThresholdWidget::setBasepairThreshold(int threshold)
71 if (cur_bp_threshold!= threshold)
73 cur_bp_threshold = threshold;
74 cur_percent_threshold = (int)(roundl(ratio() * 100));
75 basepair_spinner->setValue(threshold);
76 updatePercentThreshold();
77 emit thresholdChanged(threshold);
81 void ThresholdWidget::updatePercentThreshold()
83 int min_percent = (int)fmaxl(0.0, roundl(ratio()*100));
85 label.setNum(min_percent);
87 percent_label->setText(label);
90 int ThresholdWidget::threshold() const
92 return cur_bp_threshold;