Wt examples  3.7.1
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
PopupChatWidget Class Reference

A popup chat widget. More...

#include <PopupChatWidget.h>

Inheritance diagram for PopupChatWidget:
Inheritance graph
[legend]

Public Member Functions

 PopupChatWidget (SimpleChatServer &server, const std::string &id)
 
void setName (const Wt::WString &name)
 
- Public Member Functions inherited from SimpleChatWidget
 SimpleChatWidget (SimpleChatServer &server, Wt::WContainerWidget *parent=0)
 Create a chat widget that will connect to the given server. More...
 
 ~SimpleChatWidget ()
 Delete a chat widget. More...
 
void connect ()
 
void disconnect ()
 
void letLogin ()
 Show a simple login screen. More...
 
bool startChat (const Wt::WString &user)
 Start a chat for the given user. More...
 
void logout ()
 
SimpleChatServerserver ()
 
int userCount ()
 
const Wt::WStringuserName () const
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 
 ~WContainerWidget ()
 
void setLayout (std::unique_ptr< WLayout > layout)
 
Layout * setLayout (std::unique_ptr< Layout > layout)
 
WLayoutlayout () const
 
virtual void addWidget (std::unique_ptr< WWidget > widget)
 
Widget * addWidget (std::unique_ptr< Widget > widget)
 
Widget * addNew (Args &&...args)
 
virtual void insertBefore (std::unique_ptr< WWidget > widget, WWidget *before)
 
Widget * insertBefore (std::unique_ptr< Widget > widget, WWidget *before)
 
virtual void insertWidget (int index, std::unique_ptr< WWidget > widget)
 
Widget * insertWidget (int index, std::unique_ptr< Widget > widget)
 
Widget * insertNew (int index, Args &&...args)
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
virtual void clear ()
 
virtual int indexOf (WWidget *widget) const
 
virtual WWidgetwidget (int index) const
 
virtual int count () const
 
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
 
void setPadding (const WLength &padding, WFlags< Side > sides=AllSides)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Orientation::Horizontal|Orientation::Vertical))
 
void setList (bool list, bool ordered=false)
 
bool isList () const
 
bool isUnorderedList () const
 
bool isOrderedList () const
 
EventSignal< WScrollEvent > & scrolled ()
 
int scrollTop () const
 
int scrollLeft () const
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
EventSignal< WKeyEvent > & keyWentDown ()
 
EventSignal< WKeyEvent > & keyPressed ()
 
EventSignal< WKeyEvent > & keyWentUp ()
 
EventSignalenterPressed ()
 
EventSignalescapePressed ()
 
EventSignal< WMouseEvent > & clicked ()
 
EventSignal< WMouseEvent > & doubleClicked ()
 
EventSignal< WMouseEvent > & mouseWentDown ()
 
EventSignal< WMouseEvent > & mouseWentUp ()
 
EventSignal< WMouseEvent > & mouseWentOut ()
 
EventSignal< WMouseEvent > & mouseWentOver ()
 
EventSignal< WMouseEvent > & mouseMoved ()
 
EventSignal< WMouseEvent > & mouseDragged ()
 
EventSignal< WMouseEvent > & mouseWheel ()
 
EventSignal< WTouchEvent > & touchStarted ()
 
EventSignal< WTouchEvent > & touchEnded ()
 
EventSignal< WTouchEvent > & touchMoved ()
 
EventSignal< WGestureEvent > & gestureStarted ()
 
EventSignal< WGestureEvent > & gestureChanged ()
 
EventSignal< WGestureEvent > & gestureEnded ()
 
void setDraggable (const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget *> children () const override
 
SignalchildrenChanged ()
 
virtual void setPositionScheme (PositionScheme scheme) override
 
virtual PositionScheme positionScheme () const override
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
 
virtual WLength offset (Side s) const override
 
virtual void resize (const WLength &width, const WLength &height) override
 
virtual WLength width () const override
 
virtual WLength height () const override
 
virtual void setMinimumSize (const WLength &width, const WLength &height) override
 
virtual WLength minimumWidth () const override
 
virtual WLength minimumHeight () const override
 
virtual void setMaximumSize (const WLength &width, const WLength &height) override
 
virtual WLength maximumWidth () const override
 
virtual WLength maximumHeight () const override
 
virtual void setLineHeight (const WLength &height) override
 
virtual WLength lineHeight () const override
 
virtual void setFloatSide (Side s) override
 
virtual Side floatSide () const override
 
virtual void setClearSides (WFlags< Side > sides) override
 
virtual WFlags< SideclearSides () const override
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
 
virtual WLength margin (Side side) const override
 
virtual void setHiddenKeepsGeometry (bool enabled) override
 
virtual bool hiddenKeepsGeometry () const override
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
 
virtual bool isHidden () const override
 
virtual bool isVisible () const override
 
virtual void setDisabled (bool disabled) override
 
virtual bool isDisabled () const override
 
virtual bool isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () override
 
virtual void setStyleClass (const WString &styleClass) override
 
virtual WString styleClass () const override
 
virtual void addStyleClass (const WString &styleClass, bool force=false) override
 
virtual void removeStyleClass (const WString &styleClass, bool force=false) override
 
virtual bool hasStyleClass (const WString &styleClass) const override
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void refresh () override
 
virtual void setAttributeValue (const std::string &name, const WString &value) override
 
virtual WString attributeValue (const std::string &name) const override
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value) override
 
