GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/colormodel.cpp Lines: 22 30 73.3 %
Date: 2018-07-14 Branches: 11 34 32.4 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2012-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/models/colormodel.h"
22
23
#include "gui/widgets/widget2.h"
24
25
#include "utils/gettext.h"
26
27
#include "debug.h"
28
29
1
ColorModel::ColorModel() :
30
    ListModel(),
31
    mNames(),
32
4
    mColors()
33
{
34
}
35
36
3
ColorModel::~ColorModel()
37
{
38
2
}
39
40
2
int ColorModel::getNumberOfElements()
41
{
42
4
    return CAST_S32(mNames.size());
43
}
44
45
std::string ColorModel::getElementAt(int i)
46
{
47
    if (i >= getNumberOfElements() || i < 0)
48
        return "???";
49
    return mNames[CAST_SIZE(i)];
50
}
51
52
const ColorPair *ColorModel::getColorAt(const int i) const
53
{
54
    if (i >= CAST_S32(mColors.size()) || i < 0)
55
        return &mColors[0];
56
57
    return &mColors[CAST_SIZE(i)];
58
}
59
60
void ColorModel::add(const std::string &name, const Color *const color1,
61
                     const Color *const color2)
62
{
63





10
    mNames.push_back(name);
64
20
    mColors.push_back(ColorPair(color1, color2));
65
}
66
67
#define addColor(name, color) \
68
    model->add(name, &widget->getThemeColor(ThemeColorId::color, 255U), \
69
        &widget->getThemeColor(ThemeColorId::color##_OUTLINE, 255U));
70
71
1
ColorModel *ColorModel::createDefault(const Widget2 *const widget)
72
{
73
2
    ColorModel *const model = new ColorModel;
74
1
    if (widget == nullptr)
75
        return model;
76
    // TRANSLATORS: color name
77
6
    addColor(_("black"), BLACK);
78
    // TRANSLATORS: color name
79
6
    addColor(_("red"), RED);
80
    // TRANSLATORS: color name
81
6
    addColor(_("green"), GREEN);
82
    // TRANSLATORS: color name
83
6
    addColor(_("blue"), BLUE);
84
    // TRANSLATORS: color name
85
6
    addColor(_("gold"), ORANGE);
86
    // TRANSLATORS: color name
87
6
    addColor(_("yellow"), YELLOW);
88
    // TRANSLATORS: color name
89
6
    addColor(_("pink"), PINK);
90
    // TRANSLATORS: color name
91
6
    addColor(_("purple"), PURPLE);
92
    // TRANSLATORS: color name
93
6
    addColor(_("grey"), GRAY);
94
    // TRANSLATORS: color name
95
6
    addColor(_("brown"), BROWN);
96
1
    return model;
97
}