WWidget *WtHome::examples() { WContainerWidget *result = new WContainerWidget(); WText *intro = new WText(tr("home.examples")); intro->setInternalPathEncoding(true); result->addWidget(intro); examplesMenu_ = new WTabWidget(result); WAnimation animation(WAnimation::SlideInFromRight, WAnimation::EaseIn); examplesMenu_->contentsStack()->setTransitionAnimation(animation, true); /* * The following code is functionally equivalent to: * * examplesMenu_->addTab(helloWorldExample(), "Hello world"); * * However, we optimize here for memory consumption (it is a homepage * after all, and we hope to be slashdotted some day) * * Therefore, we wrap all the static content (including the tree * widgets), into WViewWidgets with static models. In this way the * widgets are not actually stored in memory on the server. */ // The call ->setPathComponent() is to use "/examples/" instead of // "/examples/hello_world" as internal path examplesMenu_->addTab(wrapView(&WtHome::helloWorldExample), tr("hello-world"))->setPathComponent(""); examplesMenu_->addTab(wrapView(&WtHome::chartExample), tr("charts")); examplesMenu_->addTab(wrapView(&WtHome::homepageExample), tr("wt-homepage")); examplesMenu_->addTab(wrapView(&WtHome::treeviewExample), tr("treeview")); examplesMenu_->addTab(wrapView(&WtHome::gitExample), tr("git")); examplesMenu_->addTab(wrapView(&WtHome::chatExample), tr("chat")); examplesMenu_->addTab(wrapView(&WtHome::composerExample), tr("mail-composer")); examplesMenu_->addTab(wrapView(&WtHome::hangmanExample), tr("hangman")); examplesMenu_->addTab(wrapView(&WtHome::widgetGalleryExample), tr("widget-gallery")); // Enable internal paths for the example menu examplesMenu_->setInternalPathEnabled("/examples"); examplesMenu_->currentChanged().connect(this, &Home::googleAnalyticsLogger); return result; }
void Home::createHome() { WTemplate *result = new WTemplate(tr("template"), root()); homePage_ = result; WContainerWidget *languagesDiv = new WContainerWidget(); languagesDiv->setId("top_languages"); for (unsigned i = 0; i < languages.size(); ++i) { if (i != 0) new WText("- ", languagesDiv); const Lang& l = languages[i]; new WAnchor(WLink(WLink::InternalPath, l.path_), WString::fromUTF8(l.longDescription_), languagesDiv); } WStackedWidget *contents = new WStackedWidget(); WAnimation fade(WAnimation::Fade, WAnimation::Linear, 250); contents->setTransitionAnimation(fade); contents->setId("main_page"); mainMenu_ = new WMenu(contents, Vertical); mainMenu_->addItem (tr("introduction"), introduction())->setPathComponent(""); mainMenu_->addItem (tr("blog"), deferCreate(boost::bind(&Home::blog, this))); mainMenu_->addItem (tr("features"), wrapView(&Home::features), WMenuItem::PreLoading); mainMenu_->addItem (tr("documentation"), wrapView(&Home::documentation), WMenuItem::PreLoading); mainMenu_->addItem (tr("examples"), examples(), WMenuItem::PreLoading)->setPathComponent("examples/"); mainMenu_->addItem (tr("download"), deferCreate(boost::bind(&Home::download, this)), WMenuItem::PreLoading); mainMenu_->addItem (tr("community"), wrapView(&Home::community), WMenuItem::PreLoading); mainMenu_->addItem (tr("other-language"), wrapView(&Home::otherLanguage), WMenuItem::PreLoading); mainMenu_->itemSelectRendered().connect(this, &Home::updateTitle); mainMenu_->itemSelected().connect(this, &Home::googleAnalyticsLogger); // Make the menu be internal-path aware. mainMenu_->setInternalPathEnabled("/"); sideBarContent_ = new WContainerWidget(); result->bindWidget("languages", languagesDiv); result->bindWidget("menu", mainMenu_); result->bindWidget("contents", contents); result->bindWidget("sidebar", sideBarContent_); }