Wt examples
3.2.0
|
A popup chat widget. More...
#include <PopupChatWidget.h>
Public Member Functions | |
PopupChatWidget (SimpleChatServer &server, const std::string &id) | |
void | setName (const Wt::WString &name) |
Protected Member Functions | |
virtual void | createLayout (Wt::WWidget *messages, Wt::WWidget *userList, Wt::WWidget *messageEdit, Wt::WWidget *sendButton, Wt::WWidget *logoutButton) |
virtual void | updateUsers () |
virtual void | newMessage () |
Private Member Functions | |
void | toggleSize () |
void | goOnline () |
bool | minimized () const |
Wt::WContainerWidget * | createBar () |
Private Attributes | |
Wt::WString | name_ |
Wt::WText * | title_ |
Wt::WWidget * | bar_ |
bool | online_ |
bool | minimized_ |
int | missedMessages_ |
A popup chat widget.
Definition at line 20 of file PopupChatWidget.h.
PopupChatWidget::PopupChatWidget | ( | SimpleChatServer & | server, |
const std::string & | id | ||
) |
Definition at line 19 of file PopupChatWidget.C.
: SimpleChatWidget(server), missedMessages_(0) { setId(id); if (Wt::WApplication::instance()->environment().agentIsIE()) { if (Wt::WApplication::instance()->environment().agent() == Wt::WEnvironment::IE6) setPositionScheme(Wt::Absolute); else setPositionScheme(Wt::Fixed); } implementJavaScript (&PopupChatWidget::toggleSize, "{" """var s = $('#" + id + "');" """s.toggleClass('chat-maximized chat-minimized');" "}"); online_ = false; minimized_ = true; setStyleClass("chat-widget chat-minimized"); clear(); addWidget(createBar()); updateUsers(); connect(); }
Wt::WContainerWidget * PopupChatWidget::createBar | ( | ) | [private] |
Definition at line 69 of file PopupChatWidget.C.
{ Wt::WContainerWidget *bar = new Wt::WContainerWidget(); bar->setStyleClass("chat-bar"); Wt::WText *toggleButton = new Wt::WText(); toggleButton->setInline(false); toggleButton->setStyleClass("chat-minmax"); bar->clicked().connect(this, &PopupChatWidget::toggleSize); bar->clicked().connect(this, &PopupChatWidget::goOnline); bar->addWidget(toggleButton); title_ = new Wt::WText(bar); bar_ = bar; return bar; }
void PopupChatWidget::createLayout | ( | Wt::WWidget * | messages, |
Wt::WWidget * | userList, | ||
Wt::WWidget * | messageEdit, | ||
Wt::WWidget * | sendButton, | ||
Wt::WWidget * | logoutButton | ||
) | [protected, virtual] |
Reimplemented from SimpleChatWidget.
Definition at line 118 of file PopupChatWidget.C.
{ Wt::WVBoxLayout *layout = new Wt::WVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); Wt::WContainerWidget *bar = createBar(); layout->addWidget(bar); layout->addWidget(messages, 1); layout->addWidget(messageEdit); setLayout(layout); }
void PopupChatWidget::goOnline | ( | ) | [private] |
Definition at line 94 of file PopupChatWidget.C.
{ if (!online_) { online_ = true; int tries = 1; Wt::WString name = name_; if (name.empty()) name = server().suggestGuest(); while (!startChat(name)) { if (name_.empty()) name = server().suggestGuest(); else name = name_ + boost::lexical_cast<std::string>(++tries); } name_ = name; } missedMessages_ = 0; bar_->removeStyleClass("alert"); }
bool PopupChatWidget::minimized | ( | ) | const [private] |
Definition at line 167 of file PopupChatWidget.C.
{ return minimized_; }
void PopupChatWidget::newMessage | ( | ) | [protected, virtual] |
Reimplemented from SimpleChatWidget.
Definition at line 157 of file PopupChatWidget.C.
{ if (loggedIn() && minimized()) { ++missedMessages_; if (missedMessages_ == 1) { bar_->addStyleClass("alert"); } } }
void PopupChatWidget::setName | ( | const Wt::WString & | name | ) |
Definition at line 53 of file PopupChatWidget.C.
{ if (name.empty()) return; if (online_) { int tries = 1; Wt::WString n = name; while (!server().changeName(name_, n)) n = name + boost::lexical_cast<std::string>(++tries); name_ = n; } else name_ = name; }
void PopupChatWidget::toggleSize | ( | ) | [private] |
Definition at line 89 of file PopupChatWidget.C.
{ minimized_ = !minimized_; }
void PopupChatWidget::updateUsers | ( | ) | [protected, virtual] |
Reimplemented from SimpleChatWidget.
Definition at line 137 of file PopupChatWidget.C.
{ SimpleChatWidget::updateUsers(); int count = server().users().size(); if (!loggedIn()) { if (count == 0) title_->setText("Thoughts? Ventilate."); else if (count == 1) title_->setText("Chat: 1 user online"); else title_->setText(Wt::WString("Chat: {1} users online").arg(count)); } else { title_->setText(Wt::WString("Chat: <span class=\"self\">{1}</span>" " <span class=\"online\">({2} user{3})</span>") .arg(userName()).arg(count).arg(count == 1 ? "" : "s")); } }
Wt::WWidget* PopupChatWidget::bar_ [private] |
Definition at line 38 of file PopupChatWidget.h.
bool PopupChatWidget::minimized_ [private] |
Definition at line 39 of file PopupChatWidget.h.
int PopupChatWidget::missedMessages_ [private] |
Definition at line 40 of file PopupChatWidget.h.
Wt::WString PopupChatWidget::name_ [private] |
Definition at line 36 of file PopupChatWidget.h.
bool PopupChatWidget::online_ [private] |
Definition at line 39 of file PopupChatWidget.h.
Wt::WText* PopupChatWidget::title_ [private] |
Definition at line 37 of file PopupChatWidget.h.