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)
19 basepair_spinner->setWhatsThis("How many base pairs need to be conserved in the window size");
23 connect(basepair_spinner, SIGNAL(valueChanged(int)),
24 this, SLOT(setBasepairThreshold(int)));
26 basepair_spinner->setValue(min);
27 updatePercentThreshold();
29 layout->addWidget(new QLabel("Threshold"));
30 layout->addWidget(basepair_spinner);
31 layout->addWidget(window_size_label);
32 layout->addWidget(percent_label);
36 void ThresholdWidget::setupWidgets()
38 layout = new QHBoxLayout(this);
39 basepair_spinner = new QSpinBox(this);
40 window_size_label = new QLabel(this);
41 percent_label = new QLabel(this);
44 void ThresholdWidget::setRange(int min, int max)
46 basepair_spinner->setRange(min, max);
47 if (cur_bp_threshold < min || cur_bp_threshold > max)
49 cur_bp_threshold = min;
50 basepair_spinner->setValue(min);
55 window_size_label->setText("/"+num);
56 updatePercentThreshold();
59 bool ThresholdWidget::isReadOnly() const
61 return basepair_spinner->isReadOnly();
64 void ThresholdWidget::setReadOnly(bool read_only)
66 basepair_spinner->setReadOnly(read_only);
69 double ThresholdWidget::min_ratio() const
71 double ratio=((double)basepair_spinner->minimum()/
72 (double)basepair_spinner->maximum());
77 double ThresholdWidget::ratio() const
79 return ((float)threshold())/((float)basepair_spinner->maximum());
82 void ThresholdWidget::setBasepairThreshold(int threshold)
84 if (cur_bp_threshold!= threshold)
86 cur_bp_threshold = threshold;
87 cur_percent_threshold = (int)(roundl(ratio() * 100));
88 basepair_spinner->setValue(threshold);
89 updatePercentThreshold();
90 emit thresholdChanged(threshold);
94 void ThresholdWidget::updatePercentThreshold()
96 int min_percent = (int)fmaxl(0.0, roundl(ratio()*100));
98 label.setNum(min_percent);
100 percent_label->setText(label);
103 int ThresholdWidget::threshold() const
105 return cur_bp_threshold;
108 void ThresholdWidget::reset(int min, int max, int threshold)
111 cur_bp_threshold = threshold;
112 cur_percent_threshold = (int)(roundl(ratio() * 100));
114 basepair_spinner->setValue(threshold);
115 updatePercentThreshold();