Wt examples  4.10.4
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
IconPair Class Reference

An icon pair (identical to WIconPair) More...

#include <IconPair.h>

Inheritance diagram for IconPair:
[legend]

Public Member Functions

 IconPair (const std::string icon1URI, const std::string icon2URI, bool clickIsSwitch=true)
 Construct a two-state icon widget. More...
 
void setState (int num)
 Set which icon should be visible. More...
 
int state () const
 Get the current state. More...
 
WImageicon1 () const
 Get the first icon image. More...
 
WImageicon2 () const
 Get the second icon image. More...
 
void showIcon1 ()
 Set state to 0 (show icon 1). More...
 
void showIcon2 ()
 Set state to 1 (show icon 2). More...
 
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget ()
 
 WCompositeWidget (std::unique_ptr< WWidget > implementation)
 
virtual std::vector< WWidget * > children () const override
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
virtual void setObjectName (const std::string &name) override
 
virtual std::string objectName () const override
 
virtual const std::string id () const override
 
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 isEnabled () const override
 
virtual void setPopup (bool popup) 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::Auto) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) 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 void load () override
 
virtual bool loaded () const override
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual void setFocus (bool focus) override
 
virtual bool setFirstFocus () override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &name) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &js) override
 
virtual void propagateSetEnabled (bool enabled) override
 
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 std::unique_ptr< WWidgetremoveWidget (WWidget *widget)
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
void setFocus ()
 
virtual void setFocus (bool focus)=0
 
- 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)
 
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
 

Public Attributes

EventSignal< WMouseEvent > * icon1Clicked
 Signal emitted when clicked while in state 0 (icon 1 is shown). More...
 
EventSignal< WMouseEvent > * icon2Clicked
 Signal emitted when clicked while in state 1 (icon 2 is shown). More...
 

Private Member Functions

void undoShowIcon1 ()
 Undo function for prelearning showIcon1() More...
 
void undoShowIcon2 ()
 Undo function for prelearning showIcon2() More...
 

Private Attributes

WContainerWidgetimpl_
 
WImageicon1_
 First icon. More...
 
WImageicon2_
 Second icon. More...
 
int previousState_
 Undo state for prelearning stateless showIcon1() and showIcon2() slots. More...
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax () override
 
void setImplementation (std::unique_ptr< WWidget > widget)
 
Widget * setImplementation (std::unique_ptr< Widget > widget)
 
W * setNewImplementation (Args &&... args)
 
WWidgetimplementation ()
 
virtual int boxPadding (Orientation orientation) const override
 
virtual int boxBorder (Orientation orientation) const override
 
virtual void render (WFlags< RenderFlag > flags) 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)
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 
virtual WStatelessSlot * getStateless (Method method) override
 

Detailed Description

An icon pair (identical to WIconPair)

This widget manages two images, only one of which is shown at a single time.

The widget may also react to click events, by changing state.

This widget is part of the Wt treelist example, where it is used to represent the expand/collapse icons, and the corresponding map open/close icon.

See also
TreeNode

Definition at line 36 of file IconPair.h.

Constructor & Destructor Documentation

◆ IconPair()

IconPair::IconPair ( const std::string  icon1URI,
const std::string  icon2URI,
bool  clickIsSwitch = true 
)

Construct a two-state icon widget.

The constructor takes the URI of the two icons. When clickIsSwitch is set true, clicking on the icon will switch state.

Definition at line 14 of file IconPair.C.

