#include <IconPair.h>
Public Slots | |
void | showIcon1 () |
Set state to 0 (show icon 1). | |
void | showIcon2 () |
Set state to 1 (show icon 2). | |
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. | |
void | setState (int num) |
Set which icon should be visible. | |
int | state () const |
Get the current state. | |
Wt::WImage * | icon1 () const |
Get the first icon image. | |
Wt::WImage * | icon2 () const |
Get the second icon image. | |
Public Attributes | |
Wt::EventSignal < Wt::WMouseEvent > & | icon1Clicked |
Signal emitted when clicked while in state 0 (icon 1 is shown). | |
Wt::EventSignal < Wt::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 | |
Wt::WContainerWidget * | impl_ |
Wt::WImage * | icon1_ |
First icon. | |
Wt::WImage * | icon2_ |
Second icon. | |
int | previousState_ |
Undo state for prelearning stateless showIcon1() and showIcon2() slots. |
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.
Definition at line 34 of file IconPair.h.
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.
00014 : Wt::WCompositeWidget(parent), 00015 impl_(new Wt::WContainerWidget()), 00016 icon1_(new Wt::WImage(icon1URI, impl_)), 00017 icon2_(new Wt::WImage(icon2URI, impl_)), 00018 icon1Clicked(icon1_->clicked()), 00019 icon2Clicked(icon2_->clicked()) 00020 { 00021 setImplementation(impl_); 00022 00023 implementStateless(&IconPair::showIcon1, &IconPair::undoShowIcon1); 00024 implementStateless(&IconPair::showIcon2, &IconPair::undoShowIcon2); 00025 00026 setInline(true); 00027 00028 icon2_->hide(); 00029 00030 if (clickIsSwitch) { 00031 icon1_->clicked().connect(SLOT(icon1_, Wt::WImage::hide)); 00032 icon1_->clicked().connect(SLOT(icon2_, Wt::WImage::show)); 00033 00034 icon2_->clicked().connect(SLOT(icon2_, Wt::WImage::hide)); 00035 icon2_->clicked().connect(SLOT(icon1_, Wt::WImage::show)); // 00036 00037 decorationStyle().setCursor(Wt::PointingHandCursor); 00038 } 00039 } //
void IconPair::setState | ( | int | num | ) |
Set which icon should be visible.
The first icon has number 0, and the second icon has number 1.
Definition at line 41 of file IconPair.C.
00042 { 00043 if (num == 0) { 00044 icon1_->show(); 00045 icon2_->hide(); 00046 } else { 00047 icon1_->hide(); 00048 icon2_->show(); 00049 } 00050 }
int IconPair::state | ( | ) | const |
Wt::WImage* IconPair::icon1 | ( | ) | const [inline] |
Wt::WImage* IconPair::icon2 | ( | ) | const [inline] |
void IconPair::showIcon1 | ( | ) | [slot] |
Set state to 0 (show icon 1).
Definition at line 57 of file IconPair.C.
00058 { 00059 previousState_ = (icon1_->isHidden() ? 1 : 0); 00060 setState(0); 00061 }
void IconPair::showIcon2 | ( | ) | [slot] |
Set state to 1 (show icon 2).
Definition at line 63 of file IconPair.C.
00064 { 00065 previousState_ = (icon1_->isHidden() ? 1 : 0); 00066 setState(1); 00067 }
void IconPair::undoShowIcon1 | ( | ) | [private] |
Undo function for prelearning showIcon1().
Definition at line 69 of file IconPair.C.
00070 { 00071 setState(previousState_); 00072 }
void IconPair::undoShowIcon2 | ( | ) | [private] |
Undo function for prelearning showIcon2().
Definition at line 74 of file IconPair.C.
00075 { 00076 setState(previousState_); 00077 } //
Wt::WContainerWidget* IconPair::impl_ [private] |
Definition at line 77 of file IconPair.h.
Wt::WImage* IconPair::icon1_ [private] |
Wt::WImage* IconPair::icon2_ [private] |
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition at line 89 of file IconPair.h.
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition at line 94 of file IconPair.h.
int IconPair::previousState_ [private] |
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition at line 98 of file IconPair.h.