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 |
|
5 |
WidgetGroup::WidgetGroup(const Widget2 *const widget, |
27 |
|
|
const std::string &group, |
28 |
|
|
const int height, |
29 |
|
5 |
const int spacing) : |
30 |
|
|
Container(widget), |
31 |
|
|
WidgetListener(), |
32 |
|
|
ActionListener(), |
33 |
|
|
mSpacing(spacing), |
34 |
|
|
mCount(0), |
35 |
|
|
mGroup(group), |
36 |
|
20 |
mLastX(spacing) |
37 |
|
|
{ |
38 |
✓✗ |
5 |
setHeight(height); |
39 |
✓✗ |
5 |
addWidgetListener(this); |
40 |
|
5 |
} |
41 |
|
|
|
42 |
|
24 |
void WidgetGroup::addButton(const std::string &restrict text, |
43 |
|
|
const std::string &restrict tag, |
44 |
|
|
const bool pressed) |
45 |
|
|
{ |
46 |
✓✗✗✓ ✓✗ |
48 |
if (text.empty() || tag.empty()) |
47 |
|
|
return; |
48 |
|
|
|
49 |
|
24 |
Widget *const widget = createWidget(text, pressed); |
50 |
✓✗ |
24 |
if (widget != nullptr) |
51 |
|
|
{ |
52 |
|
72 |
widget->setActionEventId(mActionEventId + tag); |
53 |
|
24 |
widget->addActionListener(this); |
54 |
|
24 |
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 |
|
24 |
void WidgetGroup::addWidget(Widget *const widget, |
68 |
|
|
const int spacing) |
69 |
|
|
{ |
70 |
✓✗ |
24 |
if (widget == nullptr) |
71 |
|
|
return; |
72 |
|
|
|
73 |
|
24 |
Container::add(widget); |
74 |
|
24 |
widget->setPosition(mLastX, spacing); |
75 |
|
24 |
mCount++; |
76 |
|
24 |
mLastX += widget->getWidth() + 2 * mSpacing; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
void WidgetGroup::clear() |
80 |
|
|
{ |
81 |
|
|
Container::clear(); |
82 |
|
|
|
83 |
|
|
mCount = 0; |
84 |
|
|
} |
85 |
|
|
|
86 |
|
6 |
void WidgetGroup::widgetResized(const Event &event A_UNUSED) |
87 |
|
|
{ |
88 |
|
6 |
} |