本文整理汇总了C++中WPushButton::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ WPushButton::parent方法的具体用法?C++ WPushButton::parent怎么用?C++ WPushButton::parent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WPushButton
的用法示例。
在下文中一共展示了WPushButton::parent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startChat
bool SimpleChatWidget::startChat(const WString& user)
{
/*
* When logging in, we pass our processChatEvent method as the function that
* is used to indicate a new chat event for this user.
*/
if (server_.login(user)) {
loggedIn_ = true;
connect();
user_ = user;
clear();
userNameEdit_ = 0;
messages_ = new WContainerWidget();
userList_ = new WContainerWidget();
messageEdit_ = new WTextArea();
messageEdit_->setRows(2);
messageEdit_->setFocus();
// Display scroll bars if contents overflows
messages_->setOverflow(WContainerWidget::OverflowAuto);
userList_->setOverflow(WContainerWidget::OverflowAuto);
sendButton_ = new WPushButton("Send");
WPushButton *logoutButton = new WPushButton("Logout");
createLayout(messages_, userList_, messageEdit_, sendButton_, logoutButton);
/*
* Connect event handlers:
* - click on button
* - enter in text area
*
* We will clear the input field using a small custom client-side
* JavaScript invocation.
*/
// Create a JavaScript 'slot' (JSlot). The JavaScript slot always takes
// 2 arguments: the originator of the event (in our case the
// button or text area), and the JavaScript event object.
clearInput_.setJavaScript
("function(o, e) { setTimeout(function() {"
"" + messageEdit_->jsRef() + ".value='';"
"}, 0); }");
/*
* Set the connection monitor
*
* The connection monitor is a javascript monitor that will
* nootify the given object by calling the onChange method to
* inform of connection change (use of websockets, connection
* online/offline) Here we just disable the TextEdit when we are
* offline and enable it once we're back online
*/
WApplication::instance()->setConnectionMonitor(
"window.monitor={ "
"'onChange':function(type, newV) {"
"var connected = window.monitor.status.connectionStatus != 0;"
"if(connected) {"
+ messageEdit_->jsRef() + ".disabled=false;"
+ messageEdit_->jsRef() + ".placeholder='';"
"} else { "
+ messageEdit_->jsRef() + ".disabled=true;"
+ messageEdit_->jsRef() + ".placeholder='connection lost';"
"}"
"}"
"}"
);
// Bind the C++ and JavaScript event handlers.
sendButton_->clicked().connect(this, &SimpleChatWidget::send);
messageEdit_->enterPressed().connect(this, &SimpleChatWidget::send);
sendButton_->clicked().connect(clearInput_);
messageEdit_->enterPressed().connect(clearInput_);
sendButton_->clicked().connect((WWidget *)messageEdit_,
&WWidget::setFocus);
messageEdit_->enterPressed().connect((WWidget *)messageEdit_,
&WWidget::setFocus);
// Prevent the enter from generating a new line, which is its default
// action
messageEdit_->enterPressed().preventDefaultAction();
logoutButton->clicked().connect(this, &SimpleChatWidget::logout);
WInPlaceEdit *nameEdit = new WInPlaceEdit();
nameEdit->addStyleClass("name-edit");
nameEdit->setButtonsEnabled(false);
nameEdit->setText(user_);
nameEdit->valueChanged().connect(this, &SimpleChatWidget::changeName);
WTemplate *joinMsg = new WTemplate(tr("join-msg.template"), messages_);
joinMsg->bindWidget("name", nameEdit);
joinMsg->setStyleClass("chat-msg");
if (!userList_->parent()) {
delete userList_;
//.........这里部分代码省略.........
示例2: startChat
bool SimpleChatWidget::startChat(const WString& user)
{
/*
* When logging in, we pass our processChatEvent method as the function that
* is used to indicate a new chat event for this user.
*/
if (server_.login(user)) {
loggedIn_ = true;
connect();
user_ = user;
clear();
userNameEdit_ = 0;
messages_ = new WContainerWidget();
userList_ = new WContainerWidget();
messageEdit_ = new WTextArea();
messageEdit_->setRows(2);
messageEdit_->setFocus();
// Display scroll bars if contents overflows
messages_->setOverflow(WContainerWidget::OverflowAuto);
userList_->setOverflow(WContainerWidget::OverflowAuto);
sendButton_ = new WPushButton("Send");
WPushButton *logoutButton = new WPushButton("Logout");
createLayout(messages_, userList_, messageEdit_, sendButton_, logoutButton);
/*
* Connect event handlers:
* - click on button
* - enter in text area
*
* We will clear the input field using a small custom client-side
* JavaScript invocation.
*/
// Create a JavaScript 'slot' (JSlot). The JavaScript slot always takes
// 2 arguments: the originator of the event (in our case the
// button or text area), and the JavaScript event object.
clearInput_.setJavaScript
("function(o, e) { setTimeout(function() {"
"" + messageEdit_->jsRef() + ".value='';"
"}, 0); }");
// Bind the C++ and JavaScript event handlers.
sendButton_->clicked().connect(this, &SimpleChatWidget::send);
messageEdit_->enterPressed().connect(this, &SimpleChatWidget::send);
sendButton_->clicked().connect(clearInput_);
messageEdit_->enterPressed().connect(clearInput_);
sendButton_->clicked().connect(messageEdit_, &WLineEdit::setFocus);
messageEdit_->enterPressed().connect(messageEdit_, &WLineEdit::setFocus);
// Prevent the enter from generating a new line, which is its default
// action
messageEdit_->enterPressed().preventDefaultAction();
logoutButton->clicked().connect(this, &SimpleChatWidget::logout);
WText *msg = new WText
("<div><span class='chat-info'>You are joining as "
+ escapeText(user_) + ".</span></div>",
messages_);
msg->setStyleClass("chat-msg");
if (!userList_->parent()) {
delete userList_;
userList_ = 0;
}
if (!sendButton_->parent()) {
delete sendButton_;
sendButton_ = 0;
}
if (!logoutButton->parent())
delete logoutButton;
updateUsers();
return true;
} else
return false;
}