diff options
| author | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
|---|---|---|
| committer | hibby <d@vehibberd.com> | 2018-02-16 15:18:44 +0000 |
| commit | 368f5331a7641772aa7e0cd1feea57d09a394a36 (patch) | |
| tree | b421ac60cc6eb726896ea268ea24e47fc4ce7c88 /HintedSpinBox.cpp | |
| parent | 71c717edc92fa771c857b3c2e5ed65f523f68f90 (diff) | |
| parent | 37f727ac0746fd85504aa46c1f023c09b3eff33a (diff) | |
Update upstream source from tag 'upstream/1.8.0+repack'
Update to upstream version '1.8.0+repack'
with Debian dir a83ef78cb70a32d1211871fdc08f3ffa295e45a8
Diffstat (limited to 'HintedSpinBox.cpp')
| -rw-r--r-- | HintedSpinBox.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/HintedSpinBox.cpp b/HintedSpinBox.cpp new file mode 100644 index 00000000..25ffcc71 --- /dev/null +++ b/HintedSpinBox.cpp @@ -0,0 +1,55 @@ +#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 + } +} |