16  : WCompositeWidget(),
17  impl_(nullptr),
18  icon1_(nullptr),
19  icon2_(nullptr),
20  icon1Clicked(nullptr),
21  icon2Clicked(nullptr)
22 {
23  auto impl = std::make_unique<WContainerWidget>();
24  impl_ = impl.get();
25  icon1_ = impl_->addWidget(std::make_unique<WImage>(icon1URI));
26  icon2_ = impl_->addWidget(std::make_unique<WImage>(icon2URI));
29 
30  setImplementation(std::move(impl));
31 
34 
35  setInline(true);
36 
37  icon2_->hide();
38 
39  if (clickIsSwitch) {
40  icon1_->clicked().connect(icon1_, &WImage::hide);
41  icon1_->clicked().connect(icon2_, &WImage::show);
42 
43  icon2_->clicked().connect(icon2_, &WImage::hide);
44  icon2_->clicked().connect(icon1_, &WImage::show); //
45 
46  decorationStyle().setCursor(Cursor::PointingHand);
47  }
48 } //
WImage * icon2_
Second icon.
Definition: IconPair.h:84
WContainerWidget * impl_
Definition: IconPair.h:78
EventSignal< WMouseEvent > * icon2Clicked
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition: IconPair.h:95
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition: IconPair.C:83
WImage * icon1_
First icon.
Definition: IconPair.h:81
void showIcon2()
Set state to 1 (show icon 2).
Definition: IconPair.C:72
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition: IconPair.C:78
EventSignal< WMouseEvent > * icon1Clicked
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition: IconPair.h:90
void showIcon1()
Set state to 0 (show icon 1).
Definition: IconPair.C:66
Wt::Signals::connection connect(F function)
virtual void setInline(bool isInline) override
void setImplementation(std::unique_ptr< WWidget > widget)
virtual WCssDecorationStyle & decorationStyle() override
virtual void addWidget(std::unique_ptr< WWidget > widget)
void setCursor(Cursor c)
EventSignal< WMouseEvent > & clicked()
WStatelessSlot * implementStateless(void(T::*method)())

Member Function Documentation

◆ icon1()

WImage* IconPair::icon1 ( ) const
inline

Get the first icon image.

Definition at line 63 of file IconPair.h.

63 { return icon1_; }

◆ icon2()

WImage* IconPair::icon2 ( ) const
inline

Get the second icon image.

Definition at line 67 of file IconPair.h.

67 { return icon2_; }

◆ setState()

void IconPair::setState ( int  num)

Set which icon should be visible.

The first icon has number 0, and the second icon has number 1.

See also
state()

Definition at line 50 of file IconPair.C.

51 {
52  if (num == 0) {
53  icon1_->show();
54  icon2_->hide();
55  } else {
56  icon1_->hide();
57  icon2_->show();
58  }
59 }

◆ showIcon1()

void IconPair::showIcon1 ( )

Set state to 0 (show icon 1).

Definition at line 66 of file IconPair.C.

67 {
68  previousState_ = (icon1_->isHidden() ? 1 : 0);
69  setState(0);
70 }
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:50
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:99
virtual bool isHidden() const override

◆ showIcon2()

void IconPair::showIcon2 ( )

Set state to 1 (show icon 2).

Definition at line 72 of file IconPair.C.

73 {
74  previousState_ = (icon1_->isHidden() ? 1 : 0);
75  setState(1);
76 }

◆ state()

int IconPair::state ( ) const

Get the current state.

See also
setState()

Definition at line 61 of file IconPair.C.

62 {
63  return (icon1_->isHidden() ? 1 : 0);
64 }

◆ undoShowIcon1()

void IconPair::undoShowIcon1 ( )
private

Undo function for prelearning showIcon1()

Definition at line 78 of file IconPair.C.

79 {
81 }

◆ undoShowIcon2()

void IconPair::undoShowIcon2 ( )
private

Undo function for prelearning showIcon2()

Definition at line 83 of file IconPair.C.

84 {
86 } //

Member Data Documentation

◆ icon1_

WImage* IconPair::icon1_
private

First icon.

Definition at line 81 of file IconPair.h.

◆ icon1Clicked

EventSignal<WMouseEvent>* IconPair::icon1Clicked

Signal emitted when clicked while in state 0 (icon 1 is shown).

Definition at line 90 of file IconPair.h.

◆ icon2_

WImage* IconPair::icon2_
private

Second icon.

Definition at line 84 of file IconPair.h.

◆ icon2Clicked

EventSignal<WMouseEvent>* IconPair::icon2Clicked

Signal emitted when clicked while in state 1 (icon 2 is shown).

Definition at line 95 of file IconPair.h.

◆ impl_

WContainerWidget* IconPair::impl_
private

Definition at line 78 of file IconPair.h.

◆ previousState_

int IconPair::previousState_
private

Undo state for prelearning stateless showIcon1() and showIcon2() slots.

Definition at line 99 of file IconPair.h.


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