ui/qt/text.cpp

changeset 70
3d801e8dda3a
parent 66
8d490d97aab8
child 130
212b63dd61be
--- a/ui/qt/text.cpp	Sat Jan 10 10:14:28 2015 +0100
+++ b/ui/qt/text.cpp	Sun Jan 11 15:29:38 2015 +0100
@@ -37,7 +37,8 @@
     
     if(value) {
         if(value->value && value->obj) {
-            ui_textarea_set(value, value->value);
+            QString str = QString::fromUtf8(value->value);
+            txtdoc->setPlainText(str);
         }
         
         value->get = ui_textarea_get;
@@ -81,6 +82,10 @@
     QString str = doc->toPlainText();
     QByteArray array = str.toLocal8Bit();
     const char *cstr = array.constData();
+    
+    if(text->value) {
+        free(text->value);
+    }
     text->value = strdup(cstr);
     return text->value;
 }
@@ -123,3 +128,63 @@
 void ui_textarea_remove(UiText *text, int begin, int end) {
     QTextDocument *doc = (QTextDocument*)text->obj;
 }
+
+
+/* ------------------- TextField ------------------- */
+
+UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
+    QLineEdit *textfield = new QLineEdit();
+    
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->add(textfield, false);
+    
+    if(value) {
+        if(value->value) {
+            QString str = QString::fromUtf8(value->value);
+            textfield->setText(str);
+            free(value->value);
+            value->value = NULL;
+        }
+        value->set = ui_textfield_set;
+        value->get = ui_textfield_get;
+        value->obj = textfield;
+    }
+    
+    return textfield;
+}
+
+UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
+    UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
+    if(var) {
+        UiString *value = (UiString*)var->value;
+        return ui_textfield(obj, value);
+    } else {
+        // TODO: error
+    }
+    return NULL;
+}
+
+char* ui_textfield_get(UiString *str) {
+    QLineEdit *textfield = (QLineEdit*)str->obj;
+    QString qstr = textfield->text();
+    
+    if(str->value) {
+        free(str->value);
+    }
+    QByteArray array = qstr.toLocal8Bit();
+    const char *cstr = array.constData();
+    str->value = strdup(cstr);
+    
+    return str->value;
+}
+
+void ui_textfield_set(UiString *str, char *value) {
+    QLineEdit *textfield = (QLineEdit*)str->obj;
+    QString qstr = QString::fromUtf8(value);
+    textfield->setText(qstr);
+    
+    if(str->value) {
+        free(str->value);
+    }
+    str->value = NULL;
+}

mercurial