ManaPlus
src
gui
widgets
widgetgroup.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2012-2019 The ManaPlus Developers
4
* Copyright (C) 2019-2021 Andrei Karas
5
*
6
* This file is part of The ManaPlus Client.
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22
#include "
gui/widgets/widgetgroup.h
"
23
24
#include "
debug.h
"
25
26
WidgetGroup::WidgetGroup
(
const
Widget2
*
const
widget,
27
const
std::string &group,
28
const
int
height,
29
const
int
spacing) :
30
Container
(widget),
31
WidgetListener
(),
32
ActionListener
(),
33
mSpacing(spacing),
34
mCount(0),
35
mGroup(group),
36
mLastX(spacing)
37
{
38
setHeight
(height);
39
addWidgetListener
(
this
);
40
}
41
42
void
WidgetGroup::addButton
(
const
std::string &
restrict
text,
43
const
std::string &
restrict
tag,
44
const
bool
pressed)
45
{
46
if
(text.empty() || tag.empty())
47
return
;
48
49
Widget
*
const
widget =
createWidget
(text, pressed);
50
if
(widget !=
nullptr
)
51
{
52
widget->
setActionEventId
(
mActionEventId
+ tag);
53
widget->
addActionListener
(
this
);
54
addWidget
(widget,
mSpacing
);
55
}
56
}
57
58
void
WidgetGroup::action
(
const
ActionEvent
&event)
59
{
60
for
(
ActionListenerIterator
iter =
mActionListeners
.begin();
61
iter !=
mActionListeners
.end(); ++iter)
62
{
63
(*iter)->action(event);
64
}
65
}
66
67
void
WidgetGroup::addWidget
(
Widget
*
const
widget,
68
const
int
spacing)
69
{
70
if
(widget ==
nullptr
)
71
return
;
72
73
Container::add
(widget);
74
widget->
setPosition
(
mLastX
, spacing);
75
mCount
++;
76
mLastX
+= widget->
getWidth
() + 2 *
mSpacing
;
77
}
78
79
void
WidgetGroup::clear
()
80
{
81
Container::clear
();
82
83
mCount
= 0;
84
}
85
86
void
WidgetGroup::widgetResized
(
const
Event
&event
A_UNUSED
)
87
{
88
}
ActionEvent
Definition:
actionevent.h:98
ActionListener
Definition:
actionlistener.h:79
BasicContainer2::add
virtual void add(Widget *const widget)
Definition:
basiccontainer2.cpp:113
BasicContainer::clear
virtual void clear()
Definition:
basiccontainer.cpp:303
Container
Definition:
container.h:39
Event
Definition:
event.h:79
Widget2
Definition:
widget2.h:37
WidgetGroup::mLastX
int mLastX
Definition:
widgetgroup.h:67
WidgetGroup::addWidget
virtual void addWidget(Widget *const widget, const int spacing)
Definition:
widgetgroup.cpp:67
WidgetGroup::addButton
virtual void addButton(const std::string &text, const std::string &tag, const bool pressed)
Definition:
widgetgroup.cpp:42
WidgetGroup::WidgetGroup
WidgetGroup(const Widget2 *const widget, const std::string &group, const int height, const int spacing)
Definition:
widgetgroup.cpp:26
WidgetGroup::clear
void clear()
Definition:
widgetgroup.cpp:79
WidgetGroup::mCount
int mCount
Definition:
widgetgroup.h:63
WidgetGroup::createWidget
virtual Widget * createWidget(const std::string &name, const bool pressed) const =0
WidgetGroup::widgetResized
void widgetResized(const Event &event)
Definition:
widgetgroup.cpp:86
WidgetGroup::mSpacing
int mSpacing
Definition:
widgetgroup.h:62
WidgetGroup::action
void action(const ActionEvent &event)
Definition:
widgetgroup.cpp:58
WidgetListener
Definition:
widgetlistener.h:81
Widget
Definition:
widget.h:99
Widget::mActionListeners
ActionListenerList mActionListeners
Definition:
widget.h:1034
Widget::addWidgetListener
void addWidgetListener(WidgetListener *const widgetListener)
Definition:
widget.cpp:302
Widget::setHeight
void setHeight(const int height)
Definition:
widget.cpp:140
Widget::setActionEventId
void setActionEventId(const std::string &actionEventId)
Definition:
widget.h:596
Widget::mActionEventId
std::string mActionEventId
Definition:
widget.h:1106
Widget::addActionListener
void addActionListener(ActionListener *const actionListener)
Definition:
widget.cpp:252
Widget::setPosition
void setPosition(const int x, const int y)
Definition:
widget.cpp:161
Widget::ActionListenerIterator
ActionListenerList::iterator ActionListenerIterator
Definition:
widget.h:1039
Widget::getWidth
int getWidth() const
Definition:
widget.h:221
debug.h
restrict
#define restrict
Definition:
localconsts.h:165
A_UNUSED
#define A_UNUSED
Definition:
localconsts.h:160
widgetgroup.h
Generated on Wed Mar 17 2021 19:19:07 for ManaPlus by
1.9.1