Thu, 28 Aug 2014 19:25:21 +0200
updated UiText implementation (Qt)
ui/qt/text.cpp | file | annotate | diff | comparison | revisions |
--- a/ui/qt/text.cpp Thu Aug 28 16:34:09 2014 +0200 +++ b/ui/qt/text.cpp Thu Aug 28 19:25:21 2014 +0200 @@ -33,13 +33,11 @@ #include "../common/document.h" UIWIDGET ui_textarea(UiObject *obj, UiText *value) { - UiContainer *ct = uic_get_current_container(obj); - QTextEdit *textedit = new QTextEdit(); - ct->add((textedit)); + QTextDocument *txtdoc = value && value->obj ? (QTextDocument*)value->obj : new QTextDocument(); if(value) { - if(value->value) { - // TODO: set text and free old value + if(value->value && value->obj) { + ui_textarea_set(value, value->value); } value->get = ui_textarea_get; @@ -50,10 +48,15 @@ value->selection = ui_textarea_selection; value->length = ui_textarea_length; value->remove = ui_textarea_remove; - value->obj = textedit->document(); + value->obj = txtdoc; value->value = NULL; } + UiContainer *ct = uic_get_current_container(obj); + QTextEdit *textedit = new QTextEdit(); + textedit->setDocument(txtdoc); + ct->add((textedit)); + return textedit; } @@ -83,14 +86,15 @@ } void ui_textarea_set(UiText *text, char *str) { + // set text + QTextDocument *doc = (QTextDocument*)text->obj; + QString qstr = QString::fromUtf8(str); + doc->setPlainText(qstr); + // cleanup if(text->value) { free(text->value); } text->value = NULL; - - QTextDocument *doc = (QTextDocument*)text->obj; - QString qstr = QString::fromUtf8(str); - doc->setPlainText(qstr); } char* ui_textarea_getsubstr(UiText *text, int begin, int end) {