ui/qt/entry.cpp

changeset 110
c00e968d018b
parent 108
77254bd6dccb
child 112
c3f2f16fa4b8
equal deleted inserted replaced
109:c3dfcb8f0be7 110:c00e968d018b
34 #include <QDoubleSpinBox> 34 #include <QDoubleSpinBox>
35 #include <QSpinBox> 35 #include <QSpinBox>
36 36
37 37
38 38
39 UIWIDGET ui_spinner_create(UiObject *obj, UiSpinnerArgs *args) { 39 UIWIDGET ui_spinbox_create(UiObject *obj, UiSpinBoxArgs *args) {
40 UiContainerPrivate *ctn = ui_obj_container(obj); 40 UiContainerPrivate *ctn = ui_obj_container(obj);
41 UI_APPLY_LAYOUT(ctn->layout, args); 41 UI_APPLY_LAYOUT(ctn->layout, args);
42 42
43 double min = args->min;
44 double max = args->max != 0 ? args->max : 100000;
45
43 bool use_double = false; 46 bool use_double = false;
44 UiVar *var = NULL; 47 UiVar *var = NULL;
48 UiVarType vartype = UI_VAR_SPECIAL;
45 if(args->varname) { 49 if(args->varname) {
46 var = uic_get_var(obj->ctx, args->varname); 50 var = uic_get_var(obj->ctx, args->varname);
51 vartype = var->type;
47 if(var->type == UI_VAR_DOUBLE) { 52 if(var->type == UI_VAR_DOUBLE) {
48 use_double = true; 53 use_double = true;
49 } else if(var->type == UI_VAR_RANGE) { 54 } else if(var->type == UI_VAR_RANGE) {
50 use_double = true; 55 use_double = true;
51 } else if(var->type != UI_VAR_INTEGER) { 56 } else if(var->type != UI_VAR_INTEGER) {
55 } 60 }
56 61
57 if(!var) { 62 if(!var) {
58 if(args->intvalue) { 63 if(args->intvalue) {
59 var = uic_widget_var(obj->ctx, obj->ctx, args->intvalue, NULL, UI_VAR_INTEGER); 64 var = uic_widget_var(obj->ctx, obj->ctx, args->intvalue, NULL, UI_VAR_INTEGER);
65 vartype = UI_VAR_INTEGER;
60 } else if(args->doublevalue) { 66 } else if(args->doublevalue) {
61 var = uic_widget_var(obj->ctx, obj->ctx, args->doublevalue, NULL, UI_VAR_DOUBLE); 67 var = uic_widget_var(obj->ctx, obj->ctx, args->doublevalue, NULL, UI_VAR_DOUBLE);
68 vartype = UI_VAR_DOUBLE;
62 use_double = true; 69 use_double = true;
63 } else if(args->rangevalue) { 70 } else if(args->rangevalue) {
64 var = uic_widget_var(obj->ctx, obj->ctx, args->rangevalue, NULL, UI_VAR_RANGE); 71 var = uic_widget_var(obj->ctx, obj->ctx, args->rangevalue, NULL, UI_VAR_RANGE);
72 vartype = UI_VAR_RANGE;
65 use_double = true; 73 use_double = true;
66 } else { 74 } else {
67 if(args->digits > 0) { 75 if(args->digits > 0) {
68 use_double = true; 76 use_double = true;
69 } 77 }
70 } 78 }
79 }
80
81 if(vartype == UI_VAR_RANGE) {
82 UiRange *r = (UiRange*)var->value;
83 min = r->min;
84 max = r->max;
71 } 85 }
72 86
73 QAbstractSpinBox *widget = nullptr; 87 QAbstractSpinBox *widget = nullptr;
74 if(use_double) { 88 if(use_double) {
75 QDoubleSpinBox *spinbox = new QDoubleSpinBox(); 89 QDoubleSpinBox *spinbox = new QDoubleSpinBox();
76 spinbox->setDecimals(args->digits); 90 spinbox->setDecimals(args->digits);
77 if(args->step != 0) { 91 if(args->step != 0) {
78 spinbox->setSingleStep(args->step); 92 spinbox->setSingleStep(args->step);
79 } 93 }
94 spinbox->setMinimum(min);
95 spinbox->setMaximum(max);
80 widget = spinbox; 96 widget = spinbox;
81 } else { 97 } else {
82 QSpinBox *spinbox = new QSpinBox(); 98 QSpinBox *spinbox = new QSpinBox();
83 if(args->step != 0) { 99 if(args->step != 0) {
84 spinbox->setSingleStep(args->step); 100 spinbox->setSingleStep(args->step);
85 } 101 }
102 spinbox->setMinimum((int)min);
103 spinbox->setMaximum((int)max);
86 widget = spinbox; 104 widget = spinbox;
87 } 105 }
88 106
89 if(var) { 107 if(var) {
90 if(var->type == UI_VAR_INTEGER) { 108 if(vartype == UI_VAR_INTEGER) {
91 UiInteger *value = (UiInteger*)var->value; 109 UiInteger *value = (UiInteger*)var->value;
92 value->obj = widget; 110 value->obj = widget;
93 if(value->value != 0) { 111 if(value->value != 0) {
94 QSpinBox *spinbox = (QSpinBox*)widget; 112 QSpinBox *spinbox = (QSpinBox*)widget;
95 spinbox->setValue(value->value); 113 spinbox->setValue(value->value);
96 } 114 }
97 value->get = ui_spinbox_int_get; 115 value->get = ui_spinbox_int_get;
98 value->set = ui_spinbox_int_set; 116 value->set = ui_spinbox_int_set;
99 } else if(var->type == UI_VAR_DOUBLE) { 117 } else if(vartype == UI_VAR_DOUBLE) {
100 UiDouble *value = (UiDouble*)var->value; 118 UiDouble *value = (UiDouble*)var->value;
101 value->obj = widget; 119 value->obj = widget;
102 if(value->value != 0) { 120 if(value->value != 0) {
103 QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget; 121 QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget;
104 spinbox->setValue(value->value); 122 spinbox->setValue(value->value);
105 } 123 }
106 value->get = ui_spinbox_double_get; 124 value->get = ui_spinbox_double_get;
107 value->set = ui_spinbox_double_set; 125 value->set = ui_spinbox_double_set;
108 } else if(var->type == UI_VAR_RANGE) { 126 } else if(vartype == UI_VAR_RANGE) {
109 UiRange *value = (UiRange*)var->value; 127 UiRange *value = (UiRange*)var->value;
110 value->obj = widget; 128 value->obj = widget;
111 QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget; 129 QDoubleSpinBox *spinbox = (QDoubleSpinBox*)widget;
112 if(value->value != 0) { 130 if(value->value != 0) {
113 spinbox->setValue(value->value); 131 spinbox->setValue(value->value);

mercurial