Wt examples  4.1.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
FormExample Class Reference

Main widget for the Form example. More...

#include <FormExample.h>

Inheritance diagram for FormExample:
Inheritance graph
[legend]

Public Member Functions

 FormExample ()
 Instantiate a new form example. More...
 

Private Member Functions

void changeLanguage (WText *t)
 Change the language. More...
 
void setLanguage (const std::string lang)
 

Private Attributes

std::vector< WText * > languageSelects_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FormExample()

FormExample::FormExample ( )

Instantiate a new form example.

Definition at line 14 of file FormExample.C.

15  : WContainerWidget()
16 {
17  WContainerWidget *langLayout = this->addWidget(cpp14::make_unique<WContainerWidget>());
18  langLayout->setContentAlignment(AlignmentFlag::Right);
19  langLayout->addWidget(cpp14::make_unique<WText>(tr("language")));
20 
21  const char *lang[] = { "en", "nl" };
22 
23  for (int i = 0; i < 2; ++i) {
24  WText *t = langLayout->addWidget(cpp14::make_unique<WText>(lang[i]));
25  t->setMargin(5);
26  t->clicked().connect(std::bind(&FormExample::changeLanguage, this, t));
27 
28  languageSelects_.push_back(t);
29  }
30 
31  /*
32  * Start with the reported locale, if available
33  */
34  setLanguage(wApp->locale().name());
35 
36  Form *form = this->addWidget(cpp14::make_unique<Form>());
37  form->setMargin(20);
38 }
A simple Form.
Definition: Form.h:35
std::vector< WText * > languageSelects_
Definition: FormExample.h:37
void setLanguage(const std::string lang)
Definition: FormExample.C:40
void changeLanguage(WText *t)
Change the language.
Definition: FormExample.C:62

Member Function Documentation

◆ changeLanguage()

void FormExample::changeLanguage ( WText *  t)
private

Change the language.

Definition at line 62 of file FormExample.C.

63 {
64  setLanguage(t->text().toUTF8());
65 }
void setLanguage(const std::string lang)
Definition: FormExample.C:40

◆ setLanguage()

void FormExample::setLanguage ( const std::string  lang)
private

Definition at line 40 of file FormExample.C.

41 {
42  bool haveLang = false;
43 
44  for (auto i : languageSelects_) {
45  WText *t = i;
46 
47  // prefix match, e.g. en matches en-us.
48  bool isLang = lang.find(t->text().toUTF8()) == 0;
49  t->setStyleClass(isLang ? "langcurrent" : "lang");
50 
51  haveLang = haveLang || isLang;
52  }
53 
54  if (!haveLang) {
55  languageSelects_[0]->setStyleClass("langcurrent");
56  WApplication::instance()
57  ->setLocale(languageSelects_[0]->text().toUTF8());
58  } else
59  WApplication::instance()->setLocale(lang);
60 }
std::vector< WText * > languageSelects_
Definition: FormExample.h:37

Member Data Documentation

◆ languageSelects_

std::vector<WText *> FormExample::languageSelects_
private

Definition at line 37 of file FormExample.h.


The documentation for this class was generated from the following files:

Generated on Mon Aug 19 2019 for the C++ Web Toolkit (Wt) by doxygen 1.8.15