|
Wt examples
3.3.5
|
Main widget for the Form example. More...
#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_ |
Main widget for the Form example.
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.
: WContainerWidget(parent)
{
WContainerWidget *langLayout = new WContainerWidget(this);
langLayout->setContentAlignment(AlignRight);
new WText(tr("language"), langLayout);
const char *lang[] = { "en", "nl" };
for (int i = 0; i < 2; ++i) {
WText *t = new WText(widen(lang[i]), langLayout);
t->setMargin(5);
t->clicked().connect(this, &FormExample::changeLanguage);
languageSelects_.push_back(t);
}
/*
* Start with the reported locale, if available
*/
setLanguage(wApp->locale().name());
Form *form = new Form(this);
form->setMargin(20);
}
| void FormExample::changeLanguage | ( | ) | [private] |
Change the language.
Definition at line 62 of file FormExample.C.
{
WText *t = (WText *)sender();
setLanguage(narrow(t->text().value()));
}
| void FormExample::setLanguage | ( | const std::string | lang | ) | [private] |
Definition at line 40 of file FormExample.C.
{
bool haveLang = false;
for (unsigned i = 0; i < languageSelects_.size(); ++i) {
WText *t = languageSelects_[i];
// prefix match, e.g. en matches en-us.
bool isLang = lang.find(narrow(t->text().value())) == 0;
t->setStyleClass(isLang ? L"langcurrent" : L"lang");
haveLang = haveLang || isLang;
}
if (!haveLang) {
languageSelects_[0]->setStyleClass(L"langcurrent");
WApplication::instance()
->setLocale(narrow(languageSelects_[0]->text().value()));
} else
WApplication::instance()->setLocale(lang);
}
std::vector<WText *> FormExample::languageSelects_ [private] |
Definition at line 37 of file FormExample.h.
1.7.6.1