virtual std::string javaScriptMember (const std::string &name) const override
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args) override
 
virtual bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const final override
 
virtual void setScrollVisibilityEnabled (bool enabled) final override
 
virtual int scrollVisibilityMargin () const final override
 
virtual void setScrollVisibilityMargin (int margin) final override
 
virtual Signal< bool > & scrollVisibilityChanged () final override
 
virtual bool isScrollVisible () const final override
 
virtual void setThemeStyleEnabled (bool enabled) final override
 
virtual bool isThemeStyleEnabled () const final override
 
virtual void setObjectName (const std::string &name) override
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
std::unique_ptr< WWidgetremoveFromParent ()
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
 
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
 
std::string jsRef () const
 
void setFocus ()
 
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
 
virtual void stopAcceptDrops (const std::string &mimeType)
 
virtual void htmlText (std::ostream &out)
 
bool isRendered () const
 
void hide ()
 
void animateHide (const WAnimation &animation)
 
void show ()
 
void animateShow (const WAnimation &animation)
 
void enable ()
 
void disable ()
 
bool layoutSizeAware () const
 
- Public Member Functions inherited from Wt::WObject
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
virtual std::string objectName () const
 
void resetLearnedSlots ()
 
void resetLearnedSlot (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)())
 
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

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 ()
 
- Protected Member Functions inherited from SimpleChatWidget
virtual void render (Wt::WFlags< Wt::RenderFlag > flags)
 
bool loggedIn () const
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

Private Member Functions

void toggleSize ()
 
void goOnline ()
 
bool minimized () const
 
Wt::WContainerWidgetcreateBar ()
 

Private Attributes

Wt::WString name_
 
Wt::WTexttitle_
 
Wt::WWidgetbar_
 
bool online_
 
bool minimized_
 
int missedMessages_
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter='\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 

Detailed Description

A popup chat widget.

Definition at line 20 of file PopupChatWidget.h.

Constructor & Destructor Documentation

◆ PopupChatWidget()

PopupChatWidget::PopupChatWidget ( SimpleChatServer server,
const std::string &  id 
)

Definition at line 19 of file PopupChatWidget.C.

21  : SimpleChatWidget(server),
23 {
24  setId(id);
25 
26  if (Wt::WApplication::instance()->environment().agentIsIE()) {
27  if (Wt::WApplication::instance()->environment().agent()
28  == Wt::WEnvironment::IE6)
29  setPositionScheme(Wt::Absolute);
30  else
31  setPositionScheme(Wt::Fixed);
32  }
33 
36  "{"
37  """var s = $('#" + id + "');"
38  """s.toggleClass('chat-maximized chat-minimized');"
39  + Wt::WApplication::instance()->javaScriptClass()
40  + ".layouts2.scheduleAdjust(true);"
41  "}");
42 
43  online_ = false;
44  minimized_ = true;
45  setStyleClass("chat-widget chat-minimized");
46 
47  clear();
49  updateUsers();
50 
51  connect();
52 }
virtual void setStyleClass(const WString &styleClass) override
virtual void setPositionScheme(PositionScheme scheme) override
virtual void setId(const std::string &id) override
virtual void updateUsers()
virtual void clear()
WStatelessSlot * implementJavaScript(void(T::*method)(), const std::string &jsCode)
static WApplication * instance()
Wt::WContainerWidget * createBar()
virtual void addWidget(std::unique_ptr< WWidget > widget)
SimpleChatWidget(SimpleChatServer &server, Wt::WContainerWidget *parent=0)
Create a chat widget that will connect to the given server.

Member Function Documentation

◆ createBar()

Wt::WContainerWidget * PopupChatWidget::createBar ( )
private

Definition at line 70 of file PopupChatWidget.C.

71 {
73  bar->setStyleClass("chat-bar");
74 
75  Wt::WText *toggleButton = new Wt::WText();
76  toggleButton->setInline(false);
77  toggleButton->setStyleClass("chat-minmax");
78  bar->clicked().connect(this, &PopupChatWidget::toggleSize);
79  bar->clicked().connect(this, &PopupChatWidget::goOnline);
80 
81  bar->addWidget(toggleButton);
82 
83  title_ = new Wt::WText(bar);
84 
85  bar_ = bar;
86 
87  return bar;
88 }
virtual void setStyleClass(const WString &styleClass) override
Wt::WText * title_
EventSignal< WMouseEvent > & clicked()
Wt::WWidget * bar_
virtual void addWidget(std::unique_ptr< WWidget > widget)
virtual void setInline(bool isInline) override

◆ createLayout()

void PopupChatWidget::createLayout ( Wt::WWidget messages,
Wt::WWidget userList,
Wt::WWidget messageEdit,
Wt::WWidget sendButton,
Wt::WWidget logoutButton 
)
protectedvirtual

