Wt examples  4.11.1
Loading...
Searching...
No Matches
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.h>
7#include <Wt/WContainerWidget.h>
8#include <Wt/WImage.h>
9
10#include "IconPair.h"
11
12using namespace Wt;
13
14IconPair::IconPair(const std::string icon1URI, const std::string icon2URI,
15 bool clickIsSwitch)
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} //
49
50void IconPair::setState(int num)
51{
52 if (num == 0) {
53 icon1_->show();
54 icon2_->hide();
55 } else {
56 icon1_->hide();
57 icon2_->show();
58 }
59}
60
61int IconPair::state() const
62{
63 return (icon1_->isHidden() ? 1 : 0);
64}
65
67{
68 previousState_ = (icon1_->isHidden() ? 1 : 0);
69 setState(0);
70}
71
73{
74 previousState_ = (icon1_->isHidden() ? 1 : 0);
75 setState(1);
76}
77
82
WImage * icon2_
Second icon.
Definition IconPair.h:84
int state() const
Get the current state.
Definition IconPair.C:61
WContainerWidget * impl_
Definition IconPair.h:78
EventSignal< WMouseEvent > * icon2Clicked
Signal emitted when clicked while in state 1 (icon 2 is shown).
Definition IconPair.h:95
void undoShowIcon2()
Undo function for prelearning showIcon2()
Definition IconPair.C:83
void setState(int num)
Set which icon should be visible.
Definition IconPair.C:50
WImage * icon1_
First icon.
Definition IconPair.h:81
void showIcon2()
Set state to 1 (show icon 2).
Definition IconPair.C:72
void undoShowIcon1()
Undo function for prelearning showIcon1()
Definition IconPair.C:78
IconPair(const std::string icon1URI, const std::string icon2URI, bool clickIsSwitch=true)
Construct a two-state icon widget.
Definition IconPair.C:14
EventSignal< WMouseEvent > * icon1Clicked
Signal emitted when clicked while in state 0 (icon 1 is shown).
Definition IconPair.h:90
int previousState_
Undo state for prelearning stateless showIcon1() and showIcon2() slots.
Definition IconPair.h:99
void showIcon1()
Set state to 0 (show icon 1).
Definition IconPair.C:66