ManaPlus
setupquickitem.cpp
Go to the documentation of this file.
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 
23 
24 #include "gui/widgets/button.h"
26 #include "gui/widgets/label.h"
28 
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),
40  mHorizont(nullptr),
41  mButton(nullptr),
42  mLabel(nullptr),
43  mGetFunc(getFunc),
44  mChangeFunc(changeFunc)
45 {
46  mValueType = VSTR;
48 }
49 
51 {
52  mHorizont = nullptr;
53  mWidget = nullptr;
54  mButton = nullptr;
55 }
56 
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 
70 {
71 }
72 
74 {
75  mHorizont = new HorizontContainer(this, 32, 2);
76 
77  mWidget = new Button(this,
78  ">",
79  mEventName + "_CHANGE",
81  nullptr);
82  mLabel = new Label(this, std::string());
84  mLabel->adjustSize();
85 
86  mHorizont->add(mWidget, 5);
88 
89  mParent->getContainer()->add2(mHorizont, true, 4);
90  mParent->addControl(this);
92  toWidget();
93 }
94 
96 {
97 }
98 
100 {
102  mLabel->adjustSize();
103 }
104 
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 
120 {
121  toWidget();
122 }
const std::string BUTTON_SKIN
Definition: button.h:89
const std::string & getId() const
Definition: actionevent.h:122
Definition: button.h:102
void add(Widget *const widget)
Definition: label.h:91
void adjustSize()
Definition: label.cpp:200
void setCaption(const std::string &caption)
Definition: label.cpp:264
Widget * mWidget
Definition: setupitem.h:143
SetupTabScroll * mParent
Definition: setupitem.h:135
std::string mDescription
Definition: setupitem.h:131
int mValueType
Definition: setupitem.h:147
std::string mEventName
Definition: setupitem.h:137
void externalUpdated(const std::string &eventName)
ModifierGetFuncPtr mGetFunc
HorizontContainer * mHorizont
ModifierChangeFuncPtr mChangeFunc
Button * mButton
void action(const ActionEvent &event)
void apply(const std::string &eventName)
void gameModifiersChanged()
void cancel(const std::string &eventName)
SetupQuickItem(const std::string &description, SetupTabScroll *const parent, const std::string &eventName, ModifierGetFuncPtr getFunc, ModifierChangeFuncPtr changeFunc)
void addControl(SetupItem *const widget)
VertContainer * getContainer() const
void setToolTip(const std::string &str)
void add2(Widget *const widget, const bool resizable, const int spacing)
void addActionListener(ActionListener *const actionListener)
Definition: widget.cpp:252
#define restrict
Definition: localconsts.h:165
#define nullptr
Definition: localconsts.h:45
#define A_UNUSED
Definition: localconsts.h:160
const bool MainConfig_false
Definition: mainconfig.h:30
std::string(* ModifierGetFuncPtr)()
void(* ModifierChangeFuncPtr)(const bool forward)