GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/setupquickitem.cpp Lines: 1 39 2.6 %
Date: 2021-03-17 Branches: 2 28 7.1 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-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/widgets/setupquickitem.h"
23
24
#include "gui/widgets/button.h"
25
#include "gui/widgets/horizontcontainer.h"
26
#include "gui/widgets/label.h"
27
#include "gui/widgets/vertcontainer.h"
28
29
#include "gui/widgets/tabs/setuptabscroll.h"
30
31
#include "debug.h"
32
33
SetupQuickItem::SetupQuickItem(const std::string &restrict description,
34
                               SetupTabScroll *restrict const parent,
35
                               const std::string &restrict eventName,
36
                               const ModifierGetFuncPtr getFunc,
37
                               const ModifierChangeFuncPtr changeFunc) :
38
    SetupItem("", description, "", parent, eventName, MainConfig_false),
39
    GameModifierListener(),
40
    mHorizont(nullptr),
41
    mButton(nullptr),
42
    mLabel(nullptr),
43
    mGetFunc(getFunc),
44
    mChangeFunc(changeFunc)
45
{
46
    mValueType = VSTR;
47
    createControls();
48
}
49
50
SetupQuickItem::~SetupQuickItem()
51
{
52
    mHorizont = nullptr;
53
    mWidget = nullptr;
54
    mButton = nullptr;
55
}
56
57
void SetupQuickItem::save()
58
{
59
}
60
61
void SetupQuickItem::cancel(const std::string &eventName A_UNUSED)
62
{
63
}
64
65
void SetupQuickItem::externalUpdated(const std::string &eventName A_UNUSED)
66
{
67
}
68
69
void SetupQuickItem::rereadValue()
70
{
71
}
72
73
void SetupQuickItem::createControls()
74
{
75
    mHorizont = new HorizontContainer(this, 32, 2);
76
77
    mWidget = new Button(this,
78
        ">",
79
        mEventName + "_CHANGE",
80
        BUTTON_SKIN,
81
        nullptr);
82
    mLabel = new Label(this, std::string());
83
    mLabel->setToolTip(mDescription);
84
    mLabel->adjustSize();
85
86
    mHorizont->add(mWidget, 5);
87
    mHorizont->add(mLabel);
88
89
    mParent->getContainer()->add2(mHorizont, true, 4);
90
    mParent->addControl(this);
91
    mWidget->addActionListener(this);
92
    toWidget();
93
}
94
95
void SetupQuickItem::fromWidget()
96
{
97
}
98
99
void SetupQuickItem::toWidget()
100
{
101
    mLabel->setCaption(mGetFunc());
102
    mLabel->adjustSize();
103
}
104
105
void SetupQuickItem::action(const ActionEvent &event)
106
{
107
    if (event.getId() == mEventName + "_CHANGE")
108
    {
109
        // need change game modifier
110
        mChangeFunc(true);
111
        toWidget();
112
    }
113
}
114
115
void SetupQuickItem::apply(const std::string &eventName A_UNUSED)
116
{
117
}
118
119
void SetupQuickItem::gameModifiersChanged()
120
{
121
    toWidget();
122

3
}