A popup chat widget.
More...
#include <PopupChatWidget.h>
|
virtual void | createLayout (std::unique_ptr< WWidget > messages, std::unique_ptr< WWidget > userList, std::unique_ptr< WWidget > messageEdit, std::unique_ptr< WWidget > sendButton, std::unique_ptr< WWidget > logoutButton) |
|
virtual void | updateUsers () |
|
virtual void | newMessage () |
|
virtual void | createLayout (std::unique_ptr< Wt::WWidget > messages, std::unique_ptr< Wt::WWidget > userList, std::unique_ptr< Wt::WWidget > messageEdit, std::unique_ptr< Wt::WWidget > sendButton, std::unique_ptr< Wt::WWidget > logoutButton) |
|
virtual void | updateUsers () |
|
virtual void | newMessage () |
|
virtual void | render (Wt::WFlags< Wt::RenderFlag > flags) |
|
bool | loggedIn () const |
|
A popup chat widget.
Definition at line 20 of file PopupChatWidget.h.
◆ PopupChatWidget()
PopupChatWidget::PopupChatWidget |
( |
SimpleChatServer & |
server, |
|
|
const std::string & |
id |
|
) |
| |
Definition at line 19 of file PopupChatWidget.C.
23{
24 setId(id);
25
26 if (Wt::WApplication::instance()->environment().agentIsIE()) {
27 if (Wt::WApplication::instance()->environment().agent()
28 == Wt::UserAgent::IE6)
29 setPositionScheme(Wt::PositionScheme::Absolute);
30 else
31 setPositionScheme(Wt::PositionScheme::Fixed);
32 }
33
34 implementJavaScript
36 "{"
37 """var s = $('#" + id + "');"
38 """s.toggleClass('chat-maximized chat-minimized');"
39 "}");
40
43 setStyleClass("chat-widget chat-minimized");
44
45 clear();
48
50}
◆ createBar()
std::unique_ptr< Wt::WContainerWidget > PopupChatWidget::createBar |
( |
| ) |
|
|
private |
Definition at line 68 of file PopupChatWidget.C.
69{
70 auto bar(std::make_unique<Wt::WContainerWidget>());
71 bar->setStyleClass("chat-bar");
72
73 auto toggleButton(std::make_unique<Wt::WText>());
74 toggleButton->setInline(false);
75 toggleButton->setStyleClass("chat-minmax");
78
79 bar->addWidget(std::move(toggleButton));
80
81 title_ = bar->addWidget(std::make_unique<Wt::WText>());
82
84
85 return bar;
86}
◆ createLayout()
void PopupChatWidget::createLayout |
( |
std::unique_ptr< WWidget > |
messages, |
|
|
std::unique_ptr< WWidget > |
userList, |
|
|
std::unique_ptr< WWidget > |
messageEdit, |
|
|
std::unique_ptr< WWidget > |
sendButton, |
|
|
std::unique_ptr< WWidget > |
logoutButton |
|
) |
| |
|
protectedvirtual |
Definition at line 117 of file PopupChatWidget.C.
122{
123 auto layout(std::make_unique<Wt::WVBoxLayout>());
124 layout->setContentsMargins(0, 0, 0, 0);
125 layout->setSpacing(0);
126
127 auto bar = layout->addWidget(
createBar());
128 bar->setMinimumSize(Wt::WLength::Auto, 20);
129 layout->addWidget(std::move(messages), 1);
130 layout->addWidget(std::move(messageEdit));
131
132 setLayout(std::move(layout));
133}
◆ goOnline()
void PopupChatWidget::goOnline |
( |
| ) |
|
|
private |
Definition at line 93 of file PopupChatWidget.C.
94{
97
98 int tries = 1;
99 Wt::WString name =
name_;
100 if (name.empty())
102
106 else
107 name =
name_ + std::to_string(++tries);
108 }
109
111 }
112
114 bar_->removeStyleClass(
"alert");
115}
Wt::WString suggestGuest()
Get a suggestion for a guest user name.
◆ minimized()
bool PopupChatWidget::minimized |
( |
| ) |
const |
|
private |
◆ newMessage()
void PopupChatWidget::newMessage |
( |
| ) |
|
|
protectedvirtual |
◆ setName()
void PopupChatWidget::setName |
( |
const Wt::WString & |
name | ) |
|
Definition at line 52 of file PopupChatWidget.C.
53{
54 if (name.empty())
55 return;
56
58 int tries = 1;
59 Wt::WString n = name;
61 n = name + std::to_string(++tries);
62
64 } else
66}
◆ toggleSize()
void PopupChatWidget::toggleSize |
( |
| ) |
|
|
private |
◆ updateUsers()
void PopupChatWidget::updateUsers |
( |
| ) |
|
|
protectedvirtual |
Reimplemented from SimpleChatWidget.
Definition at line 135 of file PopupChatWidget.C.
136{
138
140
142 if (count == 0)
143 title_->setText(
"Thoughts? Ventilate.");
144 else if (count == 1)
145 title_->setText(
"Chat: 1 user online");
146 else
147 title_->setText(Wt::WString(
"Chat: {1} users online").arg(count));
148 } else {
149 title_->setText(Wt::WString(
"Chat: <span class=\"self\">{1}</span>"
150 " <span class=\"online\">({2} user{3})</span>")
151 .arg(
userName()).arg(count).arg(count == 1 ?
"" :
"s"));
152 }
153}
UserSet users()
Get the users currently logged in.
◆ bar_
Wt::WWidget* PopupChatWidget::bar_ |
|
private |
◆ minimized_
bool PopupChatWidget::minimized_ |
|
private |
◆ missedMessages_
int PopupChatWidget::missedMessages_ |
|
private |
◆ name_
Wt::WString PopupChatWidget::name_ |
|
private |
◆ online_
bool PopupChatWidget::online_ |
|
private |
◆ title_
Wt::WText* PopupChatWidget::title_ |
|
private |
The documentation for this class was generated from the following files: