GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/models/colormodel.cpp Lines: 22 30 73.3 %
Date: 2017-11-29 Branches: 21 50 42.0 %

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/models/colormodel.h"
22
23
#include "gui/widgets/widget2.h"
24
25
#include "utils/gettext.h"
26
27
#include "debug.h"
28
29
2
ColorModel::ColorModel() :
30
    ListModel(),
31
    mNames(),
32
8
    mColors()
33
{
34
}
35
36
6
ColorModel::~ColorModel()
37
{
38
4
}
39
40
4
int ColorModel::getNumberOfElements()
41
{
42
8
    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





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