GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/setuptouchitem.cpp Lines: 33 46 71.7 %
Date: 2017-11-29 Branches: 10 30 33.3 %

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/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
52
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
52
                                         const MainConfig mainConfig) :
46
    SetupItem(text, description, keyName, parent, eventName, mainConfig),
47
    mHorizont(nullptr),
48
    mLabel(nullptr),
49
    mModel(model),
50
    mDropDown(nullptr),
51
52
    mWidth(width)
52
{
53
52
    mValueType = VSTR;
54
52
    createControls();
55
52
}
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
104
SetupActionDropDown::~SetupActionDropDown()
80
{
81
52
    mHorizont = nullptr;
82
52
    mWidget = nullptr;
83
52
    mModel = nullptr;
84
52
    mDropDown = nullptr;
85
52
    mLabel = nullptr;
86
52
}
87
88
52
void SetupActionDropDown::createControls()
89
{
90
52
    if (mModel == nullptr)
91
        return;
92
93
52
    load();
94
52
    mHorizont = new HorizontContainer(this, 32, 2);
95
96
52
    mLabel = new Label(this, mText);
97
104
    mLabel->setToolTip(mDescription);
98

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