Wt examples  4.0.3
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:
Inheritance graph
[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...
 
WImage * icon1 () const
 Get the first icon image. More...
 
WImage * icon2 () 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 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

WContainerWidget * impl_
 
WImage * icon1_
 First icon. More...
 
WImage * icon2_
 Second icon. More...
 
int previousState_
 Undo state for prelearning stateless showIcon1() and showIcon2() slots. More...
 

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 = cpp14::make_unique<WContainerWidget>();
24  impl_ = impl.get();
25  icon1_ = impl_->addWidget(cpp14::make_unique<WImage>(icon1URI));
26  icon2_ = impl_->addWidget(cpp14::make_unique<WImage>(icon2URI));
27  icon1Clicked = &icon1_->clicked();
28  icon2Clicked = &icon2_->clicked();
29 
30  setImplementation(std::move(impl));
31 
32  implementStateless(&IconPair::showIcon1, &IconPair::undoShowIcon1);
33  implementStateless(&IconPair::showIcon2, &IconPair::undoShowIcon2);
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 } //
EventSignal< WMouseEvent > * icon2Clicked
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition: IconPair.h:95
WImage * icon1_
First icon.
Definition: IconPair.h:81
WImage * icon2_
Second icon.
Definition: IconPair.h:84
EventSignal< WMouseEvent > * icon1Clicked
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition: IconPair.h:90
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition: IconPair.C:83
WContainerWidget * impl_
Definition: IconPair.h:78
void showIcon2()
Set state to 1 (show icon 2).
Definition: IconPair.C:72
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition: IconPair.C:78
void showIcon1()
Set state to 0 (show icon 1).
Definition: IconPair.C:66

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_; }
WImage * icon1_
First icon.
Definition: IconPair.h:81

◆ icon2()

WImage* IconPair::icon2 ( ) const
inline

Get the second icon image.

Definition at line 67 of file IconPair.h.

67 { return icon2_; }
WImage * icon2_
Second icon.
Definition: IconPair.h:84

◆ 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 }
WImage * icon1_
First icon.
Definition: IconPair.h:81
WImage * icon2_
Second icon.
Definition: IconPair.h:84

◆ 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
WImage * icon1_
First icon.
Definition: IconPair.h:81
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:99

◆ 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 }
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:50
WImage * icon1_
First icon.
Definition: IconPair.h:81
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:99

◆ 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 }
WImage * icon1_
First icon.
Definition: IconPair.h:81

◆ undoShowIcon1()

void IconPair::undoShowIcon1 ( )
private

Undo function for prelearning showIcon1()

Definition at line 78 of file IconPair.C.

79 {
81 }
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

◆ undoShowIcon2()

void IconPair::undoShowIcon2 ( )
private

Undo function for prelearning showIcon2()

Definition at line 83 of file IconPair.C.

84 {
86 } //
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

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:

Generated on Thu Aug 23 2018 for the C++ Web Toolkit (Wt) by doxygen 1.8.14