31 |
31 |
32 #include "../common/context.h" |
32 #include "../common/context.h" |
33 #include "../common/document.h" |
33 #include "../common/document.h" |
34 |
34 |
35 |
35 |
|
36 |
|
37 |
|
38 /* ------------------------------ TextField ------------------------------ */ |
|
39 |
|
40 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { |
|
41 UiContainerPrivate *ctn = ui_obj_container(obj); |
|
42 UI_APPLY_LAYOUT(ctn->layout, args); |
|
43 |
|
44 QLineEdit *textfield = new QLineEdit(); |
|
45 ctn->add(textfield, false); |
|
46 |
|
47 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_STRING); |
|
48 if(var) { |
|
49 UiString *value = (UiString*)var->value; |
|
50 if(value->value.ptr) { |
|
51 QString str = QString::fromUtf8(value->value.ptr); |
|
52 textfield->setText(str); |
|
53 if(value->value.free) { |
|
54 value->value.free(value->value.ptr); |
|
55 } |
|
56 value->value.ptr = NULL; |
|
57 } |
|
58 |
|
59 value->set = ui_textfield_set; |
|
60 value->get = ui_textfield_get; |
|
61 value->obj = textfield; |
|
62 } |
|
63 |
|
64 return textfield; |
|
65 } |
|
66 |
|
67 char* ui_textfield_get(UiString *str) { |
|
68 QLineEdit *textfield = (QLineEdit*)str->obj; |
|
69 QString qstr = textfield->text(); |
|
70 |
|
71 if(str->value.free) { |
|
72 str->value.free(str->value.ptr); |
|
73 } |
|
74 QByteArray array = qstr.toUtf8(); |
|
75 const char *cstr = array.constData(); |
|
76 str->value.ptr = strdup(cstr); |
|
77 str->value.free = free; |
|
78 |
|
79 return str->value.ptr; |
|
80 } |
|
81 |
|
82 void ui_textfield_set(UiString *str, const char *value) { |
|
83 QLineEdit *textfield = (QLineEdit*)str->obj; |
|
84 QString qstr = QString::fromUtf8(value); |
|
85 textfield->setText(qstr); |
|
86 |
|
87 if(str->value.free) { |
|
88 str->value.free(str->value.ptr); |
|
89 } |
|
90 str->value.ptr = NULL; |
|
91 } |