ui/qt/text.cpp

changeset 108
77254bd6dccb
parent 103
6606616eca9f
child 112
c3f2f16fa4b8
equal deleted inserted replaced
107:b34bd1557c6c 108:77254bd6dccb
55 value->value.free = NULL; 55 value->value.free = NULL;
56 56
57 return document; 57 return document;
58 } 58 }
59 59
60 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs args) { 60 UIWIDGET ui_textarea_create(UiObject *obj, UiTextAreaArgs *args) {
61 UiContainerPrivate *ctn = ui_obj_container(obj); 61 UiContainerPrivate *ctn = ui_obj_container(obj);
62 UI_APPLY_LAYOUT(ctn->layout, args); 62 UI_APPLY_LAYOUT(ctn->layout, args);
63 63
64 QTextEdit *textarea = new QTextEdit(); 64 QTextEdit *textarea = new QTextEdit();
65 ctn->add(textarea, true); 65 ctn->add(textarea);
66 66
67 QTextDocument *document = nullptr; 67 QTextDocument *document = nullptr;
68 68
69 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_STRING); 69 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING);
70 if(var) { 70 if(var) {
71 UiText *value = (UiText*)var->value; 71 UiText *value = (UiText*)var->value;
72 72
73 document = get_or_create_doc(value); 73 document = get_or_create_doc(value);
74 74
199 QTextDocument *doc = (QTextDocument*)text->data1; 199 QTextDocument *doc = (QTextDocument*)text->data1;
200 return doc->characterCount(); 200 return doc->characterCount();
201 } 201 }
202 202
203 void ui_textarea_remove(UiText *text, int begin, int end) { 203 void ui_textarea_remove(UiText *text, int begin, int end) {
204 // TODO 204 QTextDocument *doc = (QTextDocument*)text->data1;
205 QTextCursor cursor(doc);
206 cursor.setPosition(begin);
207 cursor.setPosition(end, QTextCursor::KeepAnchor);
208 cursor.removeSelectedText();
205 } 209 }
206 210
207 /* ------------------------------ TextField ------------------------------ */ 211 /* ------------------------------ TextField ------------------------------ */
208 212
209 static UIWIDGET create_textfield(UiObject *obj, UiTextFieldArgs args, bool password, bool frameless) { 213 static UIWIDGET create_textfield(UiObject *obj, UiTextFieldArgs *args, bool password, bool frameless) {
210 UiContainerPrivate *ctn = ui_obj_container(obj); 214 UiContainerPrivate *ctn = ui_obj_container(obj);
211 UI_APPLY_LAYOUT(ctn->layout, args); 215 UI_APPLY_LAYOUT(ctn->layout, args);
212 216
213 QLineEdit *textfield = new QLineEdit(); 217 QLineEdit *textfield = new QLineEdit();
214 ctn->add(textfield, false); 218 ctn->add(textfield);
215 219
216 if(password) { 220 if(password) {
217 textfield->setEchoMode(QLineEdit::Password); 221 textfield->setEchoMode(QLineEdit::Password);
218 } 222 }
219 223
220 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args.value, args.varname, UI_VAR_STRING); 224 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, args->value, args->varname, UI_VAR_STRING);
221 if(var) { 225 if(var) {
222 UiString *value = (UiString*)var->value; 226 UiString *value = (UiString*)var->value;
223 if(value->value.ptr) { 227 if(value->value.ptr) {
224 QString str = QString::fromUtf8(value->value.ptr); 228 QString str = QString::fromUtf8(value->value.ptr);
225 textfield->setText(str); 229 textfield->setText(str);
235 } 239 }
236 240
237 return textfield; 241 return textfield;
238 } 242 }
239 243
240 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs args) { 244 UIWIDGET ui_textfield_create(UiObject *obj, UiTextFieldArgs *args) {
241 return create_textfield(obj, args, false, false); 245 return create_textfield(obj, args, false, false);
242 } 246 }
243 247
244 UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs args) { 248 UIWIDGET ui_frameless_textfield_create(UiObject* obj, UiTextFieldArgs *args) {
245 return create_textfield(obj, args, false, true); 249 return create_textfield(obj, args, false, true);
246 } 250 }
247 251
248 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs args) { 252 UIWIDGET ui_passwordfield_create(UiObject* obj, UiTextFieldArgs *args) {
249 return create_textfield(obj, args, true, false); 253 return create_textfield(obj, args, true, false);
250 } 254 }
251 255
252 char* ui_textfield_get(UiString *str) { 256 char* ui_textfield_get(UiString *str) {
253 QLineEdit *textfield = (QLineEdit*)str->obj; 257 QLineEdit *textfield = (QLineEdit*)str->obj;

mercurial