C4ConsoleQtLocalizeStringDlg::C4ConsoleQtLocalizeStringDlg(class QMainWindow *parent_window, const C4Value &translations) : QDialog(parent_window, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint) , translations(translations) { ui.setupUi(this); // Add language editors int32_t lang_index = 0; C4LanguageInfo *lang_info; while (lang_info = ::Languages.GetInfo(lang_index++)) { AddEditor(lang_info->Code, lang_info->Name); } // Fill in values C4PropList *translations_proplist = translations.getPropList(); assert(translations_proplist); for (C4String *lang_str : translations_proplist->GetSortedLocalProperties(false)) { if (lang_str->GetData().getLength() == 2) { C4Value text_val; if (translations_proplist->GetPropertyByS(lang_str, &text_val)) { C4String *text = text_val.getStr(); if (text) { QLineEdit *editor = GetEditorByLanguage(lang_str->GetCStr()); if (!editor) { // Unknown language. Just add an editor without language name. editor = AddEditor(lang_str->GetCStr(), nullptr); } editor->setText(QString(text->GetCStr())); } } } } // Size adjustSize(); setMinimumSize(size()); // Focus on first empty editor if (edited_languages.size()) { edited_languages.front().value_editor->setFocus(); // fallback to first editor for (const auto & langs : edited_languages) { if (!langs.value_editor->text().length()) { langs.value_editor->setFocus(); break; } } } }
void C4ConsoleQtLocalizeStringDlg::AddLanguagePressed() { bool lang_ok = false; QRegExpValidator validator(QRegExp("^[a-zA-Z][a-zA-Z]$"), this); QString lang_id; while (!lang_ok) { bool ok; int q = 0; lang_id = QInputDialog::getText(this, LoadResStr("IDS_CNS_ADDLANGUAGE"), LoadResStr("IDS_CNS_ADDLANGUAGEID"), QLineEdit::Normal, QString(), &ok); if (!ok) return; lang_ok = (validator.validate(lang_id, q) == QValidator::Acceptable); if (!lang_ok) { DoError(LoadResStr("IDS_ERR_INVALIDLANGUAGEID")); } } // Either add or just focus existing editor QLineEdit *editor = GetEditorByLanguage(lang_id.toUtf8()); if (!editor) { editor = AddEditor(lang_id.toUtf8(), nullptr); adjustSize(); setMinimumSize(size()); } editor->setFocus(); }
void World::NewEditor() { GLEditor * pNewBuffer = new GLEditor(); //pNewBuffer->SetText("-- scratch pad!!"); AddEditor(pNewBuffer); }