GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/tabs/clanwindowtabs.cpp Lines: 39 73 53.4 %
Date: 2018-06-18 21:15:20 Branches: 20 82 24.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2018  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/tabs/clanwindowtabs.h"
22
23
#include "being/localclan.h"
24
25
#include "gui/widgets/containerplacer.h"
26
#include "gui/widgets/label.h"
27
#include "gui/widgets/layouthelper.h"
28
29
#include "utils/foreach.h"
30
#include "utils/gettext.h"
31
#include "utils/stringutils.h"
32
33
#include "debug.h"
34
35
2
InfoClanTab::InfoClanTab(const Widget2 *const widget) :
36
    Container(widget),
37

2
    mNameLabel(new Label(this, "                ")),
38

2
    mMasterLabel(new Label(this, "                ")),
39


24
    mMapLabel(new Label(this, "                "))
40
{
41
4
    setSelectable(false);
42
43
4
    LayoutHelper h(this);
44
2
    ContainerPlacer place = h.getPlacer(0, 0);
45
46
2
    place(0, 0, mNameLabel, 2, 1);
47
2
    place(0, 1, mMasterLabel, 2, 1);
48
2
    place(0, 2, mMapLabel, 2, 1);
49
50
    place.getCell().matchColWidth(0, 0);
51
4
    setDimension(Rect(0, 0, 600, 300));
52
2
}
53
54
2
void InfoClanTab::resetClan()
55
{
56
    // TRANSLATORS: not in clan label
57
4
    mNameLabel->setCaption(strprintf(_("Not in clan")));
58
6
    mMasterLabel->setCaption(std::string());
59
6
    mMapLabel->setCaption(std::string());
60
2
}
61
62
void InfoClanTab::updateClan()
63
{
64
    mNameLabel->setCaption(strprintf("%s: %s",
65
        // TRANSLATORS: clan name label
66
        _("Clan name"),
67
        localClan.name.c_str()));
68
    mMasterLabel->setCaption(strprintf("%s: %s",
69
        // TRANSLATORS: clan master name label
70
        _("Master name"),
71
        localClan.masterName.c_str()));
72
    mMapLabel->setCaption(strprintf("%s: %s",
73
        // TRANSLATORS: clan map name label
74
        _("Map name"),
75
        localClan.mapName.c_str()));
76
}
77
78
2
StatsClanTab::StatsClanTab(const Widget2 *const widget) :
79
    Container(widget),
80
4
    mLabels()
81
{
82
4
    setSelectable(false);
83
2
}
84
85
2
void StatsClanTab::clearLabels()
86
{
87
8
    FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
88
    {
89
        remove(*it);
90
        delete *it;
91
    }
92
4
    mLabels.clear();
93
2
}
94
95
2
void StatsClanTab::resetClan()
96
{
97
2
    clearLabels();
98
2
}
99
100
101
void StatsClanTab::updateClan()
102
{
103
    clearLabels();
104
105
    LayoutHelper h(this);
106
107
    const int hPadding = h.getLayout().getHPadding();
108
    const int vPadding = h.getLayout().getVPadding();
109
    int y = vPadding;
110
    FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, localClan.stats)
111
    {
112
        Label *const label = new Label(this, *it);
113
        add(label);
114
        label->setPosition(hPadding, y);
115
        label->adjustSize();
116
        y += label->getHeight() + vPadding;
117
        mLabels.push_back(label);
118
    }
119
}
120
121
4
RelationClanTab::RelationClanTab(const Widget2 *const widget) :
122
    Container(widget),
123
8
    mLabels()
124
{
125
8
    setSelectable(false);
126
4
}
127
128
4
void RelationClanTab::clearLabels()
129
{
130
16
    FOR_EACH (STD_VECTOR<Label*>::iterator, it, mLabels)
131
    {
132
        remove(*it);
133
        delete *it;
134
    }
135
8
    mLabels.clear();
136
4
}
137
138
4
void RelationClanTab::resetClan()
139
{
140
4
    clearLabels();
141
4
}
142
143
void RelationClanTab::updateClan(const STD_VECTOR<std::string> &restrict names)
144
{
145
    clearLabels();
146
147
    LayoutHelper h(this);
148
149
    const int hPadding = h.getLayout().getHPadding();
150
    const int vPadding = h.getLayout().getVPadding();
151
    int y = vPadding;
152
    FOR_EACH (STD_VECTOR<std::string>::const_iterator, it, names)
153
    {
154
        Label *const label = new Label(this, *it);
155
        add(label);
156
        label->setPosition(hPadding, y);
157
        label->adjustSize();
158
        y += label->getHeight() + vPadding;
159
        mLabels.push_back(label);
160
    }
161
}