Wt examples  4.0.0
IconPair.C
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
3  *
4  * See the LICENSE file for terms of use.
5  */
6 #include <Wt/WCssDecorationStyle.h>
7 #include <Wt/WContainerWidget.h>
8 #include <Wt/WImage.h>
9 
10 #include "IconPair.h"
11 
12 using namespace Wt;
13 
14 IconPair::IconPair(const std::string icon1URI, const std::string icon2URI,
15  bool clickIsSwitch)
16  : WCompositeWidget(),
17  impl_(cpp14::make_unique<WContainerWidget>()),
18  icon1_(impl_->addWidget(cpp14::make_unique<WImage>(icon1URI))),
19  icon2_(impl_->addWidget(cpp14::make_unique<WImage>(icon2URI))),
20  icon1Clicked(icon1_->clicked()),
21  icon2Clicked(icon2_->clicked())
22 {
23  setImplementation(std::move(impl_));
24 
27 
28  setInline(true);
29 
30  icon2_->hide();
31 
32  if (clickIsSwitch) {
33  icon1_->clicked().connect(icon1_, &WImage::hide);
34  icon1_->clicked().connect(icon2_, &WImage::show);
35 
36  icon2_->clicked().connect(icon2_, &WImage::hide);
37  icon2_->clicked().connect(icon1_, &WImage::show); //
38 
39  decorationStyle().setCursor(Cursor::PointingHand);
40  }
41 } //
42 
43 void IconPair::setState(int num)
44 {
45  if (num == 0) {
46  icon1_->show();
47  icon2_->hide();
48  } else {
49  icon1_->hide();
50  icon2_->show();
51  }
52 }
53 
54 int IconPair::state() const
55 {
56  return (icon1_->isHidden() ? 1 : 0);
57 }
58 
60 {
61  previousState_ = (icon1_->isHidden() ? 1 : 0);
62  setState(0);
63 }
64 
66 {
67  previousState_ = (icon1_->isHidden() ? 1 : 0);
68  setState(1);
69 }
70 
72 {
74 }
75 
77 {
79 } //
virtual void setInline(bool isInline) override
void setCursor(Cursor c)
void setState(int num)
Set which icon should be visible.
Definition: IconPair.C:43
WImage * icon1_
First icon.
Definition: IconPair.h:81
WImage * icon2_
Second icon.
Definition: IconPair.h:84
WStatelessSlot * implementStateless(void(T::*method)())
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition: IconPair.h:99
IconPair(const std::string icon1URI, const std::string icon2URI, bool clickIsSwitch=true)
Construct a two-state icon widget.
Definition: IconPair.C:14
void setImplementation(std::unique_ptr< WWidget > widget)
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition: IconPair.C:76
std::unique_ptr< WContainerWidget > impl_
Definition: IconPair.h:78
virtual WCssDecorationStyle & decorationStyle() override
void showIcon2()
Set state to 1 (show icon 2).
Definition: IconPair.C:65
int state() const
Get the current state.
Definition: IconPair.C:54
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition: IconPair.C:71
void showIcon1()
Set state to 0 (show icon 1).
Definition: IconPair.C:59

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11