Wt examples: mission/impossible.C Source File

Wt examples 4.10.4

Loading...
Searching...
No Matches
impossible.C
Go to the documentation of this file.
1/*
2 * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7#include <Wt/WApplication.h>
8#include <Wt/WBreak.h>
9#include <Wt/WContainerWidget.h>
10#include <Wt/WPushButton.h>
11#include <Wt/WText.h>
12
13#include "CountDownWidget.h"
14
15std::unique_ptr<WApplication> createApplication(const WEnvironment& env)
16{
17 std::unique_ptr<WApplication> appl
18 = std::make_unique<WApplication>(env);
19
20 appl->root()->addWidget(std::make_unique<WText>("<h1>Your mission</h1>"));
21 WText *secret
22 = appl->root()->addWidget(std::make_unique<WText>("Your mission, Jim, should you accept, is to create solid "
23 "web applications."));
24
25 appl->root()->addWidget(std::make_unique<WBreak>());
26 appl->root()->addWidget(std::make_unique<WBreak>());
27
28 appl->root()->addWidget(std::make_unique<WText>("This program will quit in "));
29 CountDownWidget *countdown = appl->root()->addWidget(std::make_unique<CountDownWidget>(10, 0, std::chrono::milliseconds{1000}));
30 appl->root()->addWidget(std::make_unique<WText>(" seconds."));
31
32 appl->root()->addWidget(std::make_unique<WBreak>());
33 appl->root()->addWidget(std::make_unique<WBreak>());
34
35 WPushButton *cancelButton = appl->root()->addWidget(std::make_unique<WPushButton>("Cancel!"));
36 WPushButton *quitButton = appl->root()->addWidget(std::make_unique<WPushButton>("Quit"));
37 quitButton->clicked().connect(appl.get(), &WApplication::quit);
38
39 countdown->done().connect([](){ WApplication::instance()->quit(); });
40 cancelButton->clicked().connect(countdown, &CountDownWidget::cancel);
41 cancelButton->clicked().connect(cancelButton, &WFormWidget::disable);
42 cancelButton->clicked().connect(secret, &WWidget::hide);
43
44 return appl;
45}
46
47 int main(int argc, char **argv)
48{
49 return WRun(argc, argv, &createApplication);
50}
CountDownWidget.h
CountDownWidget
A widget which displays a decrementing number.
Definition CountDownWidget.h:27
CountDownWidget::done
Signal & done()
Signal emitted when the countdown reached stop.
Definition CountDownWidget.h:38
CountDownWidget::cancel
void cancel()
Cancel the count down.
Definition CountDownWidget.C:29
main
int main(int argc, char **argv)
Definition impossible.C:47
createApplication
std::unique_ptr< WApplication > createApplication(const WEnvironment &env)
Definition impossible.C:15