add support for range values in ui_spinner_create (QT)

13 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 10 Apr 2025 21:18:14 +0200 (13 days ago)
changeset 561
5798e3a28c59
parent 560
9e302b8a6c37
child 562
88ed463e5433
child 563
6fc93c3b91c9

add support for range values in ui_spinner_create (QT)

ui/qt/entry.cpp file | annotate | diff | comparison | revisions
ui/qt/entry.h file | annotate | diff | comparison | revisions
--- a/ui/qt/entry.cpp	Wed Apr 09 21:17:26 2025 +0200
+++ b/ui/qt/entry.cpp	Thu Apr 10 21:18:14 2025 +0200
@@ -108,7 +108,20 @@
         } else if(var->type == UI_VAR_RANGE) {
             UiRange *value = (UiRange*)var->value;
             value->obj = widget;
-            // TODO
+            QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget;
+            if(value->value != 0) {
+                spinbox->setValue(value->value);
+            }
+            if(value->min != value->max) {
+                spinbox->setRange(value->min, value->max);
+            }
+            if(value->extent != 0) {
+                spinbox->setSingleStep(value->extent);
+            }
+            value->get = ui_spinbox_range_get;
+            value->set = ui_spinbox_range_set;
+            value->setrange = ui_spinbox_range_setrange;
+            value->setextent = ui_spinbox_range_setextent;
         }
     }
     
@@ -140,3 +153,28 @@
     spinbox->setValue(value);
     d->value = spinbox->value();
 }
+
+double ui_spinbox_range_get(UiRange *range) {
+    QDoubleSpinBox *spinbox = (QDoubleSpinBox*)range->obj;
+    range->value = spinbox->value();
+    return range->value;
+}
+
+void ui_spinbox_range_set(UiRange *range, double value) {
+    QDoubleSpinBox *spinbox = (QDoubleSpinBox*)range->obj;
+    spinbox->setValue(value);
+    range->value = spinbox->value();
+}
+
+void ui_spinbox_range_setrange(UiRange *range, double min, double max) {
+    QDoubleSpinBox *spinbox = (QDoubleSpinBox*)range->obj;
+    spinbox->setRange(min, max);
+    range->min = min;
+    range->max = max;
+}
+
+void ui_spinbox_range_setextent(UiRange *range, double extent) {
+    QDoubleSpinBox *spinbox = (QDoubleSpinBox*)range->obj;
+    spinbox->setSingleStep(extent);
+    range->extent = extent;
+}
--- a/ui/qt/entry.h	Wed Apr 09 21:17:26 2025 +0200
+++ b/ui/qt/entry.h	Thu Apr 10 21:18:14 2025 +0200
@@ -42,6 +42,10 @@
 double ui_spinbox_double_get(UiDouble *d);
 void ui_spinbox_double_set(UiDouble *d, double value);
 
+double ui_spinbox_range_get(UiRange *range);
+void ui_spinbox_range_set(UiRange *range, double value);
+void ui_spinbox_range_setrange(UiRange *range, double min, double max);
+void ui_spinbox_range_setextent(UiRange *range, double extent);
 
 #ifdef __cplusplus
 }

mercurial