GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/widgetgroup.cpp Lines: 21 28 75.0 %
Date: 2017-11-29 Branches: 6 14 42.9 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "gui/widgets/widgetgroup.h"
22
23
#include "debug.h"
24
25
10
WidgetGroup::WidgetGroup(const Widget2 *const widget,
26
                         const std::string &group,
27
                         const int height,
28
10
                         const int spacing) :
29
    Container(widget),
30
    WidgetListener(),
31
    ActionListener(),
32
    mSpacing(spacing),
33
    mCount(0),
34
    mGroup(group),
35
40
    mLastX(spacing)
36
{
37
10
    setHeight(height);
38
10
    addWidgetListener(this);
39
10
}
40
41
48
void WidgetGroup::addButton(const std::string &restrict text,
42
                            const std::string &restrict tag,
43
                            const bool pressed)
44
{
45

96
    if (text.empty() || tag.empty())
46
        return;
47
48
48
    Widget *const widget = createWidget(text, pressed);
49
48
    if (widget != nullptr)
50
    {
51
144
        widget->setActionEventId(mActionEventId + tag);
52
48
        widget->addActionListener(this);
53
48
        addWidget(widget, mSpacing);
54
    }
55
}
56
57
void WidgetGroup::action(const ActionEvent &event)
58
{
59
    for (ActionListenerIterator iter = mActionListeners.begin();
60
         iter != mActionListeners.end(); ++iter)
61
    {
62
        (*iter)->action(event);
63
    }
64
}
65
66
48
void WidgetGroup::addWidget(Widget *const widget,
67
                            const int spacing)
68
{
69
48
    if (widget == nullptr)
70
        return;
71
72
48
    Container::add(widget);
73
48
    widget->setPosition(mLastX, spacing);
74
48
    mCount++;
75
48
    mLastX += widget->getWidth() + 2 * mSpacing;
76
}
77
78
void WidgetGroup::clear()
79
{
80
    Container::clear();
81
82
    mCount = 0;
83
}
84
85
12
void WidgetGroup::widgetResized(const Event &event A_UNUSED)
86
{
87
12
}