Wt examples  3.7.1
IconPair.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Emweb bv, Herent, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 #include <Wt/WCssDecorationStyle>
7 #include <Wt/WContainerWidget>
8 #include <Wt/WImage>
9 
10 #include "IconPair.h"
11 
12 IconPair::IconPair(const std::string icon1URI, const std::string icon2URI,
13  bool clickIsSwitch, Wt::WContainerWidget *parent)
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 {
22 
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 } //
40 
41 void IconPair::setState(int num)
42 {
43  if (num == 0) {
44  icon1_->show();
45  icon2_->hide();
46  } else {
47  icon1_->hide();
48  icon2_->show();
49  }
50 }
51 
52 int IconPair::state() const
53 {
54  return (icon1_->isHidden() ? 1 : 0);
55 }
56 
58 {
59  previousState_ = (icon1_->isHidden() ? 1 : 0);
60  setState(0);
61 }
62 
64 {
65  previousState_ = (icon1_->isHidden() ? 1 : 0);
66  setState(1);
67 }
68 
70 {
72 }
73 
75 {
77 } //
virtual void setInline(bool isInline) override
EventSignal< WMouseEvent > & clicked()
IconPair(const std::string icon1URI, const std::string icon2URI, bool clickIsSwitch=true, Wt::WContainerWidget *parent=0)
Construct a two-state icon widget.
Definition: IconPair.C:12
void setCursor(Cursor c)
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:41
Wt::WContainerWidget * impl_
Definition: IconPair.h:76
WStatelessSlot * implementStateless(void(T::*method)())
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:97
void setImplementation(std::unique_ptr< WWidget > widget)
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition: IconPair.C:74
Wt::WImage * icon2_
Second icon.
Definition: IconPair.h:82
int state() const
Get the current state.
Definition: IconPair.C:52
virtual WCssDecorationStyle & decorationStyle() override
void showIcon2()
Set state to 1 (show icon 2).
Definition: IconPair.C:63
virtual bool isHidden() const override
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

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13