ui/qt/text.cpp

changeset 70
3d801e8dda3a
parent 66
8d490d97aab8
child 130
212b63dd61be
equal deleted inserted replaced
69:419c8c3209e8 70:3d801e8dda3a
35 UIWIDGET ui_textarea(UiObject *obj, UiText *value) { 35 UIWIDGET ui_textarea(UiObject *obj, UiText *value) {
36 QTextDocument *txtdoc = value && value->obj ? (QTextDocument*)value->obj : new QTextDocument(); 36 QTextDocument *txtdoc = value && value->obj ? (QTextDocument*)value->obj : new QTextDocument();
37 37
38 if(value) { 38 if(value) {
39 if(value->value && value->obj) { 39 if(value->value && value->obj) {
40 ui_textarea_set(value, value->value); 40 QString str = QString::fromUtf8(value->value);
41 txtdoc->setPlainText(str);
41 } 42 }
42 43
43 value->get = ui_textarea_get; 44 value->get = ui_textarea_get;
44 value->set = ui_textarea_set; 45 value->set = ui_textarea_set;
45 value->getsubstr = ui_textarea_getsubstr; 46 value->getsubstr = ui_textarea_getsubstr;
79 80
80 QTextDocument *doc = (QTextDocument*)text->obj; 81 QTextDocument *doc = (QTextDocument*)text->obj;
81 QString str = doc->toPlainText(); 82 QString str = doc->toPlainText();
82 QByteArray array = str.toLocal8Bit(); 83 QByteArray array = str.toLocal8Bit();
83 const char *cstr = array.constData(); 84 const char *cstr = array.constData();
85
86 if(text->value) {
87 free(text->value);
88 }
84 text->value = strdup(cstr); 89 text->value = strdup(cstr);
85 return text->value; 90 return text->value;
86 } 91 }
87 92
88 void ui_textarea_set(UiText *text, char *str) { 93 void ui_textarea_set(UiText *text, char *str) {
121 } 126 }
122 127
123 void ui_textarea_remove(UiText *text, int begin, int end) { 128 void ui_textarea_remove(UiText *text, int begin, int end) {
124 QTextDocument *doc = (QTextDocument*)text->obj; 129 QTextDocument *doc = (QTextDocument*)text->obj;
125 } 130 }
131
132
133 /* ------------------- TextField ------------------- */
134
135 UIWIDGET ui_textfield(UiObject *obj, UiString *value) {
136 QLineEdit *textfield = new QLineEdit();
137
138 UiContainer *ct = uic_get_current_container(obj);
139 ct->add(textfield, false);
140
141 if(value) {
142 if(value->value) {
143 QString str = QString::fromUtf8(value->value);
144 textfield->setText(str);
145 free(value->value);
146 value->value = NULL;
147 }
148 value->set = ui_textfield_set;
149 value->get = ui_textfield_get;
150 value->obj = textfield;
151 }
152
153 return textfield;
154 }
155
156 UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) {
157 UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING);
158 if(var) {
159 UiString *value = (UiString*)var->value;
160 return ui_textfield(obj, value);
161 } else {
162 // TODO: error
163 }
164 return NULL;
165 }
166
167 char* ui_textfield_get(UiString *str) {
168 QLineEdit *textfield = (QLineEdit*)str->obj;
169 QString qstr = textfield->text();
170
171 if(str->value) {
172 free(str->value);
173 }
174 QByteArray array = qstr.toLocal8Bit();
175 const char *cstr = array.constData();
176 str->value = strdup(cstr);
177
178 return str->value;
179 }
180
181 void ui_textfield_set(UiString *str, char *value) {
182 QLineEdit *textfield = (QLineEdit*)str->obj;
183 QString qstr = QString::fromUtf8(value);
184 textfield->setText(qstr);
185
186 if(str->value) {
187 free(str->value);
188 }
189 str->value = NULL;
190 }

mercurial