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)
18 basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
22 connect(basepair_spinner, SIGNAL(valueChanged(int)),
23 this, SLOT(setBasepairThreshold(int)));
25 basepair_spinner->setValue(min);
26 updatePercentThreshold();
28 layout->addWidget(new QLabel("Threshold"));
29 layout->addWidget(basepair_spinner);
30 layout->addWidget(window_size_label);
31 layout->addWidget(percent_label);
35 void ThresholdWidget::setupWidgets()
37 layout = new QHBoxLayout(this);
38 basepair_spinner = new QSpinBox(this);
39 window_size_label = new QLabel(this);
40 percent_label = new QLabel(this);
43 void ThresholdWidget::setRange(int min, int max)
45 basepair_spinner->setRange(min, max);
46 cur_bp_threshold = min;
47 basepair_spinner->setValue(min);
51 window_size_label->setText("/"+num);
52 updatePercentThreshold();
55 bool ThresholdWidget::isReadOnly() const
57 return basepair_spinner->isReadOnly();
60 void ThresholdWidget::setReadOnly(bool read_only)
62 basepair_spinner->setReadOnly(read_only);
65 double ThresholdWidget::min_ratio() const
67 double ratio=((double)basepair_spinner->minimum()/
68 (double)basepair_spinner->maximum());
73 double ThresholdWidget::ratio() const
75 return ((float)threshold())/((float)basepair_spinner->maximum());
78 void ThresholdWidget::setBasepairThreshold(int threshold)
80 if (cur_bp_threshold!= threshold)
82 cur_bp_threshold = threshold;
83 cur_percent_threshold = (int)(roundl(ratio() * 100));
84 basepair_spinner->setValue(threshold);
85 updatePercentThreshold();
86 emit thresholdChanged(threshold);
90 void ThresholdWidget::updatePercentThreshold()
92 int min_percent = (int)fmaxl(0.0, roundl(ratio()*100));
94 label.setNum(min_percent);
96 percent_label->setText(label);
99 int ThresholdWidget::threshold() const
101 return cur_bp_threshold;