Reimplemented from SimpleChatWidget.

Definition at line 119 of file PopupChatWidget.C.

124 {
126  layout->setContentsMargins(0, 0, 0, 0);
127  layout->setSpacing(0);
128 
130 
131  layout->addWidget(bar);
133  layout->addWidget(messages, 1);
134  layout->addWidget(messageEdit);
135 
136  setLayout(layout);
137 }
void setLayout(std::unique_ptr< WLayout > layout)
static WLength Auto
virtual void setMinimumSize(const WLength &width, const WLength &height) override
void addWidget(std::unique_ptr< WWidget > widget, int stretch, WFlags< AlignmentFlag > alignment)
void setContentsMargins(int left, int top, int right, int bottom)
void setSpacing(int size)
Wt::WContainerWidget * createBar()
WLayout * layout() const

◆ goOnline()

void PopupChatWidget::goOnline ( )
private

Definition at line 95 of file PopupChatWidget.C.

96 {
97  if (!online_) {
98  online_ = true;
99 
100  int tries = 1;
101  Wt::WString name = name_;
102  if (name.empty())
103  name = server().suggestGuest();
104 
105  while (!startChat(name)) {
106  if (name_.empty())
107  name = server().suggestGuest();
108  else
109  name = name_ + boost::lexical_cast<std::string>(++tries);
110  }
111 
112  name_ = name;
113  }
114 
115  missedMessages_ = 0;
116  bar_->removeStyleClass("alert");
117 }
bool empty() const
SimpleChatServer & server()
Wt::WString name_
virtual void removeStyleClass(const WString &styleClass, bool force=false)=0
Wt::WWidget * bar_
bool startChat(const Wt::WString &user)
Start a chat for the given user.
Wt::WString suggestGuest()
Get a suggestion for a guest user name.

◆ minimized()

bool PopupChatWidget::minimized ( ) const
private

Definition at line 169 of file PopupChatWidget.C.

170 {
171  return minimized_;
172 }

◆ newMessage()

void PopupChatWidget::newMessage ( )
protectedvirtual

Reimplemented from SimpleChatWidget.

Definition at line 159 of file PopupChatWidget.C.

160 {
161  if (loggedIn() && minimized()) {
162  ++missedMessages_;
163  if (missedMessages_ == 1) {
164  bar_->addStyleClass("alert");
165  }
166  }
167 }
bool minimized() const
Wt::WWidget * bar_
bool loggedIn() const
virtual void addStyleClass(const WString &styleClass, bool force=false)=0

◆ setName()

void PopupChatWidget::setName ( const Wt::WString name)

Definition at line 54 of file PopupChatWidget.C.

55 {
56  if (name.empty())
57  return;
58 
59  if (online_) {
60  int tries = 1;
61  Wt::WString n = name;
62  while (!server().changeName(name_, n))
63  n = name + boost::lexical_cast<std::string>(++tries);
64 
65  name_ = n;
66  } else
67  name_ = name;
68 }
bool empty() const
SimpleChatServer & server()
Wt::WString name_
bool changeName(const Wt::WString &user, const Wt::WString &newUser)
Changes the name.

◆ toggleSize()

void PopupChatWidget::toggleSize ( )
private

Definition at line 90 of file PopupChatWidget.C.

91 {
93 }

◆ updateUsers()

void PopupChatWidget::updateUsers ( )
protectedvirtual

Reimplemented from SimpleChatWidget.

Definition at line 139 of file PopupChatWidget.C.

140 {
142 
143  int count = server().users().size();
144 
145  if (!loggedIn()) {
146  if (count == 0)
147  title_->setText("Thoughts? Ventilate.");
148  else if (count == 1)
149  title_->setText("Chat: 1 user online");
150  else
151  title_->setText(Wt::WString("Chat: {1} users online").arg(count));
152  } else {
153  title_->setText(Wt::WString("Chat: <span class=\"self\">{1}</span>"
154  " <span class=\"online\">({2} user{3})</span>")
155  .arg(userName()).arg(count).arg(count == 1 ? "" : "s"));
156  }
157 }
Wt::WText * title_
SimpleChatServer & server()
UserSet users()
Get the users currently logged in.
virtual void updateUsers()
bool setText(const WString &text)
const Wt::WString & userName() const
virtual int count() const
bool loggedIn() const

Member Data Documentation

◆ bar_

Wt::WWidget* PopupChatWidget::bar_
private

Definition at line 38 of file PopupChatWidget.h.

◆ minimized_

bool PopupChatWidget::minimized_
private

Definition at line 39 of file PopupChatWidget.h.

◆ missedMessages_

int PopupChatWidget::missedMessages_
private

Definition at line 40 of file PopupChatWidget.h.

◆ name_

Wt::WString PopupChatWidget::name_
private

Definition at line 36 of file PopupChatWidget.h.

◆ online_

bool PopupChatWidget::online_
private

Definition at line 39 of file PopupChatWidget.h.

◆ title_

Wt::WText* PopupChatWidget::title_
private

Definition at line 37 of file PopupChatWidget.h.


The documentation for this class was generated from the following files:

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13