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

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





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