summaryrefslogtreecommitdiff
path: root/widgets/HintedSpinBox.hpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2018-12-19 22:58:32 +0100
committerChristoph Berg <myon@debian.org>2018-12-19 22:58:32 +0100
commite0737c56c1e384e05064a0c6e1ac46979371041b (patch)
treea0123d694a2d36c43dabdf0a3907392fce11d457 /widgets/HintedSpinBox.hpp
parentb4aebf2d137b892f53503b13785ecae900062ff7 (diff)
New upstream version 2.0.0+repackupstream/2.0.0+repack
Diffstat (limited to 'widgets/HintedSpinBox.hpp')
-rw-r--r--widgets/HintedSpinBox.hpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/widgets/HintedSpinBox.hpp b/widgets/HintedSpinBox.hpp
new file mode 100644
index 00000000..8498b29e
--- /dev/null
+++ b/widgets/HintedSpinBox.hpp
@@ -0,0 +1,53 @@
+#ifndef HINTED_SPIN_BOX_HPP_
+#define HINTED_SPIN_BOX_HPP_
+
+#include <vector>
+
+#include <QSpinBox>
+
+//
+// HintedSpinBox - QSpinBox refinement with an optional sequence of
+// discrete hints
+//
+// The hint sequence values are used as step values and can
+// optionally define the minimum and maximum value. Intermediate
+// values are allowed but the step up/down arrows and accelerator
+// keys will only use the hints.
+//
+// Ensure that the default minimum and maximum values are sufficient
+// to allow initial initialization if done before the hints are set.
+//
+class HintedSpinBox
+ : public QSpinBox
+{
+public:
+ typedef std::vector<int> values_type;
+
+ HintedSpinBox (QWidget * parent = nullptr)
+ : QSpinBox {parent}
+ {
+ }
+
+ // Initialize sequence of values allowed.
+ //
+ // This spin box behaves exactly as a standard QSpinBox if the
+ // sequence of values is empty.
+ //
+ // The minimum and maximum are automatically set to the lowest and
+ // highest value provided if required.
+ //
+ // Returns the previous sequence.
+ values_type values (values_type values, bool set_min_max = true);
+
+ // Read access to the values.
+ values_type const& values () const {return values_;}
+
+protected:
+ // override the QSpinBox stepping
+ void stepBy (int steps) override;
+
+private:
+ values_type values_;
+};
+
+#endif