GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/setuptouchitem.cpp Lines: 35 48 72.9 %
Date: 2018-12-09 Branches: 9 28 32.1 %

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/widgets/setuptouchitem.h"
22
23
#include "gui/models/touchactionmodel.h"
24
25
#include "gui/widgets/dropdown.h"
26
#include "gui/widgets/horizontcontainer.h"
27
#include "gui/widgets/label.h"
28
#include "gui/widgets/vertcontainer.h"
29
30
#include "gui/widgets/tabs/setuptabscroll.h"
31
32
#include "utils/stringutils.h"
33
34
#include "debug.h"
35
36
26
SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
37
                                         const std::string &restrict
38
                                         description,
39
                                         const std::string &restrict keyName,
40
                                         SetupTabScroll *restrict const parent,
41
                                         const std::string &restrict eventName,
42
                                         TouchActionsModel *restrict
43
                                         const model,
44
                                         const int width,
45
26
                                         const MainConfig mainConfig) :
46
    SetupItem(text, description, keyName, parent, eventName, mainConfig),
47
    mHorizont(nullptr),
48
    mLabel(nullptr),
49
    mModel(model),
50
    mDropDown(nullptr),
51
26
    mWidth(width)
52
{
53
26
    mValueType = VSTR;
54
26
    createControls();
55
26
}
56
57
SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
58
                                         const std::string &restrict
59
                                         description,
60
                                         const std::string &restrict keyName,
61
                                         SetupTabScroll *restrict const parent,
62
                                         const std::string &restrict eventName,
63
                                         TouchActionsModel *restrict
64
                                         const model,
65
                                         const int width,
66
                                         const std::string &restrict def,
67
                                         const MainConfig mainConfig) :
68
    SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
69
    mHorizont(nullptr),
70
    mLabel(nullptr),
71
    mModel(model),
72
    mDropDown(nullptr),
73
    mWidth(width)
74
{
75
    mValueType = VSTR;
76
    createControls();
77
}
78
79
52
SetupActionDropDown::~SetupActionDropDown()
80
{
81
26
    mHorizont = nullptr;
82
26
    mWidget = nullptr;
83
26
    mModel = nullptr;
84
26
    mDropDown = nullptr;
85
26
    mLabel = nullptr;
86
26
}
87
88
26
void SetupActionDropDown::createControls()
89
{
90
26
    if (mModel == nullptr)
91
        return;
92
93
26
    load();
94
26
    mHorizont = new HorizontContainer(this, 32, 2);
95
96
26
    mLabel = new Label(this, mText);
97
52
    mLabel->setToolTip(mDescription);
98
26
    mDropDown = new DropDown(this,
99
26
        mModel,
100
        false,
101
        Modal_false,
102
        nullptr,
103

78
        std::string());
104
52
    mDropDown->setActionEventId(mEventName);
105
26
    mDropDown->addActionListener(mParent);
106
26
    mDropDown->setWidth(mWidth);
107
26
    mDropDown->setSelected(mModel->getSelectionFromAction(
108
104
        static_cast<InputActionT>(atoi(mValue.c_str()))));
109
110
26
    mWidget = mDropDown;
111
26
    fixFirstItemSize(mLabel);
112
26
    mHorizont->add(mLabel);
113
26
    mHorizont->add(mDropDown);
114
115
52
    mParent->getContainer()->add2(mHorizont, true, 4);
116
26
    mParent->addControl(this);
117
26
    mParent->addActionListener(this);
118
26
    mWidget->addActionListener(this);
119
}
120
121
void SetupActionDropDown::fromWidget()
122
{
123
    if ((mDropDown == nullptr) || (mModel == nullptr))
124
        return;
125
126
    mValue = toString(CAST_S32(mModel->getActionFromSelection(
127
        mDropDown->getSelected())));
128
}
129
130
void SetupActionDropDown::toWidget()
131
{
132
    if ((mDropDown == nullptr) || (mModel == nullptr))
133
        return;
134
135
    mDropDown->setSelected(mModel->getSelectionFromAction(
136
        static_cast<InputActionT>(atoi(mValue.c_str()))));
137
}