mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-01 16:13:57 -04:00
095fa7740e
These were using a hijacked custom spin box that was designed only for letters i.e. submodes. Now there are two new custom spin boxes. HistedSpinBox:- can be set with a list of integer values which the step up and down will follow. Optionally limits the maximum and minimum value to the upper and lower bounds of the values set. Note that intermediate values are still valid. RestrictedSpinBox:- more like a combo box because the provided values are the only ones that can be set. HintedSpinBox is used for the frequency tolerance and RestrictedSpinBox is used for T/R period. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7698 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
#include "HintedSpinBox.hpp"
|
|
|
|
#include <algorithm>
|
|
|
|
auto HintedSpinBox::values (values_type values, bool set_min_max) -> values_type
|
|
{
|
|
// replace any prior values
|
|
std::swap (values, values_);
|
|
|
|
// sort values and make unique
|
|
std::sort (values_.begin (), values_.end ());
|
|
auto last = std::unique (values_.begin (), values_.end ());
|
|
values_.erase (last, values_.end ());
|
|
if (set_min_max)
|
|
{
|
|
setMinimum (values_.front ());
|
|
setMaximum (values_.back ());
|
|
}
|
|
return values; // return old values
|
|
}
|
|
|
|
void HintedSpinBox::stepBy (int steps)
|
|
{
|
|
if (values_.size ())
|
|
{
|
|
if (steps > 0)
|
|
{
|
|
auto p = std::upper_bound (values_.begin (), values_.end (), value ());
|
|
if (p != values_.end () && *p <= maximum ())
|
|
{
|
|
setValue (*p);
|
|
}
|
|
else if (wrapping ())
|
|
{
|
|
setValue (values_.front ());
|
|
}
|
|
}
|
|
else if (steps < 0)
|
|
{
|
|
auto p = std::lower_bound (values_.begin (), values_.end (), value ());
|
|
if (p != values_.begin () && *(p - 1) >= minimum ())
|
|
{
|
|
setValue (*(p - 1));
|
|
}
|
|
else if (wrapping ())
|
|
{
|
|
setValue (values_.back ());
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QSpinBox::stepBy (steps); // no values so revert to QSpinBox behaviour
|
|
}
|
|
}
|