GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/setupquickitem.cpp Lines: 1 37 2.7 %
Date: 2017-11-29 Branches: 2 32 6.3 %

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

6
}