Wt examples: IconPair Class Reference

Wt examples 4.10.4

Loading...
Searching...
No Matches
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.
void | setState (int num)
| Set which icon should be visible.
int | state () const
| Get the current state.
WImage * | icon1 () const
| Get the first icon image.
WImage * | icon2 () const
| Get the second icon image.
void | showIcon1 ()
| Set state to 0 (show icon 1).
void | showIcon2 ()
| Set state to 1 (show icon 2).

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

## Private Member Functions
void | undoShowIcon1 ()
| Undo function for prelearning showIcon1()
void | undoShowIcon2 ()
| Undo function for prelearning showIcon2()

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

## 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));
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} //
IconPair::icon2_
WImage * icon2_
Second icon.
Definition IconPair.h:84
IconPair::impl_
WContainerWidget * impl_
Definition IconPair.h:78
IconPair::icon2Clicked
EventSignal< WMouseEvent > * icon2Clicked
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition IconPair.h:95
IconPair::undoShowIcon2
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition IconPair.C:83
IconPair::icon1_
WImage * icon1_
First icon.
Definition IconPair.h:81
IconPair::showIcon2
void showIcon2()
Set state to 1 (show icon 2).
Definition IconPair.C:72
IconPair::undoShowIcon1
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition IconPair.C:78
IconPair::icon1Clicked
EventSignal< WMouseEvent > * icon1Clicked
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition IconPair.h:90
IconPair::showIcon1
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_; }

## ◆ 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}
IconPair::setState
void setState(int num)
Set which icon should be visible.
Definition IconPair.C:50
IconPair::previousState_
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}

## ◆ 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{
80 setState(previousState_);
81}

## ◆ undoShowIcon2()

void IconPair::undoShowIcon2 | ( |  | ) |
| private

Undo function for prelearning showIcon2()

Definition at line 83 of file IconPair.C.

84{
85 setState(previousState_);
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:

- treelist/IconPair.h
- treelist/IconPair.C