#include <FormExample.h>
Public Member Functions | |
FormExample (WContainerWidget *parent=0) | |
Instantiate a new form example. | |
Private Member Functions | |
void | changeLanguage () |
Change the language. | |
void | setLanguage (const std::string lang) |
Private Attributes | |
std::vector< WText * > | languageSelects_ |
This class demonstrates, next instantiating the form itself, handling of different languages.
Definition at line 29 of file FormExample.h.
FormExample::FormExample | ( | WContainerWidget * | parent = 0 |
) |
Instantiate a new form example.
Definition at line 14 of file FormExample.C.
00015 : WContainerWidget(parent) 00016 { 00017 WContainerWidget *langLayout = new WContainerWidget(this); 00018 langLayout->setContentAlignment(AlignRight); 00019 new WText(tr("language"), langLayout); 00020 00021 const char *lang[] = { "en", "nl" }; 00022 00023 for (int i = 0; i < 2; ++i) { 00024 WText *t = new WText(widen(lang[i]), langLayout); 00025 t->setMargin(5); 00026 t->clicked().connect(SLOT(this, FormExample::changeLanguage)); 00027 00028 languageSelects_.push_back(t); 00029 } 00030 00031 /* 00032 * Start with the reported locale, if available 00033 */ 00034 setLanguage(wApp->locale()); 00035 00036 Form *form = new Form(this); 00037 form->setMargin(20); 00038 }
void FormExample::changeLanguage | ( | ) | [private] |
void FormExample::setLanguage | ( | const std::string | lang | ) | [private] |
Definition at line 40 of file FormExample.C.
00041 { 00042 bool haveLang = false; 00043 00044 for (unsigned i = 0; i < languageSelects_.size(); ++i) { 00045 WText *t = languageSelects_[i]; 00046 00047 // prefix match, e.g. en matches en-us. 00048 bool isLang = lang.find(narrow(t->text().value())) == 0; 00049 t->setStyleClass(isLang ? L"langcurrent" : L"lang"); 00050 00051 haveLang = haveLang || isLang; 00052 } 00053 00054 if (!haveLang) { 00055 languageSelects_[0]->setStyleClass(L"langcurrent"); 00056 WApplication::instance() 00057 ->setLocale(narrow(languageSelects_[0]->text().value())); 00058 } else 00059 WApplication::instance()->setLocale(lang); 00060 }
std::vector<WText *> FormExample::languageSelects_ [private] |
Definition at line 37 of file FormExample.h.