Wt examples  3.3.6
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, Wt::WContainerWidget *parent=0)
 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...
 
Wt::WImage * icon1 () const
 Get the first icon image. More...
 
Wt::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

Wt::EventSignal< Wt::WMouseEvent > & icon1Clicked
 Signal emitted when clicked while in state 0 (icon 1 is shown). More...
 
Wt::EventSignal< Wt::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

Wt::WContainerWidget * impl_
 
Wt::WImage * icon1_
 First icon. More...
 
Wt::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 34 of file IconPair.h.

Constructor & Destructor Documentation

◆ IconPair()

IconPair::IconPair ( const std::string  icon1URI,
const std::string  icon2URI,
bool  clickIsSwitch = true,
Wt::WContainerWidget *  parent = 0 
)

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 12 of file IconPair.C.

14  : Wt::WCompositeWidget(parent),
15  impl_(new Wt::WContainerWidget()),
16  icon1_(new Wt::WImage(icon1URI, impl_)),
17  icon2_(new Wt::WImage(icon2URI, impl_)),
18  icon1Clicked(icon1_->clicked()),
19  icon2Clicked(icon2_->clicked())
20 {
21  setImplementation(impl_);
22 
23  implementStateless(&IconPair::showIcon1, &IconPair::undoShowIcon1);
24  implementStateless(&IconPair::showIcon2, &IconPair::undoShowIcon2);
25 
26  setInline(true);
27 
28  icon2_->hide();
29 
30  if (clickIsSwitch) {
31  icon1_->clicked().connect(icon1_, &Wt::WImage::hide);
32  icon1_->clicked().connect(icon2_, &Wt::WImage::show);
33 
34  icon2_->clicked().connect(icon2_, &Wt::WImage::hide);
35  icon2_->clicked().connect(icon1_, &Wt::WImage::show); //
36 
37  decorationStyle().setCursor(Wt::PointingHandCursor);
38  }
39 } //
Wt::WContainerWidget * impl_
Definition: IconPair.h:76
Wt::EventSignal< Wt::WMouseEvent > & icon1Clicked
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition: IconPair.h:88
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition: IconPair.C:74
Wt::EventSignal< Wt::WMouseEvent > & icon2Clicked
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition: IconPair.h:93
Wt::WImage * icon2_
Second icon.
Definition: IconPair.h:82
void showIcon2()
Set state to 1 (show icon 2).
Definition: IconPair.C:63
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition: IconPair.C:69
void showIcon1()
Set state to 0 (show icon 1).
Definition: IconPair.C:57
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

Member Function Documentation

◆ icon1()

Wt::WImage* IconPair::icon1 ( ) const
inline

Get the first icon image.

Definition at line 61 of file IconPair.h.

61 { return icon1_; }
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

◆ icon2()

Wt::WImage* IconPair::icon2 ( ) const
inline

Get the second icon image.

Definition at line 65 of file IconPair.h.

65 { return icon2_; }
Wt::WImage * icon2_
Second icon.
Definition: IconPair.h:82

◆ 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 41 of file IconPair.C.

42 {
43  if (num == 0) {
44  icon1_->show();
45  icon2_->hide();
46  } else {
47  icon1_->hide();
48  icon2_->show();
49  }
50 }
Wt::WImage * icon2_
Second icon.
Definition: IconPair.h:82
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

◆ showIcon1()

void IconPair::showIcon1 ( )

Set state to 0 (show icon 1).

Definition at line 57 of file IconPair.C.

58 {
59  previousState_ = (icon1_->isHidden() ? 1 : 0);
60  setState(0);
61 }
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:41
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:97
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

◆ showIcon2()

void IconPair::showIcon2 ( )

Set state to 1 (show icon 2).

Definition at line 63 of file IconPair.C.

64 {
65  previousState_ = (icon1_->isHidden() ? 1 : 0);
66  setState(1);
67 }
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:41
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:97
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

◆ state()

int IconPair::state ( ) const

Get the current state.

See also
setState()

Definition at line 52 of file IconPair.C.

53 {
54  return (icon1_->isHidden() ? 1 : 0);
55 }
Wt::WImage * icon1_
First icon.
Definition: IconPair.h:79

◆ undoShowIcon1()

void IconPair::undoShowIcon1 ( )
private

Undo function for prelearning showIcon1()

Definition at line 69 of file IconPair.C.

70 {
72 }
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:41
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:97

◆ undoShowIcon2()

void IconPair::undoShowIcon2 ( )
private

Undo function for prelearning showIcon2()

Definition at line 74 of file IconPair.C.

75 {
77 } //
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:41
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:97

Member Data Documentation

◆ icon1_

Wt::WImage* IconPair::icon1_
private

First icon.

Definition at line 79 of file IconPair.h.

◆ icon1Clicked

Wt::EventSignal<Wt::WMouseEvent>& IconPair::icon1Clicked

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

Definition at line 88 of file IconPair.h.

◆ icon2_

Wt::WImage* IconPair::icon2_
private

Second icon.

Definition at line 82 of file IconPair.h.

◆ icon2Clicked

Wt::EventSignal<Wt::WMouseEvent>& IconPair::icon2Clicked

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

Definition at line 93 of file IconPair.h.

◆ impl_

Wt::WContainerWidget* IconPair::impl_
private

Definition at line 76 of file IconPair.h.

◆ previousState_

int IconPair::previousState_
private

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

Definition at line 97 of file IconPair.h.


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

Generated on Thu Jan 12 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.13