Add update of GenlistItem fields when text and description are changed
[profile/mobile/apps/native/accessibility-setting.git] / src / SetValuePage.hpp
1 /*
2  * Copyright 2018 Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *  http://www.apache.org/licenses/LICENSE-2.0
9
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef SET_VALUE_PAGE_HPP
18 #define SET_VALUE_PAGE_HPP
19
20 #include "AppContext.hpp"
21 #include "Box.hpp"
22 #include "Check.hpp"
23 #include "GenlistItem.hpp"
24 #include "Scroller.hpp"
25
26 #include <vconf.h>
27
28 using ChangeValueCb = std::function<void(double)>;
29
30 enum class ValueEditorType
31 {
32         NUMERIC,
33         NUMERIC_SWITCH,
34         RADIOS,
35         SWITCHES,
36         LIST_SWITCH
37 };
38
39 class SetValuePage;
40 struct OptionsItem
41 {
42         SetValuePage *self;
43         int option_id;
44 };
45
46 using ChangeValueCb = std::function<void(double)>;
47 using ChangeSwitchCb = std::function<void(bool)>;
48 using ChangeRadioItemCb = std::function<void(size_t)>;
49 using ChangeSwitchItemCb = std::function<void(int, bool)>;
50 using RequestListItemOptionsCb = std::function<void(int)>;
51
52 class SetValuePage
53 {
54         public:
55         SetValuePage(ValueEditorType type, TranslatedString title, NaviframeItem targetItem = {});
56         void setDescription(const TranslatedString &description);
57         void setRange(double min, double max, double step);
58         void setValue(double value, const std::string &units);
59         void setSwitch(bool state);
60         void addRadioItem(const std::string &caption, int id, bool selected);
61         GenlistItem *addRadioListItem(const std::string &main_text, const std::string &sub_text, int option_id);
62         void addValueChangedCb(ChangeValueCb cb);
63         void addSwitchChangedCb(ChangeSwitchCb cb);
64         void addRadioItemChangedCb(ChangeRadioItemCb cb);
65         void addListItemOptionsRequestCb(RequestListItemOptionsCb cb);
66         void setCheckState(bool state);
67
68         private:
69         void callRadioItemChangeCbAndPopNaviframe(GenlistItem *item);
70         Genlist *createGenlist(Widget *parent, TranslatedString title);
71         void createScroller();
72         Layout *createLayout(Widget *parent, const std::string &layoutGroup);
73         void displayValue(double value);
74         void checkStateChangedCb();
75         static void backCb(void *data, Evas_Object *obj, void *event_info);
76
77         AppContext &context_;
78         NaviframeItem naviframeItem_;
79
80         Layout *layout_ = nullptr;
81         Scroller *scroller_ = nullptr;
82         Box *box_ = nullptr;
83         Check *check_ = nullptr;
84         Genlist *genlist_ = nullptr;
85         std::vector<OptionsItem *> options_data;
86         double minVal_ = 0.0;
87         double maxVal_ = 0.0;
88         double step_ = 0.0;
89         std::string units_;
90
91         ChangeValueCb changeValueCb_;
92         ChangeSwitchCb changeSwitchCb_;
93         ChangeRadioItemCb changeRadioItemCb_;
94         RequestListItemOptionsCb requestListItemOptionsCb_;
95 };
96
97 #endif