void SimpleChatWidget::createLayout(WWidget *messages, WWidget *userList, WWidget *messageEdit, WWidget *sendButton, WWidget *logoutButton) { /* * Create a vertical layout, which will hold 3 rows, * organized like this: * * WVBoxLayout * -------------------------------------------- * | nested WHBoxLayout (vertical stretch=1) | * | | | * | messages | userList | * | (horizontal stretch=1) | | * | | | * -------------------------------------------- * | message edit area | * -------------------------------------------- * | WHBoxLayout | * | send | logout | * -------------------------------------------- */ WVBoxLayout *vLayout = new WVBoxLayout(); // Create a horizontal layout for the messages | userslist. WHBoxLayout *hLayout = new WHBoxLayout(); // Add widget to horizontal layout with stretch = 1 hLayout->addWidget(messages, 1); messages->setStyleClass("chat-msgs"); // Add another widget to horizontal layout with stretch = 0 hLayout->addWidget(userList); userList->setStyleClass("chat-users"); hLayout->setResizable(0, true); // Add nested layout to vertical layout with stretch = 1 vLayout->addLayout(hLayout, 1); // Add widget to vertical layout with stretch = 0 vLayout->addWidget(messageEdit); messageEdit->setStyleClass("chat-noedit"); // Create a horizontal layout for the buttons. hLayout = new WHBoxLayout(); // Add button to horizontal layout with stretch = 0 hLayout->addWidget(sendButton); // Add button to horizontal layout with stretch = 0 hLayout->addWidget(logoutButton); // Add nested layout to vertical layout with stretch = 0 vLayout->addLayout(hLayout, 0, AlignLeft); setLayout(vLayout); }
void SimpleChatWidget::letLogin() { disconnect(); clear(); WVBoxLayout *vLayout = new WVBoxLayout(); setLayout(vLayout, AlignLeft | AlignTop); WHBoxLayout *hLayout = new WHBoxLayout(); vLayout->addLayout(hLayout); hLayout->addWidget(new WLabel("User name:"), 0, AlignMiddle); hLayout->addWidget(userNameEdit_ = new WLineEdit(user_), 0, AlignMiddle); userNameEdit_->setFocus(); WPushButton *b = new WPushButton("Login"); hLayout->addWidget(b, 0, AlignMiddle); b->clicked().connect(this, &SimpleChatWidget::login); userNameEdit_->enterPressed().connect(this, &SimpleChatWidget::login); vLayout->addWidget(statusMsg_ = new WText()); statusMsg_->setTextFormat(PlainText); }
/*! \brief Constructor. */ GitViewApplication(const WEnvironment& env) : WApplication(env) { useStyleSheet("gitview.css"); setTitle("Git model example"); const char *gitRepo = getenv("GITVIEW_REPOSITORY_PATH"); WGridLayout *grid = new WGridLayout(); grid->addWidget(new WText("Git repository path:"), 0, 0); grid->addWidget(repositoryEdit_ = new WLineEdit(gitRepo ? gitRepo : "") , 0, 1, AlignLeft); grid->addWidget(repositoryError_ = new WText(), 0, 2); grid->addWidget(new WText("Revision:"), 1, 0); grid->addWidget(revisionEdit_ = new WLineEdit("master"), 1, 1, AlignLeft); grid->addWidget(revisionError_ = new WText(), 1, 2); repositoryEdit_->setTextSize(30); revisionEdit_->setTextSize(20); repositoryError_->setStyleClass("error-msg"); revisionError_->setStyleClass("error-msg"); repositoryEdit_->enterPressed() .connect(this, &GitViewApplication::loadGitModel); revisionEdit_->enterPressed() .connect(this, &GitViewApplication::loadGitModel); WPushButton *b = new WPushButton("Load"); b->clicked().connect(this, &GitViewApplication::loadGitModel); grid->addWidget(b, 2, 0, AlignLeft); gitView_ = new WTreeView(); gitView_->resize(300, WLength::Auto); gitView_->setSortingEnabled(false); gitView_->setModel(gitModel_ = new GitModel(this)); gitView_->setSelectionMode(SingleSelection); gitView_->selectionChanged().connect(this, &GitViewApplication::showFile); sourceView_ = new SourceView(DisplayRole, GitModel::ContentsRole, GitModel::FilePathRole); sourceView_->setStyleClass("source-view"); if (environment().javaScript()) { /* * We have JavaScript: We can use layout managers so everything will * always fit nicely in the window. */ WVBoxLayout *topLayout = new WVBoxLayout(); topLayout->addLayout(grid, 0, AlignTop | AlignLeft); WHBoxLayout *gitLayout = new WHBoxLayout(); gitLayout->setLayoutHint("table-layout", "fixed"); gitLayout->addWidget(gitView_, 0); gitLayout->addWidget(sourceView_, 1); topLayout->addLayout(gitLayout, 1); root()->setLayout(topLayout); root()->setStyleClass("maindiv"); } else { /* * No JavaScript: let's make the best of the situation using regular * CSS-based layout */ root()->setStyleClass("maindiv"); WContainerWidget *top = new WContainerWidget(); top->setLayout(grid, AlignTop | AlignLeft); root()->addWidget(top); root()->addWidget(gitView_); gitView_->setFloatSide(Left); gitView_->setMargin(6); root()->addWidget(sourceView_); sourceView_->setMargin(6); } }
WWidget *StyleLayout::wBoxLayout() { WContainerWidget *result = new WContainerWidget(); topic("WHBoxLayout", "WVBoxLayout", result); addText(tr("layout-WBoxLayout"), result); WContainerWidget *container; WText *item; WHBoxLayout *hbox; WVBoxLayout *vbox; /* * first hbox */ container = new WContainerWidget(result); container->setStyleClass("yellow-box"); hbox = new WHBoxLayout(); container->setLayout(hbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); hbox->addWidget(item); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); hbox->addWidget(item); addText(tr("layout-WBoxLayout-stretch"), result); /* * second hbox */ container = new WContainerWidget(result); container->setStyleClass("yellow-box"); hbox = new WHBoxLayout(); container->setLayout(hbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); hbox->addWidget(item, 1); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); hbox->addWidget(item); addText(tr("layout-WBoxLayout-vbox"), result); /* * first vbox */ container = new WContainerWidget(result); container->resize(150, 150); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); vbox->addWidget(item); /* * second vbox */ container = new WContainerWidget(result); container->resize(150, 150); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item, 1); item = addText(tr("layout-item2")); item->setStyleClass("blue-box"); vbox->addWidget(item); addText(tr("layout-WBoxLayout-nested"), result); /* * nested boxes */ container = new WContainerWidget(result); container->resize(200, 200); container->setStyleClass("yellow-box centered"); vbox = new WVBoxLayout(); container->setLayout(vbox); item = addText(tr("layout-item1")); item->setStyleClass("green-box"); vbox->addWidget(item, 1); hbox = new WHBoxLayout(); vbox->addLayout(hbox); item = addText(tr("layout-item2")); item->setStyleClass("green-box"); hbox->addWidget(item); item = addText(tr("layout-item3")); item->setStyleClass("blue-box"); hbox->addWidget(item); return result; }
/// // Constructor // LoginPage::LoginPage(WContainerWidget *parent) : WContainerWidget(parent), mLoggedIn(false), mLogoutRequested(false) { setStyleClass("maindiv"); WLabel* loginText = new WLabel("Enter username and password:"******""); WText *userNameText = new WText("User Name:"); mPasswordLineEdit = new WLineEdit(""); mPasswordLineEdit->setEchoMode(WLineEdit::Password); WText *passwordText = new WText("Password:"******"Login"); WGridLayout *loginLayout = new WGridLayout(); loginLayout->addWidget(userNameText, 0, 0, AlignRight); loginLayout->addWidget(mUserNameLineEdit, 0, 1, AlignLeft); loginLayout->addWidget(passwordText, 1, 0, AlignRight); loginLayout->addWidget(mPasswordLineEdit, 1, 1, AlignLeft); WGridLayout *textLayout = new WGridLayout(); textLayout->addWidget(loginText, 0, 0, AlignCenter); WGridLayout *buttonLayout = new WGridLayout(); buttonLayout->addWidget(loginButton, 0, 0, AlignCenter | AlignMiddle); WImage *chbLogo = new WImage(tr("logo-image").toUTF8()); WGridLayout *chbLogoLayout = new WGridLayout(); chbLogoLayout->addWidget(chbLogo, 0, 0, AlignCenter); WLabel *titleLabel = new WLabel(tr("page-top-text")); titleLabel->setStyleClass("logintitlediv"); WGridLayout *titleLayout = new WGridLayout(); titleLayout->addWidget(titleLabel, 0, 0, AlignCenter); WContainerWidget *loginContainer = new WContainerWidget(); loginContainer->setStyleClass("logindiv"); mFailureLabel = new WLabel("Invalid username and/or password. Try again."); mFailureLabel->setStyleClass("redtext"); WVBoxLayout *layout = new WVBoxLayout(); layout->addLayout(chbLogoLayout, AlignCenter); layout->addLayout(titleLayout, AlignCenter); layout->addLayout(textLayout, AlignCenter); layout->addLayout(loginLayout); layout->addWidget(mFailureLabel); layout->addLayout(buttonLayout, AlignCenter | AlignMiddle); mFailureLabel->hide(); loginContainer->setLayout(layout, AlignTop); WVBoxLayout *pageLayout = new WVBoxLayout(); pageLayout->addWidget(loginContainer); pageLayout->addWidget(new WText(tr("login-page-text"))); setLayout(pageLayout, AlignMiddle | AlignCenter); loginButton->clicked().connect(SLOT(this, LoginPage::login)); mPasswordLineEdit->enterPressed().connect(SLOT(this, LoginPage::login)); resetAll(); }